OpenTTD AI API
20241130-master-g8d394c697c
|
'Abstract' class of the AIs use to register themselves. More...
Public Types | |
enum | AIConfigFlags { CONFIG_NONE , CONFIG_BOOLEAN , CONFIG_INGAME , CONFIG_DEVELOPER } |
Miscellaneous flags for AI settings. More... | |
Public Member Functions | |
string | GetAuthor () |
Gets the author name to be shown in the 'Available AIs' window. More... | |
string | GetName () |
Gets the AIs name. More... | |
string | GetShortName () |
Gets a 4 ASCII character short name of the AI to uniquely identify it from other AIs. More... | |
string | GetDescription () |
Gets the description to be shown in the 'Available AIs' window. More... | |
int | GetVersion () |
Gets the version of the AI. More... | |
int | MinVersionToLoad () |
Gets the lowest version of the AI that OpenTTD can still load the savegame of. More... | |
string | GetDate () |
Gets the development/release date of the AI. More... | |
bool | UseAsRandomAI () |
Can this AI be used as random AI? More... | |
string | CreateInstance () |
Gets the name of main class of the AI so OpenTTD knows what class to instantiate. More... | |
string | GetAPIVersion () |
Gets the API version this AI is written for. More... | |
string | GetURL () |
Gets the URL to be shown in the 'this AI has crashed' message and in the 'Available AIs' window. More... | |
void | GetSettings () |
Gets the settings that OpenTTD shows in the "AI Parameters" window so the user can customize the AI. More... | |
void | AddSetting (table setting_description) |
Add a user configurable setting for this AI. More... | |
void | AddLabels (string setting_name, table value_names) |
Add labels for the values of a setting. More... | |
'Abstract' class of the AIs use to register themselves.
Miscellaneous flags for AI settings.
void AIInfo::AddLabels | ( | string | setting_name, |
table | value_names | ||
) |
Add labels for the values of a setting.
Instead of a number the user will see the corresponding name.
setting_name | The name of the setting. |
value_names | A table that maps values to names. The first character of every identifier is ignored, the second character could be '_' to indicate the value is negative, and the rest should be an integer of the value you define a name for. The value is a short description of that value. To define labels for a setting named "competition_level" you could for example call it like this: AddLabels("competition_level", {_0 = "no competition", _1 = "some competition", _2 = "a lot of competition"}); Another example, for a setting with a negative value: AddLabels("amount", {__1 = "less than one", _0 = "none", _1 = "more than one"}); |
void AIInfo::AddSetting | ( | table | setting_description | ) |
Add a user configurable setting for this AI.
You can call this as many times as you have settings.
setting_description | A table with all information about a single setting. The table should have the following name/value pairs:
|
string AIInfo::CreateInstance | ( | ) |
Gets the name of main class of the AI so OpenTTD knows what class to instantiate.
For libraries, this name is also used when other scripts import it using AIController::Import.
string AIInfo::GetAPIVersion | ( | ) |
Gets the API version this AI is written for.
If this function does not exist API compatibility with version 0.7 is assumed. If the function returns something OpenTTD does not understand, for example a newer version or a string that is not a version, the AI will not be loaded.
Although in the future we might need to make a separate compatibility 'wrapper' for a specific version of OpenTTD, for example '0.7.1', we will use only the major and minor number and not the bugfix number as valid return for this function.
Valid return values are:
string AIInfo::GetAuthor | ( | ) |
Gets the author name to be shown in the 'Available AIs' window.
string AIInfo::GetDate | ( | ) |
Gets the development/release date of the AI.
The intention of this is to give the user an idea how old the AI is and whether there might be a newer version.
string AIInfo::GetDescription | ( | ) |
Gets the description to be shown in the 'Available AIs' window.
string AIInfo::GetName | ( | ) |
Gets the AIs name.
This is shown in the 'Available AIs' window and at all other places where the AI is mentioned, like the debug window or OpenTTD's help message. The name is used to uniquely identify an AI within OpenTTD and this name is used in savegames and the configuration file.
void AIInfo::GetSettings | ( | ) |
Gets the settings that OpenTTD shows in the "AI Parameters" window so the user can customize the AI.
This is a special function that doesn't need to return anything. Instead you can call AddSetting and AddLabels here.
string AIInfo::GetShortName | ( | ) |
Gets a 4 ASCII character short name of the AI to uniquely identify it from other AIs.
The short name is primarily used as unique identifier for the content system. The content system uses besides the short name also the MD5 checksum of all the source files to uniquely identify a specific version of the AI.
The short name must consist of precisely four ASCII characters, or more precisely four non-zero bytes.
string AIInfo::GetURL | ( | ) |
Gets the URL to be shown in the 'this AI has crashed' message and in the 'Available AIs' window.
If this function does not exist no URL will be shown.
This function purely exists to redirect users of the AI to the right place on the internet to discuss the AI and report bugs of this AI.
int AIInfo::GetVersion | ( | ) |
Gets the version of the AI.
This is a number to (in theory) uniquely identify the versions of an AI. Generally the 'instance' of an AI with the highest version is chosen to be loaded.
When OpenTTD finds, during starting, a duplicate AI with the same version number one is randomly chosen. So it is important that this number is regularly updated/incremented.
int AIInfo::MinVersionToLoad | ( | ) |
Gets the lowest version of the AI that OpenTTD can still load the savegame of.
In other words, from which version until this version can the AI load the savegames.
If this function does not exist OpenTTD assumes it can only load savegames of this version. As such it will not upgrade to this version upon load.
bool AIInfo::UseAsRandomAI | ( | ) |
Can this AI be used as random AI?
The idea behind this function is to 'forbid' highly competitive or other special AIs from running in games unless the user explicitly selects the AI to be loaded. This to try to prevent users from complaining that the AI is too aggressive or does not build profitable routes.
If this function does not exist OpenTTD assumes the AI can be used as random AI. As such it will be randomly chosen.