SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Or.h
Go to the documentation of this file.
1 
5 #pragma once
6 
8 
9 namespace ai {
10 
14 class Or: public ICondition {
15 protected:
16  Conditions _conditions;
17  CONDITION_PRINT_SUBCONDITIONS_GETCONDITIONNAMEWITHVALUE
18 
19 public:
20  explicit Or(const Conditions& conditions) :
21  ICondition("Or", ""), _conditions(conditions) {
22  }
23  virtual ~Or() {
24  }
25 
27 
28  bool evaluate(const AIPtr& entity) override {
29  for (ConditionsIter i = _conditions.begin(); i != _conditions.end(); ++i) {
30  if ((*i)->evaluate(entity)) {
31  return true;
32  }
33  }
34 
35  return false;
36  }
37 };
38 
39 inline ConditionPtr Or::Factory::create(const ConditionFactoryContext *ctx) const {
40  if (ctx->conditions.size() < 2) {
41  return ConditionPtr();
42  }
43  return std::make_shared<Or>(ctx->conditions);
44 }
45 
46 }
This condition will logically or all contained conditions.
Definition: Or.h:14
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
Condition related stuff.
#define CONDITION_FACTORY_NO_IMPL(ConditionName)
A condition factory macro to ease and unify the registration at AIRegistry. You still have to impleme...
Definition: ICondition.h:41
bool evaluate(const AIPtr &entity) override
Checks whether the condition evaluates to true for the given entity.
Definition: Or.h:28