Merge remote-tracking branch 'origin/master' into eureka/aetheria-living-world-economy-content-b1

This commit is contained in:
soul 2026-10-23 17:58:47 +02:00
commit 78b176a0ff
7 changed files with 431 additions and 6 deletions

View file

@ -47,9 +47,9 @@ public class CombatState : BaseState
// only a contact a member tracks has a track to fly on, so an untracked target is no target here.
var view = _agent.View;
var target = view.TargetOf(_agent.Ship);
if (target == null) return;
if (target == null) { ReleaseUnwanted(); return; }
var track = view.TrackOf(_agent.Ship, target.Value);
if (track == null) return;
if (track == null) { ReleaseUnwanted(); return; }
_availableGroups.Clear();
_availableLockingWeapons.Clear();
@ -88,7 +88,9 @@ public class CombatState : BaseState
view.Designated(_agent.Ship, weapon, target.Value) &&
!view.Refuses(_agent.Ship, weapon, target.Value) &&
(weapon is ConstantWeapon ||
weapon is InstantWeapon instantWeapon && instantWeapon.CanFire))
// A held AutoWeapon stays a candidate between its rounds (it is cooling because it is firing), so the
// group it belongs to is judged by the same Fires verdict below, not dropped for cooling down.
weapon is InstantWeapon instantWeapon && (instantWeapon.CanFire || weapon is AutoWeapon && weapon.Firing)))
{
if(weapon is LockWeapon lockWeapon)
_availableLockingWeapons.Add(lockWeapon);
@ -151,6 +153,7 @@ public class CombatState : BaseState
_agent.Ship.Command.Release(weapon);
}
}
ReleaseUnwanted();
_agent.Ship.Command.Aim = toTarget;
_agent.Ship.Command.Turn = TurnCommand.Toward(toTarget.xz);
_agent.Accelerate(movementDirection * _agent.TopSpeed, true);//selectedGroup >= 0);
@ -158,6 +161,19 @@ public class CombatState : BaseState
// Fire charged guns!
}
public override void OnExitState() => ReleaseUnwanted(ending: true);
// The AI's trigger level is what it commands this step: a weapon holds a down trigger until it is released (a gun, a lock,
// a beam), so every held one this step has no command for is let go, whether the target is gone, untracked, out of reach,
// its group is not the pick, or Combat has ended. Ending lets go of every held one, a weapon pulled this very step
// (held once the pull is applied) included, since nothing after Combat will command it.
private void ReleaseUnwanted(bool ending = false)
{
var command = _agent.Ship.Command;
foreach (var weapon in _agent.Ship.Weapons)
if ((weapon.Firing || command.Pulls(weapon)) && (ending || !command.Commands(weapon))) command.Release(weapon);
}
// Overdrive to close a distant target ahead, through the same consumable gate as the vent (Agent.VentOnTrack).
private void UseConsumables(float3 toTarget, float targetDistance)
{

View file

@ -94,6 +94,14 @@ public sealed class PilotCommand
// The pilot's own pending decisions, which it reads back instead of the ship (that is last step's applied state).
public TargetRef? Designated => Designations.Count > 0 ? Designations[Designations.Count - 1] : (TargetRef?) null;
// Whether this pilot has commanded a trigger, pull or release, for `behavior` this step.
public bool Commands(ActivatedBehavior behavior)
{
foreach (var trigger in Triggers)
if (ReferenceEquals(trigger.Behavior, behavior)) return true;
return false;
}
// Whether the last trigger this pilot commanded for `behavior` this step is a pull.
public bool Pulls(ActivatedBehavior behavior)
{