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
413
414
|
#include "KingSystem/ActorSystem/actActorUtil.h"
#include <container/seadSafeArray.h>
#include "KingSystem/ActorSystem/actActor.h"
#include "KingSystem/ActorSystem/actActorConstDataAccess.h"
#include "KingSystem/ActorSystem/actActorParam.h"
#include "KingSystem/ActorSystem/actBaseProcLink.h"
#include "KingSystem/ActorSystem/actInfoData.h"
#include "KingSystem/ActorSystem/actTag.h"
#include "KingSystem/GameData/gdtManager.h"
#include "KingSystem/Map/mapObject.h"
#include "KingSystem/Map/mapPlacementMgr.h"
#include "KingSystem/Resource/GeneralParamList/resGParamListObjectNpc.h"
#include "KingSystem/Resource/resResourceActorLink.h"
#include "KingSystem/Resource/resResourceGParamList.h"
#include "KingSystem/Utils/Byaml/Byaml.h"
#include "KingSystem/World/worldManager.h"
namespace ksys::act {
namespace {
ActorConstDataAccess getAccessor(BaseProcLink* link) {
ActorConstDataAccess accessor;
acquireActor(link, &accessor);
return accessor;
}
ActorConstDataAccess getAccessor(Actor* actor) {
ActorConstDataAccess accessor{actor};
return accessor;
}
sead::SafeString sDefaultDropActor = "Item_Fruit_A";
sead::SafeArray<const char*, 6> sArrowTypes{{
"NormalArrow",
"BombArrow_A",
"AncientArrow",
"FireArrow",
"IceArrow",
"ElectricArrow",
}};
gdt::FlagHandle sAnimalMasterAppearanceHandle = gdt::InvalidHandle;
gdt::FlagHandle sFairyCountCheckHandle = gdt::InvalidHandle;
gdt::FlagHandle sIsGetStopTimerLv2Handle = gdt::InvalidHandle;
} // namespace
bool hasTag(Actor* actor, const sead::SafeString& tag) {
if (!actor)
return false;
return actor->getParam()->getRes().mActorLink->hasTag(tag.cstr());
}
bool hasTag(BaseProcLink* link, const sead::SafeString& tag) {
return hasTag(getAccessor(link), tag);
}
bool hasTag(const ActorConstDataAccess& accessor, const sead::SafeString& tag) {
return accessor.hasTag(tag.cstr());
}
bool hasTag(const sead::SafeString& actor, const sead::SafeString& tag) {
auto* data = InfoData::instance();
return data && data->hasTag(actor.cstr(), tag.cstr());
}
bool hasTag(Actor* actor, u32 tag) {
return actor && actor->getParam()->getRes().mActorLink->hasTag(tag);
}
bool hasTag(BaseProcLink* link, u32 tag) {
return hasTag(getAccessor(link), tag);
}
bool hasTag(const ActorConstDataAccess& accessor, u32 tag) {
return accessor.hasTag(tag);
}
bool hasTag(const sead::SafeString& actor, u32 tag) {
auto* data = InfoData::instance();
return data && data->hasTag(actor.cstr(), tag);
}
bool hasOneTagAtLeast(Actor* actor, const sead::SafeString& tags) {
sead::FixedSafeString<32> tag;
for (auto it = tags.tokenBegin(","); tags.tokenEnd(",") != it; ++it) {
it.get(&tag);
if (hasTag(actor, tag))
return true;
}
return false;
}
bool hasOneTagAtLeast(BaseProcLink* link, const sead::SafeString& tags) {
sead::FixedSafeString<32> tag;
for (auto it = tags.tokenBegin(","); tags.tokenEnd(",") != it; ++it) {
it.get(&tag);
if (hasTag(link, tag))
return true;
}
return false;
}
bool hasOneTagAtLeast(const ActorConstDataAccess& accessor, const sead::SafeString& tags) {
sead::FixedSafeString<32> tag;
for (auto it = tags.tokenBegin(","); tags.tokenEnd(",") != it; ++it) {
it.get(&tag);
if (hasTag(accessor, tag))
return true;
}
return false;
}
// NON_MATCHING: this version doesn't have unnecessary register moves.
bool shouldSkipSpawnWhenRaining(map::Object* obj) {
if (obj->getFlags().isOff(map::Object::Flag::CreateNotRain))
return false;
if (!world::Manager::instance())
return false;
const auto pos = obj->getTranslate();
return !world::Manager::instance()->isRaining(pos);
}
bool shouldSkipSpawnIfGodForestOff(map::Object* obj) {
bool value = false;
if (obj->getFlags().isOff(map::Object::Flag::UnderGodForestOff))
return false;
if (!gdt::Manager::instance()->getBool(sAnimalMasterAppearanceHandle, &value, true))
return false;
return value != 0;
}
bool shouldSkipSpawnGodForestActor(map::Object* obj) {
bool value = false;
if (obj->getFlags().isOn(map::Object::Flag::UnderGodForest) &&
gdt::Manager::instance()->getBool(sAnimalMasterAppearanceHandle, &value, true) && !value) {
return true;
}
return shouldSkipSpawnIfGodForestOff(obj);
}
static bool isFairyCountCheckEnabled() {
bool value = false;
return gdt::Manager::instance()->getBool(sFairyCountCheckHandle, &value, true) && value;
}
bool shouldSkipSpawnFairy(map::Object* obj) {
const map::ActorData& actor_data = obj->getActorData();
if (!actor_data.mFlags.isOnBit(map::ActorData::Flag::Fairy))
return false;
return isFairyCountCheckEnabled();
}
bool shouldSkipSpawnFairy(const sead::SafeString& actor) {
auto* info = InfoData::instance();
if (!info || !info->hasTag(actor.cstr(), tags::Fairy))
return false;
return isFairyCountCheckEnabled();
}
void initSpawnConditionGameDataFlags() {
sFairyCountCheckHandle = gdt::Manager::instance()->getBoolHandle("FairyCountCheck");
sAnimalMasterAppearanceHandle =
gdt::Manager::instance()->getBoolHandle("AnimalMaster_Appearance");
sIsGetStopTimerLv2Handle = gdt::Manager::instance()->getBoolHandle("IsGet_Obj_StopTimerLv2");
}
// TODO: remove this once IsGetStopTimerLv2 is used
// The only purpose of this function is to prevent sIsGetStopTimerLv2Handle from being optimized out
auto initSpawnConditionGameDataFlags_dummy() {
return sIsGetStopTimerLv2Handle;
}
// NON_MATCHING: redundant branches in the original code.
bool hasAnyRevivalTag(const sead::SafeString& actor) {
auto* info = InfoData::instance();
al::ByamlIter iter;
if (!info || !info->getActorIter(&iter, actor.cstr()))
return false;
for (auto tag : {
tags::RevivalBloodyMoon,
tags::RevivalRandom,
tags::RevivalNone,
tags::RevivalNoneForUsed,
tags::RevivalRandomForDrop,
tags::RevivalNoneForDrop,
tags::RevivalUnderGodTime,
}) {
if (info->hasTag(iter, tag))
return true;
}
return false;
}
bool hasStopTimerMiddleTag(Actor* actor) {
return hasTag(actor, tags::StopTimerMiddle);
}
bool hasStopTimerShortTag(Actor* actor) {
return hasTag(actor, tags::StopTimerShort);
}
// NON_MATCHING: ???
const char* arrowTypeToString(ArrowType idx) {
return sArrowTypes[u32(idx)];
}
ArrowType arrowTypeFromString(const sead::SafeString& name) {
for (s32 i = 0; i < sArrowTypes.size(); ++i) {
if (name == sArrowTypes[i])
return ArrowType(i);
}
return ArrowType::Invalid;
}
ZukanType getZukanType(al::ByamlIter* iter) {
if (!iter)
return ZukanType::Invalid;
auto* info = InfoData::instance();
if (info->hasTag(*iter, tags::ZukanAnimal))
return ZukanType::Animal;
if (info->hasTag(*iter, tags::ZukanEnemy))
return ZukanType::Enemy;
if (info->hasTag(*iter, tags::ZukanSozai))
return ZukanType::Sozai;
if (info->hasTag(*iter, tags::ZukanWeapon))
return ZukanType::Weapon;
if (info->hasTag(*iter, tags::ZukanOther))
return ZukanType::Other;
return ZukanType::Invalid;
}
ZukanType getZukanType(Actor* actor) {
if (!actor)
return ZukanType::Invalid;
if (hasTag(actor, tags::ZukanAnimal))
return ZukanType::Animal;
if (hasTag(actor, tags::ZukanEnemy))
return ZukanType::Enemy;
if (hasTag(actor, tags::ZukanSozai))
return ZukanType::Sozai;
if (hasTag(actor, tags::ZukanWeapon))
return ZukanType::Weapon;
if (hasTag(actor, tags::ZukanOther))
return ZukanType::Other;
return ZukanType::Invalid;
}
static bool isProfile(const ActorConstDataAccess& accessor, const sead::SafeString& profile) {
return accessor.hasProc() && accessor.getProfile() == profile;
}
bool isPlayerProfile(const ActorConstDataAccess& accessor) {
return isProfile(accessor, "Player");
}
bool isPlayerProfile(Actor* actor) {
return isPlayerProfile(getAccessor(actor));
}
bool isPlayerProfile(BaseProcLink* link) {
return isPlayerProfile(getAccessor(link));
}
const sead::SafeString& getDefaultDropActor() {
return sDefaultDropActor;
}
bool isCameraProfile(Actor* actor) {
return isProfile(getAccessor(actor), "Camera");
}
bool isNPCProfile(const ActorConstDataAccess& accessor) {
return isProfile(accessor, "NPC");
}
bool isNPCProfile(Actor* actor) {
return isNPCProfile(getAccessor(actor));
}
bool isNPCProfile(BaseProcLink* link) {
return isNPCProfile(getAccessor(link));
}
bool isNPCOffPodFromWeapon(Actor* actor) {
if (!actor)
return false;
auto* gparam = actor->getParam()->getRes().mGParamList;
if (!gparam)
return false;
const auto* npc_param = gparam->getNpc();
return npc_param && npc_param->mIsOffPodFromWeapon.ref();
}
bool isDemoNPCProfile(Actor* actor) {
return isProfile(getAccessor(actor), "DemoNPC");
}
bool isEnemyProfile(const ActorConstDataAccess& accessor) {
if (!accessor.hasProc())
return false;
const auto& profile = accessor.getProfile();
return profile == "Enemy" || profile == "GiantEnemy" || profile == "Guardian" ||
profile == "GuardianComponent" || profile == "LastBoss" || profile == "GelEnemy" ||
profile == "EnemySwarm" || profile == "SiteBoss" || profile == "Sandworm" ||
profile == "Dragon";
}
bool isEnemyProfile(Actor* actor) {
return isEnemyProfile(getAccessor(actor));
}
bool isEnemyProfile(BaseProcLink* link) {
return isEnemyProfile(getAccessor(link));
}
bool isGuardianProfile(BaseProcLink* link) {
const auto accessor = getAccessor(link);
if (!accessor.hasProc())
return false;
const auto& profile = accessor.getProfile();
return profile == "Guardian" || profile == "GuardianComponent";
}
bool isLargeEnemy(const ActorConstDataAccess& accessor) {
if (!accessor.hasProc())
return false;
const auto& profile = accessor.getProfile();
return profile == "GiantEnemy" || profile == "LastBoss" || profile == "SiteBoss" ||
profile == "Sandworm" || profile == "Dragon";
}
bool isLargeEnemy(Actor* actor) {
return isLargeEnemy(getAccessor(actor));
}
bool isGanonBeast(const ActorConstDataAccess& accessor) {
return accessor.hasProc() && accessor.getName() == "Enemy_GanonBeast";
}
bool isGanonBeast(BaseProcLink* link) {
return isGanonBeast(getAccessor(link));
}
bool isNotLivingCreature(Actor* actor) {
return isNotLivingCreature(getAccessor(actor));
}
bool isNotLivingCreature(const ActorConstDataAccess& accessor) {
if (isPlayerProfile(accessor))
return false;
if (isNPCProfile(accessor))
return false;
if (isEnemyProfile(accessor))
return false;
if (isHorseProfile(accessor))
return false;
if (isPreyOrSwarm(accessor))
return false;
return true;
}
bool isNotLivingCreature(BaseProcLink* link) {
return isNotLivingCreature(getAccessor(link));
}
bool isWeaponProfile(const ActorConstDataAccess& accessor) {
if (!accessor.hasProc())
return false;
return isWeaponProfile(accessor.getName());
}
bool isWeaponProfile(const sead::SafeString& actor) {
const char* profile = nullptr;
InfoData::instance()->getActorProfile(&profile, actor.cstr());
return sead::SafeString(profile).startsWith("Weapon");
}
bool isHorseProfile(const ActorConstDataAccess& accessor) {
return isProfile(accessor, "Horse");
}
bool isPreyOrSwarm(const ActorConstDataAccess& accessor) {
if (!accessor.hasProc())
return false;
const auto& profile = accessor.getProfile();
return profile == "Prey" || profile == "Swarm";
}
} // namespace ksys::act
|