summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_lv6TogeRoll.cpp
blob: 386a9e5ea0ae015b27c03fb9dfbf8d2cdf6be2d4 (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
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/**
* @file d_a_obj_lv6TogeRoll.cpp
 *
 */

#include "d/dolzel_rel.h" // IWYU pragma: keep

#include "d/actor/d_a_obj_lv6TogeRoll.h"
#include "d/d_path.h"

static daTogeRoll_HIO_c l_HIO;

dCcD_SrcSph daTogeRoll_c::mCcDSph = {
    daTogeRoll_c::mCcDObjInfo,  // mObjInf
    {
        {{0.0f, 0.0f, 0.0f}, 0.0f}  // mSph
    }  // mSphAttr
};

dCcD_SrcCps daTogeRoll_c::mCcDCps = {
    daTogeRoll_c::mCcDObjInfo2,  // mObjInf
    {
        {{0.0f, 0.0f, 0.0f}, {0.0f, 1100.0f, 0.0f}, 150.0f},  // mCps
    }  // mCpsAttr
};

daTogeRoll_HIO_c::daTogeRoll_HIO_c() {
    field_0x04 = 60;
    field_0x05 = 1;
    field_0x06 = 30;
    field_0x08 = 10.0f;
    field_0x0c = 0.3f;
    field_0x10 = 50.0f;
}

void daTogeRoll_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::ZXYrotM(shape_angle.x, shape_angle.y, shape_angle.z);

    mpModel->setBaseScale(scale);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

int daTogeRoll_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes("togeRol", 4);
    mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000084);
    if (mpModel == NULL) {
        return 0;
    }
    return 1;
}

dCcD_SrcGObjInf const daTogeRoll_c::mCcDObjInfo = {
    {0, {{0x800, 0x1, 0x1f}, {0xdafbfdff, 0x1f}, {0x79}}},
    {1, 0, 1, 0, 1},
    {0xa, 5, 0, 0, 0},
    {0},
};

dCcD_SrcGObjInf const daTogeRoll_c::mCcDObjInfo2 = {
    {0, {{0, 0, 0}, {0xdafbfdff, 0x1f}, {0}}},
    {1, 0, 0, 0, 0},
    {0xa, 1, 0, 0, 2},
    {0},
};

f32 const daTogeRoll_c::mSpeed[] = {
    10.0f, 16.6666666f, 23.3333333f, 25.0f,      26.6666666f, 28.3333333f,
    30.0f, 31.6666666f, 33.3333333f, 40.0f,      46.6666666f, 53.3333333f,
    60.0f, 66.6666666f, 83.3333333f, 3.3333333f,
};

int daTogeRoll_c::create() {
    fopAcM_ct(this, daTogeRoll_c);

    int phase = dComIfG_resLoad(&mPhase, "togeRol");

    if (phase == cPhs_COMPLEATE_e) {
        if (MoveBGCreate("togeRol", -1, NULL, 0x900, NULL) == cPhs_ERROR_e) {
            return cPhs_ERROR_e;
        }

        mPathID = getPathID();

        dPath* path = dPath_GetRoomPath(mPathID, fopAcM_GetRoomNo(this));

        if (path == NULL) {
            return cPhs_INIT_e;
        }

        dPnt* points = &path->m_points[0];
        current.pos.x = points->m_position.x;
        current.pos.y = points->m_position.y + 50.0f;
        current.pos.z = points->m_position.z;

        field_0x5ad = -1;
        field_0x5ae = 0;
        field_0x5d4 = mSpeed[getSpeed()];
        init_modeWaitInit();
        fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
        fopAcM_setCullSizeBox2(this, mpModel->getModelData());
        setBaseMtx();
        mStts.Init(0xfe, 0xff, this);

        for (int i = 0; i < 8; i++) {
            mSph[i].Set(mCcDSph);
            mSph[i].SetStts(&mStts);
        }

        mCps.Set(mCcDCps);
        mCps.SetStts(&mStts);
        field_0x5da = 1;
        field_0x5dc = 0;
        mSound.init(&current.pos, 1);
        field_0x1158 = 0;
    }

    return phase;
}

