mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-24 19:06:49 +01:00
Core/Objects: Remove restriction on what object types can be set as active
This commit is contained in:
@@ -3837,71 +3837,84 @@ bool Map::ActiveObjectsNearGrid(NGridType const& ngrid) const
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Map::AddToActive(T* obj)
|
||||
void Map::AddToActive(WorldObject* obj)
|
||||
{
|
||||
AddToActiveHelper(obj);
|
||||
}
|
||||
|
||||
template <>
|
||||
void Map::AddToActive(Creature* c)
|
||||
{
|
||||
AddToActiveHelper(c);
|
||||
|
||||
// also not allow unloading spawn grid to prevent creating creature clone at load
|
||||
if (!c->IsPet() && c->GetSpawnId())
|
||||
Optional<Position> respawnLocation;
|
||||
switch (obj->GetTypeId())
|
||||
{
|
||||
float x, y, z;
|
||||
c->GetRespawnPosition(x, y, z);
|
||||
GridCoord p = Trinity::ComputeGridCoord(x, y);
|
||||
case TYPEID_UNIT:
|
||||
if (Creature* creature = obj->ToCreature(); !creature->IsPet() && creature->GetSpawnId())
|
||||
{
|
||||
respawnLocation.emplace();
|
||||
creature->GetRespawnPosition(respawnLocation->m_positionX, respawnLocation->m_positionY, respawnLocation->m_positionZ);
|
||||
}
|
||||
break;
|
||||
case TYPEID_GAMEOBJECT:
|
||||
if (GameObject* gameObject = obj->ToGameObject(); gameObject->GetSpawnId())
|
||||
{
|
||||
respawnLocation.emplace();
|
||||
gameObject->GetRespawnPosition(respawnLocation->m_positionX, respawnLocation->m_positionY, respawnLocation->m_positionZ);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (respawnLocation)
|
||||
{
|
||||
GridCoord p = Trinity::ComputeGridCoord(respawnLocation->GetPositionX(), respawnLocation->GetPositionY());
|
||||
if (getNGrid(p.x_coord, p.y_coord))
|
||||
getNGrid(p.x_coord, p.y_coord)->incUnloadActiveLock();
|
||||
else
|
||||
{
|
||||
GridCoord p2 = Trinity::ComputeGridCoord(c->GetPositionX(), c->GetPositionY());
|
||||
TC_LOG_ERROR("maps", "Active creature%s added to grid[%u, %u] but spawn grid[%u, %u] was not loaded.",
|
||||
c->GetGUID().ToString().c_str(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
|
||||
GridCoord p2 = Trinity::ComputeGridCoord(obj->GetPositionX(), obj->GetPositionY());
|
||||
TC_LOG_ERROR("maps", "Active object %s added to grid[%u, %u] but spawn grid[%u, %u] was not loaded.",
|
||||
obj->GetGUID().ToString().c_str(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void Map::AddToActive(DynamicObject* d)
|
||||
void Map::RemoveFromActive(WorldObject* obj)
|
||||
{
|
||||
AddToActiveHelper(d);
|
||||
}
|
||||
RemoveFromActiveHelper(obj);
|
||||
|
||||
template<class T>
|
||||
void Map::RemoveFromActive(T* /*obj*/) { }
|
||||
|
||||
template <>
|
||||
void Map::RemoveFromActive(Creature* c)
|
||||
{
|
||||
RemoveFromActiveHelper(c);
|
||||
|
||||
// also allow unloading spawn grid
|
||||
if (!c->IsPet() && c->GetSpawnId())
|
||||
Optional<Position> respawnLocation;
|
||||
switch (obj->GetTypeId())
|
||||
{
|
||||
float x, y, z;
|
||||
c->GetRespawnPosition(x, y, z);
|
||||
GridCoord p = Trinity::ComputeGridCoord(x, y);
|
||||
case TYPEID_UNIT:
|
||||
if (Creature* creature = obj->ToCreature(); !creature->IsPet() && creature->GetSpawnId())
|
||||
{
|
||||
respawnLocation.emplace();
|
||||
creature->GetRespawnPosition(respawnLocation->m_positionX, respawnLocation->m_positionY, respawnLocation->m_positionZ);
|
||||
}
|
||||
break;
|
||||
case TYPEID_GAMEOBJECT:
|
||||
if (GameObject* gameObject = obj->ToGameObject(); gameObject->GetSpawnId())
|
||||
{
|
||||
respawnLocation.emplace();
|
||||
gameObject->GetRespawnPosition(respawnLocation->m_positionX, respawnLocation->m_positionY, respawnLocation->m_positionZ);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (respawnLocation)
|
||||
{
|
||||
GridCoord p = Trinity::ComputeGridCoord(respawnLocation->GetPositionX(), respawnLocation->GetPositionY());
|
||||
if (getNGrid(p.x_coord, p.y_coord))
|
||||
getNGrid(p.x_coord, p.y_coord)->decUnloadActiveLock();
|
||||
else
|
||||
{
|
||||
GridCoord p2 = Trinity::ComputeGridCoord(c->GetPositionX(), c->GetPositionY());
|
||||
TC_LOG_ERROR("maps", "Active creature %s removed from grid[%u, %u] but spawn grid[%u, %u] was not loaded.",
|
||||
c->GetGUID().ToString().c_str(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
|
||||
GridCoord p2 = Trinity::ComputeGridCoord(obj->GetPositionX(), obj->GetPositionY());
|
||||
TC_LOG_ERROR("maps", "Active object %s removed from to grid[%u, %u] but spawn grid[%u, %u] was not loaded.",
|
||||
obj->GetGUID().ToString().c_str(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void Map::RemoveFromActive(DynamicObject* obj)
|
||||
{
|
||||
RemoveFromActiveHelper(obj);
|
||||
}
|
||||
|
||||
template TC_GAME_API bool Map::AddToMap(Corpse*);
|
||||
template TC_GAME_API bool Map::AddToMap(Creature*);
|
||||
template TC_GAME_API bool Map::AddToMap(GameObject*);
|
||||
|
||||
Reference in New Issue
Block a user