mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-25 06:36:24 +00:00
feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)
This commit is contained in:
@@ -23,7 +23,7 @@ class ObjectWorldLoader
|
||||
{
|
||||
public:
|
||||
explicit ObjectWorldLoader(ObjectGridLoader& gloader)
|
||||
: i_cell(gloader.i_cell), i_map(gloader.i_map), i_grid(gloader.i_grid), i_corpses (0)
|
||||
: i_cell(gloader.i_cell), i_map(gloader.i_map), i_grid(gloader.i_grid), i_corpses(gloader.i_corpses)
|
||||
{}
|
||||
|
||||
void Visit(CorpseMapType& m);
|
||||
@@ -33,9 +33,9 @@ public:
|
||||
private:
|
||||
Cell i_cell;
|
||||
Map* i_map;
|
||||
public:
|
||||
NGridType& i_grid;
|
||||
uint32 i_corpses;
|
||||
public:
|
||||
uint32& i_corpses;
|
||||
};
|
||||
|
||||
template<class T> void ObjectGridLoader::SetObjectCell(T* /*obj*/, CellCoord const& /*cellCoord*/)
|
||||
@@ -93,7 +93,7 @@ void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell, GridRefManager<T>&
|
||||
for (CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid)
|
||||
{
|
||||
T* obj = new T;
|
||||
uint32 guid = *i_guid;
|
||||
ObjectGuid::LowType guid = *i_guid;
|
||||
//LOG_INFO("server", "DEBUG: LoadHelper from table: %s for (guid: %u) Loading", table, guid);
|
||||
if (!obj->LoadFromDB(guid, map))
|
||||
{
|
||||
@@ -110,7 +110,7 @@ void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell, GridRefManager<Gam
|
||||
{
|
||||
for (CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid)
|
||||
{
|
||||
uint32 guid = *i_guid;
|
||||
ObjectGuid::LowType guid = *i_guid;
|
||||
GameObjectData const* data = sObjectMgr->GetGOData(guid);
|
||||
GameObject* obj = data && sObjectMgr->IsGameObjectStaticTransport(data->id) ? new StaticTransport() : new GameObject();
|
||||
//LOG_INFO("server", "DEBUG: LoadHelper from table: %s for (guid: %u) Loading", table, guid);
|
||||
@@ -124,38 +124,6 @@ void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell, GridRefManager<Gam
|
||||
}
|
||||
}
|
||||
|
||||
void LoadHelper(CellCorpseSet const& cell_corpses, CellCoord& cell, CorpseMapType& m, uint32& count, Map* map)
|
||||
{
|
||||
if (cell_corpses.empty())
|
||||
return;
|
||||
|
||||
for (CellCorpseSet::const_iterator itr = cell_corpses.begin(); itr != cell_corpses.end(); ++itr)
|
||||
{
|
||||
if (itr->second != map->GetInstanceId())
|
||||
continue;
|
||||
|
||||
uint32 player_guid = itr->first;
|
||||
|
||||
Corpse* obj = sObjectAccessor->GetCorpseForPlayerGUID(player_guid);
|
||||
if (!obj)
|
||||
continue;
|
||||
|
||||
// TODO: this is a hack
|
||||
// corpse's map should be reset when the map is unloaded
|
||||
// but it may still exist when the grid is unloaded but map is not
|
||||
// in that case map == currMap
|
||||
obj->SetMap(map);
|
||||
|
||||
if (obj->IsInGrid())
|
||||
{
|
||||
obj->AddToWorld();
|
||||
continue;
|
||||
}
|
||||
|
||||
AddObjectHelper(cell, m, count, map, obj);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectGridLoader::Visit(GameObjectMapType& m)
|
||||
{
|
||||
CellCoord cellCoord = i_cell.GetCellCoord();
|
||||
@@ -170,12 +138,23 @@ void ObjectGridLoader::Visit(CreatureMapType& m)
|
||||
LoadHelper(cell_guids.creatures, cellCoord, m, i_creatures, i_map);
|
||||
}
|
||||
|
||||
void ObjectWorldLoader::Visit(CorpseMapType& m)
|
||||
void ObjectWorldLoader::Visit(CorpseMapType& /*m*/)
|
||||
{
|
||||
CellCoord cellCoord = i_cell.GetCellCoord();
|
||||
// corpses are always added to spawn mode 0 and they are spawned by their instance id
|
||||
CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), 0, cellCoord.GetId());
|
||||
LoadHelper(cell_guids.corpses, cellCoord, m, i_corpses, i_map);
|
||||
if (std::unordered_set<Corpse*> const* corpses = i_map->GetCorpsesInCell(cellCoord.GetId()))
|
||||
{
|
||||
for (Corpse* corpse : *corpses)
|
||||
{
|
||||
corpse->AddToWorld();
|
||||
GridType& cell = i_grid.GetGridType(i_cell.CellX(), i_cell.CellY());
|
||||
if (corpse->IsWorldObject())
|
||||
cell.AddWorldObject(corpse);
|
||||
else
|
||||
cell.AddGridObject(corpse);
|
||||
|
||||
++i_corpses;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectGridLoader::LoadN(void)
|
||||
@@ -184,10 +163,10 @@ void ObjectGridLoader::LoadN(void)
|
||||
i_creatures = 0;
|
||||
i_corpses = 0;
|
||||
i_cell.data.Part.cell_y = 0;
|
||||
for (unsigned int x = 0; x < MAX_NUMBER_OF_CELLS; ++x)
|
||||
for (uint32 x = 0; x < MAX_NUMBER_OF_CELLS; ++x)
|
||||
{
|
||||
i_cell.data.Part.cell_x = x;
|
||||
for (unsigned int y = 0; y < MAX_NUMBER_OF_CELLS; ++y)
|
||||
for (uint32 y = 0; y < MAX_NUMBER_OF_CELLS; ++y)
|
||||
{
|
||||
i_cell.data.Part.cell_y = y;
|
||||
|
||||
@@ -202,7 +181,6 @@ void ObjectGridLoader::LoadN(void)
|
||||
ObjectWorldLoader worker(*this);
|
||||
TypeContainerVisitor<ObjectWorldLoader, WorldTypeMapContainer> visitor(worker);
|
||||
i_grid.VisitGrid(x, y, visitor);
|
||||
i_corpses += worker.i_corpses;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,7 +218,7 @@ void ObjectGridCleaner::Visit(GridRefManager<T>& m)
|
||||
template void ObjectGridUnloader::Visit(CreatureMapType&);
|
||||
template void ObjectGridUnloader::Visit(GameObjectMapType&);
|
||||
template void ObjectGridUnloader::Visit(DynamicObjectMapType&);
|
||||
template void ObjectGridUnloader::Visit(CorpseMapType&);
|
||||
|
||||
template void ObjectGridCleaner::Visit(CreatureMapType&);
|
||||
template void ObjectGridCleaner::Visit<GameObject>(GameObjectMapType&);
|
||||
template void ObjectGridCleaner::Visit<DynamicObject>(DynamicObjectMapType&);
|
||||
|
||||
Reference in New Issue
Block a user