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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
/**
* @file d_a_obj_bky_rock.cpp
*
*/
#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_obj_bky_rock.h"
#include "SSystem/SComponent/c_math.h"
#include "d/d_bg_w.h"
#include "d/d_model.h"
#include "d/d_com_inf_game.h"
#include <cstring>
static int daBkyRock_c_createHeap(fopAc_ac_c* i_this) {
return static_cast<daBkyRock_c*>(i_this)->createHeap();
}
static char* l_arcName = "BYRock";
daBkyRock_c::exeProc daBkyRock_c::s_exeProc[3] = {
&daBkyRock_c::exeModeNoDamage,
&daBkyRock_c::exeModeDamage,
&daBkyRock_c::exeModePiece,
};
daBkyRock_c::daBkyRock_c() {
mBgW = NULL;
mMode = MODE_0;
memset(mModels, 0, sizeof(mModels));
}
daBkyRock_c::~daBkyRock_c() {
dComIfG_resDelete(this, l_arcName);
}
int daBkyRock_c::create() {
fopAcM_ct(this, daBkyRock_c);
u8 swBit0 = getSwBit0();
if (fopAcM_isSwitch(this, swBit0)) {
return cPhs_ERROR_e;
}
int rv = dComIfG_resLoad(this, l_arcName);
if (rv == cPhs_COMPLEATE_e) {
if (fopAcM_entrySolidHeap(
this, daBkyRock_c_createHeap, 0x2000) == 0) {
return cPhs_ERROR_e;
}
if (getNameNo() == 1) {
if (dComIfG_Bgsp().Regist(mBgW, this) != 0) {
return cPhs_ERROR_e;
}
}
init();
}
return rv;
}
int daBkyRock_c::execute() {
middleExe();
return 1;
}
int daBkyRock_c::draw() {
g_env_light.settingTevStruct( 0,
¤t.pos, &tevStr);
g_env_light.setLightTevColorType_MAJI(
mModels[mMode], &tevStr);
if (field_0x57a) {
dMdl_c* dMdl = dMdl_mng_c::entry(mModels[2]->getModelData(), 0, current.roomNo);
if (dMdl != NULL) {
_pieceData* piece = mPieces;
for (int i = 0; i < 20; i++, piece++) {
mDoMtx_stack_c::transS(piece->position.x, piece->position.y, piece->position.z);
mDoMtx_stack_c::YrotM(piece->rotationX);
mDoMtx_stack_c::ZrotM(piece->rotationZ);
mDoMtx_stack_c::scaleM(piece->scale, piece->scale, piece->scale);
piece->mMdlObj.setMtx(mDoMtx_stack_c::get());
dMdl->entryObj(&piece->mMdlObj);
}
}
}
if (mMode != MODE_2) {
mDoExt_modelUpdate(mModels[mMode]);
}
return 1;
}
int daBkyRock_c::Delete() {
if (dComIfGp_getVibration().CheckQuake()) {
dComIfGp_getVibration().StopQuake(0x1f);
}
if (getNameNo() == 1 && mBgW != NULL && mBgW->ChkUsed()) {
dComIfG_Bgsp().Release(mBgW);
}
this->~daBkyRock_c();
return 1;
}
void daBkyRock_c::setModelMtx() {
mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
mDoMtx_stack_c::YrotM(shape_angle.y);
mModels[mMode]->setBaseTRMtx(mDoMtx_stack_c::get());
}
static int const VIBMODE_POWER[3] = {
2, 3, 3,
};
static int const PARTICLE_SCALE[2] = {
0x6D6, 0x8E3,
};
static int const PARTICLE_OFFSET_POS_Y[2] = {
0x168, 0x12C,
};
static u16 const FIRST_PARTICLE_NAME[4] = {
0x89C4, 0x89C5, 0x89C6, 0x89C7,
};
static u16 const SECOND_PARTICLE_NAME[6] = {
0x89C2, 0x89C3, 0x89C4, 0x89C5, 0x89C6, 0x89C7,
};
dCcD_SrcCyl const daBkyRock_c::s_CcDCyl = {
{
{0x0, {{0x0, 0x0, 0x0}, {0x20a0, 0x11}, 0x0}}, // mObj
{dCcD_SE_NONE, 0x0, 0x0, 0x0, 0x0}, // mGObjAt
{dCcD_SE_NONE, 0x0, 0x0, 0x0, 0x1}, // mGObjTg
{0x0}, // mGObjCo
}, // mObjInf
{
{
{0.0f, 0.0f, 0.0f}, // mCenter
0.0f, // mRadius
0.0f // mHeight
} // mCyl
}
};
static int const BMD_IDX[2][3] = {
{4, 5, 8},
{6, 7, 8},
};
int daBkyRock_c::createHeap() {
int nameNo = getNameNo();
for (int i = 0; i < 3; i++) {
J3DModelData* a_model_data_p =
(J3DModelData*)dComIfG_getObjectRes(l_arcName, BMD_IDX[nameNo][i]);
JUT_ASSERT(481, a_model_data_p != NULL);
mModels[i] = mDoExt_J3DModel__create(a_model_data_p, 0x80000, 0x11000084);
if (mModels[i] == NULL) {
return 0;
}
}
if (nameNo == 1) {
mBgW = new dBgW();
if (mBgW == NULL) {
return 0;
}
mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
mDoMtx_stack_c::YrotM(shape_angle.y);
MTXCopy(mDoMtx_stack_c::get(), mMtx);
cBgD_t* bgD = (cBgD_t*)dComIfG_getObjectRes(l_arcName, 11);
if (mBgW->Set(bgD, 1, &mMtx) == 1) {
return 0;
}
}
return 1;
}
static Vec const COL_OFFSET_POS[2][2] = {
{{-100.0f, -250.0f, -100.0f}, {100.0f, -250.0f, 0.0f}},
{{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
};
static int const COL_INIT_HEIGHT[2][2] = {
{0x190, 0x28A}, {0x384, 0x384},
};
static int const COL_INIT_RADIUS[2][2] = {
0xFA, 0x226, 0x28A, 0x320,
};
void daBkyRock_c::init() {
mMode = MODE_0;
field_0x57a = false;
int nameNo = getNameNo();
mStts.Init(0xff, 0, this);
for (int i = 0; i < 2; i++) {
mCyls[i].Set(s_CcDCyl);
mCyls[i].SetStts(&mStts);
cXyz cylCenter(current.pos.x + COL_OFFSET_POS[nameNo][i].x,
current.pos.y + COL_OFFSET_POS[nameNo][i].y,
current.pos.z + COL_OFFSET_POS[nameNo][i].z);
mCyls[i].SetC(cylCenter);
mCyls[i].SetH(COL_INIT_HEIGHT[nameNo][i]);
mCyls[i].SetR(COL_INIT_RADIUS[nameNo][i]);
}
mCyls[1].SetTgHitMark(CcG_Tg_UNK_MARK_9);
field_0x579 = false;
mVibrationTimer = 0;
setModelMtx();
fopAcM_SetMtx(this, mModels[mMode]->getBaseTRMtx());
fopAcM_setCullSizeFar(this, 1.5f);
fopAcM_setCullSizeBox(this, -800.0f, -500.0f, -800.0f, 800.0f, 1000.0f, 800.0f);
}
void daBkyRock_c::middleExe() {
if (s_exeProc[mMode] != NULL) {
(this->*(s_exeProc[mMode]))();
}
}
void daBkyRock_c::exeModeNoDamage() {
if (chkHitBombArrow()) {
initChangeModeBefore();
callBombEmt(4, FIRST_PARTICLE_NAME);
fopAcM_seStartCurrent(this, Z2SE_OBJ_BOMB_ROCK_BRK_WTR_1, 0);
mMode = MODE_1;
initChangeModeAfter();
}
setModelMtx();
for (int i = 0; i < 2; i++) {
dComIfG_Ccsp()->Set(&mCyls[i]);
}
}
void daBkyRock_c::exeModeDamage() {
if (mVibrationTimer != 0) {
mVibrationTimer--;
if (mVibrationTimer <= 0) {
if (dComIfGp_getVibration().CheckQuake()) {
dComIfGp_getVibration().StopQuake(0x1f);
}
}
}
pieceMove();
bool hitBombArrow = chkHitBombArrow();
if (!hitBombArrow) {
field_0x579 = true;
}
if (hitBombArrow && field_0x579) {
initChangeModeBefore();
callBombEmt(6, SECOND_PARTICLE_NAME);
fopAcM_seStartCurrent(this, Z2SE_OBJ_BOMB_ROCK_BRK_WTR_2, 0);
mMode = MODE_2;
u8 swBit0 = getSwBit0();
fopAcM_onSwitch(this, swBit0);
initChangeModeAfter();
}
setModelMtx();
for (int i = 0; i < 2; i++) {
dComIfG_Ccsp()->Set(&mCyls[i]);
}
}
void daBkyRock_c::exeModePiece() {
pieceMove();
if (mVibrationTimer != 0) {
if (!dComIfGp_getVibration().CheckQuake()) {
dComIfGp_getVibration().StartQuake(VIBMODE_POWER[mMode], 0x1f,
cXyz(0.0f, 1.0f, 0.0f));
}
mVibrationTimer--;
if (mVibrationTimer <= 0) {
fopAcM_delete(this);
}
}
}
bool daBkyRock_c::chkHitBombArrow() {
if (getNameNo() == 1) {
u8 swBit1 = getSwBit1();
if (!fopAcM_isSwitch(this, swBit1)) {
return false;
}
}
for (int i = 0; i < 2; i++) {
if (i == 0 && mCyls[i].ChkTgHit()) {
cCcD_Obj* hitObj = mCyls[i].GetTgHitObj();
if (hitObj != NULL && hitObj->ChkAtType(AT_TYPE_BOMB)) {
return 1;
}
mCyls[i].ClrTgHit();
}
}
return 0;
}
static int const VIBMODE_TIMER[2] = {
30, 40,
};
void daBkyRock_c::initChangeModeBefore() {
dComIfGp_getVibration().StartQuake(VIBMODE_POWER[mMode], 0x1f, cXyz(0.0f, 1.0f, 0.0f));
mVibrationTimer = VIBMODE_TIMER[mMode];
pieceMoveInit();
}
void daBkyRock_c::initChangeModeAfter() {
fopAcM_SetMtx(this, mModels[mMode]->getBaseTRMtx());
}
void daBkyRock_c::pieceMove() {
if (field_0x57a) {
f32 dVar5 = current.pos.y;
if (fopAcM_wt_c::waterCheck(¤t.pos)) {
dVar5 = fopAcM_wt_c::getWaterY() - 150.0f;
}
field_0x57a = false;
_pieceData* piece = mPieces;
for (int i = 0; i < 20; i++, piece++) {
cLib_addCalc(&piece->position.x, piece->targetX, 0.1f, 15.0f, 2.0f);
cLib_addCalc(&piece->position.z, piece->targetZ, 0.1f, 15.0f, 2.0f);
piece->speedY -= 8.0f;
piece->position.y += piece->speedY;
if (piece->position.y > dVar5) {
field_0x57a = true;
} else {
piece->scale *= 0.9f;
if (piece->scale > 0.05f) {
field_0x57a = true;
}
}
// !@bug Passing an s16 pointer as a f32 pointer
cLib_addCalc((f32*)&piece->rotationSpeed, 0.0f, 0.1f, 15.0f, 2.0f);
piece->rotationX += piece->rotationSpeed;
piece->rotationZ += piece->rotationSpeed;
}
}
}
static int const DROP_OFFSET_POS[2] = {
0x015E, 0x0DAC,
};
static int const INIT_SPEED_Y_BASE[2] = {
20, 40,
};
static int const INIT_SPEED_Y_RANGE[2] = {
60, 120,
};
static int const PIECE_SCALE_RANGE[2] = {
25, 35,
};
static int const PIECE_SCALE_BASE[2] = {
8, 20,
};
void daBkyRock_c::pieceMoveInit() {
int nameNo = getNameNo();
field_0x57a = true;
f32 speedYBase = INIT_SPEED_Y_BASE[nameNo];
f32 speedYRange = INIT_SPEED_Y_RANGE[nameNo];
int mode = mMode;
_pieceData* piece = mPieces;
for (int i = 0; i < 20; i++, piece++) {
int local_84;
if ((i & 1) != 0) {
local_84 = 1;
} else {
local_84 = -1;
}
int local_88;
if ((i & 2) != 0) {
local_88 = 1;
} else {
local_88 = -1;
}
piece->position.x = current.pos.x + local_84 * cM_rndF(500.0f);
piece->position.y = current.pos.y + cM_rndF(500.0f);
piece->position.z = current.pos.z + local_88 * cM_rndF(500.0f);
f32 dropOffset = DROP_OFFSET_POS[nameNo] + cM_rndF(800.0f);
piece->targetX = current.pos.x + local_84 * dropOffset;
piece->targetZ = current.pos.z + local_88 * dropOffset;
piece->scale = 0.01f * (PIECE_SCALE_BASE[nameNo] + cM_rndF(PIECE_SCALE_RANGE[mode]));
piece->speedY = speedYBase + cM_rndF(speedYRange);
piece->rotationX = cM_rndF(65535.0f);
piece->rotationZ = cM_rndF(65535.0f);
piece->rotationSpeed = local_84 * ((s16)cM_rndF(4096.0f) + 0x2000);
}
}
void daBkyRock_c::callBombEmt(int particleNum, u16 const* particleIds) {
int nameNo = getNameNo();
cXyz pos(current.pos.x, current.pos.y - PARTICLE_OFFSET_POS_Y[nameNo], current.pos.z);
csXyz rotation(0, 0, 0);
f32 scale = PARTICLE_SCALE[nameNo] * 0.001f;
cXyz particleScale(scale, scale, scale);
for (int i = 0; i < particleNum; i++) {
dComIfGp_particle_set(particleIds[i], &pos, &rotation, &particleScale);
}
}
static int daBkyRock_create(daBkyRock_c* i_this) {
fopAcM_ct(i_this, daBkyRock_c);
return i_this->create();
}
static int daBkyRock_Delete(daBkyRock_c* i_this) {
return i_this->Delete();
}
static int daBkyRock_execute(daBkyRock_c* i_this) {
return i_this->execute();
}
static int daBkyRock_draw(daBkyRock_c* i_this) {
return i_this->draw();
}
static actor_method_class daBkyRock_METHODS = {
(process_method_func)daBkyRock_create,
(process_method_func)daBkyRock_Delete,
(process_method_func)daBkyRock_execute,
NULL,
(process_method_func)daBkyRock_draw,
};
actor_process_profile_definition g_profile_BkyRock = {
/* Layer ID */ fpcLy_CURRENT_e,
/* List ID */ 7,
/* List Prio */ fpcPi_CURRENT_e,
/* Proc Name */ fpcNm_BkyRock_e,
/* Proc SubMtd */ &g_fpcLf_Method.base,
/* Size */ sizeof(daBkyRock_c),
/* Size Other */ 0,
/* Parameters */ 0,
/* Leaf SubMtd */ &g_fopAc_Method.base,
/* Draw Prio */ fpcDwPi_BkyRock_e,
/* Actor SubMtd */ &daBkyRock_METHODS,
/* Status */ fopAcStts_UNK_0x40000_e | fopAcStts_UNK_0x4000_e | fopAcStts_CULL_e,
/* Group */ fopAc_ENV_e,
/* Cull Type */ fopAc_CULLBOX_CUSTOM_e,
};
|