summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_pdoor.cpp
blob: cffabcd90e3ce90fde2526cf3f5c0bc60da820ef (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/**
 * @file d_a_obj_pdoor.cpp
 * 
*/

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

#include "d/actor/d_a_obj_pdoor.h"
#include "d/actor/d_a_player.h"
#include "SSystem/SComponent/c_lib.h"
#include "SSystem/SComponent/c_math.h"
#include <cmath>
#include "d/d_com_inf_game.h"
#include "d/d_bg_w.h"

static fopAc_ac_c* PPCallBack(fopAc_ac_c* i_this, fopAc_ac_c* param_2, s16 param_3,
                           dBgW_Base::PushPullLabel param_4) {
    int iVar2 = cLib_checkBit<int>(param_4, 3);
    if (iVar2) {
        cXyz acStack_40 = param_2->current.pos - i_this->current.pos;
        mDoMtx_stack_c::YrotS(-i_this->shape_angle.y);
        mDoMtx_stack_c::multVec(&acStack_40, &acStack_40);
        int bVar1;
        if (acStack_40.z > 0.0f) {
            bVar1 = cLib_checkBit(iVar2, 1) == 0 ? 1 : 0;
        } else {
            bVar1 = cLib_checkBit(iVar2, 1) != 0;
        }
        for (int i = 0; i < 2; i++) {
            if (i == bVar1) {
                static_cast<daObjPDoor_c*>(i_this)->field_0x5b6[i]++;
            } else {
                static_cast<daObjPDoor_c*>(i_this)->field_0x5b6[i] = 0;
            }
        }
        static_cast<daObjPDoor_c*>(i_this)->field_0x5b5 = 1;
        static_cast<daObjPDoor_c*>(i_this)->mPushPullLabel = param_4;
    }
    return i_this;
}

void daObjPDoor_c::initBaseMtx() {
    mModel->setBaseScale(scale);
    setBaseMtx();
}

void daObjPDoor_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    mModel->setBaseTRMtx(mDoMtx_stack_c::get());
    MTXCopy(mDoMtx_stack_c::get(), mBgMtx);
}

static char* l_arcName = "V_OsuDoor";

static cull_box l_cull_box = {
    {0.0f, 0.0f, -600.0f},
    {600.0f, 1000.0f, 600.0f},
};

int daObjPDoor_c::Create() {
    BOOL isSw = fopAcM_isSwitch(this, getSwbit());
    BOOL isSw2 = fopAcM_isSwitch(this, getSwbit2());
    if (!isSw && !isSw2) {
        mDoorDirection = 0;
    } else if (isSw) {
        mDoorDirection = 1;
        shape_angle.y = home.angle.y + 0x1555;
    } else if (!isSw2) {
        OS_REPORT("城下町押引扉:SW1,SW2共にONになっています!\n");
        JUT_ASSERT(235, FALSE);
    } else {
        mDoorDirection = -1;
        shape_angle.y = home.angle.y - 0x1555;
    }
    initBaseMtx();
    fopAcM_SetMtx(this, mModel->getBaseTRMtx());
    mpBgW->SetPushPullCallback(PPCallBack);
    fopAcM_setCullSizeBox(this, l_cull_box.min.x, l_cull_box.min.y, l_cull_box.min.z, l_cull_box.max.x,
                          l_cull_box.max.y, l_cull_box.max.z);
    return 1;
}

int daObjPDoor_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 5);
    JUT_ASSERT(270, modelData != NULL);
    mModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000084);
    return mModel != NULL ? TRUE : FALSE;
}

int daObjPDoor_c::create1st() {
    int rv = dComIfG_resLoad(&mPhase, l_arcName);
    if (rv == cPhs_COMPLEATE_e) {
        rv = MoveBGCreate(l_arcName, 8, NULL, 0x4230, NULL);
        if (rv == cPhs_ERROR_e) {
            return rv;
        }
    }
    return rv;
}

int daObjPDoor_c::Execute(Mtx** ppMtx) {
    mode_proc_call();
    *ppMtx = &mBgMtx;
    setBaseMtx();
    field_0x5b5 = 0;
    return 1;
}

void daObjPDoor_c::mode_proc_call() {
    static daObjPDoor_c::modeFunc l_func[2] = {
        &daObjPDoor_c::modeWait,
        &daObjPDoor_c::modeRotate,
    };
    (this->*(l_func[mMode]))();
}

void daObjPDoor_c::init_modeWait() {
    field_0x5ba = 0;
    field_0x5b0 = -1;
    for (int i = 0; i < 2; i++) {
        field_0x5b6[i] = 0;
    }
    mMode = MODE_WAIT;
}

