Go to the documentation of this file.
10 #ifndef SCRIPT_INSTANCE_HPP
11 #define SCRIPT_INSTANCE_HPP
16 #include "../command_type.h"
17 #include "../company_type.h"
18 #include "../fileio_type.h"
25 friend class ScriptObject;
26 friend class ScriptController;
143 void Load(
int version);
201 size_t GetAllocatedMemory()
const;
276 static bool SaveObject(HSQUIRRELVM vm, SQInteger index,
int max_depth,
bool test);
virtual void LoadDummyScript()=0
Load the dummy script.
uint32 TileIndex
The index/ID of a Tile.
static bool SaveObject(HSQUIRRELVM vm, SQInteger index, int max_depth, bool test)
Save one object (int / string / array / table) to the savegame.
class Squirrel * engine
A wrapper around the squirrel vm.
size_t last_allocated_memory
Last known allocated memory value (for display for crashed scripts)
The storage for each script.
bool CallLoad()
Call the script Load function if it exists and data was loaded from a savegame.
bool is_dead
True if the script has been stopped.
void InsertEvent(class ScriptEvent *event)
Insert an event for this script.
void GameLoop()
Run the GameLoop of a script.
bool DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
DoCommand callback function for all commands executed by scripts.
class ScriptController * controller
The script main class.
void Save()
Call the script Save function and save all data in the savegame.
Runtime information about a script like a pointer to the squirrel vm and the current state.
ScriptInstance(const char *APIName)
Create a new script.
void Unpause()
Resume execution of the script.
static void DoCommandReturnStoryPageElementID(ScriptInstance *instance)
Return a StoryPageElementID reply for a DoCommand.
static bool LoadObjects(HSQUIRRELVM vm)
Load all objects from a savegame.
SQObject * instance
Squirrel-pointer to the script main class.
void() Script_SuspendCallbackProc(class ScriptInstance *instance)
The callback function when a script suspends.
void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Define a callback function for the client, after the command is finished.
bool is_save_data_on_stack
Is the save data still on the squirrel stack?
bool is_paused
Is the script paused? (a paused script will not be executed until unpaused)
Owner
Enum for all companies/owners.
virtual CommandCallback * GetDoCommandCallback()=0
Get the callback handling DoCommands in case of networking.
SQInteger GetOpsTillSuspend()
Get the number of operations the script can execute before being suspended.
void Pause()
Suspends the script for the current tick and then pause the execution of script.
static void DoCommandReturnGoalID(ScriptInstance *instance)
Return a GoalID reply for a DoCommand.
void ReleaseSQObject(HSQOBJECT *obj)
Decrease the ref count of a squirrel object.
class ScriptStorage * storage
Some global information for each running script.
int version
Version of the script.
static void DoCommandReturnSignID(ScriptInstance *instance)
Return a SignID reply for a DoCommand.
bool in_shutdown
Is this instance currently being destructed?
Common return value for all commands.
bool InShutdown() const
Indicate whether this instance is currently being destroyed.
static void DoCommandReturn(ScriptInstance *instance)
Return a true/false reply for a DoCommand.
static void SaveEmpty()
Don't save any data in the savegame.
bool IsDead() const
Return the "this script died" value.
bool is_started
Is the scripts constructor executed?
static void DoCommandReturnStoryPageID(ScriptInstance *instance)
Return a StoryPageID reply for a DoCommand.
virtual void RegisterAPI()
Register all API functions to the VM.
void Initialize(const char *main_script, const char *instance_name, CompanyID company)
Initialize the script and prepare it for its first run.
static void LoadEmpty()
Load and discard data from a savegame.
static void DoCommandReturnGroupID(ScriptInstance *instance)
Return a GroupID reply for a DoCommand.
bool IsSleeping()
Check if the instance is sleeping, which either happened because the script executed a DoCommand,...
Script_SuspendCallbackProc * callback
Callback that should be called in the next tick the script runs.
virtual int GetSetting(const char *name)=0
Get the value of a setting of the current instance.
static void DoCommandReturnVehicleID(ScriptInstance *instance)
Return a VehicleID reply for a DoCommand.
class ScriptStorage * GetStorage()
Get the storage of this script.
class ScriptController * GetController()
Get the controller attached to the instance.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
virtual void Died()
Tell the script it died.
int suspend
The amount of ticks to suspend this script before it's allowed to continue.
void Continue()
A script in multiplayer waits for the server to handle his DoCommand.
bool IsPaused()
Checks if the script is paused.
bool LoadCompatibilityScripts(const char *api_version, Subdirectory dir)
Load squirrel scripts to emulate an older API.
void Load(int version)
Load data from a savegame and store it on the stack.
All static information from an Script like name, version, etc.
const char * versionAPI
Current API used by this script.
virtual class ScriptInfo * FindLibrary(const char *library, int version)=0
Find a library.
void * GetLogPointer()
Get the log pointer of this script.
void CollectGarbage() const
Let the VM collect any garbage.
static const uint SQUIRREL_MAX_DEPTH
The maximum recursive depth for items stored in the savegame.