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;
static bool CheckAPIVersion(const std::string &api_version)
Check if the API version provided by the AI is supported.
AIInfo keeps track of all information of an AI, like Author, Description, ...
declarations of the class for AI scanner
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.
All static information from an AI like name, version, etc.
bool CanLoadFromVersion(int version) const
Check if we can start this AI.
bool use_as_random
Should this AI be used when the user wants a "random AI"?
int min_loadable_version
The AI can load savegame data if the version is equal or greater than this.
std::string api_version
API version used by this AI.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
static SQInteger Constructor(HSQUIRRELVM vm)
Create an AI, using this AIInfo as start-template.
static SQInteger DummyConstructor(HSQUIRRELVM vm)
Create a dummy-AI.
All static information from an AI library like name, version, etc.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
std::string category
The category this library is in.
static SQInteger Constructor(HSQUIRRELVM vm)
Create an AI, using this AIInfo as start-template.
The template to define classes in Squirrel.
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!...
int version
Version of the script.
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.
bool CheckMethod(const char *name) const
Check if a given method exists.
class Squirrel * engine
Engine used to register for Squirrel.
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
int GetVersion() const
Get the version of the script.
const std::string & GetName() const
Get the Name of the script.
HSQOBJECT SQ_instance
The Squirrel instance created for this info.
void RegisterScript(class ScriptInfo *info)
Register a ScriptInfo to the scanner.
void AddClassEnd()
Finishes adding a class to the global scope.
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.
void AddClassBegin(const char *class_name)
Adds a class to the global scope.
bool MethodExists(HSQOBJECT instance, const char *method_name)
Check if a method exists in an instance.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
@ SCRIPTCONFIG_NONE
No flags set.
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
static const int MAX_GET_OPS
Number of operations to get the author and similar information.