1
0
Fork 0

(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.
release/0.5
rubidium 2006-08-15 15:18:03 +00:00
parent 8aa76f306d
commit 0d3ccad29f
19 changed files with 38 additions and 38 deletions

View File

@ -66,7 +66,7 @@ void DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number)
y += 10; y += 10;
/* Design date - Life length */ /* Design date - Life length */
SetDParam(0, ymd.year + 1920); SetDParam(0, BASE_YEAR + ymd.year);
SetDParam(1, e->lifelength); SetDParam(1, e->lifelength);
DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
y += 10; y += 10;
@ -402,7 +402,7 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
do { do {
if (v->subtype <= 2) { if (v->subtype <= 2) {
SetDParam(0, GetCustomEngineName(v->engine_type)); SetDParam(0, GetCustomEngineName(v->engine_type));
SetDParam(1, 1920 + v->build_year); SetDParam(1, BASE_YEAR + v->build_year);
SetDParam(2, v->value); SetDParam(2, v->value);
DrawString(60, y, STR_A011_BUILT_VALUE, 0); DrawString(60, y, STR_A011_BUILT_VALUE, 0);
y += 10; y += 10;

View File

@ -1174,7 +1174,7 @@ DEF_CONSOLE_CMD(ConPlayers)
GetString(buffer, STR_00D1_DARK_BLUE + _player_colors[p->index]); 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)", 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], /* 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], /* 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], /* planes */ _network_player_info[p->index].num_vehicle[3],

View File

@ -81,8 +81,8 @@ uint GetMaskOfAllowedCurrencies(void)
for (i = 0; i != lengthof(_currency_specs); i++) { for (i = 0; i != lengthof(_currency_specs); i++) {
uint16 to_euro = _currency_specs[i].to_euro; 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_NOEURO && to_euro != CF_ISEURO && BASE_YEAR + _cur_year >= to_euro) continue;
if (to_euro == CF_ISEURO && _cur_year < 2000 - MAX_YEAR_BEGIN_REAL) continue; if (to_euro == CF_ISEURO && BASE_YEAR + _cur_year < 2000) continue;
mask |= (1 << i); mask |= (1 << i);
} }
mask |= (1 << CUSTOM_CURRENCY_ID); // always allow custom currency mask |= (1 << CUSTOM_CURRENCY_ID); // always allow custom currency
@ -94,7 +94,7 @@ void CheckSwitchToEuro(void)
{ {
if (_currency_specs[_opt.currency].to_euro != CF_NOEURO && if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
_currency_specs[_opt.currency].to_euro != CF_ISEURO && _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. _opt.currency = 2; // this is the index of euro above.
AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL, 0, NT_ECONOMY, 0), 0, 0); AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL, 0, NT_ECONOMY, 0), 0, 0);
} }

8
date.c
View File

