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:
@@ -37,7 +37,7 @@ namespace Content.Server.Tabletop
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private Vector2 GetNextTabletopPosition()
|
private Vector2 GetNextTabletopPosition()
|
||||||
{
|
{
|
||||||
return UlamSpiral(_tabletops++) * TabletopSeparation;
|
return UlamSpiral(++_tabletops) * TabletopSeparation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -62,11 +62,11 @@ namespace Content.Server.Tabletop
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Algorithm for mapping scalars to 2D positions in the same pattern as an Ulam Spiral.
|
/// Algorithm for mapping scalars to 2D positions in the same pattern as an Ulam Spiral.
|
||||||
/// </summary>
|
/// </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>
|
/// <returns>The mapped 2D position for the scalar.</returns>
|
||||||
private Vector2i UlamSpiral(int n)
|
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 t = 2 * k + 1;
|
||||||
var m = (int)MathF.Pow(t, 2);
|
var m = (int)MathF.Pow(t, 2);
|
||||||
t--;
|
t--;
|
||||||
|
|||||||
Reference in New Issue
Block a user