diff options
| author | Ujp8LfXBJ6wCPR <github@lillecarl.com> | 2020-02-29 13:22:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-29 13:22:51 +0100 |
| commit | a933ba60151f478c7bae23dddbba315a448ffe3e (patch) | |
| tree | 94692732da2de57d1804a67fe588b36ea5b25d3e /src/server/game/AI | |
| parent | fb75a958f02695f166481033203869940d98b537 (diff) | |
Modernize codebase with Clang-Tidy range based loops (#24165)
Manual expansion of auto types into "typed types"
Diffstat (limited to 'src/server/game/AI')
| -rw-r--r-- | src/server/game/AI/CoreAI/PetAI.cpp | 8 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.cpp | 6 | ||||
| -rw-r--r-- | src/server/game/AI/PlayerAI/PlayerAI.cpp | 5 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 19 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 4 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.cpp | 73 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScriptMgr.cpp | 23 |
7 files changed, 67 insertions, 71 deletions
diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp index f53a4277c6e..efabd38edb0 100644 --- a/src/server/game/AI/CoreAI/PetAI.cpp +++ b/src/server/game/AI/CoreAI/PetAI.cpp @@ -169,9 +169,9 @@ void PetAI::UpdateAI(uint32 diff) // No enemy, check friendly if (!spellUsed) { - for (GuidSet::const_iterator tar = _allySet.begin(); tar != _allySet.end(); ++tar) + for (ObjectGuid target : _allySet) { - Unit* ally = ObjectAccessor::GetUnit(*me, *tar); + Unit* ally = ObjectAccessor::GetUnit(*me, target); //only buff targets that are in combat, unless the spell can only be cast while out of combat if (!ally) @@ -218,8 +218,8 @@ void PetAI::UpdateAI(uint32 diff) } // deleted cached Spell objects - for (TargetSpellList::const_iterator itr = targetSpellStore.begin(); itr != targetSpellStore.end(); ++itr) - delete itr->second; + for (std::pair<Unit*, Spell*> const& unitspellpair : targetSpellStore) + delete unitspellpair.second; } // Update speed as needed to prevent dropping too far behind and despawning diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp index d5ae31c07be..7bd37036d27 100644 --- a/src/server/game/AI/CoreAI/UnitAI.cpp +++ b/src/server/game/AI/CoreAI/UnitAI.cpp @@ -211,9 +211,9 @@ void UnitAI::FillAISpellInfo() UPDATE_TARGET(AITARGET_SELF) else { - for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j) + for (SpellEffectInfo const& Effect : spellInfo->Effects) { - uint32 targetType = spellInfo->Effects[j].TargetA.GetTarget(); + uint32 targetType = Effect.TargetA.GetTarget(); if (targetType == TARGET_UNIT_TARGET_ENEMY || targetType == TARGET_DEST_TARGET_ENEMY) @@ -221,7 +221,7 @@ void UnitAI::FillAISpellInfo() else if (targetType == TARGET_UNIT_DEST_AREA_ENEMY) UPDATE_TARGET(AITARGET_ENEMY) - if (spellInfo->Effects[j].Effect == SPELL_EFFECT_APPLY_AURA) + if (Effect.Effect == SPELL_EFFECT_APPLY_AURA) { if (targetType == TARGET_UNIT_TARGET_ENEMY) UPDATE_TARGET(AITARGET_DEBUFF) diff --git a/src/server/game/AI/PlayerAI/PlayerAI.cpp b/src/server/game/AI/PlayerAI/PlayerAI.cpp index 237a1a99d2a..2098bb8b462 100644 --- a/src/server/game/AI/PlayerAI/PlayerAI.cpp +++ b/src/server/game/AI/PlayerAI/PlayerAI.cpp @@ -1161,10 +1161,9 @@ void SimpleCharmedPlayerAI::UpdateAI(uint32 diff) // kill self if charm aura has infinite duration if (charmer->IsInEvadeMode()) { - Player::AuraEffectList const& auras = me->GetAuraEffectsByType(SPELL_AURA_MOD_CHARM); - for (Player::AuraEffectList::const_iterator iter = auras.begin(); iter != auras.end(); ++iter) + for (AuraEffect* aura : me->GetAuraEffectsByType(SPELL_AURA_MOD_CHARM)) { - if ((*iter)->GetCasterGUID() == charmer->GetGUID() && (*iter)->GetBase()->IsPermanent()) + if (aura->GetCasterGUID() == charmer->GetGUID() && aura->GetBase()->IsPermanent()) { me->KillSelf(); return; diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 9c9dfd8930b..65b805d246f 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -104,9 +104,9 @@ void SummonList::RemoveNotExisting() bool SummonList::HasEntry(uint32 entry) const { - for (StorageType::const_iterator i = _storage.begin(); i != _storage.end(); ++i) + for (ObjectGuid const& guid : _storage) { - Creature* summon = ObjectAccessor::GetCreature(*_me, *i); + Creature* summon = ObjectAccessor::GetCreature(*_me, guid); if (summon && summon->GetEntry() == entry) return true; } @@ -116,7 +116,7 @@ bool SummonList::HasEntry(uint32 entry) const void SummonList::DoActionImpl(int32 action, StorageType const& summons) { - for (auto const& guid : summons) + for (ObjectGuid const& guid : summons) { Creature* summon = ObjectAccessor::GetCreature(*_me, guid); if (summon && summon->IsAIEnabled()) @@ -317,9 +317,9 @@ SpellInfo const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mec SpellInfo const* tempSpell = nullptr; // Check if each spell is viable(set it to null if not) - for (uint32 i = 0; i < MAX_CREATURE_SPELLS; i++) + for (uint32 spell : me->m_spells) { - tempSpell = sSpellMgr->GetSpellInfo(me->m_spells[i]); + tempSpell = sSpellMgr->GetSpellInfo(spell); // This spell doesn't exist if (!tempSpell) @@ -327,11 +327,11 @@ SpellInfo const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mec // Targets and Effects checked first as most used restrictions // Check the spell targets if specified - if (targets && !(SpellSummary[me->m_spells[i]].Targets & (1 << (targets-1)))) + if (targets && !(SpellSummary[spell].Targets & (1 << (targets-1)))) continue; // Check the type of spell if we are looking for a specific spell type - if (effects && !(SpellSummary[me->m_spells[i]].Effects & (1 << (effects-1)))) + if (effects && !(SpellSummary[spell].Effects & (1 << (effects-1)))) continue; // Check for school if specified @@ -405,9 +405,8 @@ void ScriptedAI::DoTeleportAll(float x, float y, float z, float o) if (!map->IsDungeon()) return; - Map::PlayerList const& PlayerList = map->GetPlayers(); - for (Map::PlayerList::const_iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr) - if (Player* player = itr->GetSource()) + for (MapReference const& mapref : map->GetPlayers()) + if (Player* player = mapref.GetSource()) if (player->IsAlive()) player->TeleportTo(me->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT); } diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 840fabac43d..90236d81a8f 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -893,8 +893,8 @@ void SmartAI::CheckConditions(uint32 diff) { if (Vehicle* vehicleKit = me->GetVehicleKit()) { - for (SeatMap::iterator itr = vehicleKit->Seats.begin(); itr != vehicleKit->Seats.end(); ++itr) - if (Unit* passenger = ObjectAccessor::GetUnit(*me, itr->second.Passenger.Guid)) + for (std::pair<int8 const, VehicleSeat>& seat : vehicleKit->Seats) + if (Unit* passenger = ObjectAccessor::GetUnit(*me, seat.second.Passenger.Guid)) { if (Player* player = passenger->ToPlayer()) { diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 3a438004703..a337cc6397b 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -169,12 +169,12 @@ Creature* SmartScript::FindCreatureNear(WorldObject* searchObject, ObjectGuid::L void SmartScript::OnReset() { ResetBaseObject(); - for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i) + for (SmartScriptHolder& event : mEvents) { - if (!((*i).event.event_flags & SMART_EVENT_FLAG_DONT_RESET)) + if (!(event.event.event_flags & SMART_EVENT_FLAG_DONT_RESET)) { - InitTimer((*i)); - (*i).runOnce = false; + InitTimer(event); + event.runOnce = false; } } ProcessEventsFor(SMART_EVENT_RESET); @@ -214,15 +214,15 @@ void SmartScript::ResetBaseObject() void SmartScript::ProcessEventsFor(SMART_EVENT e, Unit* unit, uint32 var0, uint32 var1, bool bvar, SpellInfo const* spell, GameObject* gob) { - for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i) + for (SmartScriptHolder& event : mEvents) { - SMART_EVENT eventType = SMART_EVENT(i->GetEventType()); + SMART_EVENT eventType = SMART_EVENT(event.GetEventType()); if (eventType == SMART_EVENT_LINK)//special handling continue; if (eventType == e) - if (sConditionMgr->IsObjectMeetingSmartEventConditions(i->entryOrGuid, i->event_id, i->source_type, unit, GetBaseObject())) - ProcessEvent(*i, unit, var0, var1, bvar, spell, gob); + if (sConditionMgr->IsObjectMeetingSmartEventConditions(event.entryOrGuid, event.event_id, event.source_type, unit, GetBaseObject())) + ProcessEvent(event, unit, var0, var1, bvar, spell, gob); } } @@ -508,8 +508,8 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u // Special handling for vehicles if (IsUnit(target)) if (Vehicle* vehicle = target->ToUnit()->GetVehicleKit()) - for (SeatMap::iterator it = vehicle->Seats.begin(); it != vehicle->Seats.end(); ++it) - if (Player* player = ObjectAccessor::GetPlayer(*target, it->second.Passenger.Guid)) + for (std::pair<int8 const, VehicleSeat>& seat : vehicle->Seats) + if (Player* player = ObjectAccessor::GetPlayer(*target, seat.second.Passenger.Guid)) player->AreaExploredOrEventHappens(e.action.quest.quest); if (IsPlayer(target)) @@ -837,8 +837,8 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u // Special handling for vehicles if (Vehicle* vehicle = unit->GetVehicleKit()) - for (SeatMap::iterator it = vehicle->Seats.begin(); it != vehicle->Seats.end(); ++it) - if (Player* passenger = ObjectAccessor::GetPlayer(*unit, it->second.Passenger.Guid)) + for (std::pair<int8 const, VehicleSeat>& seat : vehicle->Seats) + if (Player* passenger = ObjectAccessor::GetPlayer(*unit, seat.second.Passenger.Guid)) passenger->GroupEventHappens(e.action.quest.quest, GetBaseObject()); break; } @@ -960,8 +960,8 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u } else if (IsUnit(target)) // Special handling for vehicles if (Vehicle* vehicle = target->ToUnit()->GetVehicleKit()) - for (SeatMap::iterator seatItr = vehicle->Seats.begin(); seatItr != vehicle->Seats.end(); ++seatItr) - if (Player* player = ObjectAccessor::GetPlayer(*target, seatItr->second.Passenger.Guid)) + for (std::pair<int8 const, VehicleSeat>& seat : vehicle->Seats) + if (Player* player = ObjectAccessor::GetPlayer(*target, seat.second.Passenger.Guid)) player->KilledMonsterCredit(e.action.killedMonster.creature); } } @@ -2067,9 +2067,8 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (!path || path->nodes.empty()) continue; - for (auto itr = path->nodes.begin(); itr != path->nodes.end(); ++itr) + for (WaypointNode const& waypoint : path->nodes) { - WaypointNode const waypoint = *itr; float distamceToThisNode = creature->GetDistance(waypoint.x, waypoint.y, waypoint.z); if (distamceToThisNode < distanceToClosest) { @@ -2811,9 +2810,9 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e, case SMART_TARGET_VEHICLE_PASSENGER: { if (me && me->IsVehicle()) - for (auto seatItr = me->GetVehicleKit()->Seats.begin(); seatItr != me->GetVehicleKit()->Seats.end(); ++seatItr) - if (!e.target.vehicle.seatMask || (e.target.vehicle.seatMask & (1 << seatItr->first))) - if (Unit* u = ObjectAccessor::GetUnit(*me, seatItr->second.Passenger.Guid)) + for (std::pair<int8 const, VehicleSeat>& seat : me->GetVehicleKit()->Seats) + if (!e.target.vehicle.seatMask || (e.target.vehicle.seatMask & (1 << seat.first))) + if (Unit* u = ObjectAccessor::GetUnit(*me, seat.second.Passenger.Guid)) targets.push_back(u); break; } @@ -3513,12 +3512,12 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff) invoker = ObjectAccessor::GetUnit(*me, mTimedActionListInvoker); ProcessEvent(e, invoker); e.enableTimed = false;//disable event if it is in an ActionList and was processed once - for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i) + for (SmartScriptHolder& scriptholder : mTimedActionList) { //find the first event which is not the current one and enable it - if (i->event_id > e.event_id) + if (scriptholder.event_id > e.event_id) { - i->enableTimed = true; + scriptholder.enableTimed = true; break; } } @@ -3542,8 +3541,8 @@ void SmartScript::InstallEvents() { if (!mInstallEvents.empty()) { - for (SmartAIEventList::iterator i = mInstallEvents.begin(); i != mInstallEvents.end(); ++i) - mEvents.push_back(*i);//must be before UpdateTimers + for (SmartScriptHolder& installevent : mInstallEvents) + mEvents.push_back(installevent);//must be before UpdateTimers mInstallEvents.clear(); } @@ -3612,8 +3611,8 @@ void SmartScript::OnUpdate(uint32 const diff) InstallEvents();//before UpdateTimers - for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i) - UpdateTimer(*i, diff); + for (SmartScriptHolder& mEvent : mEvents) + UpdateTimer(mEvent, diff); if (!mStoredEvents.empty()) { @@ -3629,11 +3628,11 @@ void SmartScript::OnUpdate(uint32 const diff) if (!mTimedActionList.empty()) { isProcessingTimedActionList = true; - for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i) + for (SmartScriptHolder& scriptholder : mTimedActionList) { - if ((*i).enableTimed) + if (scriptholder.enableTimed) { - UpdateTimer(*i, diff); + UpdateTimer(scriptholder, diff); needCleanup = false; } } @@ -3676,25 +3675,25 @@ void SmartScript::FillScript(SmartAIEventList e, WorldObject* obj, AreaTriggerEn TC_LOG_DEBUG("scripts.ai", "SmartScript: EventMap for AreaTrigger %u is empty but is using SmartScript.", at->id); return; } - for (SmartAIEventList::iterator i = e.begin(); i != e.end(); ++i) + for (SmartScriptHolder& scriptholder : e) { #ifndef TRINITY_DEBUG - if ((*i).event.event_flags & SMART_EVENT_FLAG_DEBUG_ONLY) + if (scriptholder.event.event_flags & SMART_EVENT_FLAG_DEBUG_ONLY) continue; #endif - if ((*i).event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_ALL)//if has instance flag add only if in it + if (scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_ALL)//if has instance flag add only if in it { if (obj && obj->GetMap()->IsDungeon()) { - if ((1 << (obj->GetMap()->GetSpawnMode()+1)) & (*i).event.event_flags) + if ((1 << (obj->GetMap()->GetSpawnMode()+1)) & scriptholder.event.event_flags) { - mEvents.push_back((*i)); + mEvents.push_back(scriptholder); } } continue; } - mEvents.push_back((*i));//NOTE: 'world(0)' events still get processed in ANY instance mode + mEvents.push_back(scriptholder);//NOTE: 'world(0)' events still get processed in ANY instance mode } } @@ -3756,8 +3755,8 @@ void SmartScript::OnInitialize(WorldObject* obj, AreaTriggerEntry const* at) GetScript();//load copy of script - for (SmartAIEventList::iterator i = mEvents.begin(); i != mEvents.end(); ++i) - InitTimer((*i));//calculate timers for first time use + for (SmartScriptHolder& event : mEvents) + InitTimer(event);//calculate timers for first time use ProcessEventsFor(SMART_EVENT_AI_INIT); InstallEvents(); diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp index 9ce7a61c89d..bf581b93a89 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp @@ -111,8 +111,8 @@ void SmartAIMgr::LoadSmartAIFromDB() uint32 oldMSTime = getMSTime(); - for (uint8 i = 0; i < SMART_SCRIPT_TYPE_MAX; i++) - mEventMap[i].clear(); //Drop Existing SmartAI List + for (SmartAIEventMap& eventmap : mEventMap) + eventmap.clear(); //Drop Existing SmartAI List PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_SMART_SCRIPTS); PreparedQueryResult result = WorldDatabase.Query(stmt); @@ -343,15 +343,15 @@ void SmartAIMgr::LoadSmartAIFromDB() while (result->NextRow()); // Post Loading Validation - for (uint8 i = 0; i < SMART_SCRIPT_TYPE_MAX; ++i) + for (SmartAIEventMap& eventmap : mEventMap) { - for (SmartAIEventMap::iterator itr = mEventMap[i].begin(); itr != mEventMap[i].end(); ++itr) + for (std::pair<int32 const, SmartAIEventList>& eventlistpair : eventmap) { - for (SmartScriptHolder const& e : itr->second) + for (SmartScriptHolder const& e : eventlistpair.second) { if (e.link) { - if (!FindLinkedEvent(itr->second, e.link)) + if (!FindLinkedEvent(eventlistpair.second, e.link)) { TC_LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: Entry %d SourceType %u, Event %u, Link Event %u not found or invalid.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.link); @@ -360,7 +360,7 @@ void SmartAIMgr::LoadSmartAIFromDB() if (e.GetEventType() == SMART_EVENT_LINK) { - if (!FindLinkedSourceEvent(itr->second, e.event_id)) + if (!FindLinkedSourceEvent(eventlistpair.second, e.event_id)) { TC_LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: Entry %d SourceType %u, Event %u, Link Source Event not found or invalid. Event will never trigger.", e.entryOrGuid, e.GetScriptType(), e.event_id); @@ -1168,14 +1168,13 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e) if (!IsSpellValid(e, e.action.cast.spell)) return false; - SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(e.action.cast.spell); - for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j) + for (SpellEffectInfo const& Effect : sSpellMgr->AssertSpellInfo(e.action.cast.spell)->Effects) { - if (spellInfo->Effects[j].IsEffect(SPELL_EFFECT_KILL_CREDIT) || spellInfo->Effects[j].IsEffect(SPELL_EFFECT_KILL_CREDIT2)) + if (Effect.IsEffect(SPELL_EFFECT_KILL_CREDIT) || Effect.IsEffect(SPELL_EFFECT_KILL_CREDIT2)) { - if (spellInfo->Effects[j].TargetA.GetTarget() == TARGET_UNIT_CASTER) + if (Effect.TargetA.GetTarget() == TARGET_UNIT_CASTER) TC_LOG_ERROR("sql.sql", "SmartAIMgr: Entry %d SourceType %u Event %u Action %u Effect: SPELL_EFFECT_KILL_CREDIT: (SpellId: %u targetA: %u - targetB: %u) has invalid target for this Action", - e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.action.cast.spell, spellInfo->Effects[j].TargetA.GetTarget(), spellInfo->Effects[j].TargetB.GetTarget()); + e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.action.cast.spell, Effect.TargetA.GetTarget(), Effect.TargetB.GetTarget()); } } break; |