int daTogeRoll_c::Execute(Mtx** i_mtx) {
    moveTogeRoll();

    cCcD_ObjHitInf* gobj;
    cCcD_Obj* obj = NULL;
    u32 se_id;

    if (mCps.ChkTgHit()) {
        gobj = mCps.GetTgHitGObj();
        obj = mCps.GetTgHitObj();
        se_id = mCps.GetTgHitObjHitSeID(1);
        if ((gobj->GetAtType() & 0x2000000)) {
            init_modeBreak();
        }
    } else {
        for (int i = 0; i < 8; i++) {
            if (mSph[i].ChkTgHit()) {
                gobj = mSph[i].GetTgHitGObj();
                obj = mSph[i].GetTgHitObj();
                se_id = mSph[i].GetTgHitObjHitSeID(1);
                if ((gobj->GetAtType() & 0x2000000)) {
                    init_modeBreak();
                    break;
                }
            }
        }
    }

    if (obj != NULL && gobj != NULL) {
        fopAc_ac_c* hit_actor = dCc_GetAc(obj->GetAc());

        bool bVar1 = true;

        if (hit_actor != NULL) {
            if (fopAcM_GetName(hit_actor) == fpcNm_ALINK_e && gobj->GetAtType() & 2 && field_0x1158) {
                bVar1 = false;
            }
            if (bVar1) {
                mSound.startCollisionSE(se_id, 9, NULL);
                field_0x1158 = 1;
            }
        }
    } else {
        field_0x1158 = 0;
    }

    cXyz pos;
    for (int i = 0; i < 8; i++) {
        cXyz pos(0.0f, 0.0f, 0.0f);
        pos.x = (f32)i * 70.0f - 248.0f;

        mDoMtx_stack_c::ZXYrotS(shape_angle.x, shape_angle.y, shape_angle.z);
        mDoMtx_stack_c::multVec(&pos, &pos);

        cXyz pos2 = current.pos;
        pos2 += pos;

        mSph[i].SetR(50.0f);
        mSph[i].SetC(pos2);
        dComIfG_Ccsp()->Set(&mSph[i]);
    }

    cXyz pos3(270.0f, 0.0f, 0.0f);

    mDoMtx_stack_c::ZXYrotS(current.angle.x, current.angle.y, current.angle.z);
    mDoMtx_stack_c::multVec(&pos3, &pos3);

    field_0x113c.mStart = pos3 + current.pos;
    field_0x113c.mEnd = current.pos - pos3;
    field_0x113c.mRadius = 30.0f;

    mCps.cM3dGCps::Set(field_0x113c);
    dComIfG_Ccsp()->Set(&mCps);
    mStts.Move();
    mSound.framework(0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
    *i_mtx = &mpModel->getBaseTRMtx();
    setBaseMtx();
    return 1;
}

void daTogeRoll_c::moveTogeRoll() {
    if (mPathID != 0xFF) {
        static daTogeRoll_c::modeFunc mode_proc[] = {
            &daTogeRoll_c::modeAcc,   &daTogeRoll_c::modeMove,     &daTogeRoll_c::modeBrk,
            &daTogeRoll_c::modeWait,  &daTogeRoll_c::modeWaitInit, &daTogeRoll_c::modeBreak,
            &daTogeRoll_c::modeBound, &daTogeRoll_c::modeBound2,   &daTogeRoll_c::modeBoundWait,
        };

        if (field_0x5dc == 0) {
            for (int i = 0; i < 8; i++) {
                if (mSph[i].ChkCoHit()) {
                    fopAc_ac_c* hit_actor = dCc_GetAc(mSph[i].GetCoHitObj()->GetAc());
                    if (hit_actor != NULL && fopAcM_GetName(hit_actor) == fpcNm_CSTATUE_e) {
                        field_0x5e0 = hit_actor->current.pos;
                        cXyz pos1 = current.pos - hit_actor->current.pos;
                        cXyz pos2 = current.pos - field_0x5b0;
                        if (pos1.getDotProduct(pos2) >= 0.0f) {
                            init_modeBound();
                        }
                        break;
                    }
                }
            }
        }

        cXyz pos3 = current.pos;
        (this->*mode_proc[mMode])();
        cXyz pos4 = current.pos - pos3;
        cXyz pos5 = current.pos - field_0x5b0;
        cXyz pos6 = pos5.normalizeZP();
        shape_angle.x = shape_angle.x + pos6.x * cM_deg2s((pos4.absXZ() / 314.15927f) * 360.0f);
    }
}

void daTogeRoll_c::init_modeBound() {
    field_0x5dc = 1;
    fopAcM_SetSpeedF(this, 0.0f);
    setNextPoint();
    field_0x5bc = field_0x5b0;
    field_0x5f8 = l_HIO.field_0x10;
    cXyz pos1 = current.pos - field_0x5e0;
    field_0x5ec = pos1.normalizeZP();
    cXyz pos2;
    cM3d_InDivPos2(&current.pos, &field_0x5b0, l_HIO.field_0x0c, &pos2);
    field_0x5b0 = pos2;
    mMode = MODE_BOUND;
}

void daTogeRoll_c::modeBound() {
    if (cLib_addCalcPos(&current.pos, field_0x5b0, 1.0f, field_0x5d4, 1.0f) == 0) {
        init_modeBoundWait();
    }
}

void daTogeRoll_c::modeBound2() {
    if (cLib_addCalcPos(&current.pos, field_0x5b0, 1.0f, field_0x5d4, 1.0f) == 0) {
        init_modeBoundWait();
    }
}

void daTogeRoll_c::init_modeBoundWait() {
    field_0x5db = l_HIO.field_0x06;
    mMode = MODE_BOUND_WAIT;
}

void daTogeRoll_c::modeBoundWait() {
    if (field_0x5db != 0) {
        field_0x5db -= 1;
    } else {
        field_0x5dc = 0;
        field_0x5b0 = field_0x5bc;
        init_modeWait();
    }
}

void daTogeRoll_c::init_modeAcc() {
    mMode = MODE_ACC;
}

void daTogeRoll_c::modeAcc() {
    int iVar1 = cLib_chaseF(&speedF, field_0x5d4, field_0x5d4 / l_HIO.field_0x08);

    cLib_addCalcPos(&current.pos, field_0x5b0, 1.0f, fopAcM_GetSpeedF(this), 0.1f);

    s8 reverb = dComIfGp_getReverb(fopAcM_GetRoomNo(this));
    mDoAud_seStartLevel(Z2SE_OBJ_TOGE_ROLL_MV, &current.pos, fopAcM_GetSpeedF(this), reverb);

    if (iVar1 == 1 || current.pos == field_0x5b0) {
        init_modeMove();
    }
}

void daTogeRoll_c::init_modeMove() {
    mMode = MODE_MOVE;
}

void daTogeRoll_c::modeMove() {
    cXyz pos1 = field_0x5c8;
    cXyz pos2 = field_0x5b0;
    f32 fVar1 = (pos1 - pos2).abs();
    f32 fVar2 = fVar1 * 0.3f;
    if (fVar2 < 30.0f) {
        fVar2 = 30.0f;
    }
    if (fVar2 > 300.0f) {
        fVar2 = 300.0f;
    }

    cLib_addCalcPos(&current.pos, field_0x5b0, 1.0f, fopAcM_GetSpeedF(this), 0.1f);

    s8 reverb = dComIfGp_getReverb(fopAcM_GetRoomNo(this));
    mDoAud_seStartLevel(Z2SE_OBJ_TOGE_ROLL_MV, &current.pos, fopAcM_GetSpeedF(this), reverb);

    fVar1 = (current.pos - field_0x5b0).abs();

    if (fVar2 > fVar1) {
        init_modeBrk();
    }
}

void daTogeRoll_c::init_modeBrk() {
    mMode = MODE_BRK;
}

void daTogeRoll_c::modeBrk() {
    cXyz pos1 = current.pos;
    f32 fVar1 = cLib_addCalcPos(&current.pos, field_0x5b0, 0.1f, fopAcM_GetSpeedF(this), 0.5f);

    f32 fVar2 = (pos1 - current.pos).abs();

    s8 reverb = dComIfGp_getReverb(fopAcM_GetRoomNo(this));
    mDoAud_seStartLevel(Z2SE_OBJ_TOGE_ROLL_MV, &current.pos, fVar2, reverb);

    if (fVar1 == 0) {
        init_modeWaitInit();
    }
}

void daTogeRoll_c::init_modeWaitInit() {
    speedF = 0.0f;
    mMode = MODE_WAIT_INIT;
}

void daTogeRoll_c::modeWaitInit() {
    setNextPoint();
    init_modeWait();
}

void daTogeRoll_c::init_modeWait() {
    mMode = MODE_WAIT;
}

void daTogeRoll_c::modeWait() {
    init_modeAcc();
}

void daTogeRoll_c::init_modeBreak() {
    mDoAud_seStart(Z2SE_OBJ_TRAP_BREAK, &current.pos, 0,
                   dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
    mMode = MODE_BREAK;
}

void daTogeRoll_c::modeBreak() {
    csXyz rot = shape_angle;
    rot.x = 0.0f;
    rot.z = 0.0f;

    dComIfGp_particle_set(0x8A73, &current.pos, &rot, NULL);
    dComIfGp_particle_set(0x8A74, &current.pos, &rot, NULL);
    dComIfGp_particle_set(0x8A75, &current.pos, &rot, NULL);
    dComIfGp_particle_set(0x8A76, &current.pos, &rot, NULL);
    dComIfGp_particle_set(0x8A77, &current.pos, &rot, NULL);
    dComIfGp_particle_set(0x8A78, &current.pos, &rot, NULL);

    fopAcM_delete(this);
}

void daTogeRoll_c::setNextPoint() {
    s16 sVar = field_0x5ae + field_0x5ad;
    dPath* room_path = dPath_GetRoomPath(mPathID, fopAcM_GetRoomNo(this));
    if (dPath_ChkClose(room_path)) {
        if (sVar > room_path->m_num - 1) {
            sVar = 0;
            field_0x5ad = -1;
        } else if (sVar < 0) {
            sVar = (s8)(room_path->m_num - 1);
            field_0x5ad = 1;
        }
    } else if (sVar > room_path->m_num - 1) {
        field_0x5ad = -1;
        sVar = (s8)(room_path->m_num - 2);
    } else if (sVar < 0) {
        field_0x5ad = 1;
        sVar = 1;
    }
    field_0x5c8 = field_0x5b0;
    dPnt* points = room_path->m_points;
    field_0x5b0.x = points[sVar].m_position.x;
    field_0x5b0.y = points[sVar].m_position.y + 50.0f;
    field_0x5b0.z = points[sVar].m_position.z;
    field_0x5ae = sVar;
}

int daTogeRoll_c::Draw() {
    g_env_light.settingTevStruct(64, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);
    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(mpModel);
    dComIfGd_setList();
    return 1;
}

int daTogeRoll_c::Delete() {
    mSound.deleteObject();
    dComIfG_resDelete(&mPhase, "togeRol");
    return 1;
}

static int daTogeRoll_Draw(daTogeRoll_c* i_this) {
    return i_this->Draw();
}

static int daTogeRoll_Execute(daTogeRoll_c* i_this) {
    return i_this->MoveBGExecute();
}

static int daTogeRoll_Delete(daTogeRoll_c* i_this) {
    return i_this->MoveBGDelete();
}

static int daTogeRoll_Create(fopAc_ac_c* i_this) {
    return static_cast<daTogeRoll_c*>(i_this)->create();
}

static actor_method_class l_daTogeRoll_Method = {
    (process_method_func)daTogeRoll_Create,  (process_method_func)daTogeRoll_Delete,
    (process_method_func)daTogeRoll_Execute, 0,
    (process_method_func)daTogeRoll_Draw,
};

actor_process_profile_definition g_profile_Obj_Lv6TogeRoll = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 3,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_Lv6TogeRoll_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daTogeRoll_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_Lv6TogeRoll_e,
    /* Actor SubMtd */ &l_daTogeRoll_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_CULL_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};