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
|
/**
* @file gibdo.c
* @ingroup Enemies
*
* @brief Gibdo enemy
*/
#include "enemy.h"
#include "functions.h"
#include "object.h"
typedef struct {
Entity base;
u8 filler[0xc];
u16 field_0x74;
u8 field_0x76;
u8 field_0x77;
u16 field_0x78;
u16 field_0x7a;
u8 field_0x7c;
u8 filler2[3];
Entity* field_0x80;
Entity* field_0x84;
} GibdoEntity;
// Gibudo
void sub_08037794(GibdoEntity*);
void sub_08037B10(GibdoEntity*);
void sub_0803797C(GibdoEntity*);
void sub_080379BC(GibdoEntity*);
void Gibdo_MoveObjectsToStalfos(GibdoEntity*, Entity*);
bool32 sub_08037810(GibdoEntity*);
void sub_080377B0(GibdoEntity*);
bool32 sub_080378B0(GibdoEntity*);
bool32 sub_08037914(GibdoEntity*);
bool32 sub_080379EC(GibdoEntity*);
void sub_08037A58(GibdoEntity*);
void sub_08037ACC(GibdoEntity*);
void Gibdo_CreateObjects(GibdoEntity*);
void sub_08037A14(GibdoEntity*);
void (*const Gibdo_Functions[6])(Entity*);
void (*const gUnk_080CF2AC[9])(GibdoEntity*);
extern Entity* gUnk_020000B0;
void Gibdo(Entity* this) {
EnemyFunctionHandler(this, Gibdo_Functions);
EnemySetFXOffset(this, 0, 1, -0x15);
}
void Gibdo_OnTick(GibdoEntity* this) {
gUnk_080CF2AC[super->action](this);
}
void Gibdo_OnCollision(GibdoEntity* this) {
if (super->contactFlags == 0x87) {
if (super->action == 0x6) {
sub_08037ACC(this);
}
super->action = 0x8;
super->timer = 60;
COLLISION_OFF(super);
Gibdo_CreateObjects(this);
} else {
if (super->action != 0x6) {
if (super->hitType == 0x27 && super->contactFlags == 0x80) {
sub_08037A14(this);
} else {
if ((u8)(super->action - 1) < 2) {
u8 dir;
super->action = 1;
dir = DirectionRoundUp(DirectionTurnAround(super->knockbackDirection));
super->direction = dir;
super->animationState = dir >> 3;
InitAnimationForceUpdate(super, super->animationState);
if (sub_08037810(this)) {
super->timer = 4;
}
}
}
} else {
sub_08037A58(this);
}
}
if (super->confusedTime != 0) {
EnemyCreateFX(super, FX_STARS);
}
EnemyFunctionHandlerAfterCollision(super, Gibdo_Functions);
}
void Gibdo_OnGrabbed(GibdoEntity* this) {
}
void sub_08037558(GibdoEntity* this) {
sub_0804A720(super);
super->animationState = Random() & 0x3;
this->field_0x76 = 0;
this->field_0x77 = 0;
sub_08037794(this);
}
void sub_08037580(GibdoEntity* this) {
if (!sub_08037810(this)) {
if (--this->field_0x74 == 0) {
sub_080377B0(this);
}
}
}
void sub_080375A4(GibdoEntity* this) {
if (!sub_080378B0(this) && !sub_08037810(this)) {
if (--this->field_0x74 == 0) {
sub_08037794(this);
} else {
UpdateAnimationSingleFrame(super);
if (!ProcessMovement0(super)) {
if (--super->subtimer == 0) {
sub_080379BC(this);
}
}
}
}
}
void sub_080375F8(GibdoEntity* this) {
if (!sub_080378B0(this) && (--super->timer == 0)) {
super->action = 4;
super->timer = 24;
InitAnimationForceUpdate(super, super->animationState + 4);
}
}
void sub_08037624(GibdoEntity* this) {
if (!sub_080378B0(this) && !sub_08037914(this)) {
if (--this->field_0x74 == 0) {
sub_08037794(this);
} else {
UpdateAnimationSingleFrame(super);
UpdateAnimationSingleFrame(super);
if (!ProcessMovement0(super)) {
if (--super->subtimer == 0) {
sub_080379BC(this);
}
} else if (--super->timer == 0) {
sub_0803797C(this);
}
}
}
}
void sub_08037690(GibdoEntity* this) {
UpdateAnimationSingleFrame(super);
if ((super->frame & ANIM_DONE) != 0) {
this->field_0x77 = 20;
sub_08037794(this);
} else {
if ((super->frame & 1) != 0) {
super->hitType = 0x27;
ProcessMovement0(super);
}
}
}
void sub_080376D0(GibdoEntity* this) {
if (!sub_080379EC(this)) {
ResetActiveItems();
gPlayerState.mobility |= 0x80;
gPlayerState.field_0xa |= 0x80;
CopyPositionAndSpriteOffset(&gPlayerEntity.base, super);
UpdateAnimationSingleFrame(super);
if ((super->frame & 1) != 0) {
if (--this->field_0x7c == 0) {
sub_08037A58(this);
} else {
super->frame ^= 1;
sub_08037B10(this);
}
}
}
}
void sub_0803773C(GibdoEntity* this) {
UpdateAnimationSingleFrame(super);
if ((super->frame & ANIM_DONE) != 0) {
sub_08037794(this);
}
}
// Turn into Stalfos
void sub_0803775C(GibdoEntity* this) {
Entity* stalfos;
if (--super->timer == 0) {
stalfos = CreateEnemy(STALFOS, 0);
if (stalfos != NULL) {
EnemyCopyParams(super, stalfos);
Gibdo_MoveObjectsToStalfos(this, stalfos);
}
DeleteEntity(super);
}
}
void sub_08037794(GibdoEntity* this) {
super->action = 1;
this->field_0x74 = 30;
super->hitType = 0x26;
InitAnimationForceUpdate(super, super->animationState);
}
void sub_080377B0(GibdoEntity* this) {
u32 rand1;
u32 rand2;
super->action = 2;
super->subtimer = 8;
rand1 = Random();
this->field_0x74 = (rand1 & 0x38) + 120;
super->speed = 0x40;
rand2 = Random();
if (!sub_08049FA0(super) && ((rand2 & 3) != 0)) {
super->direction = DirectionRoundUp(sub_08049EE4(super));
} else {
super->direction = DirectionRound(rand2);
}
super->animationState = super->direction / 8;
InitAnimationForceUpdate(super, super->animationState + 4);
}
bool32 sub_08037810(GibdoEntity* this) {
u32 dir;
if (this->field_0x76 == 0) {
if (sub_08049FDC(super, 1) &&
EntityWithinDistance(super, gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI, 0x40)) {
dir = GetFacingDirection(super, gUnk_020000B0);
if (((dir - super->direction + 6) & 0x1f) <= 0xc) {
super->action = 3;
super->timer = 24;
super->subtimer = 8;
super->speed = 0xc0;
super->direction = DirectionRoundUp(GetFacingDirection(super, gUnk_020000B0));
super->animationState = super->direction >> 3;
this->field_0x74 = 300;
this->field_0x78 = gUnk_020000B0->x.HALF.HI;
this->field_0x7a = gUnk_020000B0->y.HALF.HI;
InitAnimationForceUpdate(super, super->animationState);
return TRUE;
}
}
} else {
this->field_0x76--;
}
return FALSE;
}
bool32 sub_080378B0(GibdoEntity* this) {
if (this->field_0x77 == 0) {
if (sub_08049DF4(1) != NULL) {
if (sub_0804A044(super, gUnk_020000B0, 0xa) == super->direction)
if (EntityWithinDistance(super, gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI, 0x18)) {
super->action = 5;
super->speed = 0x100;
InitAnimationForceUpdate(super, super->animationState + 8);
return TRUE;
}
}
} else {
this->field_0x77--;
}
return FALSE;
}
bool32 sub_08037914(GibdoEntity* this) {
if (sub_08049FDC(super, 1)) {
if (!EntityWithinDistance(gUnk_020000B0, this->field_0x78, this->field_0x7a, 0x28)) {
this->field_0x78 = gUnk_020000B0->x.HALF_U.HI;
this->field_0x7a = gUnk_020000B0->y.HALF_U.HI;
sub_0803797C(this);
return FALSE;
}
if (!EntityWithinDistance(super, this->field_0x78, this->field_0x7a, 0x8)) {
return FALSE;
}
this->field_0x76 = 60;
}
sub_08037794(this);
return TRUE;
}
void sub_0803797C(GibdoEntity* this) {
u32 m;
super->timer = 24;
super->subtimer = 8;
m = super->direction =
(CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, this->field_0x78, this->field_0x7a) + 4) & 0x18;
m >>= 3;
if (m != super->animationState) {
super->animationState = m;
InitAnimationForceUpdate(super, m + 4);
}
}
void sub_080379BC(GibdoEntity* this) {
u32 rand;
super->timer = 24;
super->subtimer = 8;
rand = Random();
super->animationState = ((super->animationState + (rand & 2)) - 1) & 3;
super->direction = DirectionFromAnimationState(super->animationState);
InitAnimationForceUpdate(super, super->animationState + 4);
}
bool32 sub_080379EC(GibdoEntity* this) {
if (sub_0807953C() != 0) {
if (--super->timer == 0) {
sub_08037A58(this);
return TRUE;
}
}
return FALSE;
}
void sub_08037A14(GibdoEntity* this) {
super->action = 6;
super->timer = 24;
super->spritePriority.b0 &= super->timer - 32;
super->spritePriority.b0 |= 3;
super->flags2 &= 0xfe;
this->field_0x7c = 5;
CopyPosition(super, super->contactedEntity);
InitAnimationForceUpdate(super, super->animationState + 0xc);
}
// Take Damage maybe?
void sub_08037A58(GibdoEntity* this) {
sub_08037ACC(this);
super->action = 7;
super->spritePriority.b0 = 4;
if (super->iframes == 0) {
super->iframes = 0xec;
}
super->hitType = 0x26;
super->flags2 |= 1;
super->iframes = 0xf4;
super->knockbackDirection = DirectionFromAnimationState(super->animationState) ^ 0x10;
super->knockbackDuration = 8;
super->knockbackSpeed = 0x180;
this->field_0x76 = 60;
InitAnimationForceUpdate(super, super->animationState + 0x10);
}
void sub_08037ACC(GibdoEntity* this) {
gPlayerState.flags &= ~PL_DISABLE_ITEMS;
COLLISION_ON(&gPlayerEntity.base);
gPlayerEntity.base.iframes = 30;
gPlayerEntity.base.knockbackDirection = DirectionFromAnimationState(super->animationState);
gPlayerEntity.base.knockbackDuration = 4;
gPlayerEntity.base.knockbackSpeed = 0x180;
}
// Damage player maybe?
void sub_08037B10(GibdoEntity* this) {
u32 health;
gPlayerEntity.base.iframes = 0xc;
health = ModHealth(-8);
SoundReqClipped(&gPlayerEntity.base, SFX_PLY_VO6);
if (health == 0) {
sub_08037A58(this);
this->field_0x76 = 240;
}
}
void Gibdo_CreateObjects(GibdoEntity* this) {
Entity* object;
object = CreateObject(FLAME, 3, 0);
if (object != NULL) {
object->type2 = super->timer;
object->spritePriority.b0 = 3;
object->spriteOffsetX = 0;
object->spriteOffsetY = 0xfc;
object->parent = super;
}
this->field_0x80 = object;
object = CreateObject(FLAME, 3, 0);
if (object != NULL) {
object->type2 = super->timer;
object->spritePriority.b0 = 3;
object->spriteOffsetX = 0xfd;
object->spriteOffsetY = 0xf8;
object->parent = super;
}
this->field_0x84 = object;
object = CreateObject(FLAME, 3, 0);
if (object != NULL) {
object->type2 = super->timer;
object->spritePriority.b0 = 3;
object->spriteOffsetX = 0x5;
object->spriteOffsetY = 0xf5;
object->parent = super;
}
super->child = object;
}
void Gibdo_MoveObjectsToStalfos(GibdoEntity* this, Entity* that) {
Entity* entity = this->field_0x80;
if (entity != NULL) {
entity->timer = 15;
entity->parent = that;
}
entity = this->field_0x84;
if (entity != NULL) {
entity->timer = 15;
entity->parent = that;
}
entity = super->child;
if (entity != NULL) {
entity->timer = 15;
entity->parent = that;
}
}
void (*const Gibdo_Functions[6])(Entity*) = {
(EntityActionPtr)Gibdo_OnTick,
(EntityActionPtr)Gibdo_OnCollision,
GenericKnockback,
GenericDeath,
GenericConfused,
(EntityActionPtr)Gibdo_OnGrabbed,
};
void (*const gUnk_080CF2AC[9])(GibdoEntity*) = {
sub_08037558, sub_08037580, sub_080375A4, sub_080375F8, sub_08037624,
sub_08037690, sub_080376D0, sub_0803773C, sub_0803775C,
};
|