Skip to main content

Agent<TThis>

An abstract class in Root.Township, Alta.Intelligence.

Base for a creature AI that picks actions from an ActionDecider. The AI runs only on the server: it is initialized in InitializeAsServer and updated by AgentUpdater. Concrete creatures such as Wyrm pass themselves as TThis.

Constructors​

MemberWhat it is
protected Agent()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

3 private and internal fields
MemberWhat it is
private Dictionary<ActionComponentSet, ActionSet<TThis>> actionComponentSetsCache of action sets built from each ActionComponentSet this creature has used.
private Dictionary<ActionComponent, IAction<TThis>> actionsCache of actions built from each ActionComponent started directly on this creature.
private ActionTarget<TThis> currentActionThe action and target the creature is running now. Target reads from it.

Properties​

MemberWhat it is
ActionDecider<TThis> ActionDecider { get; private set; }Picks the best action and target from the current possibility set. Created in InitializeAi.
override IActionDecider GeneralActionDecider { get; }The action decider, as the non-generic interface.
static bool IsStaticInitialized { get; private set; }True once InitializeStatic has run for this agent type.
static int SpawnedCount { get; private set; }Number of agents of this type alive in the scene.
override ITarget Target { get; }The current action's target.

Methods​

MemberWhat it is
override void DoAction(ActionComponent action, ITarget target)Starts a specific action component against a target.
void PreviewAction(ActionTarget<TThis> newAction)Starts the given action straight away.
override void UseActionComponentSet(ActionComponentSet set)Switches the decider to the actions from the given set, caching the built set.
protected override void Awake()Counts the spawn and keeps the pathfinding walker off until the AI starts.
protected override bool ChangeAction()Updates target collectors and starts the best action that beats the current one's cancel priority and weighting.
protected override void InitializeAi()Server: runs InitializeStatic once per type, turns on the walker and creates the action decider.
protected virtual void InitializeStatic()Hook for shared setup, run once per agent type on the first spawn.
protected virtual void OnDestroy()Lowers SpawnedCount.
protected bool StartAction(ActionTarget<TThis> newAction)Cancels the current action and starts a new one, or restarts it if it is the same action and target.
1 private and internal method
MemberWhat it is
private ActionTarget<TThis> GetBestAction(int minimumPriority, float minimumWeighting)Asks the ActionDecider for the best action above the given cancel priority and weighting.