summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_mdoor.cpp
blob: 3407208599f869c9715aa8cb29310d0c3de76050 (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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/**
 * d_a_mdoor.cpp
 * Object - Wooden/Metal bars (Forbidden Woods, Cabana Maze, Dragon Roost Cavern, Earth Temple, etc.)
 */

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_mdoor.h"
#include "d/d_bg_w.h"
#include "d/d_com_inf_game.h"
#include "res/Object/Mdoor.h"
#include "f_op/f_op_actor_mng.h"

const char daMdoor_c::M_arcname[] = "Mdoor";

/* 00000078-00000084       .text getSwbit__9daMdoor_cFv */
u8 daMdoor_c::getSwbit() {
    return (fopAcM_GetParam(this) >> 0) & 0xFF;
}

/* 00000084-00000090       .text getType__9daMdoor_cFv */
u8 daMdoor_c::getType() {
    return (fopAcM_GetParam(this) >> 8) & 0xFF;
}

/* 00000090-0000009C       .text getToolId__9daMdoor_cFv */
u8 daMdoor_c::getToolId() {
    return (fopAcM_GetParam(this) >> 16) & 0xFF;
}

/* 0000009C-000000A8       .text getShapeType__9daMdoor_cFv */
u8 daMdoor_c::getShapeType() {
    return (fopAcM_GetParam(this) >> 24) & 0xFF;
}

/* 000000A8-000000C8       .text CheckCreateHeap__FP10fopAc_ac_c */
static BOOL CheckCreateHeap(fopAc_ac_c* a_this) {
    return ((daMdoor_c*)a_this)->CreateHeap();
}

/* 000000C8-00000230       .text CreateHeap__9daMdoor_cFv */
BOOL daMdoor_c::CreateHeap() {
    s32 modelRes;
    s32 bgdRes;

    switch (getShapeType()) {
        case 1:
            modelRes = dRes_INDEX_MDOOR_BDL_MORI2_e;
            bgdRes = dRes_INDEX_MDOOR_DZB_MORI2_e;
            break;
        
        default:
            modelRes = dRes_INDEX_MDOOR_BDL_MORI1_e;
            bgdRes = dRes_INDEX_MDOOR_DZB_MORI1_e;
            break;
    }

    J3DModelData* modelData = static_cast<J3DModelData*>(dComIfG_getObjectRes(M_arcname, modelRes));
    JUT_ASSERT(144, modelData != NULL);

    mpModel = mDoExt_J3DModel__create(modelData, 0, 0x11020203);
    if (mpModel == NULL) {
        return FALSE;
    }

    mpBgW = new dBgW();
    if (mpBgW == NULL) {
        return FALSE;
    }

    cBgD_t* pData = (cBgD_t*)dComIfG_getObjectRes(M_arcname, bgdRes);
    if (pData == NULL) {
        return FALSE;
    }

    calcMtx();

    if (mpBgW->Set(pData, cBgW::MOVE_BG_e, &mpModel->getBaseTRMtx()) == TRUE) {
        return FALSE;
    }
    return TRUE;
}

/* 00000230-0000029C       .text calcMtx__9daMdoor_cFv */
void daMdoor_c::calcMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y + m2CC, current.pos.z);
    mDoMtx_stack_c::YrotM(home.angle.y);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

/* 0000029C-00000344       .text smokeInit__9daMdoor_cFv */
void daMdoor_c::smokeInit() {
    JPABaseEmitter* emitter = dComIfGp_particle_set(dPa_name::ID_AK_JT_ELEMENTSMOKE00, &current.pos, &shape_angle, NULL, 0xAA, &m290, fopAcM_GetRoomNo(this));
    if (emitter != NULL) {
        emitter->setRate(16.0f);
        emitter->setSpread(0.35f);

        JGeometry::TVec3<f32> vec;
        vec.set(2.0f, 2.0f, 2.0f);
        emitter->setGlobalScale(vec);
    }
}

/* 00000344-00000370       .text smokeEnd__9daMdoor_cFv */
void daMdoor_c::smokeEnd() {
    m290.remove();
}

