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