(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.

This commit is contained in:
darkvater 2005-01-10 14:43:00 +00:00
parent fae367ab31
commit 29b4ab04c3
10 changed files with 22 additions and 19 deletions

View File

@ -26,8 +26,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 (i == 23) mask |= (1 << 23); // always allow custom currency 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 (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= (to_euro-MAX_YEAR_BEGIN_REAL)) continue;
if (_cur_year < (2000-1920) && (to_euro == CF_ISEURO)) continue; if (_cur_year < (2000-MAX_YEAR_BEGIN_REAL) && (to_euro == CF_ISEURO)) continue;
mask |= (1 << i); mask |= (1 << i);
} }
return mask; return mask;
@ -37,7 +37,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 &&
_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. _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);
} }

View File

@ -142,7 +142,7 @@ static void DrawGraph(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 + 1920; k = gw->year + MAX_YEAR_BEGIN_REAL;
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

@ -25,7 +25,7 @@
/* Min/Max date for scenario editor */ /* 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 static const uint MaxDate = 29220; // 2000-01-01
extern void DoTestSave(); extern void DoTestSave();

10
misc.c
View File

@ -443,7 +443,7 @@ uint ConvertYMDToDay(uint year, uint month, uint day)
} }
// convert a date on the form // convert a date on the form
// 1920 - 2090 // 1920 - 2090 (MAX_YEAR_END_REAL)
// 192001 - 209012 // 192001 - 209012
// 19200101 - 20901231 // 19200101 - 20901231
// or if > 2090 and below 65536, treat it as a daycount // or if > 2090 and below 65536, treat it as a daycount
@ -452,7 +452,7 @@ uint ConvertIntDate(uint date)
{ {
uint year, month = 0, day = 1; 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; 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;
@ -700,10 +700,10 @@ void IncreaseDate()
NetworkServerYearlyLoop(); NetworkServerYearlyLoop();
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
/* check if we reached 2090, that's the maximum year. */ /* check if we reached 2090 (MAX_YEAR_END_REAL), that's the maximum year. */
if (_cur_year == 171) { if (_cur_year == (MAX_YEAR_END + 1)) {
Vehicle *v; Vehicle *v;
_cur_year = 170; _cur_year = MAX_YEAR_END;
_date = 62093; _date = 62093;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
v->date_of_last_service -= 365; // 1 year is 365 days long v->date_of_last_service -= 365; // 1 year is 365 days long

View File

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

View File

@ -1281,10 +1281,10 @@ 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() 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; _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][0] = Random();
_random_seeds[0][1] = InteractiveRandom(); _random_seeds[0][1] = InteractiveRandom();

View File

@ -941,7 +941,7 @@ static void FixPlayer(Player *n, OldPlayer *o, int num, byte town_name_type)
FixEconomy(&n->cur_economy, &o->economy[0]); FixEconomy(&n->cur_economy, &o->economy[0]);
for(i=0; i!=24; i++) FixEconomy(&n->old_economy[i], &o->economy[i+1]); 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->last_build_coordinate = o->last_build_coordinate;
n->num_valid_stat_ent = o->num_valid_stat_ent; n->num_valid_stat_ent = o->num_valid_stat_ent;

View File

@ -682,7 +682,7 @@ static const PatchEntry _patches_economy[] = {
{PE_UINT8, 0, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT, "snow_line_height", &_patches.snow_line_height, 2, 13, 1, NULL}, {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_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_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}, {PE_BOOL, 0, STR_CONFIG_PATCHES_ALLOW_SHARES, "allow_shares", &_patches.allow_shares, 0, 0, 0, NULL},
@ -1403,7 +1403,7 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
} else { } else {
if(_currency_specs[23].to_euro == 0) _currency_specs[23].to_euro = 2000; if(_currency_specs[23].to_euro == 0) _currency_specs[23].to_euro = 2000;
else _currency_specs[23].to_euro++; 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)); WP(w,def_d).data_1 = (1 << (line * 2 + 1));
} }
} else { // enter text } else { // enter text
@ -1452,7 +1452,7 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
break; break;
case 4: case 4:
val = atoi(b); val = atoi(b);
val = clamp(val, 1999, 2090); val = clamp(val, 1999, MAX_YEAR_END_REAL);
if (val == 1999) val = 0; if (val == 1999) val = 0;
_currency_specs[23].to_euro = val; _currency_specs[23].to_euro = val;
break; break;

View File

@ -243,7 +243,7 @@ static byte *FormatYmdString(byte *buff, uint16 number)
memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4); memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4);
buff[3] = ' '; 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) static byte *FormatMonthAndYear(byte *buff, uint16 number)
@ -256,7 +256,7 @@ static byte *FormatMonthAndYear(byte *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 + 1920); return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL);
} }
uint GetCurrentCurrencyRate() { uint GetCurrentCurrencyRate() {

3
ttd.h
View File

@ -42,6 +42,9 @@ typedef struct YearMonthDay {
* * 1 day is thus about 2 seconds (74*27 = 1998) on a machine that can run OpenTTD normally * * 1 day is thus about 2 seconds (74*27 = 1998) on a machine that can run OpenTTD normally
*/ */
#define DAY_TICKS 74 #define DAY_TICKS 74
#define MAX_YEAR_BEGIN_REAL 1920
#define MAX_YEAR_END_REAL 2090
#define MAX_YEAR_END 170
#include "macros.h" #include "macros.h"