Go to the documentation of this file.
10 #include "../stdafx.h"
14 #include "../script/squirrel_class.hpp"
20 #include "../script/script_storage.hpp"
21 #include "../script/script_cmd.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;
70 if (info !=
nullptr) {
73 if (info->
GetURL() !=
nullptr) {
74 ScriptLog::Info(
"Please report the error to the following URL:");
75 ScriptLog::Info(info->
GetURL());
113 if (c ==
nullptr || c->ai_instance ==
nullptr)
return;
115 if (c->ai_instance->
DoCommandCallback(result, data, std::move(result_data), cmd)) {
static class AILibrary * FindLibrary(const char *library, int version)
Wrapper function for AIScanner::FindLibrary.
class Squirrel * engine
A wrapper around the squirrel vm.
CommandCallbackData * GetDoCommandCallback() override
Get the callback handling DoCommands in case of networking.
const char * GetMainScript() const
Get the filename of the main.nut script.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
const char * GetAPIVersion() const
Get the API version this AI is written for.
Commands
List of commands.
@ WL_WARNING
Other information.
std::vector< byte > CommandDataBuffer
Storage buffer for serialized command data.
void CcAI(Commands cmd, const CommandCost &result, const CommandDataBuffer &data, CommandDataBuffer result_data)
DoCommand callback function for all commands executed by AIs.
void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type)
Run the dummy AI and let it generate an error message.
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 char * GetURL() const
Get the website for this script.
HSQUIRRELVM GetVM()
Get the squirrel VM.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Common return value for all commands.
@ AI_DIR
Subdirectory for all AI files.
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.
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.
const char * GetInstanceName() const
Get the name of the instance of the script to create.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
CompanyID _current_company
Company currently doing an action.
void Died() override
Tell the script it died.
bool DoCommandCallback(const CommandCost &result, const CommandDataBuffer &data, CommandDataBuffer result_data, Commands cmd)
DoCommand callback function for all commands executed by scripts.
ScriptInfo * FindLibrary(const char *library, int version) override
Find a library.
Window * ShowAIDebugWindow(CompanyID show_company)
Open the AI debug window and select the given company.
virtual void Died()
Tell the script it died.
void Continue()
A script in multiplayer waits for the server to handle its DoCommand.
All static information from an AI like name, version, etc.
bool LoadCompatibilityScripts(const char *api_version, Subdirectory dir)
Load squirrel scripts to emulate an older API.
void RegisterAPI() override
Register all API functions to the VM.
All static information from an Script like name, version, etc.
const char * versionAPI
Current API used by this script.
@ SSS_FORCE_GAME
Get the Script config from the current game.
int GetSetting(const char *name) const override
Get the value of a setting for this config.
int GetSetting(const char *name) override
Get the value of a setting of the current instance.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)