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 SPELL_RUN_AWAY 8225
|
||||
#define MAX_ACTIONS 3
|
||||
#define TEXT_SOURCE_RANGE -1000000 //the amount of entries each text source has available
|
||||
|
||||
enum EventAI_Type
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts()
|
|||
m_CreatureEventAI_TextMap.clear();
|
||||
|
||||
// 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
|
||||
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.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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6524,10 +6524,35 @@ void ObjectMgr::LoadGameObjectForQuests()
|
|||
|
||||
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
|
||||
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;
|
||||
++itr;
|
||||
|
|
@ -6569,11 +6594,9 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min
|
|||
sLog.outErrorDb("Table `%s` contain reserved entry 0, ignored.",table);
|
||||
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;
|
||||
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);
|
||||
sLog.outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table,entry,min_value,max_value);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -6612,7 +6635,7 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min
|
|||
delete result;
|
||||
|
||||
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);
|
||||
else
|
||||
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)
|
||||
{
|
||||
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());
|
||||
start_value = -1;
|
||||
end_value = 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);
|
||||
return false;
|
||||
}
|
||||
|
||||
// for scripting localized strings allowed use _only_ negative entries
|
||||
return objmgr.LoadMangosStrings(db,table,end_value,start_value);
|
||||
return objmgr.LoadMangosStrings(db,table,start_value,end_value);
|
||||
}
|
||||
|
||||
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
|
||||
#define MIN_MANGOS_STRING_ID 1
|
||||
#define MIN_MANGOS_STRING_ID 1 // 'mangos_string'
|
||||
#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 MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts'
|
||||
#define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000)
|
||||
|
||||
struct MangosStringLocale
|
||||
{
|
||||
|
|
@ -885,7 +887,7 @@ class ObjectMgr
|
|||
#define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
|
||||
|
||||
// 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 GetScriptId(const char *name);
|
||||
MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "7833"
|
||||
#define REVISION_NR "7834"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue