Core/Shared: Move container functions to shared project under Trinity::Container namespace. Also implement RandomResizeList which takes a predicate function as parameter.
Core/ScriptedAI: Extend SummonList::DoAction to take a predicate function as parameter and allow specifying a maximum number of units to be selected.
This commit is contained in:
@@ -223,7 +223,7 @@ class UnitAI
|
||||
targetList.reverse();
|
||||
|
||||
if (targetType == SELECT_TARGET_RANDOM)
|
||||
Trinity::RandomResizeList(targetList, maxTargets);
|
||||
Trinity::Containers::RandomResizeList(targetList, maxTargets);
|
||||
else
|
||||
targetList.resize(maxTargets);
|
||||
}
|
||||
|
||||
@@ -30,18 +30,6 @@ void SummonList::DoZoneInCombat(uint32 entry)
|
||||
}
|
||||
}
|
||||
|
||||
void SummonList::DoAction(uint32 entry, int32 info)
|
||||
{
|
||||
for (iterator i = begin(); i != end();)
|
||||
{
|
||||
Creature* summon = Unit::GetCreature(*me, *i);
|
||||
++i;
|
||||
if (summon && summon->IsAIEnabled
|
||||
&& (!entry || summon->GetEntry() == entry))
|
||||
summon->AI()->DoAction(info);
|
||||
}
|
||||
}
|
||||
|
||||
void SummonList::DespawnEntry(uint32 entry)
|
||||
{
|
||||
for (iterator i = begin(); i != end();)
|
||||
|
||||
@@ -38,7 +38,18 @@ class SummonList : public std::list<uint64>
|
||||
void Despawn(Creature* summon) { remove(summon->GetGUID()); }
|
||||
void DespawnEntry(uint32 entry);
|
||||
void DespawnAll();
|
||||
void DoAction(uint32 entry, int32 info);
|
||||
|
||||
template <class Predicate> void DoAction(int32 info, Predicate& predicate, uint16 max = 0)
|
||||
{
|
||||
Trinity::Containers::RandomResizeList<uint64, Predicate>(*this, predicate, max);
|
||||
for (iterator i = begin(); i != end(); )
|
||||
{
|
||||
Creature* summon = Unit::GetCreature(*me, *i++);
|
||||
if (summon && summon->IsAIEnabled)
|
||||
summon->AI()->DoAction(info);
|
||||
}
|
||||
}
|
||||
|
||||
void DoZoneInCombat(uint32 entry = 0);
|
||||
void RemoveNotExisting();
|
||||
bool HasEntry(uint32 entry);
|
||||
@@ -46,6 +57,22 @@ class SummonList : public std::list<uint64>
|
||||
Creature* me;
|
||||
};
|
||||
|
||||
class EntryCheckPredicate
|
||||
{
|
||||
public:
|
||||
EntryCheckPredicate(uint32 entry) : _entry(entry) {}
|
||||
bool operator()(uint64 guid) { return GUID_ENPART(guid) == _entry; }
|
||||
|
||||
private:
|
||||
uint32 _entry;
|
||||
};
|
||||
|
||||
class DummyEntryCheckPredicate
|
||||
{
|
||||
public:
|
||||
bool operator()(uint64) { return true; }
|
||||
};
|
||||
|
||||
struct ScriptedAI : public CreatureAI
|
||||
{
|
||||
explicit ScriptedAI(Creature* creature);
|
||||
|
||||
@@ -1023,7 +1023,7 @@ bool LFGMgr::CheckCompatibility(LfgGuidList check, LfgProposal*& pProposal)
|
||||
// Select a random dungeon from the compatible list
|
||||
// TODO - Select the dungeon based on group item Level, not just random
|
||||
// Create a new proposal
|
||||
pProposal = new LfgProposal(SelectRandomContainerElement(compatibleDungeons));
|
||||
pProposal = new LfgProposal(Trinity::Containers::SelectRandomContainerElement(compatibleDungeons));
|
||||
pProposal->cancelTime = time_t(time(NULL)) + LFG_TIME_PROPOSAL;
|
||||
pProposal->state = LFG_PROPOSAL_INITIATING;
|
||||
pProposal->queues = check;
|
||||
|
||||
@@ -1432,7 +1432,7 @@ void GameObject::Use(Unit* user)
|
||||
if (info->summoningRitual.casterTargetSpell && info->summoningRitual.casterTargetSpell != 1) // No idea why this field is a bool in some cases
|
||||
for (uint32 i = 0; i < info->summoningRitual.casterTargetSpellTargets; i++)
|
||||
// m_unique_users can contain only player GUIDs
|
||||
if (Player* target = ObjectAccessor::GetPlayer(*this, SelectRandomContainerElement(m_unique_users)))
|
||||
if (Player* target = ObjectAccessor::GetPlayer(*this, Trinity::Containers::SelectRandomContainerElement(m_unique_users)))
|
||||
spellCaster->CastSpell(target, info->summoningRitual.casterTargetSpell, true);
|
||||
|
||||
// finish owners spell
|
||||
|
||||
@@ -878,20 +878,6 @@ class WorldObject : public Object, public WorldLocation
|
||||
|
||||
namespace Trinity
|
||||
{
|
||||
template<class T>
|
||||
void RandomResizeList(std::list<T> &_list, uint32 _size)
|
||||
{
|
||||
size_t list_size = _list.size();
|
||||
|
||||
while (list_size > _size)
|
||||
{
|
||||
typename std::list<T>::iterator itr = _list.begin();
|
||||
std::advance(itr, urand(0, list_size - 1));
|
||||
_list.erase(itr);
|
||||
--list_size;
|
||||
}
|
||||
}
|
||||
|
||||
// Binary predicate to sort WorldObjects based on the distance to a reference WorldObject
|
||||
class ObjectDistanceOrderPred
|
||||
{
|
||||
|
||||
@@ -14956,7 +14956,7 @@ Unit* Unit::SelectNearbyTarget(Unit* exclude, float dist) const
|
||||
return NULL;
|
||||
|
||||
// select random
|
||||
return SelectRandomContainerElement(targets);
|
||||
return Trinity::Containers::SelectRandomContainerElement(targets);
|
||||
}
|
||||
|
||||
void Unit::ApplyAttackTimePercentMod(WeaponAttackType att, float val, bool apply)
|
||||
|
||||
@@ -479,7 +479,7 @@ void PoolGroup<Quest>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32
|
||||
{
|
||||
do
|
||||
{
|
||||
uint32 questId = SelectRandomContainerElement(currentQuests);
|
||||
uint32 questId = Trinity::Containers::SelectRandomContainerElement(currentQuests);
|
||||
newQuests.insert(questId);
|
||||
currentQuests.erase(questId);
|
||||
} while (newQuests.size() < limit && !currentQuests.empty()); // failsafe
|
||||
@@ -491,7 +491,7 @@ void PoolGroup<Quest>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32
|
||||
// activate <limit> random quests
|
||||
do
|
||||
{
|
||||
uint32 questId = SelectRandomContainerElement(newQuests);
|
||||
uint32 questId = Trinity::Containers::SelectRandomContainerElement(newQuests);
|
||||
spawns.ActivateObject<Quest>(questId, poolId);
|
||||
PoolObject tempObj(questId, 0.0f);
|
||||
Spawn1Object(&tempObj);
|
||||
|
||||
@@ -1055,7 +1055,7 @@ void Spell::SelectImplicitConeTargets(SpellEffIndex effIndex, SpellImplicitTarge
|
||||
if ((*j)->IsAffectedOnSpell(m_spellInfo))
|
||||
maxTargets += (*j)->GetAmount();
|
||||
|
||||
Trinity::RandomResizeList(targets, maxTargets);
|
||||
Trinity::Containers::RandomResizeList(targets, maxTargets);
|
||||
}
|
||||
|
||||
// for compability with older code - add only unit and go targets
|
||||
@@ -1350,7 +1350,7 @@ void Spell::SelectImplicitAreaTargets(SpellEffIndex effIndex, SpellImplicitTarge
|
||||
|
||||
if (m_spellInfo->Id == 5246) //Intimidating Shout
|
||||
unitTargets.remove(m_targets.GetUnitTarget());
|
||||
Trinity::RandomResizeList(unitTargets, maxTargets);
|
||||
Trinity::Containers::RandomResizeList(unitTargets, maxTargets);
|
||||
}
|
||||
|
||||
CallScriptAfterUnitTargetSelectHandlers(unitTargets, effIndex);
|
||||
@@ -1368,7 +1368,7 @@ void Spell::SelectImplicitAreaTargets(SpellEffIndex effIndex, SpellImplicitTarge
|
||||
if ((*j)->IsAffectedOnSpell(m_spellInfo))
|
||||
maxTargets += (*j)->GetAmount();
|
||||
|
||||
Trinity::RandomResizeList(gObjTargets, maxTargets);
|
||||
Trinity::Containers::RandomResizeList(gObjTargets, maxTargets);
|
||||
}
|
||||
for (std::list<GameObject*>::iterator itr = gObjTargets.begin(); itr != gObjTargets.end(); ++itr)
|
||||
AddGOTarget(*itr, effMask);
|
||||
|
||||
@@ -774,7 +774,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex)
|
||||
uint32 maxTargets = std::min<uint32>(3, attackers.size());
|
||||
for (uint32 i = 0; i < maxTargets; ++i)
|
||||
{
|
||||
Unit* attacker = SelectRandomContainerElement(attackers);
|
||||
Unit* attacker = Trinity::Containers::SelectRandomContainerElement(attackers);
|
||||
AddUnitTarget(attacker, 1 << 1);
|
||||
attackers.erase(attacker);
|
||||
}
|
||||
@@ -2008,7 +2008,7 @@ void Spell::EffectEnergize(SpellEffIndex effIndex)
|
||||
if (!avalibleElixirs.empty())
|
||||
{
|
||||
// cast random elixir on target
|
||||
m_caster->CastSpell(unitTarget, SelectRandomContainerElement(avalibleElixirs), true, m_CastItem);
|
||||
m_caster->CastSpell(unitTarget, Trinity::Containers::SelectRandomContainerElement(avalibleElixirs), true, m_CastItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2602,7 +2602,7 @@ void World::SendAutoBroadcast()
|
||||
|
||||
std::string msg;
|
||||
|
||||
msg = SelectRandomContainerElement(m_Autobroadcasts);
|
||||
msg = Trinity::Containers::SelectRandomContainerElement(m_Autobroadcasts);
|
||||
|
||||
uint32 abcenter = sWorld->getIntConfig(CONFIG_AUTOBROADCAST_CENTER);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user