SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
IsInGroup.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 
22 class IsInGroup: public ICondition {
23 private:
24  GroupId _groupId;
25 
26 public:
28 
29  explicit IsInGroup(const std::string& parameters) :
30  ICondition("IsInGroup", parameters) {
31  if (_parameters.empty()) {
32  _groupId = -1;
33  } else {
34  _groupId = std::stoi(_parameters);
35  }
36  }
37 
38  virtual ~IsInGroup() {
39  }
40 
41  bool evaluate(const AIPtr& entity) override {
42  const GroupMgr& mgr = entity->getZone()->getGroupMgr();
43  if (_groupId == -1)
44  return mgr.isInAnyGroup(entity);
45  return mgr.isInGroup(_groupId, entity);
46  }
47 };
48 
49 }
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
bool isInGroup(GroupId id, const AIPtr &ai) const
Definition: GroupMgr.h:295
Maintains the groups a AI can be in.
Definition: GroupMgr.h:27
Checks whether the AI is in any or in a particular group.
Definition: IsInGroup.h:22
Condition related stuff.
bool evaluate(const AIPtr &entity) override
Checks whether the condition evaluates to true for the given entity.
Definition: IsInGroup.h:41
bool isInAnyGroup(const AIPtr &ai) const
Definition: GroupMgr.h:290
#define CONDITION_FACTORY(ConditionName)
A condition factory macro to ease and unify the registration at AIRegistry.
Definition: ICondition.h:55