SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
SelectGroupMembers.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include "filter/IFilter.h"
8 #include "zone/Zone.h"
9 
10 namespace ai {
11 
15 class SelectGroupMembers: public IFilter {
16 protected:
17  GroupId _groupId;
18 public:
19  FILTER_FACTORY(SelectGroupMembers)
20 
21  explicit SelectGroupMembers(const std::string& parameters = "") :
22  IFilter("SelectGroupMembers", parameters) {
23  if (_parameters.empty()) {
24  _groupId = -1;
25  } else {
26  _groupId = std::stoi(_parameters);
27  }
28  }
29 
30  void filter (const AIPtr& entity) override {
31  FilteredEntities& entities = getFilteredEntities(entity);
32  auto func = [&] (const AIPtr& ai) {
33  entities.push_back(ai->getId());
34  return true;
35  };
36  Zone* zone = entity->getZone();
37  GroupMgr& groupMgr = zone->getGroupMgr();
38  groupMgr.visit(_groupId, func);
39  }
40 };
41 
42 }
Maintains the groups a AI can be in.
Definition: GroupMgr.h:27
This filter will pick the entities from the groups the given AI instance is in.
Definition: SelectGroupMembers.h:15
void visit(GroupId id, Func &func) const
Visit all the group members of the given group until the functor returns false.
Definition: GroupMgr.h:126