Port autonomous resource surveying to daemon
This commit is contained in:
parent
5b94bec1aa
commit
27554981d1
6 changed files with 171 additions and 0 deletions
|
|
@ -23,6 +23,39 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
|
|||
TickReconcilesAndEvaluatesCatalogBehaviors();
|
||||
AgentMinesAsteroidThroughEquippedBehavior();
|
||||
CargoCapacityComesFromHullAndCatalogVolumes();
|
||||
AgentSurveysBodyIntoCorporationKnowledge();
|
||||
}
|
||||
|
||||
private static void AgentSurveysBodyIntoCorporationKnowledge()
|
||||
{
|
||||
var surveyor = Entity(0, 0, "workers");
|
||||
surveyor.AgentTaskCapabilities = [AetheriaRuntimeAgentTaskTypes.Explore];
|
||||
surveyor.Equipment = [new AetheriaRuntimeLoadoutItemSlotCommit { Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = "scanner", Enabled = true } }];
|
||||
var scanner = CatalogItem("scanner", new AetheriaRuntimeBehaviorPayload(0, "ResourceScanner", 0,
|
||||
[new AetheriaRuntimeBehaviorField(1, PerformanceStat(100)), new AetheriaRuntimeBehaviorField(2, PerformanceStat(4)), new AetheriaRuntimeBehaviorField(3, PerformanceStat(0.5))]));
|
||||
var catalog = new AetheriaRuntimeCatalogSnapshot([scanner], [], []);
|
||||
var run = new AetheriaRuntimeRunCheckpointCommit
|
||||
{
|
||||
CurrentZoneIndex = 0, CurrentEntityKey = "zone.0.entity.0",
|
||||
Zones = [new AetheriaRuntimeZoneSnapshotCommit
|
||||
{
|
||||
ZoneIndex = 0, Entities = [surveyor],
|
||||
Orbits = [new AetheriaRuntimeOrbitSnapshotCommit { OrbitKey = "survey-orbit", FixedPositionX = 10 }],
|
||||
Bodies = [new AetheriaRuntimeBodySnapshotCommit { BodyKey = "survey-world", Kind = "planet", OrbitKey = "survey-orbit" }]
|
||||
}],
|
||||
AgentTasks = [new AetheriaRuntimeAgentTaskCommit { TaskId = "survey-1", CorporationKey = "workers", TaskType = AetheriaRuntimeAgentTaskTypes.Explore, ZoneIndex = 0, Status = AetheriaRuntimeAgentTaskStatuses.Queued, TargetBodyKeys = ["survey-world"] }]
|
||||
};
|
||||
AetheriaRuntimeDaemonTickRunner.Tick(Path.Combine(Path.GetTempPath(), "aetheria-survey-smoke.cc"), run,
|
||||
new AetheriaRuntimeDaemonTickOptions { FrameId = 1, FixedDeltaSeconds = 1, SimulationTimeSeconds = 1, Catalog = catalog, BuildPublications = false });
|
||||
var knowledge = run.CorporationSurveys.Single();
|
||||
RequireEqual("workers", knowledge.CorporationKey, "survey knowledge must belong to the agent corporation");
|
||||
RequireEqual("survey-world", knowledge.BodyKey, "survey knowledge must identify the scanned body");
|
||||
RequireNear(4, knowledge.DensityFloor, 0.000001, "survey must publish the scanner minimum density");
|
||||
|
||||
AetheriaRuntimeDaemonTickRunner.Tick(Path.Combine(Path.GetTempPath(), "aetheria-survey-complete-smoke.cc"), run,
|
||||
new AetheriaRuntimeDaemonTickOptions { FrameId = 2, FixedDeltaSeconds = 1, SimulationTimeSeconds = 2, Catalog = catalog, BuildPublications = false });
|
||||
RequireEqual(AetheriaRuntimeAgentTaskStatuses.Completed, run.AgentTasks[0].Status,
|
||||
"survey order must complete when corporation knowledge satisfies the scanner threshold");
|
||||
}
|
||||
|
||||
private static void CargoCapacityComesFromHullAndCatalogVolumes()
|
||||
|
|
|
|||
|
|
@ -199,6 +199,12 @@ namespace GameCult.Aetheria.State.Verse
|
|||
commands.AddRange(PlanMining(zone!, task, agent, frameId, catalog, simulationTimeSeconds));
|
||||
continue;
|
||||
}
|
||||
if (string.Equals(task.TaskType, AetheriaRuntimeAgentTaskTypes.Explore, StringComparison.Ordinal) &&
|
||||
(task.TargetBodyKeys ?? Array.Empty<string>()).Any(key => !string.IsNullOrWhiteSpace(key)))
|
||||
{
|
||||
commands.AddRange(PlanSurvey(run, zone!, task, agent, frameId, catalog, simulationTimeSeconds));
|
||||
continue;
|
||||
}
|
||||
if (string.Equals(task.TaskType, AetheriaRuntimeAgentTaskTypes.Defend, StringComparison.Ordinal))
|
||||
{
|
||||
commands.AddRange(PlanPatrol(zone!, task, agent, frameId));
|
||||
|
|
@ -341,6 +347,52 @@ namespace GameCult.Aetheria.State.Verse
|
|||
};
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeDaemonCommandDocument> PlanSurvey(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
AetheriaRuntimeAgentTaskCommit task,
|
||||
AetheriaRuntimeEntitySnapshotCommit agent,
|
||||
long frameId,
|
||||
AetheriaRuntimeCatalogSnapshot? catalog,
|
||||
double simulationTimeSeconds)
|
||||
{
|
||||
var scanner = AetheriaRuntimeEquippedBehaviorQueries.Find(agent, catalog, "ResourceScanner").FirstOrDefault();
|
||||
if (scanner == null) { Fail(task, agent); return Array.Empty<AetheriaRuntimeDaemonCommandDocument>(); }
|
||||
var minimumDensity = scanner.EvaluateStat(2);
|
||||
var surveyed = new HashSet<string>((run.CorporationSurveys ?? Array.Empty<AetheriaRuntimeCorporationSurveyCommit>())
|
||||
.Where(value => string.Equals(value.CorporationKey, task.CorporationKey, StringComparison.Ordinal) && value.DensityFloor + 0.5 >= minimumDensity)
|
||||
.Select(value => value.BodyKey), StringComparer.Ordinal);
|
||||
var targets = (task.TargetBodyKeys ?? Array.Empty<string>()).Where(key => !surveyed.Contains(key)).ToArray();
|
||||
if (targets.Length == 0) { Complete(task, agent, frameId); return new[] { Movement(task, agent, frameId, 0, 0, 0) }; }
|
||||
|
||||
var candidates = targets.SelectMany(key =>
|
||||
{
|
||||
var body = (zone.Bodies ?? Array.Empty<AetheriaRuntimeBodySnapshotCommit>()).FirstOrDefault(value => value != null && string.Equals(value.BodyKey, key, StringComparison.Ordinal));
|
||||
if (body == null) return Array.Empty<(string Key, int Asteroid, double X, double Z)>();
|
||||
if (string.Equals(body.Kind, "asteroid_belt", StringComparison.OrdinalIgnoreCase))
|
||||
return AetheriaRuntimeDaemonRenderQueries.QueryAsteroidInstancePoses(zone, key, simulationTimeSeconds)
|
||||
.Select(pose => (Key: key, Asteroid: pose.AsteroidIndex, X: pose.PositionX, Z: pose.PositionZ)).ToArray();
|
||||
var pose = AetheriaRuntimeDaemonRenderQueries.QueryBodyPoses(zone).FirstOrDefault(value => string.Equals(value.BodyKey, key, StringComparison.Ordinal));
|
||||
return string.IsNullOrWhiteSpace(pose.BodyKey)
|
||||
? Array.Empty<(string Key, int Asteroid, double X, double Z)>()
|
||||
: new[] { (Key: key, Asteroid: -1, X: pose.CenterX, Z: pose.CenterZ) };
|
||||
}).OrderBy(value => Math.Pow(value.X - agent.PositionX, 2) + Math.Pow(value.Z - agent.PositionZ, 2)).FirstOrDefault();
|
||||
if (string.IsNullOrWhiteSpace(candidates.Key)) { Fail(task, agent); return Array.Empty<AetheriaRuntimeDaemonCommandDocument>(); }
|
||||
var dx = candidates.X - agent.PositionX; var dz = candidates.Z - agent.PositionZ;
|
||||
if (Math.Sqrt(dx * dx + dz * dz) >= Math.Max(0.01, scanner.EvaluateStat(1)))
|
||||
return new[] { Movement(task, agent, frameId, dx, dz, 1) };
|
||||
task.Phase = "scanning";
|
||||
return new[]
|
||||
{
|
||||
Movement(task, agent, frameId, 0, 0, 0),
|
||||
Command(task, agent, frameId, AetheriaRuntimeDaemonCommandKinds.SetBehaviorActive, "scan", command =>
|
||||
{
|
||||
command.EquipmentIndex = scanner.EquipmentIndex; command.BehaviorIndex = scanner.BehaviorIndex;
|
||||
command.ScalarValue = 1; command.TextValue = candidates.Key; command.PositionX = candidates.Asteroid;
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeDaemonCommandDocument> PlanHaul(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
"aetheria.starbridge.commander.root",
|
||||
StrategicWorldSurface("aetheria.starbridge.commander.world", run, zone),
|
||||
BuildAgentTaskBoard(run),
|
||||
BuildSurveyKnowledge(run),
|
||||
BuildStarbridgeStationStockCard(starbridge),
|
||||
BuildStarbridgeWaveForecastCard(starbridge),
|
||||
BuildStarbridgeRuntimeRolesCard(starbridge));
|
||||
|
|
@ -209,6 +210,27 @@ namespace GameCult.Aetheria.State.Verse
|
|||
tasks);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildSurveyKnowledge(AetheriaRuntimeRunCheckpointCommit run)
|
||||
{
|
||||
var entries = (run.CorporationSurveys ?? Array.Empty<AetheriaRuntimeCorporationSurveyCommit>())
|
||||
.Where(value => value != null)
|
||||
.OrderBy(value => value.CorporationKey, StringComparer.Ordinal)
|
||||
.ThenBy(value => value.BodyKey, StringComparer.Ordinal)
|
||||
.Select(value => Node(
|
||||
$"aetheria.starbridge.commander.surveys.{SurfaceToken(value.CorporationKey)}.{SurfaceToken(value.BodyKey)}",
|
||||
"list.item",
|
||||
new[]
|
||||
{
|
||||
("label", value.BodyKey),
|
||||
("corporation", value.CorporationKey),
|
||||
("bodyKey", value.BodyKey),
|
||||
("densityFloor", value.DensityFloor.ToString("0.###", CultureInfo.InvariantCulture)),
|
||||
("completedFrameId", value.CompletedFrameId.ToString(CultureInfo.InvariantCulture))
|
||||
}))
|
||||
.ToArray();
|
||||
return Node("aetheria.starbridge.commander.surveys", "list", new[] { ("title", "Survey Knowledge") }, entries);
|
||||
}
|
||||
|
||||
private static int TaskStatusOrder(string status) =>
|
||||
string.Equals(status, AetheriaRuntimeAgentTaskStatuses.Assigned, StringComparison.Ordinal) ? 0 :
|
||||
string.Equals(status, AetheriaRuntimeAgentTaskStatuses.Queued, StringComparison.Ordinal) ? 1 : 2;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
StepMovement(entities, deltaSeconds);
|
||||
StepCombat(run, zone, entities, intents, deltaSeconds, settings, projectilePhysics);
|
||||
AetheriaRuntimeMiningSimulation.Step(run, zone, entities, intents, catalog, frameId, simulationTimeSeconds, deltaSeconds);
|
||||
AetheriaRuntimeSurveySimulation.Step(run, zone, entities, intents, catalog, frameId, simulationTimeSeconds, deltaSeconds);
|
||||
StepTractorSalvage(run, zone, entities, settings);
|
||||
RefreshContacts(entities, settings);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,6 +199,10 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public IReadOnlyList<AetheriaRuntimeAgentTaskCommit> AgentTasks { get; set; } =
|
||||
Array.Empty<AetheriaRuntimeAgentTaskCommit>();
|
||||
|
||||
[Key(13)]
|
||||
public IReadOnlyList<AetheriaRuntimeCorporationSurveyCommit> CorporationSurveys { get; set; } =
|
||||
Array.Empty<AetheriaRuntimeCorporationSurveyCommit>();
|
||||
|
||||
public AetheriaRuntimeLoadoutTemplateCommit CreateLoadoutTemplate(string entityKey)
|
||||
{
|
||||
return TryParseEntityKey(entityKey, out var zoneIndex, out var entityIndex)
|
||||
|
|
@ -423,6 +427,15 @@ namespace GameCult.Aetheria.State.Verse
|
|||
}
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeCorporationSurveyCommit
|
||||
{
|
||||
[Key(0)] public string CorporationKey { get; set; } = "";
|
||||
[Key(1)] public string BodyKey { get; set; } = "";
|
||||
[Key(2)] public double DensityFloor { get; set; }
|
||||
[Key(3)] public long CompletedFrameId { get; set; } = -1;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeFactionRelationshipCommit
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Verse
|
||||
{
|
||||
public static class AetheriaRuntimeSurveySimulation
|
||||
{
|
||||
public static void Step(AetheriaRuntimeRunCheckpointCommit run, AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
IReadOnlyList<AetheriaRuntimeEntitySnapshotCommit> entities, AetheriaRuntimeDaemonIntentState intents,
|
||||
AetheriaRuntimeCatalogSnapshot? catalog, long frameId, double simulationTimeSeconds, double deltaSeconds)
|
||||
{
|
||||
foreach (var intent in intents?.Behaviors ?? Enumerable.Empty<AetheriaRuntimeDaemonBehaviorIntent>())
|
||||
{
|
||||
if (!intent.Active || !int.TryParse((intent.ActorEntityKey ?? "").Split('.').LastOrDefault(), out var index)) continue;
|
||||
var entity = entities.FirstOrDefault(value => value.EntityIndex == index && value.IsActive);
|
||||
var scanner = AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, "ResourceScanner")
|
||||
.FirstOrDefault(value => value.EquipmentIndex == intent.EquipmentIndex && value.BehaviorIndex == intent.BehaviorIndex);
|
||||
if (entity == null || scanner == null) continue;
|
||||
var body = (zone.Bodies ?? Array.Empty<AetheriaRuntimeBodySnapshotCommit>()).FirstOrDefault(value => value != null && string.Equals(value.BodyKey, intent.TargetBodyKey, StringComparison.Ordinal));
|
||||
if (body == null) continue;
|
||||
double x, z;
|
||||
if (intent.TargetAsteroidIndex >= 0)
|
||||
{
|
||||
var pose = AetheriaRuntimeDaemonRenderQueries.QueryAsteroidInstancePoses(zone, body.BodyKey, simulationTimeSeconds).FirstOrDefault(value => value.AsteroidIndex == intent.TargetAsteroidIndex);
|
||||
x = pose.PositionX; z = pose.PositionZ;
|
||||
}
|
||||
else
|
||||
{
|
||||
var pose = AetheriaRuntimeDaemonRenderQueries.QueryBodyPoses(zone).FirstOrDefault(value => string.Equals(value.BodyKey, body.BodyKey, StringComparison.Ordinal));
|
||||
x = pose.CenterX; z = pose.CenterZ;
|
||||
}
|
||||
var range = Math.Max(0, scanner.EvaluateStat(1));
|
||||
if (Math.Pow(x - entity.PositionX, 2) + Math.Pow(z - entity.PositionZ, 2) >= range * range) continue;
|
||||
var state = scanner.State;
|
||||
if (!string.Equals(state.ResourceScannerTargetBodyKey, body.BodyKey, StringComparison.Ordinal)) state.ResourceScannerScanTime = 0;
|
||||
state.ResourceScannerTargetBodyKey = body.BodyKey; state.ResourceScannerAsteroidIndex = intent.TargetAsteroidIndex;
|
||||
state.ResourceScannerRange = range; state.ResourceScannerMinimumDensity = scanner.EvaluateStat(2); state.ResourceScannerScanDuration = scanner.EvaluateStat(3);
|
||||
state.ResourceScannerScanTime += deltaSeconds;
|
||||
if (state.ResourceScannerScanTime <= state.ResourceScannerScanDuration) continue;
|
||||
var surveys = (run.CorporationSurveys ?? Array.Empty<AetheriaRuntimeCorporationSurveyCommit>()).ToList();
|
||||
var survey = surveys.FirstOrDefault(value => string.Equals(value.CorporationKey, entity.FactionKey, StringComparison.Ordinal) && string.Equals(value.BodyKey, body.BodyKey, StringComparison.Ordinal));
|
||||
if (survey == null) { survey = new AetheriaRuntimeCorporationSurveyCommit { CorporationKey = entity.FactionKey, BodyKey = body.BodyKey }; surveys.Add(survey); }
|
||||
survey.DensityFloor = state.ResourceScannerMinimumDensity; survey.CompletedFrameId = frameId; state.ResourceScannerScanTime = 0; run.CorporationSurveys = surveys;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue