Restore authored hull cargo capacity
This commit is contained in:
parent
922b0b06ac
commit
4fc2808989
4 changed files with 80 additions and 3 deletions
|
|
@ -22,6 +22,29 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
|
|||
AgentPatrolsHistoricalOrbitCircuitThroughMovementCommands();
|
||||
TickReconcilesAndEvaluatesCatalogBehaviors();
|
||||
AgentMinesAsteroidThroughEquippedBehavior();
|
||||
CargoCapacityComesFromHullAndCatalogVolumes();
|
||||
}
|
||||
|
||||
private static void CargoCapacityComesFromHullAndCatalogVolumes()
|
||||
{
|
||||
var hull = CatalogItem("hauler-hull");
|
||||
hull.HullCapacity = PerformanceStat(20);
|
||||
var gear = CatalogItem("scanner");
|
||||
gear.Volume = 3;
|
||||
var ore = CatalogItem("ore");
|
||||
ore.Volume = 2;
|
||||
var catalog = new AetheriaRuntimeCatalogSnapshot([hull, gear, ore], [], []);
|
||||
var entity = Entity(0, 0, "workers");
|
||||
entity.HullItemKey = hull.ItemKey;
|
||||
entity.Equipment = [new AetheriaRuntimeLoadoutItemSlotCommit { Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = gear.ItemKey } }];
|
||||
entity.CargoContents = [new AetheriaRuntimeCargoBayLoadoutCommit { Items = [new AetheriaRuntimeLoadoutItemSlotCommit { Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = ore.ItemKey, Quantity = 4 } }] }];
|
||||
|
||||
RequireNear(20, AetheriaRuntimeCargoCapacityQueries.Capacity(entity, catalog), 0.000001,
|
||||
"cargo capacity must evaluate the authored hull performance stat");
|
||||
RequireNear(11, AetheriaRuntimeCargoCapacityQueries.Occupied(entity, catalog), 0.000001,
|
||||
"equipment and stacked cargo must consume catalog volume");
|
||||
RequireEqual(4, AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(entity, catalog, ore.ItemKey),
|
||||
"available cargo volume must determine whole units that fit");
|
||||
}
|
||||
|
||||
private static void AgentMinesAsteroidThroughEquippedBehavior()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Verse
|
||||
{
|
||||
public static class AetheriaRuntimeCargoCapacityQueries
|
||||
{
|
||||
public static double Capacity(AetheriaRuntimeEntitySnapshotCommit? entity, AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
if (entity == null || catalog == null)
|
||||
return 0;
|
||||
var hull = catalog.FindItem(entity.HullItemKey ?? "");
|
||||
if (hull == null)
|
||||
return 0;
|
||||
return Math.Max(0, AetheriaRuntimeDaemonItemStatQueries.EvaluatePerformanceStat(
|
||||
hull.HullCapacity,
|
||||
new AetheriaRuntimeLoadoutItemCommit { ItemKey = hull.ItemKey, Quality = 1, Durability = 1, Enabled = true },
|
||||
1));
|
||||
}
|
||||
|
||||
public static double Occupied(AetheriaRuntimeEntitySnapshotCommit? entity, AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
if (entity == null || catalog == null)
|
||||
return 0;
|
||||
var equipment = (entity.Equipment ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>())
|
||||
.Sum(slot => Volume(slot?.Item, catalog));
|
||||
var cargo = (entity.CargoContents ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>())
|
||||
.SelectMany(bay => bay?.Items ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>())
|
||||
.Sum(slot => Volume(slot?.Item, catalog));
|
||||
return equipment + cargo;
|
||||
}
|
||||
|
||||
public static double Available(AetheriaRuntimeEntitySnapshotCommit? entity, AetheriaRuntimeCatalogSnapshot? catalog) =>
|
||||
Math.Max(0, Capacity(entity, catalog) - Occupied(entity, catalog));
|
||||
|
||||
public static int UnitsThatFit(AetheriaRuntimeEntitySnapshotCommit? entity, AetheriaRuntimeCatalogSnapshot? catalog, string itemKey)
|
||||
{
|
||||
var volume = catalog?.FindItem(itemKey ?? "")?.Volume ?? 0;
|
||||
return volume <= 0 ? int.MaxValue : Math.Max(0, (int)Math.Floor(Available(entity, catalog) / volume));
|
||||
}
|
||||
|
||||
private static double Volume(AetheriaRuntimeLoadoutItemCommit? item, AetheriaRuntimeCatalogSnapshot catalog) =>
|
||||
item == null ? 0 : Math.Max(0, catalog.FindItem(item.ItemKey ?? "")?.Volume ?? 0) * Math.Max(1, item.Quantity);
|
||||
}
|
||||
}
|
||||
|
|
@ -185,7 +185,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
IReadOnlyList<AetheriaRuntimeAudioStat> audioStats,
|
||||
IReadOnlyList<AetheriaRuntimeCurveKey> effectivenessCurveKeys,
|
||||
string simpleCommodityCategory,
|
||||
string compoundCommodityCategory)
|
||||
string compoundCommodityCategory,
|
||||
AetheriaRuntimeBehaviorValue? hullCapacity = null)
|
||||
{
|
||||
ItemKey = itemKey;
|
||||
Name = name;
|
||||
|
|
@ -235,6 +236,10 @@ namespace GameCult.Aetheria.State.Verse
|
|||
EffectivenessCurveKeys = effectivenessCurveKeys;
|
||||
SimpleCommodityCategory = simpleCommodityCategory;
|
||||
CompoundCommodityCategory = compoundCommodityCategory;
|
||||
HullCapacity = hullCapacity ?? new AetheriaRuntimeBehaviorValue(
|
||||
"", "", 0, false, "", "",
|
||||
Array.Empty<AetheriaRuntimeBehaviorValue>(),
|
||||
Array.Empty<AetheriaRuntimeBehaviorMapEntry>());
|
||||
}
|
||||
|
||||
public string ItemKey { get; set; }
|
||||
|
|
@ -247,6 +252,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public double SpecificHeat { get; set; }
|
||||
public double Conductivity { get; set; }
|
||||
public double Volume { get; set; }
|
||||
public AetheriaRuntimeBehaviorValue HullCapacity { get; set; }
|
||||
public int ShapeWidth { get; set; }
|
||||
public int ShapeHeight { get; set; }
|
||||
public int OccupiedCells { get; set; }
|
||||
|
|
|
|||
|
|
@ -707,7 +707,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
var hardpointType = ReadFieldString(ref reader, fields, 12);
|
||||
var hullType = ReadFieldString(ref reader, fields, 13);
|
||||
var behaviorKinds = ReadFieldStringArray(ref reader, fields, 14);
|
||||
SkipField(ref reader, fields, 15);
|
||||
var hullCapacity = ReadFieldBehaviorValue(ref reader, fields, 15);
|
||||
var maxStack = ReadFieldInt32(ref reader, fields, 16);
|
||||
var stackable = ReadFieldBool(ref reader, fields, 17);
|
||||
var duration = ReadFieldDouble(ref reader, fields, 18);
|
||||
|
|
@ -792,7 +792,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
audioStats,
|
||||
effectivenessCurveKeys,
|
||||
simpleCommodityCategory,
|
||||
compoundCommodityCategory);
|
||||
compoundCommodityCategory,
|
||||
hullCapacity);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCorporation ReadCorporation(byte[] payload)
|
||||
|
|
|
|||
Loading…
Reference in a new issue