SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
And.h
Go to the documentation of this file.
1 
5 #pragma once
6 
8 
9 namespace ai {
10 
14 class And: public ICondition {
15 protected:
16  Conditions _conditions;
17  CONDITION_PRINT_SUBCONDITIONS_GETCONDITIONNAMEWITHVALUE
18 
19 public:
20  explicit And(const Conditions& conditions) :
21  ICondition("And", ""), _conditions(conditions) {
22  }
23  virtual ~And() {
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 false;
32  }
33  }
34 
35  return true;
36  }
37 };
38 
39 inline ConditionPtr And::Factory::create(const ConditionFactoryContext *ctx) const {
40  if (ctx->conditions.size() < 2) {
41  return ConditionPtr();
42  }
43  return std::make_shared<And>(ctx->conditions);
44 }
45 
46 }
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: And.h:28
This condition will logically and all contained conditions.
Definition: And.h:14