summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_swpropeller.cpp
blob: f43d1dd51686f7abded8109fc44d8cea0e2dbea9 (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
/**
 * @file d_a_obj_swpropeller.cpp
 * 
*/

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

#include "d/actor/d_a_obj_swpropeller.h"
#include "d/d_com_inf_game.h"
#include "f_pc/f_pc_name.h"
#include <cstring>

#define MODEL_K_PURO 0
#define MODEL_LV9_PURO 1

#define TYPE_BOOMERANG 0  // only turns when hit with boomerang
#define TYPE_WIND 1       // automatically turns

static int nodeCallBack(J3DJoint* i_joint, int param_1) {
    if (param_1 == 0) {
        int jnt_no = i_joint->getJntNo();
        J3DModel* model_p = j3dSys.getModel();
        daObjSwPr_c* swpr_p = (daObjSwPr_c*)model_p->getUserArea();

        if (jnt_no == swpr_p->mKaitenJntID) {
            cMtx_copy(model_p->getAnmMtx(jnt_no), mDoMtx_stack_c::get());
            mDoMtx_stack_c::YrotM(swpr_p->field_0x82c);
            model_p->setAnmMtx(jnt_no, mDoMtx_stack_c::get());
            mDoMtx_copy(mDoMtx_stack_c::get(), J3DSys::mCurrentMtx);
        }
    }

    return 1;
}

static int CheckCreateHeap(fopAc_ac_c* i_this) {
    return static_cast<daObjSwPr_c*>(i_this)->CreateHeap();
}

void daObjSwPr_c::initBaseMtx() {
    mpModel->setBaseScale(scale);
    setBaseMtx();
}

void daObjSwPr_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos);
    mDoMtx_stack_c::ZXYrotM(shape_angle);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

static int const l_bmdName[] = {3, 3};

static u32 const l_heap_size[] = {0xF20, 0x36C0};

static const dCcD_SrcCyl l_cyl_src = {
    {
        {0, {{0, 0, 0}, {0x10040, 0x11}, 0x58}},
        {dCcD_SE_NONE, 0, 0, 0, {0}},
        {dCcD_SE_NONE, 2, 0, 0, {2}},
        {0},
    },
    {
        {
            {0.0f, 0.0f, 0.0f},
            100.0f,
            100.0f,
        },
    },
};

static f32 const l_cull_size[] = {-150.0f, 0.0f, -150.0f, 150.0f, 150.0f, 150.0f};

// This was used for this object's HIO, which was removed in retail
static s16 const l_r00_rot_time[] = {190, 148, 100};

static char* l_arcName[] = {"K_prop00", "Lv9_puro"};

static char* l_joint_name = "kaiten";

int daObjSwPr_c::Create() {
    initBaseMtx();
    fopAcM_SetMtx(this, mpModel->getBaseTRMtx());

    mCcStts.Init(0xFF, 0xFF, this);
    mCyl1.Set(l_cyl_src);
    mCyl1.SetStts(&mCcStts);

    if (mNameArg == 1) {
        mCyl2.Set(l_cyl_src);
        mCyl2.SetStts(&mCcStts);
        mCyl2.SetTgType(0x200);
        mCyl2.SetTgMtrl(3);
    }

    fopAcM_setCullSizeBox(this, l_cull_size[0], l_cull_size[1], l_cull_size[2], l_cull_size[3],
                          l_cull_size[4], l_cull_size[5]);

    JUTNameTab* jnt_nt_p = mpModel->getModelData()->getJointTree().getJointName();
    mKaitenJntID = 0xFFFF;

    for (u16 i = 0; i < mpModel->getModelData()->getJointNum(); i++) {
        if (strcmp(jnt_nt_p->getName(i), l_joint_name) == 0) {
            mKaitenJntID = i;
        }
    }

    J3DJoint* jnt = mpModel->getModelData()->getJointNodePointer(mKaitenJntID);
    jnt->setCallBack(nodeCallBack);
    mpModel->setUserArea((uintptr_t)this);

    eyePos.y += 100.0f;

    // Set CullSizeFar for Outside Bridge room in Forest Temple
    if (strcmp(dComIfGp_getStartStageName(), "D_MN05") == 0 && fopAcM_GetRoomNo(this) == 4) {
        fopAcM_setCullSizeFar(this, 100.0f);
    }

    return 1;
}