void daObjPDoor_c::modeWait() {
    daPy_py_c* player = daPy_getPlayerActorClass();
    bool bVar3 = true;
    int iVar6 = -1;
    if (field_0x5b5 != 0) {
        for (int i = 0; i < 2; i++) {
            if (field_0x5b6[i] == (u8)(cLib_checkBit<int>(mPushPullLabel, dBgW_Base::PPLABEL_4) ? 0x23 : 0x23)) {
                field_0x5b0 = i;
            }
            if (field_0x5b6[i] != 0) {
                iVar6 = i;
            }
        }
        if ((field_0x5b0 == 0 && mDoorDirection == 1) ||
            (field_0x5b0 == 1 && mDoorDirection == -1))
        {
            field_0x5b0 = -1;
        } else {
            bVar3 = false;
        }
        bool bVar2 = true;
        if ((iVar6 == 0 && mDoorDirection == 1) ||
            (iVar6 == 1 && mDoorDirection == -1))
        {
            bVar2 = false;
        }
        if (bVar2) {
            if (iVar6 == 0) {
                cLib_addCalcAngleS2(&field_0x5bc, 500, 0x3c, 5);
            } else {
                cLib_addCalcAngleS2(&field_0x5bc, -500, 0x3c, 5);
            }
            field_0x5b4++;
            f32 dVar8 = std::fabs(cM_ssin(0x3e0 * field_0x5b4));
            field_0x5ba = ((field_0x5bc * dVar8) + 10.0f);
        }
        if (field_0x5b0 != -1) {
            ((daPy_py_c*)dComIfGp_getPlayer(0))->onPushPullKeep();
            init_modeRotate();
        }
    } else {
        field_0x5bc = 0;
        field_0x5b4 = 0;
        cLib_addCalcAngleS(&field_0x5ba, 0, 4, 0x32, 5);
    }
    shape_angle.y = home.angle.y + (mDoorDirection << 14) / 3 + field_0x5ba;
    if (bVar3) {
        for (int i = 0; i < 2; i = i + 1) {
            field_0x5b6[i] = 0;
        }
        field_0x5b0 = -1;
    }
    if (daPy_py_c::checkNowWolf()) {
        cXyz cStack_44 = player->current.pos - current.pos;
        mDoMtx_stack_c::YrotS(-shape_angle.y);
        mDoMtx_stack_c::multVec(&cStack_44, &cStack_44);
        if (cStack_44.z > 0.0f) {
            if (mDoorDirection == 1) {
                mpBgW->OffPushPullOk();
            } else {
                mpBgW->OnPushPullOk();
            }
        } else {
            if (mDoorDirection == -1) {
                mpBgW->OffPushPullOk();
            } else {
                mpBgW->OnPushPullOk();
            }
        }
    } else {
        mpBgW->OnPushPullOk();
    }
}

void daObjPDoor_c::init_modeRotate() {
    field_0x5bc = 0;
    field_0x5b4 = 0;
    field_0x5b8 = 0;
    mMode = MODE_ROTATE;
}

void daObjPDoor_c::modeRotate() {
    daPy_getPlayerActorClass();
    field_0x5b8++;
    shape_angle.y = home.angle.y + (mDoorDirection << 14) / 3;
    field_0x5ba = ((f32)field_0x5b8 / 60.0f) * 5461.0f;
    if (field_0x5b0 == 1) {
        field_0x5ba = -field_0x5ba;
    }
    shape_angle.y += field_0x5ba;
    fopAcM_seStartLevel(this, Z2SE_OBJ_HYRULE_DR_MOVE, 0);
    if (field_0x5b8 == 60) {
        if (field_0x5b0 == 0) {
            mDoorDirection++;
        } else {
            mDoorDirection--;
        }
        if (mDoorDirection == 1) {
           fopAcM_onSwitch(this, getSwbit());
           fopAcM_offSwitch(this, getSwbit2());
        } else if (mDoorDirection == -1) {
           fopAcM_offSwitch(this, getSwbit());
           fopAcM_onSwitch(this, getSwbit2());
        } else if (mDoorDirection == 0) {
           fopAcM_offSwitch(this, getSwbit());
           fopAcM_offSwitch(this, getSwbit2());
        }
        ((daPy_py_c*)dComIfGp_getPlayer(0))->offPushPullKeep();
        dComIfGp_getVibration().StartShock(8, 0x1f, cXyz(0.0f, 1.0f, 0.0f));
        fopAcM_seStart(this, Z2SE_OBJ_HYRULE_DR_STOP, 0);
        init_modeWait();
    }
}

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

int daObjPDoor_c::Delete() {
    mpBgW->SetPushPullCallback(NULL);
    dComIfG_resDelete(&mPhase, l_arcName);
    return 1;
}

static int daObjPDoor_create1st(daObjPDoor_c* i_this) {
    fopAcM_ct(i_this, daObjPDoor_c);
    return i_this->create1st();
}

static int daObjPDoor_MoveBGDelete(daObjPDoor_c* i_this) {
    return i_this->MoveBGDelete();
}

static int daObjPDoor_MoveBGExecute(daObjPDoor_c* i_this) {
    return i_this->MoveBGExecute();
}

static int daObjPDoor_MoveBGDraw(daObjPDoor_c* i_this) {
    return i_this->Draw();
}

static actor_method_class daObjPDoor_METHODS = {
    (process_method_func)daObjPDoor_create1st,
    (process_method_func)daObjPDoor_MoveBGDelete,
    (process_method_func)daObjPDoor_MoveBGExecute,
    NULL,
    (process_method_func)daObjPDoor_MoveBGDraw,
};

actor_process_profile_definition g_profile_Obj_PushDoor = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 3,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_PushDoor_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjPDoor_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_PushDoor_e,
    /* Actor SubMtd */ &daObjPDoor_METHODS,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_CULL_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};