summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2007-12-28 04:20:56 +0000
committerbelugas <belugas@openttd.org>2007-12-28 04:20:56 +0000
commit1b76c8bb67baeb0b36eb9b845722925f02a74779 (patch)
tree3e955cb6c9b2d6c09572877bb7dfe3a00eb7a9cc
parentdb45093f7b11e4ac8327c78f460a89dda0331954 (diff)
downloadopenttd-1b76c8bb67baeb0b36eb9b845722925f02a74779.tar.xz
(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.
-rw-r--r--src/fios.h9
-rw-r--r--src/misc_gui.cpp14
-rw-r--r--src/network/network_gui.cpp1
-rw-r--r--src/openttd.cpp10
4 files changed, 33 insertions, 1 deletions
diff --git a/src/fios.h b/src/fios.h
index f6d7f3e59..016f43c4a 100644
--- 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
index 606ff4499..679cefe42 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -1671,6 +1671,17 @@ static const WindowDesc _save_dialog_desc = {
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(SaveLoadDialogMode mode)
_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
index cd550ee5d..869ae876a 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -810,6 +810,7 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
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
index fad4bf800..1bdb75a6b 100644
--- 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;