Rework simulation rules

This commit is contained in:
2026-05-11 22:18:43 +02:00
parent 3d406179bf
commit e1ac56d201
30 changed files with 554 additions and 848 deletions

View File

@@ -4,22 +4,27 @@ public sealed class SimulationEngine
{
public LevelState MoveRobot(LevelState level, GridPosition destination)
{
return PlayerActionSystem.MoveRobot(level, destination, SpendAction);
return PlayerActionSystem.MoveRobot(level, destination);
}
public LevelState InteractProp(LevelState level)
{
return PlayerActionSystem.InteractProp(level, SpendAction);
return PlayerActionSystem.InteractProp(level, ResolveStep);
}
public LevelState InteractLeak(LevelState level, ECarrierType carrier, bool useRemedy)
{
return PlayerActionSystem.InteractLeak(level, carrier, useRemedy, SpendAction);
return PlayerActionSystem.InteractLeak(level, carrier, useRemedy, ResolveStep);
}
public LevelState ApplyHeatShield(LevelState level)
{
return PlayerActionSystem.ApplyHeatShield(level, SpendAction);
return PlayerActionSystem.ApplyHeatShield(level, ResolveStep);
}
private LevelState ResolveStep(LevelState level)
{
return ResolveStep(level, true);
}
public LevelState ActivateReactor(LevelState level)
@@ -29,45 +34,37 @@ public sealed class SimulationEngine
public LevelState EndTurn(LevelState level)
{
return ResolveTurn(level with { Global = level.Global with { ActionsRemaining = 0 } });
return ResolveStep(level);
}
public LevelState AdvanceTurn(LevelState level)
{
return ResolveTurn(level);
return ResolveStep(level);
}
public IReadOnlyList<Forecast> Forecast(LevelState level)
{
return ForecastSystem.Forecast(level, simulated => ResolveTurn(simulated, false));
return ForecastSystem.Forecast(level, simulated => ResolveStep(simulated, false));
}
private LevelState SpendAction(LevelState level)
{
var actions = Math.Max(0, level.Global.ActionsRemaining - 1);
var next = level with { Global = level.Global with { ActionsRemaining = actions } };
return actions == 0 ? ResolveTurn(next) : next;
}
private LevelState ResolveTurn(LevelState level, bool refreshForecasts = true)
private LevelState ResolveStep(LevelState level, bool refreshForecasts)
{
var report = m_Validator.Validate(level);
if (!report.IsValid)
return level with { Global = level.Global with { LevelState = ELevelState.Lost, Status = report.Errors[0].Message } };
var next = RuleEventSystem.Apply(level, ERuleEventPhase.StartOfSimulation);
var next = level;
next = NetworkPropagationSystem.Propagate(next);
next = ConsumerSystem.Resolve(next);
next = StructuralIntegritySystem.Resolve(next);
next = LeakSystem.Inject(next);
next = SurfaceInteractionSystem.Resolve(next);
next = RobotSafetySystem.Resolve(next);
next = ReactorSystem.DeriveState(next);
next = RuleEventSystem.Apply(next, ERuleEventPhase.EndOfTurn);
next = SurfaceInteractionSystem.AdvanceDurations(next);
next = next with {
Global = next.Global with {
Turn = next.Global.Turn + 1,
ActionsRemaining = Balancing.Current.ActionsPerTurn
Turn = next.Global.Turn + 1
}
};