*Move addcre/go functions from opvp to objmgr.

*Do not save respawn time for internally added cre/go.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-05-31 14:26:57 -05:00
parent 8d1f4f9ea0
commit da871e2fc0
10 changed files with 130 additions and 120 deletions

View File

@@ -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;