Feature: Use real-time "wallclock" timekeeping units (#11341)
This commit is contained in:
@@ -38,6 +38,41 @@ TimerGameEconomy::Month TimerGameEconomy::month = {};
|
||||
TimerGameEconomy::Date TimerGameEconomy::date = {};
|
||||
TimerGameEconomy::DateFract TimerGameEconomy::date_fract = {};
|
||||
|
||||
/**
|
||||
* Converts a Date to a Year, Month & Day.
|
||||
* @param date the date to convert from
|
||||
* @returns YearMonthDay representation of the Date.
|
||||
*/
|
||||
/* static */ TimerGameEconomy::YearMonthDay TimerGameEconomy::ConvertDateToYMD(TimerGameEconomy::Date date)
|
||||
{
|
||||
/* If we're not using wallclock units, we keep the economy date in sync with the calendar. */
|
||||
if (!UsingWallclockUnits()) return CalendarConvertDateToYMD(date);
|
||||
|
||||
/* If we're using wallclock units, economy months have 30 days and an economy year has 360 days. */
|
||||
TimerGameEconomy::YearMonthDay ymd;
|
||||
ymd.year = TimerGameEconomy::date.base() / EconomyTime::DAYS_IN_ECONOMY_YEAR;
|
||||
ymd.month = (TimerGameEconomy::date.base() % EconomyTime::DAYS_IN_ECONOMY_YEAR) / EconomyTime::DAYS_IN_ECONOMY_MONTH;
|
||||
ymd.day = TimerGameEconomy::date.base() % EconomyTime::DAYS_IN_ECONOMY_MONTH;
|
||||
return ymd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a tuple of Year, Month and Day to a Date.
|
||||
* @param year is a number between 0..MAX_YEAR
|
||||
* @param month is a number between 0..11
|
||||
* @param day is a number between 1..31
|
||||
* @returns The equivalent date.
|
||||
*/
|
||||
/* static */ TimerGameEconomy::Date TimerGameEconomy::ConvertYMDToDate(TimerGameEconomy::Year year, TimerGameEconomy::Month month, TimerGameEconomy::Day day)
|
||||
{
|
||||
/* If we're not using wallclock units, we keep the economy date in sync with the calendar. */
|
||||
if (!UsingWallclockUnits()) return CalendarConvertYMDToDate(year, month, day);
|
||||
|
||||
/* If we're using wallclock units, economy months have 30 days and an economy year has 360 days. */
|
||||
const int total_months = (year.base() * EconomyTime::MONTHS_IN_YEAR) + month;
|
||||
return (total_months * EconomyTime::DAYS_IN_ECONOMY_MONTH) + day - 1; // Day is 1-indexed but Date is 0-indexed, hence the - 1.
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date.
|
||||
* @param date The new date
|
||||
@@ -54,6 +89,18 @@ TimerGameEconomy::DateFract TimerGameEconomy::date_fract = {};
|
||||
TimerGameEconomy::month = ymd.month;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are using wallclock units.
|
||||
* @param newgame Should we check the settings for a new game (since we are in the main menu)?
|
||||
* @return True if the game is using wallclock units, or false if the game is using calendar units.
|
||||
*/
|
||||
/* static */ bool TimerGameEconomy::UsingWallclockUnits(bool newgame)
|
||||
{
|
||||
if (newgame) return (_settings_newgame.economy.timekeeping_units == TKU_WALLCLOCK);
|
||||
|
||||
return (_settings_game.economy.timekeeping_units == TKU_WALLCLOCK);
|
||||
}
|
||||
|
||||
template<>
|
||||
void IntervalTimer<TimerGameEconomy>::Elapsed(TimerGameEconomy::TElapsed trigger)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user