AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Containers Namespace Reference

Functions

template<class C >
void RandomResize (C &container, std::size_t requestedSize)
 
template<class C , class Predicate >
void RandomResize (C &container, Predicate &&predicate, std::size_t requestedSize)
 
template<class C >
auto SelectRandomContainerElement (C const &container) -> typename std::add_const< decltype(*std::begin(container))>::type &
 
template<class C , class Predicate >
auto SelectRandomContainerElementIf (C const &container, Predicate &&predicate) -> typename std::add_const< decltype(*std::begin(container))>::type &
 
template<class C >
auto SelectRandomWeightedContainerElement (C const &container, std::vector< double > weights) -> decltype(std::begin(container))
 
template<class C , class Fn >
auto SelectRandomWeightedContainerElement (C const &container, Fn weightExtractor) -> decltype(std::begin(container))
 
template<class M >
auto MapGetValuePtr (M &map, typename M::key_type const &key) -> decltype(AddressOrSelf(map.find(key) ->second))
 
template<class C >
void RandomShuffle (C &container)
 
template<class K , class V , template< class, class, class... > class M, class... Rest>
void MultimapErasePair (M< K, V, Rest... > &multimap, K const &key, V const &value)
 
void EraseIf (Container &c, Predicate p)
 
template<class M >
auto MapEqualRange (M &map, typename M::key_type const &key) -> IteratorPair< decltype(map.begin())>
 

Function Documentation

◆ EraseIf()

void Acore::Containers::EraseIf ( Container c,
Predicate  p 
)
246 {
247 auto wpos = c.begin();
248 for (auto rpos = c.begin(), end = c.end(); rpos != end; ++rpos)
249 {
250 if (!p(*rpos))
251 {
252 if (rpos != wpos)
253 {
254 std::swap(*rpos, *wpos);
255 }
256 ++wpos;
257 }
258 }
259 c.erase(wpos, c.end());
260 }

Referenced by WardenWin::RequestChecks().

◆ MapEqualRange()

template<class M >
auto Acore::Containers::MapEqualRange ( M &  map,
typename M::key_type const &  key 
) -> IteratorPair<decltype(map.begin())>
inline
50 {
51 return { map.equal_range(key) };
52 }

◆ MapGetValuePtr()

template<class M >
auto Acore::Containers::MapGetValuePtr ( M &  map,
typename M::key_type const &  key 
) -> decltype(AddressOrSelf(map.find(key)->second))
inline

Returns a pointer to mapped value (or the value itself if map stores pointers)

209 {
210 auto itr = map.find(key);
211 return itr != map.end() ? AddressOrSelf(itr->second) : nullptr;
212 }
constexpr T * AddressOrSelf(T *ptr)
Definition: Containers.h:33

References Acore::AddressOrSelf().

Referenced by ObjectMgr::GetCreatureMovementOverride(), GetFlyByCameras(), ObjectMgr::GetQuestGreeting(), and Arena::RemovePlayerAtLeave().

◆ MultimapErasePair()

template<class K , class V , template< class, class, class... > class M, class... Rest>
void Acore::Containers::MultimapErasePair ( M< K, V, Rest... > &  multimap,
K const &  key,
V const &  value 
)
229 {
230 auto range = multimap.equal_range(key);
231 for (auto itr = range.first; itr != range.second;)
232 {
233 if (itr->second == value)
234 {
235 itr = multimap.erase(itr);
236 }
237 else
238 {
239 ++itr;
240 }
241 }
242 }

Referenced by Creature::RemoveFromWorld(), and GameObject::RemoveFromWorld().

◆ RandomResize() [1/2]

template<class C , class Predicate >
void Acore::Containers::RandomResize ( C &  container,
Predicate &&  predicate,
std::size_t  requestedSize 
)

First use predicate filter

116 {
118 C containerCopy;
119 std::copy_if(std::begin(container), std::end(container), std::inserter(containerCopy, std::end(containerCopy)), predicate);
120
121 if (requestedSize)
122 {
123 RandomResize(containerCopy, requestedSize);
124 }
125
126 container = std::move(containerCopy);
127 }
void RandomResize(C &container, std::size_t requestedSize)
Definition: Containers.h:81

References RandomResize().

◆ RandomResize() [2/2]

template<class C >
void Acore::Containers::RandomResize ( C &  container,
std::size_t  requestedSize 
)
82 {
83 static_assert(std::is_base_of<std::forward_iterator_tag, typename std::iterator_traits<typename C::iterator>::iterator_category>::value, "Invalid container passed to Acore::Containers::RandomResize");
84
85 if (std::size(container) <= requestedSize)
86 {
87 return;
88 }
89
90 auto keepIt = std::begin(container), curIt = std::begin(container);
91 uint32 elementsToKeep = requestedSize, elementsToProcess = std::size(container);
92
93 while (elementsToProcess)
94 {
95 // this element has chance (elementsToKeep / elementsToProcess) of being kept
96 if (urand(1, elementsToProcess) <= elementsToKeep)
97 {
98 if (keepIt != curIt)
99 {
100 *keepIt = std::move(*curIt);
101 }
102
103 ++keepIt;
104 --elementsToKeep;
105 }
106
107 ++curIt;
108 --elementsToProcess;
109 }
110
111 container.erase(keepIt, std::end(container));
112 }
std::uint32_t uint32
Definition: Define.h:108
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44

