From 2df51868ddb4867974bceff4355e71bf96852d67 Mon Sep 17 00:00:00 2001 From: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Date: Tue, 29 Jun 2021 00:36:46 +0100 Subject: [PATCH] BgIcicle OK and mostly documented (#180) * remove ZAPD submodule * git subrepo clone https://github.com/zeldaret/ZAPD.git tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "ca229f19" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "ca229f19" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * git subrepo clone https://github.com/simonlindholm/decomp-permuter.git tools/decomp-permuter subrepo: subdir: "tools/decomp-permuter" merged: "1e4b85a7" upstream: origin: "https://github.com/simonlindholm/decomp-permuter.git" branch: "main" commit: "1e4b85a7" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * Remove asm-differ * git subrepo clone https://github.com/simonlindholm/asm-differ.git tools/asm-differ subrepo: subdir: "tools/asm-differ" merged: "eaf72269" upstream: origin: "https://github.com/simonlindholm/asm-differ.git" branch: "master" commit: "eaf72269" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * remove asm-processor * git subrepo clone https://github.com/simonlindholm/asm-processor.git tools/asm-processor subrepo: subdir: "tools/asm-processor" merged: "85288fcd" upstream: origin: "https://github.com/simonlindholm/asm-processor.git" branch: "master" commit: "85288fcd" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * remove .gitmodules file * Update REAMDE * OK * Import data * Begin naming * Delete asm references * Main type enum * Rename in functions.txt * Review changes Co-authored-by: angie --- linker_scripts/code_script.txt | 4 +- linker_scripts/object_script.txt | 4 + .../actors/ovl_Bg_Icicle/z_bg_icicle.c | 229 +++++++++++++++++- .../actors/ovl_Bg_Icicle/z_bg_icicle.h | 17 +- tables/functions.txt | 14 +- 5 files changed, 244 insertions(+), 24 deletions(-) diff --git a/linker_scripts/code_script.txt b/linker_scripts/code_script.txt index c53ea2b2cf..8afb1b698d 100644 --- a/linker_scripts/code_script.txt +++ b/linker_scripts/code_script.txt @@ -3889,9 +3889,9 @@ SECTIONS ovl_Bg_Icicle : AT(RomLocation) { build/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.o(.text) - build/asm/overlays/ovl_Bg_Icicle_data.o(.data) + build/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.o(.data) build/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.o(.rodata) - build/asm/overlays/ovl_Bg_Icicle_rodata.o(.rodata) + build/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle_overlay.o(.ovl) } SegmentEnd = .; SegmentSize = SegmentEnd - SegmentStart; diff --git a/linker_scripts/object_script.txt b/linker_scripts/object_script.txt index 5d0de996d5..2825a0e932 100644 --- a/linker_scripts/object_script.txt +++ b/linker_scripts/object_script.txt @@ -490,6 +490,10 @@ D_06001C60 = 0x06001C60; D_06000D78 = 0x06000D78; D_06000C80 = 0x06000C80; +/* z_bg_icicle */ +D_060000D0 = 0x060000D0; +D_06000294 = 0x06000294; + /* z_obj_ghaka */ D_06001A20 = 0x06001A20; D_06001980 = 0x06001980; diff --git a/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c b/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c index bc0decc6d4..557f90e97b 100644 --- a/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c +++ b/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c @@ -1,3 +1,9 @@ +/* + * File: z_bg_icicle.c + * Overlay: ovl_Bg_Icicle + * Description: Icicles + */ + #include "z_bg_icicle.h" #define FLAGS 0x00000000 @@ -9,7 +15,32 @@ void BgIcicle_Destroy(Actor* thisx, GlobalContext* globalCtx); void BgIcicle_Update(Actor* thisx, GlobalContext* globalCtx); void BgIcicle_Draw(Actor* thisx, GlobalContext* globalCtx); -/* +void BgIcicle_DoNothing(BgIcicle* this, GlobalContext* globalCtx); +void BgIcicle_Wait(BgIcicle* this, GlobalContext* globalCtx); +void BgIcicle_Shiver(BgIcicle* this, GlobalContext* globalCtx); +void BgIcicle_Fall(BgIcicle* this, GlobalContext* globalCtx); +void BgIcicle_Regrow(BgIcicle* this, GlobalContext* globalCtx); + +static ColliderCylinderInit sCylinderInit = { + { + COLTYPE_NONE, + AT_ON | AT_TYPE_ENEMY, + AC_ON | AC_TYPE_PLAYER, + OC1_NONE, + OC2_TYPE_2, + COLSHAPE_CYLINDER, + }, + { + ELEMTYPE_UNK0, + { 0xF7CFFFFF, 0x00, 0x04 }, + { 0xF7CFFFFF, 0x00, 0x00 }, + TOUCH_ON | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { 13, 120, 0, { 0, 0, 0 } }, +}; + const ActorInit Bg_Icicle_InitVars = { ACTOR_BG_ICICLE, ACTORCAT_PROP, @@ -21,26 +52,198 @@ const ActorInit Bg_Icicle_InitVars = { (ActorFunc)BgIcicle_Update, (ActorFunc)BgIcicle_Draw, }; -*/ -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/BgIcicle_Init.asm") +static InitChainEntry sInitChain[] = { + ICHAIN_F32(uncullZoneScale, 1500, ICHAIN_CONTINUE), + ICHAIN_F32(gravity, -3, ICHAIN_CONTINUE), + ICHAIN_F32(minVelocityY, -30, ICHAIN_CONTINUE), + ICHAIN_VEC3F_DIV1000(scale, 100, ICHAIN_STOP), +}; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/BgIcicle_Destroy.asm") +extern Gfx D_060000D0[]; +extern CollisionHeader D_06000294; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/func_809C9B9C.asm") +void BgIcicle_Init(Actor* thisx, GlobalContext* globalCtx) { + s32 pad; + BgIcicle* this = THIS; + s32 paramsHigh; + s32 paramsMid; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/func_809C9D7C.asm") + Actor_ProcessInitChain(thisx, sInitChain); + BcCheck3_BgActorInit(&this->dyna, 0); + BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000294); -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/func_809C9D8C.asm") + Collider_InitAndSetCylinder(globalCtx, &this->collider, thisx, &sCylinderInit); + Collider_UpdateCylinder(thisx, &this->collider); -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/func_809C9DC4.asm") + paramsHigh = (thisx->params >> 8) & 0xFF; + paramsMid = (thisx->params >> 2) & 0x3F; + this->unk_161 = (thisx->params >> 8) & 0xFF; + thisx->params = thisx->params & 3; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/func_809C9F28.asm") + if (thisx->params == ICICLE_STALAGMITE_RANDOM_DROP || thisx->params == ICICLE_STALAGMITE_FIXED_DROP) { + this->unk_160 = ((thisx->params == ICICLE_STALAGMITE_RANDOM_DROP) ? paramsHigh : paramsMid); + this->actionFunc = BgIcicle_DoNothing; + } else { + this->dyna.actor.shape.rot.x = -0x8000; + this->dyna.actor.shape.yOffset = 1200.0f; + this->actionFunc = BgIcicle_Wait; + } +} -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/func_809CA06C.asm") +void BgIcicle_Destroy(Actor* thisx, GlobalContext* globalCtx) { + BgIcicle* this = THIS; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/func_809CA0BC.asm") + BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + Collider_DestroyCylinder(globalCtx, &this->collider); +} -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/BgIcicle_Update.asm") +void BgIcicle_Break(BgIcicle* this, GlobalContext* globalCtx, f32 arg2) { + static Vec3f accel = { 0.0f, -1.0f, 0.0f }; + static Color_RGBA8 primColor = { 170, 255, 255, 255 }; + static Color_RGBA8 envColor = { 0, 50, 100, 255 }; + Vec3f velocity; + Vec3f pos; + s32 j; + s32 i; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_Bg_Icicle_0x809C9A60/BgIcicle_Draw.asm") + func_800F0568(globalCtx, &this->dyna.actor.world.pos, 30, NA_SE_EV_ICE_BROKEN); + + for (i = 0; i < 2; i++) { + for (j = 0; j < 10; j++) { + pos.x = this->dyna.actor.world.pos.x + randPlusMinusPoint5Scaled(8.0f); + pos.y = this->dyna.actor.world.pos.y + (Rand_ZeroOne() * arg2) + (i * arg2); + pos.z = this->dyna.actor.world.pos.z + randPlusMinusPoint5Scaled(8.0f); + + velocity.x = randPlusMinusPoint5Scaled(7.0f); + velocity.z = randPlusMinusPoint5Scaled(7.0f); + velocity.y = (Rand_ZeroOne() * 4.0f) + 8.0f; + + EffectSsEnIce_Spawn(globalCtx, &pos, (Rand_ZeroOne() * 0.2f) + 0.1f, &velocity, &accel, &primColor, + &envColor, 30); + } + } +} + +void BgIcicle_DoNothing(BgIcicle* this, GlobalContext* globalCtx) { +} + +void BgIcicle_Wait(BgIcicle* this, GlobalContext* globalCtx) { + if (this->dyna.actor.xzDistToPlayer < 60.0f) { + this->shiverTimer = 10; + this->actionFunc = BgIcicle_Shiver; + } +} + +void BgIcicle_Shiver(BgIcicle* this, GlobalContext* globalCtx) { + s32 randSign; + f32 rand; + + if (this->shiverTimer != 0) { + this->shiverTimer--; + } + + if (!(this->shiverTimer % 4)) { + Audio_PlayActorSound2(&this->dyna.actor, NA_SE_EV_ICE_SWING); + } + + if (this->shiverTimer == 0) { + this->dyna.actor.world.pos.x = this->dyna.actor.home.pos.x; + this->dyna.actor.world.pos.z = this->dyna.actor.home.pos.z; + + CollisionCheck_SetAT(globalCtx, &globalCtx->colCheckCtx, &this->collider.base); + func_800C62BC(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + this->actionFunc = BgIcicle_Fall; + } else { + rand = Rand_ZeroOne(); + randSign = (Rand_ZeroOne() < 0.5f ? -1 : 1); + this->dyna.actor.world.pos.x = (randSign * ((0.5f * rand) + 0.5f)) + this->dyna.actor.home.pos.x; + rand = Rand_ZeroOne(); + randSign = (Rand_ZeroOne() < 0.5f ? -1 : 1); + this->dyna.actor.world.pos.z = (randSign * ((0.5f * rand) + 0.5f)) + this->dyna.actor.home.pos.z; + } +} + +void BgIcicle_Fall(BgIcicle* this, GlobalContext* globalCtx) { + if ((this->collider.base.atFlags & 2) || (this->dyna.actor.bgCheckFlags & 1)) { + this->collider.base.atFlags &= ~2; + this->dyna.actor.bgCheckFlags &= ~1; + + if (this->dyna.actor.world.pos.y < this->dyna.actor.floorHeight) { + this->dyna.actor.world.pos.y = this->dyna.actor.floorHeight; + } + + BgIcicle_Break(this, globalCtx, 40.0f); + + if (this->dyna.actor.params == ICICLE_STALACTITE_REGROW) { + this->dyna.actor.world.pos.y = this->dyna.actor.home.pos.y + 120.0f; + func_800C6314(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + this->actionFunc = BgIcicle_Regrow; + } else { + Actor_MarkForDeath(&this->dyna.actor); + return; + } + } else { + Actor_SetVelocityAndMoveYRotationAndGravity(&this->dyna.actor); + this->dyna.actor.world.pos.y += 40.0f; + func_800B78B8(globalCtx, &this->dyna.actor, 0.0f, 0.0f, 0.0f, 4); + this->dyna.actor.world.pos.y -= 40.0f; + CollisionCheck_SetAT(globalCtx, &globalCtx->colCheckCtx, &this->collider.base); + } +} + +void BgIcicle_Regrow(BgIcicle* this, GlobalContext* globalCtx) { + if (Math_StepToF(&this->dyna.actor.world.pos.y, this->dyna.actor.home.pos.y, 1.0f)) { + this->actionFunc = BgIcicle_Wait; + this->dyna.actor.velocity.y = 0.0f; + } +} + +void BgIcicle_UpdateAttacked(BgIcicle* this, GlobalContext* globalCtx) { + s32 sp24; + + if (this->collider.base.acFlags & 2) { + this->collider.base.acFlags &= ~2; + + if (this->dyna.actor.params == ICICLE_STALAGMITE_RANDOM_DROP) { + BgIcicle_Break(this, globalCtx, 50.0f); + + if (this->unk_160 != 0xFF) { + Item_DropCollectibleRandom(globalCtx, NULL, &this->dyna.actor.world.pos, this->unk_160 << 4); + } + } else if (this->dyna.actor.params == ICICLE_STALAGMITE_FIXED_DROP) { + sp24 = func_800A8150(this->unk_160); + BgIcicle_Break(this, globalCtx, 50.0f); + Item_DropCollectible(globalCtx, &this->dyna.actor.world.pos, (this->unk_161 << 8) | sp24); + } else { + if (this->dyna.actor.params == ICICLE_STALACTITE_REGROW) { + BgIcicle_Break(this, globalCtx, 40.0f); + this->dyna.actor.world.pos.y = this->dyna.actor.home.pos.y + 120.0f; + func_800C6314(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + this->actionFunc = BgIcicle_Regrow; + return; + } + + BgIcicle_Break(this, globalCtx, 40.0f); + } + + Actor_MarkForDeath(&this->dyna.actor); + } +} + +void BgIcicle_Update(Actor* thisx, GlobalContext* globalCtx) { + s32 pad; + BgIcicle* this = THIS; + + BgIcicle_UpdateAttacked(this, globalCtx); + this->actionFunc(this, globalCtx); + + if (this->actionFunc != BgIcicle_Regrow) { + Collider_UpdateCylinder(&this->dyna.actor, &this->collider); + CollisionCheck_SetAC(globalCtx, &globalCtx->colCheckCtx, &this->collider.base); + } +} + +void BgIcicle_Draw(Actor* thisx, GlobalContext* globalCtx) { + func_800BDFC0(globalCtx, D_060000D0); +} diff --git a/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.h b/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.h index fea19d1573..9b5a316c9c 100644 --- a/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.h +++ b/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.h @@ -5,9 +5,22 @@ struct BgIcicle; +typedef void (*BgIcicleActionFunc)(struct BgIcicle*, GlobalContext*); + +typedef enum { + /* 0 */ ICICLE_STALAGMITE_RANDOM_DROP, + /* 1 */ ICICLE_STALACTITE, + /* 2 */ ICICLE_STALACTITE_REGROW, + /* 3 */ ICICLE_STALAGMITE_FIXED_DROP +} BgIcicleMainType; + typedef struct BgIcicle { - /* 0x000 */ Actor actor; - /* 0x144 */ char unk_144[0x6C]; + /* 0x000 */ DynaPolyActor dyna; + /* 0x15C */ BgIcicleActionFunc actionFunc; + /* 0x160 */ u8 unk_160; + /* 0x161 */ u8 unk_161; + /* 0x162 */ s16 shiverTimer; + /* 0x164 */ ColliderCylinder collider; } BgIcicle; // size = 0x1B0 extern const ActorInit Bg_Icicle_InitVars; diff --git a/tables/functions.txt b/tables/functions.txt index 6e148d0d79..ae3df75799 100644 --- a/tables/functions.txt +++ b/tables/functions.txt @@ -9127,13 +9127,13 @@ 0x809C9008:("EnSyatekiMan_Draw",), 0x809C9A60:("BgIcicle_Init",), 0x809C9B54:("BgIcicle_Destroy",), - 0x809C9B9C:("func_809C9B9C",), - 0x809C9D7C:("func_809C9D7C",), - 0x809C9D8C:("func_809C9D8C",), - 0x809C9DC4:("func_809C9DC4",), - 0x809C9F28:("func_809C9F28",), - 0x809CA06C:("func_809CA06C",), - 0x809CA0BC:("func_809CA0BC",), + 0x809C9B9C:("BgIcicle_Break",), + 0x809C9D7C:("BgIcicle_DoNothing",), + 0x809C9D8C:("BgIcicle_Wait",), + 0x809C9DC4:("BgIcicle_Shiver",), + 0x809C9F28:("BgIcicle_Fall",), + 0x809CA06C:("BgIcicle_Regrow",), + 0x809CA0BC:("BgIcicle_UpdateAttacked",), 0x809CA1F8:("BgIcicle_Update",), 0x809CA27C:("BgIcicle_Draw",), 0x809CA3F0:("EnSyatekiCrow_Init",),