mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Modernize codebase with Clang-Tidy range based loops (#24165)
Manual expansion of auto types into "typed types"
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -566,8 +566,8 @@ bool AccountMgr::HasPermission(uint32 accountId, uint32 permissionId, uint32 rea
|
||||
|
||||
void AccountMgr::ClearRBAC()
|
||||
{
|
||||
for (rbac::RBACPermissionsContainer::iterator itr = _permissions.begin(); itr != _permissions.end(); ++itr)
|
||||
delete itr->second;
|
||||
for (std::pair<uint32 const, rbac::RBACPermission*>& permission : _permissions)
|
||||
delete permission.second;
|
||||
|
||||
_permissions.clear();
|
||||
_defaultPermissions.clear();
|
||||
|
||||
@@ -213,8 +213,8 @@ void RBACData::LoadFromDBCallback(PreparedQueryResult result)
|
||||
|
||||
// Add default permissions
|
||||
RBACPermissionContainer const& permissions = sAccountMgr->GetRBACDefaultPermissions(_secLevel);
|
||||
for (RBACPermissionContainer::const_iterator itr = permissions.begin(); itr != permissions.end(); ++itr)
|
||||
GrantPermission(*itr);
|
||||
for (uint32 permission : permissions)
|
||||
GrantPermission(permission);
|
||||
|
||||
// Force calculation of permissions
|
||||
CalculateNewPermissions();
|
||||
@@ -234,14 +234,14 @@ void RBACData::CalculateNewPermissions()
|
||||
|
||||
void RBACData::AddPermissions(RBACPermissionContainer const& permsFrom, RBACPermissionContainer& permsTo)
|
||||
{
|
||||
for (RBACPermissionContainer::const_iterator itr = permsFrom.begin(); itr != permsFrom.end(); ++itr)
|
||||
permsTo.insert(*itr);
|
||||
for (uint32 permission : permsFrom)
|
||||
permsTo.insert(permission);
|
||||
}
|
||||
|
||||
void RBACData::RemovePermissions(RBACPermissionContainer& permsFrom, RBACPermissionContainer const& permsToRemove)
|
||||
{
|
||||
for (RBACPermissionContainer::const_iterator itr = permsToRemove.begin(); itr != permsToRemove.end(); ++itr)
|
||||
permsFrom.erase(*itr);
|
||||
for (uint32 permission: permsToRemove)
|
||||
permsFrom.erase(permission);
|
||||
}
|
||||
|
||||
void RBACData::ExpandPermissions(RBACPermissionContainer& permissions)
|
||||
@@ -264,9 +264,9 @@ void RBACData::ExpandPermissions(RBACPermissionContainer& permissions)
|
||||
|
||||
// add all linked permissions (that are not already expanded) to the list of permissions to be checked
|
||||
RBACPermissionContainer const& linkedPerms = permission->GetLinkedPermissions();
|
||||
for (RBACPermissionContainer::const_iterator itr = linkedPerms.begin(); itr != linkedPerms.end(); ++itr)
|
||||
if (permissions.find(*itr) == permissions.end())
|
||||
toCheck.insert(*itr);
|
||||
for (uint32 linkedPerm : linkedPerms)
|
||||
if (permissions.find(linkedPerm) == permissions.end())
|
||||
toCheck.insert(linkedPerm);
|
||||
}
|
||||
|
||||
TC_LOG_DEBUG("rbac", "RBACData::ExpandPermissions: Expanded: %s", GetDebugPermissionString(permissions).c_str());
|
||||
|
||||
@@ -469,8 +469,8 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Wo
|
||||
|
||||
bool AchievementCriteriaDataSet::Meets(Player const* source, WorldObject const* target, uint32 miscvalue1 /*= 0*/, uint32 miscvalue2 /* = 0*/) const
|
||||
{
|
||||
for (Storage::const_iterator itr = storage.begin(); itr != storage.end(); ++itr)
|
||||
if (!itr->Meets(criteria_id, source, target, miscvalue1, miscvalue2))
|
||||
for (AchievementCriteriaData const& criteriadata : storage)
|
||||
if (!criteriadata.Meets(criteria_id, source, target, miscvalue1, miscvalue2))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -485,17 +485,17 @@ AchievementMgr::~AchievementMgr() { }
|
||||
|
||||
void AchievementMgr::Reset()
|
||||
{
|
||||
for (CompletedAchievementMap::const_iterator iter = m_completedAchievements.begin(); iter != m_completedAchievements.end(); ++iter)
|
||||
for (std::pair<uint32 const, CompletedAchievementData> const& completedAchievement : m_completedAchievements)
|
||||
{
|
||||
WorldPacket data(SMSG_ACHIEVEMENT_DELETED, 4);
|
||||
data << uint32(iter->first);
|
||||
data << uint32(completedAchievement.first);
|
||||
m_player->SendDirectMessage(&data);
|
||||
}
|
||||
|
||||
for (CriteriaProgressMap::const_iterator iter = m_criteriaProgress.begin(); iter != m_criteriaProgress.end(); ++iter)
|
||||
for (std::pair<uint32 const, CriteriaProgress> const& criteriaprogress : m_criteriaProgress)
|
||||
{
|
||||
WorldPacket data(SMSG_CRITERIA_DELETED, 4);
|
||||
data << uint32(iter->first);
|
||||
data << uint32(criteriaprogress.first);
|
||||
m_player->SendDirectMessage(&data);
|
||||
}
|
||||
|
||||
@@ -519,9 +519,8 @@ void AchievementMgr::ResetAchievementCriteria(AchievementCriteriaCondition condi
|
||||
if (!achievementCriteriaList)
|
||||
return;
|
||||
|
||||
for (auto itr = achievementCriteriaList->begin(); itr != achievementCriteriaList->end(); ++itr)
|
||||
for (AchievementCriteriaEntry const* achievementCriteria : *achievementCriteriaList)
|
||||
{
|
||||
AchievementCriteriaEntry const* achievementCriteria = *itr;
|
||||
AchievementEntry const* achievement = sAchievementMgr->GetAchievement(achievementCriteria->ReferredAchievement);
|
||||
if (!achievement)
|
||||
continue;
|
||||
@@ -553,49 +552,49 @@ void AchievementMgr::SaveToDB(SQLTransaction& trans)
|
||||
{
|
||||
if (!m_completedAchievements.empty())
|
||||
{
|
||||
for (CompletedAchievementMap::iterator iter = m_completedAchievements.begin(); iter != m_completedAchievements.end(); ++iter)
|
||||
for (std::pair<uint32 const, CompletedAchievementData>& completedAchievement : m_completedAchievements)
|
||||
{
|
||||
if (!iter->second.changed)
|
||||
if (!completedAchievement.second.changed)
|
||||
continue;
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_ACHIEVEMENT_BY_ACHIEVEMENT);
|
||||
stmt->setUInt16(0, iter->first);
|
||||
stmt->setUInt16(0, completedAchievement.first);
|
||||
stmt->setUInt32(1, GetPlayer()->GetGUID().GetCounter());
|
||||
trans->Append(stmt);
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_ACHIEVEMENT);
|
||||
stmt->setUInt32(0, GetPlayer()->GetGUID().GetCounter());
|
||||
stmt->setUInt16(1, iter->first);
|
||||
stmt->setUInt32(2, uint32(iter->second.date));
|
||||
stmt->setUInt16(1, completedAchievement.first);
|
||||
stmt->setUInt32(2, uint32(completedAchievement.second.date));
|
||||
trans->Append(stmt);
|
||||
|
||||
iter->second.changed = false;
|
||||
completedAchievement.second.changed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_criteriaProgress.empty())
|
||||
{
|
||||
for (CriteriaProgressMap::iterator iter = m_criteriaProgress.begin(); iter != m_criteriaProgress.end(); ++iter)
|
||||
for (std::pair<uint32 const, CriteriaProgress>& criteriaProgres : m_criteriaProgress)
|
||||
{
|
||||
if (!iter->second.changed)
|
||||
if (!criteriaProgres.second.changed)
|
||||
continue;
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_ACHIEVEMENT_PROGRESS_BY_CRITERIA);
|
||||
stmt->setUInt32(0, GetPlayer()->GetGUID().GetCounter());
|
||||
stmt->setUInt16(1, iter->first);
|
||||
stmt->setUInt16(1, criteriaProgres.first);
|
||||
trans->Append(stmt);
|
||||
|
||||
if (iter->second.counter)
|
||||
if (criteriaProgres.second.counter)
|
||||
{
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_ACHIEVEMENT_PROGRESS);
|
||||
stmt->setUInt32(0, GetPlayer()->GetGUID().GetCounter());
|
||||
stmt->setUInt16(1, iter->first);
|
||||
stmt->setUInt32(2, iter->second.counter);
|
||||
stmt->setUInt32(3, uint32(iter->second.date));
|
||||
stmt->setUInt16(1, criteriaProgres.first);
|
||||
stmt->setUInt32(2, criteriaProgres.second.counter);
|
||||
stmt->setUInt32(3, uint32(criteriaProgres.second.date));
|
||||
trans->Append(stmt);
|
||||
}
|
||||
|
||||
iter->second.changed = false;
|
||||
criteriaProgres.second.changed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -933,9 +932,9 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
|
||||
uint32 counter = 0;
|
||||
|
||||
RewardedQuestSet const& rewQuests = GetPlayer()->getRewardedQuests();
|
||||
for (RewardedQuestSet::const_iterator itr = rewQuests.begin(); itr != rewQuests.end(); ++itr)
|
||||
for (uint32 rewQuest : rewQuests)
|
||||
{
|
||||
Quest const* quest = sObjectMgr->GetQuestTemplate(*itr);
|
||||
Quest const* quest = sObjectMgr->GetQuestTemplate(rewQuest);
|
||||
if (quest && quest->GetZoneOrSort() >= 0 && uint32(quest->GetZoneOrSort()) == achievementCriteria->Asset.ZoneID)
|
||||
++counter;
|
||||
}
|
||||
@@ -993,11 +992,9 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
|
||||
case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS:
|
||||
{
|
||||
uint32 spellCount = 0;
|
||||
for (PlayerSpellMap::const_iterator spellIter = GetPlayer()->GetSpellMap().begin();
|
||||
spellIter != GetPlayer()->GetSpellMap().end();
|
||||
++spellIter)
|
||||
for (std::pair<uint32 const, PlayerSpell*>& spellIter : GetPlayer()->GetSpellMap())
|
||||
{
|
||||
SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellIter->first);
|
||||
SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellIter.first);
|
||||
for (SkillLineAbilityMap::const_iterator skillIter = bounds.first; skillIter != bounds.second; ++skillIter)
|
||||
{
|
||||
if (skillIter->second->skillId == achievementCriteria->Asset.SkillID)
|
||||
@@ -1023,18 +1020,18 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
|
||||
case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE:
|
||||
{
|
||||
uint32 spellCount = 0;
|
||||
for (PlayerSpellMap::const_iterator spellIter = GetPlayer()->GetSpellMap().begin();
|
||||
spellIter != GetPlayer()->GetSpellMap().end();
|
||||
++spellIter)
|
||||
for (std::pair<uint32 const, PlayerSpell*>& spellIter : GetPlayer()->GetSpellMap())
|
||||
{
|
||||
SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellIter->first);
|
||||
SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellIter.first);
|
||||
for (SkillLineAbilityMap::const_iterator skillIter = bounds.first; skillIter != bounds.second; ++skillIter)
|
||||
{
|
||||
if (skillIter->second->skillId == achievementCriteria->Asset.SkillID)
|
||||
{
|
||||
// do not add couter twice if by any chance skill is listed twice in dbc (eg. skill 777 and spell 22717)
|
||||
++spellCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
SetCriteriaProgress(achievementCriteria, spellCount);
|
||||
break;
|
||||
@@ -1049,8 +1046,8 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
|
||||
if (!miscValue1)
|
||||
{
|
||||
uint32 points = 0;
|
||||
for (CompletedAchievementMap::const_iterator itr = m_completedAchievements.begin(); itr != m_completedAchievements.end(); ++itr)
|
||||
if (AchievementEntry const* completedAchievements = sAchievementMgr->GetAchievement(itr->first))
|
||||
for (std::pair<uint32, CompletedAchievementData> const& completedAchievement : m_completedAchievements)
|
||||
if (AchievementEntry const* completedAchievements = sAchievementMgr->GetAchievement(completedAchievement.first))
|
||||
points += completedAchievements->Points;
|
||||
SetCriteriaProgress(achievementCriteria, points, PROGRESS_SET);
|
||||
}
|
||||
@@ -1144,9 +1141,9 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
|
||||
CompletedAchievement(achievement);
|
||||
|
||||
if (AchievementEntryList const* achRefList = sAchievementMgr->GetAchievementByReferencedId(achievement->ID))
|
||||
for (AchievementEntryList::const_iterator itr = achRefList->begin(); itr != achRefList->end(); ++itr)
|
||||
if (IsCompletedAchievement(*itr))
|
||||
CompletedAchievement(*itr);
|
||||
for (AchievementEntry const* achievement : *achRefList)
|
||||
if (IsCompletedAchievement(achievement))
|
||||
CompletedAchievement(achievement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1306,10 +1303,8 @@ bool AchievementMgr::IsCompletedAchievement(AchievementEntry const* entry)
|
||||
// Oddly, the target count is NOT countained in the achievement, but in each individual criteria
|
||||
if (entry->Flags & ACHIEVEMENT_FLAG_SUMM)
|
||||
{
|
||||
for (AchievementCriteriaEntryList::const_iterator itr = cList->begin(); itr != cList->end(); ++itr)
|
||||
for (AchievementCriteriaEntry const* criteria : *cList)
|
||||
{
|
||||
AchievementCriteriaEntry const* criteria = *itr;
|
||||
|
||||
CriteriaProgress const* progress = GetCriteriaProgress(criteria);
|
||||
if (!progress)
|
||||
continue;
|
||||
@@ -1325,10 +1320,8 @@ bool AchievementMgr::IsCompletedAchievement(AchievementEntry const* entry)
|
||||
|
||||
// Default case - need complete all or
|
||||
bool completed_all = true;
|
||||
for (AchievementCriteriaEntryList::const_iterator itr = cList->begin(); itr != cList->end(); ++itr)
|
||||
for (AchievementCriteriaEntry const* criteria : *cList)
|
||||
{
|
||||
AchievementCriteriaEntry const* criteria = *itr;
|
||||
|
||||
bool completed = IsCompletedCriteria(criteria, entry);
|
||||
|
||||
// found an uncompleted criteria, but DONT return false yet - there might be a completed criteria with ACHIEVEMENT_CRITERIA_COMPLETE_FLAG_ALL
|
||||
@@ -1467,22 +1460,21 @@ void AchievementMgr::UpdateTimedAchievements(uint32 timeDiff)
|
||||
|
||||
void AchievementMgr::StartTimedAchievement(AchievementCriteriaTimedTypes type, uint32 entry, uint32 timeLost /*= 0*/)
|
||||
{
|
||||
AchievementCriteriaEntryList const& achievementCriteriaList = sAchievementMgr->GetTimedAchievementCriteriaByType(type);
|
||||
for (AchievementCriteriaEntryList::const_iterator i = achievementCriteriaList.begin(); i != achievementCriteriaList.end(); ++i)
|
||||
for (AchievementCriteriaEntry const* criteria : sAchievementMgr->GetTimedAchievementCriteriaByType(type))
|
||||
{
|
||||
if ((*i)->StartAsset != entry)
|
||||
if (criteria->StartAsset != entry)
|
||||
continue;
|
||||
|
||||
AchievementEntry const* achievement = sAchievementMgr->GetAchievement((*i)->ReferredAchievement);
|
||||
if (m_timedAchievements.find((*i)->ID) == m_timedAchievements.end() && !IsCompletedCriteria(*i, achievement))
|
||||
AchievementEntry const* achievement = sAchievementMgr->GetAchievement(criteria->ReferredAchievement);
|
||||
if (m_timedAchievements.find(criteria->ID) == m_timedAchievements.end() && !IsCompletedCriteria(criteria, achievement))
|
||||
{
|
||||
// Start the timer
|
||||
if ((*i)->StartTimer * IN_MILLISECONDS > timeLost)
|
||||
if (criteria->StartTimer * IN_MILLISECONDS > timeLost)
|
||||
{
|
||||
m_timedAchievements[(*i)->ID] = (*i)->StartTimer * IN_MILLISECONDS - timeLost;
|
||||
m_timedAchievements[criteria->ID] = criteria->StartTimer * IN_MILLISECONDS - timeLost;
|
||||
|
||||
// and at client too
|
||||
SetCriteriaProgress(*i, 0, PROGRESS_SET);
|
||||
SetCriteriaProgress(criteria, 0, PROGRESS_SET);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1490,19 +1482,18 @@ void AchievementMgr::StartTimedAchievement(AchievementCriteriaTimedTypes type, u
|
||||
|
||||
void AchievementMgr::RemoveTimedAchievement(AchievementCriteriaTimedTypes type, uint32 entry)
|
||||
{
|
||||
AchievementCriteriaEntryList const& achievementCriteriaList = sAchievementMgr->GetTimedAchievementCriteriaByType(type);
|
||||
for (AchievementCriteriaEntryList::const_iterator i = achievementCriteriaList.begin(); i!=achievementCriteriaList.end(); ++i)
|
||||
for (AchievementCriteriaEntry const* criteria : sAchievementMgr->GetTimedAchievementCriteriaByType(type))
|
||||
{
|
||||
if ((*i)->StartAsset != entry)
|
||||
if (criteria->StartAsset != entry)
|
||||
continue;
|
||||
|
||||
TimedAchievementMap::iterator timedIter = m_timedAchievements.find((*i)->ID);
|
||||
TimedAchievementMap::iterator timedIter = m_timedAchievements.find(criteria->ID);
|
||||
// We don't have timer for this achievement
|
||||
if (timedIter == m_timedAchievements.end())
|
||||
continue;
|
||||
|
||||
// remove progress
|
||||
RemoveCriteriaProgress(*i);
|
||||
RemoveCriteriaProgress(criteria);
|
||||
|
||||
// Remove the timer
|
||||
m_timedAchievements.erase(timedIter);
|
||||
@@ -1609,25 +1600,25 @@ void AchievementMgr::SendRespondInspectAchievements(Player* player) const
|
||||
*/
|
||||
void AchievementMgr::BuildAllDataPacket(WorldPacket* data) const
|
||||
{
|
||||
for (CompletedAchievementMap::const_iterator iter = m_completedAchievements.begin(); iter != m_completedAchievements.end(); ++iter)
|
||||
for (std::pair<uint32 const, CompletedAchievementData> const& completedAchievement : m_completedAchievements)
|
||||
{
|
||||
// Skip hidden achievements
|
||||
AchievementEntry const* achievement = sAchievementMgr->GetAchievement(iter->first);
|
||||
AchievementEntry const* achievement = sAchievementMgr->GetAchievement(completedAchievement.first);
|
||||
if (!achievement || achievement->Flags & ACHIEVEMENT_FLAG_HIDDEN)
|
||||
continue;
|
||||
|
||||
*data << uint32(iter->first);
|
||||
data->AppendPackedTime(iter->second.date);
|
||||
*data << uint32(completedAchievement.first);
|
||||
data->AppendPackedTime(completedAchievement.second.date);
|
||||
}
|
||||
*data << int32(-1);
|
||||
|
||||
for (CriteriaProgressMap::const_iterator iter = m_criteriaProgress.begin(); iter != m_criteriaProgress.end(); ++iter)
|
||||
for (std::pair<uint32 const, CriteriaProgress> const& criteriaProgress : m_criteriaProgress)
|
||||
{
|
||||
*data << uint32(iter->first);
|
||||
data->appendPackGUID(iter->second.counter);
|
||||
*data << uint32(criteriaProgress.first);
|
||||
data->appendPackGUID(criteriaProgress.second.counter);
|
||||
*data << GetPlayer()->GetPackGUID();
|
||||
*data << uint32(0);
|
||||
data->AppendPackedTime(iter->second.date);
|
||||
data->AppendPackedTime(criteriaProgress.second.date);
|
||||
*data << uint32(0);
|
||||
*data << uint32(0);
|
||||
}
|
||||
@@ -1692,15 +1683,15 @@ bool AchievementMgr::CanUpdateCriteria(AchievementCriteriaEntry const* criteria,
|
||||
|
||||
bool AchievementMgr::ConditionsSatisfied(AchievementCriteriaEntry const* criteria) const
|
||||
{
|
||||
for (uint32 i = 0; i < MAX_CRITERIA_REQUIREMENTS; ++i)
|
||||
for (auto AdditionalRequirement : criteria->AdditionalRequirements)
|
||||
{
|
||||
if (!criteria->AdditionalRequirements[i].Type)
|
||||
if (!AdditionalRequirement.Type)
|
||||
continue;
|
||||
|
||||
switch (criteria->AdditionalRequirements[i].Type)
|
||||
switch (AdditionalRequirement.Type)
|
||||
{
|
||||
case ACHIEVEMENT_CRITERIA_CONDITION_BG_MAP:
|
||||
if (GetPlayer()->GetMapId() != criteria->AdditionalRequirements[i].Asset)
|
||||
if (GetPlayer()->GetMapId() != AdditionalRequirement.Asset)
|
||||
return false;
|
||||
break;
|
||||
case ACHIEVEMENT_CRITERIA_CONDITION_NOT_IN_GROUP:
|
||||
@@ -1894,9 +1885,9 @@ bool AchievementMgr::RequirementsSatisfied(AchievementCriteriaEntry const* achie
|
||||
return false;
|
||||
|
||||
bool matchFound = false;
|
||||
for (int j = 0; j < MAX_WORLD_MAP_OVERLAY_AREA_IDX; ++j)
|
||||
for (uint32 j : worldOverlayEntry->areatableID)
|
||||
{
|
||||
AreaTableEntry const* area = sAreaTableStore.LookupEntry(worldOverlayEntry->areatableID[j]);
|
||||
AreaTableEntry const* area = sAreaTableStore.LookupEntry(j);
|
||||
if (!area)
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user