Refactor station modules into typed runtime models
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using static SpaceGame.Api.Factions.AI.CommanderPlanningService;
|
||||
using static SpaceGame.Api.Shared.Runtime.SimulationRuntimeSupport;
|
||||
using SpaceGame.Api.Shared.Runtime;
|
||||
|
||||
namespace SpaceGame.Api.Stations.Simulation;
|
||||
|
||||
@@ -54,14 +55,14 @@ internal sealed class StationSimulationService
|
||||
_ => 0f,
|
||||
};
|
||||
var oreReserve = role == "refinery" ? 260f : 0f;
|
||||
var hullpartsReserve = MathF.Max(constructionHullpartsReserve, HasStationModules(station, "module_gen_build_l_01") ? 120f : 0f);
|
||||
var claytronicsReserve = MathF.Max(constructionClayReserve, HasStationModules(station, "module_gen_build_l_01") ? 120f : 0f);
|
||||
var hullpartsReserve = MathF.Max(constructionHullpartsReserve, HasShipyardCapability(station) ? 120f : 0f);
|
||||
var claytronicsReserve = MathF.Max(constructionClayReserve, HasShipyardCapability(station) ? 120f : 0f);
|
||||
var grapheneReserve = role == "graphene" ? 120f : 0f;
|
||||
var siliconWafersReserve = role == "siliconwafers" ? 120f : 0f;
|
||||
var antimatterCellsReserve = role == "antimattercells" ? 120f : 0f;
|
||||
var superfluidCoolantReserve = role == "superfluidcoolant" ? 120f : 0f;
|
||||
var quantumTubesReserve = role == "quantumtubes" ? 120f : 0f;
|
||||
var shipPartsReserve = HasStationModules(station, "module_gen_build_l_01")
|
||||
var shipPartsReserve = HasShipyardCapability(station)
|
||||
&& GetShipProductionPressure(world, station.FactionId, "military") > 0.2f
|
||||
? 90f
|
||||
: 0f;
|
||||
@@ -116,7 +117,7 @@ internal sealed class StationSimulationService
|
||||
var constructionHullpartsReserve = GetConstructionDemandForItem(world, site, "hullparts");
|
||||
var constructionClayReserve = GetConstructionDemandForItem(world, site, "claytronics");
|
||||
var constructionRefinedReserve = GetConstructionDemandForItem(world, site, "refinedmetals");
|
||||
var shipPartsReserve = HasStationModules(station, "module_gen_build_l_01")
|
||||
var shipPartsReserve = HasShipyardCapability(station)
|
||||
&& GetShipProductionPressure(world, station.FactionId, "military") > 0.2f
|
||||
? 90f
|
||||
: 0f;
|
||||
@@ -151,8 +152,8 @@ internal sealed class StationSimulationService
|
||||
"refinery" => 80f,
|
||||
_ => 0f,
|
||||
}, constructionRefinedReserve),
|
||||
"hullparts" => MathF.Max(constructionHullpartsReserve, HasStationModules(station, "module_gen_build_l_01") ? 120f : 0f) + shipPartsReserve,
|
||||
"claytronics" => MathF.Max(constructionClayReserve, HasStationModules(station, "module_gen_build_l_01") ? 120f : 0f),
|
||||
"hullparts" => MathF.Max(constructionHullpartsReserve, HasShipyardCapability(station) ? 120f : 0f) + shipPartsReserve,
|
||||
"claytronics" => MathF.Max(constructionClayReserve, HasShipyardCapability(station) ? 120f : 0f),
|
||||
"graphene" => MathF.Max(role == "graphene" ? 120f : 0f, role == "quantumtubes" ? 160f : 0f),
|
||||
"siliconwafers" => role == "siliconwafers" ? 120f : 0f,
|
||||
"antimattercells" => MathF.Max(role == "antimattercells" ? 120f : 0f, role == "claytronics" ? 120f : 0f),
|
||||
@@ -292,7 +293,7 @@ internal sealed class StationSimulationService
|
||||
|
||||
if (outputItemIds.Contains("hullparts"))
|
||||
{
|
||||
return HasStationModules(station, "module_gen_prod_advancedelectronics_01", "module_gen_build_l_01")
|
||||
return HasShipyardCapability(station) && HasStationModules(station, "module_gen_prod_advancedelectronics_01")
|
||||
? -140f * MathF.Max(expansionPressure, fleetPressure)
|
||||
: 280f * MathF.Max(expansionPressure, fleetPressure);
|
||||
}
|
||||
@@ -407,20 +408,25 @@ internal sealed class StationSimulationService
|
||||
return false;
|
||||
}
|
||||
|
||||
var requiredModule = GetStorageRequirement(itemDefinition.CargoKind);
|
||||
if (requiredModule is not null && !station.InstalledModules.Contains(requiredModule, StringComparer.Ordinal))
|
||||
var storageKind = itemDefinition.CargoStorageKind;
|
||||
if (storageKind is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var capacity = GetStationStorageCapacity(station, itemDefinition.CargoKind);
|
||||
if (!HasStorageCapacity(world, station, storageKind.Value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var capacity = GetStationStorageCapacity(world, station, storageKind.Value);
|
||||
if (capacity <= 0.01f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var used = station.Inventory
|
||||
.Where(entry => world.ItemDefinitions.TryGetValue(entry.Key, out var definition) && definition.CargoKind == itemDefinition.CargoKind)
|
||||
.Where(entry => world.ItemDefinitions.TryGetValue(entry.Key, out var definition) && definition.CargoStorageKind == storageKind)
|
||||
.Sum(entry => entry.Value);
|
||||
return used + amount <= capacity + 0.001f;
|
||||
}
|
||||
@@ -455,7 +461,7 @@ internal sealed class StationSimulationService
|
||||
return objective;
|
||||
}
|
||||
|
||||
if (HasStationModules(station, "module_gen_build_l_01"))
|
||||
if (HasShipyardCapability(station))
|
||||
{
|
||||
return "shipyard";
|
||||
}
|
||||
@@ -513,6 +519,9 @@ internal sealed class StationSimulationService
|
||||
return "general";
|
||||
}
|
||||
|
||||
private static bool HasShipyardCapability(StationRuntime station) =>
|
||||
CountStationModules(station, ModuleType.BuildModule) > 0;
|
||||
|
||||
private static float GetConstructionDemandForItem(SimulationWorld world, ConstructionSiteRuntime? site, string itemId)
|
||||
{
|
||||
if (site is null || !site.RequiredItems.TryGetValue(itemId, out var required))
|
||||
|
||||
Reference in New Issue
Block a user