PathfindAction - Ellpeck/TinyLifeExampleMod Wiki

Tiny Life


PathfindAction Class

A pathfinding action is an action that first finds a path and then allows that path to be traversed.
The pathfinding is done using MLEM.Pathfinding.AStar2.

public abstract class PathfindAction : TinyLife.Actions.Action

Inheritance System.Object 🡒 MLEM.Misc.GenericDataHolder 🡒 Action 🡒 PathfindAction



PathfindAction.PathfindAction(ActionType, ActionInfo) Constructor

Creates a new action from the given ActionType

public PathfindAction(TinyLife.Actions.ActionType type, TinyLife.Actions.ActionInfo info);


type ActionType
The type to create this action from

info ActionInfo
The information for this action


PathfindAction.SpeedMultiplier Field

A modifier that the pathfinding person's GetWalkSpeed() is multiplied with.
By default, this value is set to 1.

public float SpeedMultiplier;

Field Value



PathfindAction.Path Property

The path that this action has found.
WHen OnPathReady() is called, this has a value.

public System.Collections.Generic.Stack<Microsoft.Xna.Framework.Point> Path { get; set; }

Property Value


PathfindAction.PathReady Property

A property that determines whether or not the Path has been calculated.

protected bool PathReady { get; set; }

Property Value



PathfindAction.FindPath(Point) Method

A method called by Initialize() to start finding a path to the given goal location.

protected abstract System.Threading.Tasks.Task<System.Collections.Generic.Stack<Microsoft.Xna.Framework.Point>> FindPath(Microsoft.Xna.Framework.Point goal);


goal Microsoft.Xna.Framework.Point
The goal location


A task that, when finished, returns a path

PathfindAction.GetSpeed() Method

Returns the speed that the Person should traverse with.

protected abstract float GetSpeed();


The speed

PathfindAction.Initialize() Method

This method is called when the action is first started by a Person.
Note that it is not called when the action gets added to the ActionQueue, but when it is moved to CurrentActions.

public override void Initialize();

PathfindAction.IsCompleted() Method

This method is called every update frame by a Person if this action is currently active to check if it should be stopped.
If this returns a result other than Completed, OnCompleted(CompletionType) will be called and the action is stopped.
By default, only ForceFail modifies the completion type, otherwise Active is returned.

public override TinyLife.Actions.Action.CompletionType IsCompleted();


The current completion type of this action

PathfindAction.OnCompleted(CompletionType) Method

This method is called when this action IsCompleted(), or if it is canceled from an outside source.
Note that, if this method is called as a result of IsCompleted(), the CompletionType passed will be the same.

public override void OnCompleted(TinyLife.Actions.Action.CompletionType type);


type CompletionType
The type that this action completed with

PathfindAction.OnPathReady() Method

This method is called when the PathReady variable is set to true.
At the point of this method being claled, Path will have a value.

protected virtual void OnPathReady();

PathfindAction.Update(GameTime, TimeSpan, GameSpeed) Method

This method is called every update frame if this action is currently active.
By default, only the ElapsedTime is modified in this method and ActionUpdate(Action, GameTime, TimeSpan, GameSpeed, bool) is called.

public override void Update(Microsoft.Xna.Framework.GameTime time, System.TimeSpan passedInGame, TinyLife.GameSpeed speed);


time Microsoft.Xna.Framework.GameTime
The current game time

passedInGame System.TimeSpan
The amount of time that has passed, in game time

speed GameSpeed
The game's current speed setting

PathfindAction.Validate(Person) Method

Validates this action's data.
This is called when a map is loaded from disk.
When returning false on this method, the action is removed from the Person.

public override bool Validate(TinyLife.Objects.Person person);


person Person
The person that this action belongs to


Whether or not the action is still valid (or if it has invalid data)