aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/server/game/Globals/ObjectAccessor.h4
-rw-r--r--src/server/game/Grids/Cells/CellImpl.h4
-rw-r--r--src/server/game/Grids/GridDefines.h11
-rwxr-xr-xsrc/server/game/Maps/Map.cpp15
4 files changed, 19 insertions, 15 deletions
diff --git a/src/server/game/Globals/ObjectAccessor.h b/src/server/game/Globals/ObjectAccessor.h
index 27bc47269e9..4ffe27b19d8 100755
--- a/src/server/game/Globals/ObjectAccessor.h
+++ b/src/server/game/Globals/ObjectAccessor.h
@@ -156,14 +156,14 @@ class ObjectAccessor
return NULL;
CellCoord p = Trinity::ComputeCellCoord(x, y);
- if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!p.IsCoordValid())
{
sLog->outError("ObjectAccessor::GetObjectInWorld: invalid coordinates supplied X:%f Y:%f grid cell [%u:%u]", x, y, p.x_coord, p.y_coord);
return NULL;
}
CellCoord q = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
- if (q.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || q.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!q.IsCoordValid())
{
sLog->outError("ObjectAccessor::GetObjecInWorld: object (GUID: %u TypeId: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), q.x_coord, q.y_coord);
return NULL;
diff --git a/src/server/game/Grids/Cells/CellImpl.h b/src/server/game/Grids/Cells/CellImpl.h
index 18337f8fadc..17f85dde8f4 100644
--- a/src/server/game/Grids/Cells/CellImpl.h
+++ b/src/server/game/Grids/Cells/CellImpl.h
@@ -39,7 +39,7 @@ template<class T, class CONTAINER>
inline void
Cell::Visit(const CellCoord& standing_cell, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m) const
{
- if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!standing_cell.IsCoordValid())
return;
uint16 district = (District)this->data.Part.reserved;
@@ -170,7 +170,7 @@ template<class T, class CONTAINER>
inline void
Cell::Visit(const CellCoord& standing_cell, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, float radius, float x_off, float y_off) const
{
- if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!standing_cell.IsCoordValid())
return;
//no jokes here... Actually placing ASSERT() here was good idea, but
diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h
index 70d38720005..c8abc314ff0 100644
--- a/src/server/game/Grids/GridDefines.h
+++ b/src/server/game/Grids/GridDefines.h
@@ -71,7 +71,7 @@ typedef NGrid<MAX_NUMBER_OF_CELLS, Player, AllWorldObjectTypes, AllGridObjectTyp
typedef TypeMapContainer<AllGridObjectTypes> GridTypeMapContainer;
typedef TypeMapContainer<AllWorldObjectTypes> WorldTypeMapContainer;
-template<const unsigned int LIMIT>
+template<uint32 LIMIT>
struct CoordPair
{
CoordPair(uint32 x=0, uint32 y=0)
@@ -123,17 +123,22 @@ struct CoordPair
y_coord = LIMIT - 1;
}
+ bool IsCoordValid() const
+ {
+ return x_coord < LIMIT && y_coord < LIMIT;
+ }
+
uint32 x_coord;
uint32 y_coord;
};
-template<const unsigned int LIMIT>
+template<uint32 LIMIT>
bool operator==(const CoordPair<LIMIT> &p1, const CoordPair<LIMIT> &p2)
{
return (p1.x_coord == p2.x_coord && p1.y_coord == p2.y_coord);
}
-template<const unsigned int LIMIT>
+template<uint32 LIMIT>
bool operator!=(const CoordPair<LIMIT> &p1, const CoordPair<LIMIT> &p2)
{
return !(p1 == p2);
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 44fb7b3fc83..43eb09be775 100755
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -266,7 +266,7 @@ template<class T>
void Map::SwitchGridContainers(T* obj, bool on)
{
CellCoord p = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
- if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!p.IsCoordValid())
{
sLog->outError("Map::SwitchGridContainers: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
return;
@@ -409,7 +409,7 @@ bool Map::AddToMap(Player* player)
// Check if we are adding to correct map
ASSERT (player->GetMap() == this);
CellCoord p = Trinity::ComputeCellCoord(player->GetPositionX(), player->GetPositionY());
- if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!p.IsCoordValid())
{
sLog->outError("Map::Add: Player (GUID: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord);
return false;
@@ -451,7 +451,7 @@ void
Map::AddToMap(T *obj)
{
CellCoord p = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
- if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!p.IsCoordValid())
{
sLog->outError("Map::Add: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
return;
@@ -497,7 +497,7 @@ void Map::VisitNearbyCellsOf(WorldObject* obj, TypeContainerVisitor<Trinity::Obj
CellCoord standing_cell(Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()));
// Check for correctness of standing_cell, it also avoids problems with update_cell
- if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!standing_cell.IsCoordValid())
return;
// the overloaded operators handle range checking
@@ -688,7 +688,7 @@ void Map::RemoveFromMap(Player* player, bool remove)
SendRemoveTransports(player);
CellCoord p = Trinity::ComputeCellCoord(player->GetPositionX(), player->GetPositionY());
- if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!p.IsCoordValid())
sLog->outCrash("Map::Remove: Player is in invalid cell!");
else
{
@@ -721,7 +721,7 @@ Map::RemoveFromMap(T *obj, bool remove)
RemoveFromActive(obj);
CellCoord p = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
- if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
+ if (!p.IsCoordValid())
sLog->outError("Map::Remove: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
else
{
@@ -2132,8 +2132,7 @@ void Map::SendToPlayers(WorldPacket const* data) const
bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const
{
- ASSERT(x < MAX_NUMBER_OF_GRIDS);
- ASSERT(y < MAX_NUMBER_OF_GRIDS);
+ ASSERT(x < MAX_NUMBER_OF_GRIDS && y < MAX_NUMBER_OF_GRIDS);
CellCoord cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS);
CellCoord cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS);