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
|
/**
* @file fallingBoulder.c
* @ingroup Enemies
*
* @brief Falling Boulder enemy
*/
#include "enemy.h"
#include "room.h"
#include "player.h"
#include "physics.h"
typedef struct {
/*0x00*/ Entity base;
/*0x68*/ u8 unused1[18];
/*0x7a*/ u16 unk_7a;
/*0x7c*/ u16 unk_7c;
/*0x7e*/ u16 unk_7e;
/*0x80*/ u16 unk_80;
/*0x82*/ u16 unk_82;
/*0x84*/ u32 unk_84;
} FallingBoulderEntity;
void sub_0802C4B0(FallingBoulderEntity* this);
void sub_0802C62C(FallingBoulderEntity* this);
extern void (*const FallingBoulder_Functions[])(FallingBoulderEntity*);
extern void (*const gUnk_080CD558[])(FallingBoulderEntity*);
extern const u16 gUnk_080CD568[];
extern const u8 gUnk_080CD580[];
extern const s16 gUnk_080CD58C[];
void FallingBoulder(FallingBoulderEntity* this) {
EnemyFunctionHandler(super, (EntityActionArray)FallingBoulder_Functions);
}
void FallingBoulder_OnTick(FallingBoulderEntity* this) {
gUnk_080CD558[super->action](this);
}
void FallingBoulder_OnCollision(FallingBoulderEntity* this) {
/* ... */
}
void FallingBoulder_OnGrabbed(FallingBoulderEntity* this) {
/* ... */
}
void sub_0802C258(FallingBoulderEntity* this) {
sub_0804A720(super);
super->zVelocity = Q_16_16(2.0);
super->timer = 2;
this->unk_7a = Random() & 0x70;
switch (super->type) {
case 1:
this->unk_7a |= 0x100;
break;
case 2:
this->unk_7a |= 0x200;
break;
}
this->unk_80 = super->x.HALF.HI;
this->unk_82 = super->y.HALF.HI;
super->z.HALF.HI = -0x10;
super->collisionLayer = 3;
super->spriteRendering.b3 = 1;
super->spritePriority.b0 = 2;
this->unk_7c = 0;
this->unk_7e = COORD_TO_TILE(super);
sub_0802C62C(this);
sub_0802C4B0(this);
}
void sub_0802C318(FallingBoulderEntity* this) {
if (--this->unk_7a == 0) {
super->action = 2;
}
}
void sub_0802C334(FallingBoulderEntity* this) {
Entity* entity;
u32 roomOriginY, tmp;
s32 y, i;
if (this->unk_7c == 0) {
roomOriginY = gRoomControls.origin_y;
entity = &gPlayerEntity.base;
if (entity == NULL)
return;
tmp = entity->y.HALF.HI;
if (0x38 >= tmp - roomOriginY)
return;
this->unk_7c = 1;
super->spriteSettings.draw = 1;
}
GetNextFrame(super);
this->unk_7e = COORD_TO_TILE(super);
if (BounceUpdate(super, this->unk_84) == BOUNCE_INIT_NEXT) {
EnqueueSFX(0x14c);
COLLISION_ON(super);
this->unk_7a = 12;
sub_0802C4B0(this);
} else {
if (this->unk_7a) {
switch (--this->unk_7a) {
case 0:
COLLISION_OFF(super);
break;
case 8:
if (super->type2 != 0 && !sub_08049FA0(super)) {
for (i = 0; i < 2; i++) {
entity = CreateFx(super, FX_ROCK2, 0);
if (entity) {
entity->x.HALF.HI += 12 - i * 0x18;
}
}
sub_0802C62C(this);
this->unk_7a = (Random() & 0xff) | 0x100;
return;
}
break;
}
}
roomOriginY = gRoomControls.origin_y;
tmp = gRoomControls.height;
y = roomOriginY + tmp - super->y.HALF.HI;
if (y >= 5) {
ProcessMovement1(super);
} else {
LinearMoveUpdate(super);
if (super->z.HALF.HI - y > 0x38) {
sub_0802C62C(this);
this->unk_7a = (Random() & 0x7f) | 0x80;
if (super->type == 3) {
super->action = 3;
}
}
}
}
super->collisionLayer = 3;
super->spritePriority.b0 = 1;
UpdateSpriteForCollisionLayer(super);
}
void nullsub_148(FallingBoulderEntity* this) {
/* ... */
}
void sub_0802C4B0(FallingBoulderEntity* this) {
u32 offset;
u32 index;
u32 rand;
switch (GetTileIndex(this->unk_7e, super->collisionLayer)) {
case 0x1ab ... 0x1af:
offset = 8;
break;
case 0x1c4:
offset = 4;
break;
default:
offset = 0;
break;
}
rand = Random() & 7;
if (rand & 4) {
if (rand & 3) {
super->speed = gUnk_080CD568[offset | 2];
} else {
super->speed = gUnk_080CD568[offset | 0];
}
} else {
if (rand & 3) {
super->speed = gUnk_080CD568[offset | 1];
} else {
super->speed = gUnk_080CD568[offset | 3];
}
}
rand = Random() & 7;
if (rand & 4) {
if (super->timer != 0) {
super->timer = 0;
InitializeAnimation(super, 0);
}
if (rand & 3) {
super->direction = gUnk_080CD580[offset | 1];
} else {
super->direction = gUnk_080CD580[offset | 0];
}
} else {
if (super->timer != 1) {
super->timer = 1;
InitializeAnimation(super, 1);
}
if (rand & 3) {
super->direction = gUnk_080CD580[offset | 2];
} else {
super->direction = gUnk_080CD580[offset | 3];
}
}
rand = Random() & 7;
super->zVelocity = Q_16_16(2.0);
if (rand & 4) {
if (rand & 3) {
this->unk_84 = gUnk_080CD58C[offset | 1];
} else {
this->unk_84 = gUnk_080CD58C[offset | 3];
}
} else {
if (rand & 3) {
this->unk_84 = gUnk_080CD58C[offset | 2];
} else {
this->unk_84 = gUnk_080CD58C[offset | 0];
}
}
}
void sub_0802C62C(FallingBoulderEntity* this) {
super->action = 1;
super->y.HALF.HI = this->unk_82;
super->x.HALF.HI = this->unk_80;
super->spriteSettings.draw = 0;
COLLISION_OFF(super);
this->unk_7c = 0;
}
// clang-format off
void (*const FallingBoulder_Functions[])(FallingBoulderEntity*) = {
FallingBoulder_OnTick,
FallingBoulder_OnCollision,
(void (*)(FallingBoulderEntity*))GenericKnockback,
(void (*)(FallingBoulderEntity*))GenericDeath,
(void (*)(FallingBoulderEntity*))GenericConfused,
FallingBoulder_OnGrabbed,
};
void (*const gUnk_080CD558[])(FallingBoulderEntity*) = {
sub_0802C258,
sub_0802C318,
sub_0802C334,
nullsub_148,
};
const u16 gUnk_080CD568[] = {
0x80, 0x100, 0x180, 0x200,
0x80, 0x100, 0x180, 0x200,
0x100, 0x200, 0x300, 0x400,
};
const u8 gUnk_080CD580[] = {
10, 14, 18, 22,
10, 14, 18, 22,
10, 14, 18, 22,
};
const s16 gUnk_080CD58C[] = {
0x1800, 0x2000, 0x2800, 0x3000,
0x1800, 0x2000, 0x2800, 0x3000,
0x1800, 0x2000, 0x2800, 0x3000,
};
// clang-format on
|