-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBehaviorTreeOptimized.cpp
More file actions
135 lines (106 loc) · 2.28 KB
/
Copy pathBehaviorTreeOptimized.cpp
File metadata and controls
135 lines (106 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "pch.h"
#include "BehaviorTreeOptimized.h"
#include<assert.h>
using namespace BTOptimized;
void BehaviorTree::Tick()
{
Root->Tick();
}
BehaviorTreeBuilder* BehaviorTreeBuilder::Sequence()
{
Behavior* Sq = Bt->Allocate<class Sequence>();
AddBehavior(Sq);
return this;
}
BehaviorTreeBuilder* BehaviorTreeBuilder::Action(EActionMode ActionModes)
{
Behavior* Ac;
switch (ActionModes)
{
case EActionMode::Attack:
Ac = Bt->Allocate<class Action_Attack>();;
break;
case EActionMode::Patrol:
Ac = Bt->Allocate<class Action_Patrol>();
break;
case EActionMode::Runaway:
Ac = Bt->Allocate<class Action_Runaway>();
break;
default:
Ac = nullptr;
break;
}
AddBehavior(Ac);
return this;
}
BehaviorTreeBuilder* BehaviorTreeBuilder::Condition(EConditionMode ConditionMode, bool IsNegation)
{
Behavior* Cd;
switch (ConditionMode)
{
case EConditionMode::IsSeeEnemy:
Cd = Bt->Allocate<class Condition_IsSeeEnemy>(IsNegation);
break;
case EConditionMode::IsHealthLow:
Cd = Bt->Allocate<class Condition_IsHealthLow>(IsNegation);
break;
case EConditionMode::IsEnemyDead:
Cd = Bt->Allocate<class Condition_IsEnemyDead>(IsNegation);
break;
default:
Cd = nullptr;
break;
}
AddBehavior(Cd);
return this;
}
BehaviorTreeBuilder* BehaviorTreeBuilder::Selector()
{
Behavior* St = Bt->Allocate<class Selector>();
AddBehavior(St);
return this;
}
BehaviorTreeBuilder* BehaviorTreeBuilder::Repeat(int RepeatNum)
{
Behavior* Rp = Bt->Allocate<class Repeat>(RepeatNum);
AddBehavior(Rp);
return this;
}
BehaviorTreeBuilder* BehaviorTreeBuilder::ActiveSelector()
{
Behavior* Ast = Bt->Allocate<class ActiveSelector>();
AddBehavior(Ast);
return this;
}
BehaviorTreeBuilder* BehaviorTreeBuilder::Parallel(EPolicy InSucess, EPolicy InFailure)
{
Behavior* Pl = Bt->Allocate<class Parallel>(InSucess, InFailure);
AddBehavior(Pl);
return this;
}
BehaviorTreeBuilder* BehaviorTreeBuilder::Back()
{
NodeStack.pop();
return this;
}
BehaviorTree* BehaviorTreeBuilder::End()
{
while (!NodeStack.empty())
{
NodeStack.pop();
}
return Bt;
}
void BehaviorTreeBuilder::AddBehavior(Behavior* NewBehavior)
{
assert(NewBehavior);
if (!Bt->HaveRoot())
{
Bt->SetRoot(NewBehavior);
}
else
{
NodeStack.top()->AddChild(NewBehavior);
}
NodeStack.push(NewBehavior);
}