aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI/SmartScripts
diff options
context:
space:
mode:
authorUjp8LfXBJ6wCPR <github@lillecarl.com>2020-02-29 13:22:51 +0100
committerGitHub <noreply@github.com>2020-02-29 13:22:51 +0100
commita933ba60151f478c7bae23dddbba315a448ffe3e (patch)
tree94692732da2de57d1804a67fe588b36ea5b25d3e /src/server/game/AI/SmartScripts
parentfb75a958f02695f166481033203869940d98b537 (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/SmartScripts')
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.cpp4
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp73
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.cpp23
3 files changed, 49 insertions, 51 deletions
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;