OpenTTD Source 20260218-master-g2123fca5ea
Game Class Reference

Main Game class. More...

#include <game.hpp>

Static Public Member Functions

static void GameLoop ()
 Called every game-tick to let Game do something.
static void Initialize ()
 Initialize the Game system.
static void StartNew ()
 Start up a new GameScript.
static void Uninitialize (bool keepConfig)
 Uninitialize the Game system.
static void Pause ()
 Suspends the Game Script and then pause the execution of the script.
static void Unpause ()
 Resume execution of the Game Script.
static bool IsPaused ()
 Checks if the Game Script is paused.
static void NewEvent (class ScriptEvent *event)
 Queue a new event for the game script.
static class GameInfoGetInfo ()
 Get the current GameInfo.
static void Rescan ()
 Rescans all searchpaths for available Game scripts.
static void ResetConfig ()
 Reset all GameConfigs, and make them reload their GameInfo.
static void Save ()
 Save data from a GameScript to a savegame.
static void GetConsoleList (std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
 Get the list of registered scripts to print on the console.
static void GetConsoleLibraryList (std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
 Get the list of registered scripts to print on the console.
static const ScriptInfoListGetInfoList ()
 Get the list of all registered scripts.
static const ScriptInfoListGetUniqueInfoList ()
 Get the list of the latest version of all registered scripts.
static class GameInfoFindInfo (const std::string &name, int version, bool force_exact_match)
 Finds the appropriate ScriptInfo for a given script name and version.
static class GameLibraryFindLibrary (const std::string &library, int version)
 Find a library.
static class GameInstanceGetInstance ()
 Get the current active instance.
static void ResetInstance ()
 Reset the current active instance.
static bool HasGame (const ContentInfo &ci, bool md5sum)
 Wrapper function for GameScanner::HasGame.
static bool HasGameLibrary (const ContentInfo &ci, bool md5sum)
 Check whether we have an Game library with the exact characteristics as ci.
static GameScannerInfoGetScannerInfo ()
 Gets the ScriptScanner instance that is used to find Game scripts.
static GameScannerLibraryGetScannerLibrary ()
 Gets the ScriptScanner instance that is used to find Game Libraries.

Static Private Attributes

static uint frame_counter = 0
 Tick counter for the Game code.
static std::unique_ptr< GameInstanceinstance = nullptr
 Instance to the current active Game.
static std::unique_ptr< GameScannerInfoscanner_info = nullptr
 Scanner for Game scripts.
static std::unique_ptr< GameScannerLibraryscanner_library = nullptr
 Scanner for GS Libraries.
static GameInfoinfo = nullptr
 Current selected GameInfo.

Detailed Description

Main Game class.

Contains all functions needed to start, stop, save and load Game Scripts.

Definition at line 20 of file game.hpp.

Member Function Documentation

◆ FindInfo()

GameInfo * Game::FindInfo ( const std::string & name,
int version,
bool force_exact_match )
static

Finds the appropriate ScriptInfo for a given script name and version.

Parameters
nameThe script name to find.
versionThe version the script should have.
force_exact_matchWhether an exact match is required.
Returns
The script if found, nullptr otherwise.

Definition at line 223 of file game_core.cpp.

References scanner_info.

Referenced by GameConfig::FindInfo(), and GameConfig::ResetInfo().

◆ FindLibrary()

GameLibrary * Game::FindLibrary ( const std::string & library,
int version )
static

Find a library.

Parameters
libraryThe library name to find.
versionThe version the library should have.
Returns
The library if found, nullptr otherwise.

Definition at line 228 of file game_core.cpp.

References scanner_library.

Referenced by GameInstance::FindLibrary().

◆ GameLoop()

void Game::GameLoop ( )
static

◆ GetConsoleLibraryList()

void Game::GetConsoleLibraryList ( std::back_insert_iterator< std::string > & output_iterator,
bool newest_only )
static

Get the list of registered scripts to print on the console.

Parameters
output_iteratorThe iterator to write the output to.
newest_onlyWhether to only show the newest scripts.

Definition at line 208 of file game_core.cpp.

References scanner_library.

Referenced by ConListGameLibs().

◆ GetConsoleList()

void Game::GetConsoleList ( std::back_insert_iterator< std::string > & output_iterator,
bool newest_only )
static

Get the list of registered scripts to print on the console.

Parameters
output_iteratorThe iterator to write the output to.
newest_onlyWhether to only show the newest scripts.

Definition at line 203 of file game_core.cpp.

References scanner_info.

Referenced by ConListGame(), and ShowHelp().

◆ GetInfo()

class GameInfo * Game::GetInfo ( )
inlinestatic

Get the current GameInfo.

Returns
The info, or nullptr when there is no Game script.

Definition at line 73 of file game.hpp.

References info.

Referenced by GameInstance::Died(), ScriptDebugWindow::GetWidgetString(), LoadTranslations(), SerializeNetworkGameInfo(), and SurveyGameScript().

◆ GetInfoList()

const ScriptInfoList * Game::GetInfoList ( )
static

Get the list of all registered scripts.

Returns
The list of ScriptInfo elements.

Definition at line 213 of file game_core.cpp.

References scanner_info.

Referenced by ScriptListWindow::ScriptListWindow().

◆ GetInstance()

◆ GetScannerInfo()

GameScannerInfo * Game::GetScannerInfo ( )
static

Gets the ScriptScanner instance that is used to find Game scripts.

Get the scanner info for Game scripts.

Returns
The Game Script scanner info.

Definition at line 265 of file game_core.cpp.

References scanner_info.

Referenced by ContentInfo::GetTextfile().

◆ GetScannerLibrary()

GameScannerLibrary * Game::GetScannerLibrary ( )
static

Gets the ScriptScanner instance that is used to find Game Libraries.

Get the scanner info for Game script libraries.

Returns
The Game script library scanner info.

Definition at line 274 of file game_core.cpp.

References scanner_library.

Referenced by ContentInfo::GetTextfile().

◆ GetUniqueInfoList()

const ScriptInfoList * Game::GetUniqueInfoList ( )
static

Get the list of the latest version of all registered scripts.

Returns
The list of ScriptInfo elements.

Definition at line 218 of file game_core.cpp.

References scanner_info.

Referenced by ScriptListWindow::ScriptListWindow().

◆ HasGame()

bool Game::HasGame ( const ContentInfo & ci,
bool md5sum )
static

Wrapper function for GameScanner::HasGame.

Check whether we have an Game with the exact characteristics as ci.

Parameters
cithe characteristics to search on (shortname and md5sum)
md5sumwhether to check the MD5 checksum
Returns
true iff we have an Game matching.

Definition at line 245 of file game_core.cpp.

References scanner_info.

Referenced by GetHasContentProcforContentType().

◆ HasGameLibrary()

bool Game::HasGameLibrary ( const ContentInfo & ci,
bool md5sum )
static

Check whether we have an Game library with the exact characteristics as ci.

Parameters
cithe characteristics to search on (shortname and md5sum)
md5sumwhether to check the MD5 checksum
Returns
true iff we have an Game library matching.

Definition at line 256 of file game_core.cpp.

References scanner_library.

Referenced by GetHasContentProcforContentType().

◆ Initialize()

void Game::Initialize ( )
static

◆ IsPaused()

bool Game::IsPaused ( )
static

Checks if the Game Script is paused.

Returns
true if the Game Script is paused, otherwise false.

Definition at line 131 of file game_core.cpp.

References instance.

Referenced by ScriptDebugWindow::OnClick(), and ScriptDebugWindow::OnInvalidateData().

◆ NewEvent()

◆ Pause()

void Game::Pause ( )
static

Suspends the Game Script and then pause the execution of the script.

The script will not be resumed from its suspended state until the script has been unpaused.

Definition at line 121 of file game_core.cpp.

References instance.

Referenced by ScriptDebugWindow::OnInvalidateData().

◆ Rescan()

void Game::Rescan ( )
static

Rescans all searchpaths for available Game scripts.

If a used Game script is no longer found it is removed from the config.

Definition at line 177 of file game_core.cpp.

References TarScanner::DoScan(), TarScanner::Game, InvalidateWindowClassesData(), InvalidateWindowData(), ResetConfig(), scanner_info, scanner_library, SetWindowClassesDirty(), WC_GAME_OPTIONS, WC_SCRIPT_DEBUG, WC_SCRIPT_LIST, and WC_SCRIPT_SETTINGS.

Referenced by NetworkContentDownloadStatusWindow::Close(), ConRescanGame(), and Uninitialize().

◆ ResetConfig()

void Game::ResetConfig ( )
static

Reset all GameConfigs, and make them reload their GameInfo.

If the GameInfo could no longer be found, an error is reported to the user.

Definition at line 156 of file game_core.cpp.

References _settings_game, _settings_newgame, Debug, info, instance, and ResetInstance().

Referenced by Rescan().

◆ ResetInstance()

void Game::ResetInstance ( )
static

Reset the current active instance.

Definition at line 233 of file game_core.cpp.

References info, and instance.

Referenced by ScriptListWindow::ChangeScript(), ResetConfig(), and Uninitialize().

◆ Save()

void Game::Save ( )
static

Save data from a GameScript to a savegame.

Definition at line 192 of file game_core.cpp.

References _current_company, _network_server, _networking, instance, OWNER_DEITY, Backup< T >::Restore(), and ScriptInstance::SaveEmpty().

◆ StartNew()

◆ Uninitialize()

void Game::Uninitialize ( bool keepConfig)
static

Uninitialize the Game system.

Parameters
keepConfigShould we keep GameConfigs, or can we free that memory?

Definition at line 102 of file game_core.cpp.

References _current_company, _settings_game, _settings_newgame, Rescan(), ResetInstance(), Backup< T >::Restore(), scanner_info, and scanner_library.

Referenced by Initialize(), AfterNewGRFScan::OnNewGRFsScanned(), ShowHelp(), and ShutdownGame().

◆ Unpause()

void Game::Unpause ( )
static

Resume execution of the Game Script.

This function will not actually execute the script, but set a flag so that the script is executed by the usual mechanism that executes the script.

Definition at line 126 of file game_core.cpp.

References instance.

Referenced by ScriptDebugWindow::OnClick().

Field Documentation

◆ frame_counter

uint Game::frame_counter = 0
staticprivate

Tick counter for the Game code.

Definition at line 125 of file game.hpp.

Referenced by GameLoop(), and Initialize().

◆ info

GameInfo * Game::info = nullptr
staticprivate

Current selected GameInfo.

Definition at line 129 of file game.hpp.

Referenced by GetInfo(), ResetConfig(), ResetInstance(), and StartNew().

◆ instance

std::unique_ptr< GameInstance > Game::instance = nullptr
staticprivate

Instance to the current active Game.

Definition at line 126 of file game.hpp.

Referenced by GameLoop(), GetInstance(), Initialize(), IsPaused(), NewEvent(), Pause(), ResetConfig(), ResetInstance(), Save(), StartNew(), and Unpause().

◆ scanner_info

std::unique_ptr< GameScannerInfo > Game::scanner_info = nullptr
staticprivate

Scanner for Game scripts.

Definition at line 127 of file game.hpp.

Referenced by FindInfo(), GetConsoleList(), GetInfoList(), GetScannerInfo(), GetUniqueInfoList(), HasGame(), Initialize(), Rescan(), and Uninitialize().

◆ scanner_library

std::unique_ptr< GameScannerLibrary > Game::scanner_library = nullptr
staticprivate

Scanner for GS Libraries.

Definition at line 128 of file game.hpp.

Referenced by FindLibrary(), GetConsoleLibraryList(), GetScannerLibrary(), HasGameLibrary(), Initialize(), Rescan(), and Uninitialize().


The documentation for this class was generated from the following files: