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

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

#include "d/actor/d_a_obj_gb.h"
#include "SSystem/SComponent/c_lib.h"
#include "SSystem/SComponent/c_math.h"
#include "d/d_bg_w.h"
#include "d/d_com_inf_game.h"
#include <cstring>

static int daObj_Gb_Draw(obj_gb_class* i_this) {
    g_env_light.settingTevStruct(0x10, &i_this->current.pos, &i_this->tevStr);
    g_env_light.setLightTevColorType_MAJI(i_this->mModel, &i_this->tevStr);
    J3DModelData* modelData = (J3DModelData*)i_this->mModel->getModelData();
    for (u16 i = 0; i <= 1; i++) {
        J3DMaterial* material = (J3DMaterial*)modelData->getMaterialNodePointer(i);
        material->getTevKColor(1)->a = i_this->mColorAlpha;
    }

    dKy_bg_MAxx_proc(i_this->mModel);
    i_this->mBtk->entry(modelData);
    i_this->mBrk->entry(modelData);
    mDoExt_modelUpdateDL(i_this->mModel);
    return 1;
}

static int daObj_Gb_Execute(obj_gb_class* i_this) {
    fopAc_ac_c* player = dComIfGp_getPlayer(0);
    cXyz acStack_30;
    cXyz cStack_3c;
    i_this->field_0x58e++;
    for (int i = 0; i < 2; i++) {
        if (i_this->field_0x58a[i] != 0) {
            i_this->field_0x58a[i]--;
        }
    }
    switch(i_this->mIsFinalBattle) {
    case 0:
        if (i_this->field_0x57c == 0) {
            for (int i = 0; i < 20; i++) {
                if (i_this->mBrkFrame < 0.5f) {
                    Z2GetAudioMgr()->seStart(Z2SE_OBJ_GANON_BARRIER_APPR, &i_this->field_0x594[i],
                                             0, 0, 1.0f, 1.0f, -1.0f, -1.0f, 0);
                }
                Z2GetAudioMgr()->seStartLevel(Z2SE_OBJ_GANON_BARRIER, &i_this->field_0x594[i], 0, 0,
                                              1.0f, 1.0f, -1.0f, -1.0f, 0);
            }
        } else {
            if (i_this->mBrkFrame < 0.5f) {
                Z2GetAudioMgr()->seStart(Z2SE_OBJ_GANON_BARRIER_APPR, &i_this->current.pos, 0, 0,
                                         1.0f, 1.0f, -1.0f, -1.0f, 0);
            }
            Z2GetAudioMgr()->seStartLevel(Z2SE_OBJ_GANON_BARRIER, &i_this->current.pos, 0, 0, 1.0f,
                                          1.0f, -1.0f, -1.0f, 0);
        }
        cLib_addCalc2(&i_this->mBrkFrame, 29.0f, 1.0f, 1.0f);
        if (strcmp(dComIfGp_getStartStageName(), "D_MN09B") != 0) {
            if (dComIfGs_isSwitch(i_this->mSw2, fopAcM_GetRoomNo(i_this)) ||
                !dComIfGs_isSwitch(i_this->mSw1, fopAcM_GetRoomNo(i_this)))
            {
                i_this->mIsFinalBattle = 1;
            }
        }
        break;
    case 1:
        cLib_addCalc2(&i_this->mBrkFrame, 0, 1.0f, 1.0f);
        if (!dComIfGs_isSwitch(i_this->mSw2, fopAcM_GetRoomNo(i_this)) &&
            dComIfGs_isSwitch(i_this->mSw1, fopAcM_GetRoomNo(i_this)))
        {
            i_this->mIsFinalBattle = 0;
        }
        break;
    }
    mDoMtx_stack_c::transS(i_this->current.pos.x, i_this->current.pos.y, i_this->current.pos.z);
    mDoMtx_stack_c::YrotM(i_this->current.angle.y);
    if (i_this->field_0x57c == 0) {
        mDoMtx_stack_c::scaleM(i_this->scale.x, i_this->scale.y, i_this->scale.x);
    } else {
        mDoMtx_stack_c::scaleM(i_this->scale.x, i_this->scale.y, 1.0f);
    }
    i_this->mModel->setBaseTRMtx(mDoMtx_stack_c::get());
    i_this->mBtk->play();
    i_this->mBrk->setFrame(i_this->mBrkFrame);
    if (i_this->mBrkFrame < 1.0f) {
        mDoMtx_stack_c::transM(0.0f, -200.0f, 0.0f);
        mDoMtx_stack_c::scaleM(1.0f, 0.0f, 1.0f);
    }
    MTXCopy(mDoMtx_stack_c::get(), i_this->mBgMtx);
    i_this->mpBgW->Move();
    return 1;
}

static int daObj_Gb_IsDelete(obj_gb_class* param_0) {
    return 1;
}

static int daObj_Gb_Delete(obj_gb_class* i_this) {
    fopAcM_GetID(i_this);
    dComIfG_resDelete(&i_this->mPhase, "Obj_gb");
    if (i_this->mpBgW != NULL) {
        dComIfG_Bgsp().Release(i_this->mpBgW);
    }
    return 1;
}

static int bmd[2] = {
    6, 7,
};

static int brk[2] = {
    10, 11,
};

static int btk[2] = {
    14, 15,
};

static int dzb[2] = {
    18, 19,
};

