mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-17 10:55:43 +00:00
fix(Core/Battlegrounds) Rewrite RandomBG and enabling bg/arenas weights (#2516)
This commit is contained in:
@@ -13,9 +13,11 @@
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
//! Because circular includes are bad
|
||||
extern uint32 urand(uint32 min, uint32 max);
|
||||
extern uint32 urandweighted(size_t count, double const* chances);
|
||||
|
||||
namespace acore
|
||||
{
|
||||
@@ -97,6 +99,14 @@ namespace acore
|
||||
std::advance(it, urand(0, container.size() - 1));
|
||||
return *it;
|
||||
}
|
||||
|
||||
/* Select a random element from a container where each element has a different chance to be selected. */
|
||||
template <class C> typename C::value_type const& SelectRandomWeightedContainerElement(C const& container, std::vector<double> const& weights)
|
||||
{
|
||||
typename C::const_iterator it = container.begin();
|
||||
std::advance(it, urandweighted(weights.size(), weights.data()));
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
//! namespace Containers
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user