summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_dr.cpp
blob: 436c879cd3d7f5e27d45ff98200dcecc4128e09c (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
/**
 * d_a_dr.cpp
 * Valoo / ドラゴン (Dragon)
 */

#include "d/actor/d_a_dr.h"
#include "d/res/res_dr.h"
#include "f_op/f_op_actor_mng.h"
#include "d/d_procname.h"
#include "m_Do/m_Do_ext.h"
#include "m_Do/m_Do_mtx.h"
#include "m_Do/m_Do_hostIO.h"
#include "d/d_snap.h"
#include "d/d_com_inf_game.h"

static daDr_HIO_c l_HIO;

/* 000000EC-00000148       .text __ct__10daDr_HIO_cFv */
daDr_HIO_c::daDr_HIO_c() {
    mNo = -1;
    mScale = 1.0f;
    m0C = false;
    m0E = 10*30;
    mWait1Morf = 10.0f;
    mAkubi1Morf = 10.0f;
    mBiku1Morf = 2.0f;
    mAbare1Morf = 5.0f;
    mAbare2Morf = 5.0f;
    mHo1Morf = 10.0f;
}

/* 00000148-000001DC       .text daDr_Draw__FP8dr_class */
static BOOL daDr_Draw(dr_class* i_this) {
    J3DModel* model = i_this->mpMorf->getModel();
    g_env_light.settingTevStruct(TEV_TYPE_ACTOR, &i_this->current.pos, &i_this->tevStr);
    g_env_light.setLightTevColorType(model, &i_this->tevStr);
    i_this->mpMorf->entryDL();
    dSnap_RegistFig(DSNAP_TYPE_DR, i_this, i_this->eyePos, i_this->shape_angle.y, 1.0f, 1.0f, 1.0f);
    return TRUE;
}

/* 000001DC-00000320       .text anm_init__FP8dr_classifUcfi */
static void anm_init(dr_class* i_this, int bckFileIdx, f32 morf, u8 loopMode, f32 speed, int soundFileIdx) {
    if (i_this->mCurrBckIdx == bckFileIdx) {
        morf = 0.0f;
    }
    if (soundFileIdx >= 0) {
        void* soundAnm = dComIfG_getObjectRes("Dr", soundFileIdx);
        J3DAnmTransform* bckAnm = (J3DAnmTransform*)dComIfG_getObjectRes("Dr", bckFileIdx);
        i_this->mpMorf->setAnm(bckAnm, loopMode, morf, speed, 0.0f, -1.0f, soundAnm);
    } else {
        J3DAnmTransform* bckAnm = (J3DAnmTransform*)dComIfG_getObjectRes("Dr", bckFileIdx);
        i_this->mpMorf->setAnm(bckAnm, loopMode, morf, speed, 0.0f, -1.0f, NULL);
    }
    i_this->mCurrBckIdx = bckFileIdx;
}

/* 00000320-0000091C       .text move__FP8dr_class */
static void move(dr_class* i_this) {
    bool isIdle = false;
    switch (i_this->mState) {
    case 0:
        isIdle = true;
        anm_init(i_this, DR_BCK_DR_WAIT1, l_HIO.mWait1Morf, J3DFrameCtrl::LOOP_REPEAT_e, 1.0f, -1);
        i_this->mState++;
        i_this->mCountDownTimers[0] = (s16)(200.0f + cM_rndF(200.0f));
        break;
    case 1:
        isIdle = true;
        if (i_this->mCountDownTimers[0] == 0) {
            anm_init(i_this, DR_BCK_DR_AKUBI1, l_HIO.mAkubi1Morf, J3DFrameCtrl::LOOP_ONCE_e, 1.0f, DR_BAS_AKUBI1);
            i_this->mState++;
        }
        break;
    case 2:
        isIdle = true;
        if (i_this->mpMorf->isStop()) {
            i_this->mState = 0;
        }
        break;
    case 10:
        anm_init(i_this, DR_BCK_DR_BIKU1, l_HIO.mBiku1Morf, J3DFrameCtrl::LOOP_ONCE_e, 1.0f, DR_BAS_BIKU1);
        i_this->mState++;
        i_this->mCountDownTimers[0] = l_HIO.m0E;
        i_this->mpBreathEmitter = dComIfGp_particle_set(dPa_name::ID_SCENE_81C4, &i_this->current.pos);
        i_this->m2C9 = 0;
        // Fall-through
    case 11:
        if (i_this->m2C9 == 0 && (int)i_this->mpMorf->getFrame() == 15) {
            i_this->mCountDownTimers[1] = 5;
        }
        
        if (i_this->mpMorf->isStop()) {
            i_this->m2C9 = 1;
            if (i_this->mpBreathEmitter) {
                i_this->mpBreathEmitter->becomeInvalidEmitter();
                i_this->mpBreathEmitter = NULL;
            }
            
            if (i_this->mCountDownTimers[0] != 0) {
                if (cM_rndF(1.0f) < 0.5f) {
                    anm_init(i_this, DR_BCK_DR_ABARE1, l_HIO.mAbare1Morf, J3DFrameCtrl::LOOP_ONCE_e, 1.0f, DR_BAS_ABARE1);
                    i_this->mpBreathEmitter = dComIfGp_particle_set(dPa_name::ID_SCENE_81C5, &i_this->current.pos);
                    i_this->mCountDownTimers[1] = 500;
                } else {
                    anm_init(i_this, DR_BCK_DR_ABARE2, l_HIO.mAbare2Morf, J3DFrameCtrl::LOOP_ONCE_e, 1.0f, DR_BAS_ABARE2);
                    
                    cXyz rootPos;
                    cXyz offset(0.0f, 0.0f, 0.0f);
                    MtxP rootJntMtx = i_this->mpMorf->getModel()->getAnmMtx(0x00); // dr_all_root joint
                    cMtx_copy(rootJntMtx, *calc_mtx);
                    MtxPosition(&offset, &rootPos);
                    dComIfGp_particle_set(dPa_name::ID_SCENE_81C7, &rootPos);
                    
                    fopAcM_seStart(i_this, JA_SE_CM_DRG_MTOP_MAGMA, 0);
                    i_this->mCountDownTimers[1] = 0;
                }
            } else {
                anm_init(i_this, DR_BCK_DR_HO1, l_HIO.mHo1Morf, J3DFrameCtrl::LOOP_ONCE_e, 1.0f, -1);
                i_this->mpBreathEmitter = dComIfGp_particle_set(dPa_name::ID_SCENE_81C6, &i_this->current.pos);
                i_this->mState++;
            }
        }
        
        if (i_this->mpBreathEmitter) {
            MtxP tongueJntMtx = i_this->mpMorf->getModel()->getAnmMtx(0x20); // j_dr_sita2 (tongue) joint
            i_this->mpBreathEmitter->setGlobalRTMatrix(tongueJntMtx);
        }
        break;
    case 12:
        if (i_this->mpBreathEmitter) {
            MtxP tongueJntMtx = i_this->mpMorf->getModel()->getAnmMtx(0x20); // j_dr_sita2 (tongue) joint
            i_this->mpBreathEmitter->setGlobalRTMatrix(tongueJntMtx);
        }
        
        if ((int)i_this->mpMorf->getFrame() == 34) {
            i_this->mCountDownTimers[1] = 5;
        }
        
        if (i_this->mpMorf->isStop()) {
            i_this->mState = 0;
            if (i_this->mpBreathEmitter) {
                i_this->mpBreathEmitter->becomeInvalidEmitter();
                i_this->mpBreathEmitter = NULL;
            }
        }
        break;
    }
    
    if (!dComIfGs_isStageBossEnemy(dSv_save_c::STAGE_DRC)) {
        if ((isIdle && (l_HIO.m0C || dComIfGp_getVibration().CheckQuake())) || i_this->m2C8 != 0) {
            l_HIO.m0C = false;
            i_this->m2C8 = 0;
            i_this->mState = 10;
        }
    }
    
    i_this->mpMorf->play(&i_this->current.pos, 0, 0);
    
    if (i_this->mCountDownTimers[1] != 0) {
        fopAcM_seStart(i_this, JA_SE_CM_DRG_MTOP_FIRE, 0);
    }
}

/* 0000091C-000009CC       .text daDr_setMtx__FP8dr_class */
static void daDr_setMtx(dr_class* i_this) {
    J3DModel* model = i_this->mpMorf->getModel();
    model->setBaseScale(i_this->scale);
    mDoMtx_stack_c::transS(i_this->current.pos);
    cMtx_YrotM(mDoMtx_stack_c::get(), i_this->current.angle.y);
    cMtx_XrotM(mDoMtx_stack_c::get(), i_this->current.angle.x);
    cMtx_ZrotM(mDoMtx_stack_c::get(), i_this->current.angle.z);
    model->setBaseTRMtx(mDoMtx_stack_c::get());
    
    i_this->mpMorf->calc();
}

/* 000009CC-00000A8C       .text daDr_Execute__FP8dr_class */
static BOOL daDr_Execute(dr_class* i_this) {
    for (int i = 0; i < ARRAY_SIZE(i_this->mCountDownTimers); i++) {
        if (i_this->mCountDownTimers[i] != 0) {
            i_this->mCountDownTimers[i]--;
        }
    }
    
    move(i_this);
    
    i_this->scale.x = i_this->scale.y = i_this->scale.z = l_HIO.mScale;
    
    daDr_setMtx(i_this);
    
    MtxP tongueJntMtx = i_this->mpMorf->getModel()->getAnmMtx(0x20); // j_dr_sita2 (tongue) joint
    cMtx_copy(tongueJntMtx, *calc_mtx);
    cXyz offset(0.0f, 0.0f, 0.0f);
    MtxPosition(&offset, &i_this->eyePos);
    
    return TRUE;
}

/* 00000A8C-00000A94       .text daDr_IsDelete__FP8dr_class */
static BOOL daDr_IsDelete(dr_class* i_this) {
    return TRUE;
}

/* 00000A94-00000AE8       .text daDr_Delete__FP8dr_class */
static BOOL daDr_Delete(dr_class* i_this) {
    dComIfG_resDelete(&i_this->mPhs, "Dr");
    if (l_HIO.mNo >= 0) {
        mDoHIO_deleteChild(l_HIO.mNo);
    }
    return TRUE;
}

/* 00000AE8-00000C08       .text createHeap__FP10fopAc_ac_c */
static BOOL createHeap(fopAc_ac_c* i_actor) {
    dr_class* i_this = (dr_class*)i_actor;

    i_this->mpMorf = new mDoExt_McaMorf(
        (J3DModelData*)dComIfG_getObjectRes("Dr", DR_BMD_DR1),
        NULL, NULL,
        (J3DAnmTransformKey*)dComIfG_getObjectRes("Dr", DR_BCK_DR_BIKU1),
        J3DFrameCtrl::LOOP_ONCE_e, 1.0f, 0, -1, 1,
        dComIfG_getObjectRes("Dr", DR_BAS_BIKU1),
        0x00000000,
        0x11020203
    );
    if (!i_this->mpMorf || !i_this->mpMorf->getModel()) {
        return FALSE;
    }
    
    return TRUE;
}

/* 00000C08-00000CE4       .text daDr_Create__FP10fopAc_ac_c */
static s32 daDr_Create(fopAc_ac_c* i_actor) {
    fopAcM_SetupActor(i_actor, dr_class);
    
    dr_class* i_this = (dr_class*)i_actor;
    
    s32 phase_state = dComIfG_resLoad(&i_this->mPhs, "Dr");
    if (phase_state == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(i_this, createHeap, 0xF000)) {
            return cPhs_ERROR_e;
        }
        
        daDr_setMtx(i_this);
        
        if (l_HIO.mNo < 0) {
            l_HIO.mNo = mDoHIO_createChild("ドラゴン", &l_HIO); // "Dragon"
        }
    }
    
    return phase_state;
}

static actor_method_class l_daDr_Method = {
    (process_method_func)daDr_Create,
    (process_method_func)daDr_Delete,
    (process_method_func)daDr_Execute,
    (process_method_func)daDr_IsDelete,
    (process_method_func)daDr_Draw,
};

actor_process_profile_definition g_profile_DR = {
    /* LayerID      */ fpcLy_CURRENT_e,
    /* ListID       */ 0x0007,
    /* ListPrio     */ fpcPi_CURRENT_e,
    /* ProcName     */ PROC_DR,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(dr_class),
    /* SizeOther    */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Priority     */ 0x00D2,
    /* Actor SubMtd */ &l_daDr_Method,
    /* Status       */ fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* CullType     */ fopAc_CULLBOX_CUSTOM_e,
};