Vent on a Track paint in every agent state: Agent.Update owns the vent, CombatState keeps the overdrive

Ruling vent-in-any-state. The vent decision (own Track paint above .5, one of a kind through TryActivateConsumable)
moves out of CombatState into Agent.Update, which every state runs; CombatState's overdrive asks Agent.TrackAlarm so a
venting tick still does not overdrive. ConsumableAiTests: AVentDoesNotNeedAnyEnemyInSight is master's premise again
(empty VisibleEnemies), a patrolling agent has its own test, and the fixture zone has one orbit so an unengaged pilot
patrols it. Not built or run yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-17 00:21:40 +02:00
commit 0e40a66592
3 changed files with 58 additions and 25 deletions

View file

@ -15,6 +15,9 @@ public class Agent
{
private const float FORWARD_DELTA_THRESHOLD = 20;
private const float THRUST_DELTA_THRESHOLD = 1;
// The Strength of one Track paint in this ship's own IncomingPaints: a fire-control emitter tracking this
// that hard (rulings lock-warning-strength, sensor-stat-set item 4, launcher-lock-solution-quality).
private const float LockAlarm = .5f;
protected BaseState _rootState;
private BaseState _currentState;
private VelocityLimit _velocityLimit;
@ -52,6 +55,7 @@ public class Agent
// The pilot tick writes 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.
Ship.Turn = 0;
VentOnTrack();
_currentState.Update(delta);
foreach (var transition in _currentState.Transitions)
if (transition.Condition())
@ -61,6 +65,25 @@ public class Agent
}
}
// The AI plays the player's rule on the player's information: vent when one Track paint on this ship passes half. It
// reads only this ship's own IncomingPaints, so it runs in every state (ruling vent-in-any-state), and a ship
// carrying no vent does nothing.
private void VentOnTrack()
{
if (TrackAlarm) Use(b => b is VapourDumpData);
}
// One Track paint on this ship passes the alarm: the ship vents, and does not overdrive on the same tick.
public bool TrackAlarm => Ship.IncomingPaints.Any(p => p.Mode == PaintMode.Track && p.Strength > LockAlarm);
// Through TryActivateConsumable, one of a kind at a time: a Stackable design would otherwise be drained once per tick.
public void Use(Predicate<BehaviorData> kind)
{
if (Ship.HasActiveConsumable(kind)) return;
var consumable = Ship.FirstCarriedConsumable(kind);
if (consumable != null) Ship.TryActivateConsumable(consumable);
}
public void Accelerate(float2 targetVelocity, bool noTurn = false)
{
var deltaV = targetVelocity - Ship.Velocity;

View file

@ -155,25 +155,13 @@ public class CombatState : BaseState
// Fire charged guns!
}
// The AI plays the player's rule on the player's information: vent when one Track paint on this ship passes half,
// otherwise overdrive to close a distant target ahead. It reads only this ship's own IncomingPaints. Both go
// through TryActivateConsumable, and a ship carrying neither does nothing.
// Overdrive to close a distant target ahead, through the same consumable gate as the vent (Agent.VentOnTrack).
private void UseConsumables(float3 toTarget, float targetDistance)
{
var ship = _agent.Ship;
if (ship.IncomingPaints.Any(p => p.Mode == PaintMode.Track && p.Strength > LockAlarm))
Use(b => b is VapourDumpData);
else if (targetDistance > OverdriveRangeFactor * _optimumRange &&
dot(normalize(ship.Direction), normalize(toTarget.xz)) > cos(radians(OverdriveArcDegrees)))
Use(b => b is ThrottleLockData);
}
// One of a kind at a time: a Stackable design would otherwise be drained once per tick.
private void Use(Predicate<BehaviorData> kind)
{
if (_agent.Ship.HasActiveConsumable(kind)) return;
var consumable = _agent.Ship.FirstCarriedConsumable(kind);
if (consumable != null) _agent.Ship.TryActivateConsumable(consumable);
if (!_agent.TrackAlarm && targetDistance > OverdriveRangeFactor * _optimumRange &&
dot(normalize(ship.Direction), normalize(toTarget.xz)) > cos(radians(OverdriveArcDegrees)))
_agent.Use(b => b is ThrottleLockData);
}
private void SampleDps()