Centralize simulation balancing values

This commit is contained in:
2026-05-08 21:38:03 +02:00
parent 8ec3c7847c
commit 8018ebbabb
13 changed files with 178 additions and 106 deletions

View File

@@ -23,14 +23,14 @@ public sealed class SimulationEngine(IEnumerable<ISimulationEffect> effects, IEn
var seen = new HashSet<ForecastKey>();
var forecastLevel = level with { Cells = level.Cells.ToArray(), Forecasts = Array.Empty<Forecast>() };
if (forecastLevel.Global.Lost)
AddHazardForecasts(forecasts, seen, forecastLevel, 0);
AddHazardForecasts(forecasts, seen, forecastLevel, Balancing.CurrentForecastTurn);
AddReactorReadyForecast(forecasts, seen, forecastLevel, 0);
AddReactorReadyForecast(forecasts, seen, forecastLevel, Balancing.CurrentForecastTurn);
if (IsReactorReady(forecastLevel) || forecastLevel.Global.Lost || forecastLevel.Global.ReactorActivated)
return forecasts.OrderBy(f => f.Turns).ThenBy(f => f.Message).ToArray();
for (var step = 1; step <= c_MaxForecastStepCount; step++)
for (var step = Balancing.TurnIncrement; step <= Balancing.MaxForecastStepCount; step++)
{
forecastLevel = AdvanceTurn(forecastLevel, false);
AddHazardForecasts(forecasts, seen, forecastLevel, step);
@@ -60,9 +60,9 @@ public sealed class SimulationEngine(IEnumerable<ISimulationEffect> effects, IEn
{
var cells = level.Cells.ToArray();
for (var y = 0; y < level.Height; y++)
for (var y = Balancing.FirstGridCoordinate; y < level.Height; y++)
{
for (var x = 0; x < level.Width; x++)
for (var x = Balancing.FirstGridCoordinate; x < level.Width; x++)
{
var position = new GridPosition(x, y);
var index = level.Index(position);
@@ -84,7 +84,7 @@ public sealed class SimulationEngine(IEnumerable<ISimulationEffect> effects, IEn
var global = UpdateGlobal(level, cells);
var next = level with {
Cells = cells,
Global = global with { Turn = level.Global.Turn + 1 }
Global = global with { Turn = level.Global.Turn + Balancing.TurnIncrement }
};
return updateForecasts ? next with { Forecasts = Forecast(next) } : next;
@@ -116,14 +116,14 @@ public sealed class SimulationEngine(IEnumerable<ISimulationEffect> effects, IEn
var reactorHeat = cells.Where(c => c.Kind == ECellKind.Reactor).Select(c => c.Hazards.Heat).DefaultIfEmpty(level.Global.CoreHeat).Max();
var poweredGenerators = cells.Count(c => c is { Kind: ECellKind.Generator, Powered: true, Hazards.Fire: false });
var poweredPumps = cells.Count(c => c is { Kind: ECellKind.CoolingPump, Powered: true, Hazards.Fire: false });
var damagedCriticalCells = cells.Count(c => c.Kind is ECellKind.Reactor or ECellKind.Generator or ECellKind.CoolingPump && c.Hazards.Stability <= 3);
var damagedCriticalCells = cells.Count(c => c.Kind is ECellKind.Reactor or ECellKind.Generator or ECellKind.CoolingPump && c.Hazards.Stability <= Balancing.CriticalCellStabilityThreshold);
var stability = Rules.Clamp(level.Global.FacilityStability - damagedCriticalCells);
var lost = reactorHeat >= 10 || stability <= 0;
var status = lost ? reactorHeat >= 10 ? "CORE MELTDOWN" : "FACILITY STABILITY COLLAPSE" : "STABILIZE SYSTEMS";
var lost = reactorHeat >= Balancing.MeltdownCoreHeatThreshold || stability <= Balancing.StabilityCollapseThreshold;
var status = lost ? reactorHeat >= Balancing.MeltdownCoreHeatThreshold ? "CORE MELTDOWN" : "FACILITY STABILITY COLLAPSE" : "STABILIZE SYSTEMS";
var global = level.Global with {
CoreHeat = Rules.Clamp(reactorHeat - poweredPumps),
Power = Rules.Clamp(poweredGenerators * 3),
Cooling = Rules.Clamp(poweredPumps * 3),
Power = Rules.Clamp(poweredGenerators * Balancing.GeneratorPowerOutput),
Cooling = Rules.Clamp(poweredPumps * Balancing.CoolingPumpOutput),
FacilityStability = stability,
Lost = lost,
Status = status
@@ -135,15 +135,13 @@ public sealed class SimulationEngine(IEnumerable<ISimulationEffect> effects, IEn
private static bool IsReactorReady(LevelState level)
{
var hasReactor = level.Cells.Any(c => c.Kind == ECellKind.Reactor);
var hasStablePower = level.Global.Power >= 3 || level.Cells.Any(c => c is { Kind: ECellKind.Generator, Powered: true, Hazards.Fire: false });
var hasCooling = level.Global.Cooling >= 3 || level.Cells.Any(c => c is { Kind: ECellKind.CoolingPump, Powered: true, Hazards.Fire: false });
var reactorStable = level.Global.CoreHeat < 8;
var hasStablePower = level.Global.Power >= Balancing.ReactorReadyPowerThreshold || level.Cells.Any(c => c is { Kind: ECellKind.Generator, Powered: true, Hazards.Fire: false });
var hasCooling = level.Global.Cooling >= Balancing.ReactorReadyCoolingThreshold || level.Cells.Any(c => c is { Kind: ECellKind.CoolingPump, Powered: true, Hazards.Fire: false });
var reactorStable = level.Global.CoreHeat < Balancing.ReactorReadyCoreHeatThreshold;
return hasReactor && hasStablePower && hasCooling && reactorStable && !level.Global.Lost;
}
private const int c_MaxForecastStepCount = 12;
private readonly IReadOnlyList<IAreaSimulationEffect> m_AreaEffects = areaEffects.ToArray();
private readonly IReadOnlyList<ISimulationEffect> m_Effects = effects.ToArray();
private readonly IReadOnlyList<Hazard> m_Hazards = hazards.ToArray();
}