OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
12 #include "../script/squirrel_class.hpp"
16 #include "../string_func.h"
20 #include "../safeguards.h"
28 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" };
29 return versions.find(api_version) != versions.end();
35 template <>
const char *GetClassName<AIInfo, ST_AI>() {
return "AIInfo"; }
41 SQAIInfo.PreRegister(
engine);
42 SQAIInfo.AddConstructor<void (
AIInfo::*)(), 1>(
engine,
"x");
57 SQAIInfo.PostRegister(
engine);
65 SQUserPointer instance =
nullptr;
66 if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance ==
nullptr)
return sq_throwerror(vm,
"Pass an instance of a child class of AIInfo to RegisterAI");
70 if (res != 0)
return res;
92 DEBUG(script, 1,
"Loading info.nut from (%s.%d): GetAPIVersion returned invalid version", info->
GetName(), info->
GetVersion());
100 sq_setinstanceup(vm, 2,
nullptr);
109 SQUserPointer instance;
110 sq_getinstanceup(vm, 2, &instance, 0);
115 if (res != 0)
return res;
118 seprintf(buf,
lastof(buf),
"%d.%d",
GB(_openttd_newgrf_version, 28, 4),
GB(_openttd_newgrf_version, 24, 4));
122 sq_setinstanceup(vm, 2,
nullptr);
129 min_loadable_version(0),
130 use_as_random(false),
142 if (
version == -1)
return true;
147 AILibrary::~AILibrary()
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.
ScriptConfigItem _start_date_config
Configuration for AI start date, every AI has this setting.
class Squirrel * engine
Engine used to register for Squirrel.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
const char * api_version
API version used by this AI.
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) ).
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.
#define DEBUG(name, level,...)
Output a line of debugging information.
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.
@ 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.
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.
ScriptConfigItemList config_list
List of settings from this Script.
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.
const char * description
The description of the configuration 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.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
@ SCRIPTCONFIG_RANDOM
When randomizing the Script, pick any value between min_value and max_value when on custom difficulty...
All static information from an AI like name, version, etc.
HSQOBJECT * SQ_instance
The Squirrel instance created for this info.
The template to define classes in Squirrel.
bool CanLoadFromVersion(int version) const
Check if we can start this AI.
const char * GetName() const
Get the Name of the script.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Info about a single Script setting.
const char * name
The name of the configuration setting.
#define lastof(x)
Get the last element of an fixed size array.
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.
const char * category
The category this library is in.
static bool CheckAPIVersion(const char *api_version)
Check if the API version provided by the AI is supported.