-
Notifications
You must be signed in to change notification settings - Fork 102
/
mapObjectLink.cpp
412 lines (366 loc) · 13.4 KB
/
mapObjectLink.cpp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#include "KingSystem/Map/mapObjectLink.h"
#include <container/seadBuffer.h>
#include "KingSystem/ActorSystem/actActorConstDataAccess.h"
#include "KingSystem/Map/mapObject.h"
#include "KingSystem/Map/mapObjectGenGroup.h"
#include "KingSystem/Map/mapRail.h"
namespace ksys::map {
struct MapLinkDefinition {
const char* name;
const char* desc;
MapLinkDefType type;
};
static constexpr u32 sNumTypes = 42;
static constexpr sead::SafeArray<MapLinkDefinition, sNumTypes> sMapLinkDefinitions{{
{"-AxisX", "マイナスX軸シグナル", MapLinkDefType::NAxisX},
{"-AxisY", "マイナスY軸シグナル", MapLinkDefType::NAxisY},
{"-AxisZ", "マイナスZ軸シグナル", MapLinkDefType::NAxisZ},
{"AreaCol", "エリア(センサ)指定", MapLinkDefType::AreaCol},
{"AxisX", "X軸シグナル", MapLinkDefType::AxisX},
{"AxisY", "Y軸シグナル", MapLinkDefType::AxisY},
{"AxisZ", "Z軸シグナル", MapLinkDefType::AxisZ},
{"BAndSCs", "ボール&ソケットCS", MapLinkDefType::BAndSCs},
{"BAndSLimitAngYCs", "Y角速度制限付ボール&ソケットCS", MapLinkDefType::BAndSLimitAngYCs},
{"BasicSig", "基本シグナル", MapLinkDefType::BasicSig},
{"BasicSigOnOnly", "オンのみ基本シグナル", MapLinkDefType::BasicSigOnOnly},
{"ChangeAtnSig", "アテンション変更時シグナル", MapLinkDefType::ChangeAtnSig},
{"CogWheelCs", "歯車CS", MapLinkDefType::CogWheelCs},
{"CopyWaitRevival", "配置自動セーブ継承", MapLinkDefType::CopyWaitRevival},
{"Create", "生成", MapLinkDefType::Create},
{"DeadUp", "死んだらオン", MapLinkDefType::DeadUp},
{"DemoMember", "デモ参加", MapLinkDefType::DemoMember},
{"FixedCs", "固定CS", MapLinkDefType::FixedCs},
{"ForSale", "売り物", MapLinkDefType::ForSale},
{"ForbidAttention", "アテンションタイプ変更", MapLinkDefType::ForbidAttention},
{"Freeze", "凍結", MapLinkDefType::Freeze},
{"GimmickSuccess", "ネタ成功シグナル", MapLinkDefType::GimmickSuccess},
{"HingeCs", "ヒンジCS", MapLinkDefType::HingeCs},
{"LifeZero", "ライフ0", MapLinkDefType::LifeZero},
{"LimitHingeCs", "制限付ヒンジCS", MapLinkDefType::LimitHingeCs},
{"ModelBind", "モデルバインド", MapLinkDefType::ModelBind},
{"MtxCopyCreate", "位置継承生成", MapLinkDefType::MtxCopyCreate},
{"OffWaitRevival", "配置自動セーブオフ", MapLinkDefType::OffWaitRevival},
{"PhysSystemGroup", "物理システムグループ", MapLinkDefType::PhysSystemGroup},
{"PlacementLOD", "配置LOD", MapLinkDefType::PlacementLOD},
{"PulleyCs", "滑車CS", MapLinkDefType::PulleyCs},
{"RackAndPinionCs", "ラック&ピニオンCS", MapLinkDefType::RackAndPinionCs},
{"Recreate", "再生成", MapLinkDefType::Recreate},
{"Reference", "参照", MapLinkDefType::Reference},
{"Remains", "遺物シグナル", MapLinkDefType::Remains},
{"SensorBind", "センサバインド", MapLinkDefType::SensorBlind},
{"SliderCs", "スライダーCS", MapLinkDefType::SliderCs},
{"Stable", "安定", MapLinkDefType::Stable},
{"StackLink", "スタック", MapLinkDefType::StackLink},
{"SyncLink", "生成グループ", MapLinkDefType::SyncLink},
{"VelocityControl", "速度制御シグナル", MapLinkDefType::VelocityControl},
}};
const char* ObjectLink::getDescription() const {
return getDescriptionForType(type);
}
const char* ObjectLink::getDescriptionForType(MapLinkDefType t) {
const char* desc = "不定"; // invalid
for (int i = 0; i < sMapLinkDefinitions.size(); ++i) {
if (sMapLinkDefinitions[i].type == t) {
desc = sMapLinkDefinitions[i].desc;
break;
}
}
return desc;
}
MapLinkDefType ObjectLink::getTypeForName(const sead::SafeString& name) {
sead::Buffer<const MapLinkDefinition> buf{sMapLinkDefinitions.size(),
sMapLinkDefinitions.getBufferPtr()};
s32 idx = buf.binarySearchC(
[&](const MapLinkDefinition& item) { return sead::SafeString(item.name).compare(name); });
if (idx == -1)
return MapLinkDefType::Invalid;
return buf[idx].type;
}
bool ObjectLink::sub_7100D4E310(MapLinkDefType t) {
switch (t) {
case MapLinkDefType::Create:
case MapLinkDefType::Delete:
case MapLinkDefType::MtxCopyCreate:
case MapLinkDefType::Freeze:
case MapLinkDefType::ForbidAttention:
return true;
default:
break;
case MapLinkDefType::BasicSig:
case MapLinkDefType::AxisX:
case MapLinkDefType::AxisY:
case MapLinkDefType::AxisZ:
case MapLinkDefType::NAxisX:
case MapLinkDefType::NAxisY:
case MapLinkDefType::NAxisZ:
case MapLinkDefType::GimmickSuccess:
case MapLinkDefType::VelocityControl:
case MapLinkDefType::BasicSigOnOnly:
case MapLinkDefType::Remains:
case MapLinkDefType::DeadUp:
case MapLinkDefType::LifeZero:
case MapLinkDefType::Stable:
case MapLinkDefType::ChangeAtnSig:
return true;
}
return false;
}
bool ObjectLink::isPlacementLODOrForSaleLink(MapLinkDefType t) {
return t == MapLinkDefType::PlacementLOD || t == MapLinkDefType::ForSale;
}
act::Actor* ObjectLink::getObjectActor() const {
if (other_obj == nullptr)
return nullptr;
return other_obj->tryGetActor(false);
}
bool ObjectLink::getObjectProcWithAccessor(act::ActorLinkConstDataAccess& accessor) const {
if (other_obj == nullptr)
return accessor.acquire(nullptr);
else
return other_obj->getActorWithAccessor(accessor);
}
ObjectLinkData::ObjectLinkData() = default;
void ObjectLinkData::deleteArrays() {
if (mRails) {
delete[] mRails;
mRails = nullptr;
}
mLinksOther.links.freeBuffer();
mLinksCs.links.freeBuffer();
mObjects.freeBuffer();
mLinksToSelf.links.freeBuffer();
}
bool ObjectLinkData::allocLinks(s32 num_links_ref, s32 num_links_other, s32 num_links_cs,
sead::Heap* heap) {
if (num_links_ref > 0) {
if (!mObjects.allocBufferAssert(num_links_ref, heap)) {
return false;
}
mObjects.fill(nullptr);
}
if (num_links_other > 0) {
if (!mLinksOther.links.allocBufferAssert(num_links_other, heap)) {
return false;
}
}
if (num_links_cs > 0) {
if (!mLinksCs.links.allocBufferAssert(num_links_cs, heap)) {
return false;
}
}
return true;
}
bool ObjectLinkData::allocLinksToSelf(s32 num_links, sead::Heap* heap) {
if (num_links >= 1) {
mLinksToSelf.links.tryAllocBuffer(num_links, heap);
if (!mLinksToSelf.links.isBufferReady())
return false;
}
return true;
}
// NON_MATCHING
bool ObjectLinkData::addLink(Object* dest, const sead::SafeString& definition_name, bool passive,
Object* src, MubinIter* iter) {
MapLinkDefType type = ObjectLink::getTypeForName(definition_name);
if (type == MapLinkDefType::Invalid) {
return false;
}
if (type == MapLinkDefType::SyncLink && passive) {
return false;
}
if (type == MapLinkDefType::Reference) {
for (int i = 0; i < mObjects.size(); i++) {
if (mObjects[i] == nullptr) {
mObjects[i] = dest;
return false;
}
}
}
if (dest != nullptr && passive) {
switch (type) {
case MapLinkDefType::Create:
case MapLinkDefType::Delete:
case MapLinkDefType::MtxCopyCreate:
case MapLinkDefType::SyncLink:
case MapLinkDefType::PlacementLOD:
case MapLinkDefType::Reference:
break;
case MapLinkDefType::BasicSig:
case MapLinkDefType::AxisX:
case MapLinkDefType::AxisY:
case MapLinkDefType::AxisZ:
case MapLinkDefType::NAxisX:
case MapLinkDefType::NAxisY:
case MapLinkDefType::NAxisZ:
case MapLinkDefType::GimmickSuccess:
case MapLinkDefType::VelocityControl:
case MapLinkDefType::BasicSigOnOnly:
case MapLinkDefType::Remains:
case MapLinkDefType::DeadUp:
case MapLinkDefType::LifeZero:
case MapLinkDefType::Stable:
case MapLinkDefType::ChangeAtnSig:
dest = nullptr;
break;
default:
dest = nullptr;
break;
}
}
ObjectLinkArray* arr = &mLinksCs;
if (type == MapLinkDefType::Reference || type == MapLinkDefType::Invalid) {
arr = &mLinksOther;
}
if (type == MapLinkDefType::CopyWaitRevival) {
if (dest != nullptr) {
if (src->isLinkTag() && !src->isSetFlag8() && !src->isIncrementSave() &&
!dest->isIncrementSave()) {
src->setFlag8();
src->setRevivalGameDataFlagHash(dest->getRevivalGameDataFlagHash());
}
}
}
auto& links = arr->links;
for (auto& link : links) {
if (link.other_obj == dest && link.type == type) {
return false;
}
if (link.other_obj == nullptr && link.type == MapLinkDefType::Invalid) {
link.type = type;
link.other_obj = dest;
link.iter = *iter;
return type != MapLinkDefType::Invalid;
}
}
return true;
}
ObjectLink* ObjectLinkData::findLinkWithType(MapLinkDefType t) {
return findLinkWithType_0(t);
}
ObjectLink* ObjectLinkData::findLinkWithType_0(MapLinkDefType t) {
switch (t) {
case MapLinkDefType::FixedCs:
case MapLinkDefType::HingeCs:
case MapLinkDefType::LimitHingeCs:
case MapLinkDefType::SliderCs:
case MapLinkDefType::PulleyCs:
case MapLinkDefType::BAndSCs:
case MapLinkDefType::BAndSLimitAngYCs:
case MapLinkDefType::CogWheelCs:
case MapLinkDefType::RackAndPinionCs:
return mLinksCs.findLinkWithType(t);
default:
return mLinksOther.findLinkWithType(t);
}
}
bool ObjectLinkData::sub_7100D4EC40(Object* obj, ObjectLink* link, Object* dest) {
for (auto& l : mLinksToSelf.links) {
auto type = link->type;
if (l.other_obj == obj && l.type == link->type) {
return true;
}
if (l.other_obj == nullptr) {
l.other_obj = obj;
l.type = type;
l.iter = link->iter;
auto& iter = link->iter;
switch (type) {
default:
break;
case MapLinkDefType::BasicSig:
case MapLinkDefType::BasicSigOnOnly: {
bool no_auto_demo_member = false;
if (iter.tryGetParamBoolByKey(&no_auto_demo_member, "NoAutoDemoMember")) {
mNoAutoDemoMember = no_auto_demo_member;
}
break;
}
case MapLinkDefType::Create:
case MapLinkDefType::MtxCopyCreate:
if (obj->isLinkTag()) {
bool appear_fade = false;
if (iter.tryGetParamBoolByKey(&appear_fade, "AppearFade")) {
mAppearFade = appear_fade;
}
mCreateLinksSrcObj = obj;
}
break;
case MapLinkDefType::Delete:
if (obj->isLinkTag()) {
mDeleteLinksSrcObj = obj;
}
break;
}
return true;
}
}
return false;
}
void ObjectLinkData::setGenGroup(GenGroup* group) {
if (mGenGroup == nullptr)
mGenGroup = group;
}
bool ObjectLinkData::checkCreateLinkObjRevival() const {
if (mCreateLinksSrcObj != nullptr) {
return !mCreateLinksSrcObj->checkRevivalMaybe(false);
}
return false;
}
bool ObjectLinkData::checkDeleteLinkObjRevival() const {
if (mDeleteLinksSrcObj != nullptr) {
return mDeleteLinksSrcObj->checkRevivalMaybe(true);
}
return false;
}
// NON_MATCHING
bool ObjectLinkArray::checkLink(MapLinkDefType t, bool b) {
bool x_exists;
ObjectLink* link = nullptr;
if (t != MapLinkDefType::BasicSig) {
x_exists = false;
} else {
link = findLinkWithType(MapLinkDefType::BasicSigOnOnly);
x_exists = link != nullptr;
if (link != nullptr)
goto done;
}
link = findLinkWithType(t);
if (link == nullptr)
return false;
if (link->type == MapLinkDefType::VelocityControl)
return false;
done:
act::ActorConstDataAccess acc{};
if (link->other_obj != nullptr)
link->other_obj->getActorWithAccessor(acc);
else
acc.acquire(nullptr);
return acc.checkLinkTagActivated(b, x_exists);
}
bool ObjectLinkData::sub_7100D4EF30(act::ActorConstDataAccess& accessor) {
for (auto& link : mLinksOther.links) {
if (link.type == MapLinkDefType::Recreate && link.other_obj == accessor.getMapObject()) {
accessor.setActor687();
return true;
}
}
return false;
}
Object* ObjectLinkData::findObjectByActorName(const sead::SafeString& name) {
for (auto obj : mObjects) {
if (obj->getActorData().mActorName == name)
return obj;
}
return nullptr;
}
ObjectLink* ObjectLinkArray::findLinkWithType(MapLinkDefType type) {
return findLinkWithType_0(type);
}
ObjectLink* ObjectLinkArray::findLinkWithType_0(MapLinkDefType type) {
for (auto it = links.begin(), end = links.end(); it != end; ++it) {
if (it->type == type)
return &*it;
}
return nullptr;
}
} // namespace ksys::map