Class PathfindAction
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 : Action, IGenericDataHolder
- Inheritance
-
JsonTypeSafeGenericDataHolderPathfindAction
- Implements
-
IGenericDataHolder
- Derived
- Inherited Members
-
JsonTypeSafeGenericDataHolder.GetDataKeys()
- Extension Methods
Constructors
PathfindAction(ActionInfo)
Creates a new typeless action with the given action information.
public PathfindAction(ActionInfo info)
Parameters
infoActionInfoThe information for this action.
PathfindAction(ActionType, ActionInfo)
Creates a new action with the given action information.
public PathfindAction(ActionType type, ActionInfo info)
Parameters
typeActionTypeThe type for this action.
infoActionInfoThe information for this action.
Fields
SpeedMultiplier
A modifier that the pathfinding person's GetWalkSpeed() is multiplied with. By default, this value is set to 1.
[DataMember]
public float SpeedMultiplier
Field Value
Properties
Path
The path that this action has found. WHen OnPathReady() is called, this has a value.
public Stack<(Vector2 Pos, float Floor)> Path { get; }
Property Value
PathReady
A property that determines whether or not the Path has been calculated.
public bool PathReady { get; }
Property Value
Methods
FindPath((Point Pos, int Floor)[])
A method called by Initialize() to start finding a path to the given goal location.
protected abstract Task<Stack<(Vector2 Pos, float Floor)>> FindPath((Point Pos, int Floor)[] goals)
Parameters
Returns
GetExtraIcon()
Returns an extra icon in the form of a MLEM.Textures.TextureRegion, which, if non-null, will be displayed in the top-right corner of the action in the action queue. By default, this method returns null, and MultiAction returns an interrupted icon if it has been interrupted and is still executing.
public override TextureRegion GetExtraIcon()
Returns
- TextureRegion
The extra icon to display in the action queue.
GetSpeed()
Returns the speed that the PersonLike should traverse with.
protected abstract float GetSpeed()
Returns
- float
The speed
Initialize()
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()
IsCompleted()
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 the default behavior of Interrupt(CompletionType) modifies the completion type, otherwise Active is returned.
public override CompletionType IsCompleted()
Returns
- CompletionType
The current completion type of this action
OnCompleted(CompletionType)
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. By default, only OnActionCompleted(Action, CompletionType, bool) is called.
public override void OnCompleted(CompletionType type)
Parameters
typeCompletionTypeThe type that this action completed with
OnPathReady()
This method is called right before the PathReady variable is set to true. At the point of this method being called, Path will have a value.
protected virtual void OnPathReady()
Update(GameTime, TimeSpan, float)
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, float, bool) is called.
public override void Update(GameTime time, TimeSpan passedInGame, float speedMultiplier)
Parameters
timeGameTimeThe current game time
passedInGameTimeSpanThe amount of time that has passed, in game time
speedMultiplierfloatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
Validate(PersonLike, AppliedMigrations)
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(PersonLike person, AppliedMigrations appliedMigrations)
Parameters
personPersonLikeThe person that this action belongs to
appliedMigrationsAppliedMigrationsThe migrations that have been applied so far
Returns
- bool
Whether or not the action is still valid (or if it has invalid data)