2021-02-26 19:01:47 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
using UniRx;
|
|
|
|
|
|
2026-10-08 14:18:41 +02:00
|
|
|
// The agent graph for a piloted ship. It executes the Task and Target its flight writes (Flight.cs) and decides
|
|
|
|
|
// neither: patrol and follow follow the Task kind, combat follows the Target.
|
2021-02-26 19:01:47 +00:00
|
|
|
public class Minion : Agent
|
|
|
|
|
{
|
2026-10-08 14:18:41 +02:00
|
|
|
public Minion(Ship ship, RoleDoctrine doctrine) : base(ship, doctrine)
|
2021-02-26 19:01:47 +00:00
|
|
|
{
|
|
|
|
|
var patrolState = new PatrolOrbitsState(this);
|
2026-10-08 14:18:41 +02:00
|
|
|
var followState = new FollowState(this);
|
|
|
|
|
void Patrol() => patrolState.Task = Task as PatrolOrbitsTask;
|
|
|
|
|
_rootState.AddTransition(patrolState, () => Task is PatrolOrbitsTask, Patrol);
|
|
|
|
|
_rootState.AddTransition(followState, () => Task is FollowTask);
|
2021-02-26 19:01:47 +00:00
|
|
|
|
2026-10-08 14:18:41 +02:00
|
|
|
// A Task change switches the substate in one update, from wherever the pilot is in the old task. includeChildren
|
2026-10-08 16:20:33 +02:00
|
|
|
// reaches the patrol sub-states (MoveToOrbit) that Update actually sits in; the walk never enters the other task's state.
|
2026-10-08 14:18:41 +02:00
|
|
|
patrolState.AddTransition(followState, () => Task is FollowTask, null, true, _rootState);
|
2026-10-08 16:20:33 +02:00
|
|
|
patrolState.AddTransition(_rootState, () => !(Task is PatrolOrbitsTask), null, true, _rootState, followState);
|
|
|
|
|
followState.AddTransition(patrolState, () => Task is PatrolOrbitsTask, Patrol);
|
|
|
|
|
followState.AddTransition(_rootState, () => !(Task is FollowTask));
|
2021-02-26 19:01:47 +00:00
|
|
|
|
|
|
|
|
var combatState = new CombatState(this);
|
2021-04-18 05:13:20 +01:00
|
|
|
_rootState.AddTransition(combatState,
|
2026-10-22 15:45:02 +02:00
|
|
|
() => View.TargetOf(Ship) != null, null, true, _rootState);
|
2026-10-08 14:18:41 +02:00
|
|
|
|
2021-02-26 19:01:47 +00:00
|
|
|
combatState.AddTransition(_rootState,
|
2026-10-22 15:45:02 +02:00
|
|
|
() => View.TargetOf(Ship) == null, null, true, _rootState);
|
2021-02-26 19:01:47 +00:00
|
|
|
}
|
2026-10-08 14:18:41 +02:00
|
|
|
}
|