Qualia  0.2
BehaviorTreeBase.h
Go to the documentation of this file.
1 #include <qualia/core/common.h>
2 #include <stdarg.h>
3 
4 #ifndef BEHAVIOR_TREE_BASE_H_
5 #define BEHAVIOR_TREE_BASE_H_
6 
7 namespace BehaviorTree
8 {
10 
16 
18 
24  typedef uint8_t FAILURE_POLICY;
25  static const FAILURE_POLICY FAIL_ON_ONE = 1;
26  static const FAILURE_POLICY FAIL_ON_ALL = 255;
27 
29 
33  typedef uint8_t SUCCESS_POLICY;
34  static const SUCCESS_POLICY SUCCEED_ON_ONE = 1;
35  static const SUCCESS_POLICY SUCCEED_ON_ALL = 255;
36 
38 
43 
46  {
47  public:
49  virtual BEHAVIOR_STATUS execute(void* agent) = 0;
50 
52  virtual void init(void* agent) = 0;
53 
54  virtual ~BehaviorTreeNode(){}
55  };
56 
59  {
60  public:
62  virtual ~BehaviorTreeInternalNode();
63 
64  virtual BEHAVIOR_STATUS execute(void* agent) = 0;
65  virtual void init(void* object) = 0;
66 
76  virtual BehaviorTreeNode* setChildren(BehaviorTreeNode* node, ...);
77 
82 #if is_computer()
83  virtual BehaviorTreeInternalNode* addChild(BehaviorTreeNode* node);
84 #endif
85 
87  virtual BehaviorTreeNode* _setChildren(BehaviorTreeNode* node, va_list nodeList);
88 
91 
93  uint8_t nChildren;
94  };
95 
98  {
99  public:
101  virtual ~BehaviorTreeDecoratorNode();
102 
103  virtual BEHAVIOR_STATUS execute(void* agent) = 0;
104  virtual void init(void* object) = 0;
105 
108 
111  };
112 
115  {
117  {
118  return BT_RUNNING;
119  }
120  void init(void* agent){};
121  };
122 
125  {
127  {
128  return BT_SUCCESS;
129  }
130  void init(void* agent){};
131  };
132 
135  {
137  {
138  return BT_FAILURE;
139  }
140  void init(void* agent){};
141  };
142 
145  {
146  public:
147  int n;
148  int total;
150  {
151  if (n == 0)
152  {
153  return BT_SUCCESS;
154  }
155  else
156  {
157  n--;
158  return BT_RUNNING;
159  }
160  }
161  void init(void* agent)
162  {
163  n = total;
164  };
166  {
167  total = t;
168  n = total;
169  }
170  };
171 
174  {
175  public:
176  int n;
177  int total;
179  {
180  if (n == 0)
181  {
182  return BT_FAILURE;
183  }
184  else
185  {
186  n--;
187  return BT_RUNNING;
188  }
189  }
190  void init(void* agent)
191  {
192  n = total;
193  };
195  {
196  total = t;
197  n = total;
198  }
199  };
200 }
201 
202 #endif