SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
IsGroupLeader.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include "ICondition.h"
8 #include "common/String.h"
9 #include "group/GroupMgr.h"
10 #include "zone/Zone.h"
11 
12 namespace ai {
13 
19 class IsGroupLeader: public ICondition {
20 private:
21  GroupId _groupId;
22 public:
24 
25  explicit IsGroupLeader(const std::string& parameters) :
26  ICondition("IsGroupLeader", parameters) {
27  if (_parameters.empty()) {
28  _groupId = -1;
29  } else {
30  _groupId = std::stoi(_parameters);
31  }
32  }
33 
34  virtual ~IsGroupLeader() {
35  }
36 
37  bool evaluate(const AIPtr& entity) override {
38  if (_groupId == -1) {
39  return false;
40  }
41  const GroupMgr& mgr = entity->getZone()->getGroupMgr();
42  return mgr.isGroupLeader(_groupId, entity);
43  }
44 };
45 
46 }
bool evaluate(const AIPtr &entity) override
Checks whether the condition evaluates to true for the given entity.
Definition: IsGroupLeader.h:37
A condition can be placed on a TreeNode to decide which node is going to get executed. In general they are stateless. If they are not, it should explicitly get noted.
Definition: ICondition.h:124
Maintains the groups a AI can be in.
Definition: GroupMgr.h:27
Condition related stuff.
bool isGroupLeader(GroupId id, const AIPtr &ai) const
Definition: GroupMgr.h:270
Evaluates to true if you are the first member in a particular group.
Definition: IsGroupLeader.h:19
#define CONDITION_FACTORY(ConditionName)
A condition factory macro to ease and unify the registration at AIRegistry.
Definition: ICondition.h:55