summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_scannon_ten.cpp
blob: 15acddecbc2c8af02cecc2c96844647fa78349ac (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
475
476
477
478
479
480
481
482
483
484
485
486
/**
 * @file d_a_obj_scannon_ten.cpp
 *
*/

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

#include "d/actor/d_a_obj_scannon_ten.h"
#include "d/actor/d_a_player.h"
#include "d/d_s_play.h"
#include "f_op/f_op_camera_mng.h"
#include <cstring>

static char* l_arcName = "SCanTen";

static char* l_staffName = "SCanTen";

static char* l_eventName = "SKY_CANNON_TEN_FIRE";

static int eventCallBack(void* i_proc, int param_1) {
    daObjSCannonTen_c* proc = (daObjSCannonTen_c*)i_proc;
    if (proc != NULL) {
        proc->changeScene();
    }

    return 1;
}

static int daObjSCannonTen_c_createHeap(fopAc_ac_c* i_this) {
    return ((daObjSCannonTen_c*)i_this)->createHeap();
}

daObjSCannonTen_c::daObjSCannonTen_c() {
    mpBgW = NULL;
    memset(mpEmtSmk, 0, sizeof(mpEmtSmk));
    mpEmtLine = NULL;
}

daObjSCannonTen_c::~daObjSCannonTen_c() {
    dComIfG_resDelete(this, l_arcName);
}

int daObjSCannonTen_c::createHeap() {
    J3DModelData* a_model_data_p = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 9);
    JUT_ASSERT(116, a_model_data_p != NULL);

    mpModel = mDoExt_J3DModel__create(a_model_data_p, J3DMdlFlag_DifferedDLBuffer, J3D_DIFF_FLAG(FALSE, FALSE, TRUE, 8, 0, FALSE, 0, 0, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE));
    if (mpModel == NULL) {
        return 0;
    }

    J3DAnmTransform* a_bck_p = (J3DAnmTransform*)dComIfG_getObjectRes(l_arcName, 6);
    JUT_ASSERT(133, a_bck_p != NULL);
    int rt = mBck.init(a_bck_p, 1, 0, 0.0f, 0, -1, 0);
    if (!rt) {
        return 0;
    }

    mpBgW = new dBgW();
    if (mpBgW == 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(), mBgMtx);

    if (mpBgW->Set((cBgD_t*)dComIfG_getObjectRes(l_arcName, 12), 1, &mBgMtx) == 1) {
        return 0;
    }

    return 1;
}

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

    int phase_state = dComIfG_resLoad(this, l_arcName);
    if (phase_state == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, daObjSCannonTen_c_createHeap, 0x9500)) {
            return cPhs_ERROR_e;
        }

        if (dComIfG_Bgsp().Regist(mpBgW, this)) {
            return cPhs_ERROR_e;
        }

        init();

        setModelMtx();
        fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
        fopAcM_setCullSizeFar(this, 5.0f);

        J3DJoint* joint_p = mpModel->getModelData()->getJointNodePointer(0);
        if (joint_p != NULL) {
            fopAcM_setCullSizeBox(this,
                                  joint_p->getMin()->x - 500.0f, joint_p->getMin()->y, joint_p->getMin()->z - 500.0f,
                                  500.0f + joint_p->getMax()->x, joint_p->getMax()->y, 500.0f + joint_p->getMax()->z);
        }

        dBgS_AcchCir acchcir;
        dBgS_ObjAcch acch;
        acchcir.SetWall(0.0f, 10.0f);
        acch.Set(&current.pos, &old.pos, this, 1, &acchcir, fopAcM_GetSpeed_p(this), NULL, NULL);
        acch.CrrPos(dComIfG_Bgsp());
        mGroundY = acch.GetGroundH();
        mGroundPoly = acch.m_gnd;

        JUTNameTab* nametab_p = mpModel->getModelData()->getJointTree().getJointName();
        for (int i = 0; i < mpModel->getModelData()->getJointNum(); i++) {
            if (strcmp(nametab_p->getName(i), "head") == 0) {
                mHeadJointNo = i;
                break;
            }
        }
    }

    return phase_state;
}

int daObjSCannonTen_c::Delete() {
    if (mpBgW != NULL && mpBgW->ChkUsed()) {
        dComIfG_Bgsp().Release(mpBgW);
    }

    delEmtAll();
    this->~daObjSCannonTen_c();
    return 1;
}

