OpenTTD Source: Game Class Reference

OpenTTD Source 15.0-RC2

Static Public Member Functions | Static Private Attributes
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 a Game Script.
static class GameInfo * | GetInfo ()
| Get the current GameInfo.
static void | Rescan ()
static void | ResetConfig ()
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)
| Wrapper function for GameScanner::GetConsoleList.
static void | GetConsoleLibraryList (std::back_insert_iterator< std::string > &output_iterator)
| Wrapper function for GameScanner::GetConsoleLibraryList.
static const ScriptInfoList * | GetInfoList ()
| Wrapper function for GameScanner::GetInfoList.
static const ScriptInfoList * | GetUniqueInfoList ()
| Wrapper function for GameScanner::GetUniqueInfoList.
static class GameInfo * | FindInfo (const std::string &name, int version, bool force_exact_match)
| Wrapper function for GameScannerInfo::FindInfo.
static class GameLibrary * | FindLibrary (const std::string &library, int version)
| Wrapper function for GameScanner::FindLibrary.
static class GameInstance * | GetInstance ()
| 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)
static GameScannerInfo * | GetScannerInfo ()
| Gets the ScriptScanner instance that is used to find Game scripts.
static GameScannerLibrary * | GetScannerLibrary ()
| 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< GameInstance > | instance = nullptr
| Instance to the current active Game.
static std::unique_ptr< GameScannerInfo > | scanner_info = nullptr
| Scanner for Game scripts.
static std::unique_ptr< GameScannerLibrary > | scanner_library = nullptr
| Scanner for GS Libraries.
static GameInfo * | info = 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

Wrapper function for GameScannerInfo::FindInfo.

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

Wrapper function for GameScanner::FindLibrary.

Definition at line 228 of file game_core.cpp.

References scanner_library.

Referenced by GameInstance::FindLibrary().

## ◆ GameLoop()

void Game::GameLoop | ( |  | ) |
| static

Called every game-tick to let Game do something.

Definition at line 31 of file game_core.cpp.

References _current_company, _network_server, _networking, Backup< T >::Change(), frame_counter, instance, OWNER_DEITY, PFE_GAMESCRIPT, Backup< T >::Restore(), and PerformanceMeasurer::SetInactive().

Referenced by _GenerateWorld(), and StateGameLoop().

## ◆ GetConsoleLibraryList()

void Game::GetConsoleLibraryList | ( | std::back_insert_iterator< std::string > & | output_iterator | ) |
| static

Wrapper function for GameScanner::GetConsoleLibraryList.

Definition at line 208 of file game_core.cpp.

References scanner_library.

## ◆ GetConsoleList()

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

Wrapper function for GameScanner::GetConsoleList.

Definition at line 203 of file game_core.cpp.

References scanner_info.

Referenced by ShowHelp().

## ◆ GetInfo()

static class GameInfo * Game::GetInfo | ( |  | ) |
| inlinestatic

Get the current GameInfo.

Definition at line 70 of file game.hpp.

References info.

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

## ◆ GetInfoList()

const ScriptInfoList * Game::GetInfoList | ( |  | ) |
| static

Wrapper function for GameScanner::GetInfoList.

Definition at line 213 of file game_core.cpp.

References scanner_info.

Referenced by ScriptListWindow::ScriptListWindow().

## ◆ GetInstance()

static class GameInstance * Game::GetInstance | ( |  | ) |
| inlinestatic

Get the current active instance.

Definition at line 96 of file game.hpp.

References instance.

Referenced by _GenerateWorld(), CcGame(), ScriptListWindow::ChangeScript(), ScriptDebugWindow::IsDead(), GSConfigWindow::IsEditable(), ScriptDebugWindow::IsValidDebugCompany(), ScriptDebugWindow::SelectValidDebugCompany(), ShowScriptDebugWindowIfScriptError(), and ScriptDebugWindow::UpdateGSButtonState().

## ◆ GetScannerInfo()

GameScannerInfo * Game::GetScannerInfo | ( |  | ) |
| static

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

Definition at line 255 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.

Definition at line 259 of file game_core.cpp.

References scanner_library.

Referenced by ContentInfo::GetTextfile().

## ◆ GetUniqueInfoList()

const ScriptInfoList * Game::GetUniqueInfoList | ( |  | ) |
| static

Wrapper function for GameScanner::GetUniqueInfoList.

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 (library) with the exact characteristics as ci.

Parameters

  ci | the characteristics to search on (shortname and md5sum)
  md5sum | whether to check the MD5 checksum

Returns
  true iff we have an Game (library) 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

Definition at line 250 of file game_core.cpp.

## ◆ Initialize()

void Game::Initialize | ( |  | ) |
| static

Initialize the Game system.

Definition at line 57 of file game_core.cpp.

References TarScanner::DoScan(), frame_counter, TarScanner::Game, instance, scanner_info, scanner_library, and Uninitialize().

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

## ◆ 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()

void Game::NewEvent | ( | class ScriptEvent * | event | ) |
| static

Queue a new event for a Game Script.

Definition at line 136 of file game_core.cpp.

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

Referenced by AdvertiseIndustryOpening(), AircraftEntersTerminal(), Subsidy::AwardTo(), ChangeIndustryProduction(), CmdCompanyCtrl(), CmdFoundTown(), CmdGoalQuestionAnswer(), CmdRenameCompany(), CmdRenamePresident(), CmdStoryPageButton(), CompanyCheckBankrupt(), CrashAirplane(), CreateSubsidy(), DisasterTick_Ufo(), DispatchLeftClickEvent(), DoStartupNewCompany(), FloodVehicle(), GenerateCompanyName(), ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(), RoadVehArrivesAt(), ShipArrivesAt(), TownActionBuyRights(), TownActionRoadRebuild(), TrainCrashed(), and TrainEnterStation().

## ◆ 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

Definition at line 177 of file game_core.cpp.

## ◆ ResetConfig()

void Game::ResetConfig | ( |  | ) |
| static

Definition at line 156 of file game_core.cpp.

## ◆ 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(), 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()

void Game::StartNew | ( |  | ) |
| static

Start up a new GameScript.

Definition at line 72 of file game_core.cpp.

References _current_company, _network_server, _networking, ScriptConfig::AnchorUnchangeableSettings(), Backup< T >::Change(), GameConfig::GetConfig(), info, instance, InvalidateWindowClassesData(), OWNER_DEITY, Backup< T >::Restore(), ScriptConfig::SSS_FORCE_GAME, and WC_SCRIPT_DEBUG.

Referenced by _GenerateWorld(), ScriptListWindow::ChangeScript(), and StartScripts().

## ◆ Uninitialize()

void Game::Uninitialize | ( | bool | keepConfig | ) |
| static

Uninitialize the Game system.

Definition at line 102 of file game_core.cpp.

References _current_company, _settings_game, _settings_newgame, ScriptConfigSettings::game, ResetInstance(), Backup< T >::Restore(), scanner_info, scanner_library, and GameSettings::script_config.

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 112 of file game.hpp.

Referenced by GameLoop(), and Initialize().

## ◆ info

GameInfo * Game::info = nullptr
| staticprivate

Current selected GameInfo.

Definition at line 116 of file game.hpp.

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

## ◆ instance

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

Instance to the current active Game.

Definition at line 113 of file game.hpp.

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

## ◆ scanner_info

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

Scanner for Game scripts.

Definition at line 114 of file game.hpp.

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

## ◆ scanner_library

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

Scanner for GS Libraries.

Definition at line 115 of file game.hpp.

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

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

- src/game/game.hpp
- src/game/game_core.cpp