OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #include "../stdafx.h"
12 #include "../script/squirrel_class.hpp"
16 #include "../string_func.h"
19 #include "../safeguards.h"
27 static const std::set<std::string> versions = {
"0.7",
"1.0",
"1.1",
"1.2",
"1.3",
"1.4",
"1.5",
"1.6",
"1.7",
"1.8",
"1.9",
"1.10",
"1.11",
"12",
"13",
"14",
"15" };
28 return versions.find(api_version) != versions.end();
34 template <>
const char *GetClassName<AIInfo, ScriptType::AI>() {
return "AIInfo"; }
40 SQAIInfo.PreRegister(
engine);
41 SQAIInfo.AddConstructor<void (
AIInfo::*)(), 1>(
engine,
"x");
56 SQAIInfo.PostRegister(
engine);
64 SQUserPointer instance =
nullptr;
65 if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance,
nullptr)) || instance ==
nullptr)
return sq_throwerror(vm,
"Pass an instance of a child class of AIInfo to RegisterAI");
69 if (res != 0)
return res;
86 Debug(script, 1,
"Loading info.nut from ({}.{}): GetAPIVersion returned invalid version", info->
GetName(), info->
GetVersion());
94 sq_setinstanceup(vm, 2,
nullptr);
103 SQUserPointer instance;
104 sq_getinstanceup(vm, 2, &instance,
nullptr);
106 info->
api_version = fmt::format(
"{}.{}",
GB(_openttd_newgrf_version, 28, 4),
GB(_openttd_newgrf_version, 24, 4));
109 if (res != 0)
return res;
112 sq_setinstanceup(vm, 2,
nullptr);
119 min_loadable_version(0),
126 if (
version == -1)
return true;
bool use_as_random
Should this AI be used when the user wants a "random AI"?
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
class Squirrel * engine
Engine used to register for Squirrel.
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
void AddClassBegin(const char *class_name)
Adds a class to the global scope.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
int version
Version of the script.
int min_loadable_version
The AI can load savegame data if the version is equal or greater than this.
void AddClassEnd()
Finishes adding a class to the global scope.
static const int MAX_GET_OPS
Number of operations to get the author and similar information.
void DefSQAdvancedMethod(Squirrel *engine, Func function_proc, const char *function_name)
This defines a method inside a class for Squirrel, which has access to the 'engine' (experts only!...
All static information from an AI library like name, version, etc.
@ SCRIPTCONFIG_NONE
No flags set.
bool CheckMethod(const char *name) const
Check if a given method exists.
std::string category
The category this library is in.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
const std::string & GetName() const
Get the Name of the script.
static SQInteger Constructor(HSQUIRRELVM vm)
Create an AI, using this AIInfo as start-template.
static SQInteger Constructor(HSQUIRRELVM vm)
Create an AI, using this AIInfo as start-template.
static bool CheckAPIVersion(const std::string &api_version)
Check if the API version provided by the AI is supported.
static SQInteger DummyConstructor(HSQUIRRELVM vm)
Create a dummy-AI.
void RegisterScript(class ScriptInfo *info)
Register a ScriptInfo to the scanner.
int GetVersion() const
Get the version of the script.
bool MethodExists(HSQOBJECT instance, const char *method_name)
Check if a method exists in an instance.
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam=0, const char *params=nullptr, void *userdata=nullptr, int size=0)
Adds a function to the stack.
std::string api_version
API version used by this AI.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
All static information from an AI like name, version, etc.
The template to define classes in Squirrel.
bool CanLoadFromVersion(int version) const
Check if we can start this AI.
HSQOBJECT SQ_instance
The Squirrel instance created for this info.
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.