# HG changeset patch # User rubidium # Date 1155655083 0 # Node ID 9594c2c9c53afdcbcfe9411c1792a1ea4c11a18c # Parent 8b7fca8ace982000ee1de6f2249e9d224f51a080 (svn r5916) -Cleanup: use MIN_YEAR/MAX_YEAR for the year boundaries and BASE_YEAR when comparing _cur_year with a 'full' year. -Cleanup: replace some magic '1920' values with BASE_YEAR. diff --git a/aircraft_gui.c b/aircraft_gui.c --- a/aircraft_gui.c +++ b/aircraft_gui.c @@ -66,7 +66,7 @@ y += 10; /* Design date - Life length */ - SetDParam(0, ymd.year + 1920); + SetDParam(0, BASE_YEAR + ymd.year); SetDParam(1, e->lifelength); DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); y += 10; @@ -402,7 +402,7 @@ do { if (v->subtype <= 2) { SetDParam(0, GetCustomEngineName(v->engine_type)); - SetDParam(1, 1920 + v->build_year); + SetDParam(1, BASE_YEAR + v->build_year); SetDParam(2, v->value); DrawString(60, y, STR_A011_BUILT_VALUE, 0); y += 10; diff --git a/console_cmds.c b/console_cmds.c --- a/console_cmds.c +++ b/console_cmds.c @@ -1174,7 +1174,7 @@ GetString(buffer, STR_00D1_DARK_BLUE + _player_colors[p->index]); IConsolePrintF(8, "#:%d(%s) Company Name: '%s' Year Founded: %d Money: %d Loan: %d Value: %" OTTD_PRINTF64 "d (T:%d, R:%d, P:%d, S:%d)", - p->index + 1, buffer, _network_player_info[p->index].company_name, p->inaugurated_year + MAX_YEAR_BEGIN_REAL, p->player_money, p->current_loan, CalculateCompanyValue(p), + p->index + 1, buffer, _network_player_info[p->index].company_name, BASE_YEAR + p->inaugurated_year, p->player_money, p->current_loan, CalculateCompanyValue(p), /* trains */ _network_player_info[p->index].num_vehicle[0], /* lorry + bus */ _network_player_info[p->index].num_vehicle[1] + _network_player_info[p->index].num_vehicle[2], /* planes */ _network_player_info[p->index].num_vehicle[3], diff --git a/currency.c b/currency.c --- a/currency.c +++ b/currency.c @@ -81,8 +81,8 @@ for (i = 0; i != lengthof(_currency_specs); i++) { uint16 to_euro = _currency_specs[i].to_euro; - if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro - MAX_YEAR_BEGIN_REAL) continue; - if (to_euro == CF_ISEURO && _cur_year < 2000 - MAX_YEAR_BEGIN_REAL) continue; + if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && BASE_YEAR + _cur_year >= to_euro) continue; + if (to_euro == CF_ISEURO && BASE_YEAR + _cur_year < 2000) continue; mask |= (1 << i); } mask |= (1 << CUSTOM_CURRENCY_ID); // always allow custom currency @@ -94,7 +94,7 @@ { if (_currency_specs[_opt.currency].to_euro != CF_NOEURO && _currency_specs[_opt.currency].to_euro != CF_ISEURO && - MAX_YEAR_BEGIN_REAL + _cur_year >= _currency_specs[_opt.currency].to_euro) { + BASE_YEAR + _cur_year >= _currency_specs[_opt.currency].to_euro) { _opt.currency = 2; // this is the index of euro above. AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL, 0, NT_ECONOMY, 0), 0, 0); } diff --git a/date.c b/date.c --- a/date.c +++ b/date.c @@ -129,7 +129,7 @@ Month month = 0; Day day = 1; - if (IS_INT_INSIDE(date, 1920, MAX_YEAR_END_REAL + 1)) { + if (IS_INT_INSIDE(date, 1920, MAX_YEAR + 1)) { year = date - 1920; } else if (IS_INT_INSIDE(date, 192001, 209012 + 1)) { month = date % 100 - 1; @@ -282,13 +282,13 @@ #endif /* ENABLE_NETWORK */ /* check if we reached end of the game */ - if (_cur_year == _patches.ending_year - MAX_YEAR_BEGIN_REAL) { + if (_cur_year == _patches.ending_year - MAX_YEAR) { ShowEndGameChart(); /* check if we reached the maximum year, decrement dates by a year */ - } else if (_cur_year == (MAX_YEAR_END + 1)) { + } else if (BASE_YEAR + _cur_year == MAX_YEAR + 1) { Vehicle *v; - _cur_year = MAX_YEAR_END; + _cur_year--; _date -= 365; FOR_ALL_VEHICLES(v) { v->date_of_last_service -= 365; diff --git a/date.h b/date.h --- a/date.h +++ b/date.h @@ -8,9 +8,9 @@ */ #define DAY_TICKS 74 -#define MAX_YEAR_BEGIN_REAL 1920 -#define MAX_YEAR_END_REAL 2090 -#define MAX_YEAR_END 170 +#define BASE_YEAR 1920 +#define MIN_YEAR 1920 +#define MAX_YEAR 2090 /* Year and Date are defined elsewhere */ typedef uint8 Month; diff --git a/disaster_cmd.c b/disaster_cmd.c --- a/disaster_cmd.c +++ b/disaster_cmd.c @@ -951,7 +951,7 @@ Disaster7_Init, }; -#define MK(a, b) { (a) - MAX_YEAR_BEGIN_REAL, (b) - MAX_YEAR_BEGIN_REAL } +#define MK(a, b) { (a) - BASE_YEAR, (b) - BASE_YEAR } static const struct { byte min; byte max; diff --git a/economy.c b/economy.c --- a/economy.c +++ b/economy.c @@ -1482,7 +1482,7 @@ void PlayersMonthlyLoop(void) { PlayersGenStatistics(); - if (_patches.inflation && _cur_year < MAX_YEAR_END) + if (_patches.inflation && BASE_YEAR + _cur_year < MAX_YEAR) AddInflation(); PlayersPayInterest(); // Reset the _current_player flag diff --git a/graph_gui.c b/graph_gui.c --- a/graph_gui.c +++ b/graph_gui.c @@ -151,7 +151,7 @@ x = gw->left + 44; y = gw->top + gw->height + 1; j = gw->month; - k = gw->year + MAX_YEAR_BEGIN_REAL; + k = BASE_YEAR + gw->year; i = gw->num_on_x_axis;assert(i>0); do { SetDParam(2, k); diff --git a/misc_gui.c b/misc_gui.c --- a/misc_gui.c +++ b/misc_gui.c @@ -1677,7 +1677,7 @@ YearMonthDay ymd; ConvertDayToYMD(&ymd, _date); - if ((ymd.year == 0 && p2 == -1) || (ymd.year == 170 && p2 == 1)) return _cur_year; + if ((BASE_YEAR + ymd.year == MIN_YEAR && p2 == -1) || (BASE_YEAR + ymd.year == MAX_YEAR && p2 == 1)) return _cur_year; SetDate(ConvertYMDToDay(_cur_year + p2, ymd.month, ymd.day)); EnginesMonthlyLoop(); diff --git a/network_gui.c b/network_gui.c --- a/network_gui.c +++ b/network_gui.c @@ -876,7 +876,7 @@ DrawStringTruncated(x, y, STR_NETWORK_COMPANY_NAME, 2, trunc_width); y += 10; - SetDParam(0, _network_player_info[nd->company].inaugurated_year + MAX_YEAR_BEGIN_REAL); + SetDParam(0, BASE_YEAR + _network_player_info[nd->company].inaugurated_year); DrawString(x, y, STR_NETWORK_INAUGURATION_YEAR, 2); // inauguration year y += 10; diff --git a/network_server.c b/network_server.c --- a/network_server.c +++ b/network_server.c @@ -1313,8 +1313,8 @@ /* Check if we want to restart the map */ static void NetworkCheckRestartMap(void) { - if (_network_restart_game_year != 0 && _cur_year + MAX_YEAR_BEGIN_REAL >= _network_restart_game_year) { - DEBUG(net, 0)("Auto-restarting map. Year %d reached.", _cur_year + MAX_YEAR_BEGIN_REAL); + if (_network_restart_game_year != 0 && BASE_YEAR + _cur_year >= _network_restart_game_year) { + DEBUG(net, 0)("Auto-restarting map. Year %d reached.", BASE_YEAR + _cur_year); _random_seeds[0][0] = Random(); _random_seeds[0][1] = InteractiveRandom(); diff --git a/oldloader.c b/oldloader.c --- a/oldloader.c +++ b/oldloader.c @@ -995,7 +995,7 @@ p->money64 = p->player_money = p->current_loan = 100000; _player_colors[num] = p->player_color; - p->inaugurated_year = _old_inaugurated_year - MAX_YEAR_BEGIN_REAL; + p->inaugurated_year = _old_inaugurated_year - BASE_YEAR; if (p->location_of_house == 0xFFFF) p->location_of_house = 0; diff --git a/player_gui.c b/player_gui.c --- a/player_gui.c +++ b/player_gui.c @@ -47,7 +47,7 @@ tbl = p->yearly_expenses + 2; do { if (year >= p->inaugurated_year) { - SetDParam(0, year + 1920); + SetDParam(0, BASE_YEAR + year); DrawStringCenterUnderline(x-17, 15, STR_7010, 0); sum = 0; for (i = 0; i != 13; i++) { @@ -537,7 +537,7 @@ w->disabled_state = dis; DrawWindowWidgets(w); - SetDParam(0, p->inaugurated_year + 1920); + SetDParam(0, BASE_YEAR + p->inaugurated_year); DrawString(110, 25, STR_7038_INAUGURATED, 0); DrawPlayerVehiclesAmount(w->window_number); diff --git a/roadveh_gui.c b/roadveh_gui.c --- a/roadveh_gui.c +++ b/roadveh_gui.c @@ -54,7 +54,7 @@ y += 10; /* Design date - Life length */ - SetDParam(0, ymd.year + 1920); + SetDParam(0, BASE_YEAR + ymd.year); SetDParam(1, e->lifelength); DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); y += 10; @@ -216,7 +216,7 @@ DrawRoadVehImage(v, 3, 57, INVALID_VEHICLE); SetDParam(0, GetCustomEngineName(v->engine_type)); - SetDParam(1, 1920 + v->build_year); + SetDParam(1, BASE_YEAR + v->build_year); SetDParam(2, v->value); DrawString(34, 57, STR_9011_BUILT_VALUE, 0); diff --git a/settings.c b/settings.c --- a/settings.c +++ b/settings.c @@ -1206,7 +1206,7 @@ SDTG_BOOL("autoclean_companies", S, 0, _network_autoclean_companies, false, STR_NULL, NULL), SDTG_VAR("autoclean_unprotected",SLE_UINT8, S, 0, _network_autoclean_unprotected,12, 0, 60, STR_NULL, NULL), SDTG_VAR("autoclean_protected", SLE_UINT8, S, 0, _network_autoclean_protected, 36, 0, 180, STR_NULL, NULL), - SDTG_VAR("restart_game_year", SLE_UINT16, S,D0, _network_restart_game_year, 0, MAX_YEAR_BEGIN_REAL, MAX_YEAR_END_REAL, STR_NULL, NULL), + SDTG_VAR("restart_game_year", SLE_UINT16, S,D0, _network_restart_game_year, 0, MIN_YEAR, MAX_YEAR, STR_NULL, NULL), SDTG_END() }; #endif /* ENABLE_NETWORK */ @@ -1320,9 +1320,9 @@ SDT_BOOL(Patches, same_industry_close, 0, 0, false, STR_CONFIG_PATCHES_SAMEINDCLOSE, NULL), SDT_BOOL(Patches, bribe, 0, 0, true, STR_CONFIG_PATCHES_BRIBE, NULL), SDT_VAR(Patches, snow_line_height,SLE_UINT8, 0, 0, 7, 2, 13, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT, NULL), - SDT_VAR(Patches, colored_news_year,SLE_UINT, 0,NC, 2000, MAX_YEAR_BEGIN_REAL, MAX_YEAR_END_REAL, STR_CONFIG_PATCHES_COLORED_NEWS_YEAR,NULL), - SDT_VAR(Patches, starting_year, SLE_UINT, 0,NC, 1950, MAX_YEAR_BEGIN_REAL, MAX_YEAR_END_REAL, STR_CONFIG_PATCHES_STARTING_YEAR,NULL), - SDT_VAR(Patches, ending_year, SLE_UINT,0,NC|NO,2051, MAX_YEAR_BEGIN_REAL, MAX_YEAR_END_REAL, STR_CONFIG_PATCHES_ENDING_YEAR, NULL), + SDT_VAR(Patches, colored_news_year,SLE_UINT, 0,NC, 2000, MIN_YEAR, MAX_YEAR, STR_CONFIG_PATCHES_COLORED_NEWS_YEAR,NULL), + SDT_VAR(Patches, starting_year, SLE_UINT, 0,NC, 1950, MIN_YEAR, MAX_YEAR, STR_CONFIG_PATCHES_STARTING_YEAR,NULL), + SDT_VAR(Patches, ending_year, SLE_UINT,0,NC|NO,2051, MIN_YEAR, MAX_YEAR, STR_CONFIG_PATCHES_ENDING_YEAR, NULL), SDT_BOOL(Patches, smooth_economy, 0, 0, true, STR_CONFIG_PATCHES_SMOOTH_ECONOMY, NULL), SDT_BOOL(Patches, allow_shares, 0, 0, true, STR_CONFIG_PATCHES_ALLOW_SHARES, NULL), diff --git a/settings_gui.c b/settings_gui.c --- a/settings_gui.c +++ b/settings_gui.c @@ -1185,7 +1185,7 @@ WP(w,def_d).data_1 = (1 << (line * 2 + 0)); } else { _custom_currency.to_euro = - clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR_END_REAL); + clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR); WP(w,def_d).data_1 = (1 << (line * 2 + 1)); } } else { // enter text @@ -1237,7 +1237,7 @@ case 4: /* Year to switch to euro */ val = atoi(b); - val = clamp(val, 1999, MAX_YEAR_END_REAL); + val = clamp(val, 1999, MAX_YEAR); if (val == 1999) val = 0; _custom_currency.to_euro = val; break; diff --git a/ship_gui.c b/ship_gui.c --- a/ship_gui.c +++ b/ship_gui.c @@ -54,7 +54,7 @@ /* Design date - Life length */ e = GetEngine(engine_number); ConvertDayToYMD(&ymd, e->intro_date); - SetDParam(0, ymd.year + 1920); + SetDParam(0, BASE_YEAR + ymd.year); SetDParam(1, e->lifelength); DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); y += 10; @@ -212,7 +212,7 @@ DrawShipImage(v, 3, 57, INVALID_VEHICLE); - SetDParam(1, 1920 + v->build_year); + SetDParam(1, BASE_YEAR + v->build_year); SetDParam(0, GetCustomEngineName(v->engine_type)); SetDParam(2, v->value); DrawString(74, 57, STR_9816_BUILT_VALUE, 0); diff --git a/strings.c b/strings.c --- a/strings.c +++ b/strings.c @@ -339,7 +339,7 @@ for (src = GetStringPtr(STR_0162_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} buff[-1] = ' '; - return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL); + return FormatNoCommaNumber(buff, BASE_YEAR + ymd.year); } static char *FormatMonthAndYear(char *buff, uint16 number) @@ -352,7 +352,7 @@ for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} buff[-1] = ' '; - return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL); + return FormatNoCommaNumber(buff, BASE_YEAR + ymd.year); } static char *FormatTinyDate(char *buff, uint16 number) @@ -360,7 +360,7 @@ YearMonthDay ymd; ConvertDayToYMD(&ymd, number); - buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year + MAX_YEAR_BEGIN_REAL); + buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, BASE_YEAR + ymd.year); return buff; } diff --git a/train_gui.c b/train_gui.c --- a/train_gui.c +++ b/train_gui.c @@ -73,7 +73,7 @@ y += 10; /* Design date - Life length */ - SetDParam(0, ymd.year + 1920); + SetDParam(0, BASE_YEAR + ymd.year); SetDParam(1, e->lifelength); DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); y += 10; @@ -1115,7 +1115,7 @@ if (!(rvi->flags & RVI_WAGON)) { SetDParam(0, GetCustomEngineName(v->engine_type)); - SetDParam(1, v->build_year + 1920); + SetDParam(1, BASE_YEAR + v->build_year); SetDParam(2, v->value); DrawString(x, y, STR_882C_BUILT_VALUE, 0x10); } else {