Refactor station modules into typed runtime models
This commit is contained in:
@@ -162,21 +162,21 @@ internal sealed class InfrastructureSimulationService
|
||||
|
||||
private static IEnumerable<string> GetStoragePressureCandidates(SimulationWorld world, StationRuntime station)
|
||||
{
|
||||
foreach (var (storageClass, moduleId) in new[]
|
||||
foreach (var (storageKind, moduleId) in new[]
|
||||
{
|
||||
("solid", "module_arg_stor_solid_m_01"),
|
||||
("liquid", "module_arg_stor_liquid_m_01"),
|
||||
("container", "module_arg_stor_container_m_01"),
|
||||
(StorageKind.Solid, "module_arg_stor_solid_m_01"),
|
||||
(StorageKind.Liquid, "module_arg_stor_liquid_m_01"),
|
||||
(StorageKind.Container, "module_arg_stor_container_m_01"),
|
||||
})
|
||||
{
|
||||
var capacity = GetStationStorageCapacity(station, storageClass);
|
||||
var capacity = GetStationStorageCapacity(world, station, storageKind);
|
||||
if (capacity <= 0.01f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var used = station.Inventory
|
||||
.Where(entry => world.ItemDefinitions.TryGetValue(entry.Key, out var def) && def.CargoKind == storageClass)
|
||||
.Where(entry => world.ItemDefinitions.TryGetValue(entry.Key, out var def) && def.CargoStorageKind == storageKind)
|
||||
.Sum(entry => entry.Value);
|
||||
if (used / capacity >= 0.65f)
|
||||
{
|
||||
@@ -195,14 +195,10 @@ internal sealed class InfrastructureSimulationService
|
||||
continue;
|
||||
}
|
||||
|
||||
if (GetStorageRequirement(itemDefinition.CargoKind) is { } storageModuleId)
|
||||
if (GetStorageRequirement(world.ModuleDefinitions, itemDefinition.CargoStorageKind) is { } storageModuleId)
|
||||
{
|
||||
yield return storageModuleId;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return "module_arg_stor_container_m_01";
|
||||
}
|
||||
}
|
||||
|
||||
if (world.ModuleDefinitions.TryGetValue(recipe.ModuleId, out var moduleDefinition))
|
||||
@@ -214,14 +210,10 @@ internal sealed class InfrastructureSimulationService
|
||||
continue;
|
||||
}
|
||||
|
||||
if (GetStorageRequirement(itemDefinition.CargoKind) is { } storageModuleId)
|
||||
if (GetStorageRequirement(world.ModuleDefinitions, itemDefinition.CargoStorageKind) is { } storageModuleId)
|
||||
{
|
||||
yield return storageModuleId;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return "module_arg_stor_container_m_01";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -324,16 +316,16 @@ internal sealed class InfrastructureSimulationService
|
||||
string? objectiveCommodityId,
|
||||
bool requiredByObjective)
|
||||
{
|
||||
var storageClass = storageModuleId switch
|
||||
var storageKind = storageModuleId switch
|
||||
{
|
||||
"module_arg_stor_solid_m_01" => "solid",
|
||||
"module_arg_stor_liquid_m_01" => "liquid",
|
||||
_ => "container",
|
||||
"module_arg_stor_solid_m_01" => StorageKind.Solid,
|
||||
"module_arg_stor_liquid_m_01" => StorageKind.Liquid,
|
||||
_ => StorageKind.Container,
|
||||
};
|
||||
|
||||
var capacity = GetStationStorageCapacity(station, storageClass);
|
||||
var capacity = GetStationStorageCapacity(world, station, storageKind);
|
||||
var used = station.Inventory
|
||||
.Where(entry => world.ItemDefinitions.TryGetValue(entry.Key, out var def) && def.CargoKind == storageClass)
|
||||
.Where(entry => world.ItemDefinitions.TryGetValue(entry.Key, out var def) && def.CargoStorageKind == storageKind)
|
||||
.Sum(entry => entry.Value);
|
||||
var utilization = capacity <= 0.01f ? 0f : used / capacity;
|
||||
|
||||
@@ -342,8 +334,8 @@ internal sealed class InfrastructureSimulationService
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(objectiveModuleId) && !string.IsNullOrWhiteSpace(objectiveCommodityId))
|
||||
{
|
||||
var objectiveUsesStorage = ModuleNeedsStorageClass(world, objectiveModuleId, storageClass)
|
||||
|| CommodityUsesStorageClass(world, objectiveCommodityId, storageClass);
|
||||
var objectiveUsesStorage = ModuleNeedsStorageClass(world, objectiveModuleId, storageKind)
|
||||
|| CommodityUsesStorageClass(world, objectiveCommodityId, storageKind);
|
||||
if (objectiveUsesStorage)
|
||||
{
|
||||
score += 35f;
|
||||
@@ -579,15 +571,15 @@ internal sealed class InfrastructureSimulationService
|
||||
case "module_arg_stor_container_m_01":
|
||||
case "module_arg_stor_solid_m_01":
|
||||
case "module_arg_stor_liquid_m_01":
|
||||
var storageClass = supportModuleId switch
|
||||
var storageKind = supportModuleId switch
|
||||
{
|
||||
"module_arg_stor_solid_m_01" => "solid",
|
||||
"module_arg_stor_liquid_m_01" => "liquid",
|
||||
_ => "container",
|
||||
"module_arg_stor_solid_m_01" => StorageKind.Solid,
|
||||
"module_arg_stor_liquid_m_01" => StorageKind.Liquid,
|
||||
_ => StorageKind.Container,
|
||||
};
|
||||
if (analysis.HasMissingOutputStorage
|
||||
&& (ModuleNeedsStorageClass(world, objectiveModuleId, storageClass)
|
||||
|| CommodityUsesStorageClass(world, objectiveCommodityId, storageClass)))
|
||||
&& (ModuleNeedsStorageClass(world, objectiveModuleId, storageKind)
|
||||
|| CommodityUsesStorageClass(world, objectiveCommodityId, storageKind)))
|
||||
{
|
||||
unlockScore += 70f;
|
||||
}
|
||||
@@ -688,7 +680,7 @@ internal sealed class InfrastructureSimulationService
|
||||
return demand;
|
||||
}
|
||||
|
||||
private static bool ModuleNeedsStorageClass(SimulationWorld world, string moduleId, string storageClass)
|
||||
private static bool ModuleNeedsStorageClass(SimulationWorld world, string moduleId, StorageKind storageKind)
|
||||
{
|
||||
if (!world.ModuleRecipes.TryGetValue(moduleId, out var recipe))
|
||||
{
|
||||
@@ -697,12 +689,12 @@ internal sealed class InfrastructureSimulationService
|
||||
|
||||
return recipe.Inputs.Any(input =>
|
||||
world.ItemDefinitions.TryGetValue(input.ItemId, out var itemDefinition)
|
||||
&& string.Equals(itemDefinition.CargoKind, storageClass, StringComparison.Ordinal));
|
||||
&& itemDefinition.CargoStorageKind == storageKind);
|
||||
}
|
||||
|
||||
private static bool CommodityUsesStorageClass(SimulationWorld world, string commodityId, string storageClass) =>
|
||||
private static bool CommodityUsesStorageClass(SimulationWorld world, string commodityId, StorageKind storageKind) =>
|
||||
world.ItemDefinitions.TryGetValue(commodityId, out var itemDefinition)
|
||||
&& string.Equals(itemDefinition.CargoKind, storageClass, StringComparison.Ordinal);
|
||||
&& itemDefinition.CargoStorageKind == storageKind;
|
||||
|
||||
private static bool CanStationAcceptStationOutputSoon(SimulationWorld world, StationRuntime station, string itemId, float amount)
|
||||
{
|
||||
@@ -711,14 +703,19 @@ internal sealed class InfrastructureSimulationService
|
||||
return false;
|
||||
}
|
||||
|
||||
var capacity = GetStationStorageCapacity(station, itemDefinition.CargoKind);
|
||||
if (itemDefinition.CargoStorageKind is not { } storageKind)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var capacity = GetStationStorageCapacity(world, station, storageKind);
|
||||
if (capacity <= 0.01f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var used = station.Inventory
|
||||
.Where(entry => world.ItemDefinitions.TryGetValue(entry.Key, out var definition) && string.Equals(definition.CargoKind, itemDefinition.CargoKind, StringComparison.Ordinal))
|
||||
.Where(entry => world.ItemDefinitions.TryGetValue(entry.Key, out var definition) && definition.CargoStorageKind == storageKind)
|
||||
.Sum(entry => entry.Value);
|
||||
return used + amount <= capacity * 0.95f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user