summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_zrTurara.cpp
blob: cf1e786b41f1e8f63c31ee5fcb1cf38810efb5e4 (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
/**
 * d_a_obj_zrTurara.cpp
 * Object - Zora River Stalactite
 */

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

#include "d/actor/d_a_obj_zrTurara.h"
#include "d/d_bg_w.h"
#include "d/d_com_inf_game.h"
#include "f_pc/f_pc_name.h"
#include "SSystem/SComponent/c_math.h"

daZrTurara_HIO_c::daZrTurara_HIO_c() {
    mDebrisNum = 5;
    // mDebrisRange = 250.0f;
    mDebrisRange = 250.0f;
}

static daZrTurara_HIO_c l_HIO;

dCcD_SrcGObjInf const daZrTurara_c::mCcDObjInfo = {
    {0, {
        {0, 0, 0},
        {0x20, 0x11},
        {0}
    }},
    {1, 0, 1, 0, 0},
    {0xA, 0, 0, 0, 2},
    {0}
};

dCcD_SrcCyl daZrTurara_c::mCcDCyl = {
    mCcDObjInfo,
    {
        {{0.0f, 0.0f, 0.0f}, 0.0f, 0.0f}
    }
};

void daZrTurara_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::ZXYrotM(shape_angle.x, shape_angle.y, shape_angle.z);
    mDoMtx_stack_c::scaleM(mScaleF, mScaleF, mScaleF);
    // cXyz scale(1.0f, 1.0f, 1.0f);
    cXyz scale(1.0f, 1.0f, 1.0f);
    mpBaseModel->setBaseScale(scale);
    mpBaseModel->setBaseTRMtx(mDoMtx_stack_c::get());
    PSMTXCopy(mDoMtx_stack_c::get(), mBgMtx);
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::ZXYrotM(shape_angle.x, shape_angle.y, shape_angle.z);
    mDoMtx_stack_c::scaleM(mScaleF, mScaleF, mScaleF);
    mpRockModel->setBaseScale(scale);
    mpRockModel->setBaseTRMtx(mDoMtx_stack_c::get());
    PSMTXCopy(mDoMtx_stack_c::get(), mRockBgMtx);
}

int daZrTurara_c::CreateHeap() {
    J3DModelData* base_model_data = (J3DModelData*)dComIfG_getObjectRes("M_DrpRock", 5);
    mpBaseModel = mDoExt_J3DModel__create(base_model_data, 0x80000, 0x11000084);
    if (mpBaseModel == NULL) {
        return 0;
    }
    J3DModelData* rock_model_data = (J3DModelData*)dComIfG_getObjectRes("M_DrpRock", 4);
    mpRockModel = mDoExt_J3DModel__create(rock_model_data, 0x80000, 0x11000084);
    if (mpRockModel == NULL) {
        return 0;
    }
    mpRockBgW = new dBgW();
    if (mpRockBgW == NULL ||
        mpRockBgW->Set((cBgD_t*)dComIfG_getObjectRes("M_DrpRock", 8), 1, &mRockBgMtx))
    {
        mpRockBgW = NULL;
        return 0;
    }
    return 1;
}

cPhs_Step daZrTurara_c::create() {
    fopAcM_ct(this, daZrTurara_c);
    cPhs_Step step = dComIfG_resLoad(&mPhaseReq, "M_DrpRock");
    if (step == cPhs_COMPLEATE_e) {
        cPhs_Step bg_step = MoveBGCreate("M_DrpRock", 9, dBgS_MoveBGProc_TypicalRotY,
                                                      0x2800, NULL);
        if (bg_step == cPhs_ERROR_e) {
            return cPhs_ERROR_e;
        }
        mSw2 = getSwBit2();
        mDrawRock = true;
        mCcStatus.Init(0xff, 0xff, this);
        mCcCyl.Set(mCcDCyl);
        mCcCyl.SetStts(&mCcStatus);
        int sw1 = getSwBit1();
        if (fopAcM_isSwitch(this, sw1)) {
            if (mpRockBgW != NULL) {
                dComIfG_Bgsp().Release(mpRockBgW);
                mpRockBgW->Move();
            }
            mCcCyl.OffTgSetBit();
            mDrawRock = false;
            init_modeEnd();
        } else if (mpRockBgW != NULL) {
            dComIfG_Bgsp().Regist(mpRockBgW, this);
            mpRockBgW->Move();
        }
        fopAcM_SetMtx(this, mpBaseModel->getBaseTRMtx());
        J3DJoint* base_joint = mpBaseModel->getModelData()->getJointNodePointer(0);
        J3DJoint* rock_joint = mpRockModel->getModelData()->getJointNodePointer(0);
        fopAcM_setCullSizeBox(
            this,
            scale.x * rock_joint->getMin()->x,
            scale.y * rock_joint->getMin()->y,
            scale.z * rock_joint->getMin()->z,
            scale.x * base_joint->getMax()->x,
            scale.y * base_joint->getMax()->y,
            scale.z * base_joint->getMax()->z
        );
        u8 scale = getScale();
        if (scale == 0xff) {
            scale = 0;
        }
        mScaleF = scale * 0.1f + 1.0f;
        setBaseMtx();
    }
    return step;
}

