12 #include "../stdafx.h" 14 #include "../script/squirrel_class.hpp" 18 #include "../string_func.h" 21 #include "../safeguards.h" 29 return strcmp(api_version,
"0.7") == 0 || strcmp(api_version,
"1.0") == 0 || strcmp(api_version,
"1.1") == 0 ||
30 strcmp(api_version,
"1.2") == 0 || strcmp(api_version,
"1.3") == 0 || strcmp(api_version,
"1.4") == 0 ||
31 strcmp(api_version,
"1.5") == 0 || strcmp(api_version,
"1.6") == 0 || strcmp(api_version,
"1.7") == 0 ||
32 strcmp(api_version,
"1.8") == 0;
38 template <>
const char *GetClassName<AIInfo, ST_AI>() {
return "AIInfo"; }
44 SQAIInfo.PreRegister(engine);
45 SQAIInfo.AddConstructor<void (
AIInfo::*)(), 1>(engine,
"x");
60 SQAIInfo.PostRegister(engine);
68 SQUserPointer instance = NULL;
69 if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == NULL)
return sq_throwerror(vm,
"Pass an instance of a child class of AIInfo to RegisterAI");
73 if (res != 0)
return res;
95 DEBUG(script, 1,
"Loading info.nut from (%s.%d): GetAPIVersion returned invalid version", info->
GetName(), info->
GetVersion());
103 sq_setinstanceup(vm, 2, NULL);
112 SQUserPointer instance;
113 sq_getinstanceup(vm, 2, &instance, 0);
118 if (res != 0)
return res;
121 seprintf(buf,
lastof(buf),
"%d.%d",
GB(_openttd_newgrf_version, 28, 4),
GB(_openttd_newgrf_version, 24, 4));
125 sq_setinstanceup(vm, 2, NULL);
145 if (version == -1)
return true;
150 AILibrary::~AILibrary()
152 free(this->category);
int GetVersion() const
Get the version of the script.
This setting will only be visible when the Script development tools are active.
void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam=0, const char *params=NULL, void *userdata=NULL, int size=0)
Adds a function to the stack.
static SQInteger Constructor(HSQUIRRELVM vm)
Create an AI, using this AIInfo as start-template.
int version
Version of the script.
HSQOBJECT * SQ_instance
The Squirrel instance created for this info.
bool CheckMethod(const char *name) const
Check if a given method exists.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
const char * GetName() const
Get the Name of the script.
ScriptConfigItemList config_list
List of settings from this Script.
static bool CheckAPIVersion(const char *api_version)
Check if the API version provided by the AI is supported.
bool use_as_random
Should this AI be used when the user wants a "random AI"?
#define lastof(x)
Get the last element of an fixed size array.
ScriptConfigItem _start_date_config
Configuration for AI start date, every AI has this setting.
declarations of the class for AI scanner
The template to define classes in Squirrel.
static SQInteger Constructor(HSQUIRRELVM vm)
Create an AI, using this AIInfo as start-template.
const char * api_version
API version used by this AI.
void RegisterScript(class ScriptInfo *info)
Register a ScriptInfo to the scanner.
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
static SQInteger DummyConstructor(HSQUIRRELVM vm)
Create a dummy-AI.
All static information from an AI library like name, version, etc.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
int min_loadable_version
The AI can load savegame data if the version is equal or greater than this.
When randomizing the Script, pick any value between min_value and max_value when on custom difficulty...
This value is a boolean (either 0 (false) or 1 (true) ).
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.
bool CanLoadFromVersion(int version) const
Check if we can start this AI.
const char * description
The description of the configuration setting.
#define DEBUG(name, level,...)
Output a line of debugging information.
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
All static information from an AI like name, version, etc.
Info about a single Script setting.
const char * category
The category this library is in.
static const int MAX_GET_OPS
Number of operations to get the author and similar information.
bool MethodExists(HSQOBJECT instance, const char *method_name)
Check if a method exists in an instance.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
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!)...
void AddClassBegin(const char *class_name)
Adds a class to the global scope.
This setting can be changed while the Script is running.
class Squirrel * engine
Engine used to register for Squirrel.
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
AIInfo keeps track of all information of an AI, like Author, Description, ...
void AddClassEnd()
Finishes adding a class to the global scope.
const char * name
The name of the configuration setting.