diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/game.hpp | 15 | ||||
-rw-r--r-- | src/game/game_core.cpp | 54 |
2 files changed, 55 insertions, 14 deletions
diff --git a/src/game/game.hpp b/src/game/game.hpp index bc9a9d502..b3a87b1f1 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -34,6 +34,11 @@ public: static void Initialize(); /** + * Start up a new GameScript. + */ + static void StartNew(); + + /** * Uninitialize the Game system. */ static void Uninitialize(bool keepConfig); @@ -51,6 +56,16 @@ public: static void Rescan(); static void ResetConfig(); + /** + * Save data from a GameScript to a savegame. + */ + static void Save(); + + /** + * Load data for a GameScript from a savegame. + */ + static void Load(int version); + /** Wrapper function for GameScanner::GetConsoleList */ static char *GetConsoleList(char *p, const char *last, bool newest_only = false); /** Wrapper function for GameScanner::GetInfoList */ diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp index 22898a3d8..fa63c42e9 100644 --- a/src/game/game_core.cpp +++ b/src/game/game_core.cpp @@ -57,26 +57,29 @@ Game::scanner = new GameScannerInfo(); Game::scanner->Initialize(); } +} - if (Game::instance == NULL) { - /* Clients shouldn't start GameScripts */ - if (_networking && !_network_server) return; +/* static */ void Game::StartNew() +{ + if (Game::instance != NULL) return; - GameConfig *config = GameConfig::GetConfig(); - GameInfo *info = config->GetInfo(); - if (info == NULL) return; + /* Clients shouldn't start GameScripts */ + if (_networking && !_network_server) return; - Backup<CompanyByte> cur_company(_current_company, FILE_LINE); - cur_company.Change(OWNER_DEITY); + GameConfig *config = GameConfig::GetConfig(); + GameInfo *info = config->GetInfo(); + if (info == NULL) return; - Game::info = info; - Game::instance = new GameInstance(); - Game::instance->Initialize(info); + Backup<CompanyByte> cur_company(_current_company, FILE_LINE); + cur_company.Change(OWNER_DEITY); - cur_company.Restore(); + Game::info = info; + Game::instance = new GameInstance(); + Game::instance->Initialize(info); - InvalidateWindowData(WC_AI_DEBUG, 0, -1); - } + cur_company.Restore(); + + InvalidateWindowData(WC_AI_DEBUG, 0, -1); } /* static */ void Game::Uninitialize(bool keepConfig) @@ -138,6 +141,29 @@ } +/* static */ void Game::Save() +{ + if (Game::instance != NULL && (!_networking || _network_server)) { + Backup<CompanyByte> cur_company(_current_company, OWNER_DEITY, FILE_LINE); + Game::instance->Save(); + cur_company.Restore(); + } else { + GameInstance::SaveEmpty(); + } +} + +/* static */ void Game::Load(int version) +{ + if (Game::instance != NULL && (!_networking || _network_server)) { + Backup<CompanyByte> cur_company(_current_company, OWNER_DEITY, FILE_LINE); + Game::instance->Load(version); + cur_company.Restore(); + } else { + /* Read, but ignore, the load data */ + GameInstance::LoadEmpty(); + } +} + /* static */ char *Game::GetConsoleList(char *p, const char *last, bool newest_only) { return Game::scanner->GetConsoleList(p, last, newest_only); |