int daObjSCannonTen_c::draw() {
    g_env_light.settingTevStruct(8, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);

    mBck.entry(mpModel->getModelData());

    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(mpModel);
    dComIfGd_setList();

    cXyz sp8(current.pos.x, current.pos.y, current.pos.z);
    mShadowKey = dComIfGd_setShadow(mShadowKey, 1, mpModel, &sp8, 2500.0f, 0.0f, current.pos.y, mGroundY, mGroundPoly, &tevStr, 0, 1.0f, dDlst_shadowControl_c::getSimpleTex());
    return 1;
}

int daObjSCannonTen_c::execute() {
    middleExe();
    return 1;
}

const daObjSCannonTen_c::ExeProc daObjSCannonTen_c::s_exeProc[] = {
    &daObjSCannonTen_c::exeModeWait,
    &daObjSCannonTen_c::exeModeOrderEvt,
    &daObjSCannonTen_c::exeModeActionEvt,
    &daObjSCannonTen_c::exeModeEnd,
};

const daObjSCannonTen_c::ExeProc daObjSCannonTen_c::s_demoExeProc[][2] = {
    {&daObjSCannonTen_c::demoInitLinkIn, &daObjSCannonTen_c::demoExeLinkIn},
    {&daObjSCannonTen_c::demoInitSet, &daObjSCannonTen_c::demoExeSet},
    {&daObjSCannonTen_c::demoInitMove, &daObjSCannonTen_c::demoExeMove},
    {&daObjSCannonTen_c::demoInitFire, &daObjSCannonTen_c::demoExeFire},
    {&daObjSCannonTen_c::demoInitFireEnd, &daObjSCannonTen_c::demoExeFireEnd},
    {&daObjSCannonTen_c::demoInitFinish, &daObjSCannonTen_c::demoExeFinish},
};

void daObjSCannonTen_c::middleExe() {
    if (s_exeProc[mMode] != NULL) {
        (this->*s_exeProc[mMode])();
    }

    setModelMtx();

    mBck.play();
}

void daObjSCannonTen_c::exeModeWait() {
    if (!(DEBUG && aREG_F(0)) && fopAcM_checkHookCarryNow(this) &&
        dComIfGp_checkPlayerStatus1(0, 0x10)) {
        eventInfo.setArchiveName(l_arcName);
        mEvtIdx = (s16)dComIfGp_getEventManager().getEventIdx(this, l_eventName, 0xFF);
#if DEBUG
        if (mEvtIdx == -1) {
            // "××××××××××××× Sky Cannon (City in the Sky) d_a_obj_scannon_ten.cpp: Failed to get event\n"
            OS_REPORT("×××××××××天空砲台(天空都市) d_a_obj_scannon_ten.cpp:イベント取得失敗\n");
            return;
        }
#endif

        fopAcM_orderOtherEventId(this, mEvtIdx, 0xFF, 0xFFFF, 0, 1);
        eventInfo.onCondition(dEvtCnd_CANDEMO_e);
        mMode = MODE_ORDER_EVT;
    }
}

void daObjSCannonTen_c::exeModeOrderEvt() {
    if (eventInfo.checkCommandDemoAccrpt()) {
        mStaffId = dComIfGp_evmng_getMyStaffId(l_staffName, NULL, 0);
        mMode = MODE_ACTION_EVT;
        demoModeInit(0);
    } else {
        fopAcM_orderOtherEventId(this, mEvtIdx, 0xFF, 0xFFFF, 0, 1);
        eventInfo.onCondition(dEvtCnd_CANDEMO_e);
    }
}

void daObjSCannonTen_c::exeModeActionEvt() {
    if (dComIfGp_evmng_endCheck(mEvtIdx) != 0) {
        dComIfGp_event_reset();
        mMode = MODE_END;
    } else {
        dComIfGp_getEvent()->setSkipProc(this, eventCallBack, 0);
        demoExe();
    }
}

void daObjSCannonTen_c::exeModeEnd() {}

void daObjSCannonTen_c::demoExe() {
    static char* CUT_TYPE_TABLE_FIRE_SECOND[6] = {
        "LINK_IN",
        "SET",
        "MOVE",
        "FIRE",
        "FIRE_END",
        "FINISH",
    };

    int act_idx = dComIfGp_evmng_getMyActIdx(mStaffId, CUT_TYPE_TABLE_FIRE_SECOND, ARRAY_SIZE(CUT_TYPE_TABLE_FIRE_SECOND), 0, 0);
    if (act_idx != -1) {
        if (dComIfGp_evmng_getIsAddvance(mStaffId)) {
            demoModeInit(act_idx);
        }

        if (s_demoExeProc[act_idx][1] != NULL) {
            (this->*s_demoExeProc[act_idx][1])();
        }
    }
}