int daObjSwPr_c::CreateHeap() {
    J3DModelData* modelData =
        (J3DModelData*)dComIfG_getObjectRes(l_arcName[mModelType], l_bmdName[mModelType]);
    mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000084);

    if (mpModel == NULL) {
        return 0;
    }

    return 1;
}

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

    mNameArg = getNameArg();

    if (getMdlType() == 15 || getMdlType() == 0) {
        mModelType = MODEL_K_PURO;
    } else if (getMdlType() == 1) {
        mModelType = MODEL_LV9_PURO;
    }

    int phase = dComIfG_resLoad(&mPhase, l_arcName[mModelType]);
    if (phase == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, CheckCreateHeap, l_heap_size[mModelType])) {
            return cPhs_ERROR_e;
        }

        if (!Create()) {
            return cPhs_ERROR_e;
        }
    }

    return phase;
}

int daObjSwPr_c::setRotateTime() {
    field_0x83a = 0;
    return 100;
}

void daObjSwPr_c::switchCtrl() {
    int sw = getSwbit();

    if (mRotateSpeed == 0) {
        fopAcM_offSwitch(this, sw);
    } else if (cLib_calcTimer(&mSwDelayTimer) == 0) {
        fopAcM_onSwitch(this, sw);
    }
}

void daObjSwPr_c::execute_type_boomerang() {
    bool tg_hit = mCyl1.ChkTgHit();

    field_0x82c += mRotateSpeed;
    cLib_chaseAngleS(&mRotateSpeed, 0, mRotateInitSpeed / mRotateTime);

    BOOL start_rotate = false;
    if (mCyl1.ChkTgHit() && field_0x838 == 0) {
        cCcD_Obj* tg_obj = mCyl1.GetTgHitObj();

        if (tg_obj != NULL && ((tg_obj->ChkAtType(AT_TYPE_40) && mCyl1.GetTgHitGObj() != NULL &&
                                mCyl1.GetTgHitGObj()->GetAtMtrl() == dCcD_MTRL_WIND) ||
                               tg_obj->ChkAtType(AT_TYPE_BOOMERANG)))
        {
            start_rotate = true;
        }

        mCyl1.ClrTgHit();
    }

    if (start_rotate) {
        field_0x839++;
        mRotateInitSpeed = 0x2000;
        mRotateSpeed = 0x2000;
        mRotateTime = setRotateTime();
        fopAcM_seStart(this, Z2SE_OBJ_BOOMSHTR_HIT_SW, 0);

        // Set delay to 0 if in Forest Temple Central Room
        if (strcmp(dComIfGp_getStartStageName(), "D_MN05") == 0 && fopAcM_GetRoomNo(this) == 0) {
            mSwDelayTimer = 0;
        } else {
            mSwDelayTimer = 8;
        }
    }

    if (cLib_calcTimer(&field_0x83a) != 0) {
        mRotateSpeed = 0x2000;
    }

    switchCtrl();
    setBaseMtx();

    cXyz pos_offset(cXyz::Zero);
    mCyl1.SetC(current.pos + pos_offset);
    dComIfG_Ccsp()->Set(&mCyl1);

    field_0x838 = tg_hit;
}

