Professional Documents
Culture Documents
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright
information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ObjectGridLoader.h"
#include "CellImpl.h"
#include "Corpse.h"
#include "Creature.h"
#include "CreatureAI.h"
#include "DynamicObject.h"
#include "GameObject.h"
#include "ObjectMgr.h"
#include "Transport.h"
#include "Vehicle.h"
private:
Cell i_cell;
Map* i_map;
NGridType& i_grid;
public:
uint32& i_corpses;
};
template <>
void AddObjectHelper(CellCoord& cell, CreatureMapType& m, uint32& count, Map* map,
Creature* obj)
{
obj->AddToGrid(m);
ObjectGridLoader::SetObjectCell(obj, cell);
obj->AddToWorld();
if (obj->isActiveObject())
map->AddToActive(obj);
++count;
}
template <>
void AddObjectHelper(CellCoord& cell, GameObjectMapType& m, uint32& count, Map*
map, GameObject* obj)
{
obj->AddToGrid(m);
ObjectGridLoader::SetObjectCell(obj, cell);
obj->AddToWorld();
if (obj->isActiveObject())
map->AddToActive(obj);
++count;
}
if (!obj->LoadFromDB(guid, map))
{
delete obj;
continue;
}
template <>
void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell,
GridRefMgr<GameObject>& m, uint32& count, Map* map)
{
for (CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid !=
guid_set.end(); ++i_guid)
{
ObjectGuid::LowType guid = *i_guid;
GameObjectData const* data = sObjectMgr->GetGOData(guid);
GameObject* obj = data && sObjectMgr->IsGameObjectStaticTransport(data->id)
? new StaticTransport() : new GameObject();
if (!obj->LoadFromDB(guid, map))
{
delete obj;
continue;
}
void ObjectGridLoader::Visit(GameObjectMapType& m)
{
CellCoord cellCoord = i_cell.GetCellCoord();
CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map-
>GetId(), i_map->GetSpawnMode(), cellCoord.GetId());
LoadHelper(cell_guids.gameobjects, cellCoord, m, i_gameObjects, i_map);
}
void ObjectGridLoader::Visit(CreatureMapType& m)
{
CellCoord cellCoord = i_cell.GetCellCoord();
CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map-
>GetId(), i_map->GetSpawnMode(), cellCoord.GetId());
LoadHelper(cell_guids.creatures, cellCoord, m, i_creatures, i_map);
}
++i_corpses;
}
}
}
void ObjectGridLoader::LoadN(void)
{
i_gameObjects = 0;
i_creatures = 0;
i_corpses = 0;
i_cell.data.Part.cell_y = 0;
for (uint32 x = 0; x < MAX_NUMBER_OF_CELLS; ++x)
{
i_cell.data.Part.cell_x = x;
for (uint32 y = 0; y < MAX_NUMBER_OF_CELLS; ++y)
{
i_cell.data.Part.cell_y = y;
template<class T>
void ObjectGridUnloader::Visit(GridRefMgr<T>& m)
{
while (!m.IsEmpty())
{
T* obj = m.getFirst()->GetSource();
// if option set then object already saved at this moment
//if (!sWorld->getBoolConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY))
// obj->SaveRespawnTime();
//Some creatures may summon other temp summons in CleanupsBeforeDelete()
//So we need this even after cleaner (maybe we can remove cleaner)
//Example: Flame Leviathan Turret 33139 is summoned when a creature is
deleted
//TODO: Check if that script has the correct logic. Do we really need to
summons something before deleting?
obj->CleanupsBeforeDelete();
///- object will get delinked from the manager when deleted
delete obj;
}
}
template<class T>
void ObjectGridCleaner::Visit(GridRefMgr<T>& m)
{
for (typename GridRefMgr<T>::iterator iter = m.begin(); iter != m.end(); +
+iter)
iter->GetSource()->CleanupsBeforeDelete();
}