SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
SelectGroupLeader.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 SelectGroupLeader: public IFilter {
16 protected:
17  GroupId _groupId;
18 public:
19  FILTER_FACTORY(SelectGroupLeader)
20 
21  explicit SelectGroupLeader(const std::string& parameters = "") :
22  IFilter("SelectGroupLeader", 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  const Zone* zone = entity->getZone();
33  const GroupMgr& groupMgr = zone->getGroupMgr();
34  const AIPtr& groupLeader = groupMgr.getLeader(_groupId);
35  if (groupLeader) {
36  entities.push_back(groupLeader->getId());
37  }
38  }
39 };
40 
41 }
Maintains the groups a AI can be in.
Definition: GroupMgr.h:27
AIPtr getLeader(GroupId id) const
Definition: GroupMgr.h:248
This filter will pick the group leader of the specified group.
Definition: SelectGroupLeader.h:15