# AIInstance Class Reference

## 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.

## 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 scipts 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 / arrray / table) to the savegame.
static bool | LoadObjects (HSQUIRRELVM vm)
| Load all objects from a savegame.

## Private Attributes

class AIController * | controller
class AIStorage * | storage
class Squirrel * | engine
SQObject * | instance
bool | is_started
bool | is_dead
bool | is_save_data_on_stack
int | suspend
AISuspendCallbackProc * | callback

## Friends

class | AIObject

## Detailed Description

Definition at line 55 of file ai_instance.hpp.

## Member Function Documentation

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 280 of file ai_instance.cpp.

void AIInstance::Load | ( | int | version | ) |

Load data from a savegame and store it on the stack.

Parameters:

  | version | The version of the AI when saving, or -1 if this was not the original AI saving the game.

Definition at line 727 of file ai_instance.cpp.

References Squirrel::GetVM(), LoadEmpty(), LoadObjects(), and SlObject().

Referenced by AI::Load().

bool AIInstance::LoadObjects | ( | HSQUIRRELVM | vm | ) | `[static, private]`

Load all objects from a savegame.

Returns:
  True if the loading was successfull.

Definition at line 661 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 / arrray / table) to the savegame.

Parameters:

  | 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.

Returns:
  True if the saving was successfull.

Definition at line 467 of file ai_instance.cpp.

References AILog::Error(), SlArray(), SlObject(), SQSL_ARRAY, SQSL_ARRAY_TABLE_END, SQSL_BOOL, SQSL_INT, SQSL_NULL, SQSL_STRING, and SQSL_TABLE.

Referenced by Save().

The documentation for this class was generated from the following files:

- src/ai/ai_instance.hpp
- src/ai/ai_instance.cpp