SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Not.h
Go to the documentation of this file.
1 
5 #pragma once
6 
8 
9 namespace ai {
10 
14 class Not: public ICondition {
15 protected:
16  ConditionPtr _condition;
17 
18  void getConditionNameWithValue(std::stringstream& s, const AIPtr& entity) override {
19  s << "(" << _condition->getNameWithConditions(entity) << ")";
20  }
21 
22 public:
24 
25  explicit Not(const ConditionPtr& condition) :
26  ICondition("Not", ""), _condition(condition) {
27  }
28  virtual ~Not() {
29  }
30 
31  bool evaluate(const AIPtr& entity) override {
32  return !_condition->evaluate(entity);
33  }
34 };
35 
36 inline ConditionPtr Not::Factory::create(const ConditionFactoryContext *ctx) const {
37  if (ctx->conditions.size() != 1) {
38  return ConditionPtr();
39  }
40  return std::make_shared<Not>(ctx->conditions.front());
41 }
42 
43 }
This condition will just swap the result of the contained condition.
Definition: Not.h:14
bool evaluate(const AIPtr &entity) override
Checks whether the condition evaluates to true for the given entity.
Definition: Not.h:31
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
void getConditionNameWithValue(std::stringstream &s, const AIPtr &entity) override
Override this method to get a more detailed result in getNameWithConditions()
Definition: Not.h:18