First batch
This commit is contained in:
65
src/ReactorMaintenance.Simulation/LevelEditor.cs
Normal file
65
src/ReactorMaintenance.Simulation/LevelEditor.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
namespace ReactorMaintenance.Simulation;
|
||||
|
||||
public enum EditorTool
|
||||
{
|
||||
Floor,
|
||||
Wall,
|
||||
Reactor,
|
||||
CoolingPump,
|
||||
Generator,
|
||||
PressureRegulator,
|
||||
DiagnosticTerminal,
|
||||
ControlTerminal,
|
||||
CoolantPipe,
|
||||
FuelPipe,
|
||||
PressurePipe,
|
||||
Leak,
|
||||
Repair,
|
||||
Heat,
|
||||
Fire,
|
||||
Robot
|
||||
}
|
||||
|
||||
public static class LevelEditor
|
||||
{
|
||||
public static LevelState Apply(LevelState level, GridPosition position, EditorTool tool)
|
||||
{
|
||||
if (!level.InBounds(position))
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
if (tool == EditorTool.Robot)
|
||||
{
|
||||
return level.GetCell(position).IsWalkable ? level with { Robot = position } : level;
|
||||
}
|
||||
|
||||
var cell = level.GetCell(position);
|
||||
cell = tool switch
|
||||
{
|
||||
EditorTool.Floor => cell with { Kind = CellKind.Floor },
|
||||
EditorTool.Wall => cell with { Kind = CellKind.Wall, Pipe = PipeMedium.None, Powered = false },
|
||||
EditorTool.Reactor => cell with { Kind = CellKind.Reactor },
|
||||
EditorTool.CoolingPump => cell with { Kind = CellKind.CoolingPump, Powered = true },
|
||||
EditorTool.Generator => cell with { Kind = CellKind.Generator, Powered = true },
|
||||
EditorTool.PressureRegulator => cell with { Kind = CellKind.PressureRegulator },
|
||||
EditorTool.DiagnosticTerminal => cell with { Kind = CellKind.DiagnosticTerminal, Powered = true },
|
||||
EditorTool.ControlTerminal => cell with { Kind = CellKind.ControlTerminal, Powered = true },
|
||||
EditorTool.CoolantPipe => cell with { Pipe = PipeMedium.Coolant, Flow = 4, Pressure = 4, Integrity = Math.Max(cell.Integrity, 8), PipeOpen = true },
|
||||
EditorTool.FuelPipe => cell with { Pipe = PipeMedium.Fuel, Flow = 4, Pressure = 4, Integrity = Math.Max(cell.Integrity, 8), PipeOpen = true },
|
||||
EditorTool.PressurePipe => cell with { Pipe = PipeMedium.Pressure, Flow = 5, Pressure = 6, Integrity = Math.Max(cell.Integrity, 8), PipeOpen = true },
|
||||
EditorTool.Leak => cell with { LeakRate = Math.Max(1, cell.LeakRate), Integrity = Math.Min(cell.Integrity, 4) },
|
||||
EditorTool.Repair => cell with { LeakRate = 0, Integrity = 10, Hazards = cell.Hazards with { Fire = false, ElectricalCharge = 0 } },
|
||||
EditorTool.Heat => cell with { Hazards = cell.Hazards with { Heat = Rules.Clamp(cell.Hazards.Heat + 2) } },
|
||||
EditorTool.Fire => cell with { Hazards = cell.Hazards with { Fire = !cell.Hazards.Fire, Heat = Math.Max(cell.Hazards.Heat, 7), Smoke = Math.Max(cell.Hazards.Smoke, 3) } },
|
||||
_ => cell
|
||||
};
|
||||
|
||||
if (cell.Kind == CellKind.Wall)
|
||||
{
|
||||
cell = cell with { Hazards = new HazardState() };
|
||||
}
|
||||
|
||||
return level.SetCell(position, cell);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user