-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBehaviorEvent.cpp
More file actions
68 lines (55 loc) · 1.27 KB
/
Copy pathBehaviorEvent.cpp
File metadata and controls
68 lines (55 loc) · 1.27 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
#include "pch.h"
#include "BehaviorEvent.h"
#include "BehaviorTreeEvent.h"
#include <algorithm>
#include <random>
#include <functional>
#include<assert.h>
extern std::_Binder<std::_Unforced, std::uniform_int_distribution<>&, std::default_random_engine&> dice;
using namespace BTEvent;
EStatus Behavior::Tick()
{
if (Status != EStatus::Running)
{
OnInitialize();
}
Status = Update();
if (Status != EStatus::Running)
{
OnTerminate(Status);
}
return Status;
}
void Composite::RemoveChild(Behavior* InChild)
{
auto it = std::find(Children.begin(), Children.end(), InChild);
if (it != Children.end())
{
Children.erase(it);
}
}
void Sequence::OnInitialize()
{
CurrChild = Children.begin();
BehaviorObserver observer = std::bind(&Sequence::OnChildComplete, this, std::placeholders::_1);
Tree->Start(*CurrChild, &observer);
}
void Sequence::OnChildComplete(EStatus Status)
{
Behavior* child = *CurrChild;
if (child->IsFailuer())
{
m_pBehaviorTree->Stop(this, EStatus::Failure);
return;
}
assert(child->GetStatus() == EStatus::Success);
if (++CurrChild == Children.end())
{
Tree->Stop(this, EStatus::Success);
}
else
{
BehaviorObserver observer = std::bind(&Sequence::OnChildComplete, this, std::placeholders::_1);
Tree->Start(*CurrChild, &observer);
}
}