References urand().

Referenced by boss_chromaggus::boss_chromaggusAI::boss_chromaggusAI(), boss_victor_nefarius::boss_victor_nefariusAI::boss_victor_nefariusAI(), npc_hallows_end_soh::CastFires(), spell_pal_divine_storm_dummy::CountTargets(), spell_class_call_polymorph::FilterTargets(), spell_shazzrah_gate_dummy::spell_shazzrah_gate_dummy_SpellScript::FilterTargets(), spell_kalecgos_spectral_blast_dummy::spell_kalecgos_spectral_blast_dummy_SpellScript::FilterTargets(), spell_entropius_negative_energy::spell_entropius_negative_energy_SpellScript::FilterTargets(), spell_blood_siphon::FilterTargets(), spell_axe_flurry::FilterTargets(), spell_moam_mana_drain_filter::FilterTargets(), spell_mutate_explode_bug::FilterTargets(), spell_blood_queen_bloodbolt::spell_blood_queen_bloodbolt_SpellScript::FilterTargets(), spell_deathbringer_boiling_blood::spell_deathbringer_boiling_blood_SpellScript::FilterTargets(), spell_putricide_unbound_plague::spell_putricide_unbound_plague_SpellScript::FilterTargets(), spell_hodir_periodic_icicle::spell_hodir_periodic_icicle_SpellScript::FilterTargets(), spell_q24545_aod_special::spell_q24545_aod_special_SpellScript::FilterTargets(), spell_talon_king_ikiss_blink::FilterTargets(), spell_blade_dance_targeting::FilterTargets(), spell_dru_starfall_dummy::FilterTargets(), spell_gen_select_target_count::FilterTargets(), spell_sindragosa_unchained_magic::spell_sindragosa_unchained_magic_SpellScript::FilterTargets(), spell_morogrim_tidewalker_water_globule_new_target::spell_morogrim_tidewalker_water_globule_new_target_SpellScript::FilterTargets(), spell_tsh_shoot_flame_arrow::FilterTargets(), SmartScript::GetTargets(), npc_echo_of_medivh::HandleCheat(), spell_kaelthas_nether_beam::spell_kaelthas_nether_beam_SpellScript::HandleScriptEffect(), boss_priestess_delrissa::boss_priestess_delrissaAI::InitializeAI(), npc_obsidian_eradicator::JustEngagedWith(), npc_obsidian_nullifier::JustEngagedWith(), spell_dreamwalker_summon_suppresser::spell_dreamwalker_summon_suppresser_AuraScript::PeriodicTick(), SmartScript::ProcessAction(), RandomResize(), spell_svalna_revive_champion::spell_svalna_revive_champion_SpellScript::RemoveAliveTarget(), Spell::SelectImplicitAreaTargets(), Spell::SelectImplicitConeTargets(), spell_igb_explosion::spell_igb_explosion_SpellScript::SelectTarget(), UnitAI::SelectTargetList(), PoolGroup< T >::SpawnObject(), boss_fankriss::SummonWorms(), boss_chromaggus::boss_chromaggusAI::UpdateAI(), boss_renataki::boss_renatakiAI::UpdateAI(), boss_blood_queen_lana_thel::boss_blood_queen_lana_thelAI::UpdateAI(), and boss_hodir::boss_hodirAI::UpdateAI().

◆ RandomShuffle()

template<class C >
void Acore::Containers::RandomShuffle ( C &  container)
inline
223 {
224 std::shuffle(std::begin(container), std::end(container), RandomEngine::Instance());
225 }
static RandomEngine & Instance()
Definition: Random.cpp:95

References RandomEngine::Instance().

Referenced by npc_cameron::MoveTheChildren(), and boss_renataki::boss_renatakiAI::UpdateAI().

◆ SelectRandomContainerElement()

template<class C >
auto Acore::Containers::SelectRandomContainerElement ( C const &  container) -> typename std::add_const<decltype(*std::begin(container))>::type&
inline
136 {
137 auto it = std::begin(container);
138 std::advance(it, urand(0, uint32(std::size(container)) - 1));
139 return *it;
140 }

References urand().

