diff --git a/src/game/Map.h b/src/game/Map.h index 3f1ee0f04..cfcaeb880 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -336,7 +336,7 @@ class MANGOS_DLL_SPEC InstanceMap : public Map void Update(const uint32&); void CreateInstanceData(bool load); bool Reset(InstanceResetMethod method); - uint32 GetScriptId() { return i_script_id; } + uint32 GetScriptId() const { return i_script_id; } InstanceData* GetInstanceData() { return i_data; } void PermBindAllPlayers(Player *player); void UnloadAll(bool pForce); diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 82846ffa8..58da1861c 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -4555,28 +4555,28 @@ void ObjectMgr::LoadQuestLocales() void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) { - if(sWorld.IsScriptScheduled()) // function don't must be called in time scripts use. + if (sWorld.IsScriptScheduled()) // function don't must be called in time scripts use. return; - sLog.outString( "%s :", tablename); + sLog.outString("%s :", tablename); scripts.clear(); // need for reload support - QueryResult *result = WorldDatabase.PQuery( "SELECT id, delay, command, datalong, datalong2, datalong3, datalong4, data_flags, dataint, dataint2, dataint3, dataint4, x, y, z, o FROM %s", tablename ); + QueryResult *result = WorldDatabase.PQuery("SELECT id, delay, command, datalong, datalong2, datalong3, datalong4, data_flags, dataint, dataint2, dataint3, dataint4, x, y, z, o FROM %s", tablename); uint32 count = 0; - if( !result ) + if (!result) { - barGoLink bar( 1 ); + barGoLink bar(1); bar.step(); sLog.outString(); - sLog.outString( ">> Loaded %u script definitions", count ); + sLog.outString(">> Loaded %u script definitions", count); return; } - barGoLink bar( (int)result->GetRowCount() ); + barGoLink bar((int)result->GetRowCount()); do { @@ -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; } case SCRIPT_COMMAND_EMOTE: @@ -4735,11 +4735,11 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) continue; } - if (info->type==GAMEOBJECT_TYPE_FISHINGNODE || - info->type==GAMEOBJECT_TYPE_FISHINGHOLE || - info->type==GAMEOBJECT_TYPE_DOOR || - info->type==GAMEOBJECT_TYPE_BUTTON || - info->type==GAMEOBJECT_TYPE_TRAP) + if (info->type == GAMEOBJECT_TYPE_FISHINGNODE || + info->type == GAMEOBJECT_TYPE_FISHINGHOLE || + info->type == GAMEOBJECT_TYPE_DOOR || + info->type == GAMEOBJECT_TYPE_BUTTON || + info->type == GAMEOBJECT_TYPE_TRAP) { sLog.outErrorDb("Table `%s` have gameobject type (%u) unsupported by command SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u", tablename, info->id, tmp.id); continue; @@ -4778,7 +4778,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) continue; } - if (info->type!=GAMEOBJECT_TYPE_DOOR) + if (info->type != GAMEOBJECT_TYPE_DOOR) { sLog.outErrorDb("Table `%s` has gameobject type (%u) non supported by command %s for script id %u", tablename, info->id, (tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"), tmp.id); continue; @@ -4992,50 +4992,50 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) ScriptMap emptyMap; scripts[tmp.id] = emptyMap; } - scripts[tmp.id].insert(std::pair(tmp.delay, tmp)); + scripts[tmp.id].insert(ScriptMap::value_type(tmp.delay, tmp)); ++count; - } while( result->NextRow() ); + } while(result->NextRow()); delete result; sLog.outString(); - sLog.outString( ">> Loaded %u script definitions", count ); + sLog.outString(">> Loaded %u script definitions", count); } void ObjectMgr::LoadGameObjectScripts() { - LoadScripts(sGameObjectScripts, "gameobject_scripts"); + LoadScripts(sGameObjectScripts, "gameobject_scripts"); // check ids for(ScriptMapMap::const_iterator itr = sGameObjectScripts.begin(); itr != sGameObjectScripts.end(); ++itr) { - if(!GetGOData(itr->first)) - sLog.outErrorDb("Table `gameobject_scripts` has not existing gameobject (GUID: %u) as script id",itr->first); + if (!GetGOData(itr->first)) + sLog.outErrorDb("Table `gameobject_scripts` has not existing gameobject (GUID: %u) as script id", itr->first); } } void ObjectMgr::LoadQuestEndScripts() { - LoadScripts(sQuestEndScripts, "quest_end_scripts"); + LoadScripts(sQuestEndScripts, "quest_end_scripts"); // check ids for(ScriptMapMap::const_iterator itr = sQuestEndScripts.begin(); itr != sQuestEndScripts.end(); ++itr) { - if(!GetQuestTemplate(itr->first)) - sLog.outErrorDb("Table `quest_end_scripts` has not existing quest (Id: %u) as script id",itr->first); + if (!GetQuestTemplate(itr->first)) + sLog.outErrorDb("Table `quest_end_scripts` has not existing quest (Id: %u) as script id", itr->first); } } void ObjectMgr::LoadQuestStartScripts() { - LoadScripts(sQuestStartScripts,"quest_start_scripts"); + LoadScripts(sQuestStartScripts, "quest_start_scripts"); // check ids for(ScriptMapMap::const_iterator itr = sQuestStartScripts.begin(); itr != sQuestStartScripts.end(); ++itr) { - if(!GetQuestTemplate(itr->first)) - sLog.outErrorDb("Table `quest_start_scripts` has not existing quest (Id: %u) as script id",itr->first); + if (!GetQuestTemplate(itr->first)) + sLog.outErrorDb("Table `quest_start_scripts` has not existing quest (Id: %u) as script id", itr->first); } } @@ -5048,9 +5048,9 @@ void ObjectMgr::LoadSpellScripts() { SpellEntry const* spellInfo = sSpellStore.LookupEntry(itr->first); - if(!spellInfo) + if (!spellInfo) { - sLog.outErrorDb("Table `spell_scripts` has not existing spell (Id: %u) as script id",itr->first); + sLog.outErrorDb("Table `spell_scripts` has not existing spell (Id: %u) as script id", itr->first); continue; } @@ -5070,7 +5070,7 @@ void ObjectMgr::LoadSpellScripts() } if (!found) - sLog.outErrorDb("Table `spell_scripts` has unsupported spell (Id: %u) without SPELL_EFFECT_SCRIPT_EFFECT (%u) spell effect",itr->first,SPELL_EFFECT_SCRIPT_EFFECT); + sLog.outErrorDb("Table `spell_scripts` has unsupported spell (Id: %u) without SPELL_EFFECT_SCRIPT_EFFECT (%u) spell effect", itr->first, SPELL_EFFECT_SCRIPT_EFFECT); } } @@ -5082,19 +5082,19 @@ void ObjectMgr::LoadEventScripts() // Load all possible script entries from gameobjects for(uint32 i = 1; i < sGOStorage.MaxEntry; ++i) - if (GameObjectInfo const * goInfo = sGOStorage.LookupEntry(i)) + if (GameObjectInfo const* goInfo = sGOStorage.LookupEntry(i)) if (uint32 eventId = goInfo->GetEventScriptId()) evt_scripts.insert(eventId); // Load all possible script entries from spells for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i) { - SpellEntry const * spell = sSpellStore.LookupEntry(i); + SpellEntry const* spell = sSpellStore.LookupEntry(i); if (spell) { for(int j = 0; j < MAX_EFFECT_INDEX; ++j) { - if( spell->Effect[j] == SPELL_EFFECT_SEND_EVENT ) + if (spell->Effect[j] == SPELL_EFFECT_SEND_EVENT) { if (spell->EffectMiscValue[j]) evt_scripts.insert(spell->EffectMiscValue[j]); @@ -5670,22 +5670,22 @@ void ObjectMgr::LoadTavernAreaTriggers() 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"); uint32 count = 0; if (!result) { - barGoLink bar( 1 ); + barGoLink bar(1); bar.step(); sLog.outString(); - sLog.outString( ">> Loaded %u scripted areatrigger", count ); + sLog.outString(">> Loaded %u scripted areatrigger", count); return; } - barGoLink bar( (int)result->GetRowCount() ); + barGoLink bar((int)result->GetRowCount()); do { @@ -5694,62 +5694,61 @@ void ObjectMgr::LoadAreaTriggerScripts() Field *fields = result->Fetch(); - uint32 Trigger_ID = fields[0].GetUInt32(); + uint32 triggerId = fields[0].GetUInt32(); const char *scriptName = fields[1].GetString(); - AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); - if (!atEntry) + if (!sAreaTriggerStore.LookupEntry(triggerId)) { - 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; } - mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName); - } while( result->NextRow() ); + m_AreaTriggerScripts[triggerId] = GetScriptId(scriptName); + } while(result->NextRow()); delete result; sLog.outString(); - sLog.outString( ">> Loaded %u areatrigger scripts", count ); + sLog.outString(">> Loaded %u areatrigger scripts", count); } 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"); uint32 count = 0; if (!result) { - barGoLink bar( 1 ); + barGoLink bar(1); bar.step(); sLog.outString(); - sLog.outString( ">> Loaded %u scripted event id", count ); + sLog.outString(">> Loaded %u scripted event id", count); return; } - barGoLink bar( (int)result->GetRowCount() ); + barGoLink bar((int)result->GetRowCount()); // TODO: remove duplicate code below, same way to collect event id's used in LoadEventScripts() std::set evt_scripts; // Load all possible event entries from gameobjects for(uint32 i = 1; i < sGOStorage.MaxEntry; ++i) - if (GameObjectInfo const * goInfo = sGOStorage.LookupEntry(i)) + if (GameObjectInfo const* goInfo = sGOStorage.LookupEntry(i)) if (uint32 eventId = goInfo->GetEventScriptId()) evt_scripts.insert(eventId); // Load all possible event entries from spells for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i) { - SpellEntry const * spell = sSpellStore.LookupEntry(i); + SpellEntry const* spell = sSpellStore.LookupEntry(i); if (spell) { for(int j = 0; j < MAX_EFFECT_INDEX; ++j) { - if( spell->Effect[j] == SPELL_EFFECT_SEND_EVENT ) + if (spell->Effect[j] == SPELL_EFFECT_SEND_EVENT) { if (spell->EffectMiscValue[j]) evt_scripts.insert(spell->EffectMiscValue[j]); @@ -5788,13 +5787,13 @@ 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", eventId, SPELL_EFFECT_SEND_EVENT); - mEventIdScripts[eventId] = GetScriptId(scriptName); - } while( result->NextRow() ); + m_EventIdScripts[eventId] = GetScriptId(scriptName); + } while(result->NextRow()); delete result; sLog.outString(); - sLog.outString( ">> Loaded %u scripted event id", count ); + sLog.outString(">> Loaded %u scripted event id", count); } uint32 ObjectMgr::GetNearestTaxiNode( float x, float y, float z, uint32 mapid, Team team ) @@ -8216,19 +8215,20 @@ bool ObjectMgr::CheckDeclinedNames( std::wstring mainpart, DeclinedName const& n return true; } -uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id) +uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 triggerId) const { - AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(trigger_id); - if(i!= mAreaTriggerScripts.end()) - return i->second; + AreaTriggerScriptMap::const_iterator itr = m_AreaTriggerScripts.find(triggerId); + if (itr != m_AreaTriggerScripts.end()) + return itr->second; + return 0; } -uint32 ObjectMgr::GetEventIdScriptId(uint32 eventId) +uint32 ObjectMgr::GetEventIdScriptId(uint32 eventId) const { - EventIdScriptMap::const_iterator i = mEventIdScripts.find(eventId); - if (i!= mEventIdScripts.end()) - return i->second; + EventIdScriptMap::const_iterator itr = m_EventIdScripts.find(eventId); + if (itr != m_EventIdScripts.end()) + return itr->second; return 0; } @@ -9580,16 +9580,16 @@ void ObjectMgr::LoadScriptNames() "UNION " "SELECT DISTINCT(ScriptName) FROM instance_template WHERE ScriptName <> ''"); - if( !result ) + if (!result) { - barGoLink bar( 1 ); + barGoLink bar(1); bar.step(); sLog.outString(); sLog.outErrorDb(">> Loaded empty set of Script Names!"); return; } - barGoLink bar( (int)result->GetRowCount() ); + barGoLink bar((int)result->GetRowCount()); uint32 count = 0; do @@ -9605,14 +9605,19 @@ void ObjectMgr::LoadScriptNames() 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 // assume "" is the first element - if(!name) return 0; + if (!name) + return 0; + ScriptNameMap::const_iterator itr = 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()); } @@ -9692,9 +9697,9 @@ void ObjectMgr::RemoveArenaTeam( uint32 Id ) } // 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) @@ -9720,7 +9725,7 @@ uint32 MANGOS_DLL_SPEC GetScriptId(const char *name) return sObjectMgr.GetScriptId(name); } -ObjectMgr::ScriptNameMap & GetScriptNames() +ObjectMgr::ScriptNameMap const& GetScriptNames() { return sObjectMgr.GetScriptNames(); } diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 3767c4876..2697a5de2 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -839,8 +839,8 @@ class ObjectMgr AreaTrigger const* GetGoBackTrigger(uint32 Map) const; AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const; - uint32 GetAreaTriggerScriptId(uint32 trigger_id); - uint32 GetEventIdScriptId(uint32 eventId); + uint32 GetAreaTriggerScriptId(uint32 triggerId) const; + uint32 GetEventIdScriptId(uint32 eventId) 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* skip_vendors = NULL) const; void LoadScriptNames(); - ScriptNameMap &GetScriptNames() { return m_scriptNames; } - const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; } - uint32 GetScriptId(const char *name); + ScriptNameMap const& GetScriptNames() const { return m_scriptNames; } + const char* GetScriptName(uint32 id) const { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; } + uint32 GetScriptId(const char *name) const; int GetOrNewIndexForLocale(LocaleConstant loc); @@ -1345,8 +1345,8 @@ class ObjectMgr GossipTextMap mGossipText; AreaTriggerMap mAreaTriggers; - AreaTriggerScriptMap mAreaTriggerScripts; - EventIdScriptMap mEventIdScripts; + AreaTriggerScriptMap m_AreaTriggerScripts; + EventIdScriptMap m_EventIdScripts; RepRewardRateMap m_RepRewardRateMap; RepOnKillMap mRepOnKill; @@ -1452,10 +1452,10 @@ class ObjectMgr // 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::min()); -MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id); -MANGOS_DLL_SPEC uint32 GetEventIdScriptId(uint32 event_id); +MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 triggerId); +MANGOS_DLL_SPEC uint32 GetEventIdScriptId(uint32 eventId); 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 Quest const* GetQuestTemplateStore(uint32 entry); diff --git a/src/game/ScriptCalls.h b/src/game/ScriptCalls.h index 6bd7c74ad..54c5536a0 100644 --- a/src/game/ScriptCalls.h +++ b/src/game/ScriptCalls.h @@ -23,12 +23,14 @@ #include "ObjectMgr.h" #include "DBCEnums.h" +class Aura; class Creature; class CreatureAI; class GameObject; class Item; class Player; class Quest; +class Unit; class SpellCastTargets; class Map; class InstanceData; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 5d21b85af..fe4a69e60 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 "10908" + #define REVISION_NR "10909" #endif // __REVISION_NR_H__