4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file game.hpp Base functions for all Games. */
15 #include "../core/string_compare_type.hpp"
16 #include "game_scanner.hpp"
19 /** A list that maps AI names to their AIInfo object. */
20 typedef std::map
<const char *, class ScriptInfo
*, StringCompare
> ScriptInfoList
;
22 #include "../script/api/script_event_types.hpp"
25 * Main Game class. Contains all functions needed to start, stop, save and load Game Scripts.
30 * Called every game-tick to let Game do something.
32 static void GameLoop();
35 * Initialize the Game system.
37 static void Initialize();
40 * Start up a new GameScript.
42 static void StartNew();
45 * Uninitialize the Game system.
47 static void Uninitialize(bool keepConfig
);
50 * Suspends the Game Script and then pause the execution of the script. The
51 * script will not be resumed from its suspended state until the script
57 * Resume execution of the Game Script. This function will not actually execute
58 * the script, but set a flag so that the script is executed my the usual
59 * mechanism that executes the script.
61 static void Unpause();
64 * Checks if the Game Script is paused.
65 * @return true if the Game Script is paused, otherwise false.
67 static bool IsPaused();
70 * Queue a new event for a Game Script.
72 static void NewEvent(class ScriptEvent
*event
);
75 * Get the current GameScript instance.
77 static class GameInstance
*GetGameInstance() { return Game::instance
; }
80 * Get the current GameInfo.
82 static class GameInfo
*GetInfo() { return Game::info
; }
85 static void ResetConfig();
88 * Save data from a GameScript to a savegame.
93 * Load data for a GameScript from a savegame.
95 static void Load(int version
);
97 /** Wrapper function for GameScanner::GetConsoleList */
98 static char *GetConsoleList(char *p
, const char *last
, bool newest_only
= false);
99 /** Wrapper function for GameScanner::GetConsoleLibraryList */
100 static char *GetConsoleLibraryList(char *p
, const char *last
);
101 /** Wrapper function for GameScanner::GetInfoList */
102 static const ScriptInfoList
*GetInfoList();
103 /** Wrapper function for GameScanner::GetUniqueInfoList */
104 static const ScriptInfoList
*GetUniqueInfoList();
105 /** Wrapper function for GameScannerInfo::FindInfo */
106 static class GameInfo
*FindInfo(const char *name
, int version
, bool force_exact_match
);
107 /** Wrapper function for GameScanner::FindLibrary */
108 static class GameLibrary
*FindLibrary(const char *library
, int version
);
111 * Get the current active instance.
113 static class GameInstance
*GetInstance() { return Game::instance
; }
115 #if defined(ENABLE_NETWORK)
116 /** Wrapper function for GameScanner::HasGame */
117 static bool HasGame(const struct ContentInfo
*ci
, bool md5sum
);
118 static bool HasGameLibrary(const ContentInfo
*ci
, bool md5sum
);
120 /** Gets the ScriptScanner instance that is used to find Game scripts */
121 static GameScannerInfo
*GetScannerInfo();
122 /** Gets the ScriptScanner instance that is used to find Game Libraries */
123 static GameScannerLibrary
*GetScannerLibrary();
126 static uint frame_counter
; ///< Tick counter for the Game code.
127 static class GameInstance
*instance
; ///< Instance to the current active Game.
128 static class GameScannerInfo
*scanner_info
; ///< Scanner for Game scripts.
129 static class GameScannerLibrary
*scanner_library
; ///< Scanner for GS Libraries.
130 static class GameInfo
*info
; ///< Current selected GameInfo.
133 #endif /* GAME_HPP */