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 
)
244 {
245 auto wpos = c.begin();
246 for (auto rpos = c.begin(), end = c.end(); rpos != end; ++rpos)
247 {
248 if (!p(*rpos))
249 {
250 if (rpos != wpos)
251 {
252 std::swap(*rpos, *wpos);
253 }
254 ++wpos;
255 }
256 }
257 c.erase(wpos, c.end());
258 }

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
49 {
50 return { map.equal_range(key) };
51 }

◆ 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)

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

References Acore::AddressOrSelf().

Referenced by ObjectMgr::GetCreatureMovementOverride(), GetFlyByCameras(), 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 
)
227 {
228 auto range = multimap.equal_range(key);
229 for (auto itr = range.first; itr != range.second;)
230 {
231 if (itr->second == value)
232 {
233 itr = multimap.erase(itr);
234 }
235 else
236 {
237 ++itr;
238 }
239 }
240 }

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

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

References RandomResize().

◆ RandomResize() [2/2]

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

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::FilterTargets(), spell_malchezaar_enfeeble::FilterTargets(), spell_flamewreath::FilterTargets(), spell_kalecgos_spectral_blast_dummy::FilterTargets(), spell_blood_siphon::FilterTargets(), spell_axe_flurry::FilterTargets(), spell_anetheron_sleep::FilterTargets(), spell_moam_mana_drain_filter::FilterTargets(), spell_mutate_explode_bug::FilterTargets(), spell_blood_queen_bloodbolt::FilterTargets(), spell_deathbringer_boiling_blood::FilterTargets(), spell_putricide_unbound_plague::FilterTargets(), spell_hodir_periodic_icicle::FilterTargets(), spell_q24545_aod_special::FilterTargets(), spell_talon_king_ikiss_blink::FilterTargets(), spell_lady_vashj_summons::FilterTargets(), spell_morogrim_tidewalker_watery_grave::FilterTargets(), spell_magtheridon_debris_target_selector::FilterTargets(), spell_blade_dance_targeting::FilterTargets(), spell_dru_starfall_dummy::FilterTargets(), spell_gen_select_target_count::FilterTargets(), spell_sindragosa_unchained_magic::FilterTargets(), spell_morogrim_tidewalker_water_globule_new_target::FilterTargets(), spell_tsh_shoot_flame_arrow::FilterTargets(), npc_hyjal_ground_trash::GetNearbyFriendlyTrashCreature(), SmartScript::GetTargets(), npc_echo_of_medivh::HandleCheat(), spell_kaelthas_nether_beam::HandleScriptEffect(), boss_priestess_delrissa::InitializeAI(), npc_obsidian_eradicator::JustEngagedWith(), npc_obsidian_nullifier::JustEngagedWith(), spell_dreamwalker_summon_suppresser_aura::PeriodicTick(), SmartScript::ProcessAction(), RandomResize(), spell_svalna_revive_champion::RemoveAliveTarget(), Spell::SelectImplicitAreaTargets(), Spell::SelectImplicitConeTargets(), spell_igb_explosion::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
221 {
222 std::shuffle(std::begin(container), std::end(container), RandomEngine::Instance());
223 }
static RandomEngine & Instance()
Definition: Random.cpp:95

References RandomEngine::Instance().

Referenced by boss_maexxna::boss_maexxnaAI::DoCastWebWrap(), npc_midsummer_ribbon_pole_target::DoSpewLavaChecks(), 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
134 {
135 auto it = std::begin(container);
136 std::advance(it, urand(0, uint32(std::size(container)) - 1));
137 return *it;
138 }

References urand().

Referenced by boss_mor_grayhoof::CastRandomSpell(), lfg::LFGQueue::CheckCompatibility(), spell_dk_corpse_explosion::CheckTargets(), spell_dk_raise_dead::CheckTargets(), npc_forest_frog::DoSpawnRandom(), 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_mistress_kiss_area::FilterTargets(), spell_deathbringer_boiling_blood::FilterTargets(), spell_igb_burning_pitch_selector::FilterTargets(), spell_rotface_mutated_infection::FilterTargets(), spell_frostwarden_handler_order_whelp::FilterTargets(), spell_dreamwalker_summoner::FilterTargets(), spell_pursue::FilterTargets(), spell_ice_spear_target_picker::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_aura::HandleEffectPeriodic(), spell_frostwarden_handler_order_whelp::HandleForcedCast(), spell_ragnaros_lava_burst_randomizer::HandleScript(), spell_item_create_heart_candy::HandleScript(), spell_ayamiss_swarmer_teleport_trigger::HandleScript(), spell_tractor_beam_creator::HandleScriptEffect(), misc_commandscript::HandleSkirmishCommand(), boss_grand_warlock_nethekurse::IntroRP(), boss_priestess_delrissa::JustEngagedWith(), boss_fankriss::JustEngagedWith(), boss_jedoga_shadowseeker::MovementInform(), SmartScript::ProcessAction(), SmartScript::ProcessEvent(), LootTemplate::LootGroup::Roll(), boss_razuvious::boss_razuviousAI::ScheduleRP(), Unit::SelectNearbyNoTotemTarget(), Unit::SelectNearbyTarget(), spell_igb_rocket_artillery::SelectRandomTarget(), UnitAI::SelectTarget(), spell_putricide_ooze_channel::SelectTarget(), spell_the_lich_king_valkyr_target_search::SelectTarget(), spell_the_lich_king_vile_spirit_move_target_search::SelectTarget(), npc_minigob_manabonk::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_jedoga_shadowseeker::UpdateAI(), and npc_captain_arnath::npc_captain_arnathAI::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
147 {
148 C containerCopy;
149 std::copy_if(std::begin(container), std::end(container), std::inserter(containerCopy, std::end(containerCopy)), predicate);
150 auto it = std::begin(containerCopy);
151 std::advance(it, urand(0, uint32(std::size(containerCopy)) - 1));
152 return *it;
153 }

References urand().

Referenced by boss_laj::ScheduleTasks().

◆ SelectRandomWeightedContainerElement() [1/2]

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

References SelectRandomWeightedContainerElement().

◆ SelectRandomWeightedContainerElement() [2/2]

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

References urandweighted().

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