Add pulse contract and isolation valves

This commit is contained in:
2026-05-14 10:11:35 +02:00
parent c5688d2c0d
commit 6db3e60fd1
15 changed files with 195 additions and 27 deletions

View File

@@ -79,7 +79,57 @@ public sealed class SimulationEngineTests
var next = m_Engine.InteractProp(level);
Assert.Equal(EDoorState.Open, next.GetProp(new(3, 2)).DoorState);
Assert.Equal(1, next.Global.Turn);
Assert.Equal(1, next.Global.Pulse);
Assert.Equal(Balancing.Current.StepsPerPulse, next.Global.Step);
}
[Fact]
public void EveryAcceptedLengthyActionAdvancesOneFixedPulse()
{
var level = DoorLevel() with { Robot = new() { Position = new(3, 2) } };
var next = m_Engine.InteractProp(level);
Assert.Equal(1, next.Global.Pulse);
Assert.Equal(Balancing.Current.StepsPerPulse, next.Global.Step);
}
[Fact]
public void DebugStepAdvancementDoesNotAdvancePulse()
{
var level = BuildReadyLevel();
var next = m_Engine.AdvanceStepForDebug(level);
Assert.Equal(0, next.Global.Pulse);
Assert.Equal(1, next.Global.Step);
}
[Fact]
public void IsolationValveOpenAllowsPropagationAndClosedBlocksDownstreamFeed()
{
var open = IsolationValveLevel(EPropSwitchState.Enabled);
var closed = IsolationValveLevel(EPropSwitchState.Disabled);
var openResult = m_Engine.AdvancePulseForDebug(open);
var closedResult = m_Engine.AdvancePulseForDebug(closed);
Assert.True(openResult.GetUnderground(new(3, 2), ECarrierType.Fuel).Amount > 0);
Assert.Equal(ELevelState.Ready, openResult.Global.LevelState);
Assert.Equal(0, closedResult.GetUnderground(new(3, 2), ECarrierType.Fuel).Amount);
Assert.NotEqual(ELevelState.Ready, closedResult.Global.LevelState);
}
[Fact]
public void TogglingIsolationValveIsLengthyAndAdvancesOneFixedPulse()
{
var level = IsolationValveLevel(EPropSwitchState.Enabled) with { Robot = new() { Position = new(2, 2) } };
var next = m_Engine.InteractProp(level);
Assert.Equal(EPropSwitchState.Disabled, next.GetProp(new(2, 2)).SwitchState);
Assert.Equal(1, next.Global.Pulse);
Assert.Equal(Balancing.Current.StepsPerPulse, next.Global.Step);
}
[Fact]
@@ -320,5 +370,22 @@ public sealed class SimulationEngineTests
return level.SetProp(new(2, 3), new() { Type = EPropType.Junction, Carrier = ECarrierType.Fuel, JunctionMode = mode });
}
private static LevelState IsolationValveLevel(EPropSwitchState valveState)
{
var level = LevelState.Create("Valve", 6, 5);
level = AddLine(level, ECarrierType.Fuel, new(1, 2), new(2, 2));
level = AddLine(level, ECarrierType.Fuel, new(2, 2), new(3, 2));
level = level.SetProp(new(1, 2), new() { Type = EPropType.Flow, Carrier = ECarrierType.Fuel });
level = level.SetProp(new(2, 2), new() { Type = EPropType.IsolationValve, Carrier = ECarrierType.Fuel, SwitchState = valveState });
level = level.SetProp(new(3, 2), new() { Type = EPropType.ReactorControl, ReactorId = 1 });
return level with {
RequiredFuelConsumers = 0,
RequiredWaterConsumers = 0,
RequiredElectricityConsumers = 0,
Robot = new() { Position = new(3, 2) },
Reactors = [new() { ReactorId = 1, ControlPosition = new(3, 2) }]
};
}
private readonly SimulationEngine m_Engine = new();
}