|
OpenTTD Source 20251116-master-g21329071df
|
Runtime information about an AI like a pointer to the squirrel vm and the current state. More...
#include <ai_instance.hpp>
Public Member Functions | |
| void | Initialize (class AIInfo *info) |
| Initialize the AI and prepare it for its first run. | |
| int | GetSetting (const std::string &name) override |
| Get the value of a setting of the current instance. | |
| ScriptInfo * | FindLibrary (const std::string &library, int version) override |
| Find a library. | |
Public Member Functions inherited from ScriptInstance | |
| ScriptInstance (std::string_view api_name) | |
| Create a new script. | |
| void | Initialize (const std::string &main_script, const std::string &instance_name, CompanyID company) |
| Initialize the script and prepare it for its first run. | |
| void | Continue () |
| A script in multiplayer waits for the server to handle its DoCommand. | |
| void | GameLoop () |
| Run the GameLoop of a script. | |
| void | CollectGarbage () |
| Let the VM collect any garbage. | |
| class ScriptStorage & | GetStorage () |
| Get the storage of this script. | |
| ScriptLogTypes::LogData & | GetLogData () |
| 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. | |
| bool | IsAlive () const |
| Return whether the script is alive. | |
| void | Save () |
| Call the script Save function and save all data in the savegame. | |
| void | LoadOnStack (ScriptData *data) |
| Store loaded data on the stack. | |
| void | Pause () |
| Suspends the script for the current tick and then pause the execution of script. | |
| bool | IsPaused () |
| Checks if the script is paused. | |
| void | Unpause () |
| Resume execution of the script. | |
| SQInteger | GetOpsTillSuspend () |
| Get the number of operations the script can execute before being suspended. | |
| bool | DoCommandCallback (const CommandCost &result, const CommandDataBuffer &data, CommandDataBuffer result_data, Commands cmd) |
| DoCommand callback function for all commands executed by scripts. | |
| void | InsertEvent (class ScriptEvent *event) |
| Insert an event for this script. | |
| 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. | |
Private Member Functions | |
| void | RegisterAPI () override |
| Register all API functions to the VM. | |
| void | Died () override |
| Tell the script it died. | |
| CommandCallbackData * | GetDoCommandCallback () override |
| Get the callback handling DoCommands in case of networking. | |
| void | LoadDummyScript () override |
| Load the dummy script. | |
Additional Inherited Members | |
Public Types inherited from ScriptInstance | |
| typedef std::variant< SQInteger, std::string, SQBool, SQSaveLoadType > | ScriptDataVariant |
| typedef std::list< ScriptDataVariant > | ScriptData |
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 | DoCommandReturnLeagueTableID (ScriptInstance &instance) |
| Return a LeagueTableID reply for a DoCommand. | |
| static void | DoCommandReturnLeagueTableElementID (ScriptInstance &instance) |
| Return a LeagueTableElementID reply for a DoCommand. | |
| static void | SaveEmpty () |
| Don't save any data in the savegame. | |
| static ScriptData * | Load (int version) |
| Load data from a savegame. | |
| static void | LoadEmpty () |
| Load and discard data from a savegame. | |
Protected Member Functions inherited from ScriptInstance | |
| bool | LoadCompatibilityScripts (Subdirectory dir, std::span< const std::string_view > api_versions) |
| Load squirrel scripts to emulate an older API. | |
Protected Attributes inherited from ScriptInstance | |
| std::unique_ptr< class Squirrel > | engine |
| A wrapper around the squirrel vm. | |
| std::string | api_version {} |
| Current API used by this script. | |
Runtime information about an AI like a pointer to the squirrel vm and the current state.
Definition at line 16 of file ai_instance.hpp.
| AIInstance::AIInstance | ( | ) |
Definition at line 37 of file ai_instance.cpp.
|
overrideprivatevirtual |
Tell the script it died.
Reimplemented from ScriptInstance.
Definition at line 61 of file ai_instance.cpp.
References _current_company, _switch_mode, ScriptInstance::Died(), AIConfig::GetConfig(), GetEncodedString(), ScriptInfo::GetURL(), ShowErrorMessage(), ShowScriptDebugWindow(), and WL_WARNING.
Referenced by RegisterAPI().
|
overridevirtual |
Find a library.
| library | The library name to find. |
| version | The version the library should have. |
Implements ScriptInstance.
Definition at line 95 of file ai_instance.cpp.
References AI::FindLibrary().
|
overrideprivatevirtual |
Get the callback handling DoCommands in case of networking.
Implements ScriptInstance.
Definition at line 123 of file ai_instance.cpp.
|
overridevirtual |
Get the value of a setting of the current instance.
| name | The name of the setting. |
Implements ScriptInstance.
Definition at line 90 of file ai_instance.cpp.
References _current_company, AIConfig::GetConfig(), and ScriptConfig::GetSetting().
| void AIInstance::Initialize | ( | class AIInfo * | info | ) |
Initialize the AI and prepare it for its first run.
| info | The AI to create the instance of. |
Definition at line 41 of file ai_instance.cpp.
References _current_company, ScriptInstance::api_version, ScriptInstance::engine, AIInfo::GetAPIVersion(), ScriptInfo::GetInstanceName(), ScriptInfo::GetMainScript(), and ScriptInstance::Initialize().
|
overrideprivatevirtual |
Load the dummy script.
Implements ScriptInstance.
Definition at line 84 of file ai_instance.cpp.
References ScriptInstance::engine, and Script_CreateDummy().
|
overrideprivatevirtual |
Register all API functions to the VM.
Reimplemented from ScriptInstance.
Definition at line 51 of file ai_instance.cpp.
References AI_DIR, Died(), ScriptInstance::engine, ScriptInstance::LoadCompatibilityScripts(), and ScriptInstance::RegisterAPI().