void daObjSCannonTen_c::demoModeInit(int i_actIdx) {
    if (i_actIdx < 0 || i_actIdx >= 6) {
        return;
    }

    if (s_demoExeProc[i_actIdx][0] != NULL) {
        (this->*s_demoExeProc[i_actIdx][0])();
    }
}

void daObjSCannonTen_c::demoInitLinkIn() {}

void daObjSCannonTen_c::demoExeLinkIn() {
    if (!fopAcM_checkHookCarryNow(this)) {
        daPy_py_c* player_p = daPy_getPlayerActorClass();
        if (player_p != NULL) {
            player_p->onPlayerNoDraw();
            player_p->onPlayerShadowNoDraw();

            cXyz pos(12.100221f, 264.13156f, 12069.783f);
            player_p->setPlayerPosAndAngle(&pos, player_p->shape_angle.y, 0);
            mpBgW->OffRoofRegist();
        }
        dComIfGp_evmng_cutEnd(mStaffId);
    }
}

void daObjSCannonTen_c::demoInitSet() {
    fopAcM_seStartCurrent(this, Z2SE_OBJ_TCANNON_ACTION_L7, 0);
    mBck.setPlaySpeed(1.0f);
    initEmtSmoke();
    dComIfGp_getVibration().StartShock(VIBMODE_S_POWER3, 0x1F, cXyz(0.0f, 1.0f, 0.0f));
}

void daObjSCannonTen_c::demoExeSet() {
    exeEmtSmoke();
    if (mBck.checkFrame(84)) {
        dComIfGp_getVibration().StartShock(VIBMODE_S_POWER5, 0x1F, cXyz(0.0f, 1.0f, 0.0f));
        dComIfGp_evmng_cutEnd(mStaffId);
    }
}

void daObjSCannonTen_c::demoInitMove() {}

void daObjSCannonTen_c::demoExeMove() {
    exeEmtSmoke();
    if (mBck.checkFrame(104.0f)) {
        dComIfGp_getVibration().StartShock(VIBMODE_S_POWER5, 0x1F, cXyz(0.0f, 1.0f, 0.0f));
    } else if (mBck.checkFrame(120.0f)) {
        dComIfGp_getVibration().StartShock(VIBMODE_S_POWER5, 0x1F, cXyz(0.0f, 1.0f, 0.0f));
    } else if (mBck.checkFrame(138.0f)) {
        dComIfGp_evmng_cutEnd(mStaffId);
    }
}

void daObjSCannonTen_c::demoInitFire() {
    dComIfGp_getVibration().StartQuake(3, 0x1F, cXyz(0.0f, 1.0f, 0.0f));
}

void daObjSCannonTen_c::demoExeFire() {
    exeEmtSmoke();
    if (mBck.checkFrame(235.0f)) {
        dComIfGp_evmng_cutEnd(mStaffId);
    }
}

void daObjSCannonTen_c::demoInitFireEnd() {
    fopAcM_seStartCurrent(this, Z2SE_OBJ_BOMB_EXPLODE, 0);

    dComIfGp_getVibration().StopQuake(0x1F);
    dComIfGp_getVibration().StartShock(8, 0x1F, cXyz(0.0f, 1.0f, 0.0f));
}

void daObjSCannonTen_c::demoExeFireEnd() {
    exeEmtSmoke();
    if (mBck.checkFrame(255.0f)) {
        dComIfGp_evmng_cutEnd(mStaffId);
    }
}

void daObjSCannonTen_c::demoInitFinish() {
#if DEBUG
    J3DJoint* joint_p = mpModel->getModelData()->getJointNodePointer(mHeadJointNo);
    if (joint_p == NULL) {
        // "××××××Sky Cannon—The head joint is missing!!!! ××××××"
        OS_REPORT("______________________××××××天空砲台 頭部分のジョイントがありません!!!! ××××××____________\n");
        JUT_ASSERT(867, FALSE);
    }
#endif

    mDoAud_seStart(Z2SE_AL_V_CANON_JUMP, NULL, 0, 0);
    initEmtLine();
    fopAcM_OffStatus(this, fopAcStts_NOEXEC_e);

    int* timer_p = dComIfGp_evmng_getMyIntegerP(mStaffId, "Timer");
    if (timer_p != NULL) {
        mTimer = *timer_p;
    } else {
        mTimer = 1;
    }
}

void daObjSCannonTen_c::demoExeFinish() {
    exeEmtSmoke();
    exeEmtLine();

    if (mBck.isStop() && cLib_calcTimer<int>(&mTimer) == 0) {
        dComIfGp_evmng_cutEnd(mStaffId);
        changeScene();
    }
}

void daObjSCannonTen_c::init() {
    mTimer = 0;
    mMode = MODE_WAIT;
    mShadowKey = 0;
}

void daObjSCannonTen_c::setModelMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

void daObjSCannonTen_c::changeScene() {
    if (dComIfGp_getVibration().CheckQuake()) {
        dComIfGp_getVibration().StopQuake(0x1F);
    }

    fopAcM_OnStatus(this, fopAcStts_NOEXEC_e);

    const int a_exit_id = 1;
    dStage_changeScene(a_exit_id, 0.0f, 0, fopAcM_GetRoomNo(this), 0, -1);
}

void daObjSCannonTen_c::initEmtSmoke() {
    static const u16 PARTICLE_NAME[] = {
        dPa_RM(ID_ZF_S_SKYCANNON00_SMK),
        dPa_RM(ID_ZF_S_SKYCANNON01_SMK),
        dPa_RM(ID_ZF_S_SKYCANNON02_SMK),
    };

    MtxP mtx = mpModel->getAnmMtx(mHeadJointNo);
    if (mtx != NULL) {
        cXyz pos(mtx[0][3], mtx[1][3], mtx[2][3]);
        csXyz rot(current.angle);
        cXyz size(1.0f, 1.0f, 1.0f);

        for (int i = 0; i < ARRAY_SIZE(mpEmtSmk); i++) {
            mpEmtSmk[i] = dComIfGp_particle_set(PARTICLE_NAME[i], &pos, &rot, &size);
            if (mpEmtSmk[i] != NULL) {
                mpEmtSmk[i]->setGlobalRTMatrix(mtx);
            }
        }
    }
}

void daObjSCannonTen_c::exeEmtSmoke() {
    MtxP mtx = mpModel->getAnmMtx(mHeadJointNo);
    if (mtx != NULL) {
        for (int i = 0; i < ARRAY_SIZE(mpEmtSmk); i++) {
            if (mpEmtSmk[i] != NULL) {
                mpEmtSmk[i]->setGlobalRTMatrix(mtx);
            }
        }
    }
}

void daObjSCannonTen_c::initEmtLine() {
    cXyz pos;
    csXyz rot;

    camera_process_class* camera_p = dComIfGp_getCamera(dComIfGp_getPlayerCameraID(0));
    if (camera_p != NULL) {
        pos = *fopCamM_GetEye_p(camera_p);
        rot.set(dCam_getAngleX(camera_p), dCam_getAngleY(camera_p), 0);
    }

    mpEmtLine = dComIfGp_particle_set(dPa_RM(ID_ZF_S_TOBYCANNON00LINE), &pos, &tevStr, &rot, NULL);
}

void daObjSCannonTen_c::exeEmtLine() {
    cXyz pos;
    JGeometry::TVec3<s16> rot;
    if (mpEmtLine != NULL) {
        camera_process_class* camera_p = dComIfGp_getCamera(dComIfGp_getPlayerCameraID(0));
        if (camera_p != NULL) {
            pos = *fopCamM_GetEye_p(camera_p);
            rot.x = dCam_getAngleX(camera_p);
            rot.y = dCam_getAngleY(camera_p);
            rot.z = 0;
        }
        mpEmtLine->setGlobalTranslation(pos.x, pos.y, pos.z);
        mpEmtLine->setGlobalRotation(rot);
    }
}

void daObjSCannonTen_c::delEmtAll() {
    if (mpEmtLine != NULL) {
        mpEmtLine->becomeInvalidEmitter();
        mpEmtLine->quitImmortalEmitter();
        mpEmtLine = NULL;
    }
}

static int daObjSCannonTen_create(daObjSCannonTen_c* i_this) {
    fopAcM_ct(i_this, daObjSCannonTen_c);
    return i_this->create();
}

static int daObjSCannonTen_Delete(daObjSCannonTen_c* i_this) {
    return i_this->Delete();
}

static int daObjSCannonTen_execute(daObjSCannonTen_c* i_this) {
    return i_this->execute();
}

static int daObjSCannonTen_draw(daObjSCannonTen_c* i_this) {
    return i_this->draw();
}

static actor_method_class daObjSCannonTen_METHODS = {
    (process_method_func)daObjSCannonTen_create,
    (process_method_func)daObjSCannonTen_Delete,
    (process_method_func)daObjSCannonTen_execute,
    0,
    (process_method_func)daObjSCannonTen_draw,
};

actor_process_profile_definition g_profile_Obj_SCannonTen = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 7,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_SCannonTen_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjSCannonTen_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_SCannonTen_e,
    /* Actor SubMtd */ &daObjSCannonTen_METHODS,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_CULL_e | fopAcStts_NOEXEC_e,
    /* Group        */ fopAc_ENV_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};