Referenced by boss_mor_grayhoof::CastRandomSpell(), lfg::LFGQueue::CheckCompatibility(), spell_dk_corpse_explosion::CheckTargets(), spell_dk_raise_dead::CheckTargets(), Spell::EffectEnergize(), boss_lady_deathwhisper::boss_lady_deathwhisperAI::EmpowerCultist(), boss_sulfuron::boss_sulfuronAI::ExecuteEvent(), spell_apothecary_validate_area::FilterTargets(), spell_send_mug_target_picker::FilterTargets(), spell_deathbringer_boiling_blood::spell_deathbringer_boiling_blood_SpellScript::FilterTargets(), spell_igb_burning_pitch_selector::spell_igb_burning_pitch_selector_SpellScript::FilterTargets(), spell_rotface_mutated_infection::spell_rotface_mutated_infection_SpellScript::FilterTargets(), spell_frostwarden_handler_order_whelp::spell_frostwarden_handler_order_whelp_SpellScript::FilterTargets(), spell_dreamwalker_summoner::spell_dreamwalker_summoner_SpellScript::FilterTargets(), spell_pursue::spell_pursue_SpellScript::FilterTargets(), npc_echo_of_medivh::GetPiece(), boss_moroes::GetRandomGuest(), spell_apothecary_lingering_fumes::HandleAfterCast(), spell_corrupted_totems::HandleDummy(), spell_shadowblink::HandleDummy(), spell_item_mingos_fortune_generator::HandleDummy(), spell_rog_killing_spree::spell_rog_killing_spree_AuraScript::HandleEffectPeriodic(), spell_frostwarden_handler_order_whelp::spell_frostwarden_handler_order_whelp_SpellScript::HandleForcedCast(), spell_ragnaros_lava_burst_randomizer::HandleScript(), spell_item_create_heart_candy::HandleScript(), spell_ayamiss_swarmer_teleport_trigger::HandleScript(), spell_ayamiss_swarmer_start_loop::HandleScript(), spell_tractor_beam_creator::HandleScriptEffect(), misc_commandscript::HandleSkirmishCommand(), boss_grand_warlock_nethekurse::IntroRP(), boss_fankriss::JustEngagedWith(), boss_jedoga_shadowseeker::MovementInform(), spell_mistress_kiss_area::spell_mistress_kiss_area_SpellScript::PrepareSpellScript(), SmartScript::ProcessAction(), SmartScript::ProcessEvent(), LootTemplate::LootGroup::Roll(), Unit::SelectNearbyNoTotemTarget(), Unit::SelectNearbyTarget(), spell_igb_rocket_artillery::spell_igb_rocket_artillery_SpellScript::SelectRandomTarget(), UnitAI::SelectTarget(), spell_putricide_ooze_channel::spell_putricide_ooze_channel_SpellScript::SelectTarget(), spell_the_lich_king_valkyr_target_search::spell_the_lich_king_valkyr_target_search_SpellScript::SelectTarget(), spell_the_lich_king_vile_spirit_move_target_search::spell_the_lich_king_vile_spirit_move_target_search_SpellScript::SelectTarget(), npc_minigob_manabonk::npc_minigob_manabonkAI::SelectTargetInDalaran(), instance_icecrown_citadel::instance_icecrown_citadel_InstanceMapScript::SetPositionTraps(), PoolGroup< T >::SpawnObject(), boss_ouro::Submerge(), boss_elder_nadox::SummonHelpers(), GameObject::Update(), boss_nefarian::UpdateAI(), boss_ragnaros::boss_ragnarosAI::UpdateAI(), boss_priestess_delrissa::boss_priestess_delrissaAI::UpdateAI(), boss_jedoga_shadowseeker::UpdateAI(), npc_captain_arnath::npc_captain_arnathAI::UpdateAI(), and npc_phase_hunter::npc_phase_hunterAI::UpdateAI().

◆ SelectRandomContainerElementIf()

template<class C , class Predicate >
auto Acore::Containers::SelectRandomContainerElementIf ( C const &  container,
Predicate &&  predicate 
) -> typename std::add_const<decltype(*std::begin(container))>::type&
inline
149 {
150 C containerCopy;
151 std::copy_if(std::begin(container), std::end(container), std::inserter(containerCopy, std::end(containerCopy)), predicate);
152 auto it = std::begin(containerCopy);
153 std::advance(it, urand(0, uint32(std::size(containerCopy)) - 1));
154 return *it;
155 }

References urand().

Referenced by boss_laj::JustEngagedWith().

◆ SelectRandomWeightedContainerElement() [1/2]

template<class C , class Fn >
auto Acore::Containers::SelectRandomWeightedContainerElement ( C const &  container,
Fn  weightExtractor 
) -> decltype(std::begin(container))
184 {
185 std::vector<double> weights;
186 weights.reserve(std::size(container));
187 double weightSum = 0.0;
188
189 for (auto& val : container)
190 {
191 double weight = weightExtractor(val);
192 weights.push_back(weight);
193 weightSum += weight;
194 }
195
196 if (weightSum <= 0.0)
197 {
198 weights.assign(std::size(container), 1.0);
199 }
200
201 return SelectRandomWeightedContainerElement(container, weights);
202 }

References SelectRandomWeightedContainerElement().

◆ SelectRandomWeightedContainerElement() [2/2]

template<class C >
auto Acore::Containers::SelectRandomWeightedContainerElement ( C const &  container,
std::vector< double >  weights 
) -> decltype(std::begin(container))
inline
168 {
169 auto it = std::begin(container);
170 std::advance(it, urandweighted(weights.size(), weights.data()));
171 return it;
172 }
uint32 urandweighted(size_t count, double const *chances)
Definition: Random.cpp:89

References urandweighted().

Referenced by BattlegroundMgr::GetRandomBG(), and SelectRandomWeightedContainerElement().