fix(Core/Battlegrounds) Rewrite RandomBG and enabling bg/arenas weights (#2516)

This commit is contained in:
Shard
2019-12-28 09:40:13 +01:00
committed by Stoabrogga
parent 5198b2614e
commit 067d9e791f
19 changed files with 210 additions and 221 deletions

View File

@@ -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
}