From 92e7aaa89b0a8ceca29185aa9b9454d1e02e80d0 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Thu, 24 Mar 2022 06:32:01 +0200 Subject: [PATCH] Put const data in acroBandits + renames --- assets/assets.json | 25 ------- data/const/enemy/acroBandits.s | 55 -------------- linker.ld | 2 +- src/enemy/acroBandits.c | 131 ++++++++++++++++++++++----------- 4 files changed, 87 insertions(+), 126 deletions(-) delete mode 100644 data/const/enemy/acroBandits.s diff --git a/assets/assets.json b/assets/assets.json index d3aed18c..90c97cc9 100644 --- a/assets/assets.json +++ b/assets/assets.json @@ -25510,31 +25510,6 @@ "size": 73, "type": "animation" }, - { - "path": "acroBandits/gUnk_080CE5B0.bin", - "start": 845232, - "size": 8 - }, - { - "path": "acroBandits/gUnk_080CE5B8.bin", - "start": 845240, - "size": 8 - }, - { - "path": "acroBandits/gUnk_080CE5C0.bin", - "start": 845248, - "size": 8 - }, - { - "path": "acroBandits/gUnk_080CE5F0.bin", - "start": 845296, - "size": 10 - }, - { - "path": "acroBandits/gUnk_080CE5FA.bin", - "start": 845306, - "size": 20 - }, { "path": "animations/gSpriteAnimations_Keaton_0.bin", "start": 845848, diff --git a/data/const/enemy/acroBandits.s b/data/const/enemy/acroBandits.s deleted file mode 100644 index cdda3e2d..00000000 --- a/data/const/enemy/acroBandits.s +++ /dev/null @@ -1,55 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - .align 2 - -AcroBandit_Functions:: @ 080CE56C - .4byte AcroBandit_OnTick - .4byte AcroBandit_OnCollision - .4byte AcroBandit_OnKnockback - .4byte GenericDeath - .4byte GenericConfused - .4byte AcroBandit_OnGrabbed - -gUnk_080CE584:: @ 080CE584 - .4byte sub_08031A88 - .4byte sub_08031E90 - -gUnk_080CE58C:: @ 080CE58C - .4byte sub_08031AA0 - .4byte sub_08031AC8 - .4byte sub_08031B48 - .4byte sub_08031B98 - .4byte sub_08031C1C - .4byte sub_08031C58 - .4byte sub_08031D70 - .4byte sub_08031DA0 - .4byte sub_08031DC4 - -gUnk_080CE5B0:: @ 080CE5B0 - .incbin "acroBandits/gUnk_080CE5B0.bin" - -gUnk_080CE5B8:: @ 080CE5B8 - .incbin "acroBandits/gUnk_080CE5B8.bin" - -gUnk_080CE5C0:: @ 080CE5C0 - .incbin "acroBandits/gUnk_080CE5C0.bin" - -gUnk_080CE5C8:: @ 080CE5C8 - .4byte sub_08031EA8 - .4byte sub_08031EE8 - .4byte sub_08031F54 - .4byte sub_08031FB0 - .4byte sub_08032008 - .4byte sub_08032148 - .4byte sub_08032160 - .4byte sub_080321E8 - .4byte sub_08032204 - .4byte sub_08032248 - -gUnk_080CE5F0:: @ 080CE5F0 - .incbin "acroBandits/gUnk_080CE5F0.bin" - -gUnk_080CE5FA:: @ 080CE5FA - .incbin "acroBandits/gUnk_080CE5FA.bin" diff --git a/linker.ld b/linker.ld index c251d4c7..51a80d79 100644 --- a/linker.ld +++ b/linker.ld @@ -995,7 +995,7 @@ SECTIONS { data/const/enemy/rope.o(.rodata); data/animations/enemy/rope.o(.rodata); data/const/enemy/smallPesto.o(.rodata); - data/const/enemy/acroBandits.o(.rodata); + src/enemy/acroBandits.o(.rodata); data/animations/enemy/acroBandits.o(.rodata); data/const/enemy/keaton.o(.rodata); data/animations/enemy/keaton.o(.rodata); diff --git a/src/enemy/acroBandits.c b/src/enemy/acroBandits.c index 34d0ea7c..9ac33af9 100644 --- a/src/enemy/acroBandits.c +++ b/src/enemy/acroBandits.c @@ -10,15 +10,39 @@ extern Entity* gUnk_020000B0; extern void (*const gUnk_080012C8[])(Entity*); -extern void (*const AcroBandit_Functions[])(Entity*); -extern void (*const gUnk_080CE584[])(Entity*); -extern void (*const gUnk_080CE58C[])(Entity*); -extern void (*const gUnk_080CE5C8[])(Entity*); -extern u8 gUnk_080CE5B0[8]; -extern u8 gUnk_080CE5B8[8]; -extern s8 gUnk_080CE5C0[8]; -extern u16 gUnk_080CE5F0[5]; -extern u8 gUnk_080CE5FA[20]; // Directions + +void AcroBandit_OnTick(Entity* this); +void AcroBandit_OnCollision(Entity* this); +void AcroBandit_OnKnockback(Entity* this); +void GenericDeath(Entity* this); +void GenericConfused(Entity* this); +void AcroBandit_OnGrabbed(Entity* this); +void AcroBandit_Type0(Entity* this); +void AcroBandit_Type1(Entity* this); +void AcroBandit_Type0Action0(Entity* this); +void AcroBandit_Type0Action1(Entity* this); +void AcroBandit_Type0Action2(Entity* this); +void AcroBandit_Type0Action3(Entity* this); +void AcroBandit_Type0Action4(Entity* this); +void AcroBandit_Type0Action5(Entity* this); +void AcroBandit_Type0Action6(Entity* this); +void AcroBandit_Type0Action7(Entity* this); +void AcroBandit_Type0Action8(Entity* this); +void AcroBandit_Type1Init(Entity* this); +void AcroBandit_Type1Action1(Entity* this); +void AcroBandit_Type1Action2(Entity* this); +void AcroBandit_Type1Action3(Entity* this); +void AcroBandit_Type1Action4(Entity* this); +void AcroBandit_Type1Action5(Entity* this); +void AcroBandit_Type1Action6(Entity* this); +void AcroBandit_Type1Action7(Entity* this); +void AcroBandit_Type1Action8(Entity* this); +void AcroBandit_Type1Action9(Entity* this); + +static void (*const AcroBandit_Functions[])(Entity*) = { + AcroBandit_OnTick, AcroBandit_OnCollision, AcroBandit_OnKnockback, + GenericDeath, GenericConfused, AcroBandit_OnGrabbed, +}; void AcroBandit(Entity* this) { s32 index; @@ -37,7 +61,11 @@ void AcroBandit(Entity* this) { } void AcroBandit_OnTick(Entity* this) { - gUnk_080CE584[this->type](this); + static void (*const typeFuncs[])(Entity*) = { + AcroBandit_Type0, + AcroBandit_Type1, + }; + typeFuncs[this->type](this); } void AcroBandit_OnCollision(Entity* this) { @@ -109,25 +137,27 @@ void AcroBandit_OnKnockback(Entity* this) { GenericKnockback(this); } -void AcroBandit_OnGrabbed(void) { - /* ... */ +void AcroBandit_OnGrabbed(Entity* this) { } -void sub_08031A88(Entity* this) { - gUnk_080CE58C[this->action](this); +void AcroBandit_Type0(Entity* this) { + static void (*const actionFuncs[])(Entity*) = { + AcroBandit_Type0Action0, AcroBandit_Type0Action1, AcroBandit_Type0Action2, + AcroBandit_Type0Action3, AcroBandit_Type0Action4, AcroBandit_Type0Action5, + AcroBandit_Type0Action6, AcroBandit_Type0Action7, AcroBandit_Type0Action8, + }; + actionFuncs[this->action](this); } -void sub_08031AA0(Entity* this) { +void AcroBandit_Type0Action0(Entity* this) { sub_0804A720(this); - this->action = '\x01'; + this->action = 1; this->field_0x74.HWORD = this->x.HALF.HI; this->field_0x76.HWORD = this->y.HALF.HI; this->field_0x78.HALF.HI = Random(); } -void sub_08031AC8(Entity* this) - -{ +void AcroBandit_Type0Action1(Entity* this) { u32 rand; s32 x, y; @@ -149,7 +179,8 @@ void sub_08031AC8(Entity* this) } } -void sub_08031B48(Entity* this) { +void AcroBandit_Type0Action2(Entity* this) { + static const u8 actionDelays[] = { 2, 2, 2, 3, 3, 3, 3, 4 }; GetNextFrame(this); if (this->frame & 1) { this->frame = 0; @@ -157,13 +188,13 @@ void sub_08031B48(Entity* this) { } else { if (this->frame & ANIM_DONE) { this->action = 0x3; - this->actionDelay = gUnk_080CE5B0[Random() & 7]; + this->actionDelay = actionDelays[Random() & 7]; InitializeAnimation(this, 1); } } } -void sub_08031B98(Entity* this) { +void AcroBandit_Type0Action3(Entity* this) { if (sub_08031E04(this)) { this->action = 5; if (this->x.HALF.HI > gUnk_020000B0->x.HALF.HI) { @@ -186,21 +217,22 @@ void sub_08031B98(Entity* this) { } } -void sub_08031C1C(Entity* this) { +void AcroBandit_Type0Action4(Entity* this) { + static const u8 actionDelays[] = { 60, 60, 90, 120, 120, 120, 120, 150 }; GetNextFrame(this); if (this->frame & ANIM_DONE) { - this->action = '\x01'; - this->actionDelay = gUnk_080CE5B8[Random() & 7]; + this->action = 1; + this->actionDelay = actionDelays[Random() & 7]; this->spriteSettings.draw = 0; } } -void sub_08031C58(Entity* this) { +void AcroBandit_Type0Action5(Entity* this) { Entity *a, *b; GetNextFrame(this); if (this->frame & ANIM_DONE) { - if (gEntCount < 0x43) { + if (gEntCount < MAX_ENTITIES - 4) { u32 tmp = Random(); tmp &= 3; @@ -252,7 +284,7 @@ void sub_08031C58(Entity* this) { } } -void sub_08031D70(Entity* this) { +void AcroBandit_Type0Action6(Entity* this) { GetNextFrame(this); if (--this->actionDelay == 0) { this->action = 7; @@ -262,7 +294,7 @@ void sub_08031D70(Entity* this) { } } -void sub_08031DA0(Entity* this) { +void AcroBandit_Type0Action7(Entity* this) { if ((this->actionDelay & 0xf) == 0) { if (this->actionDelay == 0x50) { DeleteEntity(this); @@ -273,7 +305,7 @@ void sub_08031DA0(Entity* this) { } } -void sub_08031DC4(Entity* this) { +void AcroBandit_Type0Action8(Entity* this) { if (this->frame & ANIM_DONE) { this->action = 1; this->actionDelay = 0xb4; @@ -287,8 +319,9 @@ void sub_08031DC4(Entity* this) { } u32 sub_08031E04(Entity* this) { + static const s8 gUnk_080CE5C0[] = { -32, 0, 0, 32, 32, 0, 0, 0 }; Entity* ent; - s8* tmp; + const s8* tmp; ent = sub_08049DF4(1); if (ent == NULL) @@ -308,11 +341,16 @@ void sub_08031E48(Entity* this, Entity* child) { child->field_0x7c.WORD = (s32)this; } -void sub_08031E90(Entity* this) { - gUnk_080CE5C8[this->action](this); +void AcroBandit_Type1(Entity* this) { + static void (*const actionFuncs[])(Entity*) = { + AcroBandit_Type1Init, AcroBandit_Type1Action1, AcroBandit_Type1Action2, AcroBandit_Type1Action3, + AcroBandit_Type1Action4, AcroBandit_Type1Action5, AcroBandit_Type1Action6, AcroBandit_Type1Action7, + AcroBandit_Type1Action8, AcroBandit_Type1Action9, + }; + actionFuncs[this->action](this); } -void sub_08031EA8(Entity* this) { +void AcroBandit_Type1Init(Entity* this) { this->action = 1; this->spritePriority.b1 = 1; this->zVelocity = Q_16_16(4.0); @@ -321,7 +359,7 @@ void sub_08031EA8(Entity* this) { InitializeAnimation(this, 4); } -void sub_08031EE8(Entity* this) { +void AcroBandit_Type1Action1(Entity* this) { int draw; this->z.WORD -= this->zVelocity; @@ -346,8 +384,9 @@ void sub_08031EE8(Entity* this) { } } -void sub_08031F54(Entity* this) { - GravityUpdate(this, gUnk_080CE5F0[this->type2]); +void AcroBandit_Type1Action2(Entity* this) { + static const u16 banditGravity[] = { 0x1600, 0x1300, 0x1000, 0xD00, 0xB00 }; + GravityUpdate(this, banditGravity[this->type2]); if (this->type2 * -0xe <= this->z.HALF.HI) { this->action = 3; this->actionDelay = 20; @@ -358,7 +397,7 @@ void sub_08031F54(Entity* this) { } } -void sub_08031FB0(Entity* this) { +void AcroBandit_Type1Action3(Entity* this) { GetNextFrame(this); if ((this->frame & ANIM_DONE) && (this->parent || --this->actionDelay == 0)) { this->action = 4; @@ -372,7 +411,7 @@ void sub_08031FB0(Entity* this) { } } -void sub_08032008(Entity* this) { +void AcroBandit_Type1Action4(Entity* this) { Entity* parent; if (sub_080322A4(this) == 0) { @@ -421,20 +460,22 @@ void sub_08032008(Entity* this) { } } -void sub_08032148(Entity* this) { +void AcroBandit_Type1Action5(Entity* this) { if (GravityUpdate(this, 0x2000)) return; sub_08032290(this); } -void sub_08032160(Entity* this) { +void AcroBandit_Type1Action6(Entity* this) { + static const u8 fallDirections[] = { 0x8, 0x1c, 0x11, 0x2, 0x15, 0xc, 0x0, 0x15, 0x6, 0x19, + 0x10, 0x4, 0x19, 0xa, 0x1d, 0x14, 0x8, 0x1d, 0xe, 0x1 }; Entity* tmp; u32 dir; if (this->actionDelay == 0) { this->action = 7; - dir = gUnk_080CE5FA[this->field_0x74.HALF.LO * 5 + this->type2]; + dir = fallDirections[this->field_0x74.HALF.LO * 5 + this->type2]; this->direction = dir; if (dir >= 0x10) { this->spriteSettings.flipX = 1; @@ -456,14 +497,14 @@ void sub_08032160(Entity* this) { } } -void sub_080321E8(Entity* this) { +void AcroBandit_Type1Action7(Entity* this) { ProcessMovement2(this); if (sub_080044EC(this, 0x2000) == 0) this->action = 8; } -void sub_08032204(Entity* this) { +void AcroBandit_Type1Action8(Entity* this) { GetNextFrame(this); if (this->frame & 1) { this->frame = 0; @@ -476,7 +517,7 @@ void sub_08032204(Entity* this) { } } -void sub_08032248(Entity* this) { +void AcroBandit_Type1Action9(Entity* this) { if (GravityUpdate(this, Q_8_8(24.0)) == 0) { if (this->frame & ANIM_DONE) { ((Entity*)this->field_0x7c.WORD)->actionDelay--;