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

#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_shutter2.h"
#include "d/d_com_inf_game.h"
#include "res/Object/Htobi3.h"

const float daShutter2_c::m_max_speed[1] = {3.0f};
const float daShutter2_c::m_min_speed[1] = {1.0f};
const float daShutter2_c::m_move_len[1] = {350.0f};
const float daShutter2_c::m_width[1] = {500.0f};
const float daShutter2_c::m_height[1] = {400.0f};
const s16 daShutter2_c::m_bdlidx[1] = {dRes_INDEX_HTOBI3_BDL_HTOBI3_e};
const s16 daShutter2_c::m_dzbidx[1] = {dRes_INDEX_HTOBI3_DZB_HTOBI3_e};
const s32 daShutter2_c::m_heapsize[1] = {0x0C00};
const Vec daShutter2_c::m_cull_min[1] = {{-300.0f, -10.0f, -40.0f}};
const Vec daShutter2_c::m_cull_max[1] = {{300.0f, 400.0f, 40.0f}};

char* daShutter2_c::m_arcname[1] = {"Htobi3"};
char* daShutter2_c::m_open_ev_name[1] = {"R04DOOROPEN"};
char* daShutter2_c::m_close_ev_name[1] = {"R04DOORCLOSE"};
char* daShutter2_c::m_staff_name[1] = {"Htobi3"};

/* 00000078-000000B8       .text Delete__12daShutter2_cFv */
BOOL daShutter2_c::Delete() {
    dComIfG_resDelete(&mPhs, m_arcname[mType]);
    return TRUE;
}

/* 000000B8-00000194       .text CreateHeap__12daShutter2_cFv */
int daShutter2_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData *)dComIfG_getObjectRes(m_arcname[mType], m_bdlidx[mType]);
    JUT_ASSERT(0xe0, modelData != NULL);
    mpModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000022);
    if (!mpModel) {
        return FALSE;
    }
    return TRUE;
}

/* 00000194-00000350       .text Create__12daShutter2_cFv */
BOOL daShutter2_c::Create() {
    fopAcM_SetMtx(this, mpModel->getBaseTRMtx());
    Vec cullMin = m_cull_min[mType];
    Vec cullMax = m_cull_max[mType];
    fopAcM_setCullSizeBox(this, cullMin.x, cullMin.y, cullMin.z, cullMax.x, cullMax.y, cullMax.z);
    mSwitchNo = daShutter2_prm::getSwitchNo(this);
    mbIsNearEnemy = fopAcM_myRoomSearchEnemy(fopAcM_GetRoomNo(this)) == NULL;
    if (((mSwitchNo != 0xff) && (fopAcM_isSwitch(this, mSwitchNo))) ||
        ((mSwitchNo == 0xff) && (mbIsNearEnemy))) {
        m30C = 1;
        current.pos.y = home.pos.y + 350.0f;
    }
    else {
        m30C = 2;
    }
    mbIsSwitch = fopAcM_isSwitch(this, mSwitchNo);
    set_mtx();
    if (m_open_ev_name[mType] != NULL) {
        mOpenEventIdx = dComIfGp_evmng_getEventIdx(m_open_ev_name[mType], 0xff);
    }
    if (m_close_ev_name[mType] != NULL) {
        mCloseEventIdx = dComIfGp_evmng_getEventIdx(m_close_ev_name[mType], 0xff);
    }
    return TRUE;
}

/* 00000350-0000041C       .text _create__12daShutter2_cFv */
cPhs_State daShutter2_c::_create() {
    fopAcM_ct(this, daShutter2_c);
    mType = 0;
    cPhs_State phase_state = dComIfG_resLoad(&mPhs, m_arcname[mType]);
    if (phase_state == cPhs_COMPLEATE_e) {
        phase_state = MoveBGCreate(m_arcname[mType], m_dzbidx[mType], NULL, m_heapsize[mType]);
        if (phase_state == cPhs_ERROR_e) {
            phase_state = cPhs_ERROR_e;
        }
    }
    return phase_state;
}

/* 0000041C-000004AC       .text set_mtx__12daShutter2_cFv */
void daShutter2_c::set_mtx() {
    mpModel->setBaseScale(scale);
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(current.angle.y);
    mpModel->setBaseTRMtx(mDoMtx_stack_c::get());
    MTXCopy(mDoMtx_stack_c::get(), mMtx);
}

/* 000004AC-00000528       .text Execute__12daShutter2_cFPPA3_A4_f */
BOOL daShutter2_c::Execute(Mtx** pMtx) {
    demo();
    set_mtx();
    mbIsSwitch = fopAcM_isSwitch(this, mSwitchNo);
    mbIsNearEnemy = fopAcM_myRoomSearchEnemy(fopAcM_GetRoomNo(this)) == NULL;
    *pMtx = &mMtx;
    return TRUE;
}

