20 Random(
const std::string& parameters,
const Filters& filters) :
21 IFilter(
"Random", parameters), _filters(filters) {
22 ai_assert(filters.size() == 1,
"Random must have one child");
23 _n = std::stoi(parameters);
26 FILTER_ACTION_FACTORY(
Random)
28 void filter (
const AIPtr& entity)
override;
31 inline void Random::filter (
const AIPtr& entity) {
32 FilteredEntities& filtered = getFilteredEntities(entity);
33 const FilteredEntities copy = filtered;
35 _filters.front()->filter(entity);
36 FilteredEntities rndFiltered = getFilteredEntities(entity);
37 ai::shuffle(rndFiltered.begin(), rndFiltered.end());
38 rndFiltered.resize(_n);
39 for (
auto& e : copy) {
40 filtered.push_back(e);
42 for (
auto& e : rndFiltered) {
43 filtered.push_back(e);
#define ai_assert(condition,...)
Provide your own assert - this is only executed in DEBUG mode.
Definition: Types.h:75
This filter will preserve only a few random entries.
Definition: Random.h:15