Files
Project-M/Assets/_Project/Scripts/Simulation/Building/BuildPlacementMath.cs
T
2026-06-04 00:06:18 -07:00

25 lines
1.2 KiB
C#

using Unity.Collections;
using Unity.Mathematics;
namespace ProjectM.Simulation
{
/// <summary>
/// Pure, deterministic build-placement helpers (unit-tested like <see cref="BaseGridMath"/> /
/// <c>StorageMath</c>). Occupancy is DERIVED from the live structure set each placement (the structure
/// ghosts are the source of truth — restart- and replay-order-safe), never cached on the immutable
/// baked <see cref="BaseAnchor"/>. The server passes a Temp <see cref="NativeHashSet{T}"/> of occupied
/// cells built by scanning live <see cref="PlacedStructure"/> ghosts.
/// </summary>
public static class BuildPlacementMath
{
/// <summary>True if <paramref name="cell"/> is occupied in the derived set.</summary>
public static bool IsOccupied(in NativeHashSet<int2> occupied, int2 cell) => occupied.Contains(cell);
/// <summary>Full server placement legality: the cell is in-plot (half-open, negative-safe) AND not occupied.</summary>
public static bool CanPlace(in BaseAnchor anchor, in NativeHashSet<int2> occupied, int2 cell)
{
return BaseGridMath.IsCellInPlot(anchor, cell) && !occupied.Contains(cell);
}
}
}