diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2017-10-01 19:48:31 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2017-10-01 19:52:40 -0400 |
commit | 0685dd4920c64eae6bcfbc9f201854b4da91bfab (patch) | |
tree | f759feaf819167d436ab4fde480eca35ba591b04 /src/engine/play_time.c | |
parent | d0fbed6ad50c34593002c2b540c4e3e7f4c5cd16 (diff) | |
parent | 50dc4f429d4aa68e0365adc71d17e43a0dd7b843 (diff) |
Merge branch 'master' into trade
Diffstat (limited to 'src/engine/play_time.c')
-rw-r--r-- | src/engine/play_time.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/engine/play_time.c b/src/engine/play_time.c new file mode 100644 index 000000000..9882c9c4b --- /dev/null +++ b/src/engine/play_time.c @@ -0,0 +1,73 @@ +#include "global.h" +#include "play_time.h" + +enum +{ + STOPPED, + RUNNING, + MAXED_OUT +}; + +static u8 sPlayTimeCounterState; + +void PlayTimeCounter_Reset() +{ + sPlayTimeCounterState = STOPPED; + + gSaveBlock2.playTimeHours = 0; + gSaveBlock2.playTimeMinutes = 0; + gSaveBlock2.playTimeSeconds = 0; + gSaveBlock2.playTimeVBlanks = 0; +} + +void PlayTimeCounter_Start() +{ + sPlayTimeCounterState = RUNNING; + + if (gSaveBlock2.playTimeHours > 999) + PlayTimeCounter_SetToMax(); +} + +void PlayTimeCounter_Stop() +{ + sPlayTimeCounterState = STOPPED; +} + +void PlayTimeCounter_Update() +{ + if (sPlayTimeCounterState == RUNNING) + { + gSaveBlock2.playTimeVBlanks++; + + if (gSaveBlock2.playTimeVBlanks > 59) + { + gSaveBlock2.playTimeVBlanks = 0; + gSaveBlock2.playTimeSeconds++; + + if (gSaveBlock2.playTimeSeconds > 59) + { + gSaveBlock2.playTimeSeconds = 0; + gSaveBlock2.playTimeMinutes++; + + if (gSaveBlock2.playTimeMinutes > 59) + { + gSaveBlock2.playTimeMinutes = 0; + gSaveBlock2.playTimeHours++; + + if (gSaveBlock2.playTimeHours > 999) + PlayTimeCounter_SetToMax(); + } + } + } + } +} + +void PlayTimeCounter_SetToMax() +{ + sPlayTimeCounterState = MAXED_OUT; + + gSaveBlock2.playTimeHours = 999; + gSaveBlock2.playTimeMinutes = 59; + gSaveBlock2.playTimeSeconds = 59; + gSaveBlock2.playTimeVBlanks = 59; +} |