summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_obj_swBallB.cpp
blob: 54c4acd5c6bd18d550421f85361ef42f755e4647 (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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
/**
 * @file d_a_obj_swBallB.cpp
 * 
*/

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

#include "d/actor/d_a_obj_swBallB.h"
#include "d/actor/d_a_player.h"
#include "d/actor/d_a_obj_carry.h"
#include "d/d_com_inf_game.h"
#include "JSystem/J3DGraphBase/J3DMaterial.h"
#include "d/d_lib.h"

static daObjCarry_c* l_target_info[2];

static int l_target_info_count;

static void* s_ball_sub(void* param_1, void* param_2) {
    if (fopAcM_IsActor(param_1) && fopAcM_GetName(param_1) == fpcNm_Obj_Carry_e &&
        ((daObjCarry_c*)param_1)->prm_chk_type_lightball())
    {
        if (l_target_info_count < 2) {
            l_target_info[l_target_info_count] = (daObjCarry_c*)param_1;
            l_target_info_count++;
        }
    }
    return NULL;
}

static int CheckCreateHeap(fopAc_ac_c* param_0) {
    return ((daObjSwBallB_c*)param_0)->CreateHeap();
}

static GXColor const l_color = {0x03, 0x96, 0xFF, 0xFF};

static u16 const l_event_bitA[6] = {
    0x4304, /* dSv_event_flag_c::F_0551 - Palace of Twilight - Palace of Twilight control use 1 */
    0x4302, /* dSv_event_flag_c::F_0552 - Palace of Twilight - Palace of Twilight control use 2 */
    0x4301, /* dSv_event_flag_c::F_0553 - Palace of Twilight - Palace of Twilight control use 3 */
    0x4480, /* dSv_event_flag_c::F_0554 - Palace of Twilight - Palace of Twilight control use 4 */
    0x4440, /* dSv_event_flag_c::F_0555 - Palace of Twilight - Palace of Twilight control use 5 */
    0x4420, /* dSv_event_flag_c::F_0556 - Palace of Twilight - Palace of Twilight control use 6 */
};

static u16 const l_event_bitB[6] = {
    0x4410, /* dSv_event_flag_c::F_0557 - Palace of Twilight - Palace of Twilight control use 7 */
    0x4408, /* dSv_event_flag_c::F_0558 - Palace of Twilight - Palace of Twilight control use 8 */
    0x4404, /* dSv_event_flag_c::F_0559 - Palace of Twilight - Palace of Twilight control use 9 */
    0x4402, /* dSv_event_flag_c::F_0560 - Palace of Twilight - Palace of Twilight control use 10 */
    0x4401, /* dSv_event_flag_c::F_0561 - Palace of Twilight - Palace of Twilight control use 11 */
    0x4580, /* dSv_event_flag_c::F_0562 - Palace of Twilight - Palace of Twilight control use 12 */
};

int daObjSwBallB_c::checkArea_sub(fopAc_ac_c* param_1) {
    if (param_1 == NULL) {
        return 0;
    }
    if (getType() == 0) {
        if (param_1->current.pos.y >= current.pos.y - 10.0f &&
            param_1->current.pos.y < current.pos.y + scale.y * 100.0f &&
            fopAcM_searchActorDistanceXZ(this, param_1) < scale.x * 100.0f)
        {
            return 1;
        }
    } else {
        if (getType() == 1) {
            cXyz cStack_1c(scale.x * -100.0f, 0.0f, scale.z * -100.0f);
            cXyz cStack_28(scale.x * 100.0f, scale.y * 100.0f, scale.z * 100.0f);
            cStack_1c.y += current.pos.y - 10.0f;
            cStack_28.y += current.pos.y;
            if (param_1->current.pos.y >= cStack_1c.y && param_1->current.pos.y < cStack_28.y &&
                dLib_checkActorInRectangle(param_1, this, &cStack_1c, &cStack_28))
            {
                return 1;
            }
        }
    }
    return 0;
}

void daObjSwBallB_c::search_ball() {
    l_target_info_count = 0;
    for (int i = 0; i < 2; i++) {
        l_target_info[i] = NULL;
    }
    fpcM_Search(s_ball_sub, this);
    for (int i = 0; i < l_target_info_count; i++) {
        if (l_target_info[i] != 0) {
            fpc_ProcID id = fopAcM_GetID(l_target_info[i]);
            if (id != -1) {
                int idIndex = -1;
                for (int j = 0; j < 2; j++) {
                    if (id == field_0x58c[j]) {
                        idIndex = j;
                        break;
                    }
                }
                if (idIndex < 0) {
                    for (int j = 0; j < 2; j++) {
                        if (field_0x58c[j] == -1) {
                            field_0x58c[j] = id;
                            break;
                        }
                    }
                }
            }
        }
    }

    for (int j = 0; j < 2; j++) {
        if (fopAcM_SearchByID(field_0x58c[j]) == NULL) {
            field_0x58c[j] = -1;
        }
    }
    if (field_0x59c != -1 && fopAcM_SearchByID(field_0x59c) == NULL) {
        field_0x59c = -1;
    }
}

void daObjSwBallB_c::initBaseMtx() {
    setBaseMtx();
}

void daObjSwBallB_c::setBaseMtx() {
    mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z);
    mDoMtx_stack_c::YrotM(shape_angle.y);
    mModel->setBaseTRMtx(mDoMtx_stack_c::get());
}

