OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
14 #include "../script/squirrel_class.hpp"
20 #include "../script/script_storage.hpp"
25 #include "../script/api/template/template_text.hpp.sq"
28 #include "../script/api/ai/ai_includes.hpp"
30 #include "../company_base.h"
31 #include "../company_func.h"
33 #include "../safeguards.h"
35 AIInstance::AIInstance() :
44 SQAIController_Register(this->
engine);
54 SQAI_RegisterAll(this->
engine);
66 if (info !=
nullptr) {
69 if (info->
GetURL() !=
nullptr) {
70 ScriptLog::Info(
"Please report the error to the following URL:");
71 ScriptLog::Info(info->
GetURL());
110 if (c ==
nullptr || c->ai_instance ==
nullptr)
return;
static class AILibrary * FindLibrary(const char *library, int version)
Wrapper function for AIScanner::FindLibrary.
uint32 TileIndex
The index/ID of a Tile.
class Squirrel * engine
A wrapper around the squirrel vm.
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.
bool DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
DoCommand callback function for all commands executed by scripts.
@ WL_WARNING
Other information.
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.
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.
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.
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.
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.
CommandCallback * GetDoCommandCallback() override
Get the callback handling DoCommands in case of networking.
bool LoadCompatibilityScripts(const char *api_version, Subdirectory dir)
Load squirrel scripts to emulate an older API.
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
DoCommand callback function for all commands executed by AIs.
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)