Delete obj if it is not successfully added to grid. More to fix.

This commit is contained in:
megamage
2011-11-28 14:05:25 -05:00
parent cde7ea260e
commit 529af3cd09
12 changed files with 79 additions and 42 deletions
+11 -2
View File
@@ -1454,7 +1454,11 @@ bool Battleground::AddObject(uint32 type, uint32 entry, float x, float y, float
data.go_state = 1;
*/
// Add to world, so it can be later looked up from HashMapHolder
map->AddToMap(go);
if (!map->AddToMap(go))
{
delete go;
return false;
}
m_BgObjects[type] = go->GetGUID();
return true;
}
@@ -1557,7 +1561,12 @@ Creature* Battleground::AddCreature(uint32 entry, uint32 type, uint32 teamval, f
creature->SetSpeed(MOVE_WALK, cinfo->speed_walk);
creature->SetSpeed(MOVE_RUN, cinfo->speed_run);
map->AddToMap(creature);
if (!map->AddToMap(creature))
{
delete creature;
return NULL;
}
m_BgCreatures[type] = creature->GetGUID();
if (respawntime)
@@ -1241,7 +1241,7 @@ bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, uint32 vehId, uint3
return true;
}
bool Creature::LoadFromDB(uint32 guid, Map* map)
bool Creature::LoadCreatureFromDB(uint32 guid, Map* map, bool addToMap)
{
CreatureData const* data = sObjectMgr->GetCreatureData(guid);
@@ -1310,6 +1310,8 @@ bool Creature::LoadFromDB(uint32 guid, Map* map)
m_creatureData = data;
if (addToMap && !GetMap()->AddToMap(this))
return false;
return true;
}
+2 -1
View File
@@ -575,7 +575,8 @@ class Creature : public Unit, public GridObject<Creature>, public MapCreature
void setDeathState(DeathState s); // override virtual Unit::setDeathState
bool FallGround();
bool LoadFromDB(uint32 guid, Map* map);
bool LoadFromDB(uint32 guid, Map* map) { return LoadCreatureFromDB(guid, map, false); }
bool LoadCreatureFromDB(uint32 guid, Map* map, bool addToMap = true);
void SaveToDB();
// overriden in Pet
virtual void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
@@ -695,7 +695,7 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
WorldDatabase.CommitTransaction(trans);
}
bool GameObject::LoadFromDB(uint32 guid, Map* map)
bool GameObject::LoadGameObjectFromDB(uint32 guid, Map* map, bool addToMap)
{
GameObjectData const* data = sObjectMgr->GetGOData(guid);
@@ -760,6 +760,9 @@ bool GameObject::LoadFromDB(uint32 guid, Map* map)
m_goData = data;
if (addToMap && !GetMap()->AddToMap(this))
return false;
return true;
}
@@ -648,7 +648,8 @@ class GameObject : public WorldObject, public GridObject<GameObject>
void SaveToDB();
void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
bool LoadFromDB(uint32 guid, Map* map);
bool LoadFromDB(uint32 guid, Map* map) { return LoadGameObjectFromDB(guid, map, false); }
bool LoadGameObjectFromDB(uint32 guid, Map* map, bool addToMap = true);
void DeleteFromDB();
void SetOwnerGUID(uint64 owner)
+3 -4
View File
@@ -1176,10 +1176,8 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
{
Creature* creature = new Creature;
//sLog->outDebug("Spawning creature %u", *itr);
if (!creature->LoadFromDB(*itr, map))
if (!creature->LoadCreatureFromDB(*itr, map))
delete creature;
else
map->AddToMap(creature);
}
}
}
@@ -1205,7 +1203,8 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
{
GameObject* pGameobject = new GameObject;
//sLog->outDebug("Spawning gameobject %u", *itr);
if (!pGameobject->LoadFromDB(*itr, map))
//TODO: find out when it is add to map
if (!pGameobject->LoadGameObjectFromDB(*itr, map, false))
delete pGameobject;
else
{
+3 -6
View File
@@ -1630,13 +1630,12 @@ uint32 ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, float y, float
if (!map->Instanceable() && map->IsGridLoaded(x, y))
{
GameObject* go = new GameObject;
if (!go->LoadFromDB(guid, map))
if (!go->LoadGameObjectFromDB(guid, map))
{
sLog->outError("AddGOData: cannot add gameobject entry %u to map", entry);
delete go;
return 0;
}
map->AddToMap(go);
}
sLog->outDebug(LOG_FILTER_MAPS, "AddGOData: dbguid %u entry %u map %u x %f y %f z %f o %f", guid, entry, mapId, x, y, z, o);
@@ -1666,13 +1665,12 @@ bool ObjectMgr::MoveCreData(uint32 guid, uint32 mapId, Position pos)
if (!map->Instanceable() && map->IsGridLoaded(data.posX, data.posY))
{
Creature* creature = new Creature;
if (!creature->LoadFromDB(guid, map))
if (!creature->LoadCreatureFromDB(guid, map))
{
sLog->outError("AddCreature: cannot add creature entry %u to map", guid);
delete creature;
return false;
}
map->AddToMap(creature);
}
}
return true;
@@ -1719,13 +1717,12 @@ uint32 ObjectMgr::AddCreData(uint32 entry, uint32 /*team*/, uint32 mapId, float
if (!map->Instanceable() && !map->IsRemovalGrid(x, y))
{
Creature* creature = new Creature;
if (!creature->LoadFromDB(guid, map))
if (!creature->LoadCreatureFromDB(guid, map))
{
sLog->outError("AddCreature: cannot add creature entry %u to map", entry);
delete creature;
return 0;
}
map->AddToMap(creature);
}
}
+2 -4
View File
@@ -365,13 +365,11 @@ void PoolGroup<Creature>::Spawn1Object(PoolObject* obj)
{
Creature* creature = new Creature;
//sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning creature %u", guid);
if (!creature->LoadFromDB(obj->guid, map))
if (!creature->LoadCreatureFromDB(obj->guid, map))
{
delete creature;
return;
}
else
map->AddToMap(creature);
}
}
}
@@ -391,7 +389,7 @@ void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj)
{
GameObject* pGameobject = new GameObject;
//sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning gameobject %u", guid);
if (!pGameobject->LoadFromDB(obj->guid, map))
if (!pGameobject->LoadGameObjectFromDB(obj->guid, map, false))
{
delete pGameobject;
return;
+1 -3
View File
@@ -165,14 +165,12 @@ public:
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
// this will generate a new guid if the object is in an instance
if (!object->LoadFromDB(guidLow, map))
if (!object->LoadGameObjectFromDB(guidLow, map))
{
delete object;
return false;
}
map->AddToMap(object);
// TODO: is it really necessary to add both the real and DB table guid here ?
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
+5 -2
View File
@@ -147,9 +147,12 @@ public:
uint32 db_guid = creature->GetDBTableGUIDLow();
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
creature->LoadFromDB(db_guid, map);
if (!creature->LoadCreatureFromDB(db_guid, map))
{
delete creature;
return false;
}
map->AddToMap(creature);
sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid));
return true;
}
+25 -8
View File
@@ -578,8 +578,13 @@ public:
wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
wpCreature2->LoadFromDB(wpCreature2->GetDBTableGUIDLow(), map);
map->AddToMap(wpCreature2);
//TODO: Should we first use "Create" then use "LoadFromDB"?
if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetDBTableGUIDLow(), map))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature2;
return false;
}
//sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2);
}
@@ -777,8 +782,12 @@ public:
wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
wpCreature->LoadFromDB(wpCreature->GetDBTableGUIDLow(), map);
map->AddToMap(wpCreature);
if (!wpCreature->LoadCreatureFromDB(wpCreature->GetDBTableGUIDLow(), map))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete wpCreature;
return false;
}
if (target)
{
@@ -824,8 +833,12 @@ public:
}
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
creature->LoadFromDB(creature->GetDBTableGUIDLow(), map);
map->AddToMap(creature);
if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete creature;
return false;
}
if (target)
{
@@ -872,8 +885,12 @@ public:
}
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
creature->LoadFromDB(creature->GetDBTableGUIDLow(), map);
map->AddToMap(creature);
if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
{
handler->PSendSysMessage(LANG_WAYPOINT_NOTCREATED, id);
delete creature;
return false;
}
if (target)
{
+18 -9
View File
@@ -166,11 +166,15 @@ bool OutdoorPvPSI::HandleDropFlag(Player* player, uint32 spellId)
if (!go->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), SI_SILITHYST_MOUND, map, player->GetPhaseMask(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), 0, 0, 0, 0, 100, GO_STATE_READY))
{
delete go;
return true;
}
else
go->SetRespawnTime(0);
if (!map->AddToMap(go))
{
go->SetRespawnTime(0);
map->AddToMap(go);
delete go;
return true;
}
}
}
@@ -189,17 +193,22 @@ bool OutdoorPvPSI::HandleDropFlag(Player* player, uint32 spellId)
Map* map = player->GetMap();
if (!map)
{
delete go;
return true;
}
delete go;
return true;
}
if (!go->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), SI_SILITHYST_MOUND, map, player->GetPhaseMask(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), 0, 0, 0, 0, 100, GO_STATE_READY))
{
delete go;
return true;
}
else
go->SetRespawnTime(0);
if (!map->AddToMap(go))
{
go->SetRespawnTime(0);
map->AddToMap(go);
delete go;
return true;
}
}
}