35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
namespace ReactorMaintenance.Simulation;
|
|
|
|
public sealed class SmokeSpreadEffect : IAreaSimulationEffect
|
|
{
|
|
public CellState[] Apply(LevelState level, CellState[] cells)
|
|
{
|
|
var next = cells.ToArray();
|
|
for (var y = 0; y < level.Height; y++)
|
|
{
|
|
for (var x = 0; x < level.Width; x++)
|
|
{
|
|
var position = new GridPosition(x, y);
|
|
var cell = cells[level.Index(position)];
|
|
if (cell.Hazards.Smoke < 6)
|
|
continue;
|
|
|
|
SpreadToNeighbors(level, next, position);
|
|
}
|
|
}
|
|
|
|
return next;
|
|
}
|
|
|
|
private static void SpreadToNeighbors(LevelState level, CellState[] next, GridPosition position)
|
|
{
|
|
foreach (var neighbor in position.Neighbors().Where(level.InBounds))
|
|
{
|
|
var neighborCell = next[level.Index(neighbor)];
|
|
if (!neighborCell.IsWalkable || neighborCell.DoorLocked)
|
|
continue;
|
|
|
|
next[level.Index(neighbor)] = neighborCell with { Hazards = neighborCell.Hazards with { Smoke = Rules.Clamp(neighborCell.Hazards.Smoke + 1) } };
|
|
}
|
|
}
|
|
} |