Class AI
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 EAIState, 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(EAIState, Closure)).
Then, the Transition function for the current EAIState, if any, is called (see AddTransition(EAIState, 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
Namespace: Mannequin.Bindings
Assembly: Collapse.dll
Syntax
public class AI : object
Constructors
AI()
Create a custom (flexible) AI component.
Declaration
public AI()
AI(String)
Create an AI component from one that exists in the game already.
Declaration
public AI(string template)
Parameters
Type | Name | Description |
---|---|---|
System.String | template | The template AI |
Properties
IsFlexible
Whether this is a custom (flexible) AI
Declaration
public bool IsFlexible { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
OnCycleEnd
Function to run when an AI cycle ends (after each update).
note
This is only currently supported for custom (flexible) AI schemes.
void OnCycleEnd(AI ai,
Declaration
public Closure OnCycleEnd { get; set; }
Property Value
Type | Description |
---|---|
Closure |
OnCycleStart
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
This is only currently supported for custom (flexible) AI schemes.
Declaration
public Closure OnCycleStart { get; set; }
Property Value
Type | Description |
---|---|
Closure |
State
This AI's EAIState.
Declaration
public EAIState State { get; set; }
Property Value
Type | Description |
---|---|
EAIState |
Methods
AddAction(EAIState, Closure)
A function to call every update while this AI is in a certain EAIState.
Declaration
public void AddAction(EAIState state, Closure action)
Parameters
Type | Name | Description |
---|---|---|
EAIState | state | The EAIState to bind to |
Closure | action | JobResult (default None) OnAction(AI ai) The function to call |
AddAction(EAIState, Job)
Assign an Action to a Job to run while this AI is in a certain EAIState. 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)
Declaration
public void AddAction(EAIState state, Job action)
Parameters
Type | Name | Description |
---|---|---|
EAIState | state | The EAIState to bind to |
Job | action | The Job to run |
AddTransition(EAIState, Closure)
Check the environment and change AIStates if necessary
Declaration
public void AddTransition(EAIState to, Closure transition)
Parameters
Type | Name | Description |
---|---|---|
EAIState | to | The target EAIState |
Closure | transition | void OnTransitionTo(EAIState from, JobResult previousJobResult) The function to call |
AttachToAgent(Living)
Attach this AI component to a Living.
Declaration
public void AttachToAgent(Living living)
Parameters
Type | Name | Description |
---|---|---|
Living | living | The Living to attach this AI component to |