diff options
| author | ariel- <ariel-@users.noreply.github.com> | 2016-08-28 20:08:37 -0300 |
|---|---|---|
| committer | DDuarte <dnpd.dd@gmail.com> | 2016-08-29 01:38:39 +0100 |
| commit | 78041c643876fe8d1c63ee81295b3e2376092689 (patch) | |
| tree | ab2bd5de054136af6f0ad8dc46dcb254b445c88e /src/server/game/Globals/ObjectMgr.cpp | |
| parent | d2d5e5ee8883f03e4c87254d2233f391f582bd53 (diff) | |
Core/ObjectMgr: throw some consts and nullptr around
(cherry picked from commit 8727048af67f6e416f82b4c8498d9c072069371f)
Conflicts:
src/server/game/Globals/ObjectMgr.cpp
src/server/game/Globals/ObjectMgr.h
Diffstat (limited to 'src/server/game/Globals/ObjectMgr.cpp')
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 125 |
1 files changed, 63 insertions, 62 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 0beb43b591b..a8c83c13578 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -67,7 +67,7 @@ std::string GetScriptsTableNameByType(ScriptsType type) ScriptMapMap* GetScriptsMapByType(ScriptsType type) { - ScriptMapMap* res = NULL; + ScriptMapMap* res = nullptr; switch (type) { case SCRIPTS_SPELL: res = &sSpellScripts; break; @@ -197,7 +197,7 @@ LanguageDesc const* GetLanguageDescByID(uint32 lang) return &lang_description[i]; } - return NULL; + return nullptr; } bool SpellClickInfo::IsFitToRequirements(Unit const* clicker, Unit const* clickee) const @@ -206,7 +206,7 @@ bool SpellClickInfo::IsFitToRequirements(Unit const* clicker, Unit const* clicke if (!playerClicker) return true; - Unit const* summoner = NULL; + Unit const* summoner = nullptr; // Check summoners for party if (clickee->IsSummon()) summoner = clickee->ToTempSummon()->GetSummoner(); @@ -247,8 +247,9 @@ ObjectMgr::ObjectMgr(): DBCLocaleIndex(LOCALE_enUS) { for (uint8 i = 0; i < MAX_CLASSES; ++i) + for (uint8 j = 0; j < MAX_RACES; ++j) - _playerInfo[j][i] = NULL; + _playerInfo[j][i] = nullptr; } ObjectMgr* ObjectMgr::instance() @@ -791,7 +792,7 @@ void ObjectMgr::CheckCreatureTemplate(CreatureTemplate const* cInfo) TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has non-existing faction template (%u).", cInfo->Entry, cInfo->faction); // used later for scale - CreatureDisplayInfoEntry const* displayScaleEntry = NULL; + CreatureDisplayInfoEntry const* displayScaleEntry = nullptr; if (cInfo->Modelid1) { @@ -1172,41 +1173,41 @@ void ObjectMgr::LoadGameObjectAddons() TC_LOG_INFO("server.loading", ">> Loaded %u gameobject addons in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -GameObjectAddon const* ObjectMgr::GetGameObjectAddon(ObjectGuid::LowType lowguid) +GameObjectAddon const* ObjectMgr::GetGameObjectAddon(ObjectGuid::LowType lowguid) const { GameObjectAddonContainer::const_iterator itr = _gameObjectAddonStore.find(lowguid); if (itr != _gameObjectAddonStore.end()) return &(itr->second); - return NULL; + return nullptr; } -CreatureAddon const* ObjectMgr::GetCreatureAddon(ObjectGuid::LowType lowguid) +CreatureAddon const* ObjectMgr::GetCreatureAddon(ObjectGuid::LowType lowguid) const { CreatureAddonContainer::const_iterator itr = _creatureAddonStore.find(lowguid); if (itr != _creatureAddonStore.end()) return &(itr->second); - return NULL; + return nullptr; } -CreatureAddon const* ObjectMgr::GetCreatureTemplateAddon(uint32 entry) +CreatureAddon const* ObjectMgr::GetCreatureTemplateAddon(uint32 entry) const { CreatureTemplateAddonContainer::const_iterator itr = _creatureTemplateAddonStore.find(entry); if (itr != _creatureTemplateAddonStore.end()) return &(itr->second); - return NULL; + return nullptr; } -EquipmentInfo const* ObjectMgr::GetEquipmentInfo(uint32 entry, int8& id) +EquipmentInfo const* ObjectMgr::GetEquipmentInfo(uint32 entry, int8& id) const { EquipmentInfoContainer::const_iterator itr = _equipmentInfoStore.find(entry); if (itr == _equipmentInfoStore.end()) - return NULL; + return nullptr; if (itr->second.empty()) - return NULL; + return nullptr; if (id == -1) // select a random element { @@ -1222,7 +1223,7 @@ EquipmentInfo const* ObjectMgr::GetEquipmentInfo(uint32 entry, int8& id) return &itr2->second; } - return NULL; + return nullptr; } void ObjectMgr::LoadEquipmentTemplates() @@ -1302,16 +1303,16 @@ void ObjectMgr::LoadEquipmentTemplates() TC_LOG_INFO("server.loading", ">> Loaded %u equipment templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelId) +CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelId) const { CreatureModelContainer::const_iterator itr = _creatureModelStore.find(modelId); if (itr != _creatureModelStore.end()) return &(itr->second); - return NULL; + return nullptr; } -uint32 ObjectMgr::ChooseDisplayId(CreatureTemplate const* cinfo, CreatureData const* data /*= NULL*/) +uint32 ObjectMgr::ChooseDisplayId(CreatureTemplate const* cinfo, CreatureData const* data /*= nullptr*/) { // Load creature model (display id) if (data && data->displayid) @@ -1324,7 +1325,7 @@ uint32 ObjectMgr::ChooseDisplayId(CreatureTemplate const* cinfo, CreatureData co return cinfo->GetFirstInvisibleModel(); } -void ObjectMgr::ChooseCreatureFlags(CreatureTemplate const* cinfo, uint64& npcflag, uint32& unit_flags, uint32& dynamicflags, CreatureData const* data /*= NULL*/) +void ObjectMgr::ChooseCreatureFlags(const CreatureTemplate* cinfo, uint64& npcflag, uint32& unit_flags, uint32& dynamicflags, const CreatureData* data /*= nullptr*/) { npcflag = cinfo->npcflag; unit_flags = cinfo->unit_flags; @@ -1343,11 +1344,11 @@ void ObjectMgr::ChooseCreatureFlags(CreatureTemplate const* cinfo, uint64& npcfl } } -CreatureModelInfo const* ObjectMgr::GetCreatureModelRandomGender(uint32* displayID) +CreatureModelInfo const* ObjectMgr::GetCreatureModelRandomGender(uint32* displayID) const { CreatureModelInfo const* modelInfo = GetCreatureModelInfo(*displayID); if (!modelInfo) - return NULL; + return nullptr; // If a model for another gender exists, 50% chance to use it if (modelInfo->displayId_other_gender != 0 && urand(0, 1) == 0) @@ -2890,12 +2891,13 @@ void ObjectMgr::LoadItemScriptNames() TC_LOG_INFO("server.loading", ">> Loaded %u item script names in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -ItemTemplate const* ObjectMgr::GetItemTemplate(uint32 entry) + +ItemTemplate const* ObjectMgr::GetItemTemplate(uint32 entry) const { ItemTemplateContainer::const_iterator itr = _itemTemplateStore.find(entry); if (itr != _itemTemplateStore.end()) return &(itr->second); - return NULL; + return nullptr; } void ObjectMgr::LoadVehicleTemplateAccessories() @@ -3041,8 +3043,7 @@ void ObjectMgr::LoadPetLevelInfo() } PetLevelInfo*& pInfoMapEntry = _petInfoStore[creature_id]; - - if (pInfoMapEntry == NULL) + if (!pInfoMapEntry) pInfoMapEntry = new PetLevelInfo[sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)]; // data for level 1 stored in [0] array element, ... @@ -3094,7 +3095,7 @@ PetLevelInfo const* ObjectMgr::GetPetLevelInfo(uint32 creature_id, uint8 level) PetLevelInfoContainer::const_iterator itr = _petInfoStore.find(creature_id); if (itr == _petInfoStore.end()) - return NULL; + return nullptr; return &itr->second[level-1]; // data for level 1 stored in [0] array element, ... } @@ -3965,7 +3966,7 @@ void ObjectMgr::LoadQuests() for (QuestMap::iterator iter = _questTemplates.begin(); iter != _questTemplates.end(); ++iter) { // skip post-loading checks for disabled quests - if (DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, iter->first, NULL)) + if (DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, iter->first, nullptr)) continue; Quest* qinfo = iter->second; @@ -5282,7 +5283,7 @@ PageText const* ObjectMgr::GetPageText(uint32 pageEntry) if (itr != _pageTextStore.end()) return &(itr->second); - return NULL; + return nullptr; } void ObjectMgr::LoadPageTextLocales() @@ -5356,13 +5357,13 @@ void ObjectMgr::LoadInstanceTemplate() TC_LOG_INFO("server.loading", ">> Loaded %u instance templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -InstanceTemplate const* ObjectMgr::GetInstanceTemplate(uint32 mapID) +InstanceTemplate const* ObjectMgr::GetInstanceTemplate(uint32 mapID) const { InstanceTemplateContainer::const_iterator itr = _instanceTemplateStore.find(uint16(mapID)); if (itr != _instanceTemplateStore.end()) return &(itr->second); - return NULL; + return nullptr; } void ObjectMgr::LoadInstanceEncounters() @@ -5469,7 +5470,7 @@ NpcText const* ObjectMgr::GetNpcText(uint32 Text_ID) const NpcTextContainer::const_iterator itr = _npcTextStore.find(Text_ID); if (itr != _npcTextStore.end()) return &itr->second; - return NULL; + return nullptr; } void ObjectMgr::LoadNPCText() @@ -5538,7 +5539,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp) { uint32 oldMSTime = getMSTime(); - time_t curTime = time(NULL); + time_t curTime = time(nullptr); tm lt; localtime_r(&curTime, <); uint64 basetime(curTime); @@ -5593,7 +5594,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp) m->checked = fields[7].GetUInt8(); m->mailTemplateId = fields[8].GetInt16(); - Player* player = NULL; + Player* player = nullptr; if (serverUp) player = ObjectAccessor::FindConnectedPlayer(ObjectGuid::Create<HighGuid::Player>(m->receiver)); @@ -6021,7 +6022,7 @@ void ObjectMgr::LoadGraveyardZones() TC_LOG_INFO("server.loading", ">> Loaded %u graveyard-zone links in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -WorldSafeLocsEntry const* ObjectMgr::GetDefaultGraveYard(uint32 team) +WorldSafeLocsEntry const* ObjectMgr::GetDefaultGraveYard(uint32 team) const { enum DefaultGraveyard { @@ -6033,10 +6034,10 @@ WorldSafeLocsEntry const* ObjectMgr::GetDefaultGraveYard(uint32 team) return sWorldSafeLocsStore.LookupEntry(HORDE_GRAVEYARD); else if (team == ALLIANCE) return sWorldSafeLocsStore.LookupEntry(ALLIANCE_GRAVEYARD); - else return NULL; + else return nullptr; } -WorldSafeLocsEntry const* ObjectMgr::GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team) +WorldSafeLocsEntry const* ObjectMgr::GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team) const { // search for zone associated closest graveyard uint32 zoneId = sMapMgr->GetZoneId(MapId, x, y, z); @@ -6071,15 +6072,15 @@ WorldSafeLocsEntry const* ObjectMgr::GetClosestGraveYard(float x, float y, float // at corpse map bool foundNear = false; float distNear = 10000; - WorldSafeLocsEntry const* entryNear = NULL; + WorldSafeLocsEntry const* entryNear = nullptr; // at entrance map for corpse map bool foundEntr = false; float distEntr = 10000; - WorldSafeLocsEntry const* entryEntr = NULL; + WorldSafeLocsEntry const* entryEntr = nullptr; // some where other - WorldSafeLocsEntry const* entryFar = NULL; + WorldSafeLocsEntry const* entryFar = nullptr; MapEntry const* mapEntry = sMapStore.LookupEntry(MapId); @@ -6161,7 +6162,7 @@ WorldSafeLocsEntry const* ObjectMgr::GetClosestGraveYard(float x, float y, float return entryFar; } -GraveYardData const* ObjectMgr::FindGraveYardData(uint32 id, uint32 zoneId) +GraveYardData const* ObjectMgr::FindGraveYardData(uint32 id, uint32 zoneId) const { GraveYardMapBounds range = GraveYardStore.equal_range(zoneId); for (; range.first != range.second; ++range.first) @@ -6170,7 +6171,7 @@ GraveYardData const* ObjectMgr::FindGraveYardData(uint32 id, uint32 zoneId) if (data.safeLocId == id) return &data; } - return NULL; + return nullptr; } bool ObjectMgr::AddGraveYardLink(uint32 id, uint32 zoneId, uint32 team, bool persist /*= true*/) @@ -6420,14 +6421,14 @@ AreaTriggerStruct const* ObjectMgr::GetGoBackTrigger(uint32 Map) const uint32 parentId = 0; const MapEntry* mapEntry = sMapStore.LookupEntry(Map); if (!mapEntry || mapEntry->CorpseMapID < 0) - return NULL; + return nullptr; if (mapEntry->IsDungeon()) { const InstanceTemplate* iTemplate = sObjectMgr->GetInstanceTemplate(Map); if (!iTemplate) - return NULL; + return nullptr; parentId = iTemplate->Parent; useParentDbValue = true; @@ -6441,7 +6442,7 @@ AreaTriggerStruct const* ObjectMgr::GetGoBackTrigger(uint32 Map) const if (atEntry && atEntry->MapID == Map) return &itr->second; } - return NULL; + return nullptr; } /** @@ -6458,7 +6459,7 @@ AreaTriggerStruct const* ObjectMgr::GetMapEntranceTrigger(uint32 Map) const return &itr->second; } } - return NULL; + return nullptr; } void ObjectMgr::SetHighestGuids() @@ -7956,7 +7957,7 @@ bool ObjectMgr::CheckDeclinedNames(const std::wstring& w_ownname, DeclinedName c return (x || y); } -uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id) +uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id) const { AreaTriggerScriptContainer::const_iterator i = _areaTriggerScriptStore.find(trigger_id); if (i!= _areaTriggerScriptStore.end()) @@ -7970,7 +7971,7 @@ SpellScriptsBounds ObjectMgr::GetSpellScriptsBounds(uint32 spellId) } // this allows calculating base reputations to offline players, just by race and class -int32 ObjectMgr::GetBaseReputationOf(FactionEntry const* factionEntry, uint8 race, uint8 playerClass) +int32 ObjectMgr::GetBaseReputationOf(FactionEntry const* factionEntry, uint8 race, uint8 playerClass) const { if (!factionEntry) return 0; @@ -8073,18 +8074,18 @@ GameTele const* ObjectMgr::GetGameTele(const std::string& name) const // explicit name case std::wstring wname; if (!Utf8toWStr(name, wname)) - return NULL; + return nullptr; // converting string that we try to find to lower case wstrToLower(wname); // Alternative first GameTele what contains wnameLow as substring in case no GameTele location found - const GameTele* alt = NULL; + GameTele const* alt = nullptr; for (GameTeleContainer::const_iterator itr = _gameTeleStore.begin(); itr != _gameTeleStore.end(); ++itr) { if (itr->second.wnameLow == wname) return &itr->second; - else if (alt == NULL && itr->second.wnameLow.find(wname) != std::wstring::npos) + else if (!alt && itr->second.wnameLow.find(wname) != std::wstring::npos) alt = &itr->second; } @@ -8096,7 +8097,7 @@ GameTele const* ObjectMgr::GetGameTeleExactName(const std::string& name) const // explicit name case std::wstring wname; if (!Utf8toWStr(name, wname)) - return NULL; + return nullptr; // converting string that we try to find to lower case wstrToLower(wname); @@ -8107,7 +8108,7 @@ GameTele const* ObjectMgr::GetGameTeleExactName(const std::string& name) const return &itr->second; } - return NULL; + return nullptr; } bool ObjectMgr::AddGameTele(GameTele& tele) @@ -8370,7 +8371,7 @@ int ObjectMgr::LoadReferenceVendor(int32 vendor, int32 item, uint8 referenceType uint32 ExtendedCost = fields[3].GetUInt32(); uint8 type = fields[4].GetUInt8(); - if (!IsVendorItemValid(vendor, item_id, maxcount, incrtime, ExtendedCost, type, NULL, skip_vendors)) + if (!IsVendorItemValid(vendor, item_id, maxcount, incrtime, ExtendedCost, type, nullptr, skip_vendors)) continue; VendorItemData& vList = _cacheVendorItemStore[vendor]; @@ -8421,7 +8422,7 @@ void ObjectMgr::LoadVendors() uint32 ExtendedCost = fields[4].GetUInt32(); uint8 type = fields[5].GetUInt8(); - if (!IsVendorItemValid(entry, item_id, maxcount, incrtime, ExtendedCost, type, NULL, &skip_vendors)) + if (!IsVendorItemValid(entry, item_id, maxcount, incrtime, ExtendedCost, type, nullptr, &skip_vendors)) continue; VendorItemData& vList = _cacheVendorItemStore[entry]; @@ -9210,22 +9211,22 @@ void ObjectMgr::LoadAreaPhases() TC_LOG_INFO("server.loading", ">> Loaded %u phase areas in %u ms.", count, GetMSTimeDiffToNow(oldMSTime)); } -GameObjectTemplate const* ObjectMgr::GetGameObjectTemplate(uint32 entry) +GameObjectTemplate const* ObjectMgr::GetGameObjectTemplate(uint32 entry) const { GameObjectTemplateContainer::const_iterator itr = _gameObjectTemplateStore.find(entry); if (itr != _gameObjectTemplateStore.end()) return &(itr->second); - return NULL; + return nullptr; } -CreatureTemplate const* ObjectMgr::GetCreatureTemplate(uint32 entry) +CreatureTemplate const* ObjectMgr::GetCreatureTemplate(uint32 entry) const { CreatureTemplateContainer::const_iterator itr = _creatureTemplateStore.find(entry); if (itr != _creatureTemplateStore.end()) return &(itr->second); - return NULL; + return nullptr; } VehicleAccessoryList const* ObjectMgr::GetVehicleAccessoryList(Vehicle* veh) const @@ -9242,18 +9243,18 @@ VehicleAccessoryList const* ObjectMgr::GetVehicleAccessoryList(Vehicle* veh) con VehicleAccessoryTemplateContainer::const_iterator itr = _vehicleTemplateAccessoryStore.find(veh->GetCreatureEntry()); if (itr != _vehicleTemplateAccessoryStore.end()) return &itr->second; - return NULL; + return nullptr; } PlayerInfo const* ObjectMgr::GetPlayerInfo(uint32 race, uint32 class_) const { if (race >= MAX_RACES) - return NULL; + return nullptr; if (class_ >= MAX_CLASSES) - return NULL; + return nullptr; PlayerInfo const* info = _playerInfo[race][class_]; if (!info) - return NULL; + return nullptr; return info; } |
