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
|
#include "d/t/d_t_reaction.h"
#include "c/c_lib.h"
#include "c/c_math.h"
#include "d/a/d_a_item.h"
#include "d/a/d_a_player.h"
#include "d/a/obj/d_a_obj_base.h"
#include "d/col/c/c_cc_d.h"
#include "d/col/cc/d_cc_s.h"
#include "d/d_pouch.h"
#include "d/d_sc_game.h"
#include "d/flag/sceneflag_manager.h"
#include "d/snd/d_snd_small_effect_mgr.h"
#include "m/m_angle.h"
SPECIAL_ACTOR_PROFILE(TAG_REACTION, dTgReaction_c, fProfile::TAG_REACTION, 0x0151, 0, 0);
STATE_DEFINE(dTgReaction_c, Wait);
const f32 dTgReaction_c::sRadius = 100.0f;
const f32 dTgReaction_c::sHeight = 100.0f;
// clang-format off
dCcD_SrcCyl dTgReaction_c::sCcSrc = {
{{0, 0, 0, 0, 0, 0, 0, 0, 0},
{AT_TYPE_BELLOWS, 0x213, {0, 0, 0x8},0x8},
{0xE8}},
{dTgReaction_c::sRadius, dTgReaction_c::sHeight}
};
// clang-format on
bool dTgReaction_c::createHeap() {
return true;
}
int dTgReaction_c::create() {
// Note the double _c here
CREATE_ALLOCATOR_SIZE(dTgReaction_c_c, 0x1000);
if (getReactType() != REACT_UNDERWATER) {
if (getSceneFlag() >= 0xFF) {
return FAILED;
}
if (SceneflagManager::sInstance->checkBoolFlag(mRoomID, getSceneFlag())) {
return FAILED;
}
}
field_0x4E0 = mRotation.x & 0xFF;
mRotation.x = mAngle.x = 0;
if (field_0x4E0 < 0xFF && !SceneflagManager::sInstance->checkBoolFlag(mRoomID, field_0x4E0)) {
return FAILED;
}
if (dScGame_c::isHeroMode()) {
if (getParam0x10() == 1) {
field_0x4DE = 1;
}
if (field_0x4DE) {
u32 heartMedalCount = adventurePouchCountItem(ITEM_HEART_MEDAL);
if (heartMedalCount == 0) {
return FAILED;
} else if (heartMedalCount == 1 && cM::rnd() < 0.5f) {
return FAILED;
}
}
}
mStts.SetRank(0);
mCollision.Set(sCcSrc);
mCollision.SetStts(mStts);
switch (getReactType()) {
case REACT_SLINGSHOT:
mCollision.SetTgType(AT_TYPE_SLINGSHOT);
mCollision.SetTgFlag_0xA(0);
mCollision.SetR(sCcSrc.mCylInf.mRadius * mScale.x);
mCollision.SetH(sCcSrc.mCylInf.mHeight * mScale.y);
break;
case REACT_GUST_BELLOWS:
mCollision.SetTgType(AT_TYPE_BELLOWS);
mCollision.SetTgFlag_0xA(8);
mCollision.SetR(sCcSrc.mCylInf.mRadius * mScale.x);
mCollision.SetH(sCcSrc.mCylInf.mHeight * mScale.y);
break;
case REACT_UNDERWATER:
mCollision.SetTgType(AT_TYPE_BUBBLE);
mCollision.SetTgFlag_0xA(0);
mCollision.SetR(sCcSrc.mCylInf.mRadius * mScale.x);
mCollision.SetH(sCcSrc.mCylInf.mHeight * mScale.y);
break;
case REACT_BONK:
case REACT_4: break;
}
int item = getParam0x10();
if (item != 0xF) {
DowsingTarget::DowsingSlot slot;
if (item == 0) {
slot = DowsingTarget::SLOT_RUPEE;
} else if (item == 1) {
slot = DowsingTarget::SLOT_HEART;
} else {
return FAILED;
}
mVec3_c dwsOffset;
if (!getParam0x14()) {
field_0x4E4 = mScale.y * sCcSrc.mCylInf.mHeight * 0.5f;
dwsOffset = mVec3_c(0.0f, sCcSrc.mCylInf.mHeight * 0.5f, 0.0f);
} else {
dwsOffset = mVec3_c::Zero;
}
mDowsingTarget.initialize(slot, 0, &dwsOffset, 5000.0f);
mDowsingTarget.doRegister();
mHasDowsingTarget = true;
}
mStateMgr.changeState(StateID_Wait);
return SUCCEEDED;
}
int dTgReaction_c::doDelete() {
onDelete();
return SUCCEEDED;
}
int dTgReaction_c::actorExecute() {
if (SceneflagManager::sInstance->checkBoolFlag(mRoomID, getSceneFlag())) {
onDelete();
return SUCCEEDED;
} else {
mStateMgr.executeState();
return SUCCEEDED;
}
}
int dTgReaction_c::draw() {
return SUCCEEDED;
}
void dTgReaction_c::initializeState_Wait() {}
void dTgReaction_c::executeState_Wait() {
switch (getReactType()) {
case REACT_BONK:
case REACT_4: checkForBonkItem(); break;
case REACT_SLINGSHOT:
case REACT_GUST_BELLOWS: checkForSlingBellowsItem(); break;
case REACT_UNDERWATER: checkForBubble(); break;
}
}
void dTgReaction_c::finalizeState_Wait() {}
void dTgReaction_c::checkForBonkItem() {
if (dAcPy_c::LINK != nullptr && dAcPy_c::LINK->checkFlags0x350(0x2000)) {
mVec3_c diff = mPosition - dAcPy_c::LINK->mPosition;
f32 dist = diff.x * diff.x + diff.z * diff.z;
f32 rad = mScale.x * 100.0f;
if (!(dist < rad * rad)) {
return;
}
if (getReactType() == REACT_4) {
if (field_0x4DD == 0) {
mVec3_c c = mVec3_c::Ez * rad;
mVec3_c c2 = mPosition;
c.rotY(mRotation.y);
c2 += c;
c2.y += field_0x4E4;
u32 newItemParms = dAcItem_c::createItemParams(ITEM_HEART_PIECE, 1, 0, getSceneFlag(), 1, 0xFF);
if (dAcObjBase_c::create(fProfile::ITEM, mRoomID, newItemParms, &c2, nullptr, nullptr, 0xFFFFFFFF)) {
field_0x4DD = 1;
onDelete();
dSndSmallEffectMgr_c::GetInstance()->playSound(SE_S_READ_RIDDLE_A);
}
}
} else {
u32 uVar3;
mVec3_c pos = mPosition;
int p = getParam0x08();
if (p == 0) {
uVar3 = 6;
} else if (p == 0xFF) {
uVar3 = 5;
} else if (p == 1) {
uVar3 = 5;
mVec3_c c = mVec3_c::Ez * rad;
c.rotY(mRotation.y);
pos += c;
} else {
uVar3 = 6;
}
pos.y += field_0x4E4;
if (fn_578_DB0(pos, uVar3)) {
dSndSmallEffectMgr_c::GetInstance()->playSound(SE_S_READ_RIDDLE_B);
}
SceneflagManager::sInstance->setFlag(mRoomID, getSceneFlag());
onDelete();
}
}
}
void dTgReaction_c::checkForBubble() {
if (mCollision.ChkTgHit() && mCollision.ChkTgAtHitType(AT_TYPE_BUBBLE)) {
if (dAcPy_c::LINK != nullptr && dAcPy_c::LINK->checkFlags0x350(0x40)) {
mVec3_c spawnPos = mPosition;
dAcObjBase_c::create(fProfile::OBJ_BUBBLE, mRoomID, 0x4, &spawnPos, nullptr, nullptr, 0xFFFFFFFF);
}
}
mCollision.SetC(mPosition);
dCcS::GetInstance()->Set(&mCollision);
}
void dTgReaction_c::checkForSlingBellowsItem() {
if (mCollision.ChkTgHit()) {
u8 p = getParam0x08();
u32 uVar3;
if (p == 0) {
uVar3 = 6;
} else {
uVar3 = 6;
if ((int)p == 0xFF) {
uVar3 = 5;
}
}
mVec3_c spawnPos = mPosition;
spawnPos.y += field_0x4E4;
if (fn_578_DB0(spawnPos, uVar3)) {
dSndSmallEffectMgr_c::GetInstance()->playSound(SE_S_READ_RIDDLE_B);
}
SceneflagManager::sInstance->setFlag(mRoomID, getSceneFlag());
onDelete();
}
mCollision.SetC(mPosition);
dCcS::GetInstance()->Set(&mCollision);
}
void dTgReaction_c::onDelete() {
if (mHasDowsingTarget) {
mDowsingTarget.doUnregister();
mHasDowsingTarget = false;
}
}
bool dTgReaction_c::fn_578_DB0(const mVec3_c &position, u32 arg) {
return true;
}
static s32 SOME_ANG = -3641;
bool dTgReaction_c::spawnHearts(s32 params, const mVec3_c &pos, s32 velocity_type, mAng angle) {
int numHearts = params == 6 ? 3 : 1;
mAng3_c ang(0, 0, 0);
// This is annoying because we don't know which operators
// mAng supports
s32 max;
s32 min;
if (velocity_type == 6) {
max = angle;
min = SOME_ANG;
} else {
max = (s16)cLib::targetAngleY(dAcPy_c::LINK->mPosition, pos) + 0x4000;
min = -0x8000;
}
s16 stepSize = s16(min) / numHearts;
mAng range = stepSize / 2;
s32 step = s16(max) + range;
mAng rndMax = range / 2;
mAng rndMin = -rndMax;
for (int i = 0; i < numHearts; i++) {
ang.y = mAng(step) + cM::rndRange(rndMin, rndMax);
if (velocity_type == 5) {
dAcItem_c::spawnItem(ITEM_HEART, mRoomID, pos, ang, 0xFFFFFFFF, 1);
} else if (velocity_type == 6) {
dAcItem_c::spawnItem(ITEM_HEART, mRoomID, pos, ang, 0xFFFFFFFF, 0);
} else {
dAcItem_c::spawnDrop(ITEM_HEART, mRoomID, pos, ang);
}
step = mAng(step) - stepSize;
}
return true;
}
|