mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[7834] Mangos string loading code cleanups.
* Better integration creature event ai strings. * Not inclide in checks as expected max mangos strings range value to range
This commit is contained in:
parent
a1f4549862
commit
6aacc45ace
5 changed files with 57 additions and 31 deletions
|
|
@ -30,7 +30,6 @@ class WorldObject;
|
||||||
#define EVENT_UPDATE_TIME 500
|
#define EVENT_UPDATE_TIME 500
|
||||||
#define SPELL_RUN_AWAY 8225
|
#define SPELL_RUN_AWAY 8225
|
||||||
#define MAX_ACTIONS 3
|
#define MAX_ACTIONS 3
|
||||||
#define TEXT_SOURCE_RANGE -1000000 //the amount of entries each text source has available
|
|
||||||
|
|
||||||
enum EventAI_Type
|
enum EventAI_Type
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts()
|
||||||
m_CreatureEventAI_TextMap.clear();
|
m_CreatureEventAI_TextMap.clear();
|
||||||
|
|
||||||
// Load EventAI Text
|
// Load EventAI Text
|
||||||
LoadMangosStrings(WorldDatabase,"creature_ai_texts",-1,1+(TEXT_SOURCE_RANGE));
|
objmgr.LoadMangosStrings(WorldDatabase,"creature_ai_texts",MIN_CREATURE_AI_TEXT_STRING_ID,MAX_CREATURE_AI_TEXT_STRING_ID);
|
||||||
|
|
||||||
// Gather Additional data from EventAI Texts
|
// Gather Additional data from EventAI Texts
|
||||||
QueryResult *result = WorldDatabase.PQuery("SELECT entry, sound, type, language, emote FROM creature_ai_texts");
|
QueryResult *result = WorldDatabase.PQuery("SELECT entry, sound, type, language, emote FROM creature_ai_texts");
|
||||||
|
|
@ -59,15 +59,17 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts()
|
||||||
temp.Language = fields[3].GetInt32();
|
temp.Language = fields[3].GetInt32();
|
||||||
temp.Emote = fields[4].GetInt32();
|
temp.Emote = fields[4].GetInt32();
|
||||||
|
|
||||||
if (i >= 0)
|
// range negative
|
||||||
|
if (i > MIN_CREATURE_AI_TEXT_STRING_ID || i <= MAX_CREATURE_AI_TEXT_STRING_ID)
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` is not a negative value.",i);
|
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` is not in valid range(%d-%d)",i,MIN_CREATURE_AI_TEXT_STRING_ID,MAX_CREATURE_AI_TEXT_STRING_ID);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i <= TEXT_SOURCE_RANGE)
|
// range negative (don't must be happen, loaded from same table)
|
||||||
|
if (!objmgr.GetMangosStringLocale(i))
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` is out of accepted entry range for table.",i);
|
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` not found",i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6524,10 +6524,35 @@ void ObjectMgr::LoadGameObjectForQuests()
|
||||||
|
|
||||||
bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value)
|
bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value)
|
||||||
{
|
{
|
||||||
|
int32 start_value = min_value;
|
||||||
|
int32 end_value = max_value;
|
||||||
|
// some string can have negative indexes range
|
||||||
|
if (start_value < 0)
|
||||||
|
{
|
||||||
|
if (end_value >= start_value)
|
||||||
|
{
|
||||||
|
sLog.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.",table,min_value,max_value);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// real range (max+1,min+1) exaple: (-10,-1000) -> -999...-10+1
|
||||||
|
std::swap(start_value,end_value);
|
||||||
|
++start_value;
|
||||||
|
++end_value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (start_value >= end_value)
|
||||||
|
{
|
||||||
|
sLog.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.",table,min_value,max_value);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// cleanup affected map part for reloading case
|
// cleanup affected map part for reloading case
|
||||||
for(MangosStringLocaleMap::iterator itr = mMangosStringLocaleMap.begin(); itr != mMangosStringLocaleMap.end();)
|
for(MangosStringLocaleMap::iterator itr = mMangosStringLocaleMap.begin(); itr != mMangosStringLocaleMap.end();)
|
||||||
{
|
{
|
||||||
if(itr->first >= min_value && itr->first <= max_value)
|
if (itr->first >= start_value && itr->first < end_value)
|
||||||
{
|
{
|
||||||
MangosStringLocaleMap::iterator itr2 = itr;
|
MangosStringLocaleMap::iterator itr2 = itr;
|
||||||
++itr;
|
++itr;
|
||||||
|
|
@ -6539,14 +6564,14 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min
|
||||||
|
|
||||||
QueryResult *result = db.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 FROM %s",table);
|
QueryResult *result = db.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 FROM %s",table);
|
||||||
|
|
||||||
if(!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
barGoLink bar(1);
|
barGoLink bar(1);
|
||||||
|
|
||||||
bar.step();
|
bar.step();
|
||||||
|
|
||||||
sLog.outString();
|
sLog.outString();
|
||||||
if(min_value == MIN_MANGOS_STRING_ID) // error only in case internal strings
|
if (min_value == MIN_MANGOS_STRING_ID) // error only in case internal strings
|
||||||
sLog.outErrorDb(">> Loaded 0 mangos strings. DB table `%s` is empty. Cannot continue.",table);
|
sLog.outErrorDb(">> Loaded 0 mangos strings. DB table `%s` is empty. Cannot continue.",table);
|
||||||
else
|
else
|
||||||
sLog.outString(">> Loaded 0 string templates. DB table `%s` is empty.",table);
|
sLog.outString(">> Loaded 0 string templates. DB table `%s` is empty.",table);
|
||||||
|
|
@ -6564,22 +6589,20 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min
|
||||||
|
|
||||||
int32 entry = fields[0].GetInt32();
|
int32 entry = fields[0].GetInt32();
|
||||||
|
|
||||||
if(entry==0)
|
if (entry==0)
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Table `%s` contain reserved entry 0, ignored.",table);
|
sLog.outErrorDb("Table `%s` contain reserved entry 0, ignored.",table);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(entry < min_value || entry > max_value)
|
else if (entry < start_value || entry >= end_value)
|
||||||
{
|
{
|
||||||
int32 start = min_value > 0 ? min_value : max_value;
|
sLog.outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table,entry,min_value,max_value);
|
||||||
int32 end = min_value > 0 ? max_value : min_value;
|
|
||||||
sLog.outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table,entry,start,end);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
MangosStringLocale& data = mMangosStringLocaleMap[entry];
|
MangosStringLocale& data = mMangosStringLocaleMap[entry];
|
||||||
|
|
||||||
if(data.Content.size() > 0)
|
if (data.Content.size() > 0)
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Table `%s` contain data for already loaded entry %i (from another table?), ignored.",table,entry);
|
sLog.outErrorDb("Table `%s` contain data for already loaded entry %i (from another table?), ignored.",table,entry);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -6594,13 +6617,13 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min
|
||||||
for(int i = 1; i < MAX_LOCALE; ++i)
|
for(int i = 1; i < MAX_LOCALE; ++i)
|
||||||
{
|
{
|
||||||
std::string str = fields[i+1].GetCppString();
|
std::string str = fields[i+1].GetCppString();
|
||||||
if(!str.empty())
|
if (!str.empty())
|
||||||
{
|
{
|
||||||
int idx = GetOrNewIndexForLocale(LocaleConstant(i));
|
int idx = GetOrNewIndexForLocale(LocaleConstant(i));
|
||||||
if(idx >= 0)
|
if (idx >= 0)
|
||||||
{
|
{
|
||||||
// 0 -> default, idx in to idx+1
|
// 0 -> default, idx in to idx+1
|
||||||
if(data.Content.size() <= idx+1)
|
if (data.Content.size() <= idx+1)
|
||||||
data.Content.resize(idx+2);
|
data.Content.resize(idx+2);
|
||||||
|
|
||||||
data.Content[idx+1] = str;
|
data.Content[idx+1] = str;
|
||||||
|
|
@ -6612,7 +6635,7 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min
|
||||||
delete result;
|
delete result;
|
||||||
|
|
||||||
sLog.outString();
|
sLog.outString();
|
||||||
if(min_value == MIN_MANGOS_STRING_ID) // error only in case internal strings
|
if (min_value == MIN_MANGOS_STRING_ID)
|
||||||
sLog.outString( ">> Loaded %u MaNGOS strings from table %s", count,table);
|
sLog.outString( ">> Loaded %u MaNGOS strings from table %s", count,table);
|
||||||
else
|
else
|
||||||
sLog.outString( ">> Loaded %u string templates from %s", count,table);
|
sLog.outString( ">> Loaded %u string templates from %s", count,table);
|
||||||
|
|
@ -7550,15 +7573,15 @@ uint32 GetAreaTriggerScriptId(uint32 trigger_id)
|
||||||
|
|
||||||
bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value, int32 end_value)
|
bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value, int32 end_value)
|
||||||
{
|
{
|
||||||
if(start_value >= 0 || start_value <= end_value) // start/end reversed for negative values
|
// MAX_DB_SCRIPT_STRING_ID is max allowed negative value for scripts (scrpts can use only more deep negative values
|
||||||
|
// start/end reversed for negative values
|
||||||
|
if (start_value > MAX_DB_SCRIPT_STRING_ID || end_value >= start_value)
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), use (%d - %d) instead.",table,start_value,end_value,-1,std::numeric_limits<int32>::min());
|
sLog.outErrorDb("Table '%s' attempt loaded with reserved by mangos range (%d - %d), strings not loaded.",table,start_value,end_value+1);
|
||||||
start_value = -1;
|
return false;
|
||||||
end_value = std::numeric_limits<int32>::min();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for scripting localized strings allowed use _only_ negative entries
|
return objmgr.LoadMangosStrings(db,table,start_value,end_value);
|
||||||
return objmgr.LoadMangosStrings(db,table,end_value,start_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 MANGOS_DLL_SPEC GetScriptId(const char *name)
|
uint32 MANGOS_DLL_SPEC GetScriptId(const char *name)
|
||||||
|
|
|
||||||
|
|
@ -136,10 +136,12 @@ typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
|
||||||
|
|
||||||
|
|
||||||
// mangos string ranges
|
// mangos string ranges
|
||||||
#define MIN_MANGOS_STRING_ID 1
|
#define MIN_MANGOS_STRING_ID 1 // 'mangos_string'
|
||||||
#define MAX_MANGOS_STRING_ID 2000000000
|
#define MAX_MANGOS_STRING_ID 2000000000
|
||||||
#define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID
|
#define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID // 'db_script_string'
|
||||||
#define MAX_DB_SCRIPT_STRING_ID 2000010000
|
#define MAX_DB_SCRIPT_STRING_ID 2000010000
|
||||||
|
#define MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts'
|
||||||
|
#define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000)
|
||||||
|
|
||||||
struct MangosStringLocale
|
struct MangosStringLocale
|
||||||
{
|
{
|
||||||
|
|
@ -885,7 +887,7 @@ class ObjectMgr
|
||||||
#define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
|
#define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
|
||||||
|
|
||||||
// scripting access functions
|
// scripting access functions
|
||||||
MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min());
|
MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = MAX_CREATURE_AI_TEXT_STRING_ID, int32 end_value = std::numeric_limits<int32>::min());
|
||||||
MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
|
MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
|
||||||
MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
|
MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
|
||||||
MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
|
MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "7833"
|
#define REVISION_NR "7834"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue