[10909] Code style cleanups in scripting related functions

This commit is contained in:
zergtmn 2010-12-23 18:59:43 +05:00
parent a84d67a389
commit a1e0111638
5 changed files with 89 additions and 82 deletions

View file

@ -336,7 +336,7 @@ class MANGOS_DLL_SPEC InstanceMap : public Map
void Update(const uint32&); void Update(const uint32&);
void CreateInstanceData(bool load); void CreateInstanceData(bool load);
bool Reset(InstanceResetMethod method); bool Reset(InstanceResetMethod method);
uint32 GetScriptId() { return i_script_id; } uint32 GetScriptId() const { return i_script_id; }
InstanceData* GetInstanceData() { return i_data; } InstanceData* GetInstanceData() { return i_data; }
void PermBindAllPlayers(Player *player); void PermBindAllPlayers(Player *player);
void UnloadAll(bool pForce); void UnloadAll(bool pForce);

View file

@ -4641,7 +4641,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
} }
} }
// if(!GetMangosStringLocale(tmp.dataint)) will checked after db_script_string loading // if (!GetMangosStringLocale(tmp.dataint)) will be checked after db_script_string loading
break; break;
} }
case SCRIPT_COMMAND_EMOTE: case SCRIPT_COMMAND_EMOTE:
@ -4992,7 +4992,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
ScriptMap emptyMap; ScriptMap emptyMap;
scripts[tmp.id] = emptyMap; scripts[tmp.id] = emptyMap;
} }
scripts[tmp.id].insert(std::pair<uint32, ScriptInfo>(tmp.delay, tmp)); scripts[tmp.id].insert(ScriptMap::value_type(tmp.delay, tmp));
++count; ++count;
} while(result->NextRow()); } while(result->NextRow());
@ -5670,7 +5670,7 @@ void ObjectMgr::LoadTavernAreaTriggers()
void ObjectMgr::LoadAreaTriggerScripts() void ObjectMgr::LoadAreaTriggerScripts()
{ {
mAreaTriggerScripts.clear(); // need for reload case m_AreaTriggerScripts.clear(); // need for reload case
QueryResult *result = WorldDatabase.Query("SELECT entry, ScriptName FROM scripted_areatrigger"); QueryResult *result = WorldDatabase.Query("SELECT entry, ScriptName FROM scripted_areatrigger");
uint32 count = 0; uint32 count = 0;
@ -5694,17 +5694,16 @@ void ObjectMgr::LoadAreaTriggerScripts()
Field *fields = result->Fetch(); Field *fields = result->Fetch();
uint32 Trigger_ID = fields[0].GetUInt32(); uint32 triggerId = fields[0].GetUInt32();
const char *scriptName = fields[1].GetString(); const char *scriptName = fields[1].GetString();
AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); if (!sAreaTriggerStore.LookupEntry(triggerId))
if (!atEntry)
{ {
sLog.outErrorDb("Table `scripted_areatrigger` has area trigger (ID:%u) not listed in `AreaTrigger.dbc`.", Trigger_ID); sLog.outErrorDb("Table `scripted_areatrigger` has area trigger (ID: %u) not listed in `AreaTrigger.dbc`.", triggerId);
continue; continue;
} }
mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName); m_AreaTriggerScripts[triggerId] = GetScriptId(scriptName);
} while(result->NextRow()); } while(result->NextRow());
delete result; delete result;
@ -5715,7 +5714,7 @@ void ObjectMgr::LoadAreaTriggerScripts()
void ObjectMgr::LoadEventIdScripts() void ObjectMgr::LoadEventIdScripts()
{ {
mEventIdScripts.clear(); // need for reload case m_EventIdScripts.clear(); // need for reload case
QueryResult *result = WorldDatabase.Query("SELECT id, ScriptName FROM scripted_event_id"); QueryResult *result = WorldDatabase.Query("SELECT id, ScriptName FROM scripted_event_id");
uint32 count = 0; uint32 count = 0;
@ -5788,7 +5787,7 @@ void ObjectMgr::LoadEventIdScripts()
sLog.outErrorDb("Table `scripted_event_id` has id %u not referring to any gameobject_template type 10 data2 field, type 3 data6 field, type 13 data 2 field or any spell effect %u or path taxi node data", sLog.outErrorDb("Table `scripted_event_id` has id %u not referring to any gameobject_template type 10 data2 field, type 3 data6 field, type 13 data 2 field or any spell effect %u or path taxi node data",
eventId, SPELL_EFFECT_SEND_EVENT); eventId, SPELL_EFFECT_SEND_EVENT);
mEventIdScripts[eventId] = GetScriptId(scriptName); m_EventIdScripts[eventId] = GetScriptId(scriptName);
} while(result->NextRow()); } while(result->NextRow());
delete result; delete result;
@ -8216,19 +8215,20 @@ bool ObjectMgr::CheckDeclinedNames( std::wstring mainpart, DeclinedName const& n
return true; return true;
} }
uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id) uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 triggerId) const
{ {
AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(trigger_id); AreaTriggerScriptMap::const_iterator itr = m_AreaTriggerScripts.find(triggerId);
if(i!= mAreaTriggerScripts.end()) if (itr != m_AreaTriggerScripts.end())
return i->second; return itr->second;
return 0; return 0;
} }
uint32 ObjectMgr::GetEventIdScriptId(uint32 eventId) uint32 ObjectMgr::GetEventIdScriptId(uint32 eventId) const
{ {
EventIdScriptMap::const_iterator i = mEventIdScripts.find(eventId); EventIdScriptMap::const_iterator itr = m_EventIdScripts.find(eventId);
if (i!= mEventIdScripts.end()) if (itr != m_EventIdScripts.end())
return i->second; return itr->second;
return 0; return 0;
} }
@ -9605,14 +9605,19 @@ void ObjectMgr::LoadScriptNames()
sLog.outString( ">> Loaded %d Script Names", count ); sLog.outString( ">> Loaded %d Script Names", count );
} }
uint32 ObjectMgr::GetScriptId(const char *name) uint32 ObjectMgr::GetScriptId(const char *name) const
{ {
// use binary search to find the script name in the sorted vector // use binary search to find the script name in the sorted vector
// assume "" is the first element // assume "" is the first element
if(!name) return 0; if (!name)
return 0;
ScriptNameMap::const_iterator itr = ScriptNameMap::const_iterator itr =
std::lower_bound(m_scriptNames.begin(), m_scriptNames.end(), name); std::lower_bound(m_scriptNames.begin(), m_scriptNames.end(), name);
if(itr == m_scriptNames.end() || *itr != name) return 0;
if (itr == m_scriptNames.end() || *itr != name)
return 0;
return uint32(itr - m_scriptNames.begin()); return uint32(itr - m_scriptNames.begin());
} }
@ -9692,9 +9697,9 @@ void ObjectMgr::RemoveArenaTeam( uint32 Id )
} }
// Functions for scripting access // Functions for scripting access
uint32 GetAreaTriggerScriptId(uint32 trigger_id) uint32 GetAreaTriggerScriptId(uint32 triggerId)
{ {
return sObjectMgr.GetAreaTriggerScriptId(trigger_id); return sObjectMgr.GetAreaTriggerScriptId(triggerId);
} }
uint32 GetEventIdScriptId(uint32 eventId) uint32 GetEventIdScriptId(uint32 eventId)
@ -9720,7 +9725,7 @@ uint32 MANGOS_DLL_SPEC GetScriptId(const char *name)
return sObjectMgr.GetScriptId(name); return sObjectMgr.GetScriptId(name);
} }
ObjectMgr::ScriptNameMap & GetScriptNames() ObjectMgr::ScriptNameMap const& GetScriptNames()
{ {
return sObjectMgr.GetScriptNames(); return sObjectMgr.GetScriptNames();
} }

View file

@ -839,8 +839,8 @@ class ObjectMgr
AreaTrigger const* GetGoBackTrigger(uint32 Map) const; AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const; AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
uint32 GetAreaTriggerScriptId(uint32 trigger_id); uint32 GetAreaTriggerScriptId(uint32 triggerId) const;
uint32 GetEventIdScriptId(uint32 eventId); uint32 GetEventIdScriptId(uint32 eventId) const;
RepRewardRate const* GetRepRewardRate(uint32 factionId) const RepRewardRate const* GetRepRewardRate(uint32 factionId) const
{ {
@ -1242,9 +1242,9 @@ class ObjectMgr
bool IsVendorItemValid(bool isTemplate, char const* tableName, uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL) const; bool IsVendorItemValid(bool isTemplate, char const* tableName, uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL) const;
void LoadScriptNames(); void LoadScriptNames();
ScriptNameMap &GetScriptNames() { return m_scriptNames; } ScriptNameMap const& GetScriptNames() const { return m_scriptNames; }
const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; } const char* GetScriptName(uint32 id) const { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
uint32 GetScriptId(const char *name); uint32 GetScriptId(const char *name) const;
int GetOrNewIndexForLocale(LocaleConstant loc); int GetOrNewIndexForLocale(LocaleConstant loc);
@ -1345,8 +1345,8 @@ class ObjectMgr
GossipTextMap mGossipText; GossipTextMap mGossipText;
AreaTriggerMap mAreaTriggers; AreaTriggerMap mAreaTriggers;
AreaTriggerScriptMap mAreaTriggerScripts; AreaTriggerScriptMap m_AreaTriggerScripts;
EventIdScriptMap mEventIdScripts; EventIdScriptMap m_EventIdScripts;
RepRewardRateMap m_RepRewardRateMap; RepRewardRateMap m_RepRewardRateMap;
RepOnKillMap mRepOnKill; RepOnKillMap mRepOnKill;
@ -1452,10 +1452,10 @@ class ObjectMgr
// scripting access functions // scripting access functions
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 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 triggerId);
MANGOS_DLL_SPEC uint32 GetEventIdScriptId(uint32 event_id); MANGOS_DLL_SPEC uint32 GetEventIdScriptId(uint32 eventId);
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 const& GetScriptNames();
MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry); MANGOS_DLL_SPEC CreatureInfo const* GetCreatureTemplateStore(uint32 entry);
MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry); MANGOS_DLL_SPEC Quest const* GetQuestTemplateStore(uint32 entry);

View file

@ -23,12 +23,14 @@
#include "ObjectMgr.h" #include "ObjectMgr.h"
#include "DBCEnums.h" #include "DBCEnums.h"
class Aura;
class Creature; class Creature;
class CreatureAI; class CreatureAI;
class GameObject; class GameObject;
class Item; class Item;
class Player; class Player;
class Quest; class Quest;
class Unit;
class SpellCastTargets; class SpellCastTargets;
class Map; class Map;
class InstanceData; class InstanceData;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10908" #define REVISION_NR "10909"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__