/* 00000370-000005E0       .text CreateInit__9daMdoor_cFv */
BOOL daMdoor_c::CreateInit() {
    fopAc_ac_c* a_this = (fopAc_ac_c*)this;
    s32 uVar1;
    u8 bVar5;
    
    uVar1 = getSwbit();
    bVar5 = getType();

    if (dComIfG_Bgsp()->Regist(mpBgW, a_this)) {
        JUT_ASSERT(236, FALSE);
    }

    a_this->tevStr.mRoomNo = fopAcM_GetRoomNo(a_this);
    m2CC = 0.0f;
    m2C8 = 0xFF;

    switch (bVar5) {
        case 0:
            if (dComIfGs_isEventBit(dSv_event_flag_c::UNK_1101)) {
                setAction(daMdoor_c::ACT_WAIT3_e);
            } else {
                setAction(daMdoor_c::ACT_DEMO_WAIT_e);
                m2CC = 280.0f;
            }
            m2C6 = dComIfGp_evmng_getEventIdx("MORI1_EVENT", 0xFF);
            break;

        case 1:
            if (dComIfGs_isEventBit(dSv_event_flag_c::UNK_1101)) {
                setAction(daMdoor_c::ACT_WAIT7_e);
                m2CC = 280.0f;
            } else {
                dComIfGs_offEventBit(dSv_event_flag_c::UNK_1140);
                setAction(daMdoor_c::ACT_GENOCIDE_e);
                m2C6 = dComIfGp_evmng_getEventIdx("DEFAULT_STOP_OPEN", 0xFF);
                m2C4 = 1;
            }
            break;

        case 2:
            if (uVar1 == 0xFF || dComIfGs_isSwitch(uVar1, fopAcM_GetRoomNo(a_this))) {
                setAction(daMdoor_c::ACT_WAIT11_e);
                m2CC = 280.0f;
            } else {
                m2C8 = getToolId();
                m2C6 = dComIfGp_evmng_getEventIdx("DEFAULT_STOP_OPEN", getToolId());
                if (m2C8 != 0xFF) {
                    setAction(daMdoor_c::ACT_SWITCH12_e);
                } else {
                    setAction(daMdoor_c::ACT_SWITCH8_e);
                }
            }
            break;

        default:
            setAction(daMdoor_c::ACT_WAIT0_e);
            break;
    }

    a_this->attention_info.position.y += 150.0f;
    a_this->eyePos.y += 150.0f;
    calcMtx();
    mpBgW->Move();
    return TRUE;
}

/* 000005E0-00000698       .text create__9daMdoor_cFv */
cPhs_State daMdoor_c::create() {
    cPhs_State ret = dComIfG_resLoad(&mPhase, M_arcname);
    fopAcM_ct_Retail(this, daMdoor_c);
    if (ret != cPhs_COMPLEATE_e) {
        return ret;
    }
    fopAcM_ct_Demo(this, daMdoor_c);

    if (!fopAcM_entrySolidHeap(this, CheckCreateHeap, 0x1640)) {
        return cPhs_ERROR_e;
    }

    CreateInit();
    return cPhs_COMPLEATE_e;
}

/* 00000698-00000958       .text demoProc__9daMdoor_cFv */
void daMdoor_c::demoProc() {
    static char* action_table[] = {
        "WAIT", "CLOSE", "STOP_OPEN",
    };

    s32 actIdx = dComIfGp_evmng_getMyActIdx(m2C0, action_table, ARRAY_SIZE(action_table), FALSE, 0);

    if (dComIfGp_evmng_getIsAddvance(m2C0)) {
        switch (actIdx) {
            case 1:
                speedF = 0.0f;
                setFlag(1);
                fopAcM_seStart(this, JA_SE_OBJ_CAGE_CLOSE, 0);
                break;
                
            case 2:
                speedF = 0.0f;
                if (getShapeType() != 1) {
                    dComIfGp_particle_set(dPa_name::ID_AK_SN_WOODCAGE00, &current.pos, &current.angle);
                }
                fopAcM_seStart(this, JA_SE_OBJ_CAGE_OPEN, 0);
                break;
        }
    }

    switch (actIdx) {
        case 1:
            cLib_chaseF(&speedF, 60.0f, 6.0f);
            if (cLib_chaseF(&m2CC, 0.0f, speedF)) {
                dComIfGp_evmng_cutEnd(m2C0);
                if (chkFlag(1)) {
                    clrFlag(1);
                    if (getShapeType() != 1) {
                        dComIfGp_particle_set(dPa_name::ID_AK_SN_WOODCAGE00, &current.pos, &current.angle);
                    }
                    smokeInit();
                }
            }
            calcMtx();
            mpBgW->Move();
            break;

        case 2:
            cLib_chaseF(&speedF, 30.0f, 3.0f);
            if (cLib_chaseF(&m2CC, 280.0f, speedF)) {
                dComIfGp_evmng_cutEnd(m2C0);
            }
            calcMtx();
            mpBgW->Move();
            break;

        default:
            dComIfGp_evmng_cutEnd(m2C0);
            break;
    }
}

