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

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

#include "d/actor/d_a_obj_hakai_brl.h"
#include "d/d_com_inf_game.h"

static int daObjHBarrel_c_createHeap(fopAc_ac_c* i_this) {
    return ((daObjHBarrel_c*)i_this)->createHeap();
}

static char* l_arcName = "HBarrel";

daObjHBarrel_c::daObjHBarrel_c() {}

daObjHBarrel_c::~daObjHBarrel_c() {
    dComIfG_resDelete(this, l_arcName);
}

int daObjHBarrel_c::createHeap() {
    J3DModelData* a_model_data_p = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 3);
    JUT_ASSERT(0x9a, a_model_data_p != NULL);

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

    return 1;
}

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

    s32 loadResult = dComIfG_resLoad(this, l_arcName);
    if (loadResult == cPhs_COMPLEATE_e) {
        if (!fopAcM_entrySolidHeap(this, daObjHBarrel_c_createHeap, 0x1000)) {
            return cPhs_ERROR_e;
        }

        init();
        setModelMtx();
        fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
        fopAcM_setCullSizeBox2(this, mpModel->getModelData());
        mSound.init(&current.pos, 1);
    }

    return loadResult;
}

int daObjHBarrel_c::Delete() {
    mSound.deleteObject();
    this->~daObjHBarrel_c();
    return 1;
}

int daObjHBarrel_c::draw() {
    g_env_light.settingTevStruct(8, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);
    mDoExt_modelUpdate(mpModel);
    return 1;
}

int daObjHBarrel_c::execute() {
    if (dComIfGp_checkPlayerStatus0(0, 0x1000) != 0) {
        mCyl.OffTgShield();
    } else {
        mCyl.OnTgShield();
    }

    hitAction();

    setModelMtx();

    mSound.framework(0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));

    dComIfG_Ccsp()->Set(&mCyl);

    return 1;
}

dCcD_SrcCyl const daObjHBarrel_c::s_CcDCyl = {
    {
        {0x0, {{0x0, 0x0, 0xd}, {0xd8fafdff, 0x11}, 0x79}},  // mObj
        {dCcD_SE_NONE, 0x0, 0x0, 0x0, 0x0},                  // mGObjAt
        {dCcD_SE_NONE, 0x0, 0x0, 0x0, 0x5},                  // mGObjTg
        {0x0},                                               // mGObjCo
    },                                                       // mObjInf
    {
        {
            {0.0f, 0.0f, 0.0f},  // mCenter
            0.0f,                // mRadius
            0.0f                 // mHeight
        }  // mCyl
    }
};

void daObjHBarrel_c::init() {
    mStts.Init(0xff, 0, this);
    mCyl.Set(s_CcDCyl);
    mCyl.SetStts(&mStts);
    cXyz cStack_18(current.pos.x, current.pos.y, current.pos.z);
    mCyl.SetC(cStack_18);
    mCyl.SetH(170.0f);
    return mCyl.SetR(90.0f);
}

void daObjHBarrel_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());
}

void daObjHBarrel_c::hitAction() {
    if (mCyl.ChkTgHit()) {
        cCcD_ObjHitInf* hitObj = mCyl.GetTgHitObj();
        if (hitObj != NULL) {
            u32 temp = mCyl.GetTgHitObjHitSeID(1);
            mSound.startCollisionSE(temp, 0x10, NULL);
            if (hitObj->ChkAtType(AT_TYPE_BOMB) || hitObj->ChkAtType(AT_TYPE_IRON_BALL)) {
                dComIfGp_setHitMark(1, this, mCyl.GetTgHitPosP(), NULL, NULL, 0);
                callEmt();
                fopAcM_seStartCurrent(this, Z2SE_OBJ_BREAK_WOOD_FURNITURE, 0);
                fopAcM_createItemFromTable(&current.pos, getItemNo(), getItemBit(),
                                           fopAcM_GetHomeRoomNo(this), NULL, 0, NULL, NULL, NULL,
                                           false);
                fopAcM_delete(this);
            } else {
                if (hitObj->ChkAtType(AT_TYPE_NORMAL_SWORD) != 0 ||
                    hitObj->ChkAtType(AT_TYPE_ARROW) != 0)
                {
                    cXyz scale(1.0f, 1.0f, 1.0f);
                    csXyz part_shape_angle(shape_angle);
                    fopAc_ac_c* player = dComIfGp_getPlayer(0);
                    if (player != NULL) {
                        part_shape_angle.set(player->shape_angle.x, player->shape_angle.y,
                                      player->shape_angle.z);
                    }
                    dComIfGp_particle_set(0x752, mCyl.GetTgHitPosP(), &part_shape_angle, &scale);
                } else {
                    dComIfGp_setHitMark(9, this, mCyl.GetTgHitPosP(), NULL, NULL, 0);
                }
            }
        }
        mCyl.ClrTgHit();
    }
}

void daObjHBarrel_c::callEmt() {
    static u16 const PARTICLE_NAME[3] = {
        0x82AB,
        0x82AC,
        0x82AD,
    };

    cXyz acStack_34(current.pos);
    cXyz cStack_40(1.125f, 1.125f, 1.125f);

    J3DModelData* a_bmd_p = (J3DModelData*)dComIfG_getObjectRes("Always", "BreakWoodBox.bmd");
    JUT_ASSERT(0x1f3, a_bmd_p != NULL);

    JPABaseEmitter* emitter = dComIfGp_particle_set(0x82af, &acStack_34, NULL, NULL, 0xff,
                                                    &dPa_modelEcallBack::getEcallback(),
                                                    fopAcM_GetRoomNo(this), NULL, NULL, &cStack_40);
    dPa_modelEcallBack::setModel(emitter, a_bmd_p, tevStr, 3, NULL, 0, 0);
    for (s32 i = 0; i < 3; i++) {
        dComIfGp_particle_set(PARTICLE_NAME[i], &acStack_34, NULL, &cStack_40, 0xff, NULL, -1, NULL,
                              NULL, NULL);
    }
}

static int daObjHBarrel_create(daObjHBarrel_c* param_0) {
    fopAcM_ct(param_0, daObjHBarrel_c);
    return param_0->create();
}

static int daObjHBarrel_Delete(daObjHBarrel_c* param_0) {
    return param_0->Delete();
}

static int daObjHBarrel_execute(daObjHBarrel_c* param_0) {
    return param_0->execute();
}

static int daObjHBarrel_draw(daObjHBarrel_c* param_0) {
    return param_0->draw();
}

static actor_method_class daObjHBarrel_METHODS = {
    (process_method_func)daObjHBarrel_create,
    (process_method_func)daObjHBarrel_Delete,
    (process_method_func)daObjHBarrel_execute,
    NULL,
    (process_method_func)daObjHBarrel_draw,
};

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