Qualia
0.2
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
qualia
plugins
bt
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
15
enum
BEHAVIOR_STATUS
{
BT_SUCCESS
,
BT_FAILURE
,
BT_RUNNING
};
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
42
enum
TRAVERSAL_POLICY
{
RESTART
,
CONTINUE
};
43
45
class
BehaviorTreeNode
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
58
class
BehaviorTreeInternalNode
:
public
BehaviorTreeNode
59
{
60
public
:
61
BehaviorTreeInternalNode
();
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
90
BehaviorTreeNode
**
children
;
91
93
uint8_t
nChildren
;
94
};
95
97
class
BehaviorTreeDecoratorNode
:
public
BehaviorTreeNode
98
{
99
public
:
100
BehaviorTreeDecoratorNode
();
101
virtual
~BehaviorTreeDecoratorNode
();
102
103
virtual
BEHAVIOR_STATUS
execute
(
void
* agent) = 0;
104
virtual
void
init
(
void
*
object
) = 0;
105
107
virtual
BehaviorTreeNode
*
setChild
(
BehaviorTreeNode
* node);
108
110
BehaviorTreeNode
*
child
;
111
};
112
114
class
AlwaysRunning
:
public
BehaviorTreeNode
115
{
116
BEHAVIOR_STATUS
execute
(
void
* agent)
117
{
118
return
BT_RUNNING
;
119
}
120
void
init
(
void
* agent){};
121
};
122
124
class
AlwaysSuccess
:
public
BehaviorTreeNode
125
{
126
BEHAVIOR_STATUS
execute
(
void
* agent)
127
{
128
return
BT_SUCCESS
;
129
}
130
void
init
(
void
* agent){};
131
};
132
134
class
AlwaysFailure
:
public
BehaviorTreeNode
135
{
136
BEHAVIOR_STATUS
execute
(
void
* agent)
137
{
138
return
BT_FAILURE
;
139
}
140
void
init
(
void
* agent){};
141
};
142
144
class
SuccessAfter
:
public
BehaviorTreeNode
145
{
146
public
:
147
int
n
;
148
int
total
;
149
BEHAVIOR_STATUS
execute
(
void
* agent)
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
};
165
SuccessAfter
(
int
t)
166
{
167
total
= t;
168
n
=
total
;
169
}
170
};
171
173
class
FailureAfter
:
public
BehaviorTreeNode
174
{
175
public
:
176
int
n
;
177
int
total
;
178
BEHAVIOR_STATUS
execute
(
void
* agent)
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
};
194
FailureAfter
(
int
t)
195
{
196
total
= t;
197
n
=
total
;
198
}
199
};
200
}
201
202
#endif
Generated on Fri Oct 11 2013 19:01:21 for Qualia by
1.8.3.1