# HG changeset patch # User belugas # Date 2007-12-28 04:20:56 # Node ID 85dbf9d0e1903ed83ed46f3821ad335fa1e4907b # Parent 3983fe61f8f0f3474214aa44d1392dfcdf19a050 (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year. This will not (yet) be true if you are loading a scenario with the "-g" command line option. diff --git a/src/fios.h b/src/fios.h --- a/src/fios.h +++ b/src/fios.h @@ -32,6 +32,14 @@ enum SaveLoadDialogMode{ SLD_NEW_GAME, }; +/* The different types of files been handled by the system */ +enum FileType { + FT_NONE, ///< nothing to do + FT_SAVEGAME, ///< old or new savegame + FT_SCENARIO, ///< old or new scenario + FT_HEIGHTMAP, ///< heightmap file +}; + enum { FIOS_TYPE_DRIVE = 0, FIOS_TYPE_PARENT = 1, @@ -57,6 +65,7 @@ struct FiosItem { /* Deals with the type of the savegame, independent of extension */ struct SmallFiosItem { int mode; ///< savegame/scenario type (old, new) + FileType filetype; ///< what type of file are we dealing with char name[MAX_PATH]; ///< name char title[255]; ///< internal name of the game }; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1671,6 +1671,17 @@ static const WindowDesc _save_dialog_des SaveLoadDlgWndProc, }; +/** These values are used to convert the file/operations mode into a corresponding file type. + * So each entry, as expressed by the related comment, is based on the enum */ +static const FileType _file_modetotype[] = { + FT_SAVEGAME, ///< used for SLD_LOAD_GAME + FT_SCENARIO, ///< used for SLD_LOAD_SCENARIO + FT_SAVEGAME, ///< used for SLD_SAVE_GAME + FT_SCENARIO, ///< used for SLD_SAVE_SCENARIO + FT_HEIGHTMAP, ///< used for SLD_LOAD_HEIGHTMAP + FT_SAVEGAME, ///< SLD_NEW_GAME +}; + void ShowSaveLoadDialog(SaveLoadDialogMode mode) { static const StringID saveload_captions[] = { @@ -1692,6 +1703,9 @@ void ShowSaveLoadDialog(SaveLoadDialogMo _saveload_mode = mode; SetBit(_no_scroll, SCROLL_SAVE); + /* Use an array to define what will be the current file type being handled + * by current file mode */ + _file_to_saveload.filetype = _file_modetotype[mode]; switch (mode) { case SLD_SAVE_GAME: GenerateFileName(); break; case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -810,6 +810,7 @@ static void NetworkStartServerWindowWndP char *name = FiosBrowseTo(nd->map); if (name != NULL) { SetFiosType(nd->map->type); + _file_to_saveload.filetype = FT_SCENARIO; ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name)); ttd_strlcpy(_file_to_saveload.title, nd->map->title, sizeof(_file_to_saveload.title)); diff --git a/src/openttd.cpp b/src/openttd.cpp --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1289,7 +1289,15 @@ static bool InitializeWindowsAndCaches() Player *players[MAX_PLAYERS]; const Vehicle *v; - for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) players[i] = GetPlayer(i); + for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { + players[i] = GetPlayer(i); + + /* For each player, verify (while loading a scenario) that the inauguration date is the current year and set it + * accordingly if it is not the case. No need to set it on players that are not been used already, + * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */ + if (_file_to_saveload.filetype == FT_SCENARIO && players[i]->inaugurated_year != MIN_YEAR) + players[i]->inaugurated_year = _cur_year; + } FOR_ALL_VEHICLES(v) { if (!IsEngineCountable(v)) continue;