From 6842a065f0d82ebdcb51834e621f0ceff4bb6766 Mon Sep 17 00:00:00 2001 From: Lucas <60241136+ordlucas@users.noreply.github.com> Date: Fri, 21 Oct 2022 17:44:20 -0500 Subject: [PATCH] ovl_En_Encount4 OK (#989) * `ovl_En_Encount4` decompiled * Style changes * Suggested changes * Suggested changes * Formatting * review * review Co-authored-by: EllipticEllipsis * a Co-authored-by: angie Co-authored-by: EllipticEllipsis --- spec | 3 +- .../actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.c | 2 +- .../actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.h | 5 + src/overlays/actors/ovl_En_Bsb/z_en_bsb.h | 4 +- .../actors/ovl_En_Encount4/z_en_encount4.c | 179 +++++++++++++++++- .../actors/ovl_En_Encount4/z_en_encount4.h | 21 +- src/overlays/actors/ovl_En_Skb/z_en_skb.h | 4 + 7 files changed, 197 insertions(+), 21 deletions(-) diff --git a/spec b/spec index 2c24f80550..9441dc0112 100644 --- a/spec +++ b/spec @@ -2268,8 +2268,7 @@ beginseg name "ovl_En_Encount4" compress include "build/src/overlays/actors/ovl_En_Encount4/z_en_encount4.o" - include "build/data/ovl_En_Encount4/ovl_En_Encount4.data.o" - include "build/data/ovl_En_Encount4/ovl_En_Encount4.reloc.o" + include "build/src/overlays/actors/ovl_En_Encount4/ovl_En_Encount4_reloc.o" endseg beginseg diff --git a/src/overlays/actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.c b/src/overlays/actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.c index 63563f5f00..40b8c78a7f 100644 --- a/src/overlays/actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.c +++ b/src/overlays/actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.c @@ -193,7 +193,7 @@ void BgFireWall_Update(Actor* thisx, PlayState* play2) { if (this->actionFunc != func_809AC970) { if (this->actor.parent != NULL) { EnEncount4* parent = (EnEncount4*)this->actor.parent; - if ((parent->actor.update != NULL) && (parent->unk_150 != 0)) { + if ((parent->actor.update != NULL) && (parent->timer != 0)) { this->actionFunc = func_809AC970; } } diff --git a/src/overlays/actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.h b/src/overlays/actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.h index 3c8eb19826..af5a299235 100644 --- a/src/overlays/actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.h +++ b/src/overlays/actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.h @@ -7,6 +7,11 @@ struct BgFireWall; typedef void (*BgFireWallActionFunc)(struct BgFireWall*, PlayState*); +typedef enum { + /* 0 */ BGFIREWALL_PARAMS_0, + /* 1 */ BGFIREWALL_PARAMS_1, +} BgFireWallParams; + typedef struct BgFireWall { /* 0x000 */ Actor actor; /* 0x144 */ BgFireWallActionFunc actionFunc; diff --git a/src/overlays/actors/ovl_En_Bsb/z_en_bsb.h b/src/overlays/actors/ovl_En_Bsb/z_en_bsb.h index d2f67c008e..f3cd4b7d64 100644 --- a/src/overlays/actors/ovl_En_Bsb/z_en_bsb.h +++ b/src/overlays/actors/ovl_En_Bsb/z_en_bsb.h @@ -11,7 +11,9 @@ typedef struct EnBsb { /* 0x0000 */ Actor actor; /* 0x0144 */ char unk_144[0x140]; /* 0x0284 */ EnBsbActionFunc actionFunc; - /* 0x0288 */ char unk_288[0xED0]; + /* 0x0288 */ char unk_288[0x54]; + /* 0x02DC */ s32 unk2DC; + /* 0x02E0 */ char unk2E0[0xE78]; } EnBsb; // size = 0x1158 #endif // Z_EN_BSB_H diff --git a/src/overlays/actors/ovl_En_Encount4/z_en_encount4.c b/src/overlays/actors/ovl_En_Encount4/z_en_encount4.c index 69fa6bf09c..ccb9d16b5a 100644 --- a/src/overlays/actors/ovl_En_Encount4/z_en_encount4.c +++ b/src/overlays/actors/ovl_En_Encount4/z_en_encount4.c @@ -20,7 +20,6 @@ void func_809C42A8(EnEncount4* this, PlayState* play); void func_809C4598(EnEncount4* this, PlayState* play); void func_809C464C(EnEncount4* this, PlayState* play); -#if 0 ActorInit En_Encount4_InitVars = { ACTOR_EN_ENCOUNT4, ACTORCAT_PROP, @@ -33,20 +32,180 @@ ActorInit En_Encount4_InitVars = { (ActorFunc)NULL, }; -#endif +s16 D_809C46D0[] = { + 0x4000, 0xC000, 0x4000, 0, 0xC000, +}; +f32 D_809C46DC[] = { + 200.0f, 200.0f, 100.0f, 0.0f, 100.0f, +}; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Encount4/EnEncount4_Init.s") +void EnEncount4_Init(Actor* thisx, PlayState* play) { + s32 pad; + EnEncount4* this = THIS; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Encount4/EnEncount4_Destroy.s") + this->unk_148 = ENENCOUNT4_GET_F000(thisx); + this->switchFlag = ENENCOUNT4_GET_FLAG(thisx); + if (this->switchFlag == 0x7F) { + this->switchFlag = -1; + } + if ((this->switchFlag >= 0) && Flags_GetSwitch(play, this->switchFlag)) { + Actor_Kill(&this->actor); + return; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Encount4/func_809C3FD8.s") + this->actor.flags &= ~ACTOR_FLAG_1; + this->actionFunc = func_809C3FD8; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Encount4/func_809C4078.s") +void EnEncount4_Destroy(Actor* thisx, PlayState* play) { +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Encount4/func_809C42A8.s") +void func_809C3FD8(EnEncount4* this, PlayState* play) { + Actor* actor; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Encount4/func_809C4598.s") + this->unk_14E = 0; + if ((this->switchFlag >= 0) && Flags_GetSwitch(play, this->switchFlag)) { + this->timer = 100; + this->actionFunc = func_809C464C; + } else { + actor = play->actorCtx.actorLists[ACTORCAT_BOSS].first; + while (actor != NULL) { + if (actor->id != ACTOR_EN_BSB) { + actor = actor->next; + } else { + this->captainKeeta = (EnBsb*)actor; + this->actionFunc = func_809C4078; + break; + } + } + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Encount4/func_809C464C.s") +void func_809C4078(EnEncount4* this, PlayState* play) { + s16 rotY; + Vec3f pos; + s32 fireWallParams; + s32 i; + EnBsb* captainKeeta = this->captainKeeta; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Encount4/EnEncount4_Update.s") + if ((this->switchFlag >= 0) && Flags_GetSwitch(play, this->switchFlag)) { + this->timer = 100; + this->actionFunc = func_809C464C; + } else if (BREG(1) == 0) { + if ((this->captainKeeta->actor.id != ACTOR_EN_BSB) || (captainKeeta->actor.update == NULL)) { + Actor_Kill(&this->actor); + return; + } + + if ((this->unk_148 != 0) || (this->actor.xzDistToPlayer < 240.0f)) { + if ((this->unk_148 == 0) && (captainKeeta->unk2DC != 0)) { + Actor_Kill(&this->actor); + return; + } + + fireWallParams = BGFIREWALL_PARAMS_0; + if ((this->unk_148 == 0) || (captainKeeta->unk2DC != 0)) { + i = 0; + if (this->unk_148 != 0) { + fireWallParams = BGFIREWALL_PARAMS_1; + i = 2; + } + while (i < ARRAY_COUNT(D_809C46DC)) { + rotY = D_809C46D0[i] + this->actor.world.rot.y; + pos.x = Math_SinS(rotY) * D_809C46DC[i] + this->actor.world.pos.x; + pos.y = this->actor.world.pos.y; + pos.z = Math_CosS(rotY) * D_809C46DC[i] + this->actor.world.pos.z; + Actor_SpawnAsChild(&play->actorCtx, &this->actor, play, ACTOR_BG_FIRE_WALL, pos.x, pos.y, pos.z, 0, + this->actor.world.rot.y, 0, fireWallParams); + i++; + } + this->actionFunc = func_809C42A8; + } + } + } +} + +void func_809C42A8(EnEncount4* this, PlayState* play) { + Player* actor = GET_PLAYER(play); + EnBsb* captainKeeta = this->captainKeeta; + Vec3f pos; + f32 yIntersect; + s16 yRot; + CollisionPoly* colPoly; + s32 bgId; + + if ((this->switchFlag >= 0) && (Flags_GetSwitch(play, this->switchFlag))) { + this->timer = 100; + this->actionFunc = func_809C464C; + + return; + } + + if (this->unk_148 == 1) { + if ((this->captainKeeta->actor.id != ACTOR_EN_BSB) || (captainKeeta->actor.update == NULL)) { + Actor_Kill(&this->actor); + } + + return; + } else if (this->unk_14E >= 2) { + this->timer = 100; + this->actionFunc = func_809C464C; + + return; + } else if ((gSaveContext.save.weekEventReg[85] & 0x40) || (this->unk_14C >= 2) || + (this->actor.xzDistToPlayer > 240.0f)) { + return; + } + + pos.x = (Math_SinS(this->actor.world.rot.y) * 30.0f) + this->actor.world.pos.x; + pos.y = actor->actor.floorHeight + 120.0f; + pos.z = (Math_CosS(this->actor.world.rot.y) * 30.0f) + this->actor.world.pos.z; + yIntersect = BgCheck_EntityRaycastFloor5(&play->colCtx, &colPoly, &bgId, &this->actor, &pos); + if ((yIntersect <= BGCHECK_Y_MIN) || ((actor->actor.depthInWater != BGCHECK_Y_MIN) && + (yIntersect < (actor->actor.world.pos.y - actor->actor.depthInWater)))) { + return; + } + + pos.y = yIntersect; + yRot = (s32)Rand_ZeroFloat(512.0f) + this->actor.world.rot.y + 0x3800; + if (this->unk_14C != 0) { + yRot += 0x8000; + } + pos.x += Math_SinS(yRot) * (40.0f + randPlusMinusPoint5Scaled(40.0f)); + pos.z += Math_CosS(yRot) * (40.0f + randPlusMinusPoint5Scaled(40.0f)); + if (Actor_SpawnAsChild(&play->actorCtx, &this->actor, play, ACTOR_EN_SKB, pos.x, pos.y, pos.z, 0, 0, 0, + ENSKB_PARAMS_0) != NULL) { + this->unk_14C++; + if (this->unk_14C >= 2) { + this->actionFunc = func_809C4598; + } + } +} + +void func_809C4598(EnEncount4* this, PlayState* play) { + if ((this->switchFlag >= 0) && Flags_GetSwitch(play, this->switchFlag)) { + this->timer = 100; + this->actionFunc = func_809C464C; + } else if (this->unk_14E >= 2) { + this->timer = 100; + if (this->switchFlag >= 0) { + Flags_SetSwitch(play, this->switchFlag); + } + this->actionFunc = func_809C464C; + } else if (this->unk_14C == 0) { + this->actionFunc = func_809C42A8; + } +} + +void func_809C464C(EnEncount4* this, PlayState* play) { + if (this->timer == 0) { + Actor_Kill(&this->actor); + } +} + +void EnEncount4_Update(Actor* thisx, PlayState* play) { + EnEncount4* this = THIS; + + DECR(this->timer); + this->actionFunc(this, play); +} diff --git a/src/overlays/actors/ovl_En_Encount4/z_en_encount4.h b/src/overlays/actors/ovl_En_Encount4/z_en_encount4.h index 63df20f656..a692f796a9 100644 --- a/src/overlays/actors/ovl_En_Encount4/z_en_encount4.h +++ b/src/overlays/actors/ovl_En_Encount4/z_en_encount4.h @@ -2,19 +2,26 @@ #define Z_EN_ENCOUNT4_H #include "global.h" +#include "overlays/actors/ovl_Bg_Fire_Wall/z_bg_fire_wall.h" +#include "overlays/actors/ovl_En_Bsb/z_en_bsb.h" +#include "overlays/actors/ovl_En_Skb/z_en_skb.h" struct EnEncount4; typedef void (*EnEncount4ActionFunc)(struct EnEncount4*, PlayState*); +#define ENENCOUNT4_GET_FLAG(thisx) ((thisx)->params & 0x7F) +#define ENENCOUNT4_GET_F000(thisx) (((thisx)->params >> 0xC) & 0xF) + typedef struct EnEncount4 { - /* 0x0000 */ Actor actor; - /* 0x0144 */ EnEncount4ActionFunc actionFunc; - /* 0x0148 */ char unk_148[0x4]; - /* 0x014C */ s16 unk_14C; - /* 0x014E */ s16 unk_14E; - /* 0x0150 */ s16 unk_150; - /* 0x0152 */ char unk_152[0x6]; + /* 0x000 */ Actor actor; + /* 0x144 */ EnEncount4ActionFunc actionFunc; + /* 0x148 */ s16 unk_148; + /* 0x14A */ s16 switchFlag; + /* 0x14C */ s16 unk_14C; + /* 0x14E */ s16 unk_14E; + /* 0x150 */ s16 timer; + /* 0x154 */ EnBsb* captainKeeta; } EnEncount4; // size = 0x158 #endif // Z_EN_ENCOUNT4_H diff --git a/src/overlays/actors/ovl_En_Skb/z_en_skb.h b/src/overlays/actors/ovl_En_Skb/z_en_skb.h index ebdad3cd88..1fbf441ea0 100644 --- a/src/overlays/actors/ovl_En_Skb/z_en_skb.h +++ b/src/overlays/actors/ovl_En_Skb/z_en_skb.h @@ -9,6 +9,10 @@ typedef void (*EnSkbActionFunc)(struct EnSkb*, PlayState*); #define ENSKB_GET_F0(thisx) (((thisx)->params >> 4) & 0xF) +typedef enum { + /* 0 */ ENSKB_PARAMS_0, +} EnSkbParams; + typedef struct EnSkb { /* 0x000 */ Actor actor; /* 0x144 */ SkelAnime skelAnime;