diff options
author | frosch <frosch@openttd.org> | 2008-06-20 21:14:10 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2008-06-20 21:14:10 +0000 |
commit | 4236dd3be5c4c5c130551f625f3459a4c733bfc3 (patch) | |
tree | 9f0f3597960d1562c26a18b355f4fa2e98db5a01 /src | |
parent | c406ea35eccd7a7af576ce4d7f2adad2d9a13573 (diff) | |
download | openttd-4236dd3be5c4c5c130551f625f3459a4c733bfc3.tar.xz |
(svn r13594) -Feature(ette)[FS#2093]: Supply newgrfs with 'day of month', 'leap year' and 'day of year'.
Diffstat (limited to 'src')
-rw-r--r-- | src/date.cpp | 5 | ||||
-rw-r--r-- | src/date_func.h | 5 | ||||
-rw-r--r-- | src/date_type.h | 4 | ||||
-rw-r--r-- | src/newgrf.cpp | 8 |
4 files changed, 13 insertions, 9 deletions
diff --git a/src/date.cpp b/src/date.cpp index 908f94041..f6f4f19aa 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -77,11 +77,6 @@ static const uint16 _accum_days_for_month[] = { ACCUM_SEP, ACCUM_OCT, ACCUM_NOV, ACCUM_DEC, }; -static inline bool IsLeapYear(Year yr) -{ - return yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0); -} - /** * Converts a Date to a Year, Month & Day. * @param date the date to convert from diff --git a/src/date_func.h b/src/date_func.h index d196fdb52..8c484b2c4 100644 --- a/src/date_func.h +++ b/src/date_func.h @@ -16,4 +16,9 @@ void SetDate(Date date); void ConvertDateToYMD(Date date, YearMonthDay *ymd); Date ConvertYMDToDate(Year year, Month month, Day day); +static inline bool IsLeapYear(Year yr) +{ + return yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0); +} + #endif /* DATE_FUNC_H */ diff --git a/src/date_type.h b/src/date_type.h index 86885faeb..ddb6dfc7c 100644 --- a/src/date_type.h +++ b/src/date_type.h @@ -46,8 +46,8 @@ typedef uint8 Day; struct YearMonthDay { Year year; - Month month; - Day day; + Month month; ///< 0 - 11 + Day day; ///< 1 - 31 }; static const Year INVALID_YEAR = -1; diff --git a/src/newgrf.cpp b/src/newgrf.cpp index f1fe64635..3885fcf23 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3566,9 +3566,13 @@ bool GetGlobalVariable(byte param, uint32 *value) *value = Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; return true; - case 0x02: // current month - *value = _cur_month; + case 0x02: { // detailed date information: month of year (bit 0-7), day of month (bit 8-12), leap year (bit 15), day of year (bit 16-24) + YearMonthDay ymd; + ConvertDateToYMD(_date, &ymd); + Date start_of_year = ConvertYMDToDate(ymd.year, 0, 1); + *value = ymd.month | (ymd.day - 1) << 8 | (IsLeapYear(ymd.year) ? 1 << 15 : 0) | (_date - start_of_year) << 16; return true; + } case 0x03: // current climate, 0=temp, 1=arctic, 2=trop, 3=toyland *value = _settings_game.game_creation.landscape; |