OpenTTD Source  12.0-beta2
GameInstance Class Reference

Runtime information about a game script like a pointer to the squirrel vm and the current state. More...

#include <game_instance.hpp>

Inheritance diagram for GameInstance:
ScriptInstance

Public Member Functions

void Initialize (class GameInfo *info)
 Initialize the script and prepare it for its first run. More...
 
int GetSetting (const char *name) override
 Get the value of a setting of the current instance. More...
 
ScriptInfoFindLibrary (const char *library, int version) override
 Find a library. More...
 
- Public Member Functions inherited from ScriptInstance
 ScriptInstance (const char *APIName)
 Create a new script.
 
void Initialize (const char *main_script, const char *instance_name, CompanyID company)
 Initialize the script and prepare it for its first run. More...
 
void Continue ()
 A script in multiplayer waits for the server to handle its DoCommand. More...
 
void GameLoop ()
 Run the GameLoop of a script.
 
void CollectGarbage ()
 Let the VM collect any garbage.
 
class ScriptStorageGetStorage ()
 Get the storage of this script.
 
void * GetLogPointer ()
 Get the log pointer of this script.
 
class ScriptController * GetController ()
 Get the controller attached to the instance.
 
bool IsDead () const
 Return the "this script died" value.
 
void Save ()
 Call the script Save function and save all data in the savegame.
 
void Load (int version)
 Load data from a savegame and store it on the stack. More...
 
void Pause ()
 Suspends the script for the current tick and then pause the execution of script. More...
 
bool IsPaused ()
 Checks if the script is paused. More...
 
void Unpause ()
 Resume execution of the script. More...
 
SQInteger GetOpsTillSuspend ()
 Get the number of operations the script can execute before being suspended. More...
 
bool DoCommandCallback (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 DoCommand callback function for all commands executed by scripts. More...
 
void InsertEvent (class ScriptEvent *event)
 Insert an event for this script. More...
 
bool IsSleeping ()
 Check if the instance is sleeping, which either happened because the script executed a DoCommand, executed this.Sleep() or it has been paused.
 
size_t GetAllocatedMemory () const
 
bool InShutdown () const
 Indicate whether this instance is currently being destroyed.
 
void ReleaseSQObject (HSQOBJECT *obj)
 Decrease the ref count of a squirrel object. More...
 

Private Member Functions

void RegisterAPI () override
 Register all API functions to the VM.
 
void Died () override
 Tell the script it died.
 
CommandCallbackGetDoCommandCallback () override
 Get the callback handling DoCommands in case of networking.
 
void LoadDummyScript () override
 Load the dummy script.
 

Additional Inherited Members

- Static Public Member Functions inherited from ScriptInstance
static void DoCommandReturn (ScriptInstance *instance)
 Return a true/false reply for a DoCommand.
 
static void DoCommandReturnVehicleID (ScriptInstance *instance)
 Return a VehicleID reply for a DoCommand.
 
static void DoCommandReturnSignID (ScriptInstance *instance)
 Return a SignID reply for a DoCommand.
 
static void DoCommandReturnGroupID (ScriptInstance *instance)
 Return a GroupID reply for a DoCommand.
 
static void DoCommandReturnGoalID (ScriptInstance *instance)
 Return a GoalID reply for a DoCommand.
 
static void DoCommandReturnStoryPageID (ScriptInstance *instance)
 Return a StoryPageID reply for a DoCommand.
 
static void DoCommandReturnStoryPageElementID (ScriptInstance *instance)
 Return a StoryPageElementID reply for a DoCommand.
 
static void SaveEmpty ()
 Don't save any data in the savegame.
 
static void LoadEmpty ()
 Load and discard data from a savegame.
 
- Protected Member Functions inherited from ScriptInstance
bool LoadCompatibilityScripts (const char *api_version, Subdirectory dir)
 Load squirrel scripts to emulate an older API. More...
 
- Protected Attributes inherited from ScriptInstance
class Squirrelengine
 A wrapper around the squirrel vm.
 
const char * versionAPI
 Current API used by this script.
 

Detailed Description

Runtime information about a game script like a pointer to the squirrel vm and the current state.

Definition at line 16 of file game_instance.hpp.

Member Function Documentation

◆ FindLibrary()

ScriptInfo * GameInstance::FindLibrary ( const char *  library,
int  version 
)
overridevirtual

Find a library.

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

Implements ScriptInstance.

Definition at line 60 of file game_instance.cpp.

References Game::FindLibrary().

◆ GetSetting()

int GameInstance::GetSetting ( const char *  name)
overridevirtual

Get the value of a setting of the current instance.

Parameters
nameThe name of the setting.
Returns
the value for the setting, or -1 if the setting is not known.

Implements ScriptInstance.

Definition at line 55 of file game_instance.cpp.

References GameConfig::GetConfig(), and ScriptConfig::GetSetting().

◆ Initialize()

void GameInstance::Initialize ( class GameInfo info)

Initialize the script and prepare it for its first run.

Parameters
infoThe GameInfo to start.

Definition at line 33 of file game_instance.cpp.

References ScriptInstance::engine, GameInfo::GetAPIVersion(), ScriptInfo::GetInstanceName(), ScriptInfo::GetMainScript(), ScriptInstance::Initialize(), OWNER_DEITY, and ScriptInstance::versionAPI.


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