/* 00000958-00000960       .text daMdoor_actionWait__FP9daMdoor_c */
BOOL daMdoor_actionWait(daMdoor_c*) {
    return TRUE;
}

/* 00000960-000009E8       .text daMdoor_actionDemoWait__FP9daMdoor_c */
BOOL daMdoor_actionDemoWait(daMdoor_c* i_this) {
    if (dComIfGp_evmng_startCheck(i_this->m2C6)) {
        i_this->nextAction();
        i_this->m2C0 = dComIfGp_evmng_getMyStaffId("Mori1", NULL, 0);
        i_this->demoProc();
    }
    return TRUE;
}

/* 000009E8-00000A4C       .text daMdoor_actionDemo__FP9daMdoor_c */
BOOL daMdoor_actionDemo(daMdoor_c* i_this) {
    if (dComIfGp_evmng_endCheck(i_this->m2C6)) {
        i_this->nextAction();
        return TRUE;
    }
    i_this->demoProc();
    return TRUE;
}

/* 00000A4C-00000AF4       .text daMdoor_actionGenocide__FP9daMdoor_c */
BOOL daMdoor_actionGenocide(daMdoor_c* i_this) {
    if (fopAcM_myRoomSearchEnemy(fopAcM_GetRoomNo(i_this)) == NULL) {
        if (i_this->m2C4 > 0) {
            i_this->m2C4--;
        } else {
            switch (i_this->getType()) {
                case 1:
                    mDoAud_subBgmStop();
                    break;
            }
            fopAcM_orderOtherEventId(i_this, i_this->m2C6, i_this->m2C8, 0xFFFF, 0, 1);
            i_this->nextAction();
        }
    }
    return TRUE;
}

/* 00000AF4-00000C6C       .text daMdoor_actionOpen__FP9daMdoor_c */
BOOL daMdoor_actionOpen(daMdoor_c* i_this) {
    if (dComIfGp_evmng_endCheck(i_this->m2C6)) {
        i_this->nextAction();
        dComIfGp_event_reset();
        return TRUE;
    }

    if (i_this->m2C4 > 0) {
        i_this->m2C4--;
        if (i_this->m2C4 == 0) {
            i_this->speedF = 0.0f;
            if (i_this->getShapeType() != 1) {
                dComIfGp_particle_set(dPa_name::ID_AK_SN_WOODCAGE00, &i_this->current.pos, &i_this->current.angle);
            }
            fopAcM_seStart(i_this, JA_SE_OBJ_CAGE_OPEN, 0);
        }
    }

    if (i_this->m2C4 == 0) {
        cLib_chaseF(&i_this->speedF, 30.0f, 3.0f);
        cLib_chaseF(&i_this->m2CC, 280.0f, i_this->speedF);
        i_this->calcMtx();
        i_this->mpBgW->Move();
    }
    return TRUE;
}

/* 00000C6C-00000CE8       .text daMdoor_actionSwitch__FP9daMdoor_c */
BOOL daMdoor_actionSwitch(daMdoor_c* i_this) {
    s32 uVar1 = i_this->getSwbit();
    if (dComIfGs_isSwitch(uVar1, fopAcM_GetRoomNo(i_this))) {
        fopAcM_orderOtherEventId(i_this, i_this->m2C6, i_this->m2C8, 0xFFFF, 0, 1);
        i_this->nextAction();
    }
    return TRUE;
}

/* 00000CE8-00000DD0       .text daMdoor_actionReady__FP9daMdoor_c */
BOOL daMdoor_actionReady(daMdoor_c* i_this) {
    if (i_this->eventInfo.checkCommandDemoAccrpt()) {
        i_this->m2C0 = dComIfGp_evmng_getMyStaffId("SHUTTER_DOOR", NULL, 0);
        i_this->demoProc();
        i_this->nextAction();
        s32 uVar2 = i_this->getSwbit();
        if (uVar2 != 0xFF) {
            dComIfGs_isSwitch(uVar2, fopAcM_GetRoomNo(i_this));
        }

        switch (i_this->getType()) {
            case 1:
                dComIfGs_onEventBit(dSv_event_flag_c::UNK_1140);
                break;
        }
    } else {
        fopAcM_orderOtherEventId(i_this, i_this->m2C6, i_this->m2C8, 0xFFFF, 0, 1);
    }
    return TRUE;
}