/* 00000528-00000698       .text shutter_move__12daShutter2_cFv */
void daShutter2_c::shutter_move() {
    float fVar3;

    static char* action_table[4] = {
        "WAIT",
        "OPEN",
        "CLOSE",
        "OPEN_INIT",
    };
    enum {
        ACT_WAIT,
        ACT_OPEN,
        ACT_CLOSE,
        ACT_OPEN_INIT,
    };
    int actionIndex = dComIfGp_evmng_getMyActIdx(mStaffId, action_table, ARRAY_SIZE(action_table), FALSE, 0);

    float maxVel = m_max_speed[mType];
    float minVel = m_min_speed[mType];
    
    switch (actionIndex) {
        case ACT_WAIT:
        {
            dComIfGp_evmng_cutEnd(mStaffId);
            break;   
        }
        case ACT_OPEN_INIT:
        {
            fopAcM_seStart(this, JA_SE_OBJ_WDUN_R04_STR_OP, 0);
            dComIfGp_evmng_cutEnd(mStaffId);
            break;
        }
        case ACT_OPEN:
        {
            fVar3 = cLib_addCalc(&current.pos.y, home.pos.y + 350.0f, 0.1f, maxVel, minVel);
            if (fVar3 == 0.0f){
                dComIfGp_evmng_cutEnd(mStaffId);
            }
            break;

        }
        case ACT_CLOSE:
        {
            fVar3 = cLib_addCalc(&current.pos.y, home.pos.y, 0.1f, maxVel, minVel);
            if (fVar3 == 0.0f){
                dComIfGp_evmng_cutEnd(mStaffId);
            }
            break;
        }
        default:
            dComIfGp_evmng_cutEnd(mStaffId);
            break;
    }
}

/* 00000698-000008B0       .text demo__12daShutter2_cFv */
void daShutter2_c::demo() {
    u8 isSwitch = fopAcM_isSwitch(this, mSwitchNo);
    u8 isNearEnemy = fopAcM_myRoomSearchEnemy(fopAcM_GetRoomNo(this)) == NULL;
    if (mDemoState == 0) {
        if (mSwitchNo != 0xFF) {
            if (isSwitch != mbIsSwitch) {
                if (!isSwitch) {
                    mDemoState = 2;
                }
                else {
                    mDemoState = 1;
                }
            }
        }
        else if (isNearEnemy != mbIsNearEnemy) {
            if (!isNearEnemy) {
                mDemoState = 2;
            }
            else {
                mDemoState = 1;
            }
        }
    }
    if (eventInfo.checkCommandDemoAccrpt()) {
        if (dComIfGp_evmng_startCheck(mOpenEventIdx) && (mDemoState == 1)) {
            mDemoState = 0;
        }
        if (dComIfGp_evmng_startCheck(mCloseEventIdx) && (mDemoState == 2)) {
            mDemoState = 0;
        }
        if (dComIfGp_evmng_endCheck(mOpenEventIdx) || dComIfGp_evmng_endCheck(mCloseEventIdx)) {
            dComIfGp_event_reset();
        }
        mStaffId = dComIfGp_evmng_getMyStaffId(m_staff_name[mType], NULL, 0);
        shutter_move();
    }
    else if ((mDemoState == 1) && (mOpenEventIdx != 0)) {
        fopAcM_orderOtherEventId(this, mOpenEventIdx);
        eventInfo.onCondition(dEvtCnd_UNK2_e);
    }
    else if ((mDemoState == 2) && (mCloseEventIdx != 0)) {
        fopAcM_orderOtherEventId(this, mCloseEventIdx);
        eventInfo.onCondition(dEvtCnd_UNK2_e);
    }
}

/* 000008B0-00000950       .text Draw__12daShutter2_cFv */
BOOL daShutter2_c::Draw() {
    g_env_light.settingTevStruct(TEV_TYPE_BG0, &current.pos, &tevStr);
    g_env_light.setLightTevColorType(mpModel, &tevStr);
    dComIfGd_setListBG();
    mDoExt_modelUpdateDL(mpModel);
    dComIfGd_setList();
    return TRUE;
}

/* 00000950-00000970       .text daShutter2_Create__FPv */
static cPhs_State daShutter2_Create(void* i_this) {
    return ((daShutter2_c*)i_this)->_create();
}

/* 00000970-00000990       .text daShutter2_Delete__FPv */
static BOOL daShutter2_Delete(void* i_this) {
    return ((daShutter2_c*)i_this)->MoveBGDelete();
}

/* 00000990-000009BC       .text daShutter2_Draw__FPv */
static BOOL daShutter2_Draw(void* i_this) {
    return ((daShutter2_c*)i_this)->MoveBGDraw();
}

/* 000009BC-000009DC       .text daShutter2_Execute__FPv */
static BOOL daShutter2_Execute(void* i_this) {
    return ((daShutter2_c*)i_this)->MoveBGExecute();
}

/* 000009DC-000009E4       .text daShutter2_IsDelete__FPv */
static BOOL daShutter2_IsDelete(void*) {
    return TRUE;
}

static actor_method_class daShutter2MethodTable = {
    (process_method_func)daShutter2_Create,
    (process_method_func)daShutter2_Delete,
    (process_method_func)daShutter2_Execute,
    (process_method_func)daShutter2_IsDelete,
    (process_method_func)daShutter2_Draw,
};

actor_process_profile_definition g_profile_SHUTTER2 = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 0x0003,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_SHUTTER2_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daShutter2_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_SHUTTER2_e,
    /* Actor SubMtd */ &daShutter2MethodTable,
    /* Status       */ fopAcStts_CULL_e | fopAcStts_UNK40000_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};