int daObjSwBallB_c::Create() {
    initBaseMtx();
    fopAcM_SetMtx(this, mModel->getBaseTRMtx());
    J3DJoint* joint = mModel->getModelData()->getJointNodePointer(0);
    fopAcM_setCullSizeBox(this,
        joint->getMin()->x, joint->getMin()->y, joint->getMin()->z,
        joint->getMax()->x, joint->getMax()->y, joint->getMax()->z);
    for (int i = 0; i < 2; i++) {
        field_0x58c[i] = -1;
    }
    field_0x59c = -1;

    if (fopAcM_GetRoomNo(this) == 0 && fopAcM_isSwitch(this, 0x3f)) {
        field_0x588->setFrame(field_0x588->getEndFrame());
        if (getArg1() == 1) {
            fopAcM_onSwitch(this, getSwbit2());
        }
        fopAcM_onSwitch(this, getSwbit());
        field_0x596 = 5;
    }
    GXColor* color = mModel->getModelData()->getMaterialNodePointer(0)->getTevKColor(1);
    color->r = l_color.r;
    color->g = l_color.g;
    color->b = l_color.b;
    execute();
    return 1;
}

static char* l_arcName = "P_LBswBC";

int daObjSwBallB_c::CreateHeap() {
    J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 5);
    JUT_ASSERT(427, modelData != NULL);
    mModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000284);
    if (mModel == 0) {
        return 0;
    }
    J3DAnmTextureSRTKey* pbtk = (J3DAnmTextureSRTKey*)dComIfG_getObjectRes(l_arcName, 9);
    JUT_ASSERT(441, pbtk != NULL);
    field_0x588 = new mDoExt_btkAnm();
    if (field_0x588 == NULL || field_0x588->init(modelData, pbtk, 1, 0, 1.0f, 0, -1) == 0) {
        return 0;
    }
    field_0x588->setPlaySpeed(0.0f);
    return 1;
}

int daObjSwBallB_c::create() {
    fopAcM_ct(this, daObjSwBallB_c);
    if (field_0x5a0 == 0) {
        field_0x5a0 = 1;
        field_0x5a2 = home.angle.x;
        field_0x5a4 = home.angle.z;
        shape_angle.x = 0;
        current.angle.x = 0;
        home.angle.x = 0;
        shape_angle.z = 0;
        current.angle.z = 0;
        home.angle.z = 0;
    }
    int res = dComIfG_resLoad(&field_0x57c, l_arcName);
    if (res == cPhs_COMPLEATE_e) {
        if (fopAcM_entrySolidHeap(this, CheckCreateHeap, 0x940) == 0) {
            return cPhs_ERROR_e;
        } else if (Create() == 0) {
            return cPhs_ERROR_e;
        }
    }
    return res;
}

int daObjSwBallB_c::execute() {
    typedef void (daObjSwBallB_c::*ballfunc)();
    static ballfunc l_func[2] = {&daObjSwBallB_c::actionRun, &daObjSwBallB_c::actionStop};
    (this->*l_func[field_0x595])();
    eventUpdate();
    field_0x588->play();
    return 1;
}

