diff options
author | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
---|---|---|
committer | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
commit | e585187b248f48b3c6e9247b49fa07c6565d65e5 (patch) | |
tree | 637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /src/game/ObjectGridLoader.cpp | |
parent | 26b5e033ffde3d161382fc9addbfa99738379641 (diff) |
*Backed out changeset 3be01fb200a5
--HG--
branch : trunk
Diffstat (limited to 'src/game/ObjectGridLoader.cpp')
-rw-r--r-- | src/game/ObjectGridLoader.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/game/ObjectGridLoader.cpp b/src/game/ObjectGridLoader.cpp index 32b0a08e409..6a11fe44f86 100644 --- a/src/game/ObjectGridLoader.cpp +++ b/src/game/ObjectGridLoader.cpp @@ -17,6 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #include "ObjectGridLoader.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" @@ -28,20 +29,25 @@ #include "World.h" #include "CellImpl.h" #include "CreatureAI.h" + class TRINITY_DLL_DECL ObjectGridRespawnMover { public: ObjectGridRespawnMover() {} + void Move(GridType &grid); + template<class T> void Visit(GridRefManager<T> &) {} void Visit(CreatureMapType &m); }; + void ObjectGridRespawnMover::Move(GridType &grid) { TypeContainerVisitor<ObjectGridRespawnMover, GridTypeMapContainer > mover(*this); grid.Visit(mover); } + void ObjectGridRespawnMover::Visit(CreatureMapType &m) { @@ -52,12 +58,16 @@ ObjectGridRespawnMover::Visit(CreatureMapType &m) { Creature * c = iter->getSource(); ++iter; + assert(!c->isPet() && "ObjectGridRespawnMover don't must be called for pets"); + Cell const& cur_cell = c->GetCurrentCell(); + float resp_x, resp_y, resp_z; c->GetRespawnCoord(resp_x, resp_y, resp_z); CellPair resp_val = Trinity::ComputeCellPair(resp_x, resp_y); Cell resp_cell(resp_val); + if(cur_cell.DiffGrid(resp_cell)) { c->GetMap()->CreatureRespawnRelocation(c); @@ -65,6 +75,7 @@ ObjectGridRespawnMover::Visit(CreatureMapType &m) } } } + // for loading world object at grid loading (Corpses) class ObjectWorldLoader { @@ -72,8 +83,11 @@ class ObjectWorldLoader explicit ObjectWorldLoader(ObjectGridLoader& gloader) : i_cell(gloader.i_cell), i_grid(gloader.i_grid), i_map(gloader.i_map), i_corpses (0) {} + void Visit(CorpseMapType &m); + template<class T> void Visit(GridRefManager<T>&) { } + private: Cell i_cell; NGridType &i_grid; @@ -81,16 +95,20 @@ class ObjectWorldLoader public: uint32 i_corpses; }; + template<class T> void addUnitState(T* /*obj*/, CellPair const& /*cell_pair*/) { } + template<> void addUnitState(Creature *obj, CellPair const& cell_pair) { Cell cell(cell_pair); + obj->SetCurrentCell(cell); if(obj->isSpiritService()) obj->setDeathState(DEAD); } + template <class T> void AddObjectHelper(CellPair &cell, GridRefManager<T> &m, uint32 &count, Map* map, T *obj) { @@ -99,8 +117,10 @@ void AddObjectHelper(CellPair &cell, GridRefManager<T> &m, uint32 &count, Map* m obj->AddToWorld(); if(obj->isActiveObject()) map->AddToActive(obj); + ++count; } + template <class T> void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> &m, uint32 &count, Map* map) { @@ -114,29 +134,37 @@ void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> & delete obj; continue; } + AddObjectHelper(cell, m, count, map, obj); } } + void LoadHelper(CellCorpseSet const& cell_corpses, CellPair &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 = ObjectAccessor::Instance().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); + AddObjectHelper(cell, m, count, map, obj); } } + void ObjectGridLoader::Visit(GameObjectMapType &m) { @@ -144,9 +172,12 @@ ObjectGridLoader::Visit(GameObjectMapType &m) uint32 y = (i_cell.GridY()*MAX_NUMBER_OF_CELLS) + i_cell.CellY(); CellPair cell_pair(x,y); uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellObjectGuids const& cell_guids = objmgr.GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cell_id); + LoadHelper(cell_guids.gameobjects, cell_pair, m, i_gameObjects, i_map); } + void ObjectGridLoader::Visit(CreatureMapType &m) { @@ -154,9 +185,12 @@ ObjectGridLoader::Visit(CreatureMapType &m) uint32 y = (i_cell.GridY()*MAX_NUMBER_OF_CELLS) + i_cell.CellY(); CellPair cell_pair(x,y); uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellObjectGuids const& cell_guids = objmgr.GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cell_id); + LoadHelper(cell_guids.creatures, cell_pair, m, i_creatures, i_map); } + void ObjectWorldLoader::Visit(CorpseMapType &m) { @@ -164,10 +198,12 @@ ObjectWorldLoader::Visit(CorpseMapType &m) uint32 y = (i_cell.GridY()*MAX_NUMBER_OF_CELLS) + i_cell.CellY(); CellPair cell_pair(x,y); uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + // corpses are always added to spawn mode 0 and they are spawned by their instance id CellObjectGuids const& cell_guids = objmgr.GetCellObjectGuids(i_map->GetId(), 0, cell_id); LoadHelper(cell_guids.corpses, cell_pair, m, i_corpses, i_map); } + void ObjectGridLoader::Load(GridType &grid) { @@ -175,6 +211,7 @@ ObjectGridLoader::Load(GridType &grid) TypeContainerVisitor<ObjectGridLoader, GridTypeMapContainer > loader(*this); grid.Visit(loader); } + { ObjectWorldLoader wloader(*this); TypeContainerVisitor<ObjectWorldLoader, WorldTypeMapContainer > loader(wloader); @@ -182,6 +219,7 @@ ObjectGridLoader::Load(GridType &grid) i_corpses = wloader.i_corpses; } } + void ObjectGridLoader::LoadN(void) { i_gameObjects = 0; i_creatures = 0; i_corpses = 0; @@ -198,6 +236,7 @@ void ObjectGridLoader::LoadN(void) } sLog.outDebug("%u GameObjects, %u Creatures, and %u Corpses/Bones loaded for grid %u on map %u", i_gameObjects, i_creatures, i_corpses,i_grid.GetGridId(), i_map->GetId()); } + void ObjectGridUnloader::MoveToRespawnN() { for(unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x) @@ -209,12 +248,14 @@ void ObjectGridUnloader::MoveToRespawnN() } } } + void ObjectGridUnloader::Unload(GridType &grid) { TypeContainerVisitor<ObjectGridUnloader, GridTypeMapContainer > unloader(*this); grid.Visit(unloader); } + template<class T> void ObjectGridUnloader::Visit(GridRefManager<T> &m) @@ -229,12 +270,14 @@ ObjectGridUnloader::Visit(GridRefManager<T> &m) delete obj; } } + void ObjectGridStoper::Stop(GridType &grid) { TypeContainerVisitor<ObjectGridStoper, GridTypeMapContainer > stoper(*this); grid.Visit(stoper); } + void ObjectGridStoper::Visit(CreatureMapType &m) { @@ -250,18 +293,21 @@ ObjectGridStoper::Visit(CreatureMapType &m) } } } + void ObjectGridCleaner::Stop(GridType &grid) { TypeContainerVisitor<ObjectGridCleaner, GridTypeMapContainer > stoper(*this); grid.Visit(stoper); } + void ObjectGridCleaner::Visit(CreatureMapType &m) { for(CreatureMapType::iterator iter=m.begin(); iter != m.end(); ++iter) iter->getSource()->CleanupsBeforeDelete(); } + template<class T> void ObjectGridCleaner::Visit(GridRefManager<T> &m) @@ -269,6 +315,7 @@ ObjectGridCleaner::Visit(GridRefManager<T> &m) for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter) iter->getSource()->RemoveFromWorld(); } + template void ObjectGridUnloader::Visit(CreatureMapType &); template void ObjectGridUnloader::Visit(GameObjectMapType &); template void ObjectGridUnloader::Visit(DynamicObjectMapType &); |