Skip to content

SRD: AI Functions

Teekius edited this page Mar 15, 2025 · 4 revisions

This page provides an overview of Spellforce Framework functions which are used to control units AI, for example, make units utilize custom spells you have created using the Spellforce Framework.

These functions are taken from the sf_ai_functions.h header file. Please, note that you don't need to include that header in your project. It is automatically included as part of the sfsf.h general interface.

This page is up-to date for version of the Spellforce Framework 2.0.0-beta.


Below listed all functions you can find in sf_toolbox_functions.h. The toolbox functions can be accessed using aiAPI-> prefix, provided this group was previously initialized. In order to initialize the toolbox functions you should,

  1. Declare a pointer for the AI functions within global variables of your project. This is done as follows: AiFunctions *aiAPI;

  2. Assign this pointer the address of AI Functions within the main structure of the Spellforce Framework. Usually this is done as part of InitModule function after the framework was initialized. This is done in the following way: aiAPI = sfsf->aiAPI;

Functions

AC60AddOrGetEntity

Parameters:

_autoclass60: Pointer to the autoclass.
entity_index: Index of the entity.

Function Signature:

void *AC60AddOrGetEntity(void *_autoclass60, uint16_t entity_index);

Example Usage:


canFigureDoAction

Parameters:

_this: Pointer to the battle development global object.
action: Pointer to the action being verified.

Function Signature:

bool canFigureDoAction(SF_CGdBattleDevelopment *_this, SF_SGtFigureAction *action);

Example Usage:


getActionStats

Parameters:

_this: Pointer to the battle development global object.
minRange: Pointer to store the minimum range.
maxRange: Pointer to store the maximum range.
spellData: Pointer to the resource spell data.

Function Signature:

void getActionStats(SF_CGdBattleDevelopment *_this, uint16_t *minRange, uint16_t *maxRange, SF_CGdResourceSpell *spellData);

Example Usage:


getAICurrentActionRanking

Parameters:

_this: Pointer to the battle development global object.

Function Signature:

int getAICurrentActionRanking(SF_CGdBattleDevelopment *_this);

Example Usage:


getAIVectorFirstElement

Parameters:

_this: Pointer to the global object.
pvalue: Pointer to store the value of the first element.

Function Signature:

uint16_t **getAIVectorFirstElement(void *_this, uint16_t **pvalue);

Example Usage:


getAIVectorGetCurrent

Parameters:

_this: Pointer to the global object.
value: Pointer to store the current value.

Function Signature:

uint16_t **getAIVectorGetCurrent(void *_this, uint16_t **value);

Example Usage:


getAIVectorLength

Parameters:

_this: Pointer to the global object.

Function Signature:

int getAIVectorLength(void *_this);

Example Usage:


getCastType

Parameters:

resource: Pointer to the resource being used.
spellID: ID of the spell for which the cast type is being determined.

Function Signature:

uint16_t getCastType(void* resource, uint16_t spellID);

Example Usage:


getFigureAction

Parameters:

figure: Pointer to the figure from which the action is being retrieved.
action: Pointer to the action being referenced.
figure_id: ID of the figure.
action_index: Index of the action in the figure's actions.

Function Signature:

SF_SGtFigureAction *getFigureAction(SF_CGdFigure *figure, SF_SGtFigureAction *action, uint16_t figure_id, uint8_t action_index);

Example Usage:


getPositionToCastAlly

Parameters:

_this: Pointer to the battle development global object.
param_1: Pointer to store the coordinates.
std_vector_uint16_t: Pointer to the standard vector of uint16_t.

Function Signature:

SF_Coord *getPositionToCastAlly(SF_CGdBattleDevelopment *_this, SF_Coord *param_1, void *std_vector_uint16_t);

Example Usage:


getPositionToCastEnemy

Parameters:

_this: Pointer to the battle development global object.
param_1: Pointer to store the coordinates.
std_vector_uint16_t: Pointer to the standard vector of uint16_t.

Function Signature:

SF_Coord *getPositionToCastEnemy(SF_CGdBattleDevelopment *_this, SF_Coord *param_1, void *std_vector_uint16_t);

Example Usage:


getTargetAction

Parameters:

figure: Pointer to the figure for which the action is being retrieved.
action: Pointer to the action being targeted.
figure_id: ID of the figure.

Function Signature:

SF_SGtFigureAction *getTargetAction(SF_CGdFigure *figure, SF_SGtFigureAction *action, uint16_t figure_id);

Example Usage:


isAIVectorEmpty

Parameters:

_this: Pointer to the global object.

Function Signature:

bool isAIVectorEmpty(void *_this);

Example Usage:


isUnknownWorldFeature

Parameters:

toolBox: Pointer to the world toolbox.
figure_index: Index of the figure.
param2: Pointer to the first coordinate parameter.
param3: Pointer to the second coordinate parameter.
param4: A parameter of type uint32_t.
param5: Pointer to the fifth coordinate parameter.
param6: Another parameter of type uint16_t.

Function Signature:

bool isUnknownWorldFeature(SF_CGdWorldToolBox *toolBox, uint16_t figure_index, SF_Coord *param2, SF_Coord *param3, uint32_t param4, SF_Coord *param5, uint16_t param6);

Example Usage:


setAICurrentActionRanking

Parameters:

_this: Pointer to the battle development global object.
rank: The rank to be assigned to the action.

Function Signature:

void setAICurrentActionRanking(SF_CGdBattleDevelopment *_this, int rank);

Example Usage:

Types

CGdAIBattleData

    SF_CGdBuilding *CGdBuilding;                /**< Pointer to the building data. */
    void *CGdBuildingToolBox;                   /**< ToolBox for managing building-related operations. */
    SF_CGdFigure *CGdFigure;                    /**< Pointer to the Global Figure data structure . */
    SF_CGdFigureJobs *CGdFigureJobs;            /**< Pointer to the Global Figure Job data structure. */
    SF_CGdFigureToolbox *CGdFigureToolBox;      /**< Toolbox for figure-related operations. */

SF_CGdBattleDevelopment

{
    void *vfTable;                  /**< Virtual function table pointer. */
    void *battleFactory;            /**< Pointer to the battle factory object. */
    CGdAIBattleData battleData;     /**< Detailed AI battle data. */
} 

Clone this wiki locally