Skip to content

Commit 3bcf003

Browse files
committed
document unknown members of Peahat
1 parent 47a9c80 commit 3bcf003

File tree

3 files changed

+97
-71
lines changed

3 files changed

+97
-71
lines changed

assets/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3931,7 +3931,7 @@
39313931
"type": "animation"
39323932
},
39333933
{
3934-
"path": "peahat/gUnk_080CA5D4.bin",
3934+
"path": "peahat/gPeahatChargeDirectionOffsets.bin",
39353935
"start": 828884,
39363936
"size": 2
39373937
},

data/animations/enemy/peahat.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
.section .rodata
55
.align 2
66

7-
gUnk_080CA5D4:: @ 080CA5D4
8-
.incbin "peahat/gUnk_080CA5D4.bin"
7+
gPeahatChargeDirectionOffsets:: @ 080CA5D4
8+
.incbin "peahat/gPeahatChargeDirectionOffsets.bin"
99

1010
gSpriteAnimations_Peahat_0:: @ 080CA5D6
1111
.include "animations/gSpriteAnimations_Peahat_0.s"

src/enemy/peahat.c

Lines changed: 94 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,49 @@
1111
typedef struct {
1212
/*0x00*/ Entity base;
1313
/*0x68*/ u8 unused1[24];
14-
/*0x80*/ u8 unk_80;
15-
/*0x81*/ u8 unk_81;
16-
/*0x82*/ u8 unk_82;
17-
/*0x83*/ u8 unk_83;
14+
/**
15+
* While flying around the Peahat will gradually change direction using this value.
16+
* Changes between 2 and -2 at
17+
* random intervals.
18+
*/
19+
/*0x80*/ u8 directionDelta;
20+
/**
21+
* Controls if the Peahat will move up and down while flying.
22+
*/
23+
/*0x81*/ bool8 moveUpAnDown;
24+
/**
25+
* The Peahat is currently flying.
26+
*/
27+
/*0x82*/ bool8 flying;
28+
/**
29+
* The Peahat will continue flying around for this period before considering to charge again.
30+
*/
31+
/*0x83*/ u8 flyTimer;
1832
} PeahatEntity;
1933

34+
enum PeahatActions {
35+
PeahatActionInitialize,
36+
PeahatActionFly,
37+
PeahatActionChargeStart,
38+
PeahatActionChargeTarget,
39+
PeahatActionChargeEnd,
40+
PeahatActionStunned,
41+
PeahatActionRepairPropeller,
42+
PeahatActionRecover,
43+
PeahatActionHop,
44+
PeahatActionTakeoff,
45+
};
46+
2047
extern void (*const Peahat_Functions[])(PeahatEntity*);
2148
extern void (*const gPeahatPropellerFunctions[])(PeahatEntity*);
2249
extern void (*const gPeahatActions[])(PeahatEntity*);
23-
extern void (*const gUnk_080CA5BC[])(PeahatEntity*);
50+
extern void (*const gPeahatOnGrabbedSubactions[])(PeahatEntity*);
2451

2552
extern const s8 gPeahatFlightHeights[];
26-
extern const s8 gUnk_080CA5D4[];
53+
extern const s8 gPeahatChargeDirectionOffsets[];
2754

28-
void sub_080205F8(PeahatEntity* this);
29-
void sub_08020604(PeahatEntity* this);
55+
void Peahat_EndCharge(PeahatEntity* this);
56+
void Peahat_UpdateDirection(PeahatEntity* this);
3057

