AzeorthCore 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 >
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 
)
231 {
232 auto wpos = c.begin();
233 for (auto rpos = c.begin(), end = c.end(); rpos != end; ++rpos)
234 {
235 if (!p(*rpos))
236 {
237 if (rpos != wpos)
238 {
239 std::swap(*rpos, *wpos);
240 }
241 ++wpos;
242 }
243 }
244 c.erase(wpos, c.end());
245 }

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)

194 {
195 auto itr = map.find(key);
196 return itr != map.end() ? AddressOrSelf(itr->second) : nullptr;
197 }
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 
)
214 {
215 auto range = multimap.equal_range(key);
216 for (auto itr = range.first; itr != range.second;)
217 {
218 if (itr->second == value)
219 {
220 itr = multimap.erase(itr);
221 }
222 else
223 {
224 ++itr;
225 }
226 }
227 }

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(), npc_obsidian_eradicator::EnterCombat(), npc_obsidian_nullifier::EnterCombat(), 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_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::spell_tsh_shoot_flame_arrow_SpellScript::FilterTargets(), SmartScript::GetTargets(), spell_kaelthas_nether_beam::spell_kaelthas_nether_beam_SpellScript::HandleScriptEffect(), boss_priestess_delrissa::boss_priestess_delrissaAI::InitializeAI(), 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
208 {
209 std::shuffle(std::begin(container), std::end(container), RandomEngine::Instance());
210 }
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_fankriss::EnterCombat(), 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(), boss_moroes::boss_moroesAI::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(), misc_commandscript::HandleSkirmishCommand(), 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_tsh_shadow_bolt::spell_tsh_shadow_bolt_SpellScript::SelectRandomPlayer(), spell_igb_rocket_artillery::spell_igb_rocket_artillery_SpellScript::SelectRandomTarget(), 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(), boss_malchezaar::boss_malchezaarAI::SummonInfernal(), GameObject::Update(), boss_nefarian::UpdateAI(), boss_ragnaros::boss_ragnarosAI::UpdateAI(), boss_priestess_delrissa::boss_priestess_delrissaAI::UpdateAI(), npc_captain_arnath::npc_captain_arnathAI::UpdateAI(), and npc_phase_hunter::npc_phase_hunterAI::UpdateAI().

◆ SelectRandomWeightedContainerElement() [1/2]

template<class C , class Fn >
auto Acore::Containers::SelectRandomWeightedContainerElement ( C const &  container,
Fn  weightExtractor 
) -> decltype(std::begin(container))
169 {
170 std::vector<double> weights;
171 weights.reserve(std::size(container));
172 double weightSum = 0.0;
173
174 for (auto& val : container)
175 {
176 double weight = weightExtractor(val);
177 weights.push_back(weight);
178 weightSum += weight;
179 }
180
181 if (weightSum <= 0.0)
182 {
183 weights.assign(std::size(container), 1.0);
184 }
185
186 return SelectRandomWeightedContainerElement(container, weights);
187 }

References SelectRandomWeightedContainerElement().

◆ SelectRandomWeightedContainerElement() [2/2]

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

References urandweighted().

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