diff --git a/src/server/game/Grids/Cells/CellImpl.h b/src/server/game/Grids/Cells/CellImpl.h index ec6e6e93aa..ede2817b24 100644 --- a/src/server/game/Grids/Cells/CellImpl.h +++ b/src/server/game/Grids/Cells/CellImpl.h @@ -47,8 +47,8 @@ inline CellArea Cell::CalculateCellArea(float x, float y, float radius) return CellArea(center, center); } - CellCoord centerX = Acore::ComputeCellCoord(x - radius, y - radius).normalize(); - CellCoord centerY = Acore::ComputeCellCoord(x + radius, y + radius).normalize(); + CellCoord centerX = Acore::ComputeCellCoord(x + radius, y + radius).normalize(); + CellCoord centerY = Acore::ComputeCellCoord(x - radius, y - radius).normalize(); return CellArea(centerX, centerY); } @@ -99,6 +99,8 @@ inline void Cell::Visit(CellCoord const& standing_cell, TypeContainerVisitor= area.low_bound.x_coord); + ASSERT(area.high_bound.y_coord >= area.low_bound.y_coord); for (uint32 x = area.low_bound.x_coord; x <= area.high_bound.x_coord; ++x) { for (uint32 y = area.low_bound.y_coord; y <= area.high_bound.y_coord; ++y) diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h index 62d1a6f500..7eabee5cde 100644 --- a/src/server/game/Grids/GridDefines.h +++ b/src/server/game/Grids/GridDefines.h @@ -170,20 +170,17 @@ typedef CoordPair CellCoord; namespace Acore { template - inline RET_TYPE Compute(float x, float y, float center_offset, float size) + inline RET_TYPE Compute(float x, float y, float size) { - // calculate and store temporary values in double format for having same result as same mySQL calculations - double x_offset = (double(x) - center_offset) / size; - double y_offset = (double(y) - center_offset) / size; + int gx = (int)(CENTER_VAL - x / size); + int gy = (int)(CENTER_VAL - y / size); - int x_val = int(x_offset + CENTER_VAL + 0.5f); - int y_val = int(y_offset + CENTER_VAL + 0.5f); - return RET_TYPE(x_val, y_val); + return RET_TYPE(gx, gy); } inline GridCoord ComputeGridCoord(float x, float y) { - return Compute(x, y, CENTER_GRID_OFFSET, SIZE_OF_GRIDS); + return Compute(x, y, SIZE_OF_GRIDS); } inline GridCoord ComputeGridCoordSimple(float x, float y) @@ -195,19 +192,7 @@ namespace Acore inline CellCoord ComputeCellCoord(float x, float y) { - return Compute(x, y, CENTER_GRID_CELL_OFFSET, SIZE_OF_GRID_CELL); - } - - inline CellCoord ComputeCellCoord(float x, float y, float& x_off, float& y_off) - { - double x_offset = (double(x) - CENTER_GRID_CELL_OFFSET) / SIZE_OF_GRID_CELL; - double y_offset = (double(y) - CENTER_GRID_CELL_OFFSET) / SIZE_OF_GRID_CELL; - - int x_val = int(x_offset + CENTER_GRID_CELL_ID + 0.5f); - int y_val = int(y_offset + CENTER_GRID_CELL_ID + 0.5f); - x_off = (float(x_offset) - x_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; - y_off = (float(y_offset) - y_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; - return CellCoord(x_val, y_val); + return Compute(x, y, SIZE_OF_GRID_CELL); } inline void NormalizeMapCoord(float& c) diff --git a/src/server/game/Grids/GridTerrainLoader.cpp b/src/server/game/Grids/GridTerrainLoader.cpp index b82c3b5446..ecf9b09415 100644 --- a/src/server/game/Grids/GridTerrainLoader.cpp +++ b/src/server/game/Grids/GridTerrainLoader.cpp @@ -30,7 +30,7 @@ void GridTerrainLoader::LoadMap() } // map file name - std::string const mapFileName = Acore::StringFormat("{}maps/{:03}{:02}{:02}.map", sWorld->GetDataPath(), _map->GetId(), GetX(), GetY()); + std::string const mapFileName = Acore::StringFormat("{}maps/{:03}{:02}{:02}.map", sWorld->GetDataPath(), _map->GetId(), _grid.GetX(), _grid.GetY()); // loading data LOG_DEBUG("maps", "Loading map {}", mapFileName); @@ -46,25 +46,25 @@ void GridTerrainLoader::LoadMap() LOG_DEBUG("maps", "Error (result: {}) loading map file: {}", uint32(loadResult), mapFileName); } - sScriptMgr->OnLoadGridMap(_map, _grid.GetTerrainData(), GetX(), GetY()); + sScriptMgr->OnLoadGridMap(_map, _grid.GetTerrainData(), _grid.GetX(), _grid.GetY()); } void GridTerrainLoader::LoadVMap() { - int vmapLoadResult = VMAP::VMapFactory::createOrGetVMapMgr()->loadMap((sWorld->GetDataPath() + "vmaps").c_str(), _map->GetId(), GetX(), GetY()); + int vmapLoadResult = VMAP::VMapFactory::createOrGetVMapMgr()->loadMap((sWorld->GetDataPath() + "vmaps").c_str(), _map->GetId(), _grid.GetX(), _grid.GetY()); switch (vmapLoadResult) { case VMAP::VMAP_LOAD_RESULT_OK: LOG_DEBUG("maps", "VMAP loaded name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})", - _map->GetMapName(), _map->GetId(), GetX(), GetY(), GetX(), GetY()); + _map->GetMapName(), _map->GetId(), _grid.GetX(), _grid.GetY(), _grid.GetX(), _grid.GetY()); break; case VMAP::VMAP_LOAD_RESULT_ERROR: LOG_DEBUG("maps", "Could not load VMAP name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})", - _map->GetMapName(), _map->GetId(), GetX(), GetY(), GetX(), GetY()); + _map->GetMapName(), _map->GetId(), _grid.GetX(), _grid.GetY(), _grid.GetX(), _grid.GetY()); break; case VMAP::VMAP_LOAD_RESULT_IGNORED: LOG_DEBUG("maps", "Ignored VMAP name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})", - _map->GetMapName(), _map->GetId(), GetX(), GetY(), GetX(), GetY()); + _map->GetMapName(), _map->GetId(), _grid.GetX(), _grid.GetY(), _grid.GetX(), _grid.GetY()); break; } } @@ -74,20 +74,20 @@ void GridTerrainLoader::LoadMMap() if (!DisableMgr::IsPathfindingEnabled(_map)) return; - int mmapLoadResult = MMAP::MMapFactory::createOrGetMMapMgr()->loadMap(_map->GetId(), GetX(), GetY()); + int mmapLoadResult = MMAP::MMapFactory::createOrGetMMapMgr()->loadMap(_map->GetId(), _grid.GetX(), _grid.GetY()); switch (mmapLoadResult) { case MMAP::MMAP_LOAD_RESULT_OK: LOG_DEBUG("maps", "MMAP loaded name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})", - _map->GetMapName(), _map->GetId(), GetX(), GetY(), GetX(), GetY()); + _map->GetMapName(), _map->GetId(), _grid.GetX(), _grid.GetY(), _grid.GetX(), _grid.GetY()); break; case MMAP::MMAP_LOAD_RESULT_ERROR: LOG_DEBUG("maps", "Could not load MMAP name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})", - _map->GetMapName(), _map->GetId(), GetX(), GetY(), GetX(), GetY()); + _map->GetMapName(), _map->GetId(), _grid.GetX(), _grid.GetY(), _grid.GetX(), _grid.GetY()); break; case MMAP::MMAP_LOAD_RESULT_IGNORED: LOG_DEBUG("maps", "Ignored MMAP name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})", - _map->GetMapName(), _map->GetId(), GetX(), GetY(), GetX(), GetY()); + _map->GetMapName(), _map->GetId(), _grid.GetX(), _grid.GetY(), _grid.GetX(), _grid.GetY()); break; } } @@ -152,9 +152,6 @@ void GridTerrainUnloader::UnloadTerrain() if (_map->GetInstanceId() != 0) return; - int gx = (MAX_NUMBER_OF_GRIDS - 1) - _grid.GetX(); - int gy = (MAX_NUMBER_OF_GRIDS - 1) - _grid.GetY(); - - VMAP::VMapFactory::createOrGetVMapMgr()->unloadMap(_map->GetId(), gx, gy); - MMAP::MMapFactory::createOrGetMMapMgr()->unloadMap(_map->GetId(), gx, gy); + VMAP::VMapFactory::createOrGetVMapMgr()->unloadMap(_map->GetId(), _grid.GetX(), _grid.GetY()); + MMAP::MMapFactory::createOrGetMMapMgr()->unloadMap(_map->GetId(), _grid.GetX(), _grid.GetY()); } diff --git a/src/server/game/Grids/GridTerrainLoader.h b/src/server/game/Grids/GridTerrainLoader.h index 03db11f7fd..39cbc0d622 100644 --- a/src/server/game/Grids/GridTerrainLoader.h +++ b/src/server/game/Grids/GridTerrainLoader.h @@ -36,9 +36,6 @@ private: void LoadVMap(); void LoadMMap(); - uint16 GetX() { return (MAX_NUMBER_OF_GRIDS - 1) - _grid.GetX(); } - uint16 GetY() { return (MAX_NUMBER_OF_GRIDS - 1) - _grid.GetY(); } - MapGridType& _grid; Map* _map; }; diff --git a/src/server/game/Maps/MapMgr.cpp b/src/server/game/Maps/MapMgr.cpp index d4cf5493ca..34f371a678 100644 --- a/src/server/game/Maps/MapMgr.cpp +++ b/src/server/game/Maps/MapMgr.cpp @@ -304,11 +304,7 @@ void MapMgr::DoDelayedMovesAndRemoves() bool MapMgr::ExistMapAndVMap(uint32 mapid, float x, float y) { GridCoord p = Acore::ComputeGridCoord(x, y); - - int gx = 63 - p.x_coord; - int gy = 63 - p.y_coord; - - return GridTerrainLoader::ExistMap(mapid, gx, gy) && GridTerrainLoader::ExistVMap(mapid, gx, gy); + return GridTerrainLoader::ExistMap(mapid, p.x_coord, p.y_coord) && GridTerrainLoader::ExistVMap(mapid, p.x_coord, p.y_coord); } bool MapMgr::IsValidMAP(uint32 mapid, bool startUp) diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index 9f7bd95109..13ad9dec2c 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -567,7 +567,8 @@ public: return false; } - Cell cell(Acore::ComputeCellCoord(object->GetPositionX(), object->GetPositionY())); + CellCoord const cellCoord = Acore::ComputeCellCoord(object->GetPositionX(), object->GetPositionY()); + Cell cell(cellCoord); uint32 zoneId, areaId; object->GetZoneAndAreaId(zoneId, areaId); @@ -584,14 +585,8 @@ public: float groundZ = object->GetMapHeight(object->GetPositionX(), object->GetPositionY(), MAX_HEIGHT); float floorZ = object->GetMapHeight(object->GetPositionX(), object->GetPositionY(), object->GetPositionZ()); - GridCoord gridCoord = Acore::ComputeGridCoord(object->GetPositionX(), object->GetPositionY()); - - // 63? WHY? - int gridX = 63 - gridCoord.x_coord; - int gridY = 63 - gridCoord.y_coord; - - uint32 haveMap = GridTerrainLoader::ExistMap(object->GetMapId(), gridX, gridY) ? 1 : 0; - uint32 haveVMap = GridTerrainLoader::ExistVMap(object->GetMapId(), gridX, gridY) ? 1 : 0; + uint32 haveMap = GridTerrainLoader::ExistMap(object->GetMapId(), cell.GridX(), cell.GridY()) ? 1 : 0; + uint32 haveVMap = GridTerrainLoader::ExistVMap(object->GetMapId(), cell.GridX(), cell.GridY()) ? 1 : 0; uint32 haveMMAP = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId()) ? 1 : 0; if (haveVMap) diff --git a/src/server/scripts/Commands/cs_mmaps.cpp b/src/server/scripts/Commands/cs_mmaps.cpp index 130ec76867..f195c8f26a 100644 --- a/src/server/scripts/Commands/cs_mmaps.cpp +++ b/src/server/scripts/Commands/cs_mmaps.cpp @@ -133,11 +133,10 @@ public: // grid tile location Player* player = handler->GetSession()->GetPlayer(); - int32 gx = 32 - player->GetPositionX() / SIZE_OF_GRIDS; - int32 gy = 32 - player->GetPositionY() / SIZE_OF_GRIDS; + GridCoord const gridCoord = Acore::ComputeGridCoord(player->GetPositionX(), player->GetPositionY()); - handler->PSendSysMessage("{}{}{}.mmtile", player->GetMapId(), gx, gy); - handler->PSendSysMessage("gridloc [{}, {}]", gy, gx); + handler->PSendSysMessage("{}{}{}.mmtile", player->GetMapId(), gridCoord.x_coord, gridCoord.y_coord); + handler->PSendSysMessage("gridloc [{}, {}]", gridCoord.x_coord, gridCoord.y_coord); // calculate navmesh tile location dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId());