feat: simplify station production

This commit is contained in:
2026-03-17 20:38:13 -04:00
parent 0ae53b76e8
commit b3508d9d08
4 changed files with 29 additions and 63 deletions

View File

@@ -86,7 +86,7 @@ public sealed partial class SimulationEngine
private void RunStationProduction(SimulationWorld world, StationRuntime station, float deltaSeconds, ICollection<SimulationEventRecord> events)
{
var faction = world.Factions.FirstOrDefault(candidate => candidate.Id == station.FactionId);
foreach (var laneKey in GetStationProductionLanes(station))
foreach (var laneKey in GetStationProductionLanes(world, station))
{
var recipe = SelectProductionRecipe(world, station, laneKey);
if (recipe is null)
@@ -95,7 +95,7 @@ public sealed partial class SimulationEngine
continue;
}
var throughput = GetStationProductionThroughput(station, recipe);
var throughput = GetStationProductionThroughput(world, station, recipe);
var produced = 0f;
station.ProductionLaneTimers[laneKey] = GetStationProductionTimer(station, laneKey) + (deltaSeconds * station.WorkforceEffectiveRatio * throughput);
@@ -132,26 +132,21 @@ public sealed partial class SimulationEngine
}
}
private static IEnumerable<string> GetStationProductionLanes(StationRuntime station)
private static IEnumerable<string> GetStationProductionLanes(SimulationWorld world, StationRuntime station)
{
if (CountModules(station.InstalledModules, "refinery-stack") > 0)
foreach (var moduleId in station.InstalledModules.Distinct(StringComparer.Ordinal))
{
yield return "refinery";
}
if (!world.ModuleDefinitions.TryGetValue(moduleId, out var def) || string.IsNullOrEmpty(def.ProductionMode))
{
continue;
}
if (CountModules(station.InstalledModules, "fabricator-array") > 0)
{
yield return "fabrication";
}
if (string.Equals(def.ProductionMode, "commanded", StringComparison.Ordinal) && station.CommanderId is null)
{
continue;
}
if (CountModules(station.InstalledModules, "component-factory") > 0)
{
yield return "components";
}
if (CountModules(station.InstalledModules, "ship-factory") > 0)
{
yield return "shipyard";
yield return moduleId;
}
}
@@ -160,34 +155,13 @@ public sealed partial class SimulationEngine
private static RecipeDefinition? SelectProductionRecipe(SimulationWorld world, StationRuntime station, string laneKey) =>
world.Recipes.Values
.Where(recipe => RecipeAppliesToStation(station, recipe) && string.Equals(GetStationProductionLaneKey(recipe), laneKey, StringComparison.Ordinal))
.Where(recipe => RecipeAppliesToStation(station, recipe) && string.Equals(GetStationProductionLaneKey(world, recipe), laneKey, StringComparison.Ordinal))
.OrderByDescending(recipe => GetStationRecipePriority(world, station, recipe))
.FirstOrDefault(recipe => CanRunRecipe(world, station, recipe));
private static string? GetStationProductionLaneKey(RecipeDefinition recipe)
{
if (recipe.RequiredModules.Contains("refinery-stack", StringComparer.Ordinal))
{
return "refinery";
}
if (recipe.RequiredModules.Contains("fabricator-array", StringComparer.Ordinal))
{
return "fabrication";
}
if (recipe.RequiredModules.Contains("component-factory", StringComparer.Ordinal))
{
return "components";
}
if (recipe.RequiredModules.Contains("ship-factory", StringComparer.Ordinal))
{
return "shipyard";
}
return null;
}
private static string? GetStationProductionLaneKey(SimulationWorld world, RecipeDefinition recipe) =>
recipe.RequiredModules.FirstOrDefault(moduleId =>
world.ModuleDefinitions.TryGetValue(moduleId, out var def) && !string.IsNullOrEmpty(def.ProductionMode));
private static float GetStationRecipePriority(SimulationWorld world, StationRuntime station, RecipeDefinition recipe)
{
@@ -467,29 +441,15 @@ public sealed partial class SimulationEngine
};
}
private static float GetStationProductionThroughput(StationRuntime station, RecipeDefinition recipe)
private static float GetStationProductionThroughput(SimulationWorld world, StationRuntime station, RecipeDefinition recipe)
{
if (recipe.RequiredModules.Contains("refinery-stack", StringComparer.Ordinal))
var laneModuleId = GetStationProductionLaneKey(world, recipe);
if (laneModuleId is null)
{
return Math.Max(1, CountModules(station.InstalledModules, "refinery-stack"));
return 1f;
}
if (recipe.RequiredModules.Contains("fabricator-array", StringComparer.Ordinal))
{
return Math.Max(1, CountModules(station.InstalledModules, "fabricator-array"));
}
if (recipe.RequiredModules.Contains("component-factory", StringComparer.Ordinal))
{
return Math.Max(1, CountModules(station.InstalledModules, "component-factory"));
}
if (recipe.RequiredModules.Contains("ship-factory", StringComparer.Ordinal))
{
return Math.Max(1, CountModules(station.InstalledModules, "ship-factory"));
}
return 1f;
return Math.Max(1, CountModules(station.InstalledModules, laneModuleId));
}
private sealed record DesiredMarketOrder(string Kind, string ItemId, float Amount, float Valuation, float? ReserveThreshold);