void daObjSwBallB_c::actionRun() {
    u32 iVar4 = field_0x59c;
    search_ball();
    PutCrrPos();
    switch (field_0x596) {
    case 0:
        if (iVar4 == -1 && field_0x59c != -1) {
            fopAcM_seStart(this, Z2SE_OBJ_L8_L_BALL_SW_ON, 0);
            field_0x588->setPlaySpeed(1.0f);
            field_0x596 = 1;
        } else if (field_0x5ac != 0) {
            fopAcM_seStart(this, Z2SE_OBJ_L8_L_BALL_SW_ON, 0);
            field_0x588->setPlaySpeed(1.0f);
            field_0x596 = 3;
        }
        break;
    case 1:
        if (field_0x59c == -1) {
            field_0x588->setPlaySpeed(-1.0f);
            if (dComIfGp_roomControl_getStayNo() != 0) {
                fopAcM_offSwitch(this, getSwbit());
            }
            fopAcM_seStart(this, Z2SE_OBJ_L8_L_BALL_SW_OFF, 0);
            field_0x5a8 = -1;
            field_0x596 = 0;
        } else {
            if (field_0x588->play() != 0) {
                if (dComIfGp_roomControl_getStayNo() == 0) {
                    daObjCarry_c* carryObj = (daObjCarry_c*)fopAcM_SearchByID(field_0x59c);
                    if (carryObj != NULL) {
                        if (getArg1() == 1) {
                            fopAcM_onSwitch(this, getSwbit2());
                        }
                        if (carryObj->getType() == 8) {
                            fopAcM_onSwitch(this, getSwbit());
                            dComIfGs_onEventBit(l_event_bitA[getID()]);
                            field_0x5a8 = 0;
                        } else {
                            dComIfGs_onEventBit(l_event_bitB[getID()]);
                            field_0x5a8 = 1;
                        }
                    }
                } else {
                    fopAcM_onSwitch(this, getSwbit());
                }
                if (getEvent() != 0xff) {
                    orderEvent(getEvent(), 0xff, 1);
                }
            }
            if (field_0x5ad != 0) {
                fopAcM_seStart(this, Z2SE_OBJ_L8_L_BALL_SW_OFF, 0);
                field_0x588->setPlaySpeed(-1.0f);
                field_0x596 = 4;
            }
            fopAcM_seStartLevel(this, Z2SE_OBJ_L8_L_BALL_SW, 0);
        }
        break;
    case 2:
        break;
    case 3:
        field_0x588->play();
        fopAcM_seStartLevel(this, Z2SE_OBJ_L8_L_BALL_SW, 0);
        break;
    case 4:
        if (field_0x588->play() != 0 && field_0x5ac != 0) {
            fopAcM_seStart(this, Z2SE_OBJ_L8_L_BALL_SW_ON, 0);
            field_0x588->setPlaySpeed(1.0f);
            field_0x596 = 3;
        }
        break;
    case 5:
        break;
    }
}

void daObjSwBallB_c::actionStop() {
    /* empty function */
}

void daObjSwBallB_c::PutCrrPos() {
    daPy_py_c* player = daPy_getPlayerActorClass();
    s16 sVar5 = cLib_targetAngleY(&player->current.pos, &current.pos) - player->shape_angle.y;
    if (fopAcM_searchPlayerDistanceXZ(this) < 150.0f && sVar5 < 0x4000 && sVar5 > -0x4000) {
        daObjCarry_c* carryObj = (daObjCarry_c*)fopAcM_SearchByID(player->getGrabActorID());
        if (carryObj != NULL && fopAcM_IsActor(carryObj) &&
            fopAcM_GetName(carryObj) == fpcNm_Obj_Carry_e && carryObj->prm_chk_type_lightball())
        {
            player->setForcePutPos(current.pos);
            if (!dComIfGp_event_runCheck()) {
                dComIfGp_setDoStatus(0x14, 2);
            }
        }
    }
    daObjCarry_c* carryObj;
    for (u8 i = 0; i < 2; i++) {
        bool isArea = false;
        u8 carryNow = 0;
        u8 hookCarryNow = 0;
        if (field_0x58c[i] != -1) {
            carryObj = (daObjCarry_c*)fopAcM_SearchByID(field_0x58c[i]);
            isArea = checkArea_sub(carryObj);
            carryNow = fopAcM_checkCarryNow(carryObj) >> 13;
            hookCarryNow = fopAcM_checkHookCarryNow(carryObj) >> 20;
            if (field_0x59c == -1 || field_0x59c == field_0x58c[i]) {
                switch(field_0x599[i]) {
                case 0:
                    if ((isArea && ((carryNow == 0 && checkFlag(i, 1)) ||
                                        (hookCarryNow == 0 && checkFlag(i, 4)))) ||
                        (isArea && !checkFlag(i, 2) && carryNow == 0 && hookCarryNow == 0))
                    {
                        carryObj->startCtrl();
                        field_0x59c = field_0x58c[i];
                        field_0x599[i] = 1;
                    } else {
                        if (!isArea) {
                            field_0x59c = 0xffffffff;
                        }
                    }
                    break;
                case 1:
                    if (isArea != 0) {
                        cLib_chaseF(&carryObj->current.pos.x, current.pos.x,
                                                 10.0f);
                        cLib_chaseF(&carryObj->current.pos.z, current.pos.z,
                                                 10.0f);
                        if (fopAcM_searchActorDistanceXZ(this, carryObj) == 0.0f) {
                            carryObj->endCtrl();
                            field_0x599[i] = 0;
                        }
                    } else {
                        carryObj->endCtrl();
                        field_0x599[i] = 0;
                        field_0x59c = 0xffffffff;
                    }
                    break;
                }
            }
        }
        clrFlag(i);
        if (isArea) {
            onFlag(i, 2);
        }
        if (carryNow) {
            onFlag(i, 1);
        }
        if (hookCarryNow) {
            onFlag(i, 4);
        }
    }
}

