mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-23 13:46:24 +00:00
Merge branch 'master' into Playerbot
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "DetourNavMesh.h"
|
||||
|
||||
#define MAX_NUMBER_OF_GRIDS 64
|
||||
#define MAX_NUMBER_OF_CELLS 8
|
||||
#define SIZE_OF_GRIDS 533.3333f
|
||||
|
||||
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
|
||||
|
||||
@@ -138,18 +138,28 @@ namespace Acore::Containers
|
||||
}
|
||||
|
||||
/*
|
||||
* Select a random element from a container.
|
||||
* @brief Selects a random element from a container that matches the given predicate
|
||||
*
|
||||
* @param container Source container to select from
|
||||
* @param predicate Unary predicate to filter elements
|
||||
* @return Iterator to the randomly selected element, or end iterator if no elements match the predicate
|
||||
*
|
||||
* Note: container cannot be empty
|
||||
*/
|
||||
template<class C, class Predicate>
|
||||
inline auto SelectRandomContainerElementIf(C const& container, Predicate&& predicate) -> typename std::add_const<decltype(*std::begin(container))>::type&
|
||||
inline auto SelectRandomContainerElementIf(C const& container, Predicate&& predicate) -> decltype(std::begin(container))
|
||||
{
|
||||
C containerCopy;
|
||||
std::copy_if(std::begin(container), std::end(container), std::inserter(containerCopy, std::end(containerCopy)), predicate);
|
||||
auto it = std::begin(containerCopy);
|
||||
std::advance(it, urand(0, uint32(std::size(containerCopy)) - 1));
|
||||
return *it;
|
||||
std::vector<decltype(std::begin(container))> matchingElements;
|
||||
|
||||
for (auto it = std::begin(container); it != std::end(container); ++it)
|
||||
if (predicate(*it))
|
||||
matchingElements.push_back(it);
|
||||
|
||||
if (matchingElements.empty())
|
||||
return std::end(container);
|
||||
|
||||
auto randomIt = matchingElements[urand(0, matchingElements.size() - 1)];
|
||||
return randomIt;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
|
||||
#ifndef Random_h__
|
||||
#define Random_h__
|
||||
|
||||
#undef max
|
||||
#undef min
|
||||
#include "Define.h"
|
||||
#include "Duration.h"
|
||||
#include <limits>
|
||||
|
||||
Reference in New Issue
Block a user