Core/Maps: Use the same logic to calculate grid coords to avoid mismatches

Port From (https://github.com/TrinityCore/TrinityCore/commit/c14f4dc83502dea7dad8ad4f92270d8d36b01c12)
This commit is contained in:
hondacrx
2022-05-24 13:43:59 -04:00
parent 88d36a9039
commit 3e7425030b
2 changed files with 8 additions and 1 deletions
+7
View File
@@ -86,6 +86,13 @@ namespace Game.Maps
return new GridCoord(x_val, y_val); return new GridCoord(x_val, y_val);
} }
public static GridCoord ComputeGridCoordSimple(float x, float y)
{
int gx = (int)(MapConst.CenterGridId - x / MapConst.SizeofGrids);
int gy = (int)(MapConst.CenterGridId - y / MapConst.SizeofGrids);
return new GridCoord((uint)((MapConst.MaxGrids - 1) - gx), (uint)((MapConst.MaxGrids - 1) - gy));
}
public static CellCoord ComputeCellCoord(float x, float y) public static CellCoord ComputeCellCoord(float x, float y)
{ {
double x_offset = ((double)x - MapConst.CenterGridCellOffset) / MapConst.SizeofCells; double x_offset = ((double)x - MapConst.CenterGridCellOffset) / MapConst.SizeofCells;
+1 -1
View File
@@ -480,7 +480,7 @@ namespace Game.Maps
if (_minHeightPlanes == null) if (_minHeightPlanes == null)
return -500.0f; return -500.0f;
GridCoord gridCoord = GridDefines.ComputeGridCoord(x, y); GridCoord gridCoord = GridDefines.ComputeGridCoordSimple(x, y);
int doubleGridX = (int)(Math.Floor(-(x - MapConst.MapHalfSize) / MapConst.CenterGridOffset)); int doubleGridX = (int)(Math.Floor(-(x - MapConst.MapHalfSize) / MapConst.CenterGridOffset));
int doubleGridY = (int)(Math.Floor(-(y - MapConst.MapHalfSize) / MapConst.CenterGridOffset)); int doubleGridY = (int)(Math.Floor(-(y - MapConst.MapHalfSize) / MapConst.CenterGridOffset));