SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Invert.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "tree/TreeNode.h"
7 
8 namespace ai {
9 
17 class Invert: public TreeNode {
18 public:
20 
21  TreeNodeStatus execute(const AIPtr& entity, int64_t deltaMillis) override {
22  if (_children.size() != 1) {
23  ai_assert(false, "Invert must have exactly one child");
24  }
25 
26  if (TreeNode::execute(entity, deltaMillis) == CANNOTEXECUTE) {
27  return CANNOTEXECUTE;
28  }
29 
30  const TreeNodePtr& treeNode = *_children.begin();
31  const TreeNodeStatus status = treeNode->execute(entity, deltaMillis);
32  if (status == FINISHED) {
33  return state(entity, FAILED);
34  } else if (status == FAILED) {
35  return state(entity, FINISHED);
36  } else if (status == EXCEPTION) {
37  return state(entity, EXCEPTION);
38  } else if (status == CANNOTEXECUTE) {
39  return state(entity, FINISHED);
40  }
41  return state(entity, RUNNING);
42  }
43 };
44 
45 }
#define ai_assert(condition,...)
Provide your own assert - this is only executed in DEBUG mode.
Definition: Types.h:75
A node with only one child attached. The result of the attached child is inverted.
Definition: Invert.h:17
virtual TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis)
Definition: TreeNodeImpl.h:184
TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis) override
Definition: Invert.h:21
The base class for all behaviour tree actions.
Definition: TreeNode.h:88
#define NODE_CLASS(NodeName)
A node class macro that also defines a factory.
Definition: TreeNode.h:69