mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-22 18:31:59 -05:00
Refactor date update and checks to new functions
This commit is contained in:
parent
f0b8559341
commit
017eb4df72
3 changed files with 57 additions and 14 deletions
|
@ -67,6 +67,20 @@ void date_reset()
|
|||
gCurrentTicks = 0;
|
||||
}
|
||||
|
||||
void date_update()
|
||||
{
|
||||
sint32 monthTicks = gDateMonthTicks + 4;
|
||||
if (monthTicks >= 0x10000)
|
||||
{
|
||||
gDateMonthTicks = 0;
|
||||
gDateMonthsElapsed++;
|
||||
}
|
||||
else
|
||||
{
|
||||
gDateMonthTicks = floor2((uint16)monthTicks, 4);
|
||||
}
|
||||
}
|
||||
|
||||
void date_update_real_time_of_day()
|
||||
{
|
||||
time_t timestamp = time(0);
|
||||
|
@ -76,3 +90,30 @@ void date_update_real_time_of_day()
|
|||
gRealTimeOfDay.minute = now->tm_min;
|
||||
gRealTimeOfDay.hour = now->tm_hour;
|
||||
}
|
||||
|
||||
bool date_is_day_start(sint32 monthTicks)
|
||||
{
|
||||
if (monthTicks < 4)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
sint32 prevMonthTick = monthTicks - 4;
|
||||
sint32 currentMonth = date_get_month(gDateMonthsElapsed);
|
||||
sint32 currentDaysInMonth = days_in_month[currentMonth];
|
||||
return ((currentDaysInMonth * monthTicks) >> 16 != (currentDaysInMonth * prevMonthTick) >> 16);
|
||||
}
|
||||
|
||||
bool date_is_week_start(sint32 monthTicks)
|
||||
{
|
||||
return (monthTicks & 0x3FFF) == 0;
|
||||
}
|
||||
|
||||
bool date_is_fortnight_start(sint32 monthTicks)
|
||||
{
|
||||
return (monthTicks & 0x7FFF) == 0;
|
||||
}
|
||||
|
||||
bool date_is_month_start(sint32 monthTicks)
|
||||
{
|
||||
return (monthTicks == 0);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,12 @@ sint32 date_get_month(sint32 months);
|
|||
sint32 date_get_year(sint32 months);
|
||||
sint32 date_get_total_months(sint32 month, sint32 year);
|
||||
void date_reset();
|
||||
void date_update();
|
||||
void date_update_real_time_of_day();
|
||||
bool date_is_day_start(sint32 monthTicks);
|
||||
bool date_is_week_start(sint32 monthTicks);
|
||||
bool date_is_fortnight_start(sint32 monthTicks);
|
||||
bool date_is_month_start(sint32 monthTicks);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -394,29 +394,26 @@ static void scenario_update_daynight_cycle()
|
|||
*/
|
||||
void scenario_update()
|
||||
{
|
||||
if (!(gScreenFlags & ~SCREEN_FLAGS_PLAYING)) {
|
||||
uint32 currentMonthTick = floor2(gDateMonthTicks, 4);
|
||||
uint32 nextMonthTick = currentMonthTick + 4;
|
||||
uint8 currentMonth = gDateMonthsElapsed & 7;
|
||||
uint8 currentDaysInMonth = (uint8)days_in_month[currentMonth];
|
||||
|
||||
if ((currentDaysInMonth * nextMonthTick) >> 16 != (currentDaysInMonth * currentMonthTick) >> 16) {
|
||||
if (gScreenFlags == SCREEN_FLAGS_PLAYING)
|
||||
{
|
||||
date_update();
|
||||
if (date_is_day_start(gDateMonthTicks))
|
||||
{
|
||||
scenario_day_update();
|
||||
}
|
||||
if (nextMonthTick % 0x4000 == 0) {
|
||||
if (date_is_week_start(gDateMonthTicks))
|
||||
{
|
||||
scenario_week_update();
|
||||
}
|
||||
if (nextMonthTick % 0x8000 == 0) {
|
||||
if (date_is_fortnight_start(gDateMonthTicks))
|
||||
{
|
||||
scenario_fortnight_update();
|
||||
}
|
||||
|
||||
gDateMonthTicks = (uint16)nextMonthTick;
|
||||
if (nextMonthTick >= 0x10000) {
|
||||
gDateMonthsElapsed++;
|
||||
if (date_is_month_start(gDateMonthTicks))
|
||||
{
|
||||
scenario_month_update();
|
||||
}
|
||||
}
|
||||
|
||||
scenario_update_daynight_cycle();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue