Complete autonomous mining offload loop
This commit is contained in:
parent
4fc2808989
commit
5b94bec1aa
5 changed files with 95 additions and 6 deletions
|
|
@ -50,17 +50,29 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
|
|||
private static void AgentMinesAsteroidThroughEquippedBehavior()
|
||||
{
|
||||
var miner = Entity(0, 0, "workers");
|
||||
var home = Entity(1, 0, "workers");
|
||||
miner.AgentTaskCapabilities = [AetheriaRuntimeAgentTaskTypes.Mine];
|
||||
miner.Equipment = [new AetheriaRuntimeLoadoutItemSlotCommit { Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = "mining-tool", Enabled = true, Quality = 1, Durability = 1 } }];
|
||||
var minerHull = CatalogItem("miner-hull");
|
||||
minerHull.HullCapacity = PerformanceStat(2);
|
||||
var homeHull = CatalogItem("home-hull");
|
||||
homeHull.HullCapacity = PerformanceStat(100);
|
||||
var iron = CatalogItem("iron");
|
||||
iron.SimpleCommodityCategory = "ore";
|
||||
iron.Volume = 1;
|
||||
miner.HullItemKey = minerHull.ItemKey;
|
||||
home.HullItemKey = homeHull.ItemKey;
|
||||
miner.CargoContents = [new AetheriaRuntimeCargoBayLoadoutCommit()];
|
||||
home.CargoContents = [new AetheriaRuntimeCargoBayLoadoutCommit()];
|
||||
var catalog = new AetheriaRuntimeCatalogSnapshot(
|
||||
[CatalogItem("mining-tool", new AetheriaRuntimeBehaviorPayload(0, "MiningTool", 0,
|
||||
[minerHull, homeHull, iron, CatalogItem("mining-tool", new AetheriaRuntimeBehaviorPayload(0, "MiningTool", 0,
|
||||
[new AetheriaRuntimeBehaviorField(1, PerformanceStat(1000)), new AetheriaRuntimeBehaviorField(2, PerformanceStat(1000000000)), new AetheriaRuntimeBehaviorField(3, PerformanceStat(2)), new AetheriaRuntimeBehaviorField(4, PerformanceStat(1000))]))],
|
||||
[], []);
|
||||
var asteroid = new AetheriaRuntimeAsteroidCommit { Distance = 0, Size = 6 };
|
||||
var zone = new AetheriaRuntimeZoneSnapshotCommit
|
||||
{
|
||||
ZoneIndex = 0,
|
||||
Entities = [miner],
|
||||
Entities = [miner, home],
|
||||
Bodies = [new AetheriaRuntimeBodySnapshotCommit { BodyKey = "belt", Kind = "asteroid_belt", Asteroids = [asteroid], Resources = [new AetheriaRuntimeBodyResourceCommit { ItemKey = "iron", Amount = 1 }] }]
|
||||
};
|
||||
var run = new AetheriaRuntimeRunCheckpointCommit
|
||||
|
|
@ -69,7 +81,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
|
|||
CurrentZoneIndex = 0,
|
||||
CurrentEntityKey = "zone.0.entity.0",
|
||||
Zones = [zone],
|
||||
AgentTasks = [new AetheriaRuntimeAgentTaskCommit { TaskId = "mine-1", CorporationKey = "workers", TaskType = AetheriaRuntimeAgentTaskTypes.Mine, ZoneIndex = 0, Status = AetheriaRuntimeAgentTaskStatuses.Queued, TargetBodyKeys = ["belt"] }]
|
||||
AgentTasks = [new AetheriaRuntimeAgentTaskCommit { TaskId = "mine-1", CorporationKey = "workers", TaskType = AetheriaRuntimeAgentTaskTypes.Mine, ZoneIndex = 0, OriginEntityIndex = 1, CompletionRadius = 10, Status = AetheriaRuntimeAgentTaskStatuses.Queued, TargetBodyKeys = ["belt"] }]
|
||||
};
|
||||
|
||||
var result = AetheriaRuntimeDaemonTickRunner.Tick(Path.Combine(Path.GetTempPath(), "aetheria-mining-smoke.cc"), run,
|
||||
|
|
@ -83,6 +95,15 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
|
|||
Require(committedAsteroid.RespawnTimer > 0, $"mining damage must deplete the asteroid and start historical respawn (damage={committedAsteroid.Damage}, respawn={committedAsteroid.RespawnTimer})");
|
||||
Require(committedMiner.CargoContents.SelectMany(bay => bay.Items).Any(slot => slot.Item.ItemKey == "iron" && slot.Item.Quantity > 0),
|
||||
"historical mining yield must enter daemon-owned cargo");
|
||||
|
||||
AetheriaRuntimeDaemonTickRunner.Tick(Path.Combine(Path.GetTempPath(), "aetheria-mining-offload-smoke.cc"), run,
|
||||
new AetheriaRuntimeDaemonTickOptions { FrameId = 2, FixedDeltaSeconds = 1, SimulationTimeSeconds = 2, Catalog = catalog, BuildPublications = false });
|
||||
Require(!run.Zones[0].Entities[0].CargoContents.SelectMany(bay => bay.Items).Any(),
|
||||
"full miner must offload through the shared cargo transfer command");
|
||||
Require(run.Zones[0].Entities[1].CargoContents.SelectMany(bay => bay.Items).Any(slot => slot.Item.ItemKey == "iron" && slot.Item.Quantity == 1),
|
||||
"home storage must receive the mined commodity");
|
||||
RequireEqual(AetheriaRuntimeAgentTaskStatuses.Assigned, run.AgentTasks[0].Status,
|
||||
"miner must remain assigned after a successful offload");
|
||||
}
|
||||
|
||||
private static void TickReconcilesAndEvaluatesCatalogBehaviors()
|
||||
|
|
|
|||
|
|
@ -128,6 +128,15 @@ namespace GameCult.Aetheria.State.Verse
|
|||
if (rejected.Contains(pickupId) || rejected.Contains(deliveryId))
|
||||
task.PendingQuantity = 0;
|
||||
}
|
||||
foreach (var task in (run?.AgentTasks ?? Array.Empty<AetheriaRuntimeAgentTaskCommit>())
|
||||
.Where(task => task != null && string.Equals(task.TaskType, AetheriaRuntimeAgentTaskTypes.Mine, StringComparison.Ordinal)))
|
||||
{
|
||||
if (!rejected.Contains(CommandId(task, frameId, "offload")))
|
||||
continue;
|
||||
var agent = FindEntity(run, task.ZoneIndex, task.AssignedEntityIndex);
|
||||
if (agent != null)
|
||||
Complete(task, agent, frameId);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssignQueuedTasks(AetheriaRuntimeRunCheckpointCommit run, long frameId)
|
||||
|
|
@ -240,6 +249,59 @@ namespace GameCult.Aetheria.State.Verse
|
|||
AetheriaRuntimeCatalogSnapshot? catalog,
|
||||
double simulationTimeSeconds)
|
||||
{
|
||||
var home = zone.Entities.FirstOrDefault(entity => entity != null && entity.EntityIndex == task.OriginEntityIndex);
|
||||
if (string.Equals(task.Phase, "offload", StringComparison.Ordinal) ||
|
||||
AetheriaRuntimeCargoCapacityQueries.Available(agent, catalog) < 1)
|
||||
{
|
||||
if (home == null)
|
||||
{
|
||||
Fail(task, agent);
|
||||
return Array.Empty<AetheriaRuntimeDaemonCommandDocument>();
|
||||
}
|
||||
task.Phase = "offload";
|
||||
var homeDx = home.PositionX - agent.PositionX;
|
||||
var homeDz = home.PositionZ - agent.PositionZ;
|
||||
if (Math.Sqrt(homeDx * homeDx + homeDz * homeDz) > Math.Max(0.01, task.CompletionRadius))
|
||||
return new[] { Movement(task, agent, frameId, homeDx, homeDz, 1) };
|
||||
|
||||
var commodity = (agent.CargoContents ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>())
|
||||
.SelectMany((bay, bayIndex) => (bay?.Items ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>())
|
||||
.Where(slot => slot?.Item != null && !string.IsNullOrWhiteSpace(catalog?.FindItem(slot.Item.ItemKey)?.SimpleCommodityCategory))
|
||||
.Select(slot => (BayIndex: bayIndex, Slot: slot)))
|
||||
.FirstOrDefault();
|
||||
if (commodity.Slot == null)
|
||||
{
|
||||
task.Phase = "mining";
|
||||
return new[] { Movement(task, agent, frameId, 0, 0, 0) };
|
||||
}
|
||||
var quantity = Math.Min(commodity.Slot.Item.Quantity,
|
||||
AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(home, catalog, commodity.Slot.Item.ItemKey));
|
||||
if (quantity <= 0)
|
||||
{
|
||||
Complete(task, agent, frameId);
|
||||
return new[] { Movement(task, agent, frameId, 0, 0, 0) };
|
||||
}
|
||||
return new[]
|
||||
{
|
||||
Movement(task, agent, frameId, 0, 0, 0),
|
||||
Command(task, agent, frameId, AetheriaRuntimeDaemonCommandKinds.TransferCargoItem, "offload", command =>
|
||||
{
|
||||
command.TextValue = commodity.Slot.Item.ItemKey;
|
||||
command.ScalarValue = quantity;
|
||||
command.TargetEntityKey = $"zone.{task.ZoneIndex}.entity.{home.EntityIndex}";
|
||||
command.CargoTransfer = new AetheriaRuntimeCargoTransferCommand
|
||||
{
|
||||
OriginEntityKey = $"zone.{task.ZoneIndex}.entity.{agent.EntityIndex}",
|
||||
OriginCargoIndex = commodity.BayIndex,
|
||||
DestinationEntityKey = $"zone.{task.ZoneIndex}.entity.{home.EntityIndex}",
|
||||
DestinationCargoIndex = 0,
|
||||
SourceX = commodity.Slot.X,
|
||||
SourceY = commodity.Slot.Y,
|
||||
Quantity = quantity
|
||||
};
|
||||
})
|
||||
};
|
||||
}
|
||||
var tool = AetheriaRuntimeEquippedBehaviorQueries.Find(agent, catalog, "MiningTool").FirstOrDefault();
|
||||
var bodyKey = (task.TargetBodyKeys ?? Array.Empty<string>()).FirstOrDefault() ?? "";
|
||||
var body = (zone.Bodies ?? Array.Empty<AetheriaRuntimeBodySnapshotCommit>())
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public double DockingDistance { get; set; } = AetheriaRuntimeDaemonOperationContext.DefaultDockingDistance;
|
||||
|
||||
public double WormholeExitRadius { get; set; } = AetheriaRuntimeDaemonOperationContext.DefaultWormholeExitRadius;
|
||||
public AetheriaRuntimeCatalogSnapshot? Catalog { get; set; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeDaemonOperations
|
||||
|
|
@ -134,7 +135,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
case AetheriaRuntimeDaemonCommandKinds.SetDockedCurrentShip:
|
||||
return ApplySetDockedCurrentShip(run, command.TargetEntityKey);
|
||||
case AetheriaRuntimeDaemonCommandKinds.TransferCargoItem:
|
||||
return ApplyTransferCargoItem(run, command);
|
||||
return ApplyTransferCargoItem(run, command, context.Catalog);
|
||||
case AetheriaRuntimeDaemonCommandKinds.EquipItem:
|
||||
return ApplyEquipItem(run, command);
|
||||
case AetheriaRuntimeDaemonCommandKinds.StoreItem:
|
||||
|
|
@ -649,7 +650,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
|
||||
private static bool ApplyTransferCargoItem(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeDaemonCommandDocument command)
|
||||
AetheriaRuntimeDaemonCommandDocument command,
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
var transfer = command.CargoTransfer ?? new AetheriaRuntimeCargoTransferCommand();
|
||||
if (!TryResolveCargoBay(
|
||||
|
|
@ -682,6 +684,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
var quantity = transfer.Quantity > 0
|
||||
? transfer.Quantity
|
||||
: (int)Math.Round(command.ScalarValue);
|
||||
if (quantity <= 0 || quantity > AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(destinationEntity, catalog, command.TextValue))
|
||||
return false;
|
||||
if (!TryRemoveCargoItemQuantity(
|
||||
originEntity,
|
||||
originCargoIndex,
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
run ??= new AetheriaRuntimeRunCheckpointCommit();
|
||||
options ??= new AetheriaRuntimeDaemonTickOptions();
|
||||
options.OperationContext ??= new AetheriaRuntimeDaemonOperationContext();
|
||||
options.OperationContext.Catalog = options.Catalog;
|
||||
EnsureBehaviorStates(run, options.Catalog);
|
||||
|
||||
var observedCommands = (options.ObservedCommands ?? Array.Empty<AetheriaRuntimeDaemonCommandDocument>())
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
if (efficiency * Roll(run.GenerationSeed, frameId, minerIndex, intent.TargetAsteroidIndex, "yield") * accumulator.Amount * resources.Length / MiningDifficulty > 1)
|
||||
{
|
||||
accumulator.Amount = 0;
|
||||
AddCargo(miner, resource.ItemKey);
|
||||
if (AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(miner, catalog, resource.ItemKey) > 0)
|
||||
AddCargo(miner, resource.ItemKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue