SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Fail.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "tree/TreeNode.h"
7 
8 namespace ai {
9 
15 class Fail: public TreeNode {
16 public:
18 
19  TreeNodeStatus execute(const AIPtr& entity, int64_t deltaMillis) override {
20  if (_children.size() != 1) {
21  ai_assert(false, "Fail must have exactly one child");
22  }
23 
24  if (TreeNode::execute(entity, deltaMillis) == CANNOTEXECUTE) {
25  return CANNOTEXECUTE;
26  }
27 
28  const TreeNodePtr& treeNode = *_children.begin();
29  const TreeNodeStatus status = treeNode->execute(entity, deltaMillis);
30  if (status == RUNNING) {
31  return state(entity, RUNNING);
32  }
33  return state(entity, FAILED);
34  }
35 };
36 
37 }
#define ai_assert(condition,...)
Provide your own assert - this is only executed in DEBUG mode.
Definition: Types.h:75
virtual TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis)
Definition: TreeNodeImpl.h:184
A decorator node with only one child attached. The result of the attached child is only taken into ac...
Definition: Fail.h:15
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
TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis) override
Definition: Fail.h:19