aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/server/game/Battlegrounds/Battleground.cpp13
-rwxr-xr-xsrc/server/game/Entities/Creature/Creature.cpp4
-rwxr-xr-xsrc/server/game/Entities/Creature/Creature.h3
-rwxr-xr-xsrc/server/game/Entities/GameObject/GameObject.cpp5
-rwxr-xr-xsrc/server/game/Entities/GameObject/GameObject.h3
-rwxr-xr-xsrc/server/game/Events/GameEventMgr.cpp7
-rwxr-xr-xsrc/server/game/Globals/ObjectMgr.cpp9
-rwxr-xr-xsrc/server/game/Pools/PoolMgr.cpp6
-rw-r--r--src/server/scripts/Commands/cs_gobject.cpp4
-rw-r--r--src/server/scripts/Commands/cs_npc.cpp7
-rw-r--r--src/server/scripts/Commands/cs_wp.cpp33
-rwxr-xr-xsrc/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp27
12 files changed, 79 insertions, 42 deletions
diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp
index af350ac39d6..4ad00f5d7aa 100755
--- a/src/server/game/Battlegrounds/Battleground.cpp
+++ b/src/server/game/Battlegrounds/Battleground.cpp
@@ -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)
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 922db88bcd0..3238d9873a9 100755
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -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;
}
diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h
index 665942e134a..6ae9fa97462 100755
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -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);
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index 9e514ad34bb..de1b0f84871 100755
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -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;
}
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index 9167b40d285..c47587177c8 100755
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -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)
diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp
index dbcb07e88f5..d3cc27c9e6c 100755
--- a/src/server/game/Events/GameEventMgr.cpp
+++ b/src/server/game/Events/GameEventMgr.cpp
@@ -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
{
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 6b0601d9663..6201a932a60 100755
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -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);
}
}
diff --git a/src/server/game/Pools/PoolMgr.cpp b/src/server/game/Pools/PoolMgr.cpp
index bd8840ff8a8..96bb4a211eb 100755
--- a/src/server/game/Pools/PoolMgr.cpp
+++ b/src/server/game/Pools/PoolMgr.cpp
@@ -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;
diff --git a/src/server/scripts/Commands/cs_gobject.cpp b/src/server/scripts/Commands/cs_gobject.cpp
index 4c9960992e1..eb1ccc543f3 100644
--- a/src/server/scripts/Commands/cs_gobject.cpp
+++ b/src/server/scripts/Commands/cs_gobject.cpp
@@ -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));
diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp
index 20d0994b911..bfa8b76f295 100644
--- a/src/server/scripts/Commands/cs_npc.cpp
+++ b/src/server/scripts/Commands/cs_npc.cpp
@@ -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;
}
diff --git a/src/server/scripts/Commands/cs_wp.cpp b/src/server/scripts/Commands/cs_wp.cpp
index ebeb7b8f4f4..d34ee801e50 100644
--- a/src/server/scripts/Commands/cs_wp.cpp
+++ b/src/server/scripts/Commands/cs_wp.cpp
@@ -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)
{
diff --git a/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp b/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp
index 23477741ba1..bcdcc69181a 100755
--- a/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp
+++ b/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp
@@ -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;
}
}
}