From e75b0c51f5a0856e03d7c5fd2e16171a982c4e53 Mon Sep 17 00:00:00 2001 From: SonicDcer <96613413+sonicdcer@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:19:20 -0300 Subject: [PATCH] ovl_Bg_Umajump OK (#1050) * all functions matching * data imported * symbols left * Documenting * ovl_Bg_Umajump OK * pr review * pr review * rotationTimer * CS_STATE Enum * params enum * PascalCase and singular * sceneId * pr review * pr review * params macro * enum --- assets/xml/objects/object_umajump.xml | 2 +- spec | 3 +- .../actors/ovl_Bg_Umajump/z_bg_umajump.c | 191 ++++++++++++++++-- .../actors/ovl_Bg_Umajump/z_bg_umajump.h | 24 ++- tools/disasm/functions.txt | 8 +- 5 files changed, 203 insertions(+), 25 deletions(-) diff --git a/assets/xml/objects/object_umajump.xml b/assets/xml/objects/object_umajump.xml index 6d86b4298b..cec43c3a67 100644 --- a/assets/xml/objects/object_umajump.xml +++ b/assets/xml/objects/object_umajump.xml @@ -2,7 +2,7 @@ - + diff --git a/spec b/spec index ab1f8a0442..a59e3f0f44 100644 --- a/spec +++ b/spec @@ -1286,8 +1286,7 @@ beginseg name "ovl_Bg_Umajump" compress include "build/src/overlays/actors/ovl_Bg_Umajump/z_bg_umajump.o" - include "build/data/ovl_Bg_Umajump/ovl_Bg_Umajump.data.o" - include "build/data/ovl_Bg_Umajump/ovl_Bg_Umajump.reloc.o" + include "build/src/overlays/actors/ovl_Bg_Umajump/ovl_Bg_Umajump_reloc.o" endseg beginseg diff --git a/src/overlays/actors/ovl_Bg_Umajump/z_bg_umajump.c b/src/overlays/actors/ovl_Bg_Umajump/z_bg_umajump.c index 894ced5529..2a584bb314 100644 --- a/src/overlays/actors/ovl_Bg_Umajump/z_bg_umajump.c +++ b/src/overlays/actors/ovl_Bg_Umajump/z_bg_umajump.c @@ -5,6 +5,7 @@ */ #include "z_bg_umajump.h" +#include "assets/objects/object_umajump/object_umajump.h" #define FLAGS 0x00000000 @@ -13,8 +14,10 @@ void BgUmajump_Init(Actor* thisx, PlayState* play); void BgUmajump_Destroy(Actor* thisx, PlayState* play); void BgUmajump_Update(Actor* thisx, PlayState* play); +void BgUmajump_Draw(Actor* thisx, PlayState* play); + +void func_8091A5A0(Actor* thisx, PlayState* play); -#if 0 const ActorInit Bg_Umajump_InitVars = { ACTOR_BG_UMAJUMP, ACTORCAT_PROP, @@ -27,34 +30,190 @@ const ActorInit Bg_Umajump_InitVars = { (ActorFunc)NULL, }; -// static InitChainEntry sInitChain[] = { -static InitChainEntry D_8091A810[] = { +static InitChainEntry sInitChain[] = { ICHAIN_F32(uncullZoneScale, 1200, ICHAIN_CONTINUE), ICHAIN_F32(uncullZoneDownward, 300, ICHAIN_CONTINUE), ICHAIN_VEC3F_DIV1000(scale, 100, ICHAIN_STOP), }; -#endif +void func_80919F30(BgUmajump* this, PlayState* play) { + if (this->rotationTimer >= 90) { + this->rotationTimer = 0; + } -extern InitChainEntry D_8091A810[]; + this->rotationTimer++; + this->dyna.actor.shape.yOffset = + Math_SinS((this->rotationTimer / 90.0f) * 0x10000) * (20.0f / this->dyna.actor.scale.y); +} -extern UNK_TYPE D_06001220; -extern UNK_TYPE D_06001558; +void BgUmajump_StopCutscene(BgUmajump* this, PlayState* play) { + if ((play->csCtx.frames >= 6) && !this->hasSoundPlayed) { + this->hasSoundPlayed = true; + play_sound(NA_SE_EV_KID_HORSE_NEIGH); + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Umajump/func_80919F30.s") + if (play->csCtx.state == CS_STATE_0) { + ActorCutscene_Stop(this->dyna.actor.cutscene); + this->dyna.actor.update = Actor_Noop; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Umajump/func_80919FC8.s") +void BgUmajump_PlayCutscene(BgUmajump* this, PlayState* play) { + if (ActorCutscene_GetCanPlayNext(this->dyna.actor.cutscene)) { + ActorCutscene_StartAndSetUnkLinkFields(this->dyna.actor.cutscene, &this->dyna.actor); + gSaveContext.save.weekEventReg[89] |= 0x20; + this->actionFunc = BgUmajump_StopCutscene; + } else { + ActorCutscene_SetIntentToPlay(this->dyna.actor.cutscene); + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Umajump/func_8091A044.s") +void BgUmajump_CheckDistance(BgUmajump* this, PlayState* play) { + Player* player = GET_PLAYER(play); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Umajump/func_8091A0B8.s") + if ((this->horse != NULL) && (player != NULL) && + (Math3D_XZDistance(this->horse->world.pos.x, this->horse->world.pos.z, player->actor.world.pos.x, + player->actor.world.pos.z) < 1400.0f)) { + this->actionFunc = BgUmajump_PlayCutscene; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Umajump/BgUmajump_Init.s") +void BgUmajump_Init(Actor* thisx, PlayState* play) { + BgUmajump* this = THIS; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Umajump/BgUmajump_Destroy.s") + Actor_ProcessInitChain(thisx, sInitChain); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Umajump/BgUmajump_Update.s") + this->actionFunc = NULL; + this->horse = NULL; + this->hasSoundPlayed = false; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Umajump/func_8091A5A0.s") + DynaPolyActor_Init(&this->dyna, 0); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Umajump/func_8091A7B0.s") + this->objectIndex = BG_UMAJUMP_GET_OBJECT_INDEX(thisx); + thisx->params = BG_UMAJUMP_GET_FF(thisx); + + if ((thisx->params == BG_UMAJUMP_TYPE_2)) { + if ((((play->sceneId == SCENE_F01) && !(gSaveContext.save.weekEventReg[89] & 0x20)) && + !CHECK_QUEST_ITEM(QUEST_SONG_EPONA)) && + (thisx->cutscene != -1)) { + this->actionFunc = BgUmajump_CheckDistance; + thisx->update = func_8091A5A0; + thisx->flags |= ACTOR_FLAG_10; + this->horse = SubS_FindActor(play, this->horse, ACTORCAT_BG, ACTOR_EN_HORSE); + } else { + thisx->update = Actor_Noop; + } + } else { + this->objectIndex = Object_GetIndex(&play->objectCtx, OBJECT_UMAJUMP); + + if (this->objectIndex < 0) { + Actor_MarkForDeath(thisx); + } + + if ((thisx->params == BG_UMAJUMP_TYPE_3) && CHECK_QUEST_ITEM(QUEST_SONG_EPONA)) { + Actor_Spawn(&play->actorCtx, play, ACTOR_EN_KANBAN, thisx->world.pos.x, thisx->world.pos.y, + thisx->world.pos.z, thisx->shape.rot.x, thisx->shape.rot.y, thisx->shape.rot.z, 0x3E); + Actor_MarkForDeath(thisx); + } + } +} + +void BgUmajump_Destroy(Actor* thisx, PlayState* play) { + BgUmajump* this = THIS; + + DynaPoly_DeleteBgActor(play, &play->colCtx.dyna, this->dyna.bgId); +} + +void BgUmajump_Update(Actor* thisx, PlayState* play) { + BgUmajump* this = THIS; + + if (Object_IsLoaded(&play->objectCtx, this->objectIndex)) { + this->dyna.actor.objBankIndex = this->objectIndex; + this->dyna.actor.draw = BgUmajump_Draw; + + Actor_SetObjectDependency(play, &this->dyna.actor); + + if (this->dyna.actor.params == BG_UMAJUMP_TYPE_5) { + if (gSaveContext.save.weekEventReg[22] & 1) { + DynaPolyActor_LoadMesh(play, &this->dyna, &object_umajump_Colheader_001558); + } + } else if (this->dyna.actor.params == BG_UMAJUMP_TYPE_6) { + if (!(gSaveContext.save.weekEventReg[22] & 1)) { + DynaPolyActor_LoadMesh(play, &this->dyna, &object_umajump_Colheader_001558); + } + } else if ((this->dyna.actor.params == BG_UMAJUMP_TYPE_4) || (this->dyna.actor.params == BG_UMAJUMP_TYPE_3)) { + DynaPolyActor_LoadMesh(play, &this->dyna, &object_umajump_Colheader_001558); + } else { + DynaPolyActor_LoadMesh(play, &this->dyna, &object_umajump_Colheader_001438); + } + + if (this->dyna.actor.params == BG_UMAJUMP_TYPE_1) { + this->rotationTimer = 0; + this->actionFunc = func_80919F30; + this->dyna.actor.update = func_8091A5A0; + } else if (this->dyna.actor.params == BG_UMAJUMP_TYPE_3) { + this->dyna.actor.update = func_8091A5A0; + } else if ((this->dyna.actor.params == BG_UMAJUMP_TYPE_5) || (this->dyna.actor.params == BG_UMAJUMP_TYPE_6)) { + if (this->dyna.actor.params == BG_UMAJUMP_TYPE_5) { + if ((this->dyna.bgId == BGACTOR_NEG_ONE) && (gSaveContext.save.weekEventReg[22] & 1)) { + DynaPolyActor_LoadMesh(play, &this->dyna, &object_umajump_Colheader_001558); + } + } else if ((this->dyna.actor.params == BG_UMAJUMP_TYPE_6) && (this->dyna.bgId == BGACTOR_NEG_ONE) && + (!(gSaveContext.save.weekEventReg[22] & 1) || + ((gSaveContext.save.day == 2) && (gSaveContext.save.isNight == true) && + ((gSaveContext.save.time >= CLOCK_TIME(5, 30)) && + (gSaveContext.save.time <= CLOCK_TIME(6, 0)))))) { + DynaPolyActor_LoadMesh(play, &this->dyna, &object_umajump_Colheader_001558); + } + func_800C641C(play, &play->colCtx.dyna, this->dyna.bgId); + this->dyna.actor.update = func_8091A5A0; + } else if (this->dyna.actor.params == BG_UMAJUMP_TYPE_4) { + func_800C641C(play, &play->colCtx.dyna, this->dyna.bgId); + this->dyna.actor.update = Actor_Noop; + } else { + this->dyna.actor.update = Actor_Noop; + } + } +} + +void func_8091A5A0(Actor* thisx, PlayState* play) { + BgUmajump* this = THIS; + + if (this->actionFunc != NULL) { + this->actionFunc(this, play); + } + + if ((this->dyna.actor.params == BG_UMAJUMP_TYPE_3) && CHECK_QUEST_ITEM(QUEST_SONG_EPONA)) { + Actor_Spawn(&play->actorCtx, play, ACTOR_EN_KANBAN, this->dyna.actor.world.pos.x, this->dyna.actor.world.pos.y, + this->dyna.actor.world.pos.z, this->dyna.actor.shape.rot.x, this->dyna.actor.shape.rot.y, + this->dyna.actor.shape.rot.z, 0x3E); + Actor_MarkForDeath(&this->dyna.actor); + } + + if (this->dyna.actor.params == BG_UMAJUMP_TYPE_5) { + if ((this->dyna.bgId == BGACTOR_NEG_ONE) && (gSaveContext.save.weekEventReg[22] & 1)) { + DynaPolyActor_LoadMesh(play, &this->dyna, &object_umajump_Colheader_001558); + } else if ((this->dyna.bgId != BGACTOR_NEG_ONE) && !(gSaveContext.save.weekEventReg[22] & 1)) { + DynaPoly_DeleteBgActor(play, &play->colCtx.dyna, this->dyna.bgId); + } + } else if (this->dyna.actor.params == BG_UMAJUMP_TYPE_6) { + if ((this->dyna.bgId == BGACTOR_NEG_ONE) && + (!(gSaveContext.save.weekEventReg[22] & 1) || + ((gSaveContext.save.day == 2) && (gSaveContext.save.isNight == true) && + (gSaveContext.save.time >= CLOCK_TIME(5, 30)) && (gSaveContext.save.time <= CLOCK_TIME(6, 0))))) { + DynaPolyActor_LoadMesh(play, &this->dyna, &object_umajump_Colheader_001558); + } else if ((this->dyna.bgId != BGACTOR_NEG_ONE) && (gSaveContext.save.weekEventReg[22] & 1) && + ((gSaveContext.save.day != 2) || (gSaveContext.save.isNight != true) || + (gSaveContext.save.time < CLOCK_TIME(5, 30)) || (gSaveContext.save.time > CLOCK_TIME(6, 0)))) { + DynaPoly_DeleteBgActor(play, &play->colCtx.dyna, this->dyna.bgId); + } + } +} + +void BgUmajump_Draw(Actor* thisx, PlayState* play) { + BgUmajump* this = THIS; + + if (this->dyna.bgId != BGACTOR_NEG_ONE) { + Gfx_DrawDListOpa(play, gHorseJumpFenceDL); + } +} diff --git a/src/overlays/actors/ovl_Bg_Umajump/z_bg_umajump.h b/src/overlays/actors/ovl_Bg_Umajump/z_bg_umajump.h index 22fe9ca44f..733bf77da3 100644 --- a/src/overlays/actors/ovl_Bg_Umajump/z_bg_umajump.h +++ b/src/overlays/actors/ovl_Bg_Umajump/z_bg_umajump.h @@ -3,11 +3,31 @@ #include "global.h" +#define BG_UMAJUMP_GET_OBJECT_INDEX(thisx) (((thisx)->params >> 8) & 0xFF) +#define BG_UMAJUMP_GET_FF(thisx) ((thisx)->params & 0xFF) + +typedef enum { + BG_UMAJUMP_TYPE_1 = 1, + BG_UMAJUMP_TYPE_2, + BG_UMAJUMP_TYPE_3, + BG_UMAJUMP_TYPE_4, + BG_UMAJUMP_TYPE_5, + BG_UMAJUMP_TYPE_6, +} BgUmaJumpType; + struct BgUmajump; +typedef void (*BgUmajumpActionFunc)(struct BgUmajump*, PlayState*); + typedef struct BgUmajump { - /* 0x000 */ Actor actor; - /* 0x144 */ char unk_144[0x28]; + /* 0x000 */ DynaPolyActor dyna; + /* 0x15C */ BgUmajumpActionFunc actionFunc; + /* 0x160 */ union { + s32 objectIndex; + s32 rotationTimer; // y rotation + }; + /* 0x164 */ s32 hasSoundPlayed; + /* 0x168 */ Actor* horse; } BgUmajump; // size = 0x16C extern const ActorInit Bg_Umajump_InitVars; diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 6589629f1a..5746355b33 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -6903,14 +6903,14 @@ 0x809199FC:("func_809199FC",), 0x80919D68:("EffDust_Draw",), 0x80919F30:("func_80919F30",), - 0x80919FC8:("func_80919FC8",), - 0x8091A044:("func_8091A044",), - 0x8091A0B8:("func_8091A0B8",), + 0x80919FC8:("BgUmajump_StopCutscene",), + 0x8091A044:("BgUmajump_PlayCutscene",), + 0x8091A0B8:("BgUmajump_CheckDistance",), 0x8091A124:("BgUmajump_Init",), 0x8091A2D8:("BgUmajump_Destroy",), 0x8091A30C:("BgUmajump_Update",), 0x8091A5A0:("func_8091A5A0",), - 0x8091A7B0:("func_8091A7B0",), + 0x8091A7B0:("BgUmajump_Draw",), 0x8091A8A0:("func_8091A8A0",), 0x8091A8C4:("EnInsect_XZDistanceSquared",), 0x8091A8F4:("EnInsect_InBottleRange",),