(svn r5916) -Cleanup: use MIN_YEAR/MAX_YEAR for the year boundaries and BASE_YEAR when comparing _cur_year with a 'full' year.
authorrubidium
Tue, 15 Aug 2006 15:18:03 +0000
changeset 4286 a040bf5c203d
parent 4285 72b3f7d6c891
child 4287 27182ee2e707
(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.
aircraft_gui.c
console_cmds.c
currency.c
date.c
date.h
disaster_cmd.c
economy.c
graph_gui.c
misc_gui.c
network_gui.c
network_server.c
oldloader.c
player_gui.c
roadveh_gui.c
settings.c
settings_gui.c
ship_gui.c
strings.c
train_gui.c
--- a/aircraft_gui.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/aircraft_gui.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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;
--- a/console_cmds.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/console_cmds.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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],
--- a/currency.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/currency.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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);
 	}
--- a/date.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/date.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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;
--- a/date.h	Tue Aug 15 14:52:17 2006 +0000
+++ b/date.h	Tue Aug 15 15:18:03 2006 +0000
@@ -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;
--- a/disaster_cmd.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/disaster_cmd.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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;
--- a/economy.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/economy.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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
--- a/graph_gui.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/graph_gui.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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);
--- a/misc_gui.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/misc_gui.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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();
--- a/network_gui.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/network_gui.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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;
 
--- a/network_server.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/network_server.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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();
--- a/oldloader.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/oldloader.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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;
 
--- a/player_gui.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/player_gui.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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);
--- a/roadveh_gui.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/roadveh_gui.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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);
 
--- a/settings.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/settings.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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),
 
--- a/settings_gui.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/settings_gui.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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;
--- a/ship_gui.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/ship_gui.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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);
--- a/strings.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/strings.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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;
 }
--- a/train_gui.c	Tue Aug 15 14:52:17 2006 +0000
+++ b/train_gui.c	Tue Aug 15 15:18:03 2006 +0000
@@ -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 {