12#include "../script/squirrel_class.hpp"
16#include "../string_func.h"
19#include "../safeguards.h"
27 return std::ranges::find(AIInfo::ApiVersions, api_version) != std::end(AIInfo::ApiVersions);
30template <> SQInteger PushClassName<AIInfo, ScriptType::AI>(HSQUIRRELVM vm) { sq_pushstring(vm,
"AIInfo");
return 1; }
36 SQAIInfo.PreRegister(
engine);
37 SQAIInfo.AddConstructor<void (
AIInfo::*)(), 1>(
engine,
"x");
52 SQAIInfo.PostRegister(
engine);
60 SQUserPointer instance =
nullptr;
61 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");
65 if (res != 0)
return res;
83 Debug(script, 1,
"Loading info.nut from ({}.{}): GetAPIVersion returned invalid version", info->
GetName(), info->
GetVersion());
91 sq_setinstanceup(vm, 2,
nullptr);
100 SQUserPointer instance;
101 sq_getinstanceup(vm, 2, &instance,
nullptr);
103 info->
api_version = *std::rbegin(AIInfo::ApiVersions);
106 if (res != 0)
return res;
109 sq_setinstanceup(vm, 2,
nullptr);
116 min_loadable_version(0),
123 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
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.
std::string category
The category this library is in.
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.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
The template to define classes in Squirrel.
void DefSQAdvancedMethod(Squirrel &engine, Func function_proc, std::string_view function_name)
This defines a method inside a class for Squirrel, which has access to the 'engine' (experts only!...
bool CheckMethod(std::string_view name) const
Check if a given method exists.
int version
Version of the script.
const std::string & GetName() const
Get the Name of the script.
class Squirrel * engine
Engine used to register for Squirrel.
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo &info)
Process the creation of a FileInfo object.
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.
HSQOBJECT SQ_instance
The Squirrel instance created for this info.
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.
void RegisterScript(class ScriptInfo *info)
Register a ScriptInfo to the scanner.
void AddClassEnd()
Finishes adding a class to the global scope.
void AddClassBegin(std::string_view class_name)
Adds a class to the global scope.
void AddMethod(std::string_view method_name, SQFUNCTION proc, std::string_view params={}, void *userdata=nullptr, int size=0)
Adds a function to the stack.
bool MethodExists(HSQOBJECT instance, std::string_view method_name)
Check if a method exists in an instance.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
@ Boolean
This value is a boolean (either 0 (false) or 1 (true) ).
@ Developer
This setting will only be visible when the Script development tools are active.
@ InGame
This setting can be changed while the Script is running.
static const int MAX_GET_OPS
Number of operations to get the author and similar information.