summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_kamome2.cpp
blob: ada2cb3a59a6f015fcc51f227e9aafe36bdced81 (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
#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_kamome2.h"
#include "res/Object/Kamome.h"
#include "m_Do/m_Do_ext.h"
#include "d/d_camera.h"
#include "d/d_meter.h"
#include "d/d_snap.h"
#include "d/d_s_play.h"
#include "m_Do/m_Do_hostIO.h"
#include "m_Do/m_Do_ext.h"
#include "m_Do/m_Do_controller_pad.h"
#include "f_op/f_op_camera.h"

class kamome2HIO_c : public JORReflexible {
public:
    kamome2HIO_c() {
        m05 = 0;
        m08 = -2500.0f;
        m0C = 60.0f;
    }
    virtual ~kamome2HIO_c() {}

    void genMessage(JORMContext* ctx) {}

public:
    /* 0x04 */ s8 mNo;
    /* 0x05 */ u8 m05;
    /* 0x08 */ f32 m08;
    /* 0x0C */ f32 m0C;
}; // size = 0x10

static bool hio_set;
static kamome2HIO_c l_HIO;

static void anm_init(kamome2_class* i_this, int anmResIdx, f32 morf, u8 loopMode, f32 playSpeed, int soundResIdx) {
    i_this->mpMorf->setAnm(
        (J3DAnmTransform*)dComIfG_getObjectRes("Kamome", anmResIdx), loopMode, morf, playSpeed, 0.0f, -1.0f, dComIfG_getObjectRes("Kamome", soundResIdx)
    );
}

static BOOL daKamome2_Draw(kamome2_class* i_this) {
    g_env_light.settingTevStruct(dDlst_alphaModel_c::TYPE_SPHERE, &i_this->actor.current.pos, &i_this->actor.tevStr);
    g_env_light.setLightTevColorType(i_this->mpMorf->getModel(), &i_this->actor.tevStr);
    i_this->mpMorf->entryDL();

    J3DModel* pJVar4 = i_this->mpMorf->getModel();
    J3DModel* pJVar3 = i_this->mpModel;

    for (u16 i = 0; i < pJVar4->getModelData()->getJointNum(); i++) {
        pJVar3->setAnmMtx(i, pJVar4->getAnmMtx(i));
    }

    for (u16 i = 0; i < pJVar4->getModelData()->getWEvlpMtxNum(); i++) {
        pJVar3->setWeightAnmMtx(i, pJVar4->getWeightAnmMtx(i));
    }

    cXyz sp08;
    sp08.set(i_this->actor.current.pos.x, i_this->actor.current.pos.y + REG0_F(1) * 10.0f, i_this->actor.current.pos.z);
    i_this->m2A0 = dComIfGd_setRealShadow(i_this->m2A0, 1, i_this->mpModel, &sp08, REG0_F(2) * 10.0f + 500.0f, 0.0f, &i_this->actor.tevStr);
    dSnap_RegistFig(DSNAP_TYPE_KAMOME, &i_this->actor, 1.0f, 1.0f, 1.0f);
    return TRUE;
}

const f64 unused_4206[] = {0.5, 3.0};
const f32 unused_4207[] = {0.5f, 0.04f};

static void kamome2_bgcheck(kamome2_class* i_this) {
    f32 val = 40.0f;

    i_this->actor.current.pos.y -= val;
    i_this->actor.old.pos.y -= val;
    i_this->mAcch.CrrPos(*dComIfG_Bgsp());
    i_this->actor.current.pos.y += val;
    i_this->actor.old.pos.y += val;
}

static void key_move(kamome2_class* i_this) {
    interface_of_controller_pad* pad = &g_mDoCPd_cpadInfo[0];
    f32 fVar3 = pad->mMainStickPosX;
    f32 fVar4 = pad->mMainStickPosY;
    s32 iVar1 = i_this->mpMorf->getFrame();

    switch (i_this->m2AC) {
    case 0:
        i_this->m2BC = 30.0f;
        i_this->m2C0 = unused_4207[0];
        if (!CPad_CHECK_HOLD_A(0) && iVar1 == REG0_S(0) + 9) {
            i_this->m2AC = 1;
            anm_init(i_this, dRes_INDEX_KAMOME_BCK_KA_WAIT1_e, REG0_F(0) + 12.0f, 2, 1.0f, dRes_INDEX_KAMOME_BAS_KA_WAIT1_e);
        }
        break;

    case 1:
        if (CPad_CHECK_HOLD_X(0)) {
            i_this->m2BC = 5.0f;
            i_this->m2C0 = 0.2f;
        } else {
            i_this->m2BC = 20.0f;
            i_this->m2C0 = 0.1f;
        }

        if (CPad_CHECK_HOLD_A(0)) {
            i_this->m2AC = 0;
            anm_init(i_this, dRes_INDEX_KAMOME_BCK_KA_WAIT2_e, 5.0f, 2, 1.0f, dRes_INDEX_KAMOME_BAS_KA_WAIT2_e);
            fopAcM_seStart(&i_this->actor, JA_SE_CV_KAMOME, 0);
        }
        break;
    }

    s16 iVar2 = fVar3 * (REG6_F(10) + -5.0f) * 1000.0f;
    s16 iVar10 = fVar4 * (REG6_F(11) + 5.0f) * 1000.0f;
    s16 uVar9;
    s16 uVar8;
    s16 uVar7;
    s16 uVar6;
    if (std::fabsf(fVar3) > 0.2f) {
        uVar6 = 0x100;
        uVar7 = 0x400;
    } else {
        uVar6 = 0x80;
        uVar7 = 0x80;
    }

    if (std::fabsf(fVar4) > 0.2f) {
        uVar8 = 0x200;
    } else {
        uVar8 = 0x80;
    }

    if (iVar10 > 0 && i_this->mAcch.ChkGroundHit()) {
        iVar10 = 0;
        uVar8 = 0x800;
        uVar9 = 10;
    } else {
        uVar9 = 4;
    }

    cLib_addCalcAngleS2(&i_this->m2DC, iVar2, 10, uVar6);
    cLib_addCalcAngleS2(&i_this->m2DA, iVar10, uVar9, uVar8);
    cLib_addCalc2(&i_this->m314, fVar3 * (REG6_F(12) + -0.4f) * 1000.0f, 1.0f, 50.0f);

    i_this->actor.current.angle.y += (s16)i_this->m314;

    cLib_addCalcAngleS2(&i_this->actor.current.angle.x, iVar10, uVar9, uVar8);
    cLib_addCalcAngleS2(&i_this->actor.current.angle.z, -iVar2, 5, uVar7);
    cLib_addCalcAngleS2(&i_this->m308, i_this->m314 * (REG0_F(8) + -5.0f), 10, 100);
    cLib_addCalc2(&i_this->actor.speedF, i_this->m2BC, 1.0f, i_this->m2C0);

    cXyz sp08;
    sp08.x = 0.0f;
    sp08.y = 0.0f;
    sp08.z = i_this->actor.speedF;
    cMtx_YrotS(*calc_mtx, i_this->actor.current.angle.y);
    cMtx_XrotM(*calc_mtx, i_this->actor.current.angle.x);
    MtxPosition(&sp08, &i_this->actor.speed);

    i_this->actor.current.pos.x += i_this->actor.speed.x;
    i_this->actor.current.pos.y += i_this->actor.speed.y;
    i_this->actor.current.pos.z += i_this->actor.speed.z;

    kamome2_bgcheck(i_this);

    i_this->mSph.SetC(i_this->actor.current.pos);

    dComIfG_Ccsp()->Set(&i_this->mSph);
}

static BOOL daKamome2_Execute(kamome2_class* i_this) {
    fopAc_ac_c* player = dComIfGp_getPlayer(0);
    camera_class* camera = dComIfGp_getCamera(dComIfGp_getPlayerCameraID(0));

    i_this->m2A8++;
    if (l_HIO.m05 == 0) {
        for (s32 i = 0; i < ARRAY_SSIZE(i_this->m2D0); i++) {
            if (i_this->m2D0[i] != 0) {
                i_this->m2D0[i]--;
            }
        }

        if (i_this->m2A4 == 0) {
            key_move(i_this);
        }
        i_this->mpMorf->play(&i_this->actor.eyePos, 0, 0);
    }

    MtxTrans(i_this->actor.current.pos.x, i_this->actor.current.pos.y, i_this->actor.current.pos.z, 0);
    cMtx_YrotM(*calc_mtx, i_this->actor.current.angle.y + i_this->m2DC);
    cMtx_XrotM(*calc_mtx, i_this->actor.current.angle.x + i_this->m2DA);
    cMtx_ZrotM(*calc_mtx, i_this->actor.current.angle.z);

    J3DModel* model = i_this->mpMorf->getModel();
    model->setBaseTRMtx(*calc_mtx);
    i_this->mpMorf->calc();
    model = i_this->mpModel;
    model->setBaseTRMtx(*calc_mtx);

    switch (i_this->m2EC) {
    case 0:
        if (i_this->m2D0[0] == 1) {
            i_this->m2EC = 1;
        }
        break;

    case 1:
        if (!i_this->actor.eventInfo.checkCommandDemoAccrpt()) {
            fopAcM_orderPotentialEvent(&i_this->actor, 2, 0xffff, 0);
            i_this->actor.eventInfo.onCondition(dEvtCnd_UNK2_e);
            break;
        }

        camera->mCamera.Stop();
        dMeter_mtrHide();
        camera->mCamera.SetTrimSize(2);
        i_this->m2EC = 1;
        i_this->m2F0 = i_this->actor.current.pos;
        i_this->m2FC = i_this->actor.current.pos;

    case 2:
        cMtx_YrotS(*calc_mtx, i_this->actor.current.angle.y);
        cMtx_XrotM(*calc_mtx, i_this->actor.current.angle.x);

        cXyz sp2C;
        sp2C.x = 0.0f;
        sp2C.y = 0.0f;
        sp2C.z = l_HIO.m08;
        cXyz sp20;
        MtxPosition(&sp2C, &sp20);
        cLib_addCalc2(&i_this->m2F0.x, i_this->actor.current.pos.x + sp20.x, 0.1f, 1000.0f);
        cLib_addCalc2(&i_this->m2F0.y, i_this->actor.current.pos.y + sp20.y, 0.1f, 1000.0f);
        cLib_addCalc2(&i_this->m2F0.z, i_this->actor.current.pos.z + sp20.z, 0.1f, 1000.0f);

        sp2C.x = i_this->m2DC * 0.015f;
        sp2C.y = i_this->m2DA * -0.01f;
        sp2C.z = 0;
        MtxPosition(&sp2C, &sp20);
        cLib_addCalc2(&i_this->m2FC.x, i_this->actor.current.pos.x + sp20.x, 0.1f, 1000.0f);
        cLib_addCalc2(&i_this->m2FC.y, i_this->actor.current.pos.y + sp20.y, 0.1f, 1000.0f);
        cLib_addCalc2(&i_this->m2FC.z, i_this->actor.current.pos.z + sp20.z, 0.1f, 1000.0f);
        break;
    }

    if (i_this->m2EC != 0) {
        camera->mCamera.Set(i_this->m2FC, i_this->m2F0, i_this->m308, l_HIO.m0C);
    }

    i_this->actor.eyePos = i_this->actor.current.pos;
    return TRUE;
}

static BOOL daKamome2_IsDelete(kamome2_class*) {
    return TRUE;
}

static BOOL daKamome2_Delete(kamome2_class* i_this) {
    dComIfG_deleteObjectRes("Kamome");
    if (i_this->m68C) {
        hio_set = false;
        mDoHIO_deleteChild(l_HIO.mNo);
    }
    return TRUE;
}

static BOOL useHeapInit(fopAc_ac_c* a_this) {
    kamome2_class* i_this = (kamome2_class*)a_this;
    i_this->mpMorf = new mDoExt_McaMorf(
        (J3DModelData*)dComIfG_getObjectRes("Kamome", dRes_INDEX_KAMOME_BDL_KA_e),
        NULL,
        NULL,
        (J3DAnmTransform*)dComIfG_getObjectRes("Kamome", dRes_INDEX_KAMOME_BCK_KA_WAIT1_e),
        J3DFrameCtrl::EMode_LOOP,
        1.0f,
        0,
        -1,
        0x1,
        dComIfG_getObjectRes("Kamome", dRes_INDEX_KAMOME_BAS_KA_WAIT1_e),
        0x80000,
        0x11000002
    );

    if ((i_this->mpMorf == NULL) || (i_this->mpMorf->getModel() == NULL)) {
        return FALSE;
    }

    i_this->mpModel = mDoExt_J3DModel__create(i_this->mpMorf->getModel()->getModelData(), 0x20000, 0x11020203);
    if (i_this->mpModel == NULL) {
        return FALSE;
    }
    return TRUE;
}

static cPhs_State daKamome2_Create(fopAc_ac_c* a_this) {
    static dCcD_SrcSph at_sph_src = {
        // dCcD_SrcGObjInf
        {
            /* Flags             */ 0,
            /* SrcObjAt  Type    */ AT_TYPE_SWORD,
            /* SrcObjAt  Atp     */ 1,
            /* SrcObjAt  SPrm    */ cCcD_AtSPrm_Set_e | cCcD_AtSPrm_VsEnemy_e,
            /* SrcObjTg  Type    */ 0,
            /* SrcObjTg  SPrm    */ 0,
            /* SrcObjCo  SPrm    */ 0,
            /* SrcGObjAt Se      */ 0,
            /* SrcGObjAt HitMark */ dCcG_AtHitMark_None_e,
            /* SrcGObjAt Spl     */ dCcG_At_Spl_UNK0,
            /* SrcGObjAt Mtrl    */ 0,
            /* SrcGObjAt SPrm    */ 0,
            /* SrcGObjTg Se      */ 0,
            /* SrcGObjTg HitMark */ 0,
            /* SrcGObjTg Spl     */ dCcG_Tg_Spl_UNK0,
            /* SrcGObjTg Mtrl    */ 0,
            /* SrcGObjTg SPrm    */ 0,
            /* SrcGObjCo SPrm    */ 0,
        },
        // cM3dGSphS
        {{
            /* Center */ {0.0f, 0.0f, 0.0f},
            /* Radius */ 40.0f,
        }},
    };

    kamome2_class* i_this = (kamome2_class*)a_this;

    cPhs_State iVar1 = dComIfG_resLoad(&i_this->mPhase, "Kamome");
    if (iVar1 == cPhs_COMPLEATE_e) {
        fopAcM_ct(a_this, kamome2_class);

        i_this->m2A4 = fopAcM_GetParam(a_this);
        if (!fopAcM_entrySolidHeap(a_this, useHeapInit, 0x59A0)) {
            return cPhs_ERROR_e;
        }

        fopAcM_SetMtx(a_this, i_this->mpMorf->getModel()->getBaseTRMtx());
        i_this->mAcch.Set(fopAcM_GetPosition_p(a_this), fopAcM_GetOldPosition_p(a_this), a_this, 1, &i_this->mAcchCir, fopAcM_GetSpeed_p(a_this));

        if (i_this->m2A4 == 3) {
            i_this->mAcchCir.SetWall(50.0f, 80.0f);
            i_this->mAcch.SetGroundUpY(40.0f);
        } else {
            i_this->mAcchCir.SetWall(30.0f, 20.0f);
        }
        i_this->mStts.Init(0, 0xff, a_this);
        i_this->mSph.Set(at_sph_src);
        i_this->mSph.SetStts(&i_this->mStts);
        i_this->m2A8 = (s16)cM_rndF(10000.0f);
        if (!hio_set) {
            l_HIO.mNo = mDoHIO_createChild("操作カモメ", &l_HIO);
            i_this->m68C = true;
            hio_set = true;
        }
        i_this->m2D0[0] = 0x1e;
    }

    return iVar1;
}

static actor_method_class l_daKamome2_Method = {
    (process_method_func)daKamome2_Create,
    (process_method_func)daKamome2_Delete,
    (process_method_func)daKamome2_Execute,
    (process_method_func)daKamome2_IsDelete,
    (process_method_func)daKamome2_Draw,
};

#if VERSION == VERSION_DEMO
actor_process_profile_definition g_profile_KAMOME2 = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0007,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_KAMOME2_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(kamome2_class),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_KAMOME2_e,
    /* Actor SubMtd */ &l_daKamome2_Method,
    /* Status       */ fopAcStts_CULL_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_0_e,
};
#endif