Fix tabletop grids rarely spawning on top of another (#39327)

* fix: fix off-by-one for tabletop map positions

Ulam spirals start at 1, not 0.

* fix: make the ulam spiral a ulam spiral
This commit is contained in:
Perry Fraser
2025-08-01 17:48:40 -04:00
committed by GitHub
parent a99615992a
commit c376e69518

View File

@@ -37,7 +37,7 @@ namespace Content.Server.Tabletop
/// <returns></returns>
private Vector2 GetNextTabletopPosition()
{
return UlamSpiral(_tabletops++) * TabletopSeparation;
return UlamSpiral(++_tabletops) * TabletopSeparation;
}
/// <summary>
@@ -62,11 +62,11 @@ namespace Content.Server.Tabletop
/// <summary>
/// Algorithm for mapping scalars to 2D positions in the same pattern as an Ulam Spiral.
/// </summary>
/// <param name="n">Scalar to map to a 2D position.</param>
/// <param name="n">Scalar to map to a 2D position. Must be greater than or equal to 1.</param>
/// <returns>The mapped 2D position for the scalar.</returns>
private Vector2i UlamSpiral(int n)
{
var k = (int)MathF.Ceiling(MathF.Sqrt(n) - 1) / 2;
var k = (int)MathF.Ceiling((MathF.Sqrt(n) - 1) / 2);
var t = 2 * k + 1;
var m = (int)MathF.Pow(t, 2);
t--;