blob: 5989bdbaccce101a2360e1c68e5af633754b5717 (
plain)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#include "KingSystem/ActorSystem/aiForkAI.h"
#include "KingSystem/ActorSystem/aiRootAi.h"
namespace ksys::act::ai {
ForkAI::ForkAI(const InitArg& arg) : Ai(arg) {}
ForkAI::~ForkAI() = default;
bool ForkAI::init_(sead::Heap* heap) {
mFlags.set(Flag::_80);
return true;
}
void ForkAI::enter_(InlineParamPack* params) {
const int num_children = getNumChildren();
if (num_children >= 1) {
for (int i = 0; i < num_children; ++i)
getChild(i)->enter(params, getName());
changeChildIdx(num_children - 1);
} else {
SEAD_WARN("ForkAI::enter_: no children");
changeChildIdx(num_children - 1);
}
setRootAiFlag(RootAiFlag::_8);
}
bool ForkAI::reenter(ActionBase* other, const sead::SafeString& context) {
auto* other_ = sead::DynamicCast<ForkAI>(other);
if (!other_)
return false;
const int num_children = getNumChildren();
if (other_->getNumChildren() != num_children)
return false;
changeChildIdx(other_->mPrevChildIdx);
changeChildIdx(other_->mChildIdx);
bool ok = true;
for (int i = 0; i < num_children; ++i) {
auto* child_other = other_->getChild(i);
auto* child = getChild(i);
if (child_other && child)
ok &= child->takeOver(child_other, getName());
}
return ok;
}
void ForkAI::calc() {
calc_();
const int num_children = getNumChildren();
for (int i = 0; i < num_children; ++i)
getChild(i)->calc();
handlePendingChildChange();
}
void ForkAI::leave_() {
const int num_children = getNumChildren();
for (int i = num_children - 2; i >= 0; --i)
getChild(i)->leave();
}
bool ForkAI::isFailed() const {
const int num_children = getNumChildren();
bool failed = false;
int i = 0;
for (; i < num_children; ++i) {
auto* child = getChild(i);
failed |= child->isFailed();
if (!child->isFinished() && !child->isFailed() && !child->isChangeable())
break;
}
return i == num_children && failed;
}
bool ForkAI::isFinished() const {
const int num_children = getNumChildren();
bool finished = false;
int i = 0;
for (; i < num_children; ++i) {
auto* child = getChild(i);
if (child->isFailed())
break;
if (child->isFinished())
finished = true;
else if (!child->isChangeable())
break;
}
return i == num_children && finished;
}
bool ForkAI::isChangeable() const {
const int num_children = getNumChildren();
for (int i = 0; i < num_children; ++i) {
if (!getChild(i)->isChangeable())
return false;
}
return true;
}
bool ForkAI::handleMessage_(const Message& message) {
const int num_children = getNumChildren();
bool ok = false;
for (int i = 0; i < num_children - 1; ++i)
ok |= getChild(i)->handleMessage(message);
if (!ok)
return false;
getChild(num_children - 1)->handleMessage(message);
return true;
}
bool ForkAI::handleAck_(const MessageAck& message) {
const int num_children = getNumChildren();
bool ok = false;
for (int i = 0; i < num_children - 1; ++i)
ok |= getChild(i)->handleAck(message);
if (!ok)
return false;
getChild(num_children - 1)->handleAck(message);
return true;
}
void ForkAI::getCurrentName(sead::BufferedSafeString* name, ActionBase* last) const {
name->appendWithFormat("/%s{", getName());
if (this != last) {
const int num_children = getNumChildren();
for (int i = 0; i < num_children; ++i) {
getChild(i)->getCurrentName(name, last);
name->appendWithFormat(",");
}
}
name->appendWithFormat("}");
}
void ForkAI::getNames(sead::BufferedSafeString* out) const {
out->appendWithFormat("{");
const int num_children = getNumChildren();
for (int i = 0; i < num_children; ++i) {
auto* child = getChild(i);
out->appendWithFormat("/%s", child->getName());
if (auto* ai = sead::DynamicCast<Ai>(child))
ai->getNames(out);
out->appendWithFormat(",");
}
out->appendWithFormat("}");
}
} // namespace ksys::act::ai
|