Command seam, agents: one PilotCommand per entity, applied once per step by PilotApplier in Zone.Update
Agent, Flight, Combat, MoveTo and Follow write only Ship.Command. Entities with no agent apply first, then each agent applies right after it decides. A pilot reads its own pending designation and aim item back from its command; FireControl gains Refuses/AgentFires/HitProbability overloads that take them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b13aa7385a
commit
9a2a9390e1
11 changed files with 169 additions and 34 deletions
|
|
@ -55,9 +55,9 @@ public class Agent
|
|||
|
||||
public void Update(float delta)
|
||||
{
|
||||
// The pilot tick writes Turn every tick, in every state: a state that pilots overwrites this zero with its
|
||||
// The pilot tick commands Turn every tick, in every state: a state that pilots overwrites this zero with its
|
||||
// demand, and one that does not leaves the hull holding course instead of inheriting the last state's rate.
|
||||
/*DEL turn0*/
|
||||
Ship.Command.Turn = TurnCommand.OfRate(0);
|
||||
VentOnTrack();
|
||||
_currentState.Update(delta);
|
||||
foreach (var transition in _currentState.Transitions)
|
||||
|
|
@ -84,7 +84,7 @@ public class Agent
|
|||
{
|
||||
if (Ship.HasActiveConsumable(kind)) return;
|
||||
var consumable = Ship.FirstCarriedConsumable(kind);
|
||||
if (consumable != null) /*DEL use*/;
|
||||
if (consumable != null) Ship.Command.Use(consumable);
|
||||
}
|
||||
|
||||
public void Accelerate(float2 targetVelocity, bool noTurn = false)
|
||||
|
|
@ -95,18 +95,18 @@ public class Agent
|
|||
// If Delta V is above the threshold, direct the ship towards the delta and use only main thrusters
|
||||
if (!noTurn && deltaVMag > FORWARD_DELTA_THRESHOLD)
|
||||
{
|
||||
/*DEL accel-turn*/
|
||||
/*DEL accel-move1*/
|
||||
Ship.Command.Turn = TurnCommand.Toward(deltaVDirection);
|
||||
Ship.Command.Movement = float2(0, pow(dot(Ship.Direction, deltaVDirection), 2));
|
||||
}
|
||||
// If Delta V is low, use all thrusters and leave Turn to the caller (MoveTo already pointed it at the target)
|
||||
else if(deltaVMag > THRUST_DELTA_THRESHOLD)
|
||||
{
|
||||
var right = Ship.Direction.Rotate(ItemRotation.Clockwise);
|
||||
/*DEL accel-move2*/
|
||||
Ship.Command.Movement = float2(dot(right, deltaVDirection), dot(Ship.Direction, deltaVDirection));
|
||||
}
|
||||
else
|
||||
{
|
||||
/*DEL accel-move3*/
|
||||
Ship.Command.Movement = float2.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class Flight
|
|||
{
|
||||
track.Phase = Phase.Hailing;
|
||||
track.Start = _time;
|
||||
if (!string.IsNullOrEmpty(_doctrine.Hail)) /*DEL hail*/;
|
||||
if (!string.IsNullOrEmpty(_doctrine.Hail)) Nearest(entity)?.Agent.Ship.Command.Hail(_doctrine.Hail);
|
||||
}
|
||||
else track.Phase = Phase.Engaged;
|
||||
break;
|
||||
|
|
@ -175,7 +175,7 @@ public class Flight
|
|||
private static void Aim(Ship ship, Entity target)
|
||||
{
|
||||
var wanted = target == null ? TargetRef.None : new TargetRef(target);
|
||||
if (!ship.Target.Value.Equals(wanted)) /*DEL designate*/;
|
||||
if (!ship.Target.Value.Equals(wanted)) ship.Command.Designate(wanted);
|
||||
}
|
||||
|
||||
private float Standoff(Ship ship)
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ public class Minion : Agent
|
|||
|
||||
var combatState = new CombatState(this);
|
||||
_rootState.AddTransition(combatState,
|
||||
() => Ship.Target.Value.Entity != null, null, true, _rootState);
|
||||
() => (Ship.Command.Designated ?? Ship.Target.Value).Entity != null, null, true, _rootState);
|
||||
|
||||
combatState.AddTransition(_rootState,
|
||||
() => Ship.Target.Value.Entity == null, null, true, _rootState);
|
||||
() => (Ship.Command.Designated ?? Ship.Target.Value).Entity == null, null, true, _rootState);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ public class CombatState : BaseState
|
|||
_optimumStale = false;
|
||||
}
|
||||
|
||||
var target = _agent.Ship.Target.Value.Entity;
|
||||
// The pilot's own pending designation (its Flight's, this step) when set, else last step's applied target.
|
||||
var target = (_agent.Ship.Command.Designated ?? _agent.Ship.Target.Value).Entity;
|
||||
if (target == null) return;
|
||||
|
||||
_availableGroups.Clear();
|
||||
|
|
@ -70,7 +71,8 @@ public class CombatState : BaseState
|
|||
bestTargetItem = reveal.Item;
|
||||
}
|
||||
}
|
||||
/*DEL select*/
|
||||
_agent.Ship.Command.SelectItem(bestTargetItem);
|
||||
var aim = bestTargetItem == null ? AimTarget.None : AimTarget.OfItem(bestTargetItem);
|
||||
|
||||
for (var i = 0; i < _agent.Ship.WeaponGroups.Length; i++)
|
||||
{
|
||||
|
|
@ -81,7 +83,7 @@ public class CombatState : BaseState
|
|||
// damage.
|
||||
if (weapon.Item.Online.Value &&
|
||||
FireControl.Designated(weapon, _agent.Ship, target, out _) &&
|
||||
!FireControl.Refuses(weapon, _agent.Ship) &&
|
||||
!FireControl.Refuses(weapon, _agent.Ship, target) &&
|
||||
(weapon is ConstantWeapon ||
|
||||
weapon is InstantWeapon instantWeapon && instantWeapon.CanFire))
|
||||
{
|
||||
|
|
@ -94,7 +96,7 @@ public class CombatState : BaseState
|
|||
if (dps > .1) _availableGroups.Add((i, dps));
|
||||
}
|
||||
|
||||
foreach(var w in _availableLockingWeapons) /*DEL lock*/;
|
||||
foreach(var w in _availableLockingWeapons) _agent.Ship.Command.Pull(w);
|
||||
|
||||
UseConsumables(toTarget, targetDistance);
|
||||
|
||||
|
|
@ -139,14 +141,15 @@ public class CombatState : BaseState
|
|||
// fires at, and "the target is designated" for a fused one.
|
||||
foreach (var weapon in _agent.Ship.WeaponGroups[selectedGroup].weapons)
|
||||
{
|
||||
if (FireControl.AgentFires(weapon, _agent.Ship, target, _agent.Doctrine.MinHitProbability))
|
||||
/*DEL pull*/;
|
||||
else if (weapon.Firing)
|
||||
/*DEL release*/;
|
||||
if (FireControl.AgentFires(weapon, _agent.Ship, target, _agent.Doctrine.MinHitProbability, aim))
|
||||
_agent.Ship.Command.Pull(weapon);
|
||||
// A lock pulled above this step counts as firing, as it did when it was activated in place.
|
||||
else if (weapon.Firing || _agent.Ship.Command.Pulls(weapon))
|
||||
_agent.Ship.Command.Release(weapon);
|
||||
}
|
||||
}
|
||||
/*DEL aim*/
|
||||
/*DEL turn*/
|
||||
_agent.Ship.Command.Aim = toTarget;
|
||||
_agent.Ship.Command.Turn = TurnCommand.Toward(toTarget.xz);
|
||||
_agent.Accelerate(movementDirection * _agent.TopSpeed, true);//selectedGroup >= 0);
|
||||
|
||||
// Fire charged guns!
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class FollowState : BaseState
|
|||
var pull = direction * (float) sign(error) * saturate(abs(error) / max(task.Standoff, 1f));
|
||||
var desired = task.Anchor.Velocity + pull * _agent.TopSpeed;
|
||||
|
||||
/*DEL aim*/
|
||||
_agent.Ship.Command.Aim = float3(direction.x, 0, direction.y);
|
||||
_agent.Accelerate(desired);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ public abstract class MoveToState : BaseState
|
|||
|
||||
// We want to go top speed in the direction of our target
|
||||
var desiredVelocity = dir * _agent.TopSpeed;
|
||||
/*DEL aim*/
|
||||
/*DEL turn*/
|
||||
_agent.Ship.Command.Aim = float3(dir.x, 0, dir.y);
|
||||
_agent.Ship.Command.Turn = TurnCommand.Toward(dir);
|
||||
_agent.Accelerate(desiredVelocity);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue