From e64d4d8bf27c55e64819afb9cfa8d993a1e5c246 Mon Sep 17 00:00:00 2001 From: Isghj <42048411+isghj5@users.noreply.github.com> Date: Wed, 24 Mar 2021 01:58:25 -0700 Subject: [PATCH] EnPoFusen: OK (#69) * EnPoFusen: OK EnPoFusen: WIP EnPoFusen: init is matched * EnPoFusen: requested changes * Update src/overlays/actors/ovl_En_Ma4/z_en_ma4.h Co-authored-by: Rozelette * EnPoFusen: forgot I renamed a function to check diff, changed back * EnPoFusen: Bad search and replace * EnPoFusen: really bad search replace * EnPoFusen: ColliderInit and requested changes * Functions: renamed func_800B8EC8 to Audio_PlayActorSound2 Co-authored-by: isghj8 Co-authored-by: Rozelette --- include/functions.h | 2 +- linker_scripts/code_script.txt | 6 +- linker_scripts/object_script.txt | 4 + src/code/z_actor.c | 2 +- .../actors/ovl_En_Dy_Extra/z_en_dy_extra.c | 2 +- src/overlays/actors/ovl_En_Ma4/z_en_ma4.h | 5 +- .../actors/ovl_En_Po_Fusen/z_en_po_fusen.c | 247 ++++++++++++++++-- .../actors/ovl_En_Po_Fusen/z_en_po_fusen.h | 25 +- tables/functions.txt | 2 +- 9 files changed, 269 insertions(+), 26 deletions(-) diff --git a/include/functions.h b/include/functions.h index 53ab3df24c..ee99370452 100644 --- a/include/functions.h +++ b/include/functions.h @@ -821,7 +821,7 @@ u32 Actor_HasParent(Actor* actor, GlobalContext* ctxt); // void func_800B8DD4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // void func_800B8E1C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // void func_800B8E58(void); -void func_800B8EC8(Actor* actor, u32 uParm2); +void Audio_PlayActorSound2(Actor* actor, u16 sfxId); // void func_800B8EF4(void); void func_800B8F98(Actor* actor, u16 sfxId); // void func_800B8FC0(void); diff --git a/linker_scripts/code_script.txt b/linker_scripts/code_script.txt index 590a774d72..d9c4e61c3e 100644 --- a/linker_scripts/code_script.txt +++ b/linker_scripts/code_script.txt @@ -5553,9 +5553,9 @@ SECTIONS ovl_En_Po_Fusen : AT(RomLocation) { build/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.o(.text) - build/asm/overlays/ovl_En_Po_Fusen_data.o(.data) + build/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.o(.data) build/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.o(.rodata) - build/asm/overlays/ovl_En_Po_Fusen_rodata.o(.rodata) + build/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen_overlay.o(.ovl) } SegmentEnd = .; SegmentSize = SegmentEnd - SegmentStart; @@ -9342,4 +9342,4 @@ SECTIONS SegmentSize = SegmentEnd - SegmentStart; RomLocation += SegmentSize; _ovl_En_RsnSegmentEnd = SegmentEnd; -} \ No newline at end of file +} diff --git a/linker_scripts/object_script.txt b/linker_scripts/object_script.txt index aaf9dbafb1..8569e1c93d 100644 --- a/linker_scripts/object_script.txt +++ b/linker_scripts/object_script.txt @@ -94,6 +94,10 @@ D_06007750 = 0x06007750; D_0600A390 = 0x0600A390; D_0600A490 = 0x0600A490; +/* en_po_fusen */ +D_06000040 = 0x06000040; +D_060024F0 = 0x060024F0; + /* bg_ikana_shutter */ D_06000F28 = 0x06000F28; D_06000CE8 = 0x06000CE8; diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 11a7a5ae53..57058949ae 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -556,7 +556,7 @@ u32 Actor_HasParent(Actor* actor, GlobalContext* ctxt) { #pragma GLOBAL_ASM("./asm/non_matchings/code/z_actor//func_800B8E58.asm") -#pragma GLOBAL_ASM("./asm/non_matchings/code/z_actor//func_800B8EC8.asm") +#pragma GLOBAL_ASM("./asm/non_matchings/code/z_actor//Audio_PlayActorSound2.asm") #pragma GLOBAL_ASM("./asm/non_matchings/code/z_actor//func_800B8EF4.asm") diff --git a/src/overlays/actors/ovl_En_Dy_Extra/z_en_dy_extra.c b/src/overlays/actors/ovl_En_Dy_Extra/z_en_dy_extra.c index 1e01cdb454..1a0c98f308 100644 --- a/src/overlays/actors/ovl_En_Dy_Extra/z_en_dy_extra.c +++ b/src/overlays/actors/ovl_En_Dy_Extra/z_en_dy_extra.c @@ -76,7 +76,7 @@ void EnDyExtra_Update(Actor* thisx, GlobalContext* globalCtx) { EnDyExtra* this = THIS; DECR(this->unk14C); - func_800B8EC8(&this->actor, 0xC4U); + Audio_PlayActorSound2(&this->actor, 0xC4U); this->actionFunc(this, globalCtx); Actor_SetVelocityAndMoveYRotationAndGravity(&this->actor); } diff --git a/src/overlays/actors/ovl_En_Ma4/z_en_ma4.h b/src/overlays/actors/ovl_En_Ma4/z_en_ma4.h index fbe815259d..50c003e840 100644 --- a/src/overlays/actors/ovl_En_Ma4/z_en_ma4.h +++ b/src/overlays/actors/ovl_En_Ma4/z_en_ma4.h @@ -7,7 +7,10 @@ struct EnMa4; typedef struct EnMa4 { /* 0x000 */ Actor actor; - /* 0x144 */ char unk_144[0x1FC]; + /* 0x144 */ char unk_144[0x1F4]; + /* 0x338 */ s16 unk338; // modified by EnPoFusen + /* 0x33A */ char unk33A[0x6]; + } EnMa4; // size = 0x340 extern const ActorInit En_Ma4_InitVars; diff --git a/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.c b/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.c index 135cf9f7f1..38ac7ff14a 100644 --- a/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.c +++ b/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.c @@ -1,4 +1,5 @@ #include "z_en_po_fusen.h" +#include "../ovl_En_Ma4/z_en_ma4.h" #define FLAGS 0x80100030 @@ -9,7 +10,14 @@ void EnPoFusen_Destroy(Actor* thisx, GlobalContext* globalCtx); void EnPoFusen_Update(Actor* thisx, GlobalContext* globalCtx); void EnPoFusen_Draw(Actor* thisx, GlobalContext* globalCtx); -/* +u16 EnPoFusen_CheckParent(EnPoFusen* this, GlobalContext* globalCtx); +void EnPoFusen_InitNoFuse(EnPoFusen* this); +void EnPoFusen_InitFuse(EnPoFusen *this); +void EnPoFusen_Pop(EnPoFusen *this, GlobalContext *gCtx); +void EnPoFusen_Idle(EnPoFusen* this, GlobalContext* gCtx); +void EnPoFusen_IdleFuse(EnPoFusen* this, GlobalContext* gCtx); +s32 EnPoFusen_OverrideLimbDraw(GlobalContext* gCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, struct Actor* actor); + const ActorInit En_Po_Fusen_InitVars = { ACTOR_EN_PO_FUSEN, ACTORCAT_PROP, @@ -21,34 +29,239 @@ const ActorInit En_Po_Fusen_InitVars = { (ActorFunc)EnPoFusen_Update, (ActorFunc)EnPoFusen_Draw }; -*/ -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/EnPoFusen_Init.asm") +static ColliderSphereInit sSphereInit = { + { COLTYPE_NONE, AT_NONE, AC_ON | AC_TYPE_PLAYER, OC1_ON | OC1_TYPE_ALL, OC2_TYPE_1 | OC2_UNK1, COLSHAPE_SPHERE, }, + { ELEMTYPE_UNK0, { 0xF7CFFFFF, 0x00, 0x00 }, { 0xF7CFFFFF, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_ON, }, + { 0, { { 0, 0, 0 }, 200 }, 100 }, +}; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/EnPoFusen_Destroy.asm") +DamageTable EnPoFusenDamageTable = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF1, 0xF1, 0xF1, 0xF1, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC1450.asm") +void EnPoFusen_Init(Actor *thisx, GlobalContext *globalCtx) { + EnPoFusen* this = THIS; + f32 heightTemp; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC14A4.asm") + this->actor.scale.x = this->actor.scale.y = this->actor.scale.z = 0.00700000021607; + this->actor.targetMode = 6; + this->actor.colChkInfo.damageTable = &EnPoFusenDamageTable; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC1574.asm") + Collider_InitSphere(globalCtx, &this->collider); + Collider_SetSphere(globalCtx, &this->collider, &this->actor, &sSphereInit); -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC158C.asm") + if (0){} + this->collider.dim.worldSphere.radius = 40; + SkelAnime_InitSV(globalCtx, &this->anime, &D_060024F0, &D_06000040, &this->limbDrawTbl, &this->transitionDrawTbl, 10); + Actor_SetDrawParams(&this->actor.shape, 0.0f, func_800B3FC0, 25.0f); + func_800B78B8(globalCtx, this, 0.0f, 0.0f, 0.0f, 4); -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC18EC.asm") + if (EnPoFusen_CheckParent(this, globalCtx) == 0) { + Actor_MarkForDeath(&this->actor); + } -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC192C.asm") + heightTemp = this->actor.floorHeight + 90.0f; + if (this->actor.home.pos.y < heightTemp) { + this->actor.home.pos.y = heightTemp; + } -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC19B0.asm") + this->randScaleChange = ((rand() % 0xFFFEU) - 0x7FFF); + this->randYRotChange = ((rand() % 0x4B0U) - 0x258); + this->avgBaseRotation = 0x1555; + this->limb3Rot = 0; + this->limb46Rot = 0; + this->limb57Rot = 0; + this->limb8Rot = 0; + this->limb9Rot = 0x71C; + this->randBaseRotChange = 0; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC19DC.asm") + if (GET_IS_FUSE_TYPE_PARAM(this)) { + EnPoFusen_InitFuse(this); + return; + } -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/EnPoFusen_Update.asm") + EnPoFusen_InitNoFuse(this); +} -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC1A68.asm") +void EnPoFusen_Destroy(Actor* thisx, GlobalContext *gCtx) { + EnPoFusen* this = THIS; + Collider_DestroySphere(gCtx, &this->collider); +} -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC1CE8.asm") +u16 EnPoFusen_CheckParent(EnPoFusen *this, GlobalContext *globalCtx) { + struct Actor *actorPtr; -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/func_80AC1D00.asm") + actorPtr = globalCtx->actorCtx.actorList[4].first; + if (GET_IS_FUSE_TYPE_PARAM(this)) { + return 1; + } -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Po_Fusen_0x80AC1270/EnPoFusen_Draw.asm") + if (actorPtr != 0) { + do{ + if (actorPtr->id == ACTOR_EN_MA4) { + this->actor.parent = actorPtr; + return 1; + } + actorPtr = actorPtr->next; + } while (actorPtr != 0); + } + + return 0; +} + +u16 EnPoFusen_CheckCollision(EnPoFusen *this, GlobalContext *gCtx) { + if ((u32) this->actionFunc == (u32) EnPoFusen_IdleFuse ) { + return 0; + } + + this->collider.dim.worldSphere.center.x = this->actor.world.pos.x; + this->collider.dim.worldSphere.center.y = (this->actor.world.pos.y + 20.0f); + this->collider.dim.worldSphere.center.z = this->actor.world.pos.z; + + if (((this->collider.base.acFlags & 2) != 0) + && (this->actor.colChkInfo.damageEffect == 0xF)) { + this->collider.base.acFlags &= ~0x2; + return 1; + } + + CollisionCheck_SetOC(gCtx, &gCtx->colCheckCtx, &this->collider); + CollisionCheck_SetAC(gCtx, &gCtx->colCheckCtx, &this->collider); + + return 0; +} + +void EnPoFusen_InitNoFuse(EnPoFusen *this) { + this->actor.shape.rot.z = 0; + this->actionFunc = EnPoFusen_Idle; +} + +void EnPoFusen_Idle(EnPoFusen *this, GlobalContext *gCtx) { + f32 shadowScaleTmp; + f32 shadowAlphaTmp; + f32 heightOffset; + f32 f255 = 255.0f; + + this->actor.world.pos = this->actor.home.pos; + this->randScaleChange += 0x190; + this->randXZRotChange += 0x5DC; + this->randBaseRotChange += 0x9C4; + heightOffset = Math_Sins(this->randScaleChange); + heightOffset = 50.0f * heightOffset; + this->actor.shape.rot.y += this->randYRotChange; + this->actor.world.pos.y += heightOffset; + this->actor.shape.rot.z = (Math_Sins(this->randBaseRotChange) * 910.0f); + + if ((this->randScaleChange < 0x4000) && (this->randScaleChange >= -0x3FFF)) { + Math_SmoothScaleMaxMinS( &this->limb9Rot, 0x38E, 0x14, 0xBB8, 0x64); + } else { + Math_SmoothScaleMaxMinS( &this->limb9Rot, 0x71C, 0x8, 0xBB8, 0x64); + } + + this->avgBaseRotation = this->limb9Rot * 3; + this->limb3Rot = (Math_Sins(this->randBaseRotChange + 0x38E3) * this->avgBaseRotation); + this->limb46Rot = (Math_Sins(this->randBaseRotChange) * this->avgBaseRotation); + this->limb57Rot = (Math_Sins(this->randBaseRotChange - 0x38E3) * this->avgBaseRotation); + this->limb8Rot = (Math_Sins(this->randBaseRotChange - 0x71C6) * this->avgBaseRotation); + + shadowScaleTmp = ((1.0f - Math_Sins(this->randScaleChange)) * 10.0f) + 50.0f; + shadowAlphaTmp = ((1.0f - Math_Sins(this->randScaleChange)) * 75.0f) + 100.0f; + this->actor.shape.shadowScale = shadowScaleTmp; + this->actor.shape.shadowAlpha = (shadowAlphaTmp > f255) ? (u8) f255 : (u8) shadowAlphaTmp; +} + +void EnPoFusen_IncrementMalonPop(EnPoFusen *this) { + Actor* parent = this->actor.parent; + EnMa4* romani; + + if ((parent != 0) && (parent->id == ACTOR_EN_MA4)) { + romani = (EnMa4*) parent; + romani->unk338++; + } + + this->actor.draw = NULL; + this->actionFunc = EnPoFusen_Pop; +} + +void EnPoFusen_Pop(EnPoFusen *this, GlobalContext *gCtx) { + Actor_Spawn(&gCtx->actorCtx, gCtx, ACTOR_EN_CLEAR_TAG, + this->actor.world.pos.x, this->actor.world.pos.y + 20.0f, this->actor.world.pos.z, + 255, 255, 200, 2); + Audio_PlayActorSound2(&this->actor, 0x180E); // NA_SE_IT_BOMB_EXPLOSION sfx + Actor_MarkForDeath(&this->actor); +} + +void EnPoFusen_InitFuse(EnPoFusen *this) { + s16 rotZ = this->actor.shape.rot.z; + this->fuse = GET_FUSE_LEN_PARAM(this); + this->actor.shape.rot.z = 0; + this->randScaleChange = rotZ & 0xFFFFu; + this->actionFunc = EnPoFusen_IdleFuse; +} + +void EnPoFusen_IdleFuse(EnPoFusen *this, GlobalContext *gCtx) { + EnPoFusen_Idle(this, gCtx); + if (this->fuse-- == 0) { + EnPoFusen_IncrementMalonPop(this); + } +} + +void EnPoFusen_Update(Actor *thisx, GlobalContext *globalCtx) { + EnPoFusen* this = THIS; + this->actionFunc(this, globalCtx); + if (EnPoFusen_CheckCollision(this, globalCtx) != 0) { + EnPoFusen_IncrementMalonPop(this); + } +} + +s32 EnPoFusen_OverrideLimbDraw(GlobalContext *gCtx, s32 limbIndex, Gfx **dList, Vec3f *pos, Vec3s *rot, struct Actor *actor) { + EnPoFusen* this = (EnPoFusen*)actor; + f32 zScale; + f32 yScale; + f32 xScale; + s16 pad; + s16 zRot; + s16 pad2; + s16 xRot; + + if (limbIndex == 2) { + zScale = (Math_Coss(this->randScaleChange) * 0.0799999982119f) + 1.0f; + xScale = zScale; + if (!zScale) { } + yScale = (Math_Sins(this->randScaleChange) * 0.0799999982119f) + 1.0f; + yScale = yScale * yScale; + xRot = ((Math_Sins(this->randXZRotChange) * 2730.0f)); + zRot = ((Math_Coss(this->randXZRotChange) * 2730.0f)); + SysMatrix_InsertRotation(xRot, 0, zRot , 1); + SysMatrix_InsertScale(xScale, yScale , zScale, 1); + SysMatrix_InsertZRotation_s( -zRot, 1); + SysMatrix_InsertXRotation_s( -xRot, 1); + } else if (limbIndex == 3) { + rot->y += this->limb3Rot; + } else if (limbIndex == 6) { + rot->y += this->limb46Rot; + } else if (limbIndex == 4) { + rot->z += this->limb46Rot; + } else if ((limbIndex == 5) || (limbIndex == 7)) { + rot->z += this->limb57Rot; + } else if (limbIndex == 8) { + rot->z += this->limb8Rot; + } else if (limbIndex == 9) { + rot->y += (s16) (this->limb9Rot * Math_Sins(this->randBaseRotChange)); + rot->z += (s16) (this->limb9Rot * Math_Coss(this->randBaseRotChange)); + } + return 0; +} + +void EnPoFusen_PostLimbDraw(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { } + +void EnPoFusen_UnkActorDraw(s32 arg0, s32 arg1, s32 arg2) { } + +void EnPoFusen_Draw(Actor *thisx, GlobalContext *globalCtx) { + EnPoFusen* this = THIS; + func_8012C28C(globalCtx->state.gfxCtx); + func_801343C0(globalCtx, this->anime.skeleton, + this->anime.limbDrawTbl, this->anime.dListCount, + EnPoFusen_OverrideLimbDraw, EnPoFusen_PostLimbDraw, EnPoFusen_UnkActorDraw, &this->actor); +} diff --git a/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.h b/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.h index 5b610c32bb..245a44baa9 100644 --- a/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.h +++ b/src/overlays/actors/ovl_En_Po_Fusen/z_en_po_fusen.h @@ -5,11 +5,34 @@ struct EnPoFusen; +typedef void (*EnPoFusenActionFunc)(struct EnPoFusen*, GlobalContext*); + typedef struct EnPoFusen { /* 0x000 */ Actor actor; - /* 0x144 */ char unk_144[0x130]; + /* 0x144 */ SkelAnime anime; + /* 0x188 */ EnPoFusenActionFunc actionFunc; + /* 0x18C */ ColliderSphere collider; + /* 0x1E4 */ Vec3s limbDrawTbl[0xA]; + /* 0x220 */ Vec3s transitionDrawTbl[0xA]; + /* 0x25C */ s16 randScaleChange; + /* 0x25E */ s16 randXZRotChange; + /* 0x260 */ s16 randYRotChange; + /* 0x262 */ s16 avgBaseRotation; + /* 0x264 */ s16 limb3Rot; + /* 0x266 */ s16 limb46Rot; + /* 0x268 */ s16 limb57Rot; + /* 0x26A */ s16 limb8Rot; + /* 0x26C */ s16 limb9Rot; + /* 0x26E */ s16 randBaseRotChange; + /* 0x270 */ s16 fuse; } EnPoFusen; // size = 0x274 +extern SkeletonHeader D_06000040; +extern AnimationHeader D_060024F0; + extern const ActorInit En_Po_Fusen_InitVars; +#define GET_FUSE_LEN_PARAM(thisx) ((this)->actor.params & 0x3FF) +#define GET_IS_FUSE_TYPE_PARAM(thisx) ((this)->actor.params & 0x8000) + #endif // Z_EN_PO_FUSEN_H diff --git a/tables/functions.txt b/tables/functions.txt index 9231e8f14e..21ad22a100 100644 --- a/tables/functions.txt +++ b/tables/functions.txt @@ -810,7 +810,7 @@ 0x800B8DD4:("func_800B8DD4",), 0x800B8E1C:("func_800B8E1C",), 0x800B8E58:("func_800B8E58",), - 0x800B8EC8:("func_800B8EC8",), + 0x800B8EC8:("Audio_PlayActorSound2",), 0x800B8EF4:("func_800B8EF4",), 0x800B8F98:("func_800B8F98",), 0x800B8FC0:("func_800B8FC0",),