diff options
author | megamage <none@none> | 2009-05-31 14:26:57 -0500 |
---|---|---|
committer | megamage <none@none> | 2009-05-31 14:26:57 -0500 |
commit | da871e2fc07ef529beea3d3e8a52518bde842775 (patch) | |
tree | 7314d7c7b03304d75d606874693cf565e95daa28 /src/game/ObjectMgr.cpp | |
parent | 8d1f4f9ea0beb503e2a3014abb95263e501ef1c5 (diff) |
*Move addcre/go functions from opvp to objmgr.
*Do not save respawn time for internally added cre/go.
--HG--
branch : trunk
Diffstat (limited to 'src/game/ObjectMgr.cpp')
-rw-r--r-- | src/game/ObjectMgr.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index e23d114f0f2..1b661bc41ba 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -1229,6 +1229,102 @@ void ObjectMgr::RemoveCreatureFromGrid(uint32 guid, CreatureData const* data) } } +uint32 ObjectMgr::AddGameObject(uint32 entry, uint32 mapId, float x, float y, float z, float o, uint32 spawntimedelay, float rotation0, float rotation1, float rotation2, float rotation3) +{ + GameObjectInfo const* goinfo = GetGameObjectInfo(entry); + if (!goinfo) + return 0; + + uint32 guid = GenerateLowGuid(HIGHGUID_GAMEOBJECT); + GameObjectData& data = NewGOData(guid); + data.id = entry; + data.mapid = mapId; + data.posX = x; + data.posY = y; + data.posZ = z; + data.orientation = o; + data.rotation0 = rotation0; + data.rotation1 = rotation1; + data.rotation2 = rotation2; + data.rotation3 = rotation3; + data.spawntimesecs = spawntimedelay; + data.animprogress = 100; + data.spawnMask = 1; + data.go_state = GO_STATE_READY; + data.phaseMask = PHASEMASK_NORMAL; + data.dbData = false; + + AddGameobjectToGrid(guid, &data); + + // Spawn if necessary (loaded grids only) + if(Map* map = const_cast<Map*>(MapManager::Instance().GetBaseMap(mapId))) + { + // We use spawn coords to spawn + if(!map->Instanceable() && !map->IsRemovalGrid(x, y)) + { + GameObject *go = new GameObject; + if(!go->LoadFromDB(guid, map)) + { + sLog.outError("AddGameObject: cannot add gameobject entry %u to map", entry); + delete go; + return 0; + } + map->Add(go); + } + } + + return guid; +} + +uint32 ObjectMgr::AddCreature(uint32 entry, uint32 team, uint32 mapId, float x, float y, float z, float o, uint32 spawntimedelay) +{ + CreatureInfo const *cInfo = GetCreatureTemplate(entry); + if(!cInfo) + return 0; + + uint32 guid = GenerateLowGuid(HIGHGUID_UNIT); + CreatureData& data = NewOrExistCreatureData(guid); + data.id = entry; + data.mapid = mapId; + data.displayid = 0; + data.equipmentId = cInfo->equipmentId; + data.posX = x; + data.posY = y; + data.posZ = z; + data.orientation = o; + data.spawntimesecs = spawntimedelay; + data.spawndist = 0; + data.currentwaypoint = 0; + data.curhealth = cInfo->maxhealth; + data.curmana = cInfo->maxmana; + data.is_dead = false; + data.movementType = cInfo->MovementType; + data.spawnMask = 1; + data.phaseMask = PHASEMASK_NORMAL; + data.dbData = false; + + AddCreatureToGrid(guid, &data); + + // Spawn if necessary (loaded grids only) + if(Map* map = const_cast<Map*>(MapManager::Instance().GetBaseMap(mapId))) + { + // We use spawn coords to spawn + if(!map->Instanceable() && !map->IsRemovalGrid(x, y)) + { + Creature* creature = new Creature; + if(!creature->LoadFromDB(guid, map)) + { + sLog.outError("AddCreature: cannot add creature entry %u to map", entry); + delete creature; + return 0; + } + map->Add(creature); + } + } + + return guid; +} + void ObjectMgr::LoadGameobjects() { uint32 count = 0; |