Runtime information about an AI like a pointer to the squirrel vm and the current state. More...
#include <ai_instance.hpp>
Public Member Functions | |
| AIInstance (class AIInfo *info) | |
| void | Continue () |
| An AI in multiplayer waits for the server to handle his DoCommand. | |
| void | GameLoop () |
| Run the GameLoop of an AI. | |
| void | CollectGarbage () const |
| Let the VM collect any garbage. | |
| class AIController * | GetController () |
| Get the controller attached to the instance. | |
| bool | IsDead () const |
| Return the "this AI died" value. | |
| void | Save () |
| Call the AI Save function and save all data in the savegame. | |
| void | Load (int version) |
| Load data from a savegame and store it on the stack. | |
| bool | CallLoad () |
| Call the AI Load function if it exists and data was loaded from a savegame. | |
| void | Suspend () |
| Reduces the number of opcodes the AI have left to zero. | |
Static Public Member Functions | |
| static class AIStorage * | GetStorage () |
| Get the storage of this AI. | |
| static void | DoCommandReturn (AIInstance *instance) |
| Return a true/false reply for a DoCommand. | |
| static void | DoCommandReturnVehicleID (AIInstance *instance) |
| Return a VehicleID reply for a DoCommand. | |
| static void | DoCommandReturnSignID (AIInstance *instance) |
| Return a SignID reply for a DoCommand. | |
| static void | DoCommandReturnGroupID (AIInstance *instance) |
| Return a GroupID reply for a DoCommand. | |
| static void | SaveEmpty () |
| Don't save any data in the savegame. | |
| static void | LoadEmpty () |
| Load and discard data from a savegame. | |
Private Member Functions | |
| void | RegisterAPI () |
| Register all API functions to the VM. | |
| bool | LoadCompatibilityScripts (const char *api_version) |
| Load squirrel scripts to emulate an older API. | |
| void | Died () |
| Tell the AI it died. | |
Static Private Member Functions | |
| static bool | SaveObject (HSQUIRRELVM vm, SQInteger index, int max_depth, bool test) |
| Save one object (int / string / array / table) to the savegame. | |
| static bool | LoadObjects (HSQUIRRELVM vm) |
| Load all objects from a savegame. | |
Private Attributes | |
| class AIController * | controller |
| The AI main class. | |
| class AIStorage * | storage |
| Some global information for each running AI. | |
| class Squirrel * | engine |
| A wrapper around the squirrel vm. | |
| SQObject * | instance |
| Squirrel-pointer to the AI main class. | |
| bool | is_started |
| Is the AIs constructor executed? | |
| bool | is_dead |
| True if the AI has been stopped. | |
| bool | is_save_data_on_stack |
| Is the save data still on the squirrel stack? | |
| int | suspend |
| The amount of ticks to suspend this AI before it's allowed to continue. | |
| AISuspendCallbackProc * | callback |
| Callback that should be called in the next tick the AI runs. | |
Friends | |
| class | AIObject |
Runtime information about an AI like a pointer to the squirrel vm and the current state.
Definition at line 65 of file ai_instance.hpp.
| void AIInstance::Continue | ( | ) |
An AI in multiplayer waits for the server to handle his DoCommand.
It keeps waiting for this until this function is called.
Definition at line 287 of file ai_instance.cpp.
References suspend.
| void AIInstance::Load | ( | int | version | ) |
Load data from a savegame and store it on the stack.
| version | The version of the AI when saving, or -1 if this was not the original AI saving the game. |
Definition at line 739 of file ai_instance.cpp.
References engine, Squirrel::GetVM(), is_save_data_on_stack, LoadEmpty(), LoadObjects(), and SlObject().
Referenced by AI::Load().
| bool AIInstance::LoadObjects | ( | HSQUIRRELVM | vm | ) | [static, private] |
Load all objects from a savegame.
Definition at line 673 of file ai_instance.cpp.
References SlArray(), SlObject(), SQSL_ARRAY, SQSL_ARRAY_TABLE_END, SQSL_BOOL, SQSL_INT, SQSL_NULL, SQSL_STRING, and SQSL_TABLE.
Referenced by Load(), and LoadEmpty().
| bool AIInstance::SaveObject | ( | HSQUIRRELVM | vm, | |
| SQInteger | index, | |||
| int | max_depth, | |||
| bool | test | |||
| ) | [static, private] |
Save one object (int / string / array / table) to the savegame.
| vm | The virtual machine to get all the data from. | |
| index | The index on the squirrel stack of the element to save. | |
| max_depth | The maximum depth recursive arrays / tables will be stored with before an error is returned. | |
| test | If true, don't really store the data but only check if it is valid. |
Definition at line 473 of file ai_instance.cpp.
References AILog::Error(), SlArray(), and SlObject().
Referenced by Save().
| void AIInstance::Suspend | ( | ) |
Reduces the number of opcodes the AI have left to zero.
Unless the AI is in a state where it cannot suspend it will be suspended for the reminder of the current tick. This function is safe to call from within a function called by the AI.
Definition at line 667 of file ai_instance.cpp.
References _settings_game, GameSettings::ai, AISettings::ai_max_opcode_till_suspend, Squirrel::DecreaseOps(), engine, and Squirrel::GetVM().
1.7.1