From 827a97a5ce8248675ee770c1f349b0dc5a01844f Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 30 Jun 2010 20:20:15 +0000 Subject: [PATCH] (svn r20038) -Change: move SafeSaveOrLoad a bit --- src/openttd.cpp | 63 +++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/openttd.cpp b/src/openttd.cpp index b49e36c555..0d37c2a8e7 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -853,6 +853,38 @@ void StartupCompanies(); void StartupDisasters(); extern void StartupEconomy(); +/** + * Load the specified savegame but on error do different things. + * If loading fails due to corrupt savegame, bad version, etc. go back to + * a previous correct state. In the menu for example load the intro game again. + * @param filename file to be loaded + * @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD + * @param newgm switch to this mode of loading fails due to some unknown error + * @param subdir default directory to look for filename, set to 0 if not needed + */ +bool SafeSaveOrLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir) +{ + GameMode ogm = _game_mode; + + _game_mode = newgm; + assert(mode == SL_LOAD || mode == SL_OLD_LOAD); + switch (SaveOrLoad(filename, mode, subdir)) { + case SL_OK: return true; + + case SL_REINIT: + switch (ogm) { + default: + case GM_MENU: LoadIntroGame(); break; + case GM_EDITOR: MakeNewEditorWorld(); break; + } + return false; + + default: + _game_mode = ogm; + return false; + } +} + /** * Start Scenario starts a new game based on a scenario. * Eg 'New Game' --> select a preset scenario @@ -900,37 +932,6 @@ static void StartScenario() MarkWholeScreenDirty(); } -/** Load the specified savegame but on error do different things. - * If loading fails due to corrupt savegame, bad version, etc. go back to - * a previous correct state. In the menu for example load the intro game again. - * @param filename file to be loaded - * @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD - * @param newgm switch to this mode of loading fails due to some unknown error - * @param subdir default directory to look for filename, set to 0 if not needed - */ -bool SafeSaveOrLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir) -{ - GameMode ogm = _game_mode; - - _game_mode = newgm; - assert(mode == SL_LOAD || mode == SL_OLD_LOAD); - switch (SaveOrLoad(filename, mode, subdir)) { - case SL_OK: return true; - - case SL_REINIT: - switch (ogm) { - default: - case GM_MENU: LoadIntroGame(); break; - case GM_EDITOR: MakeNewEditorWorld(); break; - } - return false; - - default: - _game_mode = ogm; - return false; - } -} - void SwitchToMode(SwitchMode new_mode) { #ifdef ENABLE_NETWORK