From ca873e6b7fb9e62bc26f6637caab9023aa2f6e59 Mon Sep 17 00:00:00 2001 From: Henny022p Date: Sun, 12 Jan 2025 01:46:48 +0000 Subject: [PATCH 1/2] rename gUnk_020000B0 to gEnemyTarget and move it to a header --- asm/src/code_08001A7C.s | 4 ++-- include/enemy.h | 6 ++++++ linker.ld | 2 +- src/code_08049DF4.c | 13 ++++++------- src/enemy/acroBandits.c | 6 ++---- src/enemy/armos.c | 8 +++----- src/enemy/ballChainSoldier.c | 12 +++++------- src/enemy/chuchu.c | 6 ++---- src/enemy/crow.c | 5 ++--- src/enemy/darkNut.c | 34 ++++++++++++++++------------------ src/enemy/enemy4D.c | 8 +++----- src/enemy/enemy50.c | 6 ++---- src/enemy/eyegore.c | 7 +++---- src/enemy/ghini.c | 8 +++----- src/enemy/gibdo.c | 21 ++++++++++----------- src/enemy/keaton.c | 6 ++---- src/enemy/leever.c | 18 ++++++++---------- src/enemy/mulldozer.c | 4 +--- src/enemy/octorok.c | 7 +++---- src/enemy/peahat.c | 8 +++----- src/enemy/pesto.c | 18 ++++++++---------- src/enemy/rope.c | 4 +--- src/enemy/sluggula.c | 4 +--- src/enemy/spikedBeetle.c | 4 +--- src/enemy/spinyChuchu.c | 4 +--- src/enemy/stalfos.c | 12 +++++------- src/enemy/takkuri.c | 6 ++---- src/enemy/torchTrap.c | 6 ++---- src/enemy/vaatiProjectile.c | 6 ++---- src/enemy/wallMaster2.c | 4 +--- 30 files changed, 107 insertions(+), 150 deletions(-) diff --git a/asm/src/code_08001A7C.s b/asm/src/code_08001A7C.s index 4568bf6cc..9be7ef322 100644 --- a/asm/src/code_08001A7C.s +++ b/asm/src/code_08001A7C.s @@ -862,12 +862,12 @@ _080026A0: .4byte gUnk_08002342 gUnk_080026A4:: @ normal entities - .4byte gUnk_020000B0 @ enemy target? (player) + .4byte gEnemyTarget @ enemy target? (player) .4byte gEntityLists - 8 @ first linked list .4byte gEntityLists + 64 @ last linked list .4byte ram_sub_080B2248 @ entity table @ managers - .4byte gUnk_020000B0 + .4byte gEnemyTarget .4byte gEntityLists + 56 .4byte gCollidableCount .4byte ram_sub_080B2248 diff --git a/include/enemy.h b/include/enemy.h index c799f0589..84c2d1e0a 100644 --- a/include/enemy.h +++ b/include/enemy.h @@ -288,4 +288,10 @@ void Enemy66(); extern void (*const gUnk_080012C8[])(Entity*); +/** + * The Entity targeted by enemies. + * This is usually the player. + */ +extern Entity* gEnemyTarget; + #endif // ENEMY_H diff --git a/linker.ld b/linker.ld index 4ed6e5b11..d06a86b0c 100644 --- a/linker.ld +++ b/linker.ld @@ -21,7 +21,7 @@ SECTIONS { . = 0x00000080; gIntroState = .; . = 0x00000080; gChooseFileState = .; . = 0x00000090; gUnk_02000090 = .; - . = 0x000000B0; gUnk_020000B0 = .; + . = 0x000000B0; gEnemyTarget = .; . = 0x000000C0; gUnk_020000C0 = .; . = 0x00000CC0; gBgAnimations = .; . = 0x00000D00; gTextGfxBuffer = .; diff --git a/src/code_08049DF4.c b/src/code_08049DF4.c index b2004f1ac..2852df19d 100644 --- a/src/code_08049DF4.c +++ b/src/code_08049DF4.c @@ -7,12 +7,11 @@ #include "room.h" #include "enemy.h" -extern Entity* gUnk_020000B0; extern Entity* (*const gUnk_080D3BE8[])(void); Entity* sub_08049DF4(u32 arg0) { - if (gUnk_020000B0 != NULL) { - return gUnk_020000B0; + if (gEnemyTarget != NULL) { + return gEnemyTarget; } return gUnk_080D3BE8[arg0](); } @@ -22,7 +21,7 @@ Entity* sub_08049E18(void) { !(gPlayerState.flags & (PL_BUSY | PL_DROWNING | PL_CAPTURED | PL_USE_PORTAL | PL_HIDDEN | PL_DISABLE_ITEMS | PL_FALLING | PL_FROZEN | PL_IN_MINECART | PL_PIT_IS_EXIT | PL_MOLDWORM_CAPTURED | PL_IN_HOLE | PL_CONVEYOR_PUSHED | PL_CLIMBING))) { - gUnk_020000B0 = &gPlayerEntity.base; + gEnemyTarget = &gPlayerEntity.base; return &gPlayerEntity.base; } return NULL; @@ -33,7 +32,7 @@ Entity* sub_08049E4C(void) { !(gPlayerState.flags & (PL_BUSY | PL_DROWNING | PL_CAPTURED | PL_USE_PORTAL | PL_HIDDEN | PL_MINISH | PL_DISABLE_ITEMS | PL_FALLING | PL_FROZEN | PL_IN_MINECART | PL_PIT_IS_EXIT | PL_MOLDWORM_CAPTURED | PL_IN_HOLE | PL_CONVEYOR_PUSHED | PL_CLIMBING))) { - gUnk_020000B0 = &gPlayerEntity.base; + gEnemyTarget = &gPlayerEntity.base; return &gPlayerEntity.base; } return NULL; @@ -43,14 +42,14 @@ Entity* sub_08049E80(void) { if ((gPlayerState.killed != 0) || !(gPlayerState.flags & PL_MINISH)) { return NULL; } - gUnk_020000B0 = &gPlayerEntity.base; + gEnemyTarget = &gPlayerEntity.base; return &gPlayerEntity.base; } Entity* sub_08049EB0(void) { if ((gPlayerState.killed == 0) && !(gPlayerState.flags & (PL_MOLDWORM_CAPTURED | PL_DISABLE_ITEMS | PL_MINISH | PL_CAPTURED))) { - gUnk_020000B0 = &gPlayerEntity.base; + gEnemyTarget = &gPlayerEntity.base; return &gPlayerEntity.base; } return NULL; diff --git a/src/enemy/acroBandits.c b/src/enemy/acroBandits.c index 4e6854b97..705180511 100644 --- a/src/enemy/acroBandits.c +++ b/src/enemy/acroBandits.c @@ -25,8 +25,6 @@ typedef struct { /*0x7c*/ Entity* unk_7c; } AcroBanditEntity; -extern Entity* gUnk_020000B0; - static void sub_08031E48(AcroBanditEntity* this, AcroBanditEntity* child); static void sub_08032290(AcroBanditEntity* this); static bool32 sub_080322A4(AcroBanditEntity* this); @@ -224,7 +222,7 @@ void AcroBandit_Type0Action2(AcroBanditEntity* this) { void AcroBandit_Type0Action3(AcroBanditEntity* this) { if (sub_08031E04(this)) { super->action = 5; - if (super->x.HALF.HI > gUnk_020000B0->x.HALF.HI) { + if (super->x.HALF.HI > gEnemyTarget->x.HALF.HI) { super->spriteSettings.flipX = 0; } else { super->spriteSettings.flipX = 1; @@ -447,7 +445,7 @@ void AcroBandit_Type1Action4(AcroBanditEntity* this) { if (parent == NULL) { if (sub_08049FDC(super, 1)) { if ((++this->unk_79 & 7) == 0) { - sub_08004596(super, GetFacingDirection(super, gUnk_020000B0)); + sub_08004596(super, GetFacingDirection(super, gEnemyTarget)); } this->unk_76.HALF.LO = 0; } else { diff --git a/src/enemy/armos.c b/src/enemy/armos.c index 94236dee0..51daa2a8f 100644 --- a/src/enemy/armos.c +++ b/src/enemy/armos.c @@ -26,8 +26,6 @@ typedef struct { /*0x84*/ u32 unk_84; } ArmosEntity; -extern Entity* gUnk_020000B0; - extern void (*const gUnk_080CE124[])(ArmosEntity*); extern void (*const gUnk_080CE13C[])(ArmosEntity*); extern const u8 gUnk_080CE160[]; @@ -343,7 +341,7 @@ bool32 sub_08030650(ArmosEntity* this) { return 1; } } else if (this->unk_80 != 2) { - if (!sub_08049FDC(super, 1) || (0x20 < (gUnk_020000B0->x.HALF.HI - super->x.HALF.HI) + 0x10U)) { + if (!sub_08049FDC(super, 1) || (0x20 < (gEnemyTarget->x.HALF.HI - super->x.HALF.HI) + 0x10U)) { return FALSE; } return TRUE; @@ -351,7 +349,7 @@ bool32 sub_08030650(ArmosEntity* this) { if (!sub_08049FDC(super, 1)) { return FALSE; } - if (gUnk_020000B0->x.HALF.HI >= (s32)(gRoomControls.origin_x + 0xa8)) { + if (gEnemyTarget->x.HALF.HI >= (s32)(gRoomControls.origin_x + 0xa8)) { return FALSE; } return TRUE; @@ -367,7 +365,7 @@ void sub_080306C4(ArmosEntity* this) { if (sub_08049FDC(super, 1) && this->unk_7a != 0) { super->timer = 24; - uVar3 = sub_0800132C(super, gUnk_020000B0); + uVar3 = sub_0800132C(super, gEnemyTarget); if (uVar3 != 0xff) { var = 0; if ((((Random() & 7) != 0) || (super->animationState == 0xff)) && ((this->unk_82 & 3) != 3)) { diff --git a/src/enemy/ballChainSoldier.c b/src/enemy/ballChainSoldier.c index bc6ff6d29..f6010778a 100644 --- a/src/enemy/ballChainSoldier.c +++ b/src/enemy/ballChainSoldier.c @@ -20,8 +20,6 @@ typedef struct { u8 unk_7f; } BallChainSoldierEntity; -extern Entity* gUnk_020000B0; - void (*const BallChainSoldier_Functions[])(BallChainSoldierEntity*); void (*const gUnk_080D06F8[])(BallChainSoldierEntity*); const u8 gUnk_080D0724[]; @@ -210,7 +208,7 @@ void sub_0803E818(BallChainSoldierEntity* this) { void sub_0803E86C(BallChainSoldierEntity* this) { if (sub_08049FDC(super, 1) && sub_0803EAD0(this, 0x50)) { - super->direction = DirectionRoundUp(GetFacingDirection(super, gUnk_020000B0)); + super->direction = DirectionRoundUp(GetFacingDirection(super, gEnemyTarget)); } super->action = 1; @@ -276,12 +274,12 @@ bool32 sub_0803E9D4(BallChainSoldierEntity* this) { if (sub_08049FDC(super, 1)) { if (sub_0803EAD0(this, 0x38)) { super->action = 3; - super->direction = DirectionRoundUp(GetFacingDirection(super, gUnk_020000B0)); + super->direction = DirectionRoundUp(GetFacingDirection(super, gEnemyTarget)); this->unk_7b = 1; sub_0803E94C(this, 0); return 1; } else if (sub_0803EAD0(this, 0x4e)) { - dir = sub_0804A044(super, gUnk_020000B0, 0x12); + dir = sub_0804A044(super, gEnemyTarget, 0x12); if (dir != 0xff) { if (--this->unk_7a != 0) return 0; @@ -302,7 +300,7 @@ bool32 sub_0803EA64(BallChainSoldierEntity* this) { u32 dir; if (sub_08049FDC(super, 1)) { if (sub_0803EAD0(this, 0x4e)) { - dir = sub_0804A044(super, gUnk_020000B0, 0x12); + dir = sub_0804A044(super, gEnemyTarget, 0x12); if (dir != 0xff) { if (--this->unk_7a != 0) return 1; @@ -322,7 +320,7 @@ bool32 sub_0803EA64(BallChainSoldierEntity* this) { } bool32 sub_0803EAD0(BallChainSoldierEntity* this, u32 distance) { - return EntityWithinDistance(super, gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI - 4, distance); + return EntityWithinDistance(super, gEnemyTarget->x.HALF.HI, gEnemyTarget->y.HALF.HI - 4, distance); } void (*const BallChainSoldier_Functions[])(BallChainSoldierEntity*) = { diff --git a/src/enemy/chuchu.c b/src/enemy/chuchu.c index 7f3186bbf..a24aa6b92 100644 --- a/src/enemy/chuchu.c +++ b/src/enemy/chuchu.c @@ -21,8 +21,6 @@ typedef struct { /*0x83*/ u8 unk_83; } ChuchuEntity; -extern Entity* gUnk_020000B0; - void sub_0801F328(ChuchuEntity* this); void sub_0801F340(ChuchuEntity* this); void sub_0801F360(ChuchuEntity* this); @@ -579,12 +577,12 @@ void sub_0801F8C0(ChuchuEntity* this) { sub_0801F730(this); } else { u8 tmp = ++super->timer & 7; - if (tmp == 0 && sub_08049F1C(super, gUnk_020000B0, 0x38)) { + if (tmp == 0 && sub_08049F1C(super, gEnemyTarget, 0x38)) { super->action = 5; Chuchu_JumpAtPlayer(this); } else { if (tmp == 4) { - super->direction = GetFacingDirection(super, gUnk_020000B0); + super->direction = GetFacingDirection(super, gEnemyTarget); } ProcessMovement0(super); GetNextFrame(super); diff --git a/src/enemy/crow.c b/src/enemy/crow.c index 5c8824809..5ed6d5ee9 100644 --- a/src/enemy/crow.c +++ b/src/enemy/crow.c @@ -23,7 +23,6 @@ typedef struct { void (*const Crow_Functions[])(Entity*); void (*const gUnk_080CE990[])(CrowEntity*); void (*const gUnk_080CE9A4[])(CrowEntity*); -extern Entity* gUnk_020000B0; void sub_08032AF4(CrowEntity* this); void sub_08032AB0(CrowEntity* this); @@ -123,9 +122,9 @@ void sub_0803298C(CrowEntity* this) { if (sub_08049DF4(1) == NULL) return; - if (EntityInRectRadius(super, gUnk_020000B0, 0x88, 0x50) == 0) + if (EntityInRectRadius(super, gEnemyTarget, 0x88, 0x50) == 0) return; - if (gUnk_020000B0->y.HALF.HI <= super->y.HALF.HI + 8) + if (gEnemyTarget->y.HALF.HI <= super->y.HALF.HI + 8) return; super->action = 2; diff --git a/src/enemy/darkNut.c b/src/enemy/darkNut.c index 6a7a17db5..3eda472a1 100644 --- a/src/enemy/darkNut.c +++ b/src/enemy/darkNut.c @@ -46,8 +46,6 @@ void sub_08021644(DarkNutEntity*); u32 sub_08021664(DarkNutEntity*, Entity*); u32 sub_0802169C(DarkNutEntity*, Entity*); -extern Entity* gUnk_020000B0; - extern void (*const DarkNut_Functions[])(DarkNutEntity*); extern void (*const gUnk_080CAAB0[])(DarkNutEntity*); @@ -197,11 +195,11 @@ void sub_08020E78(DarkNutEntity* this) { void sub_08020E98(DarkNutEntity* this) { if (PlayerInRange(super, 1, 56)) { - if (sub_0802169C(this, gUnk_020000B0)) { + if (sub_0802169C(this, gEnemyTarget)) { super->action = 8; sub_08021218(this, 7, super->animationState); } else { - super->direction = GetFacingDirection(gUnk_020000B0, super); + super->direction = GetFacingDirection(gEnemyTarget, super); if (ProcessMovement0(super) == 0) { super->action = 8; sub_08021218(this, 7, super->animationState); @@ -212,10 +210,10 @@ void sub_08020E98(DarkNutEntity* this) { } } } else { - if (gUnk_020000B0 == NULL) { + if (gEnemyTarget == NULL) { sub_08021414(this); } else { - super->direction = GetFacingDirection(super, gUnk_020000B0); + super->direction = GetFacingDirection(super, gEnemyTarget); ProcessMovement0(super); sub_0802124C(this); sub_08021644(this); @@ -231,8 +229,8 @@ void sub_08020F28(DarkNutEntity* this) { void sub_08020F48(DarkNutEntity* this) { if (PlayerInRange(super, 1, 0x48)) { - if (sub_08021664(this, gUnk_020000B0)) { - u32 uVar2 = sub_0804A044(super, gUnk_020000B0, 9); + if (sub_08021664(this, gEnemyTarget)) { + u32 uVar2 = sub_0804A044(super, gEnemyTarget, 9); if (uVar2 == 0xff) { sub_08021424(this); } else { @@ -510,7 +508,7 @@ void sub_08021424(DarkNutEntity* this) { s32 x, y; u32 tmp; - u32 dir = GetFacingDirection(super, gUnk_020000B0); + u32 dir = GetFacingDirection(super, gEnemyTarget); tmp = sub_08021274(super->animationState, dir); if (tmp != 0xff) { sub_08021218(this, this->unk_74, tmp); @@ -520,20 +518,20 @@ void sub_08021424(DarkNutEntity* this) { switch (tmp) { case 0: - x = gUnk_020000B0->x.HALF.HI; - y = gUnk_020000B0->y.HALF.HI + 0x2c; + x = gEnemyTarget->x.HALF.HI; + y = gEnemyTarget->y.HALF.HI + 0x2c; break; case 1: - x = gUnk_020000B0->x.HALF.HI - 0x24; - y = gUnk_020000B0->y.HALF.HI; + x = gEnemyTarget->x.HALF.HI - 0x24; + y = gEnemyTarget->y.HALF.HI; break; case 2: - x = gUnk_020000B0->x.HALF.HI; - y = gUnk_020000B0->y.HALF.HI - 0x1d; + x = gEnemyTarget->x.HALF.HI; + y = gEnemyTarget->y.HALF.HI - 0x1d; break; default: - x = gUnk_020000B0->x.HALF.HI + 0x24; - y = gUnk_020000B0->y.HALF.HI; + x = gEnemyTarget->x.HALF.HI + 0x24; + y = gEnemyTarget->y.HALF.HI; break; } @@ -555,7 +553,7 @@ u32 sub_080214FC(DarkNutEntity* this) { if (!sub_08049FDC(super, 1)) return 0; - direction = GetFacingDirection(super, gUnk_020000B0); + direction = GetFacingDirection(super, gEnemyTarget); if (4 < (direction - (super->frame & 0x1f)) - 2) return 0; diff --git a/src/enemy/enemy4D.c b/src/enemy/enemy4D.c index 4fe0acfa0..479941f6e 100644 --- a/src/enemy/enemy4D.c +++ b/src/enemy/enemy4D.c @@ -33,8 +33,6 @@ typedef struct { extern void sub_0803E9A4(Entity*); // ballChainSoldier extern void sub_0803E94C(Entity*, u32); // ballChainSoldier -extern Entity* gUnk_020000B0; - void sub_0803EE8C(Enemy4DEntity*); bool32 sub_0803EF20(Enemy4DEntity*); bool32 sub_0803EEA4(Enemy4DEntity*); @@ -120,7 +118,7 @@ void Enemy4D_Init(Enemy4DEntity* this) { void Enemy4D_Action1(Enemy4DEntity* this) { this->unk_7c -= 0xa; if (sub_08049DF4(1)) { - super->direction = DirectionRoundUp(GetFacingDirection(super, gUnk_020000B0)); + super->direction = DirectionRoundUp(GetFacingDirection(super, gEnemyTarget)); sub_0803E94C(super, 0); } sub_0803E9A4(super); @@ -268,7 +266,7 @@ bool32 sub_0803EEA4(Enemy4DEntity* this) { s32 tmp; if (sub_08049FDC(super, 1)) { if (sub_0803EF04(this, 0x4e) != 0) { - tmp = sub_0804A044(super, gUnk_020000B0, 0x12); + tmp = sub_0804A044(super, gEnemyTarget, 0x12); if (tmp != 0xff) { if (--this->unk_7a == 0) { super->action = 5; @@ -285,7 +283,7 @@ bool32 sub_0803EEA4(Enemy4DEntity* this) { } bool32 sub_0803EF04(Enemy4DEntity* this, u32 distance) { - return EntityWithinDistance(super, gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI - 4, distance); + return EntityWithinDistance(super, gEnemyTarget->x.HALF.HI, gEnemyTarget->y.HALF.HI - 4, distance); } bool32 sub_0803EF20(Enemy4DEntity* this) { diff --git a/src/enemy/enemy50.c b/src/enemy/enemy50.c index 36156ce7b..1bb3c1933 100644 --- a/src/enemy/enemy50.c +++ b/src/enemy/enemy50.c @@ -26,8 +26,6 @@ typedef struct { /*0x80*/ u8 unk_80; } Enemy50Entity; -extern Entity* gUnk_020000B0; - extern void sub_0803F58C(Enemy50Entity*); extern void sub_0803F6EC(Enemy50Entity*); extern void sub_0803F66C(Enemy50Entity*); @@ -265,7 +263,7 @@ void Enemy50_Action6(Enemy50Entity* this) { tmp = super->timer + 1; super->timer = tmp; if ((tmp & gUnk_080D0E14[tmp * 0x1000000 >> 0x1e]) == 0) { - sub_08004596(super, GetFacingDirection(super, gUnk_020000B0)); + sub_08004596(super, GetFacingDirection(super, gEnemyTarget)); } sub_0803F66C(this); ProcessMovement1(super); @@ -350,7 +348,7 @@ bool32 sub_08041170(Enemy50Entity* this) { } else { if ((sub_08049FDC(super, 1)) && ((sub_0806FD54(super) || - ((0xf < (s16)gArea.lightLevel && (EntityInRectRadius(super, gUnk_020000B0, 0x70, 0x48))))))) { + ((0xf < (s16)gArea.lightLevel && (EntityInRectRadius(super, gEnemyTarget, 0x70, 0x48))))))) { sub_08041134(this); return TRUE; } diff --git a/src/enemy/eyegore.c b/src/enemy/eyegore.c index 03b1c90e8..dfa963435 100644 --- a/src/enemy/eyegore.c +++ b/src/enemy/eyegore.c @@ -33,7 +33,6 @@ typedef struct { extern Entity* sub_08017A90(Entity*, Entity*); -extern Entity* gUnk_020000B0; extern const u8 gMapTileTypeToCollisionData[]; void sub_08031344(EyegoreEntity*); @@ -175,7 +174,7 @@ void Eyegore_Action2(EyegoreEntity* this) { super->timer = 60; super->direction = (CalculateDirectionTo(super->x.HALF.HI + super->hitbox->offset_x, super->y.HALF.HI + super->hitbox->offset_y, - gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI) + + gEnemyTarget->x.HALF.HI, gEnemyTarget->y.HALF.HI) + 4) & 0x18; InitializeAnimation(super, 10); @@ -364,8 +363,8 @@ void sub_08031024(EyegoreEntity* this) { if (this->unk_79 == 0) { if (boolresult != 0) { super->direction = CalculateDirectionTo(super->x.HALF.HI + super->hitbox->offset_x, - super->y.HALF.HI + super->hitbox->offset_y, - gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI); + super->y.HALF.HI + super->hitbox->offset_y, gEnemyTarget->x.HALF.HI, + gEnemyTarget->y.HALF.HI); } else { this->unk_79 = 1; this->unk_78 = boolresult != 0; diff --git a/src/enemy/ghini.c b/src/enemy/ghini.c index f835ec1fb..877db7a0b 100644 --- a/src/enemy/ghini.c +++ b/src/enemy/ghini.c @@ -18,8 +18,6 @@ typedef struct { /*0x7c*/ u16 unk_7c; } GhiniEntity; -extern Entity* gUnk_020000B0; - extern void (*const Ghini_Functions[])(GhiniEntity*); extern void (*const Ghini_Actions[])(GhiniEntity*); extern void (*const Ghini_SubActions[])(GhiniEntity*); @@ -173,7 +171,7 @@ void Ghini_Action2(GhiniEntity* this) { super->action = 3; super->timer = 30; if (sub_08049DF4(1) != NULL) { - super->direction = GetFacingDirection(super, gUnk_020000B0); + super->direction = GetFacingDirection(super, gEnemyTarget); } else { super->direction = Random() & 0x1f; } @@ -222,7 +220,7 @@ void Ghini_Action6(GhiniEntity* this) { tmp = super->timer + 1; super->timer = tmp; if ((tmp & gUnk_080D0970[tmp * 0x1000000 >> 0x1e]) == 0) { - sub_08004596(super, GetFacingDirection(super, gUnk_020000B0)); + sub_08004596(super, GetFacingDirection(super, gEnemyTarget)); } sub_0803F66C(this); ProcessMovement1(super); @@ -326,7 +324,7 @@ bool32 sub_0803F5D4(GhiniEntity* this) { this->unk_7c--; } else if ((sub_08049FDC(super, 1)) && ((sub_0806FD54(super) || - ((0xf < (s16)gArea.lightLevel && (EntityInRectRadius(super, gUnk_020000B0, 0x70, 0x48))))))) { + ((0xf < (s16)gArea.lightLevel && (EntityInRectRadius(super, gEnemyTarget, 0x70, 0x48))))))) { sub_0803F630(this); return TRUE; } diff --git a/src/enemy/gibdo.c b/src/enemy/gibdo.c index e0813e6df..04bf487db 100644 --- a/src/enemy/gibdo.c +++ b/src/enemy/gibdo.c @@ -40,7 +40,6 @@ 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); @@ -230,18 +229,18 @@ bool32 sub_08037810(GibdoEntity* this) { 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); + EntityWithinDistance(super, gEnemyTarget->x.HALF.HI, gEnemyTarget->y.HALF.HI, 0x40)) { + dir = GetFacingDirection(super, gEnemyTarget); 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->direction = DirectionRoundUp(GetFacingDirection(super, gEnemyTarget)); 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; + this->field_0x78 = gEnemyTarget->x.HALF.HI; + this->field_0x7a = gEnemyTarget->y.HALF.HI; InitAnimationForceUpdate(super, super->animationState); return TRUE; } @@ -255,8 +254,8 @@ bool32 sub_08037810(GibdoEntity* this) { 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)) { + if (sub_0804A044(super, gEnemyTarget, 0xa) == super->direction) + if (EntityWithinDistance(super, gEnemyTarget->x.HALF.HI, gEnemyTarget->y.HALF.HI, 0x18)) { super->action = 5; super->speed = 0x100; InitAnimationForceUpdate(super, super->animationState + 8); @@ -271,9 +270,9 @@ bool32 sub_080378B0(GibdoEntity* this) { 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; + if (!EntityWithinDistance(gEnemyTarget, this->field_0x78, this->field_0x7a, 0x28)) { + this->field_0x78 = gEnemyTarget->x.HALF_U.HI; + this->field_0x7a = gEnemyTarget->y.HALF_U.HI; sub_0803797C(this); return FALSE; } diff --git a/src/enemy/keaton.c b/src/enemy/keaton.c index 40688bfec..a6f007f81 100644 --- a/src/enemy/keaton.c +++ b/src/enemy/keaton.c @@ -17,7 +17,6 @@ typedef struct { /*0x7b*/ u8 unk_7b; } KeatonEntity; -extern Entity* gUnk_020000B0; void Keaton_OnTick(KeatonEntity*); void Keaton_OnCollision(KeatonEntity*); void Keaton_OnGrabbed(KeatonEntity*); @@ -167,9 +166,8 @@ void Keaton_Action5(KeatonEntity* this) { } u32 sub_080325E8(KeatonEntity* this) { - if ((sub_08049FA0(super) && sub_08049FDC(super, 1)) && - (EntityInRectRadius(super, gUnk_020000B0, 0x68, 0x40) != 0)) { - if (((GetFacingDirection(super, gUnk_020000B0) - (DirectionRound(super->frame)) + 2) & 0x1F) < 5) { + if ((sub_08049FA0(super) && sub_08049FDC(super, 1)) && (EntityInRectRadius(super, gEnemyTarget, 0x68, 0x40) != 0)) { + if (((GetFacingDirection(super, gEnemyTarget) - (DirectionRound(super->frame)) + 2) & 0x1F) < 5) { super->action = 3; super->timer = 12; super->direction = DirectionRound(super->frame); diff --git a/src/enemy/leever.c b/src/enemy/leever.c index 6b12cf8e7..ef2c051af 100644 --- a/src/enemy/leever.c +++ b/src/enemy/leever.c @@ -15,8 +15,6 @@ typedef struct { /*0x74*/ u16 unk_74; } LeeverEntity; -extern Entity* gUnk_020000B0; - bool32 Leever_PlayerInRange(Entity*, s32); void Leever_Move(LeeverEntity*); @@ -78,7 +76,7 @@ void Leever_Idle(LeeverEntity* this) { super->action = 2; super->spriteSettings.draw = TRUE; super->direction = - (GetFacingDirection(super, gUnk_020000B0) + gLeeverDrift[Random() & 1]) & (0x3 | DirectionNorthWest); + (GetFacingDirection(super, gEnemyTarget) + gLeeverDrift[Random() & 1]) & (0x3 | DirectionNorthWest); InitializeAnimation(super, LeeverAnimation_DigUp); UpdateSpriteForCollisionLayer(super); } else { @@ -129,15 +127,15 @@ bool32 sub_0801FDE4(Entity* entity, s32 x, s32 y) { u32 actTile; const u16* puVar4; - if (GetCollisionDataAtWorldCoords(x, y, gUnk_020000B0->collisionLayer) != 0) { + if (GetCollisionDataAtWorldCoords(x, y, gEnemyTarget->collisionLayer) != 0) { return FALSE; } else { - actTile = GetActTileAtWorldCoords(x, y, gUnk_020000B0->collisionLayer); + actTile = GetActTileAtWorldCoords(x, y, gEnemyTarget->collisionLayer); for (puVar4 = gUnk_080CA4CA; *puVar4 != (u16)-1;) { if (*puVar4++ == actTile) { entity->x.HALF.HI = (x & 0xfff0) + 8; entity->y.HALF.HI = (y & 0xfff0) + 8; - entity->collisionLayer = gUnk_020000B0->collisionLayer; + entity->collisionLayer = gEnemyTarget->collisionLayer; return TRUE; } } @@ -153,8 +151,8 @@ bool32 Leever_PlayerInRange(Entity* entity, s32 arg2) { if (sub_08049FDC(entity, 1) == 0) { return 0; } else { - x = gUnk_020000B0->x.WORD; - y = gUnk_020000B0->y.WORD; + x = gEnemyTarget->x.WORD; + y = gEnemyTarget->y.WORD; sin = gSineTable[arg2 * 8] << 11; cos = gSineTable[arg2 * 8 + 0x40] << 11; for (i = 0; i < 8; i++) { @@ -176,12 +174,12 @@ void Leever_Move(LeeverEntity* this) { super->speed = (super->frame & 0xf) * 0x20; if (super->type == LeeverForm_Red) { if ((super->subtimer++ & 0xf) == 0) { - sub_08004596(super, sub_0800132C(super, gUnk_020000B0)); + sub_08004596(super, sub_0800132C(super, gEnemyTarget)); } } else { super->speed += 0x40; if ((super->subtimer++ & 0x7) == 0) { - sub_08004596(super, sub_0800132C(super, gUnk_020000B0)); + sub_08004596(super, sub_0800132C(super, gEnemyTarget)); } } diff --git a/src/enemy/mulldozer.c b/src/enemy/mulldozer.c index 9afd925a4..9f29616d4 100644 --- a/src/enemy/mulldozer.c +++ b/src/enemy/mulldozer.c @@ -16,8 +16,6 @@ typedef struct { /*0x83*/ u8 unk_83; } MulldozerEntity; -extern Entity* gUnk_020000B0; - extern void (*const Mulldozer_Functions[])(MulldozerEntity*); extern void (*const Mulldozer_Actions[])(MulldozerEntity*); extern const u8 gUnk_080CEA50[]; @@ -449,7 +447,7 @@ bool32 sub_08033364(MulldozerEntity* this) { if (super->type != 0) { return TRUE; } - tmp = GetFacingDirection(super, gUnk_020000B0); + tmp = GetFacingDirection(super, gEnemyTarget); tmp = Direction8RoundUp(tmp); tmp = Direction8ToAnimationState(tmp); if (super->animationState == tmp) { diff --git a/src/enemy/octorok.c b/src/enemy/octorok.c index bdf9c73f6..35153389d 100644 --- a/src/enemy/octorok.c +++ b/src/enemy/octorok.c @@ -15,7 +15,6 @@ extern void (*const Octorok_Functions[6])(Entity*); extern void (*const gOctorokActions[4])(Entity*); extern void (*const gUnk_080CA158[6])(Entity*); -extern Entity* gUnk_020000B0; extern const u8 gOctorokWalkDuration[4]; extern const u8 gOctorokSpitChanceModifier[2]; extern const u8 gOctorokNutOffset[8]; @@ -153,7 +152,7 @@ void Octorok_Turn(Entity* this) { if (this->type != 2) { if (sub_08049FA0(this)) { if (this->type == 1 && (Random() & 3) == 0 && sub_08049FDC(this, 1)) { - this->direction = DirectionRoundUp(GetFacingDirection(this, gUnk_020000B0)); + this->direction = DirectionRoundUp(GetFacingDirection(this, gEnemyTarget)); } else { this->direction = DirectionRound(Random()); } @@ -169,10 +168,10 @@ void Octorok_Turn(Entity* this) { } else if (Random() & 3) { this->direction = DirectionRound(sub_08049EE4(this) + gUnk_080CA17E[Random() & 1]); } else { - this->direction = DirectionRoundUp(GetFacingDirection(this, gUnk_020000B0)); + this->direction = DirectionRoundUp(GetFacingDirection(this, gEnemyTarget)); } } else { - this->direction = DirectionRoundUp(GetFacingDirection(this, gUnk_020000B0)); + this->direction = DirectionRoundUp(GetFacingDirection(this, gEnemyTarget)); } } diff --git a/src/enemy/peahat.c b/src/enemy/peahat.c index a8404af91..dc3b8b2fd 100644 --- a/src/enemy/peahat.c +++ b/src/enemy/peahat.c @@ -28,8 +28,6 @@ extern const s8 gUnk_080CA5D4[]; void sub_080205F8(PeahatEntity* this); void sub_08020604(PeahatEntity* this); -extern Entity* gUnk_020000B0; - enum { PeahatForm_Torso, PeahatForm_Propeller, @@ -161,7 +159,7 @@ void Peahat_Fly(PeahatEntity* this) { this->unk_83--; if (sub_08049FDC(super, 1)) { - if (this->unk_83 == 0 && (super->subtimer & 0xf) == 0 && sub_08049F1C(super, gUnk_020000B0, 0x30)) { + if (this->unk_83 == 0 && (super->subtimer & 0xf) == 0 && sub_08049F1C(super, gEnemyTarget, 0x30)) { super->action = 2; super->subAction = Random() & 3; super->timer = 60; @@ -191,7 +189,7 @@ void Peahat_ChargeStart(PeahatEntity* this) { super->timer = 120; super->speed = 192; super->direction = - (GetFacingDirection(super, gUnk_020000B0) + gUnk_080CA5D4[Random() & 1]) & (0x3 | DirectionNorthWest); + (GetFacingDirection(super, gEnemyTarget) + gUnk_080CA5D4[Random() & 1]) & (0x3 | DirectionNorthWest); } } else { sub_080205F8(this); @@ -210,7 +208,7 @@ void Peahat_ChargeTarget(PeahatEntity* this) { super->speed += 4; if ((gRoomTransition.frameCount & 3) == 0) - sub_08004596(super, GetFacingDirection(super, gUnk_020000B0)); + sub_08004596(super, GetFacingDirection(super, gEnemyTarget)); } ProcessMovement2(super); } else { diff --git a/src/enemy/pesto.c b/src/enemy/pesto.c index 37bc230ac..489098cdb 100644 --- a/src/enemy/pesto.c +++ b/src/enemy/pesto.c @@ -45,8 +45,6 @@ u32 sub_08024E34(void); void sub_08024E4C(PestoEntity*); void sub_08024F50(PestoEntity*); -extern Entity* gUnk_020000B0; - extern void (*const Pesto_Functions[])(PestoEntity*); extern void (*const gUnk_080CBEDC[])(PestoEntity*); extern void (*const gUnk_080CBEF8[])(PestoEntity*); @@ -238,7 +236,7 @@ void sub_080242A0(PestoEntity* this) { sub_08024940(this); if (sub_08024CC0(this)) { if (--super->timer == 0) { - super->direction = GetFacingDirection(super, gUnk_020000B0); + super->direction = GetFacingDirection(super, gEnemyTarget); sub_08024E00(this, 1); if (super->speed != 0) { super->speed = 0; @@ -249,7 +247,7 @@ void sub_080242A0(PestoEntity* this) { sub_08024A14(this, 3, 10); } - if (sub_08049F1C(super, gUnk_020000B0, 0x20) && sub_08049FDC(super, 3)) { + if (sub_08049F1C(super, gEnemyTarget, 0x20) && sub_08049FDC(super, 3)) { super->action = 4; this->unk_80 = 0; super->timer = 16; @@ -294,7 +292,7 @@ void sub_080243B8(PestoEntity* this) { super->timer = 32; super->speed = 0x80; this->unk_83 = 0x80; - } else if (sub_08049F1C(super, gUnk_020000B0, 0xe)) { + } else if (sub_08049F1C(super, gEnemyTarget, 0xe)) { this->unk_80++; super->timer = 30; super->speed = 0x100; @@ -600,13 +598,13 @@ void sub_08024A14(PestoEntity* this, u32 param_2, u32 param_3) { break; case 2: if (sub_08024C48(this, TRUE)) { - sub_08004596(super, GetFacingDirection(super, gUnk_020000B0)); + sub_08004596(super, GetFacingDirection(super, gEnemyTarget)); unk = TRUE; } break; case 3: if (sub_08024C48(this, TRUE)) { - super->direction = GetFacingDirection(super, gUnk_020000B0); + super->direction = GetFacingDirection(super, gEnemyTarget); unk = TRUE; } break; @@ -662,9 +660,9 @@ bool32 sub_08024B38(PestoEntity* this) { } } if (gPlayerState.hurtBlinkSpeed != 0) { - if (sub_08024C48(this, 1) && sub_08049F1C(super, gUnk_020000B0, 0xa0)) { + if (sub_08024C48(this, 1) && sub_08049F1C(super, gEnemyTarget, 0xa0)) { iVar4 = 1; - super->child = gUnk_020000B0; + super->child = gEnemyTarget; this->unk_83 |= 3; this->unk_83 &= ~0x40; } @@ -761,7 +759,7 @@ bool32 sub_08024CC0(PestoEntity* this) { uVar2 = TRUE; if (!sub_08024C48(this, 1)) { uVar2 = FALSE; - } else if (!sub_08049F1C(super, gUnk_020000B0, 0x50) || !sub_08049FDC(super, 3)) { + } else if (!sub_08049F1C(super, gEnemyTarget, 0x50) || !sub_08049FDC(super, 3)) { uVar2 = FALSE; sub_08024C7C(this); } diff --git a/src/enemy/rope.c b/src/enemy/rope.c index 74c770665..f8b171f44 100644 --- a/src/enemy/rope.c +++ b/src/enemy/rope.c @@ -36,8 +36,6 @@ static void (*const Rope_Functions[6])(RopeEntity*) = { Rope_OnGrabbed, }; -extern Entity* gUnk_020000B0; - void sub_08031600(RopeEntity* this); u32 sub_0803163C(RopeEntity* this); @@ -147,7 +145,7 @@ void sub_080314FC(RopeEntity* this) { if (sub_08049FA0(super)) { if (!(this->unk_78)) { if (sub_08049FDC(super, 1)) { - u = sub_0804A044(super, gUnk_020000B0, 0xc); + u = sub_0804A044(super, gEnemyTarget, 0xc); if (u != 0xff) { super->action = 3; super->timer = 30; diff --git a/src/enemy/sluggula.c b/src/enemy/sluggula.c index cd371ec46..4217da7e2 100644 --- a/src/enemy/sluggula.c +++ b/src/enemy/sluggula.c @@ -167,14 +167,12 @@ void sub_08023E54(Entity* this) { } } -extern Entity* gUnk_020000B0; - void sub_08023E9C(Entity* this) { u32 uVar3 = Random(); if (!sub_08049FA0(this) && (uVar3 & 1)) { this->direction = DirectionRoundUp(sub_08049EE4(this)); } else if (sub_08049FDC(this, 1) && (uVar3 & 6)) { - u32 uVar3 = GetFacingDirection(this, gUnk_020000B0) - this->direction; + u32 uVar3 = GetFacingDirection(this, gEnemyTarget) - this->direction; if (uVar3 != 0 && ((uVar3 + 4) & 0x1f) > 8) { if ((uVar3 & 0x1f) < 0x10) { this->direction = DirectionRound(this->direction + 8); diff --git a/src/enemy/spikedBeetle.c b/src/enemy/spikedBeetle.c index 4dcd1ec36..95e3566fa 100644 --- a/src/enemy/spikedBeetle.c +++ b/src/enemy/spikedBeetle.c @@ -9,8 +9,6 @@ extern u32 sub_0804A024(Entity*, u32, u32); -extern Entity* gUnk_020000B0; - void sub_0802B9B4(Entity*); void sub_0802B7A4(Entity*); void sub_0802B960(Entity*); @@ -134,7 +132,7 @@ void sub_0802B820(Entity* this) { sub_0802B9B4(this); } else if (sub_08049FDC(this, 1)) { if ((this->timer & 0xf) == 0) { - sub_08004596(this, GetFacingDirection(this, gUnk_020000B0)); + sub_08004596(this, GetFacingDirection(this, gEnemyTarget)); } } else { sub_0802B9B4(this); diff --git a/src/enemy/spinyChuchu.c b/src/enemy/spinyChuchu.c index 72329b9f1..ee63610d8 100644 --- a/src/enemy/spinyChuchu.c +++ b/src/enemy/spinyChuchu.c @@ -23,8 +23,6 @@ extern void (*const gUnk_080CBA40[])(SpinyChuchuEntity*); extern const u8 gUnk_080CBA60[]; -extern Entity* gUnk_020000B0; - void SpinyChuchu(SpinyChuchuEntity* this) { EnemyFunctionHandler(super, (EntityActionArray)SpinyChuchu_Functions); EnemySetFXOffset(super, 0, 1, -0x10); @@ -164,7 +162,7 @@ void sub_080226EC(SpinyChuchuEntity* this) { super->action = 6; super->zVelocity = Q_16_16(1.125); super->speed = 0x140; - super->direction = GetFacingDirection(super, gUnk_020000B0); + super->direction = GetFacingDirection(super, gEnemyTarget); super->hitType = 0x5a; InitializeAnimation(super, 4); return; diff --git a/src/enemy/stalfos.c b/src/enemy/stalfos.c index 3a54a8c28..3d31789b5 100644 --- a/src/enemy/stalfos.c +++ b/src/enemy/stalfos.c @@ -19,8 +19,6 @@ typedef struct { /*0x7d*/ u8 unk_7d; } StalfosEntity; -extern Entity* gUnk_020000B0; - extern void (*const Stalfos_Functions[])(StalfosEntity*); extern void (*const Stalfos_Actions[])(StalfosEntity*); extern void (*const Stalfos_SubActions[])(StalfosEntity*); @@ -291,10 +289,10 @@ bool32 sub_08039758(StalfosEntity* this) { } if (sub_08049FDC(super, 1) && (this->unk_7a == 0)) { if (super->type == 0) { - if (EntityWithinDistance(super, gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI, 0x24)) { + if (EntityWithinDistance(super, gEnemyTarget->x.HALF.HI, gEnemyTarget->y.HALF.HI, 0x24)) { super->action = 5; super->speed = 0x180; - super->direction = GetFacingDirection(super, gUnk_020000B0); + super->direction = GetFacingDirection(super, gEnemyTarget); super->animationState = (((super->direction + 4) & 0x18) >> 3); sub_0803981C(this); super->hitType = 0x46; @@ -303,10 +301,10 @@ bool32 sub_08039758(StalfosEntity* this) { return TRUE; } } else { - if (EntityWithinDistance(super, gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI, 0x48)) { + if (EntityWithinDistance(super, gEnemyTarget->x.HALF.HI, gEnemyTarget->y.HALF.HI, 0x48)) { super->action = 8; super->timer = 60; - super->direction = GetFacingDirection(super, gUnk_020000B0); + super->direction = GetFacingDirection(super, gEnemyTarget); InitAnimationForceUpdate(super, super->animationState + 0xc); return TRUE; } @@ -347,7 +345,7 @@ void sub_08039858(StalfosEntity* this) { u32 sub_080398C0(StalfosEntity* this) { u32 rand = Random(); if ((super->type == 0) && sub_08049FDC(super, 1) && - (EntityWithinDistance(super, gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI, 0x58) != 0)) { + (EntityWithinDistance(super, gEnemyTarget->x.HALF.HI, gEnemyTarget->y.HALF.HI, 0x58) != 0)) { return GetFacingDirection(super, &gPlayerEntity.base); } else { if ((sub_08049FA0(super) == 0) && ((rand & 7) != 0)) { diff --git a/src/enemy/takkuri.c b/src/enemy/takkuri.c index fc5c90bd5..d0524ddeb 100644 --- a/src/enemy/takkuri.c +++ b/src/enemy/takkuri.c @@ -25,8 +25,6 @@ typedef struct { static_assert(sizeof(TakkuriEntity) == 0x88); -extern Entity* gUnk_020000B0; - void (*const Takkuri_Functions[])(Entity*); void (*const gUnk_080CFF54[])(TakkuriEntity*); void (*const gUnk_080CFF6C[])(TakkuriEntity*); @@ -138,8 +136,8 @@ void sub_0803BD08(TakkuriEntity* this) { GetNextFrame(super); entity = sub_08049DF4(1); if (entity != NULL) { - if (EntityInRectRadius(super, gUnk_020000B0, 0x88, 0x50)) { - if (gUnk_020000B0->y.HALF.HI > super->y.HALF.HI + 8) { + if (EntityInRectRadius(super, gEnemyTarget, 0x88, 0x50)) { + if (gEnemyTarget->y.HALF.HI > super->y.HALF.HI + 8) { super->action = 2; this->unk_0x84 = 0; super->timer = 16; diff --git a/src/enemy/torchTrap.c b/src/enemy/torchTrap.c index e34e2caac..62789aa99 100644 --- a/src/enemy/torchTrap.c +++ b/src/enemy/torchTrap.c @@ -29,8 +29,6 @@ void (*const gTorchTrapActions[])(TorchTrapEntity*); const u16 gTorchTrapTimerLengths[]; const u16 gTorchTrapProjectileSpeeds[]; -extern Entity* gUnk_020000B0; - bool32 sub_0803CFF0(TorchTrapEntity*); bool32 sub_0803CFD8(TorchTrapEntity*); void sub_0803D0B0(TorchTrapEntity*); @@ -66,7 +64,7 @@ void sub_0803CF38(TorchTrapEntity* this) { if (sub_0803CFF0(this)) { sub_0803D0B0(this); } else if (sub_08049FDC(super, 0)) { - if (EntityWithinDistance(super, gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI, 0x20) == 0) { + if (EntityWithinDistance(super, gEnemyTarget->x.HALF.HI, gEnemyTarget->y.HALF.HI, 0x20) == 0) { if (--this->projectileTimer == 0) { TorchTrap_CreateProjectile(this); TorchTrap_Reset(this); @@ -132,7 +130,7 @@ void TorchTrap_CreateProjectile(TorchTrapEntity* this) { } if (super->direction & 0x20) { - proj->direction = GetFacingDirection(super, gUnk_020000B0); + proj->direction = GetFacingDirection(super, gEnemyTarget); } else { proj->direction = super->direction; } diff --git a/src/enemy/vaatiProjectile.c b/src/enemy/vaatiProjectile.c index 71c84c446..bb366ef5c 100644 --- a/src/enemy/vaatiProjectile.c +++ b/src/enemy/vaatiProjectile.c @@ -15,8 +15,6 @@ typedef struct { /*0x78*/ u16 unk_78; } VaatiProjectileEntity; -extern Entity* gUnk_020000B0; - bool32 sub_0803E4A0(VaatiProjectileEntity*); void VaatiProjectile_OnTick(VaatiProjectileEntity*); void VaatiProjectile_OnCollision(VaatiProjectileEntity*); @@ -142,8 +140,8 @@ void VaatiProjectileFunction0Action1(VaatiProjectileEntity* this) { super->timer = 10; InitializeAnimation(super->child, 2); } else { - if (gUnk_020000B0 != NULL) { - sub_08004596(super, GetFacingDirection(super, gUnk_020000B0)); + if (gEnemyTarget != NULL) { + sub_08004596(super, GetFacingDirection(super, gEnemyTarget)); LinearMoveUpdate(super); } } diff --git a/src/enemy/wallMaster2.c b/src/enemy/wallMaster2.c index 63f14826c..a44230498 100644 --- a/src/enemy/wallMaster2.c +++ b/src/enemy/wallMaster2.c @@ -20,8 +20,6 @@ typedef struct { /*0x7c*/ u16 unk_7c; } WallMaster2Entity; -extern Entity* gUnk_020000B0; - void sub_0802CF64(WallMaster2Entity*); void sub_0802CF8C(WallMaster2Entity*); void sub_0802CFD8(WallMaster2Entity*); @@ -113,7 +111,7 @@ void sub_0802CD54(WallMaster2Entity* this) { void sub_0802CDE8(WallMaster2Entity* this) { if (--this->unk_78 && sub_08049FDC(super, 1)) { if ((super->timer++ & 3) == 0) { - sub_08004596(super, GetFacingDirection(super, gUnk_020000B0)); + sub_08004596(super, GetFacingDirection(super, gEnemyTarget)); sub_0802CF8C(this); } LinearMoveUpdate(super); From f3365f1e2ecd0559f50b21dcce1556a50d5db57c Mon Sep 17 00:00:00 2001 From: Henny022p Date: Sun, 12 Jan 2025 02:07:19 +0000 Subject: [PATCH 2/2] document unknown members of Peahat --- assets/assets.json | 2 +- data/animations/enemy/peahat.s | 4 +- src/enemy/peahat.c | 162 +++++++++++++++++++-------------- 3 files changed, 97 insertions(+), 71 deletions(-) diff --git a/assets/assets.json b/assets/assets.json index 159dcb760..262535040 100644 --- a/assets/assets.json +++ b/assets/assets.json @@ -3931,7 +3931,7 @@ "type": "animation" }, { - "path": "peahat/gUnk_080CA5D4.bin", + "path": "peahat/gPeahatChargeDirectionOffsets.bin", "start": 828884, "size": 2 }, diff --git a/data/animations/enemy/peahat.s b/data/animations/enemy/peahat.s index dd98efe62..5d5e60c70 100644 --- a/data/animations/enemy/peahat.s +++ b/data/animations/enemy/peahat.s @@ -4,8 +4,8 @@ .section .rodata .align 2 -gUnk_080CA5D4:: @ 080CA5D4 - .incbin "peahat/gUnk_080CA5D4.bin" +gPeahatChargeDirectionOffsets:: @ 080CA5D4 + .incbin "peahat/gPeahatChargeDirectionOffsets.bin" gSpriteAnimations_Peahat_0:: @ 080CA5D6 .include "animations/gSpriteAnimations_Peahat_0.s" diff --git a/src/enemy/peahat.c b/src/enemy/peahat.c index dc3b8b2fd..8c5f66467 100644 --- a/src/enemy/peahat.c +++ b/src/enemy/peahat.c @@ -11,22 +11,49 @@ typedef struct { /*0x00*/ Entity base; /*0x68*/ u8 unused1[24]; - /*0x80*/ u8 unk_80; - /*0x81*/ u8 unk_81; - /*0x82*/ u8 unk_82; - /*0x83*/ u8 unk_83; + /** + * While flying around the Peahat will gradually change direction using this value. + * Changes between 2 and -2 at + * random intervals. + */ + /*0x80*/ u8 directionDelta; + /** + * Controls if the Peahat will move up and down while flying. + */ + /*0x81*/ bool8 moveUpAnDown; + /** + * The Peahat is currently flying. + */ + /*0x82*/ bool8 flying; + /** + * The Peahat will continue flying around for this period before considering to charge again. + */ + /*0x83*/ u8 flyTimer; } PeahatEntity; +enum PeahatActions { + PeahatActionInitialize, + PeahatActionFly, + PeahatActionChargeStart, + PeahatActionChargeTarget, + PeahatActionChargeEnd, + PeahatActionStunned, + PeahatActionRepairPropeller, + PeahatActionRecover, + PeahatActionHop, + PeahatActionTakeoff, +}; + extern void (*const Peahat_Functions[])(PeahatEntity*); extern void (*const gPeahatPropellerFunctions[])(PeahatEntity*); extern void (*const gPeahatActions[])(PeahatEntity*); -extern void (*const gUnk_080CA5BC[])(PeahatEntity*); +extern void (*const gPeahatOnGrabbedSubactions[])(PeahatEntity*); extern const s8 gPeahatFlightHeights[]; -extern const s8 gUnk_080CA5D4[]; +extern const s8 gPeahatChargeDirectionOffsets[]; -void sub_080205F8(PeahatEntity* this); -void sub_08020604(PeahatEntity* this); +void Peahat_EndCharge(PeahatEntity* this); +void Peahat_UpdateDirection(PeahatEntity* this); enum { PeahatForm_Torso, @@ -53,39 +80,39 @@ void Peahat(PeahatEntity* this) { void Peahat_OnTick(PeahatEntity* this) { gPeahatActions[super->action](this); - if (this->unk_81) + if (this->moveUpAnDown) super->z.HALF.HI = gPeahatFlightHeights[(super->subtimer++ & 0x30) >> 4]; } void Peahat_OnCollision(PeahatEntity* this) { - if (this->unk_82) { + if (this->flying) { if (super->contactFlags == (CONTACT_NOW | 0x14)) { Entity* entity = CreateEnemy(PEAHAT, PeahatForm_Propeller); if (entity != NULL) { CopyPosition(super, entity); entity->z.HALF.HI -= 8; } - this->unk_82 = 0; + this->flying = FALSE; super->animationState = PeahatAnimation_SlicedPropeller; - super->action = 5; + super->action = PeahatActionStunned; super->speed = 0x80; super->iframes = -30; - this->unk_81 = 0; + this->moveUpAnDown = FALSE; InitializeAnimation(super, super->animationState); } else if (super->contactFlags == (CONTACT_NOW | 0x1b)) { super->animationState = PeahatAnimation_BrokenPropeller; - super->action = 5; + super->action = PeahatActionStunned; super->speed = 0x80; super->iframes = -30; - this->unk_81 = 0; + this->moveUpAnDown = FALSE; InitializeAnimation(super, super->animationState); } else if (super->contactFlags == CONTACT_NOW) { if (super->animationState == PeahatAnimation_Flying) { - super->action = 1; + super->action = PeahatActionFly; super->timer = 30; super->speed = 0x80; super->direction = -1; - this->unk_83 = 0x78; + this->flyTimer = 120; GetNextFrame(super); } } @@ -101,37 +128,37 @@ void Peahat_OnGrabbed(PeahatEntity* this) { if (2 >= super->subAction && !sub_0806F520(super)) return; - gUnk_080CA5BC[super->subAction](this); + gPeahatOnGrabbedSubactions[super->subAction](this); } -void sub_080200B4(PeahatEntity* this) { +void Peahat_OnGrabbed_Subaction0(PeahatEntity* this) { super->subAction = 1; super->gustJarTolerance = 60; if (super->animationState == PeahatAnimation_Flying) { super->animationState = PeahatAnimation_BrokenPropeller; - super->action = 5; + super->action = PeahatActionStunned; super->hitType = 0x71; - this->unk_81 = 0; + this->moveUpAnDown = FALSE; InitializeAnimation(super, super->animationState); } } -void sub_080200E4(PeahatEntity* this) { +void Peahat_OnGrabbed_Subaction1(PeahatEntity* this) { sub_0806F4E8(super); } -void sub_080200EC(PeahatEntity* this) { +void Peahat_OnGrabbed_Subaction2(PeahatEntity* this) { sub_0806F3E4(super); } -void sub_080200F4(PeahatEntity* this) { +void Peahat_OnGrabbed_Subaction3(PeahatEntity* this) { COLLISION_OFF(super); } -void nullsub_5(PeahatEntity* this) { +void Peahat_OnGrabbed_Subaction4(PeahatEntity* this) { } -void sub_08020104(PeahatEntity* this) { +void Peahat_OnGrabbed_Subaction5(PeahatEntity* this) { if (super->flags & ENT_COLLIDE) { COLLISION_ON(super); super->gustJarState &= 0xfb; @@ -142,25 +169,25 @@ void sub_08020104(PeahatEntity* this) { void Peahat_Initialize(PeahatEntity* this) { sub_0804A720(super); - super->action = 1; + super->action = PeahatActionFly; super->timer = 16; super->subtimer = Random(); super->direction = Random() & 0x1f; super->gustJarFlags = 18; - this->unk_80 = (Random() & 1) ? 2 : -2; - this->unk_81 = 1; - this->unk_82 = 1; + this->directionDelta = (Random() & 1) ? 2 : -2; + this->moveUpAnDown = TRUE; + this->flying = TRUE; super->animationState = PeahatAnimation_Flying; InitializeAnimation(super, super->animationState); } void Peahat_Fly(PeahatEntity* this) { - if (this->unk_83) - this->unk_83--; + if (this->flyTimer) + this->flyTimer--; if (sub_08049FDC(super, 1)) { - if (this->unk_83 == 0 && (super->subtimer & 0xf) == 0 && sub_08049F1C(super, gEnemyTarget, 0x30)) { - super->action = 2; + if (this->flyTimer == 0 && (super->subtimer & 0xf) == 0 && sub_08049F1C(super, gEnemyTarget, 0x30)) { + super->action = PeahatActionChargeStart; super->subAction = Random() & 3; super->timer = 60; super->speed = 160; @@ -169,9 +196,9 @@ void Peahat_Fly(PeahatEntity* this) { if (--super->timer == 0) { super->timer = 16; - sub_08020604(this); + Peahat_UpdateDirection(this); if ((Random() & 3) == 0) { - this->unk_80 = (Random() & 1) ? 2 : -2; + this->directionDelta = (Random() & 1) ? 2 : -2; } } @@ -184,15 +211,14 @@ void Peahat_ChargeStart(PeahatEntity* this) { if (--super->timer) { UpdateAnimationVariableFrames(super, 4 - ((super->timer >> 4) & 0x3)); return; - } else { - super->action = 3; - super->timer = 120; - super->speed = 192; - super->direction = - (GetFacingDirection(super, gEnemyTarget) + gUnk_080CA5D4[Random() & 1]) & (0x3 | DirectionNorthWest); } + super->action = PeahatActionChargeTarget; + super->timer = 120; + super->speed = 192; + super->direction = (GetFacingDirection(super, gEnemyTarget) + gPeahatChargeDirectionOffsets[Random() & 1]) & + (0x3 | DirectionNorthWest); } else { - sub_080205F8(this); + Peahat_EndCharge(this); } UpdateAnimationVariableFrames(super, 4); @@ -201,7 +227,7 @@ void Peahat_ChargeStart(PeahatEntity* this) { void Peahat_ChargeTarget(PeahatEntity* this) { if (sub_08049FDC(super, 1)) { if (--super->timer == 0) { - sub_080205F8(this); + Peahat_EndCharge(this); } if (super->timer > 60) { if (super->timer & 1) @@ -212,17 +238,17 @@ void Peahat_ChargeTarget(PeahatEntity* this) { } ProcessMovement2(super); } else { - sub_080205F8(this); + Peahat_EndCharge(this); } UpdateAnimationVariableFrames(super, 4); } void Peahat_ChargeEnd(PeahatEntity* this) { if (--super->timer == 0) { - super->action = 1; + super->action = PeahatActionFly; super->timer = 1; super->speed = 128; - this->unk_83 = 120; + this->flyTimer = 120; GetNextFrame(super); } else { if (super->timer & 1) @@ -239,7 +265,7 @@ void Peahat_Stunned(PeahatEntity* this) { switch (super->animationState) { default: if (BounceUpdate(super, Q_8_8(24.0)) == BOUNCE_DONE_ALL) { - super->action = 6; + super->action = PeahatActionRepairPropeller; super->timer = 240; super->subtimer = 10; super->hitType = 0x71; @@ -254,7 +280,7 @@ void Peahat_Stunned(PeahatEntity* this) { case PeahatAnimation_SlicedPropeller: GravityUpdate(super, Q_8_8(28.0)); if (super->z.HALF.HI == 0) { - super->action = 7; + super->action = PeahatActionRecover; super->timer = 150; super->subtimer = 10; super->hitType = 0x71; @@ -269,7 +295,7 @@ void Peahat_RepairPropeller(PeahatEntity* this) { } if (sub_0800442E(super) || (--super->timer == 0)) { - super->action = 9; + super->action = PeahatActionTakeoff; super->zVelocity = Q_16_16(1.5); super->direction = Random() & 0x1f; EnemyDetachFX(super); @@ -284,7 +310,7 @@ void Peahat_Recover(PeahatEntity* this) { } if (sub_0800442E(super) || (--super->timer == 0)) { - super->action = 8; + super->action = PeahatActionHop; super->timer = 240; super->direction = Random() & 0x1f; EnemyDetachFX(super); @@ -295,7 +321,7 @@ void Peahat_Hop(PeahatEntity* this) { GetNextFrame(super); if (--super->timer == 0) { if (super->frame & ANIM_DONE) { - super->action = 9; + super->action = PeahatActionTakeoff; super->zVelocity = Q_16_16(1.5); super->animationState = PeahatAnimation_NewPropeller; InitializeAnimation(super, super->animationState); @@ -319,10 +345,10 @@ void Peahat_Hop(PeahatEntity* this) { void Peahat_Takeoff(PeahatEntity* this) { GetNextFrame(super); if (super->frame & ANIM_DONE) { - super->action = 1; + super->action = PeahatActionFly; super->hitType = 0x70; - this->unk_82 = 1; - this->unk_81 = 1; + this->flying = TRUE; + this->moveUpAnDown = TRUE; super->animationState = PeahatAnimation_Flying; InitializeAnimation(super, super->animationState); } else if (super->frame & 1) { @@ -334,7 +360,7 @@ void Peahat_Takeoff(PeahatEntity* this) { } void PeahatPropeller_Initialize(PeahatEntity* this) { - super->action = 1; + super->action = PeahatActionFly; super->timer = 240; super->subtimer = 40; super->spriteSettings.draw = 1; @@ -363,16 +389,16 @@ void PeahatPropeller_Fly(PeahatEntity* this) { } } -void sub_080205F8(PeahatEntity* this) { - super->action = 4; +void Peahat_EndCharge(PeahatEntity* this) { + super->action = PeahatActionChargeEnd; super->timer = 60; } -void sub_08020604(PeahatEntity* this) { +void Peahat_UpdateDirection(PeahatEntity* this) { if (!sub_08049FA0(super) && (Random() & 3)) { super->direction = sub_08049EE4(super); } else { - super->direction += this->unk_80; + super->direction += this->directionDelta; super->direction &= (0x3 | DirectionNorthWest); } } @@ -409,17 +435,17 @@ const s8 gPeahatFlightHeights[] = { -5, -6, -7, -6, }; -void (*const gUnk_080CA5BC[])(PeahatEntity*) = { - sub_080200B4, - sub_080200E4, - sub_080200EC, - sub_080200F4, - nullsub_5, - sub_08020104, +void (*const gPeahatOnGrabbedSubactions[])(PeahatEntity*) = { + Peahat_OnGrabbed_Subaction0, + Peahat_OnGrabbed_Subaction1, + Peahat_OnGrabbed_Subaction2, + Peahat_OnGrabbed_Subaction3, + Peahat_OnGrabbed_Subaction4, + Peahat_OnGrabbed_Subaction5, }; /* Alignment issue -const s8 gUnk_080CA5D4[] = { +const s8 gPeahatChargeDirectionOffsets[] = { 4, -4, }; */