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

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

#include "d/actor/d_a_obj_hakai_ftr.h"
#include "d/d_bg_w.h"
#include "d/d_com_inf_game.h"

static int daObjHFtr_c_createHeap(fopAc_ac_c* param_0) {
    return ((daObjHFtr_c*)param_0)->createHeap();
}

static const char* l_arcName[3] = {"HChair", "HSofa", "HTable"};

daObjHFtr_c::daObjHFtr_c() {}

daObjHFtr_c::~daObjHFtr_c() {
    u32 index = getNameId();
    dComIfG_resDelete(this, l_arcName[index]);
}

static u32 const l_bmdIdx[3] = {4, 4, 4};

static u32 const l_dzbIdx[3] = {7, 7, 7};

int daObjHFtr_c::createHeap() {
    uint nameId = getNameId();

    J3DModelData* a_model_data_p =
        (J3DModelData*)dComIfG_getObjectRes(l_arcName[nameId], l_bmdIdx[nameId]);
    JUT_ASSERT(0xb2, a_model_data_p != NULL);

    mpModel = mDoExt_J3DModel__create(a_model_data_p, 0x80000, 0x11000084);
    if (mpModel == NULL) {
        return 0;
    }

    field_0x5a4 = new dBgW();
    if (field_0x5a4 == NULL) {
        return 0;
    }

    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    MTXCopy(mDoMtx_stack_c::get(), mMtx);
    if (field_0x5a4->Set((cBgD_t*)dComIfG_getObjectRes(l_arcName[nameId], l_dzbIdx[nameId]), 1,
                         &mMtx) == 1)
    {
        return 0;
    }

    return 1;
}

static u32 const l_heapSize[3] = {0x2000, 0x2000, 0x2000};

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

    u32 nameIndex = getNameId();
    s32 loadResult = dComIfG_resLoad(this, l_arcName[nameIndex]);
    if (loadResult == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, daObjHFtr_c_createHeap, l_heapSize[nameIndex])) {
            return cPhs_ERROR_e;
        }

        if (dComIfG_Bgsp().Regist(field_0x5a4, this) != 0) {
            return cPhs_ERROR_e;
        }

        init();
        setModelMtx();
        fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
        fopAcM_setCullSizeBox2(this, mpModel->getModelData());
    }

    return loadResult;
}

int daObjHFtr_c::Delete() {
    if (field_0x5a4 != NULL && field_0x5a4->ChkUsed()) {
        dComIfG_Bgsp().Release(field_0x5a4);
    }
    this->~daObjHFtr_c();
    return 1;
}

int daObjHFtr_c::draw() {
    g_env_light.settingTevStruct(8, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);

    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(this->mpModel);
    dComIfGd_setList();

    return 1;
}

dCcD_SrcCyl const daObjHFtr_c::s_CcDCyl = {
    {
        {0x0, {{0x0, 0x0, 0x0}, {0x400020, 0x11}, 0x0}},  // mObj
        {dCcD_SE_NONE, 0x0, 0x0, 0x0, 0x0},               // mGObjAt
        {dCcD_SE_NONE, 0x0, 0x0, 0x0, 0x0},               // mGObjTg
        {0x0},                                            // mGObjCo
    },   
    {                                                 // mObjInf
        {
            {0.0f, 0.0f, 0.0f},  // mCenter
            0.0f,                // mRadius
            0.0f                 // mHeight
        }  // mCyl
    }
};

int daObjHFtr_c::execute() {
    if (chkHit()) {
        callEmt();

        s32 nameId = getNameId();
        Z2SoundID soundId = nameId == 1 ? Z2SE_OBJ_BREAK_WOOD_FURNITURE : Z2SE_OBJ_BREAK_BARREL;
        fopAcM_seStartCurrent(this, soundId, 0);

        fopAcM_delete(this);
        return 1;
    }

    setModelMtx();
    for (s32 i = 0; i < 2; i++) {
        dComIfG_Ccsp()->Set(&mCyls[i]);
    }
    return 1;
}

void daObjHFtr_c::init() {
    static s32 const COL_OFFSET_X[3][2] = {{0, 0}, {50, -50}, {0, 0}};
    static s32 const COL_HEIGHT[3] = {170, 160, 110};
    static s32 const COL_RADIUS[3] = {60, 70, 90};

    u32 nameId = getNameId();
    mStts.Init(0xff, 0, this);
    for (s32 i = 0; i < 2; i++) {
        mCyls[i].Set(s_CcDCyl);
        mCyls[i].SetStts(&mStts);
        cXyz cStack_48(current.pos.x + COL_OFFSET_X[nameId][i], current.pos.y, current.pos.z);
        mCyls[i].SetC(cStack_48);
        mCyls[i].SetH(COL_HEIGHT[nameId]);
        mCyls[i].SetR(COL_RADIUS[nameId]);
    }
    // return iVar2;
}

void daObjHFtr_c::setModelMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

bool daObjHFtr_c::chkHit() {
    for (s32 i = 0; i < 2; i++) {
        if (mCyls[i].ChkTgHit()) {
            return true;
        }
    }
    return false;
}


void daObjHFtr_c::callEmt() {
    static u16 const PARTICLE_NAME[4] = {
        0x8AE7,
        0x8AE8,
        0x8AE9,
        0x8AEA,
    };

    cXyz acStack_24(current.pos.x, current.pos.y, current.pos.z);
    csXyz cStack_38(current.angle);
    cXyz cStack_30(1.0f, 1.0f, 1.0f);
    for (s32 i = 0; i < 4; i++) {
        dComIfGp_particle_set(PARTICLE_NAME[i], &acStack_24, &cStack_38, &cStack_30);
    }
}

static int daObjHFtr_create(daObjHFtr_c* param_0) {
    fopAcM_ct(param_0, daObjHFtr_c);
    return param_0->create();
}

static int daObjHFtr_Delete(daObjHFtr_c* param_0) {
    return param_0->Delete();
}

static int daObjHFtr_execute(daObjHFtr_c* param_0) {
    return param_0->execute();
}

static int daObjHFtr_draw(daObjHFtr_c* param_0) {
    return param_0->draw();
}

static actor_method_class daObjHFtr_METHODS = {
    (process_method_func)daObjHFtr_create,  (process_method_func)daObjHFtr_Delete,
    (process_method_func)daObjHFtr_execute, 0,
    (process_method_func)daObjHFtr_draw,
};

actor_process_profile_definition g_profile_Obj_HFtr = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 7,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_HFtr_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjHFtr_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_HFtr_e,
    /* Actor SubMtd */ &daObjHFtr_METHODS,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_CULL_e | fopAcStts_NOEXEC_e,
    /* Group        */ fopAc_ENV_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};