]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix tabletop grids rarely spawning on top of another (#39327)
authorPerry Fraser <perryprog@users.noreply.github.com>
Fri, 1 Aug 2025 21:48:40 +0000 (17:48 -0400)
committerGitHub <noreply@github.com>
Fri, 1 Aug 2025 21:48:40 +0000 (23:48 +0200)
* fix: fix off-by-one for tabletop map positions

Ulam spirals start at 1, not 0.

* fix: make the ulam spiral a ulam spiral

Content.Server/Tabletop/TabletopSystem.Map.cs

index 5e116d81ef6db457f046ebe12ab2b6fbf239010d..89563ec6bf0b3be45528e61fecabc9474cd0ab9a 100644 (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--;