Restore patrol combat preemption

This commit is contained in:
Meta Vens 2026-07-17 09:38:21 +01:00
commit c78fdb0361
8 changed files with 284 additions and 11 deletions

View file

@ -302,6 +302,16 @@ namespace GameCult.Aetheria.State.Verse
if (string.Equals(task.TaskType, AetheriaRuntimeAgentTaskTypes.Defend, StringComparison.Ordinal) ||
string.Equals(task.TaskType, AetheriaRuntimeAgentTaskTypes.Patrol, StringComparison.Ordinal))
{
var hostile = FirstVisibleHostileShip(zone!, agent);
if (hostile != null && ResolveAgentWeapons(agent, catalog).Count > 0)
{
var combatDx = hostile.PositionX - agent.PositionX;
var combatDz = hostile.PositionZ - agent.PositionZ;
commands.AddRange(PlanAttack(
run, task, agent, hostile, frameId, combatDx, combatDz,
Math.Sqrt(combatDx * combatDx + combatDz * combatDz), catalog, simulationSettings));
continue;
}
commands.AddRange(PlanPatrol(zone!, task, agent, frameId));
continue;
}
@ -1123,6 +1133,25 @@ namespace GameCult.Aetheria.State.Verse
return new[] { Movement(task, agent, frameId, dx, dz, 1) };
}
private static AetheriaRuntimeEntitySnapshotCommit? FirstVisibleHostileShip(
AetheriaRuntimeZoneSnapshotCommit zone,
AetheriaRuntimeEntitySnapshotCommit agent)
{
var hostileIndices = (agent.Contacts ?? Array.Empty<AetheriaRuntimeEntityContactCommit>())
.Where(contact => contact != null && contact.Visible && contact.Hostile)
.Select(contact => contact.TargetEntityIndex)
.ToArray();
foreach (var index in hostileIndices)
{
var target = (zone.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
.FirstOrDefault(entity => entity != null && entity.EntityIndex == index &&
entity.IsActive && string.Equals(entity.Kind, "ship", StringComparison.OrdinalIgnoreCase));
if (target != null)
return target;
}
return null;
}
private static AetheriaRuntimeDaemonCommandDocument Movement(
AetheriaRuntimeAgentTaskCommit task,
AetheriaRuntimeEntitySnapshotCommit agent,

View file

@ -111,7 +111,8 @@ namespace GameCult.Aetheria.State.Verse
deltaSeconds,
settings.TargetInfoDecay,
activeRenderSettings.TargetDetectionInfoThreshold,
frameId);
frameId,
settings.SecureAreaRadiusMultiplier);
AetheriaRuntimeMiningSimulation.Step(run, zone, entities, intents, catalog, frameId, simulationTimeSeconds, deltaSeconds);
AetheriaRuntimeSurveySimulation.Step(run, zone, entities, intents, catalog, frameId, simulationTimeSeconds, deltaSeconds);
}

View file

@ -110,7 +110,8 @@ namespace GameCult.Aetheria.State.Verse
double wormholeExitRadius = AetheriaDefaultRaw.WormholeExitRadius,
double wormholeDepth = AetheriaDefaultRaw.WormholeDepth,
double visibilityDecay = AetheriaDefaultRaw.VisibilityDecay,
double targetInfoDecay = AetheriaDefaultRaw.TargetInfoDecay)
double targetInfoDecay = AetheriaDefaultRaw.TargetInfoDecay,
double secureAreaRadiusMultiplier = AetheriaDefaultRaw.SecureAreaRadiusMultiplier)
{
PawnSpeed = PositiveOr(pawnSpeed, AetheriaDefaultRaw.PawnSpeed);
RaiderSpeed = PositiveOr(raiderSpeed, AetheriaDefaultRaw.RaiderSpeed);
@ -165,6 +166,8 @@ namespace GameCult.Aetheria.State.Verse
WormholeDepth = PositiveOr(wormholeDepth, AetheriaDefaultRaw.WormholeDepth);
VisibilityDecay = NonNegativeOr(visibilityDecay, AetheriaDefaultRaw.VisibilityDecay);
TargetInfoDecay = NonNegativeOr(targetInfoDecay, AetheriaDefaultRaw.TargetInfoDecay);
SecureAreaRadiusMultiplier = PositiveOr(
secureAreaRadiusMultiplier, AetheriaDefaultRaw.SecureAreaRadiusMultiplier);
}
public double PawnSpeed { get; }
@ -222,6 +225,7 @@ namespace GameCult.Aetheria.State.Verse
public double WormholeDepth { get; }
public double VisibilityDecay { get; }
public double TargetInfoDecay { get; }
public double SecureAreaRadiusMultiplier { get; }
private static double PositiveOr(double value, double fallback)
{
@ -293,6 +297,7 @@ namespace GameCult.Aetheria.State.Verse
public const double WormholeDepth = 1000.0;
public const double VisibilityDecay = 0.5;
public const double TargetInfoDecay = 0.5;
public const double SecureAreaRadiusMultiplier = 0.425;
}
}
}

View file

