OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
14 #include "../script/squirrel_class.hpp"
19 #include "../script/script_storage.hpp"
20 #include "../script/script_cmd.h"
21 #include "../script/script_gui.h"
26 #include "../script/api/template/template_text.hpp.sq"
29 #include "../script/api/ai/ai_includes.hpp"
31 #include "../company_base.h"
32 #include "../company_func.h"
34 #include "../safeguards.h"
36 AIInstance::AIInstance() :
45 SQAIController_Register(this->
engine);
55 SQAI_RegisterAll(this->
engine);
65 if (_game_mode == GM_MENU)
return;
73 if (info !=
nullptr) {
76 if (!info->
GetURL().empty()) {
77 ScriptLog::Info(
"Please report the error to the following URL:");
78 ScriptLog::Info(info->
GetURL());
115 if (c ==
nullptr || c->ai_instance ==
nullptr)
return;
117 if (c->ai_instance->DoCommandCallback(result, data, std::move(result_data), cmd)) {
118 c->ai_instance->Continue();
Window * ShowScriptDebugWindow(CompanyID show_company, bool new_window)
Open the Script debug window and select the given company.
int GetSetting(const std::string &name) override
Get the value of a setting of the current instance.
class Squirrel * engine
A wrapper around the squirrel vm.
CommandCallbackData * GetDoCommandCallback() override
Get the callback handling DoCommands in case of networking.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
const std::string & GetAPIVersion() const
Get the API version this AI is written for.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
@ WL_WARNING
Other information.
void CcAI(Commands cmd, const CommandCost &result, const CommandDataBuffer &data, CommandDataBuffer result_data)
DoCommand callback function for all commands executed by AIs.
Runtime information about a script like a pointer to the squirrel vm and the current state.
void Initialize(class AIInfo *info)
Initialize the AI and prepare it for its first run.
const std::string & GetMainScript() const
Get the filename of the main.nut script.
HSQUIRRELVM GetVM()
Get the squirrel VM.
void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type)
Run the dummy AI and let it generate an error message.
Common return value for all commands.
const std::string & GetURL() const
Get the website for this script.
@ AI_DIR
Subdirectory for all AI files.
ScriptInfo * FindLibrary(const std::string &library, int version) override
Find a library.
void LoadDummyScript() override
Load the dummy script.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
void CommandCallbackData(Commands cmd, const CommandCost &result, const CommandDataBuffer &data, CommandDataBuffer result_data)
Define a callback function for the client, after the command is finished.
std::vector< uint8_t > CommandDataBuffer
Storage buffer for serialized command data.
virtual void RegisterAPI()
Register all API functions to the VM.
static class AILibrary * FindLibrary(const std::string &library, int version)
Wrapper function for AIScanner::FindLibrary.
std::string versionAPI
Current API used by this script.
SwitchMode _switch_mode
The next mainloop command.
CompanyID _current_company
Company currently doing an action.
bool LoadCompatibilityScripts(const std::string &api_version, Subdirectory dir)
Load squirrel scripts to emulate an older API.
void Died() override
Tell the script it died.
void Initialize(const std::string &main_script, const std::string &instance_name, CompanyID company)
Initialize the script and prepare it for its first run.
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
virtual void Died()
Tell the script it died.
All static information from an AI like name, version, etc.
Commands
List of commands.
const std::string & GetInstanceName() const
Get the name of the instance of the script to create.
void RegisterAPI() override
Register all API functions to the VM.
All static information from an Script like name, version, etc.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)