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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
/**
* @file itemOnGround.c
* @ingroup Objects
*
* @brief Item On Ground object
*/
#include "object/itemOnGround.h"
#include "collision.h"
#include "entity.h"
#include "flags.h"
#include "functions.h"
#include "hitbox.h"
#include "item.h"
#include "itemMetaData.h"
#include "object.h"
#include "player.h"
#include "sound.h"
#include "tiles.h"
void sub_08081150(ItemOnGroundEntity* this);
u8 sub_0808147C(u32);
void sub_080814A4(ItemOnGroundEntity* this);
u32 sub_080814C0(ItemOnGroundEntity* this);
void sub_08081500(ItemOnGroundEntity* this);
void sub_0808153C(ItemOnGroundEntity* this);
void sub_08081598(ItemOnGroundEntity* this);
void sub_080813BC(ItemOnGroundEntity* this);
void sub_080810FC(ItemOnGroundEntity* this);
void ItemOnGround_Init(ItemOnGroundEntity* this);
void ItemOnGround_Action1(ItemOnGroundEntity* this);
void ItemOnGround_Action2(ItemOnGroundEntity* this);
void ItemOnGround_Action3(ItemOnGroundEntity* this);
void ItemOnGround_Action4(ItemOnGroundEntity* this);
void sub_080810A8(ItemOnGroundEntity* this);
void sub_080810FC(ItemOnGroundEntity* this);
void sub_08081150(ItemOnGroundEntity* this);
void sub_08081134(ItemOnGroundEntity* this);
void sub_08081188(ItemOnGroundEntity* this);
void sub_080811AC(ItemOnGroundEntity* this);
void sub_080811C8(ItemOnGroundEntity* this);
void sub_080811D8(ItemOnGroundEntity* this);
void sub_08081248(ItemOnGroundEntity* this);
void sub_0808126C(ItemOnGroundEntity* this);
void sub_0808127C(ItemOnGroundEntity* this);
void nullsub_113(ItemOnGroundEntity* this);
void sub_080812A0(ItemOnGroundEntity* this);
void sub_080812A8(ItemOnGroundEntity* this);
void sub_080812E8(ItemOnGroundEntity* this);
void nullsub_510(ItemOnGroundEntity* this);
void sub_080813D4(ItemOnGroundEntity* this);
void sub_080813E8(ItemOnGroundEntity* this);
void sub_080813F0(ItemOnGroundEntity* this);
bool32 CheckShouldPlayItemGetCutscene(ItemOnGroundEntity* this);
void sub_08081404(ItemOnGroundEntity*, u32);
typedef struct {
u8 unk0[2];
u16 sfx;
u8 unk4;
u8 unk5[3];
} Unk_0811E84C;
void ItemOnGround(ItemOnGroundEntity* this) {
static void (*const ItemOnGround_Actions[])(ItemOnGroundEntity*) = {
ItemOnGround_Init, ItemOnGround_Action1, ItemOnGround_Action2, ItemOnGround_Action3, ItemOnGround_Action4,
};
if (super->contactFlags & CONTACT_NOW) {
switch (super->contactFlags & 0x7F) {
case 20:
super->action = 3;
COLLISION_OFF(super);
super->spriteSettings.draw = 1;
super->collisionFlags |= 0x10;
super->child = super->contactedEntity;
break;
case 0:
case 1:
case 4:
case 5:
case 6:
case 8:
case 9:
case 10:
case 11:
case 12:
case 30:
sub_08081598(this);
break;
}
}
if (sub_0806F520(super)) {
sub_080813BC(this);
} else {
ItemOnGround_Actions[super->action](this);
}
if (super->type == 0x5C) {
gRoomVars.numKinstoneDrops++;
}
sub_08080CB4(super);
}
void ItemOnGround_Init(ItemOnGroundEntity* this) {
static void (*const gUnk_0811E7E8[])(ItemOnGroundEntity*) = {
sub_080810A8, sub_080810FC, sub_08081150, sub_08081134, sub_08081188, sub_080810A8,
sub_080810A8, sub_080811AC, sub_080811C8, sub_080811D8, sub_080810A8,
};
if (this->unk_86 && CheckFlags(this->unk_86)) {
DeleteThisEntity();
}
if (super->type != ITEM_FAIRY) {
super->spriteSettings.draw = 1;
super->spritePriority.b1 = 3;
super->spriteSettings.shadow = 0;
super->hitType = 7;
super->collisionFlags = 0x47;
super->hurtType = 0x44;
super->health = 0xFF;
super->hitbox = (Hitbox*)&gUnk_080FD1A8;
switch (super->type) {
case ITEM_SHELLS:
case ITEM_RUPEE1:
case ITEM_RUPEE5:
case ITEM_RUPEE20:
case ITEM_RUPEE50:
case ITEM_RUPEE100:
case ITEM_KINSTONE:
case ITEM_BOMBS5:
case ITEM_ARROWS5:
case ITEM_HEART:
super->collisionMask = 0x17;
break;
default:
super->collisionMask = 0x11;
break;
}
this->unk_69 = super->timer;
this->unk_6a = 0;
this->unk_6c = 0;
this->unk_68 = 0;
super->timer = 0;
SetEntityPriority(super, PRIO_NO_BLOCK);
super->gustJarFlags = sub_0808147C(super->type);
gUnk_0811E7E8[this->unk_69](this);
} else {
Entity* entity = CreateObject(FAIRY, 0x60, 0);
if (entity != NULL) {
entity->timer = 0;
if (super->timer == 1) {
entity->type2 = 2;
}
CopyPosition(super, entity);
DeleteThisEntity();
}
}
}
void sub_080810A8(ItemOnGroundEntity* this) {
super->action = 1;
sub_080814A4(this);
if (super->direction & 0x80) {
super->direction &= 0x1F;
if (super->speed == 0) {
super->speed = 0x100;
}
} else {
super->direction |= 0xFF;
}
if (super->zVelocity == 0) {
super->zVelocity = Q_16_16(1.875);
}
if (super->collisionLayer == 2) {
ResolveCollisionLayer(super);
}
}
void sub_080810FC(ItemOnGroundEntity* this) {
if (super->type != ITEM_HEART) {
sub_08081598(this);
} else {
super->action = 2;
super->subAction = 0;
COLLISION_ON(super);
super->collisionMask = 0x11;
CopyPosition(&gPlayerEntity.base, super);
}
}
void sub_08081134(ItemOnGroundEntity* this) {
sub_080814A4(this);
this->unk_6c += 80;
sub_08081150(this);
}
void sub_08081150(ItemOnGroundEntity* this) {
super->action = 2;
COLLISION_ON(super);
super->z.HALF.HI = -0x80;
super->spriteOrientation.flipY = 1;
super->spriteRendering.b3 = 1;
SoundReq(SFX_12D);
}
void sub_08081188(ItemOnGroundEntity* this) {
super->action = 2;
COLLISION_ON(super);
if (super->collisionLayer == 2) {
ResolveCollisionLayer(super);
}
}
void sub_080811AC(ItemOnGroundEntity* this) {
super->action = 2;
super->spriteSettings.draw = 0;
this->unk_6e = GetTileTypeAtEntity(super);
}
void sub_080811C8(ItemOnGroundEntity* this) {
super->action = 2;
super->spriteSettings.draw = 0;
}
void sub_080811D8(ItemOnGroundEntity* this) {
sub_08081188(this);
SoundReq(SFX_215);
}
void ItemOnGround_Action1(ItemOnGroundEntity* this) {
if (this->unk_69 != 6) {
ProcessMovement2(super);
} else {
LinearMoveUpdate(super);
}
GravityUpdate(super, Q_8_8(40.0));
if (super->zVelocity <= 0) {
super->action = 2;
COLLISION_ON(super);
sub_080814A4(this);
}
}
void ItemOnGround_Action2(ItemOnGroundEntity* this) {
static void (*const gUnk_0811E814[])(ItemOnGroundEntity*) = {
sub_08081248, sub_08081248, sub_0808126C, sub_0808127C, nullsub_113, sub_080812A0,
sub_08081248, sub_080812A8, sub_080812E8, nullsub_510, sub_08081248,
};
gUnk_0811E814[this->unk_69](this);
}
void sub_08081248(ItemOnGroundEntity* this) {
sub_08081500(this);
if (sub_080814C0(this)) {
sub_08081404(this, 0);
} else {
sub_0800442E(super);
}
}
void sub_0808126C(ItemOnGroundEntity* this) {
UpdateAnimationSingleFrame(super);
sub_0808153C(this);
}
void sub_0808127C(ItemOnGroundEntity* this) {
if (sub_080814C0(this)) {
sub_08081404(this, 0);
} else {
sub_0808153C(this);
}
}
void nullsub_113(ItemOnGroundEntity* this) {
}
void sub_080812A0(ItemOnGroundEntity* this) {
sub_08081500(this);
}
void sub_080812A8(ItemOnGroundEntity* this) {
if (GetCollisionDataAtEntity(super) != COLLISION_DATA_15 &&
this->unk_6e != GetTileTypeAtEntity(super)) {
super->direction = 0;
super->speed = 0;
super->spriteSettings.draw = 1;
this->unk_69 = 0;
sub_080810A8(this);
}
}
void sub_080812E8(ItemOnGroundEntity* this) {
PlayerState* playerState = &gPlayerState;
#ifdef EU
if ((playerState->swim_state & 0x80) && IsColliding(super, &gPlayerEntity.base)) {
#else
if ((playerState->swim_state & 0x80) && (playerState->flags & PL_MINISH) == 0 &&
IsColliding(super, &gPlayerEntity.base)) {
#endif
sub_080810FC(this);
}
}
void nullsub_510(ItemOnGroundEntity* this) {
}
void ItemOnGround_Action3(ItemOnGroundEntity* this) {
Entity* other = super->child;
if (!(other->kind == PLAYER_ITEM && other->id == 3)) {
sub_08081404(this, 0);
} else {
CopyPosition(other, super);
super->z.HALF.HI--;
other = &gPlayerEntity.base;
if (IsColliding(super, other)) {
sub_080810FC(this);
}
}
}
void ItemOnGround_Action4(ItemOnGroundEntity* this) {
if (--super->timer) {
Entity* other = super->child;
super->x.WORD = other->x.WORD;
super->y.WORD = other->y.WORD;
super->spriteOrientation.flipY = other->spriteOrientation.flipY;
super->spriteRendering.b3 = other->spriteRendering.b3;
GravityUpdate(super, Q_8_8(40.0));
} else {
sub_08081404(this, 1);
}
}
void sub_080813BC(ItemOnGroundEntity* this) {
static void (*const subActionFuncs[])(ItemOnGroundEntity*) = {
sub_080813D4,
sub_080813E8,
sub_080813F0,
};
subActionFuncs[super->subAction](this);
}
void sub_080813D4(ItemOnGroundEntity* this) {
super->subAction = 1;
super->gustJarTolerance = 1;
super->spriteSettings.draw = 1;
}
void sub_080813E8(ItemOnGroundEntity* this) {
sub_0806F4E8(super);
}
void sub_080813F0(ItemOnGroundEntity* this) {
if (sub_0806F3E4(super)) {
sub_080810FC(this);
}
}
void sub_08081404(ItemOnGroundEntity* this, u32 arg1) {
if (arg1 && this->unk_86) {
SetFlag(this->unk_86);
}
DeleteThisEntity();
}
bool32 sub_08081420(ItemOnGroundEntity* this) {
if (CheckShouldPlayItemGetCutscene(this)) {
SetEntityPriority(super, PRIO_PLAYER_EVENT);
CreateItemEntity(super->type, super->type2, 0);
return TRUE;
} else {
GiveItem(super->type, super->type2);
return FALSE;
}
}
bool32 CheckShouldPlayItemGetCutscene(ItemOnGroundEntity* this) {
return ((gItemMetaData[super->type].unk3 & 0x2) || !GetInventoryValue(super->type));
}
static const Unk_0811E84C gUnk_0811E84C[118] = {
[ITEM_SHELLS] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_DUNGEON_MAP] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_COMPASS] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_BIG_KEY] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_SMALL_KEY] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_RUPEE1] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_RUPEE5] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_RUPEE20] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_RUPEE50] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_RUPEE100] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_RUPEE200] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_KINSTONE] = { { 0x0, 0x0 }, SFX_RUPEE_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_BOMBS5] = { { 0x0, 0x0 }, SFX_HEART_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_ARROWS5] = { { 0x0, 0x0 }, SFX_HEART_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
[ITEM_HEART] = { { 0x0, 0x0 }, SFX_HEART_BOUNCE, 0x1, { 0x0, 0x0, 0x0 } },
};
u8 sub_0808147C(u32 arg0) {
const Unk_0811E84C* var0 = &gUnk_0811E84C[arg0];
return var0->unk4;
}
void sub_0808148C(u32 arg0) {
const Unk_0811E84C* var0 = &gUnk_0811E84C[arg0];
if (var0->sfx) {
SoundReq(var0->sfx);
}
}
void sub_080814A4(ItemOnGroundEntity* this) {
if (this->unk_69 == 10) {
this->unk_6c = 120;
} else {
this->unk_6c = 600;
}
}
u32 sub_080814C0(ItemOnGroundEntity* this) {
if (!AnyPrioritySet()) {
if (--this->unk_6c == 0) {
return TRUE;
}
if (this->unk_6c < 90) {
super->spriteSettings.draw ^= 1;
}
}
return FALSE;
}
void sub_08081500(ItemOnGroundEntity* this) {
if (this->unk_68 == 0) {
u32 var0 = BounceUpdate(super, Q_8_8(40.0));
if (var0 == 0) {
this->unk_68 = 1;
} else {
if (var0 == 1) {
sub_0808148C(super->type);
UpdateSpriteForCollisionLayer(super);
}
ProcessMovement2(super);
}
}
}
void sub_0808153C(ItemOnGroundEntity* this) {
if (this->unk_68 > 1)
return;
if (this->unk_68 == 0) {
if (!GravityUpdate(super, Q_8_8(16.0)) && !sub_0800442E(super)) {
this->unk_68 = 1;
super->zVelocity = Q_16_16(1.875);
sub_0808148C(super->type);
UpdateSpriteForCollisionLayer(super);
}
} else {
if (!GravityUpdate(super, Q_8_8(40.0))) {
this->unk_68 = 2;
sub_0808148C(super->type);
}
}
}
void sub_08081598(ItemOnGroundEntity* this) {
if (super->health == 0) {
sub_08081404(this, 1);
}
COLLISION_OFF(super);
super->action = 4;
super->timer = 14;
super->zVelocity = Q_16_16(2.0);
super->spriteSettings.draw = 1;
super->spritePriority.b1 = 2;
super->spritePriority.b0 = 3;
super->child = &gPlayerEntity.base;
CopyPosition(super->child, super);
super->z.HALF.HI -= 4;
if (super->type != 0x5F && sub_08081420(this)) {
sub_08081404(this, 1);
}
}
|