int daZrTurara_c::Execute(Mtx** i_mtxP) {
    move();
    *i_mtxP = &mpBaseModel->getBaseTRMtx();
    setBaseMtx();
    if (mpRockBgW != NULL) {
        mpRockBgW->Move();
    }
    return 1;
}

void daZrTurara_c::move() {
    typedef void (daZrTurara_c::*daZrTurara_modeFunc)();
    static daZrTurara_modeFunc mode_proc[3] = {
        &daZrTurara_c::modeWait,
        &daZrTurara_c::modeBreak,
        &daZrTurara_c::modeEnd,
    };
    (this->*mode_proc[mMode])();
    mCcCyl.SetR(130.0f);
    mCcCyl.SetH(450.0f);
    cXyz pos = current.pos;
    pos.y -= 500.0f;
    mCcCyl.SetC(pos);
    dComIfG_Ccsp()->Set(&mCcCyl);
}


void daZrTurara_c::modeWait() {
    if (mSw2 != 0xff && fopAcM_isSwitch(this, mSw2)) {
        init_modeBreak();
    }
    if (mCcCyl.ChkTgHit() && mCcCyl.GetTgHitGObj()->GetAtType() == AT_TYPE_BOMB) {
        init_modeBreak();
    }
}

void daZrTurara_c::init_modeBreak() {
    mDoAud_seStart(Z2SE_OBJ_RG_ROCK_BREAK, &current.pos, 0,
                   dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
    if (mpRockBgW != NULL) {
        dComIfG_Bgsp().Release(mpRockBgW);
        mpRockBgW->Move();
    }
    mDrawRock = false;
    mCcCyl.OffTgSetBit();
    cXyz scale(mScaleF, mScaleF, mScaleF);
    dComIfGp_particle_set(0x8a93, &current.pos, NULL, &scale);
    dComIfGp_particle_set(0x8a94, &current.pos, NULL, &scale);
    dComIfGp_particle_set(0x8a95, &current.pos, NULL, &scale);
    dComIfGp_particle_set(0x8a96, &current.pos, NULL, &scale);
    dComIfGp_particle_set(0x8a97, &current.pos, NULL, &scale);
    mParticleKey = dComIfGp_particle_set(mParticleKey, 0x8a98, &current.pos, NULL, &scale);
    int sw1 = getSwBit1();
    fopAcM_onSwitch(this, sw1);
    mDebrisCount = 0;
    mBreakTimer = 0;
    mMode = 1;
}

void daZrTurara_c::modeBreak() {
    cXyz scale(mScaleF, mScaleF, mScaleF);
    mParticleKey = dComIfGp_particle_set(mParticleKey, 0x8a98, &current.pos, NULL, &scale);
    if (mBreakTimer != 0) {
        mBreakTimer--;
    } else {
        cXyz pos = current.pos;
        pos.y -= 200.0f;
        pos.x += l_HIO.mDebrisRange * cM_rndFX(1.0f);
        pos.y += l_HIO.mDebrisRange * cM_rndFX(1.0f);
        fopAcM_create(fpcNm_Obj_zrTuraraRc_e, getScale(), &pos,
                      fopAcM_GetRoomNo(this), NULL, NULL, 0xff);
        mDebrisCount++;
        mBreakTimer = cM_rndF(1.0f) * 20.0f;
        if (mDebrisCount >= l_HIO.mDebrisNum) {
            JPABaseEmitter* emitter = dComIfGp_particle_getEmitter(mParticleKey);
            if (emitter != NULL) {
                emitter->becomeInvalidEmitter();
            }
            init_modeEnd();
        }
    }
}

void daZrTurara_c::init_modeEnd() {
    mMode = 2;
}

void daZrTurara_c::modeEnd() {
    /* empty function */
}

int daZrTurara_c::Draw() {
    g_env_light.settingTevStruct(0x10, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpBaseModel, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpRockModel, &tevStr);
    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(mpBaseModel);
    if (mDrawRock) {
        mDoExt_modelUpdateDL(mpRockModel);
    }
    dComIfGd_setList();
    return 1;
}

int daZrTurara_c::Delete() {
    dComIfG_resDelete(&mPhaseReq, "M_DrpRock");
    if (mpRockBgW != NULL && mpRockBgW->ChkUsed()) {
        dComIfG_Bgsp().Release(mpRockBgW);
    }
    return 1;
}

static int daZrTurara_Draw(daZrTurara_c* i_this) {
    return i_this->MoveBGDraw();
}

static int daZrTurara_Execute(daZrTurara_c* i_this) {
    return i_this->MoveBGExecute();
}

static int daZrTurara_Delete(daZrTurara_c* i_this) {
    return i_this->MoveBGDelete();
}

static cPhs_Step daZrTurara_Create(fopAc_ac_c* i_this) {
    return static_cast<daZrTurara_c*>(i_this)->create();
}

static actor_method_class l_daZrTurara_Method = {
    (process_method_func)daZrTurara_Create,
    (process_method_func)daZrTurara_Delete,
    (process_method_func)daZrTurara_Execute,
    (process_method_func)NULL,
    (process_method_func)daZrTurara_Draw,
};

actor_process_profile_definition g_profile_Obj_zrTurara = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 3,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_zrTurara_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daZrTurara_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_zrTurara_e,
    /* Actor SubMtd */ &l_daZrTurara_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_CULL_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};