summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_bsGate.cpp
blob: 694ea3c2ceef7ca6d30b157c3b241e7c70b7f5b7 (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
/**
 * d_a_obj_bsGate.cpp
 * Object - Lakebed Temple Gate
 */

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

#include "d/actor/d_a_obj_bsGate.h"
#include "d/d_com_inf_game.h"
#include "f_pc/f_pc_name.h"

class daBsGate_HIO_c : public mDoHIO_entry_c {
public:
    daBsGate_HIO_c();
    ~daBsGate_HIO_c() {}

    void genMessage(JORMContext*);

    /* 0x4 */ f32 mOpenSpeed;
    /* 0x8 */ f32 mCloseSpeed;
    /* 0xC */ u8 mShockStrength;
};

STATIC_ASSERT(sizeof(daBsGate_HIO_c) == 0x10);

static daBsGate_HIO_c l_HIO;

daBsGate_HIO_c::daBsGate_HIO_c() {
    mOpenSpeed = 2.0f;
    mCloseSpeed = 12.0f;
    mShockStrength = 3;
}

#if DEBUG
void daBsGate_HIO_c::genMessage(JORMContext* mctx) {
    // OPEN speed
    mctx->genSlider("OPEN速度", &mOpenSpeed, 0.1f, 100.0f);
    // CLOSE speed
    mctx->genSlider("CLOSE速度", &mCloseSpeed, 0.1f, 100.0f);

    /* Vibration */
    /* Vibration */
    mctx->startComboBox("振動", &mShockStrength);
    // Strength 1
    mctx->genComboBoxItem("強さ1", VIBMODE_S_POWER1);
    // Strength 2
    mctx->genComboBoxItem("強さ2", VIBMODE_S_POWER2);
    // Strength 3
    mctx->genComboBoxItem("強さ3", VIBMODE_S_POWER3);
    // Strength 4
    mctx->genComboBoxItem("強さ4", VIBMODE_S_POWER4);
    // Strength 5
    mctx->genComboBoxItem("強さ5", VIBMODE_S_POWER5);
    // Strength 6
    mctx->genComboBoxItem("強さ6", VIBMODE_S_POWER6);
    // Strength 7
    mctx->genComboBoxItem("強さ7", VIBMODE_S_POWER7);
    // Strength 8
    mctx->genComboBoxItem("強さ8", VIBMODE_S_POWER8);
    mctx->endComboBox();
}
#endif

void daBsGate_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::ZXYrotM(shape_angle.x, shape_angle.y, shape_angle.z);
    mDoMtx_stack_c::transM(mOpenDist, 0.0f, 0.0f);
    mpModel->setBaseScale(scale);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

int daBsGate_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes("S_Zgate", 4);

    JUT_ASSERT(178, modelData != NULL);

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

cPhs_Step daBsGate_c::create() {
    fopAcM_ct(this, daBsGate_c);
    cPhs_Step step = dComIfG_resLoad(&mPhaseReq, "S_Zgate");
    if (step == cPhs_COMPLEATE_e) {
        if (MoveBGCreate("S_Zgate", 7, dBgS_MoveBGProc_TypicalRotY, 0xf00, NULL) == cPhs_ERROR_e) {
            return cPhs_ERROR_e;
        }
        fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
        fopAcM_setCullSizeBox2(this, mpModel->getModelData());
        mOpen = fopAcM_isSwitch(this, fopAcM_GetParam(this) & 0xff);
        mSide = (fopAcM_GetParam(this) & 0xFF00) >> 8;
        mTargetDist = -250.0f;
        if (mSide == 1) {
            #if DEBUG
            shape_angle.y += static_cast<s16>(0x8000);
            #else
            shape_angle.y += 0x8000;
            #endif
        }
        mOpenDist = 0.0f;
        if (mOpen) {
            mOpenDist = mTargetDist;
        }
        init_modeWait();
        setBaseMtx();

        #if DEBUG
        l_HIO.entryHIO("ぶら下がりスイッチゲート"); // "Hanging Switch Gate" / "Pull-Down Switch Gate"
        #endif
    }
    return step;
}

int daBsGate_c::Execute(Mtx** i_mtxP) {
    moveGate();
    *i_mtxP = &mpModel->getBaseTRMtx();
    setBaseMtx();
    return 1;
}

void daBsGate_c::moveGate() {
    typedef void (daBsGate_c::*daBsGate_modeFunc)();
    static const daBsGate_modeFunc mode_proc[3] = {
        &daBsGate_c::modeWait,
        &daBsGate_c::modeOpen,
        &daBsGate_c::modeClose,
    };
    u8 was_open = mOpen;
    mOpen = fopAcM_isSwitch(this, fopAcM_GetParam(this) & 0xff);
    if (mOpen != was_open) {
        if (mOpen) {
            init_modeOpen();
        } else {
            init_modeClose();
        }
    }
    (this->*mode_proc[mMode])();
}

void daBsGate_c::init_modeWait() {
    mMode = MODE_WAIT;
}

void daBsGate_c::modeWait() {
    /* empty function */
}

void daBsGate_c::init_modeOpen() {
    mMode = MODE_OPEN;
}

void daBsGate_c::modeOpen() {
    if (mSide == 0) {
        mDoAud_seStartLevel(Z2SE_OBJ_SW_W_DR_OP, &current.pos, 0,
                            dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
    }

    const f32 distanceToOpenPosition = cLib_addCalc(&mOpenDist, mTargetDist, 0.2f, l_HIO.mOpenSpeed, 0.5f);
    if (distanceToOpenPosition == 0.0f) {
        if (mSide == 0) {
            mDoAud_seStart(Z2SE_OBJ_SW_W_DR_OP_STOP, &current.pos, 0,
                           dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
        }
        dComIfGp_getVibration().StartShock(l_HIO.mShockStrength, 0xf, cXyz(0.0f, 1.0f, 0.0f));
        init_modeWait();
    }
}

void daBsGate_c::init_modeClose() {
    mMode = MODE_CLOSE;
}

void daBsGate_c::modeClose() {
    if (mSide == 0) {
        mDoAud_seStartLevel(Z2SE_OBJ_SW_W_DR_CL, &current.pos, 0,
                            dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
    }

    const f32 distanceToClosedPosition = cLib_addCalc(&mOpenDist, 0.0f, 0.4f, l_HIO.mCloseSpeed, 0.5f);
    if (distanceToClosedPosition == 0.0f) {
        if (mSide == 0) {
            mDoAud_seStart(Z2SE_OBJ_SW_W_DR_CL_STOP, &current.pos, 0,
                           dComIfGp_getReverb(fopAcM_GetRoomNo(this)));
        }
        dComIfGp_getVibration().StartShock(l_HIO.mShockStrength, 0xf, cXyz(0.0f, 1.0f, 0.0f));
        init_modeWait();
    }
}

int daBsGate_c::Draw() {
    g_env_light.settingTevStruct(0x10, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mpModel, &tevStr);
    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(mpModel);
    dComIfGd_setList();
    return 1;
}

int daBsGate_c::Delete() {
    dComIfG_resDelete(&mPhaseReq, "S_Zgate");

    #if DEBUG
    l_HIO.removeHIO();
    #endif

    return 1;
}

static int daBsGate_Draw(daBsGate_c* i_this) {
    return i_this->MoveBGDraw();
}


static int daBsGate_Execute(daBsGate_c* i_this) {
    return i_this->MoveBGExecute();
}

static int daBsGate_Delete(daBsGate_c* i_this) {
    fopAcM_RegisterDeleteID(i_this, "daBsGate");
    return i_this->MoveBGDelete();
}

static cPhs_Step daBsGate_Create(fopAc_ac_c* i_this) {
    return static_cast<daBsGate_c*>(i_this)->create();
}

static actor_method_class l_daBsGate_Method = {
    (process_method_func)daBsGate_Create,
    (process_method_func)daBsGate_Delete,
    (process_method_func)daBsGate_Execute,
    (process_method_func)NULL,
    (process_method_func)daBsGate_Draw,
};

actor_process_profile_definition g_profile_Obj_BsGate = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 3,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_BsGate_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daBsGate_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_BsGate_e,
    /* Actor SubMtd */ &l_daBsGate_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};