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

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

#include "d/actor/d_a_obj_stairBlock.h"

daStairBlock_HIO_c::daStairBlock_HIO_c() {
    for (int i = 0; i < 10; i++) {
        collision_radius[i] = 0.0f;
    }
}

void daStairBlock_c::setBaseMtx() {
    for (int i = 0; i < 10; i++) {
        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);
        mpModel[i]->setBaseScale(scale);
        mpModel[i]->setBaseTRMtx(mDoMtx_stack_c::get());
    }
}

const dCcD_SrcGObjInf daStairBlock_c::mCcDObjInfo = {
    {0, {0, 0, 0, {0x0, 0x0}, {0x19}}},
    {dCcD_SE_NONE, 0, 0, 0, 0x0},
    {dCcD_SE_NONE, 0, 0, 0, 0x0},
    {0},
};

static const s32 l_bmdIdx[10] = {
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
};

static const s32 l_bckIdx[10] = {
    0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
};

static const Vec centerPos[10] = {
    {28214.64f, -2576.334f, 7412.408f},   {28217.744f, -2681.6169f, 7392.684f},
    {28336.742f, -2641.343f, 7329.605f},  {27901.223f, -2526.949f, 7028.0098f},
    {27893.008f, -2604.662f, 7142.8018f}, {28036.146f, -2555.01f, 7141.08f},
    {27985.621f, -2644.115f, 6984.075f},  {27985.621f, -2644.115f, 6984.075f},
    {27985.621f, -2644.115f, 6984.075f},  {27985.621f, -2644.115f, 6984.075f},
};

int daStairBlock_c::CreateHeap() {
    for (int i = 0; i < 10; i++) {
        J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes("StaBlock", l_bmdIdx[i]);
        JUT_ASSERT(276, modelData != NULL);

        mpModel[i] = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000084);
        if (mpModel[i] == NULL) {
            return 0;
        }

        s32 res = mBckAnm[i].init((J3DAnmTransform*)dComIfG_getObjectRes("StaBlock", l_bckIdx[i]), 1, 0, 1.0f, 0, -1, false);
        JUT_ASSERT(290, res == 1);

        mBckAnm[i].setEndFrame(mBckAnm[i].getEndFrame() - 1.0f);
    }
    return 1;
}

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

    int phase = dComIfG_resLoad(&mPhaseReq, "StaBlock");
    if (phase == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, createHeapCallBack, 0x9000)) {
            return cPhs_ERROR_e;
        }

        fopAcM_SetMtx(this, mpModel[0]->getBaseTRMtx());
        fopAcM_setCullSizeBox2(this, mpModel[0]->getModelData());
        mStts.Init(0, 0xFF, this);

        for (int i = 0; i < 10; i++) {
            mSpheres[i].Set(mCcDSph);
            mSpheres[i].SetStts(&mStts);
            mHit[i] = 0;
        }

        for (int i = 1; i < 10; i++) {
            mDoExt_setupShareTexture(mpModel[i]->getModelData(), mpModel[0]->getModelData());
        }

        setBaseMtx();
    }

    return phase;
}

int daStairBlock_c::createHeapCallBack(fopAc_ac_c* i_this) {
    return static_cast<daStairBlock_c*>(i_this)->CreateHeap();
}

static daStairBlock_HIO_c l_HIO;

int daStairBlock_c::Execute() {
    for (int i = 0; i < 10; i++) {
        if (mSpheres[i].ChkCoHit()) {
            if (mHit[i] == 0) {
                mSpheres[i].OffCoSetBit();
                mHit[i] = 1;
                cXyz soundPos(centerPos[i]);
                mDoAud_seStart(Z2SE_OBJ_BREAK_STEPS, &soundPos, 0,
                               dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
            }
            mSpheres[i].ClrCoHit();
        }
        mSpheres[i].SetR(l_HIO.collision_radius[i] + 200.0f);
        cXyz posC(centerPos[i]);
        mSpheres[i].SetC(posC);
        dComIfG_Ccsp()->Set(&mSpheres[i]);

        if (mHit[i] != 0 && mBckAnm[i].play()) {
            mHit[i] = 0;
            cXyz soundPos(centerPos[i]);
            mDoAud_seStart(Z2SE_OBJ_BREAK_STONE, &soundPos, 0,
                           dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
            mDoAud_seStart(Z2SE_OBJ_FALL_WATER_S, &soundPos, 0,
                           dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
        }
    }
    return 1;
}

int daStairBlock_c::Draw() {
    g_env_light.settingTevStruct(0x40, &current.pos, &tevStr);
    dComIfGd_setListBG();

    for (int i = 0; i < 10; i++) {
        g_env_light.setLightTevColorType_MAJI(mpModel[i], &tevStr);
        mBckAnm[i].entry(mpModel[i]->getModelData());
        mDoExt_modelUpdateDL(mpModel[i]);
    }
    dComIfGd_setList();
    return 1;
}

int daStairBlock_c::Delete() {
    dComIfG_resDelete(&mPhaseReq, "StaBlock");

#if DEBUG
    l_HIO.removeHIO();
#endif

    return 1;
}

static int daStairBlock_Draw(daStairBlock_c* i_this) {
    return i_this->Draw();
}

static int daStairBlock_Execute(daStairBlock_c* i_this) {
    return i_this->Execute();
}

static int daStairBlock_Delete(daStairBlock_c* i_this) {
    return i_this->Delete();
}

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

dCcD_SrcSph daStairBlock_c::mCcDSph = {daStairBlock_c::mCcDObjInfo, {{{0.0f, 0.0f, 0.0f}, 4.0f}}};

static actor_method_class l_daStairBlock_Method = {
    (process_method_func)daStairBlock_Create,  (process_method_func)daStairBlock_Delete,
    (process_method_func)daStairBlock_Execute, 0,
    (process_method_func)daStairBlock_Draw,
};

actor_process_profile_definition g_profile_Obj_StairBlock = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 7,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_StairBlock_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daStairBlock_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_StairBlock_e,
    /* Actor SubMtd */ &l_daStairBlock_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_UNK_0x4000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};