From cd507622065603800b276209889a0d30d6e69bb2 Mon Sep 17 00:00:00 2001 From: ApoC Date: Fri, 21 Nov 2008 12:38:15 +0100 Subject: [PATCH] [6841] Fixed texts loading for waypoints. Better reporting of unused script text, now it excludes from report also ids used for waypoints. Signed-off-by: ApoC --- src/game/ObjectMgr.cpp | 3 ++ src/game/WaypointManager.cpp | 68 ++++++++++++++++++++++++++---------- src/game/WaypointManager.h | 1 + src/shared/revision_nr.h | 2 +- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 900dea2b2..d5c3d27b9 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -42,6 +42,7 @@ #include "InstanceSaveMgr.h" #include "SpellAuras.h" #include "Util.h" +#include "WaypointManager.h" INSTANTIATE_SINGLETON_1(ObjectMgr); @@ -7281,6 +7282,8 @@ void ObjectMgr::LoadDbScriptStrings() CheckScripts(sGameObjectScripts,ids); CheckScripts(sEventScripts,ids); + WaypointMgr.CheckTextsExistance(ids); + for(std::set::const_iterator itr = ids.begin(); itr != ids.end(); ++itr) sLog.outErrorDb( "Table `db_script_string` has unused string id %u", *itr); } diff --git a/src/game/WaypointManager.cpp b/src/game/WaypointManager.cpp index 6b58a2234..7478f8efe 100644 --- a/src/game/WaypointManager.cpp +++ b/src/game/WaypointManager.cpp @@ -122,32 +122,18 @@ void WaypointManager::Load() be.emote = fields[7].GetUInt32(); be.spell = fields[8].GetUInt32(); - // load and store without holes in array - int j = 0; for(int i = 0; i < MAX_WAYPOINT_TEXT; ++i) { - be.textid[j] = fields[9+i].GetUInt32(); - if(be.textid[j]) + be.textid[i] = fields[9+i].GetUInt32(); + if(be.textid[i]) { - if (be.textid[j] < MIN_DB_SCRIPT_STRING_ID || be.textid[j] >= MAX_DB_SCRIPT_STRING_ID) + if (be.textid[i] < MIN_DB_SCRIPT_STRING_ID || be.textid[i] >= MAX_DB_SCRIPT_STRING_ID) { - sLog.outErrorDb( "Table `db_script_string` not have string id %u", be.textid[j]); + sLog.outErrorDb( "Table `db_script_string` not have string id %u", be.textid[i]); continue; } - - if (!objmgr.GetMangosStringLocale (be.textid[j])) - { - sLog.outErrorDb("ERROR: Waypoint path %d (point %d), have invalid text id (%i) in `textid%d, ignored.", - id, point, be.textid[j], i+1); - continue; - } - - ++j; // to next internal field } } - // fill array tail - for(; j < MAX_WAYPOINT_TEXT; ++j) - be.textid[j] = 0; // save memory by not storing empty behaviors if(!be.isEmpty()) @@ -306,3 +292,49 @@ void WaypointManager::SetNodeText(uint32 id, uint32 point, const char *text_fiel if(field == "model2") node.behavior->model2 = text ? atoi(text) : 0; } } + +void WaypointManager::CheckTextsExistance(std::set& ids) +{ + WaypointPathMap::iterator pmItr = m_pathMap.begin(); + for ( ; pmItr != m_pathMap.end(); ++pmItr) + { + for (int i = 0; i < pmItr->second.size(); ++i) + { + if (!pmItr->second[i].behavior) + continue; + + // Now we check text existence and put all zero texts ids to the end of array + + // Counting leading zeros for futher textid shift + int zeroCount = 0; + for (int j = 0; j < MAX_WAYPOINT_TEXT; ++j) + { + if (!pmItr->second[i].behavior->textid[j]) + { + ++zeroCount; + continue; + } + else + { + if (!objmgr.GetMangosStringLocale(pmItr->second[i].behavior->textid[j])) + { + sLog.outErrorDb("ERROR: Some waypoint has textid%u with not existing %u text.", j, pmItr->second[i].behavior->textid[j]); + pmItr->second[i].behavior->textid[j] = 0; + ++zeroCount; + continue; + } + else + ids.erase(pmItr->second[i].behavior->textid[j]); + + // Shifting check + if (zeroCount) + { + // Correct textid but some zeros leading, so move it forward. + pmItr->second[i].behavior->textid[j-zeroCount] = pmItr->second[i].behavior->textid[j]; + pmItr->second[i].behavior->textid[j] = 0; + } + } + } + } + } +} diff --git a/src/game/WaypointManager.h b/src/game/WaypointManager.h index 0a8307aac..939d7f2af 100644 --- a/src/game/WaypointManager.h +++ b/src/game/WaypointManager.h @@ -76,6 +76,7 @@ class WaypointManager void DeletePath(uint32 id); void SetNodePosition(uint32 id, uint32 point, float x, float y, float z); void SetNodeText(uint32 id, uint32 point, const char *text_field, const char *text); + void CheckTextsExistance(std::set& ids); private: void _addNode(uint32 id, uint32 point, float x, float y, float z, float o, uint32 delay, uint32 wpGuid); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index b39349b28..2dd1470a8 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "6840" + #define REVISION_NR "6841" #endif // __REVISION_NR_H__