static int useHeapInit(fopAc_ac_c* actor) {
    obj_gb_class* i_this = (obj_gb_class*)actor;
    J3DModelData* modelData = (J3DModelData*) dComIfG_getObjectRes("Obj_gb", bmd[i_this->field_0x57c]);
    JUT_ASSERT(324, modelData != NULL);
    i_this->mModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000284);
    if (i_this->mModel == NULL) {
        return 0;
    }
    i_this->mBtk = new mDoExt_btkAnm();
    if (i_this->mBtk == NULL) {
        return 0;
    }
    J3DAnmTextureSRTKey* anmTexture = (J3DAnmTextureSRTKey*) dComIfG_getObjectRes(
        "Obj_gb", btk[i_this->field_0x57c]);
    if (i_this->mBtk->init(i_this->mModel->getModelData(), anmTexture, 1, 2, 1.0f, 0, -1) == 0) {
        return 0;
    }
    i_this->mBrk = new mDoExt_brkAnm();
    if (i_this->mBrk== NULL) {
        return 0;
    }
    J3DAnmTevRegKey* anmTevKey = (J3DAnmTevRegKey*)dComIfG_getObjectRes(
        "Obj_gb", brk[i_this->field_0x57c]);
    if (i_this->mBrk->init(i_this->mModel->getModelData(), anmTevKey, 1, 2, 0.0f, 0, -1) == 0) {
        return 0;
    }
    i_this->mpBgW = new dBgW();
    if (i_this->mpBgW == NULL) {
        return 0;
    }
    cBgD_t* pbGd = (cBgD_t*)dComIfG_getObjectRes(
        "Obj_gb", dzb[i_this->field_0x57c]);
    return i_this->mpBgW->Set(pbGd, 1, &i_this->mBgMtx) == 1 ? 0 : 1;
}

static int daObj_Gb_Create(fopAc_ac_c* actor) {
    fopAcM_ct(actor, obj_gb_class);
    obj_gb_class* i_this = (obj_gb_class*)actor;
    int rv = dComIfG_resLoad(&i_this->mPhase, "Obj_gb");
    
    if (rv == cPhs_COMPLEATE_e) {
        OS_REPORT("OBJ_GB PARAM %x\n", fopAcM_GetParam(i_this));
        i_this->field_0x57c = fopAcM_GetParam(i_this);
        if (i_this->field_0x57c == 0xff) {
            i_this->field_0x57c = 0;
        }
        u8 local_47 = (fopAcM_GetParam(i_this) >> 8) & 0xff;
        if (local_47 == 0xff) {
            if (i_this->field_0x57c == 0) {
                local_47 = 100;
            } else {
                local_47 = 10;
            }
        }
        if (i_this->field_0x57c == 0) {
            i_this->scale.x = local_47 * 0.01f;
        } else {
            i_this->scale.x = local_47 * 0.5f;
        }
        i_this->scale.y = ((fopAcM_GetParam(i_this) >> 16) & 0xff) * 0.333333f * 0.5f;
        i_this->mColorAlpha = fopAcM_GetParam(i_this) >> 24;
        i_this->mSw1 = i_this->current.angle.x & 0xff;
        i_this->mSw2 = (i_this->current.angle.x & 0xff00) >> 8;
        i_this->shape_angle.x = 0;
        i_this->current.angle.x = 0;
        OS_REPORT("OBJ_GB//////////////OBJ_GB SET 1 !!\n");
        int heapSize;
        if (i_this->field_0x57c == 0) {
            heapSize = 0x1c40;
        } else {
            heapSize = 0x1320;
        }
        if (fopAcM_entrySolidHeap(i_this, useHeapInit, heapSize) == 0) {
            OS_REPORT("//////////////OBJ_GB SET NON !!\n");
            return cPhs_ERROR_e;
        }
        OS_REPORT("//////////////OBJ_GB SET 2 !!\n");
        if (i_this->mpBgW != NULL) {
            if (dComIfG_Bgsp().Regist(i_this->mpBgW, i_this) != 0) {
                return cPhs_ERROR_e;
            }
        }
        i_this->field_0x58e = cM_rndF(65536.0f);
        if (strcmp(dComIfGp_getStartStageName(), "D_MN09B") != 0) {
            i_this->mIsFinalBattle = 1;
        }
        s16 local_44 = 0;
        cXyz cStack_30(0.0f, 0.0f, i_this->scale.x * 1000.0f);
        for (int i = 0; i < 20; i++, local_44 += 0xccc) {
            cMtx_YrotS(*calc_mtx, local_44);
            MtxPosition(&cStack_30, &i_this->field_0x594[i]);
            i_this->field_0x594[i] += i_this->current.pos;
        }
        daObj_Gb_Execute(i_this);
    }
    return rv;
}

static actor_method_class l_daObj_Gb_Method = {
    (process_method_func)daObj_Gb_Create,
    (process_method_func)daObj_Gb_Delete,
    (process_method_func)daObj_Gb_Execute,
    (process_method_func)daObj_Gb_IsDelete,
    (process_method_func)daObj_Gb_Draw,
};

actor_process_profile_definition g_profile_OBJ_GB = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 3,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_OBJ_GB_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(obj_gb_class),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_OBJ_GB_e,
    /* Actor SubMtd */ &l_daObj_Gb_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_UNK_0x4000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};