(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
authordarkvater
Mon, 10 Jan 2005 14:43:00 +0000
changeset 970 24abd02b1092
parent 969 862685f513ca
child 971 374251680a61
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
economy.c
graph_gui.c
main_gui.c
misc.c
network_gui.c
network_server.c
oldloader.c
settings_gui.c
strings.c
ttd.h
--- a/economy.c	Mon Jan 10 14:36:08 2005 +0000
+++ b/economy.c	Mon Jan 10 14:43:00 2005 +0000
@@ -26,8 +26,8 @@
 	for (i = 0; i != lengthof(_currency_specs); i++) {
 		uint16 to_euro = _currency_specs[i].to_euro;
 		if (i == 23) mask |= (1 << 23); // always allow custom currency
-		if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= (to_euro-1920)) continue;
-		if (_cur_year < (2000-1920) && (to_euro == CF_ISEURO)) continue;
+		if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= (to_euro-MAX_YEAR_BEGIN_REAL)) continue;
+		if (_cur_year < (2000-MAX_YEAR_BEGIN_REAL) && (to_euro == CF_ISEURO)) continue;
 		mask |= (1 << i);
 	}
 	return mask;
@@ -37,7 +37,7 @@
 {
 	if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
 			_currency_specs[_opt.currency].to_euro != CF_ISEURO &&
-			_cur_year >= (_currency_specs[_opt.currency].to_euro-1920)) {
+			_cur_year >= (_currency_specs[_opt.currency].to_euro-MAX_YEAR_BEGIN_REAL)) {
 		_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/graph_gui.c	Mon Jan 10 14:36:08 2005 +0000
+++ b/graph_gui.c	Mon Jan 10 14:43:00 2005 +0000
@@ -142,7 +142,7 @@
 		x = gw->left + 44;
 		y = gw->top + gw->height + 1;
 		j = gw->month;
-		k = gw->year + 1920;
+		k = gw->year + MAX_YEAR_BEGIN_REAL;
 		i = gw->num_on_x_axis;assert(i>0);
 		do {
 			SetDParam(2, k);
--- a/main_gui.c	Mon Jan 10 14:36:08 2005 +0000
+++ b/main_gui.c	Mon Jan 10 14:43:00 2005 +0000
@@ -25,7 +25,7 @@
 
 
 /* Min/Max date for scenario editor */
-static const uint MinDate = 0;     // 1920-01-01
+static const uint MinDate = 0;     // 1920-01-01 (MAX_YEAR_BEGIN_REAL)
 static const uint MaxDate = 29220; // 2000-01-01
 
 extern void DoTestSave();
--- a/misc.c	Mon Jan 10 14:36:08 2005 +0000
+++ b/misc.c	Mon Jan 10 14:43:00 2005 +0000
@@ -443,7 +443,7 @@
 }
 
 // convert a date on the form
-// 1920 - 2090
+// 1920 - 2090 (MAX_YEAR_END_REAL)
 // 192001 - 209012
 // 19200101 - 20901231
 // or if > 2090 and below 65536, treat it as a daycount
@@ -452,7 +452,7 @@
 {
 	uint year, month = 0, day = 1;
 
-	if (IS_INT_INSIDE(date, 1920, 2090 + 1)) {
+	if (IS_INT_INSIDE(date, 1920, MAX_YEAR_END_REAL + 1)) {
 		year = date - 1920;
 	} else if (IS_INT_INSIDE(date, 192001, 209012+1)) {
 		month = date % 100 - 1;
@@ -700,10 +700,10 @@
 		NetworkServerYearlyLoop();
 #endif /* ENABLE_NETWORK */
 
-	/* check if we reached 2090, that's the maximum year. */
-	if (_cur_year == 171) {
+	/* check if we reached 2090 (MAX_YEAR_END_REAL), that's the maximum year. */
+	if (_cur_year == (MAX_YEAR_END + 1)) {
 		Vehicle *v;
-		_cur_year = 170;
+		_cur_year = MAX_YEAR_END;
 		_date = 62093;
 		FOR_ALL_VEHICLES(v) {
 			v->date_of_last_service -= 365; // 1 year is 365 days long
--- a/network_gui.c	Mon Jan 10 14:36:08 2005 +0000
+++ b/network_gui.c	Mon Jan 10 14:43:00 2005 +0000
@@ -746,7 +746,7 @@
 			DeleteName(str);
 			y += 10;
 
-			SetDParam(0, _network_player_info[_selected_company_item].inaugurated_year + 1920);
+			SetDParam(0, _network_player_info[_selected_company_item].inaugurated_year + MAX_YEAR_BEGIN_REAL);
 			DrawString(x, y, STR_NETWORK_INAUGURATION_YEAR, 2); // inauguration year
 			y += 10;
 
--- a/network_server.c	Mon Jan 10 14:36:08 2005 +0000
+++ b/network_server.c	Mon Jan 10 14:43:00 2005 +0000
@@ -1281,10 +1281,10 @@
 /* Check if we want to restart the map */
 static void NetworkCheckRestartMap()
 {
-	if (_network_restart_game_date != 0 && _cur_year + 1920 >= _network_restart_game_date) {
+	if (_network_restart_game_date != 0 && _cur_year + MAX_YEAR_BEGIN_REAL >= _network_restart_game_date) {
 		_docommand_recursive = 0;
 
-		DEBUG(net, 0)("Auto-restarting map. Year %d reached.", _cur_year + 1920);
+		DEBUG(net, 0)("Auto-restarting map. Year %d reached.", _cur_year + MAX_YEAR_BEGIN_REAL);
 
 		_random_seeds[0][0] = Random();
 		_random_seeds[0][1] = InteractiveRandom();
--- a/oldloader.c	Mon Jan 10 14:36:08 2005 +0000
+++ b/oldloader.c	Mon Jan 10 14:43:00 2005 +0000
@@ -941,7 +941,7 @@
 
 		FixEconomy(&n->cur_economy, &o->economy[0]);
 		for(i=0; i!=24; i++) FixEconomy(&n->old_economy[i], &o->economy[i+1]);
-		n->inaugurated_year = o->inaugurated_date - 1920;
+		n->inaugurated_year = o->inaugurated_date - MAX_YEAR_BEGIN_REAL;
 		n->last_build_coordinate = o->last_build_coordinate;
 		n->num_valid_stat_ent = o->num_valid_stat_ent;
 
--- a/settings_gui.c	Mon Jan 10 14:36:08 2005 +0000
+++ b/settings_gui.c	Mon Jan 10 14:43:00 2005 +0000
@@ -682,7 +682,7 @@
 	{PE_UINT8,	0, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT,	"snow_line_height", &_patches.snow_line_height,					2, 13,  1, NULL},
 
 	{PE_INT32,	PF_NOCOMMA, STR_CONFIG_PATCHES_COLORED_NEWS_DATE, "colored_new_data", &_patches.colored_news_date, 1900, 2200, 5, NULL},
-	{PE_INT32,	PF_NOCOMMA, STR_CONFIG_PATCHES_STARTING_DATE, "starting_date", &_patches.starting_date,	 1920,2100, 1, NULL},
+	{PE_INT32,	PF_NOCOMMA, STR_CONFIG_PATCHES_STARTING_DATE, "starting_date", &_patches.starting_date,	 1920, MAX_YEAR_END_REAL, 1, NULL},
 
 	{PE_BOOL,		0, STR_CONFIG_PATCHES_SMOOTH_ECONOMY,		"smooth_economy", &_patches.smooth_economy,						0,  0,  0, NULL},
 	{PE_BOOL,		0, STR_CONFIG_PATCHES_ALLOW_SHARES,			"allow_shares", &_patches.allow_shares,						0,  0,  0, NULL},
@@ -1403,7 +1403,7 @@
 					} else {
 						if(_currency_specs[23].to_euro == 0) _currency_specs[23].to_euro = 2000;
 						else _currency_specs[23].to_euro++;
-						_currency_specs[23].to_euro = min(2090, _currency_specs[23].to_euro);
+						_currency_specs[23].to_euro = min(MAX_YEAR_END_REAL, _currency_specs[23].to_euro);
 						WP(w,def_d).data_1 = (1 << (line * 2 + 1));
 					}
 				} else { // enter text
@@ -1452,7 +1452,7 @@
 				break;
 				case 4:
 					val = atoi(b);
-					val = clamp(val, 1999, 2090);
+					val = clamp(val, 1999, MAX_YEAR_END_REAL);
 					if (val == 1999) val = 0;
 					_currency_specs[23].to_euro = val;
 				break;
--- a/strings.c	Mon Jan 10 14:36:08 2005 +0000
+++ b/strings.c	Mon Jan 10 14:43:00 2005 +0000
@@ -243,7 +243,7 @@
 	memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4);
 	buff[3] = ' ';
 
-	return FormatNoCommaNumber(buff+4, ymd.year + 1920);
+	return FormatNoCommaNumber(buff+4, ymd.year + MAX_YEAR_BEGIN_REAL);
 }
 
 static byte *FormatMonthAndYear(byte *buff, uint16 number)
@@ -256,7 +256,7 @@
 	for(src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++=*src++) != 0;) {}
 	buff[-1] = ' ';
 
-	return FormatNoCommaNumber(buff, ymd.year + 1920);
+	return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL);
 }
 
 uint GetCurrentCurrencyRate() {
--- a/ttd.h	Mon Jan 10 14:36:08 2005 +0000
+++ b/ttd.h	Mon Jan 10 14:43:00 2005 +0000
@@ -42,6 +42,9 @@
 * * 1 day is thus about 2 seconds (74*27 = 1998) on a machine that can run OpenTTD normally
 */
 #define DAY_TICKS 74
+#define MAX_YEAR_BEGIN_REAL 1920
+#define MAX_YEAR_END_REAL 2090
+#define MAX_YEAR_END 170
 
 #include "macros.h"