summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_dragonhead.cpp
blob: 24d9f517985a0f7f9f7218f98e93c2354e5c6e48 (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
//
// Generated by dtk
// Translation Unit: d_a_obj_dragonhead.cpp
//

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_obj_dragonhead.h"
#include "res/Object/Qdghd.h"
#include "f_op/f_op_actor_mng.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "d/d_bg_w.h"
#include "d/d_com_inf_game.h"
#include "d/d_cc_d.h"
#include "m_Do/m_Do_ext.h"
#include "m_Do/m_Do_mtx.h"

static dCcD_SrcSph sph_check_src = {
    // dCcD_SrcGObjInf
    {
        /* Flags             */ 0,
        /* SrcObjAt  Type    */ 0,
        /* SrcObjAt  Atp     */ 0,
        /* SrcObjAt  SPrm    */ 0,
        /* SrcObjTg  Type    */ AT_TYPE_FIRE_ARROW,
        /* SrcObjTg  SPrm    */ cCcD_TgSPrm_Set_e | cCcD_TgSPrm_IsOther_e,
        /* SrcObjCo  SPrm    */ 0,
        /* SrcGObjAt Se      */ 0,
        /* SrcGObjAt HitMark */ 0,
        /* SrcGObjAt Spl     */ 0,
        /* SrcGObjAt Mtrl    */ 0,
        /* SrcGObjAt SPrm    */ 0,
        /* SrcGObjTg Se      */ 0,
        /* SrcGObjTg HitMark */ 0,
        /* SrcGObjTg Spl     */ 0,
        /* SrcGObjTg Mtrl    */ 0,
        /* SrcGObjTg SPrm    */ 0,
        /* SrcGObjCo SPrm    */ 0,
    },
    // cM3dGSphS
    {{
        /* Center */ {0.0f, 0.0f, 0.0f},
        /* Radius */ 1000.0f,
    }},
};

/* 00000078-00000098       .text CheckCreateHeap__FP10fopAc_ac_c */
static BOOL CheckCreateHeap(fopAc_ac_c* i_this) {
    return ((daObjDragonhead_c*)i_this)->CreateHeap();
}

namespace daObjDragonhead_prm {
    inline u32 getSwitchNo(daObjDragonhead_c* ac) { return (fopAcM_GetParam(ac) >> 8) & 0xFF; }
};

/* 00000098-00000228       .text CreateHeap__17daObjDragonhead_cFv */
BOOL daObjDragonhead_c::CreateHeap() {
    J3DModelData* model_data = (J3DModelData*)(dComIfG_getObjectRes("Qdghd", dRes_INDEX_QDGHD_BDL_QDGHD_e));
    JUT_ASSERT(DEMO_SELECT(158, 160), model_data != NULL);
    mpModel = mDoExt_J3DModel__create(model_data, 0x00, 0x11020203);
    if (!mpModel)
        return FALSE;

    s32 ret = 1;

    mDoMtx_stack_c::transS(current.pos);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    mDoMtx_stack_c::scaleM(scale);
    mDoMtx_copy(mDoMtx_stack_c::get(), mtx);

    mpBgW = new dBgW();
    if (!mpBgW || mpBgW->Set((cBgD_t*)dComIfG_getObjectRes("Qdghd", dRes_INDEX_QDGHD_DZB_QDGHD_e), cBgW::MOVE_BG_e, &mtx))
        ret = 0;

    if (ret != 1)
        return false;

    return mpModel != NULL;
}

/* 00000228-0000034C       .text CreateInit__17daObjDragonhead_cFv */
void daObjDragonhead_c::CreateInit() {
    fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
    fopAcM_setCullSizeFar(this, 1.0f);
    set_mtx();

    field_0x40c = 0;
    u32 switchNo = daObjDragonhead_prm::getSwitchNo(this);
    if (dComIfGs_isSwitch(switchNo, fopAcM_GetHomeRoomNo(this))) {
        mSwitchOn = true;
        mAlpha = 0;
    } else {
        mSwitchOn = false;
        mAlpha = 0xFF;
        if (field_0x40c == 0 && !dComIfG_Bgsp()->Regist(mpBgW, this))
            field_0x40c = 1;
    }

    mStts.Init(0xFF, 0xFF, this);
    mSph.Set(sph_check_src);
    mSphCenter.set(79338.0f, 950.0f, 220000.0f);
    mSph.SetC(mSphCenter);
    mSph.SetStts(&mStts);
}

/* 0000034C-000003CC       .text set_mtx__17daObjDragonhead_cFv */
void daObjDragonhead_c::set_mtx() {
    mpModel->setBaseScale(scale);
    mDoMtx_stack_c::transS(current.pos);
    mDoMtx_stack_c::YrotM(current.angle.y);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

cPhs_State daObjDragonhead_c::_create() {
    fopAcM_ct(this, daObjDragonhead_c);

    cPhs_State ret = dComIfG_resLoad(&mPhs, "Qdghd");

    if (ret == cPhs_COMPLEATE_e) {
        if (fopAcM_entrySolidHeap(this, CheckCreateHeap, DEMO_SELECT(0x300, 0x10500)) == 0) {
            ret = cPhs_ERROR_e;
        } else {
            CreateInit();
        }
    }

    return ret;
}

bool daObjDragonhead_c::_delete() {
    if (
#if VERSION > VERSION_DEMO
        heap != NULL &&
#endif
        field_0x40c == 1
    ) {
        dComIfG_Bgsp()->Release(mpBgW);
    }

    mDoAud_seDeleteObject(&mSphCenter);
    dComIfG_resDelete(&mPhs, "Qdghd");
    return TRUE;
}

bool daObjDragonhead_c::_execute() {
    dComIfG_Ccsp()->Set(&mSph);
    if (!mSwitchOn) {
        mDoAud_seStart(JA_SE_OBJ_ICEBERG_BREATH, &mSphCenter, 0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
        if (mSph.ChkTgHit()) {
            cCcD_Obj* at = mSph.GetTgHitObj();
            if (at != NULL && at->ChkAtType(AT_TYPE_FIRE_ARROW)) {
                u32 switchNo = daObjDragonhead_prm::getSwitchNo(this);
                dComIfGs_onSwitch(switchNo, fopAcM_GetHomeRoomNo(this));
                mSwitchOn = true;
            }
        }
    }

    u32 switchNo = daObjDragonhead_prm::getSwitchNo(this);
    if (dComIfGs_isSwitch(switchNo, fopAcM_GetHomeRoomNo(this))) {
        if (field_0x40c == 1) {
            if (!dComIfG_Bgsp()->Release(mpBgW))
                field_0x40c = 0;

            mDoAud_seStart(JA_SE_OBJ_ICEVERG_MELT, &eyePos, 0, dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
        }

        if (mAlpha != 0) {
            if (mAlpha >= 2)
                mAlpha -= 2;
            else
                mAlpha = 0;
        }
    } else {
        mSwitchOn = false;
        if (field_0x40c == 0 && !dComIfG_Bgsp()->Regist(mpBgW, this))
            field_0x40c = 1;

        if (mAlpha < 0xFF) {
            if (mAlpha <= 0xFD)
                mAlpha += 2;
            else
                mAlpha = 0xFF;
        }
    }

    set_mtx();
    return TRUE;
}

bool daObjDragonhead_c::_draw() {
    g_env_light.settingTevStruct(TEV_TYPE_BG0, &current.pos, &tevStr);
    g_env_light.setLightTevColorType(mpModel, &tevStr);
    dComIfGd_setListBG();
    J3DModelData* modelData = mpModel->getModelData();
    u16 materialNum = modelData->getMaterialNum();
    for (u16 i = 0; i < materialNum; i++) {
        J3DMaterial* mat = modelData->getMaterialNodePointer(i);
        mat->getTevKColor(3)->mColor.a = mAlpha;
    }
    mDoExt_modelUpdateDL(mpModel);
    dComIfGd_setList();
    return TRUE;
}

/* 000003CC-000004FC       .text daObjDragonhead_Create__FPv */
static cPhs_State daObjDragonhead_Create(void* i_this) {
    return ((daObjDragonhead_c*)i_this)->_create();
}

/* 000006B4-00000730       .text daObjDragonhead_Delete__FPv */
static BOOL daObjDragonhead_Delete(void* i_this) {
    return ((daObjDragonhead_c*)i_this)->_delete();
}

/* 00000730-00000824       .text daObjDragonhead_Draw__FPv */
static BOOL daObjDragonhead_Draw(void* i_this) {
    return ((daObjDragonhead_c*)i_this)->_draw();
}

/* 00000824-00000A48       .text daObjDragonhead_Execute__FPv */
static BOOL daObjDragonhead_Execute(void* i_this) {
    return ((daObjDragonhead_c*)i_this)->_execute();
}

/* 00000A48-00000A50       .text daObjDragonhead_IsDelete__FPv */
static BOOL daObjDragonhead_IsDelete(void* i_this) {
    return TRUE;
}

static actor_method_class daObj_DragonheadMethodTable = {
    (process_method_func)daObjDragonhead_Create,
    (process_method_func)daObjDragonhead_Delete,
    (process_method_func)daObjDragonhead_Execute,
    (process_method_func)daObjDragonhead_IsDelete,
    (process_method_func)daObjDragonhead_Draw,
};

actor_process_profile_definition g_profile_Obj_Dragonhead = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0003,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_Dragonhead_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjDragonhead_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_Dragonhead_e,
    /* Actor SubMtd */ &daObj_DragonheadMethodTable,
    /* Status       */ fopAcStts_UNK4000_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};