diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 4db0796b2..ef344fe87 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -345,24 +345,17 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 { case ACTION_T_TEXT: { - if (!action.text.TextId1) + if (!action.text.TextId[0]) return; int32 temp = 0; - if (action.text.TextId2 && action.text.TextId3) - { - switch( rand()%3 ) - { - case 0: temp = action.text.TextId1; break; - case 1: temp = action.text.TextId2; break; - case 2: temp = action.text.TextId3; break; - } - } - else if (action.text.TextId2 && urand(0,1)) - temp = action.text.TextId2; + if (action.text.TextId[1] && action.text.TextId[2]) + temp = action.text.TextId[rand()%3]; + else if (action.text.TextId[1] && urand(0,1)) + temp = action.text.TextId[1]; else - temp = action.text.TextId1; + temp = action.text.TextId[0]; if (temp) { diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index 603d88974..092ea1a67 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -185,9 +185,7 @@ struct CreatureEventAI_Action // ACTION_T_TEXT = 1 struct { - int32 TextId1; - int32 TextId2; - int32 TextId3; + int32 TextId[3]; } text; // ACTION_T_SET_FACTION = 2 struct @@ -534,7 +532,8 @@ struct CreatureEventAI_Event CreatureEventAI_Action action[MAX_ACTIONS]; }; //Event_Map -typedef UNORDERED_MAP > CreatureEventAI_Event_Map; +typedef std::vector CreatureEventAI_Event_Vec; +typedef UNORDERED_MAP CreatureEventAI_Event_Map; struct CreatureEventAI_Summon { diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp index 8a920be00..aa3e219ea 100644 --- a/src/game/CreatureEventAIMgr.cpp +++ b/src/game/CreatureEventAIMgr.cpp @@ -30,7 +30,7 @@ INSTANTIATE_SINGLETON_1(CreatureEventAIMgr); // ------------------- -void CreatureEventAIMgr::LoadCreatureEventAI_Texts() +void CreatureEventAIMgr::LoadCreatureEventAI_Texts(bool check_entry_use) { // Drop Existing Text Map, only done once and we are ready to add data from multiple sources. m_CreatureEventAI_TextMap.clear(); @@ -97,6 +97,9 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts() delete result; + if(check_entry_use) + CheckUnusedAITexts(); + sLog.outString(); sLog.outString(">> Loaded %u additional CreatureEventAI Texts data.", count); } @@ -107,11 +110,46 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts() sLog.outString(); sLog.outString(">> Loaded 0 additional CreatureEventAI Texts data. DB table `creature_ai_texts` is empty."); } +} +void CreatureEventAIMgr::CheckUnusedAITexts() +{ + std::set idx_set; + // check not used strings this is negative range + for(CreatureEventAI_TextMap::const_iterator itr = m_CreatureEventAI_TextMap.begin(); itr != m_CreatureEventAI_TextMap.end(); ++itr) + idx_set.insert(itr->first); + + for(CreatureEventAI_Event_Map::const_iterator itr = m_CreatureEventAI_Event_Map.begin(); itr != m_CreatureEventAI_Event_Map.end(); ++itr) + { + for(size_t i = 0; i < itr->second.size(); ++i) + { + CreatureEventAI_Event const& event = itr->second[i]; + + for(int j = 0; j < MAX_ACTIONS; ++j) + { + CreatureEventAI_Action const& action = event.action[j]; + switch(action.type) + { + case ACTION_T_TEXT: + { + for(int k = 0; k < 3; ++k) + if (action.text.TextId[k]) + idx_set.erase(action.text.TextId[k]); + break; + } + default: break; + } + + } + } + } + + for(std::set::const_iterator itr = idx_set.begin(); itr != idx_set.end(); ++itr) + sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` but not used in EventAI scripts.",*itr); } // ------------------- -void CreatureEventAIMgr::LoadCreatureEventAI_Summons() +void CreatureEventAIMgr::LoadCreatureEventAI_Summons(bool check_entry_use) { //Drop Existing EventSummon Map @@ -151,6 +189,9 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Summons() delete result; + if(check_entry_use) + CheckUnusedAISummons(); + sLog.outString(); sLog.outString(">> Loaded %u CreatureEventAI summon definitions", Count); }else @@ -160,7 +201,41 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Summons() sLog.outString(); sLog.outString(">> Loaded 0 CreatureEventAI Summon definitions. DB table `creature_ai_summons` is empty."); } +} +void CreatureEventAIMgr::CheckUnusedAISummons() +{ + std::set idx_set; + // check not used strings this is negative range + for(CreatureEventAI_Summon_Map::const_iterator itr = m_CreatureEventAI_Summon_Map.begin(); itr != m_CreatureEventAI_Summon_Map.end(); ++itr) + idx_set.insert(itr->first); + + for(CreatureEventAI_Event_Map::const_iterator itr = m_CreatureEventAI_Event_Map.begin(); itr != m_CreatureEventAI_Event_Map.end(); ++itr) + { + for(size_t i = 0; i < itr->second.size(); ++i) + { + CreatureEventAI_Event const& event = itr->second[i]; + + for(int j = 0; j < MAX_ACTIONS; ++j) + { + CreatureEventAI_Action const& action = event.action[j]; + switch(action.type) + { + case ACTION_T_SUMMON_ID: + { + if (action.summon_id.spawnId) + idx_set.erase(action.summon_id.spawnId); + break; + } + default: break; + } + + } + } + } + + for(std::set::const_iterator itr = idx_set.begin(); itr != idx_set.end(); ++itr) + sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_summons` but not used in EventAI scripts.",*itr); } // ------------------- @@ -421,26 +496,28 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() break; case ACTION_T_TEXT: { - if (action.text.TextId1 < 0) + bool not_set = false; + for(int k = 0; k < 3; ++k) { - if (m_CreatureEventAI_TextMap.find(action.text.TextId1) == m_CreatureEventAI_TextMap.end()) - sLog.outErrorDb("CreatureEventAI: Event %u Action %u param1 refrences non-existing entry in texts table.", i, j+1); - } - if (action.text.TextId2 < 0) - { - if (m_CreatureEventAI_TextMap.find(action.text.TextId2) == m_CreatureEventAI_TextMap.end()) - sLog.outErrorDb("CreatureEventAI: Event %u Action %u param2 refrences non-existing entry in texts table.", i, j+1); + if (action.text.TextId[k]) + { + if (k > 0 && not_set) + sLog.outErrorDb("CreatureEventAI: Event %u Action %u has param%d, but it follow after not set param. Required for randomized text.", i, j+1, k+1); - if (!action.text.TextId1) - sLog.outErrorDb("CreatureEventAI: Event %u Action %u has param2, but param1 is not set. Required for randomized text.", i, j+1); - } - if (action.text.TextId3 < 0) - { - if (m_CreatureEventAI_TextMap.find(action.text.TextId3) == m_CreatureEventAI_TextMap.end()) - sLog.outErrorDb("CreatureEventAI: Event %u Action %u param3 refrences non-existing entry in texts table.", i, j+1); - - if (!action.text.TextId1 || !action.text.TextId2) - sLog.outErrorDb("CreatureEventAI: Event %u Action %u has param3, but param1 and/or param2 is not set. Required for randomized text.", i, j+1); + if(!action.text.TextId[k]) + not_set = true; + // range negative + else if(action.text.TextId[k] > MIN_CREATURE_AI_TEXT_STRING_ID || action.text.TextId[k] <= MAX_CREATURE_AI_TEXT_STRING_ID) + { + sLog.outErrorDb("CreatureEventAI: Event %u Action %u param%d references out-of-range entry (%i) in texts table.", i, j+1, k+1, action.text.TextId[k]); + action.text.TextId[k] = 0; + } + else if (m_CreatureEventAI_TextMap.find(action.text.TextId[k]) == m_CreatureEventAI_TextMap.end()) + { + sLog.outErrorDb("CreatureEventAI: Event %u Action %u param%d references non-existing entry (%i) in texts table.", i, j+1, k+1, action.text.TextId[k]); + action.text.TextId[k] = 0; + } + } } break; } @@ -700,6 +777,9 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() delete result; + CheckUnusedAITexts(); + CheckUnusedAISummons(); + sLog.outString(); sLog.outString(">> Loaded %u CreatureEventAI scripts", Count); }else diff --git a/src/game/CreatureEventAIMgr.h b/src/game/CreatureEventAIMgr.h index b4672460c..1345774e6 100644 --- a/src/game/CreatureEventAIMgr.h +++ b/src/game/CreatureEventAIMgr.h @@ -28,8 +28,8 @@ class CreatureEventAIMgr CreatureEventAIMgr(){}; ~CreatureEventAIMgr(){}; - void LoadCreatureEventAI_Texts(); - void LoadCreatureEventAI_Summons(); + void LoadCreatureEventAI_Texts(bool check_entry_use); + void LoadCreatureEventAI_Summons(bool check_entry_use); void LoadCreatureEventAI_Scripts(); CreatureEventAI_Event_Map const& GetCreatureEventAIMap() const { return m_CreatureEventAI_Event_Map; } @@ -37,6 +37,9 @@ class CreatureEventAIMgr CreatureEventAI_TextMap const& GetCreatureEventAITextMap() const { return m_CreatureEventAI_TextMap; } private: + void CheckUnusedAITexts(); + void CheckUnusedAISummons(); + CreatureEventAI_Event_Map m_CreatureEventAI_Event_Map; CreatureEventAI_Summon_Map m_CreatureEventAI_Summon_Map; CreatureEventAI_TextMap m_CreatureEventAI_TextMap; diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index 35164c1b7..27abeb0eb 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -647,7 +647,7 @@ bool ChatHandler::HandleReloadEventAITextsCommand(const char* arg) { sLog.outString( "Re-Loading Texts from `creature_ai_texts`..."); - CreatureEAI_Mgr.LoadCreatureEventAI_Texts(); + CreatureEAI_Mgr.LoadCreatureEventAI_Texts(true); SendGlobalSysMessage("DB table `creature_ai_texts` reloaded."); return true; } @@ -655,7 +655,7 @@ bool ChatHandler::HandleReloadEventAITextsCommand(const char* arg) bool ChatHandler::HandleReloadEventAISummonsCommand(const char* arg) { sLog.outString( "Re-Loading Summons from `creature_ai_summons`..."); - CreatureEAI_Mgr.LoadCreatureEventAI_Summons(); + CreatureEAI_Mgr.LoadCreatureEventAI_Summons(true); SendGlobalSysMessage("DB table `creature_ai_summons` reloaded."); return true; } diff --git a/src/game/World.cpp b/src/game/World.cpp index b3260ddf4..fb5fb2cd1 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1426,10 +1426,10 @@ void World::SetInitialWorldSettings() objmgr.LoadDbScriptStrings(); sLog.outString( "Loading CreatureEventAI Texts..."); - CreatureEAI_Mgr.LoadCreatureEventAI_Texts(); + CreatureEAI_Mgr.LoadCreatureEventAI_Texts(false); // false, will checked in LoadCreatureEventAI_Scripts sLog.outString( "Loading CreatureEventAI Summons..."); - CreatureEAI_Mgr.LoadCreatureEventAI_Summons(); + CreatureEAI_Mgr.LoadCreatureEventAI_Summons(false); // false, will checked in LoadCreatureEventAI_Scripts sLog.outString( "Loading CreatureEventAI Scripts..."); CreatureEAI_Mgr.LoadCreatureEventAI_Scripts(); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index ec8060f5c..44f845580 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 "8604" + #define REVISION_NR "8605" #endif // __REVISION_NR_H__