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
|
/**
* @file d_a_obj_swBallA.cpp
*
*/
#include "d/dolzel_rel.h" // IWYU pragma: keep
#include "d/actor/d_a_obj_swBallA.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[8];
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)->getType() == daObjCarry_c::TYPE_LV8_BALL)
{
if (l_target_info_count < 8) {
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 ((daObjSwBallA_c*)param_0)->CreateHeap();
}
static GXColor const l_color = {0x3,0x96,0xFF,0xFF};
int daObjSwBallA_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 daObjSwBallA_c::search_ball() {
l_target_info_count = 0;
for (int i = 0; i < 8; 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 < 8; j++) {
if (id == field_0x58c[j]) {
idIndex = j;
break;
}
}
if (idIndex < 0) {
for (int j = 0; j < 8; j++) {
if (field_0x58c[j] == -1) {
field_0x58c[j] = id;
break;
}
}
}
}
}
}
}
void daObjSwBallA_c::initBaseMtx() {
setBaseMtx();
}
void daObjSwBallA_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 daObjSwBallA_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 < 8; i++) {
field_0x58c[i] = -1;
}
field_0x5c0 = -1;
if (fopAcM_isSwitch(this, getSwbit2())) {
field_0x588->setFrame(field_0x588->getEndFrame());
field_0x5ae = 2;
} else {
fopAcM_offSwitch(this, getSwbit());
field_0x588->setFrame(0.0f);
field_0x5ae = 0;
}
GXColor* color = mModel->getModelData()->getMaterialNodePointer(0)->getTevKColor(1);
color->r = l_color.r;
color->g = l_color.g;
color->b = l_color.b;
return 1;
}
static char* l_arcName = "P_LBswA";
int daObjSwBallA_c::CreateHeap() {
J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes(l_arcName, 4);
JUT_ASSERT(381, modelData != NULL);
mModel = mDoExt_J3DModel__create(modelData, 0x80000, 0x11000284);
if (mModel == 0) {
return 0;
}
J3DAnmTextureSRTKey* pbtk = (J3DAnmTextureSRTKey*)dComIfG_getObjectRes(l_arcName, 7);
JUT_ASSERT(381, 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 daObjSwBallA_c::create() {
fopAcM_ct(this, daObjSwBallA_c);
if (field_0x5c4 == 0) {
field_0x5c4 = 1;
field_0x5c6 = home.angle.x;
field_0x5c8 = 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 daObjSwBallA_c::execute() {
typedef void (daObjSwBallA_c::*ballfunc)();
static ballfunc l_func[2] = {&daObjSwBallA_c::actionRun, &daObjSwBallA_c::actionStop};
(this->*l_func[field_0x5ad])();
eventUpdate();
field_0x588->play();
return 1;
}
void daObjSwBallA_c::actionRun() {
u32 iVar4 = field_0x5c0;
search_ball();
PutCrrPos();
switch (field_0x5ae) {
case 0:
if (iVar4 == -1 && field_0x5c0 != -1) {
fopAcM_seStart(this, Z2SE_OBJ_L8_L_BALL_SW_ON, 0);
field_0x588->setPlaySpeed(1.0f);
field_0x5ae = 1;
}
break;
case 1:
if (field_0x5c0 == -1) {
fopAcM_seStart(this, Z2SE_OBJ_L8_L_BALL_SW_OFF, 0);
field_0x588->setPlaySpeed(-1.0f);
fopAcM_offSwitch(this, getSwbit());
field_0x5ae = 0;
} else {
if (field_0x588->play() != 0) {
fopAcM_onSwitch(this, getSwbit());
if (getEvent() != 0xff) {
orderEvent(getEvent(), 0xff, 1);
}
if (getArg0() == 1) {
field_0x5ae = 2;
}
}
fopAcM_seStartLevel(this, Z2SE_OBJ_L8_L_BALL_SW, 0);
}
break;
case 2:
break;
}
}
void daObjSwBallA_c::actionStop() {
/* empty function */
}
void daObjSwBallA_c::PutCrrPos() {
daPy_py_c* player = daPy_getPlayerActorClass();
s16 sVar5 = cLib_targetAngleY(&player->current.pos, ¤t.pos) - player->shape_angle.y;
if (fopAcM_searchPlayerDistanceXZ(this) < 300.0f && 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->getType() == daObjCarry_c::TYPE_LV8_BALL)
{
player->setForcePutPos(current.pos);
}
}
daObjCarry_c* carryObj;
for (u8 i = 0; i < 8; 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_0x5c0 == -1 || field_0x5c0 == field_0x58c[i]) {
switch(field_0x5b7[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_0x5c0 = field_0x58c[i];
field_0x5b7[i] = 1;
} else {
if (!isArea) {
field_0x5c0 = 0xffffffff;
}
}
break;
case 1:
if (isArea != 0 && carryNow == 0 && hookCarryNow == 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_0x5b7[i] = 0;
}
} else {
carryObj->endCtrl();
field_0x5b7[i] = 0;
field_0x5c0 = 0xffffffff;
}
break;
}
}
}
clrFlag(i);
if (isArea) {
onFlag(i, 2);
}
if (carryNow) {
onFlag(i, 1);
}
if (hookCarryNow) {
onFlag(i, 4);
}
}
}
int daObjSwBallA_c::draw() {
g_env_light.settingTevStruct(0, ¤t.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 daObjSwBallA_c::_delete() {
if (!fopAcM_isSwitch(this, getSwbit2())) {
fopAcM_offSwitch(this, getSwbit());
}
dComIfG_resDelete(&field_0x57c, l_arcName);
return 1;
}
static int daObjSwBallA_Draw(daObjSwBallA_c* param_0) {
return param_0->draw();
}
static int daObjSwBallA_Execute(daObjSwBallA_c* param_0) {
return param_0->execute();
}
static int daObjSwBallA_Delete(daObjSwBallA_c* param_0) {
return param_0->_delete();
}
static int daObjSwBallA_Create(fopAc_ac_c* param_0) {
return ((daObjSwBallA_c*)param_0)->create();
}
static actor_method_class l_daObjSwBallA_Method = {
(process_method_func)daObjSwBallA_Create,
(process_method_func)daObjSwBallA_Delete,
(process_method_func)daObjSwBallA_Execute,
NULL,
(process_method_func)daObjSwBallA_Draw,
};
actor_process_profile_definition g_profile_Obj_SwBallA = {
/* Layer ID */ fpcLy_CURRENT_e,
/* List ID */ 7,
/* List Prio */ fpcPi_CURRENT_e,
/* Proc Name */ fpcNm_Obj_SwBallA_e,
/* Proc SubMtd */ &g_fpcLf_Method.base,
/* Size */ sizeof(daObjSwBallA_c),
/* Size Other */ 0,
/* Parameters */ 0,
/* Leaf SubMtd */ &g_fopAc_Method.base,
/* Draw Prio */ fpcDwPi_Obj_SwBallA_e,
/* Actor SubMtd */ &l_daObjSwBallA_Method,
/* Status */ fopAcStts_UNK_0x40000_e | fopAcStts_CULL_e,
/* Group */ fopAc_ACTOR_e,
/* Cull Type */ fopAc_CULLBOX_CUSTOM_e,
};
|