summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_lv3WaterB.cpp
blob: 373ce390f5008dfb0d9aa1b6294ef56776773d67 (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
/**
 * d_a_obj_lv3WaterB.cpp
 * Morpheel Arena Water
 */

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

#include "d/actor/d_a_obj_lv3WaterB.h"
#include "JSystem/J3DGraphBase/J3DMaterial.h"
#include "d/d_bg_w.h"
#include "d/d_com_inf_game.h"
#include "d/d_s_play.h"
#include "f_op/f_op_actor.h"
#include "f_op/f_op_actor_mng.h"

static int daObj_Lv3waterB_Draw(obj_lv3WaterB_class* i_this) {
    fopAc_ac_c* const actor = i_this;

    g_env_light.settingTevStruct(0x10, &actor->current.pos, &actor->tevStr);
    g_env_light.setLightTevColorType_MAJI(i_this->mpBWaterModel, &actor->tevStr);

    i_this->mpBWaterBtk->entry(i_this->mpBWaterModel->getModelData());

    dComIfGd_setListInvisisble();
    J3DMaterial* material_p = i_this->mpBWaterModel->getModelData()->getMaterialNodePointer(0);
    if (material_p->getTexGenBlock()->getTexMtx(0) != NULL) {
        J3DTexMtxInfo* tex_mtx_info = &material_p->getTexGenBlock()->getTexMtx(0)->getTexMtxInfo();
        if (tex_mtx_info != NULL) {
            Mtx m;
            C_MTXLightPerspective(m, dComIfGd_getView()->fovy, dComIfGd_getView()->aspect, 1.0f,
                                  1.0f, -0.015f, 0.0f);
            #if WIDESCREEN_SUPPORT
            mDoGph_gInf_c::setWideZoomLightProjection(m);
            #endif

            tex_mtx_info->setEffectMtx(m);
            i_this->mpBWaterModel->getModelData()->simpleCalcMaterial((MtxP)j3dDefaultMtx);
        }
    }

    mDoExt_modelUpdateDL(i_this->mpBWaterModel);

    if (i_this->mpOctHibiModel != NULL) {
        g_env_light.setLightTevColorType_MAJI(i_this->mpOctHibiModel, &actor->tevStr);

        dComIfGd_setListBG();
        mDoExt_modelUpdateDL(i_this->mpOctHibiModel);
        dComIfGd_setList();
    }

    return 1;
}

static void action(obj_lv3WaterB_class* i_this) {
    fopAc_ac_c* const actor = i_this;

    switch (i_this->mAction) {
    case LV3WATERB_ACT_WAIT:
        break;
    case LV3WATERB_ACT_REMOVE:
        dComIfG_Bgsp().Release(i_this->mpOctHibiBgW);
        i_this->mpOctHibiModel = NULL;
        i_this->mAction = LV3WATERB_ACT_WAIT;
        break;
    case LV3WATERB_ACT_END:
        dKy_custom_colset(4, 4, 0.0f);

        if (i_this->field_0x586 == 0) {
            actor->current.pos.y = (actor->home.pos.y - 14450.0f) + AREG_F(17) + 160.0f + 4000.0f + AREG_F(16);
            i_this->field_0x586 = 1;
        }

        cLib_addCalc2(&actor->current.pos.y, (actor->home.pos.y - 14450.0f) + AREG_F(17) + 160.0f, 0.05f,
                      10.0f + AREG_F(19));
        break;
    }

    mDoMtx_stack_c::transS(actor->current.pos.x, actor->current.pos.y, actor->current.pos.z);
    i_this->mpBWaterModel->setBaseTRMtx(mDoMtx_stack_c::get());
    MTXCopy(mDoMtx_stack_c::get(), i_this->mpBWaterMtx);

    i_this->mpBWaterBgW->Move();
    i_this->mpBWaterBtk->play();

    if (i_this->mpOctHibiModel != NULL) {
        mDoMtx_stack_c::transS(0.0f, 0.0f, 0.0f);
        i_this->mpOctHibiModel->setBaseTRMtx(mDoMtx_stack_c::get());
        MTXCopy(mDoMtx_stack_c::get(), i_this->mpOctHibiMtx);

        i_this->mpOctHibiBgW->Move();
    }
}

static int daObj_Lv3waterB_Execute(obj_lv3WaterB_class* i_this) {
    fopAc_ac_c* const actor = i_this;

    action(i_this);
    return 1;
}

static int daObj_Lv3waterB_IsDelete(obj_lv3WaterB_class* i_this) {
    return 1;
}

static int daObj_Lv3waterB_Delete(obj_lv3WaterB_class* i_this) {
    fopAc_ac_c* const actor = i_this;
    fopAcM_RegisterDeleteID(i_this, "Obj_Lv3waterB");

    dComIfG_resDelete(&i_this->mBWaterPhase, "L3_bwater");
    dComIfG_resDelete(&i_this->mOcthibiPhase, "S_octhibi");

    dComIfG_Bgsp().Release(i_this->mpBWaterBgW);

    if (i_this->mpOctHibiBgW != NULL) {
        dComIfG_Bgsp().Release(i_this->mpOctHibiBgW);
    }

    return 1;
}

static int useHeapInit(fopAc_ac_c* i_this) {
    obj_lv3WaterB_class* const actor = static_cast<obj_lv3WaterB_class*>(i_this);

    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes("L3_bwater", 5);
    JUT_ASSERT(308, modelData != NULL);

    actor->mpBWaterModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000284);
    if (actor->mpBWaterModel == NULL) {
        return 0;
    }

    actor->mpBWaterBtk = new mDoExt_btkAnm();
    if (actor->mpBWaterBtk == NULL) {
        return 0;
    }

    if (!actor->mpBWaterBtk->init(actor->mpBWaterModel->getModelData(),
                                  (J3DAnmTextureSRTKey*)dComIfG_getObjectRes("L3_bwater", 8),
                                  TRUE, J3DFrameCtrl::EMode_LOOP, 1.0f, 0, -1))
    {
        return 0;
    }

    actor->mpBWaterBgW = new dBgW();
    if (actor->mpBWaterBgW == NULL) {
        return 0;
    }

    if (actor->mpBWaterBgW->Set((cBgD_t*)dComIfG_getObjectRes("L3_bwater", 11),
        dBgW::MOVE_BG_e, &actor->mpBWaterMtx) == true) {
        return 0;
    }

    modelData = (J3DModelData*)dComIfG_getObjectRes("S_octhibi", 4);
    JUT_ASSERT(343, modelData != NULL);

    actor->mpOctHibiModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000084);
    if (actor->mpOctHibiModel == NULL) {
        return 0;
    }

    actor->mpOctHibiBgW = new dBgW();
    if (actor->mpOctHibiBgW == NULL) {
        return 0;
    }

    if (actor->mpOctHibiBgW->Set((cBgD_t*) dComIfG_getObjectRes("S_octhibi", 7),
        dBgW::MOVE_BG_e, &actor->mpOctHibiMtx) == true) {
        return 0;
    }

    return 1;
}

