|
static int | GetTick () |
| Find at which tick your script currently is.
|
|
static int | GetOpsTillSuspend () |
| Get the number of operations the script may still execute this tick.
|
|
static int | GetSetting (string name) |
| Get the value of one of your settings you set via info.nut.
|
|
static int | GetVersion () |
| Get the OpenTTD version of this executable.
|
|
static void | SetCommandDelay (int ticks) |
| Change the minimum amount of time the script should be put in suspend mode when you execute a command.
|
|
static void | Sleep (int ticks) |
| Sleep for X ticks.
|
|
static void | Break (string message) |
| Break execution of the script when script developer tools are active.
|
|
static void | Print (bool error_msg, string message) |
| When Squirrel triggers a print, this function is called.
|
|
static object | Import (string library, string class_name, int version) |
| Import a library.
|
|
The Controller, the class each AI should extend.
It creates the AI, makes sure the logic kicks in correctly, and that GetTick() has a valid value.
When starting a new game, or when loading a game, OpenTTD tries to match a script that matches to the specified version as close as possible. It tries (from first to last, stopping as soon as the attempt succeeds)
- load the latest version of the same script that supports loading data from the saved version (the version of saved data must be equal or greater than AIInfo::MinVersionToLoad),
- load the latest version of the same script (ignoring version requirements),
- (for AIs) load a random AI, and finally
- (for AIs) load the dummy AI.
After determining the script to use, starting it is done as follows
- An instance is constructed of the class derived from AIController (class name is retrieved from AIInfo::CreateInstance).
- If there is script data available in the loaded game and if the data is loadable according to AIInfo::MinVersionToLoad, Load is called with the data from the loaded game.
- Finally, Start is called to start execution of the script.
See also https://wiki.openttd.org/en/Development/AI/Save%20and%20Load for more details.
static int AIController::GetVersion |
( |
| ) |
|
|
static |
Get the OpenTTD version of this executable.
The version is formatted with the bits having the following meaning: 24-31 major version + 16. 20-23 minor version. 19 1 if it is a release, 0 if it is not. 0-18 revision number; 0 when the revision is unknown. You have to subtract 16 from the major version to get the correct value.
Prior to OpenTTD 12, the bits have the following meaning: 28-31 major version. 24-27 minor version. 20-23 build. 19 1 if it is a release, 0 if it is not. 0-18 revision number; 0 when the revision is unknown.
- Returns
- The version in newgrf format.
table AIController::Save |
( |
| ) |
|
Save the state of the script.
By implementing this function, you can store some data inside the savegame. The function should return a table with the information you want to store. You can only store:
- integers,
- strings,
- arrays (max. 25 levels deep),
- tables (max. 25 levels deep),
- booleans, and
- nulls.
In particular, instances of classes can't be saved including AIList. Such a list should be converted to an array or table on save and converted back on load.
The function is called as soon as the user saves the game, independently of other activities of the script. The script is not notified of the call. To avoid race-conditions between Save and the other script code, change variables directly after a Sleep, it is very unlikely, to get interrupted at that point in the execution. See also https://wiki.openttd.org/en/Development/AI/Save%20and%20Load for more details.
- Note
- No other information is saved than the table returned by Save. For example all pending events are lost as soon as the game is loaded.
- Returns
- Data of the script that should be stored in the save game.