Refactor simulation effects and forecast hazards
This commit is contained in:
26
src/ReactorMaintenance.Simulation/PipeLeakEffect.cs
Normal file
26
src/ReactorMaintenance.Simulation/PipeLeakEffect.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace ReactorMaintenance.Simulation;
|
||||
|
||||
public sealed class PipeLeakEffect : ISimulationEffect
|
||||
{
|
||||
public CellState Apply(CellState cell)
|
||||
{
|
||||
if (!cell.HasPipe || cell.LeakRate <= 0)
|
||||
return cell;
|
||||
|
||||
var hazards = cell.Pipe switch {
|
||||
EPipeMedium.Fuel => cell.Hazards with {
|
||||
LiquidFuel = cell.Hazards.LiquidFuel + cell.LeakRate,
|
||||
FuelVapor = cell.Hazards.FuelVapor + (cell.Pressure >= 7 ? cell.LeakRate : Math.Max(0, cell.Hazards.Heat - 3) / 3)
|
||||
},
|
||||
EPipeMedium.Coolant => cell.Hazards with {
|
||||
CoolantPooling = cell.Hazards.CoolantPooling + cell.LeakRate,
|
||||
Heat = cell.Hazards.Heat - Math.Max(1, cell.LeakRate / 2),
|
||||
Smoke = cell.Hazards.Smoke + (cell.Hazards.Heat >= 7 ? 2 : 0)
|
||||
},
|
||||
EPipeMedium.Pressure => cell.Hazards with { Smoke = cell.Hazards.Smoke + (cell.Pressure >= 8 ? 1 : 0) },
|
||||
_ => cell.Hazards
|
||||
};
|
||||
|
||||
return cell with { Hazards = hazards.Clamp() };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user