Click or drag to resize

AI Class

Control Living AI from Lua. Note: this is currently broken.

AIs within the Anarkis Gaming engine are finite state machines.

Every game update call, OnCycleStart is called if functions are bound to it to determine whether the Action set for the Living's current AIState, if any, should be called. In the game, Actions are generally interrupted by needs (e.g. combat).

If the result of OnCycleStart is false (i.e. not interrupted), the Action is called that reflects the AI's current state (see AddAction(AIState, Closure)).

Then, the Transition function for the current AIState, if any, is called (see AddTransition(AIState, Closure)). This is where you should check the environment and the result of the Action to determine whether you should switch states.

Finally, OnCycleEnd is called, if any functions are bound to it.

Inheritance Hierarchy
SystemObject
  Mannequin.BindingsAI

Namespace:  Mannequin.Bindings
Assembly:  Collapse (in Collapse.exe) Version: 0.4.6.1290 (0.4.6.1290)
Syntax
C#
public class AI

The AI type exposes the following members.

Constructors
  NameDescription
Public methodAI
Create a custom (flexible) AI component.
Public methodAI(String)
Create an AI component from one that exists in the game already.
Top
Properties
  NameDescription
Public propertyIsFlexible
Whether this is a custom (flexible) AI
Public propertyOnCycleEnd
Function to run when an AI cycle ends (after each update).

Note Note
This is only currently supported for custom (flexible) AI schemes.

void OnCycleEnd(AI ai, Int32 gameTime)

Public propertyOnCycleStart
Function to run when an AI cycle starts (before each update). Useful for interupting logic (i.e. when combat occurs). Return true here to skip this cycle.

Note Note
This is only currently supported for custom (flexible) AI schemes.

Boolean (default false) OnCycleStart(AI ai, int gameTime)

Public propertyState
This AI's AIState.
Top
Methods
  NameDescription
Public methodAddAction(AIState, Job)
Assign an Action to a Job to run while this AI is in a certain AIState. This is really just replacing boilerplate code and could resolve to

myJob = Job()

myAI:AddAction(EAIState.None, function()
    if Job.IsComplete then return EJobResult.Success
    else return EJobResult.InProgress
    end
end)

Public methodAddAction(AIState, Closure)
A function to call every update while this AI is in a certain AIState.
Public methodAddTransition
Check the environment and change AIStates if necessary
Public methodAttachToAgent
Attach this AI component to a Living.
Top
See Also