void daObjSwPr_c::execute_type_wind() {
    s16 target_speed = 0;
    int sw = getSwbit();
    BOOL var_r29 = 0;

    if (mCyl2.ChkTgHit()) {
        if (mCyl2.GetTgHitGObj() != NULL) {
            if (mCyl2.GetTgHitGObj()->GetAtMtrl() == dCcD_MTRL_WIND && mCyl2.GetTgHitObj() != NULL) {
                target_speed = 7000;
                mRotateInitSpeed = 7000;
                var_r29 = 1;

                field_0x834++;
                if (field_0x834 == 20) {
                    fopAcM_onSwitch(this, sw);
                } else if (field_0x834 == 25) {
                    fopAcM_offSwitch(this, sw);
                }
            }
        }
    } else {
        field_0x834 = 0;
    }

    if (mCyl1.ChkTgHit()) {
        if (mCyl1.GetTgHitGObj() != NULL && mCyl1.GetTgHitGObj()->GetAtMtrl() == dCcD_MTRL_WIND) {
            cCcD_Obj* tg_obj = mCyl1.GetTgHitObj();

            if (tg_obj != NULL &&
                (tg_obj->ChkAtType(AT_TYPE_40) || tg_obj->ChkAtType(AT_TYPE_BOOMERANG)))
            {
                mRotateSpeed = 7000;
                mRotateInitSpeed = mRotateSpeed;
                fopAcM_onSwitch(this, sw);
                mSwOffDelayTimer = 10;

                if (getSwbit2() != 0xFF) {
                    fopAcM_onSwitch(this, getSwbit2());
                }
            }
        }
    } else if (mSwOffDelayTimer != 0 && cLib_calcTimer(&mSwOffDelayTimer) == 0) {
        fopAcM_offSwitch(this, sw);
    }

    cLib_addCalcAngleS(&mRotateSpeed, target_speed, 30, 100, 50);
    field_0x82c += mRotateSpeed;

    setBaseMtx();

    mCyl1.SetC(current.pos);
    dComIfG_Ccsp()->Set(&mCyl1);
    mCyl2.SetC(current.pos);
    dComIfG_Ccsp()->Set(&mCyl2);

    field_0x83d = var_r29;
}

int daObjSwPr_c::execute() {
    switch (mNameArg) {
    case TYPE_BOOMERANG:
        execute_type_boomerang();
        break;
    case TYPE_WIND:
        execute_type_wind();
        break;
    }

    if (mRotateSpeed != 0 && mRotateInitSpeed != 0) {
        fopAcM_seStartLevel(this, Z2SE_OBJ_BOOMSHTR_SWITCH,
                            ((f32)mRotateSpeed / (f32)mRotateInitSpeed) * 127.0f);
    }

    dComIfGp_att_LookRequest(this, 1200.0f, 600.0f, 0.0f, 27000, 2);
    return 1;
}

int daObjSwPr_c::draw() {
    g_env_light.settingTevStruct(0x10, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);

    mDoExt_modelUpdateDL(mpModel);
    return 1;
}

int daObjSwPr_c::_delete() {
    dComIfG_resDelete(&mPhase, l_arcName[mModelType]);
    return 1;
}

static int daObjSwPr_Draw(daObjSwPr_c* i_this) {
    return i_this->draw();
}

static int daObjSwPr_Execute(daObjSwPr_c* i_this) {
    return i_this->execute();
}

static int daObjSwPr_Delete(daObjSwPr_c* i_this) {
    return i_this->_delete();
}

static int daObjSwPr_Create(fopAc_ac_c* i_this) {
    return static_cast<daObjSwPr_c*>(i_this)->create();
}

static actor_method_class l_daObjSwPr_Method = {
    (process_method_func)daObjSwPr_Create,  (process_method_func)daObjSwPr_Delete,
    (process_method_func)daObjSwPr_Execute, (process_method_func)NULL,
    (process_method_func)daObjSwPr_Draw,
};

actor_process_profile_definition g_profile_Obj_Swpropeller = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 3,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_Swpropeller_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjSwPr_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_Swpropeller_e,
    /* Actor SubMtd */ &l_daObjSwPr_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_UNK_0x4000_e | fopAcStts_CULL_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};