@ -129,7 +129,7 @@ Date ConvertIntDate(uint date)
Month month = 0; Month month = 0;
Day day = 1; 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; year = date - 1920;
} else if (IS_INT_INSIDE(date, 192001, 209012 + 1)) { } else if (IS_INT_INSIDE(date, 192001, 209012 + 1)) {
month = date % 100 - 1; month = date % 100 - 1;
@ -282,13 +282,13 @@ void IncreaseDate(void)
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
/* check if we reached end of the game */ /* 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(); ShowEndGameChart();
/* check if we reached the maximum year, decrement dates by a year */ /* 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; Vehicle *v;
_cur_year = MAX_YEAR_END; _cur_year--;
_date -= 365; _date -= 365;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
v->date_of_last_service -= 365; v->date_of_last_service -= 365;

6
date.h
View File

@ -8,9 +8,9 @@
*/ */
#define DAY_TICKS 74 #define DAY_TICKS 74
#define MAX_YEAR_BEGIN_REAL 1920 #define BASE_YEAR 1920
#define MAX_YEAR_END_REAL 2090 #define MIN_YEAR 1920
#define MAX_YEAR_END 170 #define MAX_YEAR 2090
/* Year and Date are defined elsewhere */ /* Year and Date are defined elsewhere */
typedef uint8 Month; typedef uint8 Month;

View File

@ -951,7 +951,7 @@ static DisasterInitProc * const _disaster_initprocs[] = {
Disaster7_Init, 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 { static const struct {
byte min; byte min;
byte max; byte max;

View File

@ -1482,7 +1482,7 @@ int LoadUnloadVehicle(Vehicle *v)
void PlayersMonthlyLoop(void) void PlayersMonthlyLoop(void)
{ {
PlayersGenStatistics(); PlayersGenStatistics();
if (_patches.inflation && _cur_year < MAX_YEAR_END) if (_patches.inflation && BASE_YEAR + _cur_year < MAX_YEAR)
AddInflation(); AddInflation();
PlayersPayInterest(); PlayersPayInterest();
// Reset the _current_player flag // Reset the _current_player flag

View File

@ -151,7 +151,7 @@ static void DrawGraph(const GraphDrawer *gw)
x = gw->left + 44; x = gw->left + 44;
y = gw->top + gw->height + 1; y = gw->top + gw->height + 1;
j = gw->month; j = gw->month;
k = gw->year + MAX_YEAR_BEGIN_REAL; k = BASE_YEAR + gw->year;
i = gw->num_on_x_axis;assert(i>0); i = gw->num_on_x_axis;assert(i>0);
do { do {
SetDParam(2, k); SetDParam(2, k);

View File

@ -1677,7 +1677,7 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2)
YearMonthDay ymd; YearMonthDay ymd;
ConvertDayToYMD(&ymd, _date); 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)); SetDate(ConvertYMDToDay(_cur_year + p2, ymd.month, ymd.day));
EnginesMonthlyLoop(); EnginesMonthlyLoop();

View File

@ -876,7 +876,7 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
DrawStringTruncated(x, y, STR_NETWORK_COMPANY_NAME, 2, trunc_width); DrawStringTruncated(x, y, STR_NETWORK_COMPANY_NAME, 2, trunc_width);
y += 10; 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 DrawString(x, y, STR_NETWORK_INAUGURATION_YEAR, 2); // inauguration year
y += 10; y += 10;

View File

@ -1313,8 +1313,8 @@ extern void SwitchMode(int new_mode);
/* Check if we want to restart the map */ /* Check if we want to restart the map */
static void NetworkCheckRestartMap(void) static void NetworkCheckRestartMap(void)
{ {
if (_network_restart_game_year != 0 && _cur_year + MAX_YEAR_BEGIN_REAL >= _network_restart_game_year) { if (_network_restart_game_year != 0 && BASE_YEAR + _cur_year >= _network_restart_game_year) {
DEBUG(net, 0)("Auto-restarting map. Year %d reached.", _cur_year + MAX_YEAR_BEGIN_REAL); DEBUG(net, 0)("Auto-restarting map. Year %d reached.", BASE_YEAR + _cur_year);
_random_seeds[0][0] = Random(); _random_seeds[0][0] = Random();
_random_seeds[0][1] = InteractiveRandom(); _random_seeds[0][1] = InteractiveRandom();

View File

@ -995,7 +995,7 @@ static bool LoadOldPlayer(LoadgameState *ls, int num)
p->money64 = p->player_money = p->current_loan = 100000; p->money64 = p->player_money = p->current_loan = 100000;
_player_colors[num] = p->player_color; _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) if (p->location_of_house == 0xFFFF)
p->location_of_house = 0; p->location_of_house = 0;

View File

@ -47,7 +47,7 @@ static void DrawPlayerEconomyStats(const Player *p, byte mode)
tbl = p->yearly_expenses + 2; tbl = p->yearly_expenses + 2;
do { do {
if (year >= p->inaugurated_year) { if (year >= p->inaugurated_year) {
SetDParam(0, year + 1920); SetDParam(0, BASE_YEAR + year);
DrawStringCenterUnderline(x-17, 15, STR_7010, 0); DrawStringCenterUnderline(x-17, 15, STR_7010, 0);
sum = 0; sum = 0;
for (i = 0; i != 13; i++) { for (i = 0; i != 13; i++) {
@ -537,7 +537,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
w->disabled_state = dis; w->disabled_state = dis;
DrawWindowWidgets(w); DrawWindowWidgets(w);
SetDParam(0, p->inaugurated_year + 1920); SetDParam(0, BASE_YEAR + p->inaugurated_year);
DrawString(110, 25, STR_7038_INAUGURATED, 0); DrawString(110, 25, STR_7038_INAUGURATED, 0);
DrawPlayerVehiclesAmount(w->window_number); DrawPlayerVehiclesAmount(w->window_number);

View File

@ -54,7 +54,7 @@ void DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number)
y += 10; y += 10;
/* Design date - Life length */ /* Design date - Life length */
SetDParam(0, ymd.year + 1920); SetDParam(0, BASE_YEAR + ymd.year);
SetDParam(1, e->lifelength); SetDParam(1, e->lifelength);
DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
y += 10; y += 10;
@ -216,7 +216,7 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e)
DrawRoadVehImage(v, 3, 57, INVALID_VEHICLE); DrawRoadVehImage(v, 3, 57, INVALID_VEHICLE);
SetDParam(0, GetCustomEngineName(v->engine_type)); SetDParam(0, GetCustomEngineName(v->engine_type));
SetDParam(1, 1920 + v->build_year); SetDParam(1, BASE_YEAR + v->build_year);
SetDParam(2, v->value); SetDParam(2, v->value);
DrawString(34, 57, STR_9011_BUILT_VALUE, 0); DrawString(34, 57, STR_9011_BUILT_VALUE, 0);

View File

@ -1206,7 +1206,7 @@ static const SettingDescGlobVarList _network_settings[] = {
SDTG_BOOL("autoclean_companies", S, 0, _network_autoclean_companies, false, STR_NULL, NULL), 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_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("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() SDTG_END()
}; };
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
@ -1320,9 +1320,9 @@ const SettingDesc _patch_settings[] = {
SDT_BOOL(Patches, same_industry_close, 0, 0, false, STR_CONFIG_PATCHES_SAMEINDCLOSE, NULL), 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_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, 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, 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, MAX_YEAR_BEGIN_REAL, MAX_YEAR_END_REAL, STR_CONFIG_PATCHES_STARTING_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, MAX_YEAR_BEGIN_REAL, MAX_YEAR_END_REAL, STR_CONFIG_PATCHES_ENDING_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, 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), SDT_BOOL(Patches, allow_shares, 0, 0, true, STR_CONFIG_PATCHES_ALLOW_SHARES, NULL),

View File

@ -1185,7 +1185,7 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
WP(w,def_d).data_1 = (1 << (line * 2 + 0)); WP(w,def_d).data_1 = (1 << (line * 2 + 0));
} else { } else {
_custom_currency.to_euro = _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)); WP(w,def_d).data_1 = (1 << (line * 2 + 1));
} }
} else { // enter text } else { // enter text
@ -1237,7 +1237,7 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
case 4: /* Year to switch to euro */ case 4: /* Year to switch to euro */
val = atoi(b); val = atoi(b);
val = clamp(val, 1999, MAX_YEAR_END_REAL); val = clamp(val, 1999, MAX_YEAR);
if (val == 1999) val = 0; if (val == 1999) val = 0;
_custom_currency.to_euro = val; _custom_currency.to_euro = val;
break; break;

View File

@ -54,7 +54,7 @@ void DrawShipPurchaseInfo(int x, int y, EngineID engine_number)
/* Design date - Life length */ /* Design date - Life length */
e = GetEngine(engine_number); e = GetEngine(engine_number);
ConvertDayToYMD(&ymd, e->intro_date); ConvertDayToYMD(&ymd, e->intro_date);
SetDParam(0, ymd.year + 1920); SetDParam(0, BASE_YEAR + ymd.year);
SetDParam(1, e->lifelength); SetDParam(1, e->lifelength);
DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
y += 10; y += 10;
@ -212,7 +212,7 @@ static void ShipDetailsWndProc(Window *w, WindowEvent *e)
DrawShipImage(v, 3, 57, INVALID_VEHICLE); 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(0, GetCustomEngineName(v->engine_type));
SetDParam(2, v->value); SetDParam(2, v->value);
DrawString(74, 57, STR_9816_BUILT_VALUE, 0); DrawString(74, 57, STR_9816_BUILT_VALUE, 0);

View File

@ -339,7 +339,7 @@ static char *FormatYmdString(char *buff, uint16 number)
for (src = GetStringPtr(STR_0162_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} for (src = GetStringPtr(STR_0162_JAN + ymd.month); (*buff++ = *src++) != '\0';) {}
buff[-1] = ' '; 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) static char *FormatMonthAndYear(char *buff, uint16 number)
@ -352,7 +352,7 @@ static char *FormatMonthAndYear(char *buff, uint16 number)
for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {}
buff[-1] = ' '; 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) static char *FormatTinyDate(char *buff, uint16 number)
@ -360,7 +360,7 @@ static char *FormatTinyDate(char *buff, uint16 number)
YearMonthDay ymd; YearMonthDay ymd;
ConvertDayToYMD(&ymd, number); 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; return buff;
} }

View File

@ -73,7 +73,7 @@ void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number)
y += 10; y += 10;
/* Design date - Life length */ /* Design date - Life length */
SetDParam(0, ymd.year + 1920); SetDParam(0, BASE_YEAR + ymd.year);
SetDParam(1, e->lifelength); SetDParam(1, e->lifelength);
DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
y += 10; y += 10;
@ -1115,7 +1115,7 @@ static void TrainDetailsInfoTab(const Vehicle *v, int x, int y)
if (!(rvi->flags & RVI_WAGON)) { if (!(rvi->flags & RVI_WAGON)) {
SetDParam(0, GetCustomEngineName(v->engine_type)); SetDParam(0, GetCustomEngineName(v->engine_type));
SetDParam(1, v->build_year + 1920); SetDParam(1, BASE_YEAR + v->build_year);
SetDParam(2, v->value); SetDParam(2, v->value);
DrawString(x, y, STR_882C_BUILT_VALUE, 0x10); DrawString(x, y, STR_882C_BUILT_VALUE, 0x10);
} else { } else {