diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index e2d0be3..7adb9c4 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -1392,9 +1392,146 @@ void ObjectMgr::RemoveCreatureFromGrid(uint32 guid, CreatureData const* data) } } +uint32 ObjectMgr::LoadGameObject(Field *fields, std::map spawnMasks, uint32 guid, uint32 entry, uint32 guid_last) +{ + GameObjectInfo const* gInfo = GetGameObjectInfo(entry); + if (!gInfo) + { + sLog.outErrorDb("Table `gameobject` has gameobject (GUID: %u) with non existing gameobject entry %u, skipped.", guid, entry); + return guid_last; + } + + if (!gInfo->displayId) + { + switch(gInfo->type) + { + // can be invisible always and then not req. display id in like case + case GAMEOBJECT_TYPE_TRAP: + case GAMEOBJECT_TYPE_SPELL_FOCUS: + break; + default: + sLog.outErrorDb("Gameobject (GUID: %u Entry %u GoType: %u) have displayId == 0 and then will always invisible in game.", guid, entry, gInfo->type); + break; + } + } + else if (!sGameObjectDisplayInfoStore.LookupEntry(gInfo->displayId)) + { + sLog.outErrorDb("Gameobject (GUID: %u Entry %u GoType: %u) have invalid displayId (%u), not loaded.", guid, entry, gInfo->type, gInfo->displayId); + return guid_last; + } + + GameObjectData& data = mGameObjectDataMap[guid]; + + data.id = entry; + data.mapid = fields[ 2].GetUInt32(); + data.posX = fields[ 3].GetFloat(); + data.posY = fields[ 4].GetFloat(); + data.posZ = fields[ 5].GetFloat(); + data.orientation = fields[ 6].GetFloat(); + data.rotation.x = fields[ 7].GetFloat(); + data.rotation.y = fields[ 8].GetFloat(); + data.rotation.z = fields[ 9].GetFloat(); + data.rotation.w = fields[10].GetFloat(); + data.spawntimesecs = fields[11].GetInt32(); + data.animprogress = fields[12].GetUInt32(); + uint32 go_state = fields[13].GetUInt32(); + data.spawnMask = fields[14].GetUInt8(); + data.phaseMask = fields[15].GetUInt16(); + int16 gameEvent = fields[16].GetInt16(); + int16 GuidPoolId = fields[17].GetInt16(); + int16 EntryPoolId = fields[18].GetInt16(); + + MapEntry const* mapEntry = sMapStore.LookupEntry(data.mapid); + if (!mapEntry) + { + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) that spawned at nonexistent map (Id: %u), skip", guid, data.id, data.mapid); + return guid_last; + } + + if (data.spawnMask & ~spawnMasks[data.mapid]) + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) that have wrong spawn mask %u including not supported difficulty modes for map (Id: %u), skip", guid, data.id, data.spawnMask, data.mapid); + + if (data.spawntimesecs == 0 && gInfo->IsDespawnAtAction()) + { + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with `spawntimesecs` (0) value, but gameobejct marked as despawnable at action.", guid, data.id); + } + + if (go_state >= MAX_GO_STATE) + { + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid `state` (%u) value, skip", guid, data.id, go_state); + return guid_last; + } + data.go_state = GOState(go_state); + + if (data.rotation.x < -1.0f || data.rotation.x > 1.0f) + { + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.x (%f) value, skip", guid, data.id, data.rotation.x); + return guid_last; + } + + if (data.rotation.y < -1.0f || data.rotation.y > 1.0f) + { + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.y (%f) value, skip", guid, data.id, data.rotation.y); + return guid_last; + } + + if (data.rotation.z < -1.0f || data.rotation.z > 1.0f) + { + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.z (%f) value, skip", guid, data.id, data.rotation.z); + return guid_last; + } + + if (data.rotation.w < -1.0f || data.rotation.w > 1.0f) + { + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.w (%f) value, skip", guid, data.id, data.rotation.w); + return guid_last; + } + + if (!MapManager::IsValidMapCoord(data.mapid, data.posX, data.posY, data.posZ, data.orientation)) + { + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid coordinates, skip", guid, data.id); + return guid_last; + } + + if (data.phaseMask == 0) + { + sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with `phaseMask`=0 (not visible for anyone), set to 1.", guid, data.id); + data.phaseMask = 1; + } + + if (gameEvent==0 && GuidPoolId==0 && EntryPoolId==0)// if not this is to be managed by GameEvent System or Pool system + AddGameobjectToGrid(guid, &data); + + uint32 linkedTrapId = gInfo->GetLinkedGameObjectEntry(); + if (linkedTrapId > 0) + { + guid_last++; + sLog.outErrorDb("guid_last = %u", guid_last); + guid_last = LoadGameObject(fields, spawnMasks, guid_last, linkedTrapId, guid_last); + } + return guid_last; +} + void ObjectMgr::LoadGameObjects() { - uint32 count = 0; + // calculaate last guid + QueryResult *result0 = WorldDatabase.Query("SELECT MAX(guid) FROM gameobject"); + if (!result0) + { + BarGoLink bar0(1); + + bar0.step(); + + sLog.outString(); + sLog.outErrorDb(">> Loaded 0 gameobjects. DB table `gameobject` is empty."); + return; + } + BarGoLink bar0(1); + Field *fields0 = result0->Fetch(); + bar0.step(); + uint32 guid_last = fields0[ 0].GetUInt32(); + sLog.outErrorDb("guid_last=%u", guid_last); + delete result0; // 0 1 2 3 4 5 6 QueryResult *result = WorldDatabase.Query("SELECT gameobject.guid, gameobject.id, map, position_x, position_y, position_z, orientation," @@ -1407,17 +1544,6 @@ void ObjectMgr::LoadGameObjects() "LEFT OUTER JOIN pool_gameobject ON gameobject.guid = pool_gameobject.guid " "LEFT OUTER JOIN pool_gameobject_template ON gameobject.id = pool_gameobject_template.id"); - if (!result) - { - BarGoLink bar(1); - - bar.step(); - - sLog.outString(); - sLog.outErrorDb(">> Loaded 0 gameobjects. DB table `gameobject` is empty."); - return; - } - // build single time for check spawnmask std::map spawnMasks; for(uint32 i = 0; i < sMapStore.GetNumRows(); ++i) @@ -1436,115 +1562,7 @@ void ObjectMgr::LoadGameObjects() uint32 guid = fields[ 0].GetUInt32(); uint32 entry = fields[ 1].GetUInt32(); - GameObjectInfo const* gInfo = GetGameObjectInfo(entry); - if (!gInfo) - { - sLog.outErrorDb("Table `gameobject` has gameobject (GUID: %u) with non existing gameobject entry %u, skipped.", guid, entry); - continue; - } - - if (!gInfo->displayId) - { - switch(gInfo->type) - { - // can be invisible always and then not req. display id in like case - case GAMEOBJECT_TYPE_TRAP: - case GAMEOBJECT_TYPE_SPELL_FOCUS: - break; - default: - sLog.outErrorDb("Gameobject (GUID: %u Entry %u GoType: %u) have displayId == 0 and then will always invisible in game.", guid, entry, gInfo->type); - break; - } - } - else if (!sGameObjectDisplayInfoStore.LookupEntry(gInfo->displayId)) - { - sLog.outErrorDb("Gameobject (GUID: %u Entry %u GoType: %u) have invalid displayId (%u), not loaded.", guid, entry, gInfo->type, gInfo->displayId); - continue; - } - - GameObjectData& data = mGameObjectDataMap[guid]; - - data.id = entry; - data.mapid = fields[ 2].GetUInt32(); - data.posX = fields[ 3].GetFloat(); - data.posY = fields[ 4].GetFloat(); - data.posZ = fields[ 5].GetFloat(); - data.orientation = fields[ 6].GetFloat(); - data.rotation.x = fields[ 7].GetFloat(); - data.rotation.y = fields[ 8].GetFloat(); - data.rotation.z = fields[ 9].GetFloat(); - data.rotation.w = fields[10].GetFloat(); - data.spawntimesecs = fields[11].GetInt32(); - data.animprogress = fields[12].GetUInt32(); - uint32 go_state = fields[13].GetUInt32(); - data.spawnMask = fields[14].GetUInt8(); - data.phaseMask = fields[15].GetUInt16(); - int16 gameEvent = fields[16].GetInt16(); - int16 GuidPoolId = fields[17].GetInt16(); - int16 EntryPoolId = fields[18].GetInt16(); - - MapEntry const* mapEntry = sMapStore.LookupEntry(data.mapid); - if (!mapEntry) - { - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) that spawned at nonexistent map (Id: %u), skip", guid, data.id, data.mapid); - continue; - } - - if (data.spawnMask & ~spawnMasks[data.mapid]) - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) that have wrong spawn mask %u including not supported difficulty modes for map (Id: %u), skip", guid, data.id, data.spawnMask, data.mapid); - - if (data.spawntimesecs == 0 && gInfo->IsDespawnAtAction()) - { - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with `spawntimesecs` (0) value, but gameobejct marked as despawnable at action.", guid, data.id); - } - - if (go_state >= MAX_GO_STATE) - { - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid `state` (%u) value, skip", guid, data.id, go_state); - continue; - } - data.go_state = GOState(go_state); - - if (data.rotation.x < -1.0f || data.rotation.x > 1.0f) - { - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.x (%f) value, skip", guid, data.id, data.rotation.x); - continue; - } - - if (data.rotation.y < -1.0f || data.rotation.y > 1.0f) - { - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.y (%f) value, skip", guid, data.id, data.rotation.y); - continue; - } - - if (data.rotation.z < -1.0f || data.rotation.z > 1.0f) - { - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.z (%f) value, skip", guid, data.id, data.rotation.z); - continue; - } - - if (data.rotation.w < -1.0f || data.rotation.w > 1.0f) - { - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.w (%f) value, skip", guid, data.id, data.rotation.w); - continue; - } - - if (!MapManager::IsValidMapCoord(data.mapid, data.posX, data.posY, data.posZ, data.orientation)) - { - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid coordinates, skip", guid, data.id); - continue; - } - - if (data.phaseMask == 0) - { - sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with `phaseMask`=0 (not visible for anyone), set to 1.", guid, data.id); - data.phaseMask = 1; - } - - if (gameEvent==0 && GuidPoolId==0 && EntryPoolId==0)// if not this is to be managed by GameEvent System or Pool system - AddGameobjectToGrid(guid, &data); - - ++count; + guid_last = LoadGameObject(fields, spawnMasks, guid, entry, guid_last); } while (result->NextRow()); diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index af16dbb..2707011 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -658,6 +658,7 @@ class ObjectMgr void LoadCreatureModelRace(); void LoadEquipmentTemplates(); void LoadGameObjectLocales(); + uint32 LoadGameObject(Field *fields, std::map spawnMasks, uint32 guid, uint32 entry, uint32 guid_last); void LoadGameObjects(); void LoadGameObjectAddon(); void LoadItemPrototypes();