@ -17,7 +17,8 @@ namespace GameCult.Aetheria.State.Verse
double deltaSeconds,
double targetInfoDecay,
double detectionThreshold,
long frameId)
long frameId,
double secureAreaRadiusMultiplier = 0.425)
{
if (catalog == null || deltaSeconds <= 0)
return;
@ -44,7 +45,7 @@ namespace GameCult.Aetheria.State.Verse
foreach (var sensor in sensors)
StepSensor(run, zone, observer, sensor, entities, contacts, catalog,
deltaSeconds, targetInfoDecay, frameId);
deltaSeconds, targetInfoDecay, secureAreaRadiusMultiplier, frameId);
observer.Contacts = entities
.Where(target => target != null && target.EntityIndex != observer.EntityIndex)
@ -56,7 +57,9 @@ namespace GameCult.Aetheria.State.Verse
{
TargetEntityIndex = target.EntityIndex,
InfoGathered = information,
Hostile = Hostile(observer, target),
Hostile = Hostile(
run, zone, entities, catalog, observer, target,
secureAreaRadiusMultiplier),
Visible = information > detectionThreshold
};
})
@ -108,6 +111,7 @@ namespace GameCult.Aetheria.State.Verse
AetheriaRuntimeCatalogSnapshot catalog,
double deltaSeconds,
double targetInfoDecay,
double secureAreaRadiusMultiplier,
long frameId)
{
var thermal = ThermalPerformance(observer, sensor.EquipmentIndex);
@ -164,7 +168,9 @@ namespace GameCult.Aetheria.State.Verse
{
TargetEntityIndex = target.EntityIndex,
InfoGathered = next,
Hostile = Hostile(observer, target)
Hostile = Hostile(
run, zone, entities, catalog, observer, target,
secureAreaRadiusMultiplier)
};
}
sensor.State.PingedEntityIndices = pinged.OrderBy(index => index).ToArray();
@ -250,6 +256,94 @@ namespace GameCult.Aetheria.State.Verse
.ThermalPerformance ?? 1;
private static bool Hostile(
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeZoneSnapshotCommit zone,
IReadOnlyList<AetheriaRuntimeEntitySnapshotCommit> entities,
AetheriaRuntimeCatalogSnapshot catalog,
AetheriaRuntimeEntitySnapshotCommit left,
AetheriaRuntimeEntitySnapshotCommit right,
double secureAreaRadiusMultiplier)
{
var ownerKey = zone.OwnerFactionIndex >= 0 &&
zone.OwnerFactionIndex < (catalog.Corporations?.Count ?? 0)
? catalog.Corporations[zone.OwnerFactionIndex].CorporationKey ?? ""
: "";
if (string.IsNullOrWhiteSpace(ownerKey))
return LegacyHostile(left, right);
return OwnerRejects(run, zone, entities, left, right, ownerKey, secureAreaRadiusMultiplier) ||
OwnerRejects(run, zone, entities, right, left, ownerKey, secureAreaRadiusMultiplier);
}
private static bool OwnerRejects(
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeZoneSnapshotCommit zone,
IReadOnlyList<AetheriaRuntimeEntitySnapshotCommit> entities,
AetheriaRuntimeEntitySnapshotCommit ownerEntity,
AetheriaRuntimeEntitySnapshotCommit visitor,
string ownerKey,
double secureAreaRadiusMultiplier)
{
if (!string.Equals(ownerEntity.FactionKey, ownerKey, StringComparison.OrdinalIgnoreCase))
return false;
var relationship = RelationshipTo(run, zone, visitor, ownerKey);
var security = LocalSecurity(
entities, visitor.PositionX, visitor.PositionZ, ownerKey, secureAreaRadiusMultiplier);
return relationship - security <= 0;
}
private static int RelationshipTo(
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeZoneSnapshotCommit zone,
AetheriaRuntimeEntitySnapshotCommit entity,
string factionKey)
{
if (string.Equals(entity.FactionKey, factionKey, StringComparison.OrdinalIgnoreCase))
return 4;
if (AetheriaRuntimeRunCheckpointCommit.TryParseEntityKey(
run.CurrentEntityKey, out var playerZoneIndex, out var playerEntityIndex) &&
playerZoneIndex == zone.ZoneIndex && playerEntityIndex == entity.EntityIndex)
{
var relationship = (run.FactionRelationships ?? Array.Empty<AetheriaRuntimeFactionRelationshipCommit>())
.FirstOrDefault(value => value != null &&
string.Equals(value.FactionKey, factionKey, StringComparison.OrdinalIgnoreCase));
return RelationshipValue(relationship?.Relationship);
}
return 2;
}
private static int LocalSecurity(
IReadOnlyList<AetheriaRuntimeEntitySnapshotCommit> entities,
double positionX,
double positionZ,
string ownerKey,
double secureAreaRadiusMultiplier)
{
var security = 0;
foreach (var entity in entities)
{
if (entity == null || entity.SecurityRadius <= 1 ||
!string.Equals(entity.FactionKey, ownerKey, StringComparison.OrdinalIgnoreCase))
continue;
var dx = entity.PositionX - positionX;
var dz = entity.PositionZ - positionZ;
var radius = entity.SecurityRadius * secureAreaRadiusMultiplier;
if (dx * dx + dz * dz < radius * radius)
security = Math.Max(security, entity.SecurityLevel);
}
return security;
}
private static int RelationshipValue(string? relationship)
{
if (string.Equals(relationship, "Hated", StringComparison.OrdinalIgnoreCase)) return 0;
if (string.Equals(relationship, "Hostile", StringComparison.OrdinalIgnoreCase)) return 1;
if (string.Equals(relationship, "Friendly", StringComparison.OrdinalIgnoreCase)) return 3;
if (string.Equals(relationship, "Beloved", StringComparison.OrdinalIgnoreCase)) return 4;
return 2;
}
private static bool LegacyHostile(
AetheriaRuntimeEntitySnapshotCommit left,
AetheriaRuntimeEntitySnapshotCommit right) =>
string.Equals(left.FactionKey, "player", StringComparison.OrdinalIgnoreCase) !=