int daObjSwBallB_c::draw() {
    g_env_light.settingTevStruct(0, &current.pos, &tevStr);
    g_env_light.setLightTevColorType_MAJI(mModel, &tevStr);
    dComIfGd_setListDarkBG();
    J3DMaterial* material = mModel->getModelData()->getMaterialNodePointer(0);
    if (material->getTexGenBlock()->getTexMtx(1) != NULL) {
        J3DTexMtxInfo* texMtxInfo = &material->getTexGenBlock()->getTexMtx(1)->getTexMtxInfo();
        if (texMtxInfo != NULL) {
            Mtx auStack_48;
            C_MTXLightOrtho(auStack_48, 100.0f, -100.0f, -100.0f, 100.0f, 1.0f, 1.0f, 0.0f, 0.0f);
            mDoMtx_stack_c::XrotS(0x4000);
            mDoMtx_stack_c::transM(-current.pos.x, -current.pos.y, -current.pos.z);
            cMtx_concat(auStack_48, mDoMtx_stack_c::get(), texMtxInfo->mEffectMtx);
        }
    }
    field_0x588->entry(mModel->getModelData());
    mDoExt_modelUpdateDL(mModel);
    mDoExt_btkAnmRemove(mModel->getModelData());
    dComIfGd_setList();
    return 1;
}

int daObjSwBallB_c::_delete() {
    dComIfG_resDelete(&field_0x57c, l_arcName);
    return 1;
}

static int daObjSwBallB_Draw(daObjSwBallB_c* param_0) {
    return param_0->draw();
}

static int daObjSwBallB_Execute(daObjSwBallB_c* param_0) {
    return param_0->execute();
}

static int daObjSwBallB_Delete(daObjSwBallB_c* param_0) {
    return param_0->_delete();
}

static int daObjSwBallB_Create(fopAc_ac_c* param_0) {
    return ((daObjSwBallB_c*)param_0)->create();
}

static actor_method_class l_daObjSwBallB_Method = {
    (process_method_func)daObjSwBallB_Create,
    (process_method_func)daObjSwBallB_Delete,
    (process_method_func)daObjSwBallB_Execute,
    NULL,
    (process_method_func)daObjSwBallB_Draw,
};

actor_process_profile_definition g_profile_Obj_SwBallB = {
    /* Layer ID     */ fpcLy_CURRENT_e,
    /* List ID      */ 7,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_Obj_SwBallB_e,
    /* Proc SubMtd  */ &g_fpcLf_Method.base,
    /* Size         */ sizeof(daObjSwBallB_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopAc_Method.base,
    /* Draw Prio    */ fpcDwPi_Obj_SwBallB_e,
    /* Actor SubMtd */ &l_daObjSwBallB_Method,
    /* Status       */ fopAcStts_UNK_0x40000_e | fopAcStts_UNK_0x4000_e | fopAcStts_CULL_e,
    /* Group        */ fopAc_ACTOR_e,
    /* Cull Type    */ fopAc_CULLBOX_CUSTOM_e,
};