static int daObj_Lv3waterB_Create(fopAc_ac_c* i_this) {
    obj_lv3WaterB_class* const actor = static_cast<obj_lv3WaterB_class*>(i_this);
    fopAcM_ct(actor, obj_lv3WaterB_class);

    int phase_state = dComIfG_resLoad(&actor->mBWaterPhase, "L3_bwater");
    int octhibi_phase_state = dComIfG_resLoad(&actor->mOcthibiPhase, "S_octhibi");
    if (phase_state == cPhs_COMPLEATE_e && octhibi_phase_state == cPhs_COMPLEATE_e) {
        OS_REPORT("OBJ_LV3WATERB PARAM %x\n", fopAcM_GetParam(i_this));
        OS_REPORT("OBJ_LV3WATERB//////////////OBJ_LV3WATERB SET 1 !!\n");

        if (!fopAcM_entrySolidHeap(i_this, useHeapInit, 0x4B000)) {
            OS_REPORT("//////////////OBJ_LV3WATERB SET NON !!\n");
            return cPhs_ERROR_e;
        }

        OS_REPORT("//////////////OBJ_LV3WATERB SET 2 !!\n");

        if (dComIfG_Bgsp().Regist(actor->mpBWaterBgW, actor)) {
            return cPhs_ERROR_e;
        }

        if (dComIfG_Bgsp().Regist(actor->mpOctHibiBgW, actor)) {
            return cPhs_ERROR_e;
        }

        if (dComIfGs_isStageBossEnemy()) {
            i_this->current.pos.y = (i_this->home.pos.y - 14450.0f) + AREG_F(17) + 160.0f;
            actor->mAction = LV3WATERB_ACT_END;
            actor->field_0x586 = 1;
            actor->mpOctHibiModel = NULL;
        }

        daObj_Lv3waterB_Execute(actor);
        return phase_state;
    } else if (phase_state == cPhs_COMPLEATE_e) {
        return octhibi_phase_state;
    }

    return phase_state;
}

static actor_method_class l_daObj_Lv3waterB_Method = {
    (process_method_func)daObj_Lv3waterB_Create,  (process_method_func)daObj_Lv3waterB_Delete,
    (process_method_func)daObj_Lv3waterB_Execute, (process_method_func)daObj_Lv3waterB_IsDelete,
    (process_method_func)daObj_Lv3waterB_Draw,
};

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