Merge origin/master (da6fe033) into faction-play-1
Combat.cs: master's lazy optimum-range owner kept, the OptimumRange accessor beside it. FireControlPerWeaponTests: the exponent test runs the first Update before reading the optimum (master derives it there). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
2ff48d0b45
10 changed files with 800 additions and 12 deletions
|
|
@ -10,22 +10,42 @@ using float2x2 = CultMath.float2x2;
|
|||
public class CombatState : BaseState
|
||||
{
|
||||
private const int DPS_SAMPLE_COUNT = 32;
|
||||
// The Strength of one Track paint in this ship's own IncomingPaints: a fire-control emitter tracking this ship
|
||||
// that hard (rulings lock-warning-strength, sensor-stat-set item 4, launcher-lock-solution-quality).
|
||||
private const float LockAlarm = .5f;
|
||||
// Overdrive only to close a target farther than this many optimum ranges, while heading within this many degrees of it.
|
||||
private const float OverdriveRangeFactor = 2f;
|
||||
private const float OverdriveArcDegrees = 15f;
|
||||
private float _optimumRange;
|
||||
public float OptimumRange => _optimumRange;
|
||||
private bool _optimumStale = true;
|
||||
private readonly List<(int index, float dps)> _availableGroups = new List<(int index, float dps)>();
|
||||
private readonly List<LockWeapon> _availableLockingWeapons = new List<LockWeapon>();
|
||||
|
||||
public CombatState(Agent agent) : base(agent)
|
||||
{
|
||||
SampleDps();
|
||||
foreach (var weapon in _agent.Ship.Weapons)
|
||||
{
|
||||
weapon.Item.Online.Subscribe(b => SampleDps());
|
||||
}
|
||||
foreach (var item in _agent.Ship.Equipment) Watch(item);
|
||||
_agent.Ship.Equipment.ObserveAdd().Subscribe(add => Watch(add.Value));
|
||||
_agent.Ship.Equipment.ObserveRemove().Subscribe(_ => _optimumStale = true);
|
||||
}
|
||||
|
||||
// The optimum is a function of the loadout's evaluated stats, so it is re-derived at the next Update (agents update
|
||||
// before the entities, so by then the weapons that came online this tick have evaluated) whenever a weapon is
|
||||
// added, removed or changes online state. Sampling on the event itself would read the stats before they exist: a
|
||||
// ship the zone just spawned would keep an optimum of 0.
|
||||
private void Watch(EquippedItem item)
|
||||
{
|
||||
if (item.Behaviors.OfType<Weapon>().Any()) item.Online.Subscribe(_ => _optimumStale = true);
|
||||
}
|
||||
|
||||
public override void Update(float delta)
|
||||
{
|
||||
if (_optimumStale)
|
||||
{
|
||||
SampleDps();
|
||||
_optimumStale = false;
|
||||
}
|
||||
|
||||
var target = _agent.Ship.Target.Value.Entity;
|
||||
if (target == null) return;
|
||||
|
||||
|
|
@ -79,6 +99,8 @@ public class CombatState : BaseState
|
|||
|
||||
foreach(var w in _availableLockingWeapons) w.Activate();
|
||||
|
||||
UseConsumables(toTarget, targetDistance);
|
||||
|
||||
var selectedGroup = -1;
|
||||
var maxDps = Single.MinValue;
|
||||
foreach (var group in _availableGroups)
|
||||
|
|
@ -133,6 +155,27 @@ 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.
|
||||
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);
|
||||
}
|
||||
|
||||
private void SampleDps()
|
||||
{
|
||||
var minRange = Single.MaxValue;
|
||||
|
|
|
|||
Loading…
Reference in a new issue