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
|
/**
* @file playerItemBoomerang.c
* @ingroup Items
*
* @brief Boomerang Player Item
*/
#include "asm.h"
#include "entity.h"
#include "functions.h"
#include "item.h"
#include "sound.h"
typedef struct {
/*0x00*/ Entity base;
/*0x68*/ u8 unk_68;
/*0x69*/ u8 unused1[23];
/*0x80*/ u8 unk_80;
/*0x81*/ u8 unused2[1];
/*0x83*/ union SplitHWord unk_82;
/*0x84*/ u8 unused3[2];
/*0x86*/ u16 unk_86;
} PlayerItemBoomerangEntity;
void sub_0801B804(PlayerItemBoomerangEntity* this);
Entity* sub_0801B864(Entity* this);
void PlayerItemBoomerang_Action1(PlayerItemBoomerangEntity* this);
void PlayerItemBoomerang_Init(PlayerItemBoomerangEntity* this);
void PlayerItemBoomerang_Action2(PlayerItemBoomerangEntity* this);
void PlayerItemBoomerang_Action3(PlayerItemBoomerangEntity* this);
extern Entity* DoTileInteractionOffset(Entity*, u32, s32, s32);
extern bool32 sub_080040E2(Entity*, u8*);
extern Hitbox gUnk_081271CC;
extern u8 gUnk_08003E44;
void PlayerItemBoomerang(PlayerItemBoomerangEntity* this) {
static void (*const PlayerItemBoomerang_Actions[])(PlayerItemBoomerangEntity*) = {
PlayerItemBoomerang_Init,
PlayerItemBoomerang_Action1,
PlayerItemBoomerang_Action2,
PlayerItemBoomerang_Action3,
};
// Unused
static const u16 gUnk_080B780C[] = { 0x75, 0x1, 0x76, 0x1, 0x3ac, 0x1, 0x4050, 0x1, 0x377, 0x1, 0x378, 0x1, 0x0 };
PlayerItemBoomerang_Actions[super->action](this);
if (super->animIndex != 0xb) {
if (super->animationState == 6) {
this->unk_86 += 0x2000;
} else {
this->unk_86 -= 0x2000;
}
SetAffineInfo(super, 0x100, 0x100, this->unk_86);
}
super->subtimer--;
if ((super->subtimer & 0xf) == 0) {
EnqueueSFX(SFX_FB);
}
}
void PlayerItemBoomerang_Init(PlayerItemBoomerangEntity* this) {
gPlayerState.item = super;
super->action = 1;
super->hitbox = &gUnk_081271CC;
super->frameIndex = 0xff;
this->unk_80 = 0;
#ifdef EU
super->spriteVramOffset = gPlayerEntity.base.spriteVramOffset;
#endif
super->animIndex = 11;
super->parent = &gPlayerEntity.base;
this->unk_86 = 0;
if ((super->animationState & 2) != 0) {
super->spriteSettings.flipX = ~gPlayerEntity.base.spriteSettings.flipX;
}
if (this->unk_68 == 12) {
super->speed = 0x280;
super->timer = 60;
} else {
super->speed = 0x200;
super->timer = 30;
}
if (((s8)gPlayerState.direction) >= 0) {
super->direction = gPlayerState.direction;
} else {
super->direction = super->animationState << 2;
}
this->unk_82.HALF.HI = super->direction;
if (super->collisionLayer == 2) {
super->type2 = 1;
}
LoadSwapGFX(super, 1, 3);
sub_0801766C(super);
PlayerItemBoomerang_Action1(this);
}
void PlayerItemBoomerang_Action1(PlayerItemBoomerangEntity* this) {
static const s8 gUnk_080B7826[] = { 0, -8, 8, -4, 0, 8, -8, -4 };
u32 frameIndex;
int iVar2;
u32 cVar3;
sub_0801B804(this);
if ((gPlayerState.attack_status == 0) || (gPlayerState.mobility != 0) || gPlayerState.item != super ||
(gPlayerState.item == super && gPlayerEntity.base.action != PLAYER_NORMAL)) {
if (gPlayerState.item == super) {
gPlayerState.item = NULL;
}
DeleteThisEntity();
}
if ((gPlayerEntity.base.frame & 1) == 0) {
if (this->unk_68 == 12) {
cVar3 = 6;
} else {
cVar3 = 0;
}
frameIndex = (gPlayerEntity.base.frame >> 4) + cVar3;
if (super->frameIndex != frameIndex) {
super->frameIndex = frameIndex;
sub_080042D0(super, super->frameIndex, super->spriteIndex);
}
sub_08078E84(super, &gPlayerEntity.base);
} else {
super->action = 2;
super->spriteVramOffset = 0xd5;
COLLISION_ON(super);
super->collisionFlags |= 1;
super->flags2 = gPlayerEntity.base.flags2;
super->spriteIndex = 0xa6;
super->spriteSettings.flipX = 0;
super->spriteSettings.draw = 1;
iVar2 = (super->animationState >> 1) * 2;
super->x.HALF.HI += gUnk_080B7826[iVar2];
super->y.HALF.HI += gUnk_080B7826[iVar2 + 1];
InitializeAnimation(super, 0);
gPlayerState.item = NULL;
gPlayerState.attack_status |= 0x80;
}
}
void PlayerItemBoomerang_Action2(PlayerItemBoomerangEntity* this) {
u32 uVar1;
bool32 uVar6;
sub_0801B804(this);
if ((this->unk_68 == 12) && (this->unk_80 == 0) && !(gPlayerState.direction & DIR_NOT_MOVING_CHECK)) {
if (((this->unk_82.HALF.HI - gPlayerState.direction) &
(0x3 | DIR_DIAGONAL | DirectionNorth | DirectionEast | DirectionSouth | DirectionWest)) > DirectionSouth) {
this->unk_82.HWORD += 0x40;
this->unk_82.HALF.HI &= 0x1f;
super->direction = this->unk_82.HALF.HI;
} else {
this->unk_82.HWORD -= 0x40;
this->unk_82.HALF.HI &= 0x1f;
super->direction = this->unk_82.HALF.HI;
}
}
LinearMoveUpdate(super);
uVar6 = FALSE;
if (sub_0801B864(super)) {
uVar1 = this->unk_68;
uVar1 ^= 0xc;
if (uVar1) {
uVar6 = TRUE;
} else {
uVar6 = FALSE;
}
}
if (sub_080B1BA4(COORD_TO_TILE(super), gPlayerEntity.base.collisionLayer, 0x80) == 0) {
if (!uVar6) {
uVar6 = sub_080040E2(super, &gUnk_08003E44);
}
}
if (!uVar6) {
if (--super->timer < 0xc) {
super->speed = super->speed + -0x10;
}
if (super->timer == 0) {
uVar6 = TRUE;
}
if (super->contactFlags & CONTACT_TAKE_DAMAGE) {
uVar6 = TRUE;
}
if (!uVar6) {
return;
}
if (this->unk_68 == 12) {
super->timer = 30;
} else {
super->timer = 12;
}
} else {
super->timer = 1;
}
if (uVar6) {
super->action++;
super->speed = 0x1c0;
}
}
void PlayerItemBoomerang_Action3(PlayerItemBoomerangEntity* this) {
sub_0801B804(this);
if (super->timer != 0) {
super->timer--;
} else {
sub_0801B864(super);
if (super->speed < 0x280) {
super->speed += 8;
}
super->direction = GetFacingDirection(super, &gPlayerEntity.base);
LinearMoveUpdate(super);
if (sub_0800419C(super, &gPlayerEntity.base, 2, 2) != 0) {
DeleteThisEntity();
}
}
}
void sub_0801B804(PlayerItemBoomerangEntity* this) {
EquipSlot equipSlot;
u32 uVar1;
equipSlot = IsItemEquipped(ITEM_MAGIC_BOOMERANG);
switch (equipSlot) {
case EQUIP_SLOT_A:
uVar1 = 1;
break;
case EQUIP_SLOT_B:
uVar1 = 2;
break;
case EQUIP_SLOT_NONE:
uVar1 = 0;
break;
}
if ((uVar1 & gPlayerState.playerInput.heldInput) == 0) {
this->unk_80 = 1;
gPlayerState.field_0xa &= ~0x80;
gPlayerState.keepFacing &= ~0x80;
} else {
gPlayerState.field_0xa |= 0x80;
gPlayerState.keepFacing |= 0x80;
}
}
Entity* sub_0801B864(Entity* this) {
static const s8 gUnk_080B782E[] = { 0, -6, 4, -4, 4, 0, 4, 4, 0, 4, -4, 4, -4, 0, -4, 0, 0, 0 };
s32 iVar1;
if (this->type2 == 0) {
sub_0800451C(this);
}
iVar1 = (this->direction >> 2) * 2;
return DoTileInteractionOffset(this, 2, gUnk_080B782E[iVar1], gUnk_080B782E[iVar1 + 1]);
}
|