Reject impossible attack orders

This commit is contained in:
Meta Vens 2026-07-11 20:19:04 +01:00
commit 9b55f2b908
3 changed files with 103 additions and 1 deletions

View file

@ -29,6 +29,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
IdleAgentReturnsToCanonicalHomeAndDocks();
ControlledShipDoesNotReceiveAutonomousHelmCommands();
AttackAgentControlsOptimumRangeThroughMovementLever();
AttackTaskAdmissionRejectsImpossibleWork();
AgentCompletesAttackTaskThroughTargetFireAndYmir();
AgentCompletesHaulTaskThroughMovementAndCargoCommands();
RejectedHaulTransferDoesNotAdvanceTask();
@ -550,6 +551,53 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
"attack task must complete when its target dies");
}
private static void AttackTaskAdmissionRejectsImpossibleWork()
{
var agent = Entity(0, 0, "player");
agent.AgentTaskCapabilities = [AetheriaRuntimeAgentTaskTypes.Attack];
agent.WeaponGroups = [new[] { 0 }];
var hostile = Entity(1, 100, "raider");
var friendly = Entity(2, 100, "player");
var run = new AetheriaRuntimeRunCheckpointCommit
{
RunId = "attack-admission-smoke",
CurrentEntityKey = "",
Zones = [new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [agent, hostile, friendly] }]
};
AetheriaRuntimeDaemonCommandDocument Command(string id, int targetIndex, int weaponGroup)
{
var command = AetheriaRuntimeDaemonCommandDocument.Create(
AetheriaRuntimeDaemonCommandKinds.IssueAgentTask, "commander-smoke", "starbridge-smoke", 0, "");
command.CommandId = id;
command.AgentTask = new AetheriaRuntimeAgentTaskCommand
{
TaskId = id,
CorporationKey = "player",
TaskType = AetheriaRuntimeAgentTaskTypes.Attack,
ZoneIndex = 0,
TargetEntityIndex = targetIndex,
WeaponGroup = weaponGroup
};
return command;
}
var result = AetheriaRuntimeDaemonOperations.Execute(run,
[
Command("missing-target", 99, 0),
Command("friendly-target", 2, 0),
Command("missing-group", 1, 1),
Command("valid-attack", 1, 0)
]);
Require(result.RejectedCommandIds.SequenceEqual(new[] { "missing-target", "friendly-target", "missing-group" }),
"attack admission must reject missing/friendly targets and unavailable weapon groups");
Require(result.AppliedCommandIds.SequenceEqual(new[] { "valid-attack" }),
"attack admission must accept executable hostile work");
Require(run.AgentTasks.Count == 1 && run.AgentTasks[0].TaskId == "valid-attack",
"rejected attack orders must not enter the durable corporation queue");
}
private static void AttackAgentControlsOptimumRangeThroughMovementLever()
{
var settings = AetheriaRuntimeDaemonSimulationSettings.AetheriaDefault;

View file

@ -218,6 +218,9 @@ namespace GameCult.Aetheria.State.Verse
if (string.Equals(taskType, AetheriaRuntimeAgentTaskTypes.Tow, StringComparison.Ordinal) &&
(request.TargetEntityIndex < 0 || string.IsNullOrWhiteSpace(request.OrbitParentKey) || request.OrbitDistance <= 0))
return false;
if (string.Equals(taskType, AetheriaRuntimeAgentTaskTypes.Attack, StringComparison.Ordinal) &&
!CanIssueAttackTask(run, request))
return false;
run.AgentTasks = (run.AgentTasks ?? Array.Empty<AetheriaRuntimeAgentTaskCommit>())
.Concat(new[]
@ -250,6 +253,57 @@ namespace GameCult.Aetheria.State.Verse
return true;
}
private static bool CanIssueAttackTask(
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeAgentTaskCommand request)
{
if (request.TargetEntityIndex < 0 || request.WeaponGroup < 0)
return false;
var zone = (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
.FirstOrDefault(candidate => candidate != null && candidate.ZoneIndex == request.ZoneIndex);
var target = (zone?.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
.FirstOrDefault(candidate => candidate != null && candidate.EntityIndex == request.TargetEntityIndex);
if (target == null || !target.IsActive || !IsAttackHostile(request.CorporationKey, target.FactionKey))
return false;
return (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
.Where(candidate => candidate != null)
.SelectMany(candidate => (candidate.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
.Select(entity => (ZoneIndex: candidate.ZoneIndex, Entity: entity)))
.Any(candidate =>
candidate.Entity != null &&
candidate.Entity.IsActive &&
!IsCurrentEntity(run, candidate.ZoneIndex, candidate.Entity.EntityIndex) &&
string.Equals(candidate.Entity.FactionKey ?? "", request.CorporationKey ?? "", StringComparison.Ordinal) &&
(candidate.Entity.AgentTaskCapabilities ?? Array.Empty<string>())
.Contains(AetheriaRuntimeAgentTaskTypes.Attack, StringComparer.Ordinal) &&
request.WeaponGroup < (candidate.Entity.WeaponGroups ?? Array.Empty<IReadOnlyList<int>>()).Count &&
(candidate.Entity.WeaponGroups[request.WeaponGroup] ?? Array.Empty<int>()).Count > 0);
}
private static bool IsAttackHostile(string? corporationKey, string? targetFactionKey)
{
var corporationIsPlayer = string.Equals(corporationKey, "player", StringComparison.OrdinalIgnoreCase);
var targetIsPlayer = string.Equals(targetFactionKey, "player", StringComparison.OrdinalIgnoreCase);
return corporationIsPlayer != targetIsPlayer &&
(string.Equals(corporationKey, "raider", StringComparison.OrdinalIgnoreCase) ||
string.Equals(targetFactionKey, "raider", StringComparison.OrdinalIgnoreCase));
}
private static bool IsCurrentEntity(
AetheriaRuntimeRunCheckpointCommit run,
int zoneIndex,
int entityIndex)
{
return AetheriaRuntimeRunCheckpointCommit.TryParseEntityKey(
run.CurrentEntityKey,
out var currentZoneIndex,
out var currentEntityIndex) &&
currentZoneIndex == zoneIndex &&
currentEntityIndex == entityIndex;
}
private static bool ApplyCancelAgentTask(
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeDaemonCommandDocument command)

View file

@ -42,7 +42,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity.
| Starbridge | original/shared architecture intent | one daemon session | pilot + commander surfaces | Unity + Electron | commander task board and autonomous explore execution wired; Electron Eve lowering and split-target proof missing | commander orders plus four pilots and autonomous workers |
| Behavior engine | `ServerShared/Behaviors` composition | daemon | executable action/status projection | action bar and feedback | tick reconciles equipped catalog payloads into persistent behavior state; shared evaluated-stat query proven; execution families remain partial | every behavior family, ordering, resource transaction and modifier lifecycle |
| Sensors/visibility | decaying sources and observer information thresholds | daemon | contacts and ping events | indicators/maps | reference | threshold, decay, ping and classification timelines |
| AI/tasks | corporation task scheduler plus agent state machines | daemon | commander task board, corporation survey ledger, and shared semantic controls | Eve commander/pilot clients | point exploration, attack with optimum-range control, same-zone haul, mining/offload, resource surveying, physical station towing, persistent orbit patrol, route-aware assignment, and autonomous return home wired through shared commands; capability/priority assignment and rejection behavior proven; generic Electron commander lowering proves the worker roster | cross-zone logistics execution, cancellation, reconnect, and multi-client command transfer |
| AI/tasks | corporation task scheduler plus agent state machines | daemon | commander task board, corporation survey ledger, and shared semantic controls | Eve commander/pilot clients | point exploration, attack with optimum-range control, same-zone haul, mining/offload, resource surveying, physical station towing, persistent orbit patrol, route-aware assignment, and autonomous return home wired through shared commands; attack admission rejects missing/friendly targets and unavailable weapon groups before durable queueing; capability/priority assignment and rejection behavior proven; generic Electron commander lowering proves the worker roster | cross-zone logistics execution, cancellation, reconnect, and multi-client command transfer |
| Consumables | cargo-backed timed behavior containers | daemon | dynamic actions and active effects | action bar/schematic | reference | consume, stacking, duration and cleanup |
## Ownership Invariants