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
|
/**
* @file objectA8.c
* @ingroup Objects
*
* @brief ObjectA8 object
*/
#include "collision.h"
#include "functions.h"
#include "hitbox.h"
#include "item.h"
#include "object.h"
typedef struct {
/*0x00*/ Entity base;
/*0x68*/ u8 unk_68[0xc];
/*0x74*/ u16 unk_74;
/*0x76*/ u16 unk_76;
/*0x78*/ u8 unk_78[0xf];
/*0x87*/ u8 unk_87;
} ObjectA8Entity;
void sub_0809FECC(ObjectA8Entity*);
bool32 sub_0809FE9C(ObjectA8Entity*);
void ObjectA8_Init(ObjectA8Entity*);
void ObjectA8_Action1(ObjectA8Entity*);
void ObjectA8_Action2(ObjectA8Entity*);
void ObjectA8_Action3(ObjectA8Entity*);
void ObjectA8_Action4(ObjectA8Entity*);
void ObjectA8_Action5(ObjectA8Entity*);
void ObjectA8_Action6(ObjectA8Entity*);
void ObjectA8_Action2Subaction0(ObjectA8Entity*);
void ObjectA8_Action2Subaction1(ObjectA8Entity*);
void ObjectA8_Action2Subaction2(ObjectA8Entity*);
extern void sub_08081404(Entity*, u32);
void ObjectA8(ObjectA8Entity* this) {
static void (*const ObjectA8_Actions[])(ObjectA8Entity*) = {
ObjectA8_Init, ObjectA8_Action1, ObjectA8_Action2, ObjectA8_Action3,
ObjectA8_Action4, ObjectA8_Action5, ObjectA8_Action6,
};
if ((super->contactFlags & CONTACT_NOW) != 0) {
switch (super->contactFlags & 0x7f) {
case 0:
case 1:
case 4:
case 5:
case 6:
case 8:
case 9:
case 10:
case 0xb:
case 0xc:
case 0x1e:
case 0x1f:
super->action = 5;
super->child = &gPlayerEntity.base;
CreateItemEntity(super->type, 0, 0);
DeleteThisEntity();
}
}
ObjectA8_Actions[super->action](this);
sub_08080CB4(super);
}
void ObjectA8_Init(ObjectA8Entity* this) {
super->action = 1;
switch (super->type2) {
case 0:
super->zVelocity = Q_16_16(1.875);
super->z.HALF.HI += 8;
break;
case 2:
sub_0809FECC(this);
return;
}
super->collisionLayer = 3;
super->collisionFlags = 0x17;
super->hurtType = 0x48;
super->hitType = 7;
super->collisionMask = 0x17;
super->hitbox = (Hitbox*)&gUnk_080FD1A8;
super->gustJarFlags = 1;
this->unk_74 = super->x.HALF.HI;
this->unk_76 = super->y.HALF.HI;
SetEntityPriority(super, 3);
EnqueueSFX(SFX_136);
}
void ObjectA8_Action1(ObjectA8Entity* this) {
super->z.WORD -= Q_16_16(0.875);
if (super->frame != 0) {
if (super->timer != 0) {
super->timer *= 0x1e;
} else {
super->timer = 240;
}
super->action = 3;
super->subtimer = 1;
super->speed = 0x80;
}
}
void ObjectA8_Action2(ObjectA8Entity* this) {
static void (*const ObjectA8_Action2Subactions[])(ObjectA8Entity*) = {
ObjectA8_Action2Subaction0,
ObjectA8_Action2Subaction1,
ObjectA8_Action2Subaction2,
};
ObjectA8_Action2Subactions[super->subAction](this);
}
void ObjectA8_Action2Subaction0(ObjectA8Entity* this) {
super->subAction = 1;
super->gustJarTolerance = 1;
super->spriteSettings.draw = 1;
}
void ObjectA8_Action2Subaction1(ObjectA8Entity* this) {
if ((gPlayerState.gustJarState & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) {
super->action = 3;
} else {
sub_0806F4E8(super);
}
}
void ObjectA8_Action2Subaction2(ObjectA8Entity* this) {
if ((gPlayerState.gustJarState & 0xf) != 1 || (super->contactFlags & 0x7f) != 0x13) {
super->action = 3;
} else {
if (sub_0806F3E4(super)) {
super->flags &= ~ENT_COLLIDE;
super->action = 5;
super->child = &gPlayerEntity.base;
GiveItem(super->type, 0);
}
}
}
void ObjectA8_Action3(ObjectA8Entity* this) {
static const u8 gUnk_0812484C[] = {
128,
96,
0,
0,
};
if (--super->subtimer == 0) {
u32 rand = Random();
super->flags |= ENT_COLLIDE;
super->subtimer = 32;
super->speed = gUnk_0812484C[rand >> 8 & 1];
if (sub_0809FE9C(this)) {
super->direction = rand & 0x1f;
} else {
super->direction = CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, this->unk_74, this->unk_76);
}
if ((super->direction & 0xf) != 0) {
super->spriteSettings.flipX = ((super->direction ^ 0x10) >> 4);
}
}
ProcessMovement1(super);
if ((AnyPrioritySet() == 0) && (super->type == 0)) {
if (((gRoomTransition.frameCount & 1) != 0) && (--super->timer == 0)) {
sub_08081404(super, 0);
}
if (super->timer < 0x3c) {
super->spriteSettings.draw ^= 1;
}
}
}
void ObjectA8_Action4(ObjectA8Entity* this) {
if (*(u16*)&super->child->kind != 0xb08) {
sub_08081404(super, 0);
} else {
CopyPosition(super->child, super);
super->z.HALF.HI--;
if (IsColliding(super, &gPlayerEntity.base)) {
sub_0809FECC(this);
GiveItem(super->type, 0);
}
}
}
void ObjectA8_Action5(ObjectA8Entity* this) {
super->action = 6;
super->timer = 128;
super->subtimer = 6;
super->flags &= ~ENT_COLLIDE;
super->spriteSettings.draw = 1;
super->spritePriority.b1 = 2;
super->spriteOffsetY = -5;
CopyPosition(super->child, super);
}
void ObjectA8_Action6(ObjectA8Entity* this) {
s32 tmp;
Entity* child = super->child;
tmp = gSineTable[super->timer] * 0xa00;
if (tmp < 0) {
tmp += 0xffff;
}
super->x.HALF.HI = (s16)(tmp >> 0x10) + child->x.HALF.HI;
tmp = gSineTable[super->timer + 0x40] * 0x500;
if (tmp < 0) {
tmp += 0xffff;
}
super->y.HALF.HI = super->child->y.HALF.HI - (tmp >> 0x10);
super->timer += 8;
super->z.HALF.HI = super->child->z.HALF.HI;
super->spriteOrientation.flipY = super->child->spriteOrientation.flipY;
super->spriteRendering.b3 = super->child->spriteRendering.b3;
if ((u8)(super->timer - 0x41) < 0x7f) {
super->spritePriority.b0 = 3;
} else {
super->spritePriority.b0 = 5;
}
if (--super->subtimer == 0) {
super->subtimer = 6;
if (--super->spriteOffsetY < -0x16) {
sub_08081404(super, 1);
}
}
if (super->spriteOffsetY < -0x11) {
super->spriteSettings.draw ^= 1;
}
if (this->unk_87 > 10) {
this->unk_87 = 0xa;
}
}
bool32 sub_0809FE9C(ObjectA8Entity* this) {
if (((super->x.HALF.HI - (u32)this->unk_74) + 0x48 < 0x91) &&
((super->y.HALF.HI - (u32)this->unk_76) + 0x30 < 0x61)) {
return TRUE;
} else {
return FALSE;
}
}
void sub_0809FECC(ObjectA8Entity* this) {
super->child = &gPlayerEntity.base;
super->action = 5;
super->subAction = 0;
}
|