changeset 12645:b9f1e5ce4831 draft

(svn r17097) -Fix [FS#3092] (r13256): make restart command work again and make the help show how it works and how it doesn't work
author rubidium <rubidium@openttd.org>
date Thu, 06 Aug 2009 22:00:32 +0000
parents 82a22ae11c24
children b37b292d0726
files src/console_cmds.cpp src/genworld.cpp src/genworld.h src/misc.cpp src/openttd.cpp src/openttd.h src/saveload/saveload.cpp
diffstat 7 files changed, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -952,13 +952,16 @@
 	if (argc == 0) {
 		IConsoleHelp("Restart game. Usage: 'restart'");
 		IConsoleHelp("Restarts a game. It tries to reproduce the exact same map as the game started with.");
+		IConsoleHelp("However:");
+		IConsoleHelp(" * restarting games started in another version might create another map due to difference in map generation");
+		IConsoleHelp(" * restarting games based on scenarios, loaded games or heightmaps will start a new game based on the settings stored in the scenario/savegame");
 		return true;
 	}
 
 	/* Don't copy the _newgame pointers to the real pointers, so call SwitchToMode directly */
 	_settings_game.game_creation.map_x = MapLogX();
 	_settings_game.game_creation.map_y = FindFirstBit(MapSizeY());
-	SwitchToMode(SM_NEWGAME);
+	SwitchToMode(SM_RESTARTGAME);
 	return true;
 }
 
--- a/src/genworld.cpp
+++ b/src/genworld.cpp
@@ -39,7 +39,7 @@
 void StartupCompanies();
 void StartupDisasters();
 
-void InitializeGame(uint size_x, uint size_y, bool reset_date);
+void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings);
 
 /* Please only use this variable in genworld.h and genworld.c and
  *  nowhere else. For speed improvements we need it to be global, but
@@ -256,7 +256,7 @@
  * @param size_x The X-size of the map.
  * @param size_y The Y-size of the map.
  */
-void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y)
+void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y, bool reset_settings)
 {
 	if (_gw.active) return;
 	_gw.mode   = mode;
@@ -281,7 +281,7 @@
 	GfxLoadSprites();
 	LoadStringWidthTable();
 
-	InitializeGame(_gw.size_x, _gw.size_y, false);
+	InitializeGame(_gw.size_x, _gw.size_y, false, reset_settings);
 	PrepareGenerateWorldProgress();
 
 	/* Re-init the windowing system */
--- a/src/genworld.h
+++ b/src/genworld.h
@@ -74,7 +74,7 @@
 void GenerateWorldSetCallback(gw_done_proc *proc);
 void GenerateWorldSetAbortCallback(gw_abort_proc *proc);
 void WaitTillGeneratedWorld();
-void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y);
+void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y, bool reset_settings = true);
 void AbortGeneratingWorld();
 bool IsGeneratingWorldAborted();
 void HandleGeneratingWorldAbortion();
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -52,7 +52,7 @@
 void InitializeNPF();
 void InitializeOldNames();
 
-void InitializeGame(uint size_x, uint size_y, bool reset_date)
+void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings)
 {
 	/* Make sure there isn't any window that can influence anything
 	 * related to the new game we're about to start/load. */
@@ -69,7 +69,7 @@
 	_date_fract = 0;
 	_cur_tileloop_tile = 0;
 	_thd.redsq = INVALID_TILE;
-	MakeNewgameSettingsLive();
+	if (reset_settings) MakeNewgameSettingsLive();
 
 	if (reset_date) {
 		SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -796,7 +796,7 @@
 	MarkWholeScreenDirty();
 }
 
-static void MakeNewGame(bool from_heightmap)
+static void MakeNewGame(bool from_heightmap, bool reset_settings)
 {
 	_game_mode = GM_NORMAL;
 
@@ -807,7 +807,7 @@
 	_industry_mngr.ResetMapping();
 
 	GenerateWorldSetCallback(&MakeNewGameDone);
-	GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
+	GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y, reset_settings);
 }
 
 static void MakeNewEditorWorldDone()
@@ -915,7 +915,7 @@
 	if (new_mode != SM_SAVE) {
 		/* If the network is active, make it not-active */
 		if (_networking) {
-			if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME)) {
+			if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME || new_mode == SM_RESTARTGAME)) {
 				NetworkReboot();
 			} else {
 				NetworkDisconnect();
@@ -948,13 +948,14 @@
 			MakeNewEditorWorld();
 			break;
 
+		case SM_RESTARTGAME: // Restart --> 'Random game' with current settings
 		case SM_NEWGAME: // New Game --> 'Random game'
 #ifdef ENABLE_NETWORK
 			if (_network_server) {
 				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "Random Map");
 			}
 #endif /* ENABLE_NETWORK */
-			MakeNewGame(false);
+			MakeNewGame(false, new_mode == SM_NEWGAME);
 			break;
 
 		case SM_START_SCENARIO: // New Game --> Choose one of the preset scenarios
@@ -1000,7 +1001,7 @@
 				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Heightmap)", _file_to_saveload.title);
 			}
 #endif /* ENABLE_NETWORK */
-			MakeNewGame(true);
+			MakeNewGame(true, true);
 			break;
 
 		case SM_LOAD_HEIGHTMAP: // Load heightmap from scenario editor
--- a/src/openttd.h
+++ b/src/openttd.h
@@ -16,6 +16,7 @@
 enum SwitchMode {
 	SM_NONE,
 	SM_NEWGAME,
+	SM_RESTARTGAME,
 	SM_EDITOR,
 	SM_LOAD,
 	SM_MENU,
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -1633,7 +1633,7 @@
 }
 
 /* actual loader/saver function */
-void InitializeGame(uint size_x, uint size_y, bool reset_date);
+void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings);
 extern bool AfterLoadGame();
 extern bool LoadOldSaveGame(const char *file);
 
@@ -1793,7 +1793,7 @@
 	/* Load a TTDLX or TTDPatch game */
 	if (mode == SL_OLD_LOAD) {
 		_engine_mngr.ResetToDefaultMapping();
-		InitializeGame(256, 256, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
+		InitializeGame(256, 256, true, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
 		GamelogReset();
 		if (!LoadOldSaveGame(filename)) return SL_REINIT;
 		_sl_version = 0;
@@ -1912,7 +1912,7 @@
 			/* Old maps were hardcoded to 256x256 and thus did not contain
 			 * any mapsize information. Pre-initialize to 256x256 to not to
 			 * confuse old games */
-			InitializeGame(256, 256, true);
+			InitializeGame(256, 256, true, true);
 
 			GamelogReset();