3158
enum {
3259
PeahatForm_Torso,
@@ -53,39 +80,39 @@ void Peahat(PeahatEntity* this) {
5380

5481
void Peahat_OnTick(PeahatEntity* this) {
5582
gPeahatActions[super->action](this);
56-
if (this->unk_81)
83+
if (this->moveUpAnDown)
5784
super->z.HALF.HI = gPeahatFlightHeights[(super->subtimer++ & 0x30) >> 4];
5885
}
5986

6087
void Peahat_OnCollision(PeahatEntity* this) {
61-
if (this->unk_82) {
88+
if (this->flying) {
6289
if (super->contactFlags == (CONTACT_NOW | 0x14)) {
6390
Entity* entity = CreateEnemy(PEAHAT, PeahatForm_Propeller);
6491
if (entity != NULL) {
6592
CopyPosition(super, entity);
6693
entity->z.HALF.HI -= 8;
6794
}
68-
this->unk_82 = 0;
95+
this->flying = FALSE;
6996
super->animationState = PeahatAnimation_SlicedPropeller;
70-
super->action = 5;
97+
super->action = PeahatActionStunned;
7198
super->speed = 0x80;
7299
super->iframes = -30;
73-
this->unk_81 = 0;
100+
this->moveUpAnDown = FALSE;
74101
InitializeAnimation(super, super->animationState);
75102
} else if (super->contactFlags == (CONTACT_NOW | 0x1b)) {
76103
super->animationState = PeahatAnimation_BrokenPropeller;
77-
super->action = 5;
104+
super->action = PeahatActionStunned;
78105
super->speed = 0x80;
79106
super->iframes = -30;
80-
this->unk_81 = 0;
107+
this->moveUpAnDown = FALSE;
81108
InitializeAnimation(super, super->animationState);
82109
} else if (super->contactFlags == CONTACT_NOW) {
83110
if (super->animationState == PeahatAnimation_Flying) {
84-
super->action = 1;
111+
super->action = PeahatActionFly;
85112
super->timer = 30;
86113
super->speed = 0x80;
87114
super->direction = -1;
88-
this->unk_83 = 0x78;
115+
this->flyTimer = 120;
89116
GetNextFrame(super);
90117
}
91118
}
@@ -101,37 +128,37 @@ void Peahat_OnGrabbed(PeahatEntity* this) {
101128
if (2 >= super->subAction && !sub_0806F520(super))
102129
return;
103130

104-
gUnk_080CA5BC[super->subAction](this);
131+
gPeahatOnGrabbedSubactions[super->subAction](this);
105132
}
106133

107-
void sub_080200B4(PeahatEntity* this) {
134+
void Peahat_OnGrabbed_Subaction0(PeahatEntity* this) {
108135
super->subAction = 1;
109136
super->gustJarTolerance = 60;
110137
if (super->animationState == PeahatAnimation_Flying) {
111138
super->animationState = PeahatAnimation_BrokenPropeller;
112-
super->action = 5;
139+
super->action = PeahatActionStunned;
113140
super->hitType = 0x71;
114-
this->unk_81 = 0;
141+
this->moveUpAnDown = FALSE;
115142
InitializeAnimation(super, super->animationState);
116143
}
117144
}
118145

119-
void sub_080200E4(PeahatEntity* this) {
146+
void Peahat_OnGrabbed_Subaction1(PeahatEntity* this) {
120147
sub_0806F4E8(super);
121148
}
122149

123-
void sub_080200EC(PeahatEntity* this) {
150+
void Peahat_OnGrabbed_Subaction2(PeahatEntity* this) {
124151
sub_0806F3E4(super);
125152
}
126153

127-
void sub_080200F4(PeahatEntity* this) {
154+
void Peahat_OnGrabbed_Subaction3(PeahatEntity* this) {
128155
COLLISION_OFF(super);
129156
}
130157

131-
void nullsub_5(PeahatEntity* this) {
158+
void Peahat_OnGrabbed_Subaction4(PeahatEntity* this) {
132159
}
133160

134-
void sub_08020104(PeahatEntity* this) {
161+
void Peahat_OnGrabbed_Subaction5(PeahatEntity* this) {
135162
if (super->flags & ENT_COLLIDE) {
136163
COLLISION_ON(super);
137164
super->gustJarState &= 0xfb;
@@ -142,25 +169,25 @@ void sub_08020104(PeahatEntity* this) {
142169

143170
void Peahat_Initialize(PeahatEntity* this) {
144171
sub_0804A720(super);
145-
super->action = 1;
172+
super->action = PeahatActionFly;
146173
super->timer = 16;
147174
super->subtimer = Random();
148175
super->direction = Random() & 0x1f;
149176
super->gustJarFlags = 18;
150-
this->unk_80 = (Random() & 1) ? 2 : -2;
151-
this->unk_81 = 1;
152-
this->unk_82 = 1;
177+
this->directionDelta = (Random() & 1) ? 2 : -2;
178+
this->moveUpAnDown = TRUE;
179+
this->flying = TRUE;
153180
super->animationState = PeahatAnimation_Flying;
154181
InitializeAnimation(super, super->animationState);
155182
}
156183

157184
void Peahat_Fly(PeahatEntity* this) {
158-
if (this->unk_83)
159-
this->unk_83--;
185+
if (this->flyTimer)
186+
this->flyTimer--;
160187

161188
if (sub_08049FDC(super, 1)) {
162-
if (this->unk_83 == 0 && (super->subtimer & 0xf) == 0 && sub_08049F1C(super, gEnemyTarget, 0x30)) {
163-
super->action = 2;
189+
if (this->flyTimer == 0 && (super->subtimer & 0xf) == 0 && sub_08049F1C(super, gEnemyTarget, 0x30)) {
190+
super->action = PeahatActionChargeStart;
164191
super->subAction = Random() & 3;
165192
super->timer = 60;
166193
super->speed = 160;
@@ -169,9 +196,9 @@ void Peahat_Fly(PeahatEntity* this) {
169196

170197
if (--super->timer == 0) {
171198
super->timer = 16;
172-
sub_08020604(this);
199+
Peahat_UpdateDirection(this);
173200
if ((Random() & 3) == 0) {
174-
this->unk_80 = (Random() & 1) ? 2 : -2;
201+
this->directionDelta = (Random() & 1) ? 2 : -2;
175202
}
176203
}
177204

@@ -184,15 +211,14 @@ void Peahat_ChargeStart(PeahatEntity* this) {
184211
if (--super->timer) {
185212
UpdateAnimationVariableFrames(super, 4 - ((super->timer >> 4) & 0x3));
186213
return;
187-
} else {
188-
super->action = 3;
189-
super->timer = 120;
190-
super->speed = 192;
191-
super->direction =
192-
(GetFacingDirection(super, gEnemyTarget) + gUnk_080CA5D4[Random() & 1]) & (0x3 | DirectionNorthWest);
193214
}
215+
super->action = PeahatActionChargeTarget;
216+
super->timer = 120;
217+
super->speed = 192;
218+
super->direction = (GetFacingDirection(super, gEnemyTarget) + gPeahatChargeDirectionOffsets[Random() & 1]) &
219+
(0x3 | DirectionNorthWest);
194220
} else {
195-
sub_080205F8(this);
221+
Peahat_EndCharge(this);
196222
}
197223

198224
UpdateAnimationVariableFrames(super, 4);
@@ -201,7 +227,7 @@ void Peahat_ChargeStart(PeahatEntity* this) {
201227
void Peahat_ChargeTarget(PeahatEntity* this) {
202228
if (sub_08049FDC(super, 1)) {
203229
if (--super->timer == 0) {
204-
sub_080205F8(this);
230+
Peahat_EndCharge(this);
205231
}
206232
if (super->timer > 60) {
207233
if (super->timer & 1)
@@ -212,17 +238,17 @@ void Peahat_ChargeTarget(PeahatEntity* this) {
212238
}
213239
ProcessMovement2(super);
214240
} else {
215-
sub_080205F8(this);
241+
Peahat_EndCharge(this);
216242
}
217243
UpdateAnimationVariableFrames(super, 4);
218244
}
219245

220246
void Peahat_ChargeEnd(PeahatEntity* this) {
221247
if (--super->timer == 0) {
222-
super->action = 1;
248+
super->action = PeahatActionFly;
223249
super->timer = 1;
224250
super->speed = 128;
225-
this->unk_83 = 120;
251+
this->flyTimer = 120;
226252
GetNextFrame(super);
227253
} else {
228254
if (super->timer & 1)
@@ -239,7 +265,7 @@ void Peahat_Stunned(PeahatEntity* this) {
239265
switch (super->animationState) {
240266
default:
241267
if (BounceUpdate(super, Q_8_8(24.0)) == BOUNCE_DONE_ALL) {
242-
super->action = 6;
268+
super->action = PeahatActionRepairPropeller;
243269
super->timer = 240;
244270
super->subtimer = 10;
245271
super->hitType = 0x71;
@@ -254,7 +280,7 @@ void Peahat_Stunned(PeahatEntity* this) {
254280
case PeahatAnimation_SlicedPropeller:
255281
GravityUpdate(super, Q_8_8(28.0));
256282
if (super->z.HALF.HI == 0) {
257-
super->action = 7;
283+
super->action = PeahatActionRecover;
258284
super->timer = 150;
259285
super->subtimer = 10;
260286
super->hitType = 0x71;
@@ -269,7 +295,7 @@ void Peahat_RepairPropeller(PeahatEntity* this) {
269295
}
270296

271297
if (sub_0800442E(super) || (--super->timer == 0)) {
272-
super->action = 9;
298+
super->action = PeahatActionTakeoff;
273299
super->zVelocity = Q_16_16(1.5);
274300
super->direction = Random() & 0x1f;
275301
EnemyDetachFX(super);
@@ -284,7 +310,7 @@ void Peahat_Recover(PeahatEntity* this) {
284310
}
285311

286312
if (sub_0800442E(super) || (--super->timer == 0)) {
287-
super->action = 8;
313+
super->action = PeahatActionHop;
288314
super->timer = 240;
289315
super->direction = Random() & 0x1f;
290316
EnemyDetachFX(super);
@@ -295,7 +321,7 @@ void Peahat_Hop(PeahatEntity* this) {
295321
GetNextFrame(super);
296322
if (--super->timer == 0) {
297323
if (super->frame & ANIM_DONE) {
298-
super->action = 9;
324+
super->action = PeahatActionTakeoff;
299325
super->zVelocity = Q_16_16(1.5);
300326
super->animationState = PeahatAnimation_NewPropeller;
301327
InitializeAnimation(super, super->animationState);
@@ -319,10 +345,10 @@ void Peahat_Hop(PeahatEntity* this) {
319345
void Peahat_Takeoff(PeahatEntity* this) {
320346
GetNextFrame(super);
321347
if (super->frame & ANIM_DONE) {
322-
super->action = 1;
348+
super->action = PeahatActionFly;
323349
super->hitType = 0x70;
324-
this->unk_82 = 1;
325-
this->unk_81 = 1;
350+
this->flying = TRUE;
351+
this->moveUpAnDown = TRUE;
326352
super->animationState = PeahatAnimation_Flying;
327353
InitializeAnimation(super, super->animationState);
328354
} else if (super->frame & 1) {
@@ -334,7 +360,7 @@ void Peahat_Takeoff(PeahatEntity* this) {
334360
}
335361

336362
void PeahatPropeller_Initialize(PeahatEntity* this) {
337-
super->action = 1;
363+
super->action = PeahatActionFly;
338364
super->timer = 240;
339365
super->subtimer = 40;
340366
super->spriteSettings.draw = 1;
@@ -363,16 +389,16 @@ void PeahatPropeller_Fly(PeahatEntity* this) {
363389
}
364390
}
365391

366-
void sub_080205F8(PeahatEntity* this) {
367-
super->action = 4;
392+
void Peahat_EndCharge(PeahatEntity* this) {
393+
super->action = PeahatActionChargeEnd;
368394
super->timer = 60;
369395
}
370396

371-
void sub_08020604(PeahatEntity* this) {
397+
void Peahat_UpdateDirection(PeahatEntity* this) {
372398
if (!sub_08049FA0(super) && (Random() & 3)) {
373399
super->direction = sub_08049EE4(super);
374400
} else {
375-
super->direction += this->unk_80;
401+
super->direction += this->directionDelta;
376402
super->direction &= (0x3 | DirectionNorthWest);
377403
}
378404
}
@@ -409,17 +435,17 @@ const s8 gPeahatFlightHeights[] = {
409435
-5, -6, -7, -6,
410436
};
411437

412-
void (*const gUnk_080CA5BC[])(PeahatEntity*) = {
413-
sub_080200B4,
414-
sub_080200E4,
415-
sub_080200EC,
416-
sub_080200F4,
417-
nullsub_5,
418-
sub_08020104,
438+
void (*const gPeahatOnGrabbedSubactions[])(PeahatEntity*) = {
439+
Peahat_OnGrabbed_Subaction0,
440+
Peahat_OnGrabbed_Subaction1,
441+
Peahat_OnGrabbed_Subaction2,
442+
Peahat_OnGrabbed_Subaction3,
443+
Peahat_OnGrabbed_Subaction4,
444+
Peahat_OnGrabbed_Subaction5,
419445
};
420446

421447
/* Alignment issue
422-
const s8 gUnk_080CA5D4[] = {
448+
const s8 gPeahatChargeDirectionOffsets[] = {
423449
4, -4,
424450
};
425451
*/

0 commit comments

Comments
 (0)