/* 00000DD0-00000E60       .text daMdoor_actionReadyOpen__FP9daMdoor_c */
BOOL daMdoor_actionReadyOpen(daMdoor_c* i_this) {
    if (i_this->eventInfo.checkCommandDemoAccrpt()) {
        i_this->nextAction();
        s32 uVar1 = i_this->getSwbit();
        if (uVar1 != 0xFF) {
            dComIfGs_isSwitch(uVar1, fopAcM_GetRoomNo(i_this));
        }
        i_this->m2C4 = 0x14;
    } else {
        fopAcM_orderOtherEventId(i_this, i_this->m2C6, i_this->m2C8, 0xFFFF, 0, 1);
    }
    return TRUE;
}

/* 00000E60-00000ED4       .text daMdoor_actionEvent__FP9daMdoor_c */
BOOL daMdoor_actionEvent(daMdoor_c* i_this) {
    if (dComIfGp_evmng_endCheck(i_this->m2C6)) {
        i_this->nextAction();
        dComIfGp_event_reset();
    } else {
        i_this->demoProc();
    }
    return TRUE;
}

BOOL daMdoor_c::draw() {
    g_env_light.settingTevStruct(TEV_TYPE_BG0, &current.pos, &tevStr);
    g_env_light.setLightTevColorType(mpModel, &tevStr);
    mDoExt_modelUpdateDL(mpModel);
    return TRUE;
}

/* 00000ED4-00000F34       .text daMdoor_Draw__FP9daMdoor_c */
static BOOL daMdoor_Draw(daMdoor_c* i_this) {
    return i_this->draw();
}

BOOL daMdoor_c::execute() {
    typedef BOOL (*actionFunc)(daMdoor_c*);
    static actionFunc l_action[] = {
        daMdoor_actionWait,
        daMdoor_actionDemoWait,
        daMdoor_actionDemo,
        daMdoor_actionWait,
        daMdoor_actionGenocide,
        daMdoor_actionReady,
        daMdoor_actionEvent,
        daMdoor_actionWait,
        daMdoor_actionSwitch,
        daMdoor_actionReady,
        daMdoor_actionEvent,
        daMdoor_actionWait,
        daMdoor_actionSwitch,
        daMdoor_actionReadyOpen,
        daMdoor_actionOpen,
        daMdoor_actionWait,
    };
    
    smokeEnd();
    l_action[mAction](this);
    return TRUE;
}

/* 00000F34-00000F84       .text daMdoor_Execute__FP9daMdoor_c */
static BOOL daMdoor_Execute(daMdoor_c* i_this) {
    return i_this->execute();
}

/* 00000F84-00000F8C       .text daMdoor_IsDelete__FP9daMdoor_c */
static BOOL daMdoor_IsDelete(daMdoor_c*) {
    return TRUE;
}

/* 00000F8C-00001054       .text daMdoor_Delete__FP9daMdoor_c */
static BOOL daMdoor_Delete(daMdoor_c* i_this) {
#if VERSION > VERSION_DEMO
    if (i_this->heap != NULL) 
#endif
    {
        dComIfG_Bgsp()->Release(i_this->mpBgW);
    }

#if VERSION > VERSION_DEMO
    i_this->smokeEnd();
#endif
    dComIfG_resDelete(&i_this->mPhase, daMdoor_c::M_arcname);

    i_this->~daMdoor_c();

    return TRUE;
}

/* 00001054-00001074       .text daMdoor_Create__FP10fopAc_ac_c */
static cPhs_State daMdoor_Create(fopAc_ac_c* i_this) {
    return ((daMdoor_c*)i_this)->create();
}

static actor_method_class l_daMdoor_Method = {
    (process_method_func)daMdoor_Create,
    (process_method_func)daMdoor_Delete,
    (process_method_func)daMdoor_Execute,
    (process_method_func)daMdoor_IsDelete,
    (process_method_func)daMdoor_Draw,
};

actor_process_profile_definition g_profile_MDOOR = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0007,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_MDOOR_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daMdoor_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_MDOOR_e,
    /* Actor SubMtd */ &l_daMdoor_Method,
    /* Status       */ fopAcStts_UNK4000_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_6_e,
};