mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 10:37:02 +00:00
[8605] Check unused text/summon data in EventAI scripts.
This commit is contained in:
parent
fe1560a483
commit
c5bda77fe2
7 changed files with 119 additions and 44 deletions
|
|
@ -345,24 +345,17 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
||||||
{
|
{
|
||||||
case ACTION_T_TEXT:
|
case ACTION_T_TEXT:
|
||||||
{
|
{
|
||||||
if (!action.text.TextId1)
|
if (!action.text.TextId[0])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 temp = 0;
|
int32 temp = 0;
|
||||||
|
|
||||||
if (action.text.TextId2 && action.text.TextId3)
|
if (action.text.TextId[1] && action.text.TextId[2])
|
||||||
{
|
temp = action.text.TextId[rand()%3];
|
||||||
switch( rand()%3 )
|
else if (action.text.TextId[1] && urand(0,1))
|
||||||
{
|
temp = action.text.TextId[1];
|
||||||
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;
|
|
||||||
else
|
else
|
||||||
temp = action.text.TextId1;
|
temp = action.text.TextId[0];
|
||||||
|
|
||||||
if (temp)
|
if (temp)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -185,9 +185,7 @@ struct CreatureEventAI_Action
|
||||||
// ACTION_T_TEXT = 1
|
// ACTION_T_TEXT = 1
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int32 TextId1;
|
int32 TextId[3];
|
||||||
int32 TextId2;
|
|
||||||
int32 TextId3;
|
|
||||||
} text;
|
} text;
|
||||||
// ACTION_T_SET_FACTION = 2
|
// ACTION_T_SET_FACTION = 2
|
||||||
struct
|
struct
|
||||||
|
|
@ -534,7 +532,8 @@ struct CreatureEventAI_Event
|
||||||
CreatureEventAI_Action action[MAX_ACTIONS];
|
CreatureEventAI_Action action[MAX_ACTIONS];
|
||||||
};
|
};
|
||||||
//Event_Map
|
//Event_Map
|
||||||
typedef UNORDERED_MAP<uint32, std::vector<CreatureEventAI_Event> > CreatureEventAI_Event_Map;
|
typedef std::vector<CreatureEventAI_Event> CreatureEventAI_Event_Vec;
|
||||||
|
typedef UNORDERED_MAP<uint32, CreatureEventAI_Event_Vec > CreatureEventAI_Event_Map;
|
||||||
|
|
||||||
struct CreatureEventAI_Summon
|
struct CreatureEventAI_Summon
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
INSTANTIATE_SINGLETON_1(CreatureEventAIMgr);
|
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.
|
// Drop Existing Text Map, only done once and we are ready to add data from multiple sources.
|
||||||
m_CreatureEventAI_TextMap.clear();
|
m_CreatureEventAI_TextMap.clear();
|
||||||
|
|
@ -97,6 +97,9 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts()
|
||||||
|
|
||||||
delete result;
|
delete result;
|
||||||
|
|
||||||
|
if(check_entry_use)
|
||||||
|
CheckUnusedAITexts();
|
||||||
|
|
||||||
sLog.outString();
|
sLog.outString();
|
||||||
sLog.outString(">> Loaded %u additional CreatureEventAI Texts data.", count);
|
sLog.outString(">> Loaded %u additional CreatureEventAI Texts data.", count);
|
||||||
}
|
}
|
||||||
|
|
@ -107,11 +110,46 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts()
|
||||||
sLog.outString();
|
sLog.outString();
|
||||||
sLog.outString(">> Loaded 0 additional CreatureEventAI Texts data. DB table `creature_ai_texts` is empty.");
|
sLog.outString(">> Loaded 0 additional CreatureEventAI Texts data. DB table `creature_ai_texts` is empty.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatureEventAIMgr::CheckUnusedAITexts()
|
||||||
|
{
|
||||||
|
std::set<int32> 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<int32>::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
|
//Drop Existing EventSummon Map
|
||||||
|
|
@ -151,6 +189,9 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Summons()
|
||||||
|
|
||||||
delete result;
|
delete result;
|
||||||
|
|
||||||
|
if(check_entry_use)
|
||||||
|
CheckUnusedAISummons();
|
||||||
|
|
||||||
sLog.outString();
|
sLog.outString();
|
||||||
sLog.outString(">> Loaded %u CreatureEventAI summon definitions", Count);
|
sLog.outString(">> Loaded %u CreatureEventAI summon definitions", Count);
|
||||||
}else
|
}else
|
||||||
|
|
@ -160,7 +201,41 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Summons()
|
||||||
sLog.outString();
|
sLog.outString();
|
||||||
sLog.outString(">> Loaded 0 CreatureEventAI Summon definitions. DB table `creature_ai_summons` is empty.");
|
sLog.outString(">> Loaded 0 CreatureEventAI Summon definitions. DB table `creature_ai_summons` is empty.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatureEventAIMgr::CheckUnusedAISummons()
|
||||||
|
{
|
||||||
|
std::set<int32> 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<int32>::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;
|
break;
|
||||||
case ACTION_T_TEXT:
|
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())
|
if (action.text.TextId[k])
|
||||||
sLog.outErrorDb("CreatureEventAI: Event %u Action %u param1 refrences non-existing entry in texts table.", i, j+1);
|
{
|
||||||
}
|
if (k > 0 && not_set)
|
||||||
if (action.text.TextId2 < 0)
|
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 (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.TextId1)
|
if(!action.text.TextId[k])
|
||||||
sLog.outErrorDb("CreatureEventAI: Event %u Action %u has param2, but param1 is not set. Required for randomized text.", i, j+1);
|
not_set = true;
|
||||||
}
|
// range negative
|
||||||
if (action.text.TextId3 < 0)
|
else if(action.text.TextId[k] > MIN_CREATURE_AI_TEXT_STRING_ID || action.text.TextId[k] <= MAX_CREATURE_AI_TEXT_STRING_ID)
|
||||||
{
|
{
|
||||||
if (m_CreatureEventAI_TextMap.find(action.text.TextId3) == m_CreatureEventAI_TextMap.end())
|
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]);
|
||||||
sLog.outErrorDb("CreatureEventAI: Event %u Action %u param3 refrences non-existing entry in texts table.", i, j+1);
|
action.text.TextId[k] = 0;
|
||||||
|
}
|
||||||
if (!action.text.TextId1 || !action.text.TextId2)
|
else if (m_CreatureEventAI_TextMap.find(action.text.TextId[k]) == m_CreatureEventAI_TextMap.end())
|
||||||
sLog.outErrorDb("CreatureEventAI: Event %u Action %u has param3, but param1 and/or param2 is not set. Required for randomized text.", i, j+1);
|
{
|
||||||
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -700,6 +777,9 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
|
||||||
|
|
||||||
delete result;
|
delete result;
|
||||||
|
|
||||||
|
CheckUnusedAITexts();
|
||||||
|
CheckUnusedAISummons();
|
||||||
|
|
||||||
sLog.outString();
|
sLog.outString();
|
||||||
sLog.outString(">> Loaded %u CreatureEventAI scripts", Count);
|
sLog.outString(">> Loaded %u CreatureEventAI scripts", Count);
|
||||||
}else
|
}else
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ class CreatureEventAIMgr
|
||||||
CreatureEventAIMgr(){};
|
CreatureEventAIMgr(){};
|
||||||
~CreatureEventAIMgr(){};
|
~CreatureEventAIMgr(){};
|
||||||
|
|
||||||
void LoadCreatureEventAI_Texts();
|
void LoadCreatureEventAI_Texts(bool check_entry_use);
|
||||||
void LoadCreatureEventAI_Summons();
|
void LoadCreatureEventAI_Summons(bool check_entry_use);
|
||||||
void LoadCreatureEventAI_Scripts();
|
void LoadCreatureEventAI_Scripts();
|
||||||
|
|
||||||
CreatureEventAI_Event_Map const& GetCreatureEventAIMap() const { return m_CreatureEventAI_Event_Map; }
|
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; }
|
CreatureEventAI_TextMap const& GetCreatureEventAITextMap() const { return m_CreatureEventAI_TextMap; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void CheckUnusedAITexts();
|
||||||
|
void CheckUnusedAISummons();
|
||||||
|
|
||||||
CreatureEventAI_Event_Map m_CreatureEventAI_Event_Map;
|
CreatureEventAI_Event_Map m_CreatureEventAI_Event_Map;
|
||||||
CreatureEventAI_Summon_Map m_CreatureEventAI_Summon_Map;
|
CreatureEventAI_Summon_Map m_CreatureEventAI_Summon_Map;
|
||||||
CreatureEventAI_TextMap m_CreatureEventAI_TextMap;
|
CreatureEventAI_TextMap m_CreatureEventAI_TextMap;
|
||||||
|
|
|
||||||
|
|
@ -647,7 +647,7 @@ bool ChatHandler::HandleReloadEventAITextsCommand(const char* arg)
|
||||||
{
|
{
|
||||||
|
|
||||||
sLog.outString( "Re-Loading Texts from `creature_ai_texts`...");
|
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.");
|
SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -655,7 +655,7 @@ bool ChatHandler::HandleReloadEventAITextsCommand(const char* arg)
|
||||||
bool ChatHandler::HandleReloadEventAISummonsCommand(const char* arg)
|
bool ChatHandler::HandleReloadEventAISummonsCommand(const char* arg)
|
||||||
{
|
{
|
||||||
sLog.outString( "Re-Loading Summons from `creature_ai_summons`...");
|
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.");
|
SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1426,10 +1426,10 @@ void World::SetInitialWorldSettings()
|
||||||
objmgr.LoadDbScriptStrings();
|
objmgr.LoadDbScriptStrings();
|
||||||
|
|
||||||
sLog.outString( "Loading CreatureEventAI Texts...");
|
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...");
|
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...");
|
sLog.outString( "Loading CreatureEventAI Scripts...");
|
||||||
CreatureEAI_Mgr.LoadCreatureEventAI_Scripts();
|
CreatureEAI_Mgr.LoadCreatureEventAI_Scripts();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "8604"
|
#define REVISION_NR "8605"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue