summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_tornado.cpp
blob: 270ebf252efe7f8d2b2d0bf98c6a30e2430e7bca (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
/**
 * d_a_tornado.cpp
 * Object - Ballad of Gales tornado
 */

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_tornado.h"
#include "res/Object/Trnd.h"
#include "f_op/f_op_actor_mng.h"
#include "m_Do/m_Do_ext.h"
#include "d/d_com_inf_game.h"
#include "d/actor/d_a_ship.h"
#include "d/d_kankyo_wether.h"

static char l_arcName[] = "Trnd";

const float daTornado_HIO_c0::move_dis = 7500.0f;
const float daTornado_HIO_c0::start_dis = 10000.0f;

/* 000000EC-00000260       .text jointCallBack__11daTornado_cFi */
BOOL daTornado_c::jointCallBack(int jntNo) {
    int jntIdx = jntNo - 1;
    if ((jntIdx < YTRND00_JNT_ROOT_e) || (jntIdx >= YTRND00_JNT_JOINT11_e)) {
        return TRUE;
    }

    mDoMtx_stack_c::transS(mJointX[jntIdx], 0.0f, mJointZ[jntIdx]);
    if (jntIdx != YTRND00_JNT_JOINT10_e && jntIdx != YTRND00_JNT_ROOT_e) {
        mDoMtx_stack_c::ZXYrotM(-mJointZ[jntIdx] * 3572.0f * 0.001f, 0.0f, mJointX[jntIdx] * 3572.0f * 0.001f);
    }

    if (fopAcM_GetParam(this) != 0) {
        float scale = mJointScale[jntIdx];
        mDoMtx_stack_c::scaleM(scale, scale, scale);
    }
    mDoMtx_stack_c::revConcat(mpModel->getAnmMtx(jntNo));
    mpModel->setAnmMtx(jntNo, mDoMtx_stack_c::get());
    mDoMtx_stack_c::transS(mJointX[jntIdx], 0.0f, mJointZ[jntIdx]);
    mDoMtx_stack_c::revConcat(J3DSys::mCurrentMtx);
    cMtx_copy(mDoMtx_stack_c::get(), J3DSys::mCurrentMtx);
    return TRUE;
}

static const float l_joint_scale[11] = { 0.1f, 0.4f, 0.7f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };

static daTornado_HIO_c0 l_HIO;

/* 00000260-000002A4       .text daTornado_jointCallBack__FP7J3DNodei */
static BOOL daTornado_jointCallBack(J3DNode* node, int calcTiming) {
    if (calcTiming == J3DNodeCBCalcTiming_In) {
        J3DJoint* joint = (J3DJoint*)node;
        s32 jntNo = joint->getJntNo();
        J3DModel* model = j3dSys.getModel();
        daTornado_c* i_this = reinterpret_cast<daTornado_c*>(model->getUserArea());
        i_this->jointCallBack(jntNo);
    }
    return TRUE;
}

/* 000002A4-00000464       .text draw__11daTornado_cFv */
BOOL daTornado_c::draw() {
    g_env_light.settingTevStruct(TEV_TYPE_ACTOR, &current.pos, &tevStr);
    g_env_light.setLightTevColorType(mpModel, &tevStr);

    mBck.entry(mpModel->getModelData());
    mBtk.entry(mpModel->getModelData(), mBtkFrame);
    mBrk.entry(mpModel->getModelData(), mBrkFrame);

    if (dComIfGs_isTmpBit(dSv_event_tmp_flag_c::UNK_0404)) {
        dComIfGd_setListMaskOff();
        mDoExt_modelUpdateDL(mpModel);
        dComIfGd_setList();
    } else {
        mDoExt_modelUpdateDL(mpModel);
    }

    if (fopAcM_GetParam(this) == 0) {
        g_env_light.settingTevStruct(TEV_TYPE_BG1, &current.pos, &tevStr);
        g_env_light.setLightTevColorType(mpModelUnder, &tevStr);

        mBckUnder.entry(mpModelUnder->getModelData(), mBck.getFrame());
        mBtkUnder.entry(mpModelUnder->getModelData(), mBtkUnderFrame);
        mBrkUnder.entry(mpModelUnder->getModelData(), mBrkFrame);

        dComIfGd_setListMaskOff();
        mDoExt_modelUpdateDL(mpModelUnder);
        dComIfGd_setList();
    }

    return TRUE;
}

/* 00000464-00000484       .text daTornado_Draw__FP11daTornado_c */
static BOOL daTornado_Draw(daTornado_c* i_this) {
    return i_this->draw();
}

/* 00000484-00000C4C       .text execute__11daTornado_cFv */
BOOL daTornado_c::execute() {
    static cXyz wind_scale(20.0f,20.0f,20.0f);

    mBck.play();
    mBtkFrame += 1.0f;
    if (mBtkFrame >= mBtk.getBtkAnm()->getFrameMax()) {
        mBtkFrame -= mBtk.getBtkAnm()->getFrameMax();
    }

    mBtkUnderFrame += 1.0f;
    if (mBtkUnderFrame >= mBtkUnder.getBtkAnm()->getFrameMax()) {
        mBtkUnderFrame -= mBtkUnder.getBtkAnm()->getFrameMax();
    }
    mAngle2 += 250;
    mAngle1 += 500;
    m32c = 10000.0f;
    u32 param = fopAcM_GetParam(this);
    f32 fVar8;
    if (param == 1) {
        if (dComIfGp_getShipActor() != NULL) {
            fVar8 = (dComIfGp_getShipActor()->current.pos.y - home.pos.y) / 500.0f;
            if (fVar8 < 0.0f) {
                fVar8 = 0.0f;
            } else {
                if (fVar8 > 1.0f) {
                    fVar8 = 1.0f;
                }
            }
        } else {
            fVar8 = 1.0f;
        }
    } else if (param == 0 && dComIfGp_getShipActor() != NULL && dComIfGp_getShipActor()->getTornadoActor() != NULL) {
        fVar8 = 0.25f;
    } else {
        fVar8 = 1.0f;
    }

    for (int i = 0; i < 11; i++) {
        static const f32 joint_offset[11] = { 100.0f, 200.0f, 300.0f, 400.0f, 300.0f, 300.0f, 400.0f, 500.0f, 400.0f, 500.0f, 600.0f };
        f32 fVar1 = (fVar8 * joint_offset[i]) * ((cM_ssin(mAngle1 - 0x1000 * i)) + 1.0f);
        s16 angle2 = mAngle2 - 0x1800 * i;
        mJointX[i] = cM_ssin(angle2) * fVar1 * scale.x;
        mJointZ[i] = cM_scos(angle2) * fVar1 * scale.x;
    }

    param = fopAcM_GetParam(this);
    if (param == 0) {
        if (!dComIfGp_event_runCheck()) {
            s16 target = fopAcM_searchActorAngleY(this, dComIfGp_getLinkPlayer());
            cLib_addCalcAngleS(&current.angle.y, target, 10, 0x1000, 0x100);
            cLib_chaseF(&speedF, 20.0f, 0.2f);
        }
        if (dComIfGp_checkPlayerStatus0(0, daPyStts0_SHIP_RIDE_e) && dComIfGp_getShipActor() != NULL) {
            daShip_c* ship = dComIfGp_getShipActor();
            cXyz diff = ship->current.pos - current.pos;
            if (diff.abs2XZ() < SQUARE(10000.0f)) {
                ship->onTornadoFlg(fopAcM_GetID(this));
                speedF = 0.0f;
            }
        }

        if (!dComIfGp_event_runCheck()) {
            fopAcM_posMoveF(this, NULL);
            cXyz diff = current.pos - home.pos;
            diff.y = 0;
            if (diff.abs2XZ() > SQUARE(7500.0f)) {
                diff.normalize();
                current.pos = home.pos + diff * 7500.0f;
            }
        }

        if (mPtclTimer != 0) {
            mPtclTimer -= 1;
        } else {
            mPtclTimer = 10;
            dComIfGp_particle_set(dPa_name::ID_AK_SN_TORNADOWIND00, &current.pos, NULL, (cXyz*)&wind_scale);
        }

        fopAcM_seStartCurrent(this, JA_SE_OBJ_TORNADE_SUS, 100);

        if (dComIfGs_isEventBit(dSv_event_flag_c::UNK_2710)) {
            mPtclCb.remove();
            daShip_c* ship = dComIfGp_getShipActor();
            if (ship != NULL) {
                ship->offTornadoFlg();
            }
            mBrkFrame += 0.3f;
            if (mBrkFrame >= mBrk.getBrkAnm()->getFrameMax()) {
                fopAcM_delete(this);
            }
        } else {
            dKyw_tornado_Notice(&current.pos);
        }
    } else if (param == 1) {
        if (m31c != 0) {
            for (int i = 0; i < 11; i++) {
                cLib_chaseF(&mJointScale[i], l_joint_scale[i], (11-i)*0.007f);
                mJointX[i] *= mJointScale[i];
                mJointZ[i] *= mJointScale[i];
            }
        }
    } else if (m31c != 0) {
        for (int i = 0; i < 11; i++) {
            cLib_chaseF(&mJointScale[i], 0.0f, (i + 1) * 0.001f);
            mJointX[i] *= mJointScale[i];
            mJointZ[i] *= mJointScale[i];
        }
        if (mJointScale[10] < 1e-06f) {
            fopAcM_delete(this);
            return TRUE;
        }
    }
    mDoMtx_stack_c::transS(current.pos);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
    attention_info.position = current.pos;
    eyePos = current.pos;
    mCenter.set(current.pos.x + mJointX[0], current.pos.y, current.pos.z + mJointZ[0]);
    if (mPtclCb.getEmitter() != NULL) {
        GXColor colorAmb, colorDif;
        dKy_get_seacolor(&colorAmb, &colorDif);
        mPtclCb.getEmitter()->setGlobalPrmColor(colorAmb.r, colorAmb.g, colorAmb.b);
    }
    mDoMtx_stack_c::transS(mCenter);
    mpModelUnder->setBaseTRMtx(mDoMtx_stack_c::get());

    return TRUE;
}

/* 00000C88-00000CA8       .text daTornado_Execute__FP11daTornado_c */
static BOOL daTornado_Execute(daTornado_c* i_this) {
    return i_this->execute();
}

/* 00000CA8-00000CB0       .text daTornado_IsDelete__FP11daTornado_c */
static BOOL daTornado_IsDelete(daTornado_c*) {
    return TRUE;
}

/* 00000CB0-00000D30       .text tornado_delete__11daTornado_cFv */
BOOL daTornado_c::tornado_delete() {
    mPtclCb.remove();
    if (fopAcM_GetParam(this) == 0 && dComIfGp_getShipActor() != NULL) {
        dComIfGp_getShipActor()->offTornadoFlg();
    }
    dComIfG_resDelete(&mPhs, l_arcName);
    return TRUE;
}

/* 00000D30-00000D54       .text daTornado_Delete__FP11daTornado_c */
static BOOL daTornado_Delete(daTornado_c* i_this) {
    i_this->tornado_delete();
    return TRUE;
}

/* 00000D54-0000109C       .text createHeap__11daTornado_cFv */
BOOL daTornado_c::createHeap() {
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes(l_arcName, dRes_INDEX_TRND_BDL_YTRND00_e);
    JUT_ASSERT(0x1fe, modelData != NULL);
    mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000202);
    if (!mpModel)
        return FALSE;
    if (!mBck.init(modelData, (J3DAnmTransform*)dComIfG_getObjectRes(l_arcName, dRes_INDEX_TRND_BCK_YTRND00_e), true, J3DFrameCtrl::EMode_LOOP))
        return FALSE;
    if (!mBtk.init(modelData, (J3DAnmTextureSRTKey*)dComIfG_getObjectRes(l_arcName, dRes_INDEX_TRND_BTK_YTRND00_e), false, J3DFrameCtrl::EMode_LOOP))
        return FALSE;
    if (!mBrk.init(modelData, (J3DAnmTevRegKey*)dComIfG_getObjectRes(l_arcName, dRes_INDEX_TRND_BRK_YTRND00_e), false, J3DFrameCtrl::EMode_LOOP))
        return FALSE;

    modelData = (J3DModelData*)dComIfG_getObjectRes(l_arcName, dRes_INDEX_TRND_BDL_YWUWT00_e);
    JUT_ASSERT(0x226, modelData != NULL);
    mpModelUnder = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000202);
    if (!mpModelUnder)
        return FALSE;
    if (!mBckUnder.init(modelData, (J3DAnmTransform*)dComIfG_getObjectRes(l_arcName, dRes_INDEX_TRND_BCK_YWUWT00_e), false, J3DFrameCtrl::EMode_LOOP))
        return FALSE;
    if (!mBtkUnder.init(modelData, (J3DAnmTextureSRTKey*)dComIfG_getObjectRes(l_arcName, dRes_INDEX_TRND_BTK_YWUWT00_e), false, J3DFrameCtrl::EMode_LOOP))
        return FALSE;
    if (!mBrkUnder.init(modelData, (J3DAnmTevRegKey*)dComIfG_getObjectRes(l_arcName, dRes_INDEX_TRND_BRK_YWUWT00_e), false, J3DFrameCtrl::EMode_LOOP))
        return FALSE;

    return TRUE;
}

/* 0000109C-000010BC       .text daTornado_createHeap__FP10fopAc_ac_c */
static BOOL daTornado_createHeap(fopAc_ac_c* i_this) {
    return ((daTornado_c*)i_this)->createHeap();
}

/* 000010BC-000014D0       .text create__11daTornado_cFv */
cPhs_State daTornado_c::create() {
    static cXyz small_scale(0.25f, 0.175f, 0.25f);
    static cXyz under_small_scale(0.251f, 0.25f, 0.251f);
    static cXyz under_scale(1.01f, 1.0f, 1.01f);

    cPhs_State rt = dComIfG_resLoad(&mPhs, l_arcName);
    fopAcM_ct(this, daTornado_c);

    if (rt == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, daTornado_createHeap, 0x8000)) {
            return cPhs_ERROR_e;
        }

        u32 param = fopAcM_GetParam(this);
        if (param == 1) {
            current.pos.y -= 2000.0f;
            mpModel->setBaseScale(small_scale);
            mpModelUnder->setBaseScale(under_small_scale);
        } else if (param == 2) {
            mpModel->setBaseScale(small_scale);
            mpModelUnder->setBaseScale(under_small_scale);
            for (int i=0; i<11; i++) {
                mJointScale[i] = l_joint_scale[i];
            }
        } else {
            fopAcM_SetParam(this, 0);
            if (dComIfGs_isEventBit(dSv_event_flag_c::UNK_2710)) {
                return cPhs_ERROR_e;
            }
            dKyw_tornado_Notice(&current.pos);
            mpModelUnder->setBaseScale(under_scale);
            mCenter = current.pos;
            dComIfGp_particle_set(dPa_name::ID_AK_SN_WINDUPWATER00, &mCenter, NULL, NULL, 0xFF, &mPtclCb);
            fopAcM_OnStatus(this, fopAcStts_SHOWMAP_e);
        }
        mDoMtx_stack_c::transS(current.pos);
        mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
        mpModelUnder->setBaseTRMtx(mDoMtx_stack_c::get());
        J3DModelData* modelData = mpModel->getModelData();
        for (u16 i = 1; i < modelData->getJointNum(); i++) {
            modelData->getJointNodePointer(i)->setCallBack(daTornado_jointCallBack);
        }
        mpModel->setUserArea((u32) this);
    }
    return rt;
}

/* 0000162C-0000164C       .text daTornado_Create__FP10fopAc_ac_c */
static cPhs_State daTornado_Create(fopAc_ac_c* i_this) {
    return ((daTornado_c*)i_this)->create();
}

static actor_method_class l_daTornado_Method = {
    (process_method_func)daTornado_Create,
    (process_method_func)daTornado_Delete,
    (process_method_func)daTornado_Execute,
    (process_method_func)daTornado_IsDelete,
    (process_method_func)daTornado_Draw,
};

actor_process_profile_definition g_profile_TORNADO = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0007,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_TORNADO_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daTornado_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_TORNADO_e,
    /* Actor SubMtd */ &l_daTornado_Method,
    /* Status       */ 0x06 | fopAcStts_UNK4000_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};