From 831fa5485a95cdb71981efbb075029e753b8882f Mon Sep 17 00:00:00 2001 From: Maide Date: Tue, 28 Sep 2021 21:01:36 +0100 Subject: [PATCH 01/26] Obj_Mine --- include/functions.h | 2 +- spec | 6 +- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 1058 ++++++++++++++++- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 60 +- 4 files changed, 1061 insertions(+), 65 deletions(-) diff --git a/include/functions.h b/include/functions.h index 2b92417a8..f3c1be135 100644 --- a/include/functions.h +++ b/include/functions.h @@ -3284,7 +3284,7 @@ void func_80179B34(float fParm1, f32 fParm2, f32 fParm5, f32 fParm6, f32 param_5 // void func_80179D74(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); void Math3D_ScaleAndAdd(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dst); void Math3D_Lerp(Vec3f* a, Vec3f* b, f32 t, Vec3f* dst); -s32 Math3D_Parallel(Vec3f* a, Vec3f* b); +f32 Math3D_Parallel(Vec3f* a, Vec3f* b); s32 Math3D_AngleBetweenVectors(Vec3f* a, Vec3f* b, f32* angle); void func_80179F64(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); s32 Math3D_XZBoundCheck(f32 xMin, f32 xMax, f32 zMin, f32 zMax, f32 x, f32 z); diff --git a/spec b/spec index a42617d9a..acf39407e 100644 --- a/spec +++ b/spec @@ -3229,9 +3229,11 @@ beginseg name "ovl_Obj_Mine" compress include "build/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.o" - include "build/data/ovl_Obj_Mine/ovl_Obj_Mine.data.o" - include "build/data/ovl_Obj_Mine/ovl_Obj_Mine.bss.o" +#ifdef NON_MATCHING + include "build/src/overlays/actors/ovl_Obj_Mine/ovl_Obj_Mine_reloc.o" +#else include "build/data/ovl_Obj_Mine/ovl_Obj_Mine.reloc.o" +#endif endseg beginseg diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index a1f127eaa..a1a35a780 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -1,4 +1,11 @@ +/* + * File: z_obj_mine.c + * Overlay: ovl_Obj_Mine + * Description: Spike metal Mine + */ + #include "z_obj_mine.h" +#include "overlays/actors/ovl_En_Bom/z_en_bom.h" #define FLAGS 0x00000000 @@ -9,7 +16,30 @@ void ObjMine_Destroy(Actor* thisx, GlobalContext* globalCtx); void ObjMine_Update(Actor* thisx, GlobalContext* globalCtx); void ObjMine_Draw(Actor* thisx, GlobalContext* globalCtx); -#if 0 +void func_80A82F84(ObjMine* this); +void func_80A82F98(ObjMine* this, GlobalContext* globalCtx); +void func_80A82FA8(ObjMine* this); +void func_80A82FC8(ObjMine* this, GlobalContext* globalCtx); +void func_80A83258(ObjMine* this, GlobalContext* globalCtx); +void func_80A832BC(ObjMine* this); +void func_80A832D0(ObjMine* this, GlobalContext* globalCtx); +void func_80A83A74(ObjMine* this); +void func_80A83A88(ObjMine* this, GlobalContext* globalCtx); +void func_80A83B14(ObjMine* this); +void func_80A83B28(ObjMine* this, GlobalContext* globalCtx); +void func_80A83CEC(ObjMine* this); +void func_80A83D00(ObjMine* this, GlobalContext* globalCtx); +void func_80A83E7C(Actor* thisx, GlobalContext* globalCtx); +void func_80A83FBC(Actor* thisx, GlobalContext* globalCtx); +void func_80A84088(Actor* thisx, GlobalContext* globalCtx); +void func_80A84338(Actor* thisx, GlobalContext* globalCtx); + +extern Gfx D_06000030[]; +extern Gfx D_06002068[]; +extern Gfx D_06002188[]; + +static s32 D_80A849D0[0xC0]; + const ActorInit Obj_Mine_InitVars = { ACTOR_OBJ_MINE, ACTORCAT_PROP, @@ -22,127 +52,1035 @@ const ActorInit Obj_Mine_InitVars = { (ActorFunc)ObjMine_Draw, }; -// static ColliderJntSphElementInit sJntSphElementsInit[1] = { -static ColliderJntSphElementInit D_80A84570[1] = { +static ColliderJntSphElementInit sJntSphElementsInit[1] = { { - { ELEMTYPE_UNK2, { 0x00000000, 0x00, 0x00 }, { 0x01CBFFBE, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_ON, }, + { + ELEMTYPE_UNK2, + { 0x00000000, 0x00, 0x00 }, + { 0x01CBFFBE, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_ON, + }, { 0, { { 0, 0, 0 }, 30 }, 100 }, }, }; -// static ColliderJntSphInit sJntSphInit = { -static ColliderJntSphInit D_80A84594 = { - { COLTYPE_METAL, AT_NONE, AC_ON | AC_TYPE_PLAYER, OC1_ON | OC1_TYPE_PLAYER | OC1_TYPE_1, OC2_TYPE_1, COLSHAPE_JNTSPH, }, - 1, D_80A84570, // sJntSphElementsInit, +static ColliderJntSphInit sJntSphInit = { + { + COLTYPE_METAL, + AT_NONE, + AC_ON | AC_TYPE_PLAYER, + OC1_ON | OC1_TYPE_PLAYER | OC1_TYPE_1, + OC2_TYPE_1, + COLSHAPE_JNTSPH, + }, + 1, + sJntSphElementsInit, }; -// static InitChainEntry sInitChain[] = { -static InitChainEntry D_80A845E8[] = { +static f32 D_80A845A4[] = { + 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, +}; + +static Vec3f D_80A845C4 = { 1.0f, 0.0f, 0.0f }; + +static Vec3f D_80A845D0[] = { + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 0.0f, 1.0f }, +}; + +static InitChainEntry sInitChain[] = { ICHAIN_F32(uncullZoneForward, 1300, ICHAIN_CONTINUE), ICHAIN_F32(uncullZoneScale, 150, ICHAIN_CONTINUE), ICHAIN_F32(uncullZoneDownward, 100, ICHAIN_CONTINUE), ICHAIN_VEC3F_DIV1000(scale, 10, ICHAIN_STOP), }; +void func_80A811D0(ObjMine* this, s32 arg1) { + Math_Vec3s_ToVec3f(&this->actor.world.pos, &this->unk_1B4[arg1]); +} + +s32 func_80A8120C(Vec3f* arg0, Vec3f* arg1) { + f32 temp_f0 = Math3D_Vec3fMagnitude(arg0); + + if (temp_f0 < 0.001f) { + return false; + } + + arg1->x = arg0->x * (1.0f / temp_f0); + arg1->y = arg0->y * (1.0f / temp_f0); + arg1->z = arg0->z * (1.0f / temp_f0); + return true; +} + +s32 func_80A81288(Vec3f* arg0, Vec3f* arg1, f32* arg2, f32* arg3) { + f32 temp_f0 = Math3D_Vec3fMagnitude(arg0); + + if (temp_f0 < 0.001f) { + return false; + } + + arg1->x = arg0->x * (1.0f / temp_f0); + arg1->y = arg0->y * (1.0f / temp_f0); + arg1->z = arg0->z * (1.0f / temp_f0); + *arg2 = temp_f0; + *arg3 = 1.0f / temp_f0; + + return true; +} + +void func_80A8131C(ObjMine* this, GlobalContext* globalCtx) { + EnBom* bomb = (EnBom*)Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_BOM, this->actor.world.pos.x, + this->actor.world.pos.y - 15.0f, this->actor.world.pos.z, 0, 0, 0, 0); + + if (bomb != NULL) { + bomb->timer = 0; + } +} + +void func_80A81384(ObjMine* this, GlobalContext* globalCtx) { + f32 x = this->collider.elements[0].dim.worldSphere.center.x; + f32 y = this->collider.elements[0].dim.worldSphere.center.y - 15.0f; + f32 z = this->collider.elements[0].dim.worldSphere.center.z; + + EnBom* bom = (EnBom*)Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_BOM, x, y, z, 0, 0, 0, 0); + + if (bom != NULL) { + bom->timer = 0; + } +} + +s32 func_80A8140C(ObjMine* this) { + if (this->collider.base.ocFlags2 & OC2_HIT_PLAYER) { + return true; + } + + if ((this->collider.base.ocFlags1 & OC2_UNK1)) { + Actor* mine = this->collider.base.oc; + + if ((mine->id == ACTOR_OBJ_MINE) && (mine->room == this->actor.room)) { + return true; + } + } + + return false; +} + +void func_80A8146C(ObjMine* this, s16* arg1, s16* arg2) { + s32 pad2[3]; + Vec3f sp40; + s16 sp3E; + s16 pad; + Actor* temp_s0 = this->collider.base.ac; + + Math_Vec3s_ToVec3f(&sp40, &this->collider.elements[0].dim.worldSphere.center); + sp3E = Math_Vec3f_Yaw(&temp_s0->world.pos, &sp40); + + if (this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820) { + *arg1 = temp_s0->shape.rot.y; + *arg2 = temp_s0->shape.rot.y - sp3E; + } else { + Vec3f sp2C; + Vec3s* hitPos = &this->collider.elements[0].info.bumper.hitPos; + + Math_Vec3s_ToVec3f(&sp2C, hitPos); + *arg1 = Actor_YawBetweenActors(temp_s0, &this->actor); + *arg2 = Math_Vec3f_Yaw(&temp_s0->world.pos, &sp2C) - sp3E; + } +} + +#ifdef NON_MATCHING +// stack, 1 var needs to go without changing code gen +void func_80A81544(ObjMine* this, Vec3f* arg1) { + ColliderJntSphElement* element = &this->collider.elements[0]; + Vec3s* sphere = &element->dim.worldSphere.center; + Actor* temp_v1 = this->collider.base.ac; + + if ((element->info.acHitInfo->toucher.dmgFlags & 0x13820)) { + SysMatrix_StatePush(); + Matrix_RotateY(temp_v1->shape.rot.y, MTXMODE_NEW); + SysMatrix_InsertXRotation_s(temp_v1->shape.rot.x, MTXMODE_APPLY); + SysMatrix_GetStateTranslationAndScaledZ(1.0f, arg1); + SysMatrix_StatePop(); + } else { + Vec3f sp20; + + sp20.x = sphere->x - temp_v1->world.pos.x; + sp20.y = sphere->y - temp_v1->world.pos.y; + sp20.z = sphere->z - temp_v1->world.pos.z; + if (!func_80A8120C(&sp20, arg1)) { + Math_Vec3f_Copy(arg1, D_80A845D0); + } + } +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81544.s") #endif -extern ColliderJntSphElementInit D_80A84570[1]; -extern ColliderJntSphInit D_80A84594; -extern InitChainEntry D_80A845E8[]; +void func_80A81640(ObjMine* this) { +} -extern UNK_TYPE D_06000030; -extern UNK_TYPE D_06002068; +void func_80A8164C(Vec3f* arg0) { + MtxF* matrix = SysMatrix_GetCurrentState(); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A811D0.s") + matrix->mf[3][0] = arg0->x; + matrix->mf[3][1] = arg0->y; + matrix->mf[3][2] = arg0->z; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8120C.s") +void func_80A81684(ObjMineUnkStruct* arg0) { + MtxF* matrix = SysMatrix_GetCurrentState(); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81288.s") + matrix->mf[0][0] = arg0->unk_00.x; + matrix->mf[0][1] = arg0->unk_00.y; + matrix->mf[0][2] = arg0->unk_00.z; + matrix->mf[0][3] = 0.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8131C.s") + matrix->mf[1][0] = arg0->unk_0C.x; + matrix->mf[1][1] = arg0->unk_0C.y; + matrix->mf[1][2] = arg0->unk_0C.z; + matrix->mf[1][3] = 0.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81384.s") + matrix->mf[2][0] = arg0->unk_18.x; + matrix->mf[2][1] = arg0->unk_18.y; + matrix->mf[2][2] = arg0->unk_18.z; + matrix->mf[2][3] = 0.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8140C.s") + matrix->mf[3][0] = 0.0f; + matrix->mf[3][1] = 0.0f; + matrix->mf[3][2] = 0.0f; + matrix->mf[3][3] = 1.0f; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8146C.s") +s32 func_80A81714(Vec3f* arg0, Vec3f* arg1, f32 arg2) { + Vec3f sp3C; + Vec3f sp30; + Vec3f sp24; + f32 sp20 = Math3D_Parallel(arg0, arg1); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81544.s") + if (cos_rad(arg2) <= sp20) { + Math_Vec3f_Copy(arg0, arg1); + return true; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81640.s") + SysMatrix_StatePush(); + Math_Vec3f_Copy(&sp30, arg0); + Math3D_CrossProduct(arg0, arg1, &sp3C); + if (func_80A8120C(&sp3C, &sp24)) { + SysMatrix_InsertRotationAroundUnitVector_s(arg2 * 10430.378f, &sp24, MTXMODE_NEW); + SysMatrix_MultiplyVector3fByState(&sp30, arg0); + } else { + SysMatrix_SetStateXRotation(arg2); + SysMatrix_MultiplyVector3fByState(&sp30, arg0); + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8164C.s") + SysMatrix_StatePop(); + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81684.s") +void func_80A81818(ObjMine* this) { + this->collider.elements->dim.worldSphere.center.x = this->actor.world.pos.x; + this->collider.elements->dim.worldSphere.center.y = this->actor.world.pos.y; + this->collider.elements->dim.worldSphere.center.z = this->actor.world.pos.z; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81714.s") +void func_80A81868(ObjMine* this, s32 arg1) { + s32 i; + ObjMineUnkStruct* ptr = &this->unk_1B8; + ObjMineUnkStruct3* unkStruct; + f32 arg = arg1; + f32 temp_f12 = this->actor.home.rot.z * 5.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81818.s") + ptr->unk_00.x = 1.0f; + ptr->unk_0C.y = 1.0f; + ptr->unk_18.z = 1.0f; + ptr->unk_24.y = 1.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81868.s") + if (arg1 > 0) { + ptr->unk_40 = -sqrtf(0.001984f / arg); + ptr->unk_44 = (0.00031746097f * arg) + 0.95f; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A819A4.s") + ptr->unk_58 = 0.0002f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81A00.s") + for (i = 0, unkStruct = &ptr->unk_60[0]; i < arg1; i++, unkStruct++) { + unkStruct->unk_00 = 0x4000; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81AA4.s") + if (temp_f12 < 0.0f) { + ptr->unk_5C = -1.0f; + } else if (temp_f12 <= 21.0f) { + ptr->unk_5C = 0.0f; + } else { + ptr->unk_5C = SQ(temp_f12 - 20.0f); + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81B14.s") +void func_80A819A4(ObjMine* this, s32 arg1) { + SysMatrix_InsertTranslation(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, MTXMODE_NEW); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + Collider_UpdateSpheres(0, &this->collider); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81B7C.s") +void func_80A81A00(ObjMine* this) { + ObjMineUnkStruct* ptr = &this->unk_1B8; + Vec3f sp28; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81D70.s") + sp28.x = -ptr->unk_30; + sp28.y = 1.0f; + sp28.z = -ptr->unk_34; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81DEC.s") + func_80A8120C(&sp28, &ptr->unk_0C); + Math3D_CrossProduct(&D_80A845C4, &ptr->unk_0C, &sp28); + func_80A8120C(&sp28, &ptr->unk_18); + Math3D_CrossProduct(&ptr->unk_0C, &ptr->unk_18, &sp28); + func_80A8120C(&sp28, &ptr->unk_00); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81E7C.s") +void func_80A81AA4(ObjMine* this) { + s32 params = this->actor.params & 0x3F; + f32 temp_f0 = -((params * 12.0f) + 10.0f); + + this->actor.world.pos.x = (this->unk_1B8.unk_0C.x * temp_f0) + this->actor.home.pos.x; + this->actor.world.pos.y = (this->unk_1B8.unk_0C.y * temp_f0) + this->actor.home.pos.y; + this->actor.world.pos.z = (this->unk_1B8.unk_0C.z * temp_f0) + this->actor.home.pos.z; +} + +void func_80A81B14(ObjMine* this) { + s32 params = this->actor.params & 0x3F; + f32 temp_f0 = 1.0f / ((params * 12.0f) + 10.0f); + f32 x = this->actor.world.pos.x - this->actor.home.pos.x; + f32 z = this->actor.world.pos.z - this->actor.home.pos.z; + + this->unk_1B8.unk_30 = x * temp_f0; + this->unk_1B8.unk_34 = z * temp_f0; +} + +void func_80A81B7C(ObjMine* this, s32 arg1) { + ObjMineUnkStruct* ptr = &this->unk_1B8; + ObjMineUnkStruct2* unkStruct; + s32 i; + f32 sp58 = this->actor.home.rot.z * 5.0f; + f32 temp_f24; + f32 temp_f26; + + ptr->unk_00.x = 0.9f; + ptr->unk_18.y = 0.003f; + + *(s16*)((u8*)ptr + 0x20) = (u32)Rand_Next() >> 0x13; + ptr->unk_24.x = -0.0002f; + ptr->unk_30 = -0.0002f; + + temp_f26 = ptr->unk_18.y * 6.0f; + temp_f24 = this->actor.home.pos.y; + + unkStruct = (ObjMineUnkStruct2*)&ptr->unk_44; + for (i = 0; i < arg1; i++, unkStruct++) { + temp_f24 += 12.0f; + unkStruct->unk_00.x = 1.0f; + unkStruct->unk_0C.y = 1.0f; + unkStruct->unk_18.z = 1.0f; + unkStruct->unk_24.x = this->actor.home.pos.x; + unkStruct->unk_24.y = temp_f24; + unkStruct->unk_24.z = this->actor.home.pos.z; + unkStruct->unk_30.x = (Rand_ZeroOne() - 0.5f) * temp_f26; + unkStruct->unk_30.y = (Rand_ZeroOne() - 0.5f) * temp_f26; + unkStruct->unk_30.z = (Rand_ZeroOne() - 0.5f) * temp_f26; + } + + ptr->unk_24.y = temp_f24; + ptr->unk_24.z = temp_f24 * 0.97f; + temp_f24 = temp_f24 - 18.0f; + + if (ptr->unk_24.z < temp_f24) { + ptr->unk_24.z = temp_f24; + } + + if (sp58 < 0.0f) { + ptr->unk_34 = -1.0f; + } else if (sp58 <= 37.0f) { + ptr->unk_34 = 0.0f; + } else { + ptr->unk_34 = SQ(sp58 - 36.0f); + } +} + +void func_80A81D70(ObjMine* this, s32 arg1) { + SysMatrix_InsertTranslation(this->actor.home.pos.x, this->actor.home.pos.y + (arg1 * 12.0f) + 10.0f, + this->actor.home.pos.z, MTXMODE_NEW); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + Collider_UpdateSpheres(0, &this->collider); +} + +void func_80A81DEC(ObjMine* this) { + s32 pad[2]; + s32 temp_v0 = this->actor.params & 0x3F; + NextUnkStruct* temp_v1 = &((NextUnkStruct*)&this->unk_1B8)[temp_v0]; + + if (temp_v0 == 0) { + this->actor.world.pos.y = (this->actor.home.pos.y + 12.0f) + 10.0f; + } else { + Vec3f sp1C; + + Math_Vec3f_ScaleAndStore(&temp_v1->unk_08, 10.0f, &sp1C); + Math_Vec3f_Sum(&temp_v1->unk_20, &sp1C, &this->actor.world.pos); + } +} + +void func_80A81E7C(ObjMine* this, GlobalContext* globalCtx) { + ObjMineUnkStruct* temp_v1 = &this->unk_1B8; + s32 pad; + Vec3f sp7C; + Vec3f sp70; + Vec3f sp64; + Vec3f sp58; + Vec3f sp4C; + CollisionPoly* sp48; + u32 sp44; + f32 sp40; + f32 sp3C; + + *(s8*)(&temp_v1->unk_40) = 0; + if (temp_v1->unk_34 > -0.000001f) { + if (temp_v1->unk_34 <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, + this->actor.world.pos.x, this->actor.world.pos.z)) { + sp58.x = this->actor.world.pos.x - this->actor.home.pos.x; + sp58.y = 0.0f; + sp58.z = this->actor.world.pos.z - this->actor.home.pos.z; + if (func_80A81288(&sp58, &sp4C, &sp40, &sp3C)) { + sp70.x = this->actor.world.pos.x + (sp4C.x * 36.0f); + sp70.y = this->actor.world.pos.y; + sp70.z = this->actor.world.pos.z + (sp4C.z * 36.0f); + sp7C.x = this->actor.home.pos.x; + sp7C.y = this->actor.world.pos.y; + sp7C.z = this->actor.home.pos.z; + if (func_800C55C4(&globalCtx->colCtx, &sp7C, &sp70, &sp64, &sp48, 1, 0, 0, 1, &sp44)) { + *(s8*)(&temp_v1->unk_40) = 1; + temp_v1->unk_38 = sp4C.x * -0.2f; + temp_v1->unk_3C = sp4C.z * -0.2f; + } + } + } + } +} #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81FFC.s") -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A828A8.s") +void func_80A828A8(ObjMine* this) { + s32 pad; + Vec3f spE0; + Vec3f spD4; + Vec3f spC8; + s32 spC4 = this->actor.params & 0x3F; + s32 i = 0; + s32 phi_s5; + Vec3f* phi_s3 = NULL; + ObjMineUnkStruct* sp70 = &this->unk_1B8; + Vec3f spA8; + Vec3f sp9C; + Vec3f sp90; + Vec3f sp84; + ObjMineUnkStruct2* temp_s0 = (ObjMineUnkStruct2*)&sp70->unk_44; + f32 sp7C; + f32 sp78; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82C28.s") + sp84.x = this->actor.home.pos.x; + sp84.y = this->actor.home.pos.y + 6.0f; + sp84.z = this->actor.home.pos.z; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Init.s") + for (; i < spC4; i++, temp_s0++) { + phi_s5 = false; + temp_s0->unk_30.x += temp_s0->unk_3C.x; + temp_s0->unk_30.y += temp_s0->unk_3C.y; + temp_s0->unk_30.z += temp_s0->unk_3C.z; + Math_Vec3f_Scale(&temp_s0->unk_30, sp70->unk_00.x); + Math_Vec3f_Copy(&sp90, &temp_s0->unk_24); + temp_s0->unk_24.x += temp_s0->unk_30.x; + temp_s0->unk_24.y += temp_s0->unk_30.y; + temp_s0->unk_24.z += temp_s0->unk_30.z; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Destroy.s") + if ((temp_s0->unk_24.y <= this->actor.home.pos.y) && (temp_s0->unk_30.y < 0.0f)) { + temp_s0->unk_30.y *= 0.1f; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82F84.s") + Math_Vec3f_Diff(&temp_s0->unk_24, &sp84, &spA8); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82F98.s") + if (func_80A81288(&spA8, &sp9C, &sp7C, &sp78) && (sp7C > 4.0f)) { + Math_Vec3f_Copy(&spD4, &temp_s0->unk_0C); + func_80A81714(&spD4, &sp9C, 0.10471976f); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82FA8.s") + Math3D_CrossProduct((phi_s3 == NULL) ? &D_80A845C4 : phi_s3, &spD4, &spA8); + if (func_80A8120C(&spA8, &spE0)) { + Math3D_CrossProduct(&spD4, &spE0, &spA8); + if (func_80A8120C(&spA8, &spC8)) { + phi_s5 = true; + } + } + } + + if (phi_s5) { + Math_Vec3f_Copy(&temp_s0->unk_00, &spC8); + Math_Vec3f_Copy(&temp_s0->unk_0C, &spD4); + Math_Vec3f_Copy(&temp_s0->unk_18, &spE0); + } else { + sp7C = 4.0f; + } + + if (sp7C >= 6.0f) { + temp_s0->unk_24.x = (temp_s0->unk_0C.x * 6.0f) + sp84.x; + temp_s0->unk_24.y = (temp_s0->unk_0C.y * 6.0f) + sp84.y; + temp_s0->unk_24.z = (temp_s0->unk_0C.z * 6.0f) + sp84.z; + } else { + temp_s0->unk_24.x = (temp_s0->unk_0C.x * sp7C) + sp84.x; + temp_s0->unk_24.y = (temp_s0->unk_0C.y * sp7C) + sp84.y; + temp_s0->unk_24.z = (temp_s0->unk_0C.z * sp7C) + sp84.z; + } + + sp84.x = temp_s0->unk_24.x + (temp_s0->unk_0C.x * 6.0f); + sp84.y = temp_s0->unk_24.y + (temp_s0->unk_0C.y * 6.0f); + sp84.z = temp_s0->unk_24.z + (temp_s0->unk_0C.z * 6.0f); + + phi_s3 = &temp_s0->unk_00; + } +} + +void func_80A81FFC(ObjMine* this); + +void func_80A82C28(ObjMine* this, GlobalContext* globalCtx) { + func_80A81E7C(this, globalCtx); + func_80A81FFC(this); + func_80A828A8(this); +} + +void ObjMine_Init(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + s32 pad; + s32 sp44 = this->actor.params & 0xFF; + Path* path; + s32 sp3C; + s32 sp38 = (this->actor.params >> 0xC) & 3; + s32 sp34; + + Actor_ProcessInitChain(&this->actor, sInitChain); + this->actor.shape.rot.z = 0; + this->actor.world.rot.z = 0; + Collider_InitJntSph(globalCtx, &this->collider); + Collider_SetJntSph(globalCtx, &this->collider, &this->actor, &sJntSphInit, this->colliderElements); + + if (sp38 == 0) { + ActorShape_Init(&this->actor.shape, 0.0f, func_800B3FC0, 45.0f); + this->actor.shape.shadowAlpha = 140; + this->unk_1A8 = D_80A845A4[(this->actor.params >> 8) & 7]; + if (sp44 == 0xFF) { + func_80A82F84(this); + } else { + path = &globalCtx->setupPathList[sp44]; + this->unk_1B0 = 0; + this->unk_1AC = path->count - 1; + this->unk_1B4 = (Vec3s*)Lib_SegmentedToVirtual(path->points); + func_80A811D0(this, this->unk_1B0); + func_80A82FA8(this); + } + SysMatrix_SetStateRotationAndTranslation(this->actor.world.pos.x, this->actor.world.pos.y, + this->actor.world.pos.z, &this->actor.shape.rot); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + Collider_UpdateSpheres(0, &this->collider); + this->actor.floorHeight = + func_800C411C(&globalCtx->colCtx, &this->actor.floorPoly, &sp3C, &this->actor, &this->actor.world.pos); + } else { + sp34 = this->actor.params & 0x3F; + this->actor.update = func_80A83E7C; + this->actor.uncullZoneScale = (sp34 * 21.0f) + 150.0f; + this->actor.uncullZoneDownward = (sp34 * 21.0f) + 150.0f; + ActorShape_Init(&this->actor.shape, 0.0f, func_800B3FC0, 45.0f); + this->actor.shape.shadowAlpha = 0x8C; + + if (sp38 == 1) { + this->actor.draw = func_80A84088; + func_80A81868(this, sp34); + this->actor.world.pos.y = (-10.0f - (sp34 * 12.0f)) + this->actor.home.pos.y; + func_80A819A4(this, sp34); + func_800B4AEC(globalCtx, &this->actor, 0.0f); + if (sp34 == 0) { + func_80A83A74(this); + } else { + func_80A832BC(this); + } + } else { + this->actor.draw = func_80A84338; + func_80A81B7C(this, sp34); + this->actor.world.pos.y = (sp34 * 12.0f) + 10.0f + this->actor.home.pos.y; + func_80A81D70(this, sp34); + if (sp34 == 0) { + func_80A83CEC(this); + } else { + func_80A83B14(this); + } + } + } +} + +void ObjMine_Destroy(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + + Collider_DestroyJntSph(globalCtx, &this->collider); +} + +void func_80A82F84(ObjMine* this) { + this->actionFunc = func_80A82F98; +} + +void func_80A82F98(ObjMine* this, GlobalContext* globalCtx) { +} + +void func_80A82FA8(ObjMine* this) { + this->actor.flags |= 0x10; + this->actionFunc = func_80A82FC8; +} + +#ifdef NON_MATCHING +// stack +void func_80A82FC8(ObjMine* this, GlobalContext* globalCtx) { + f32 phi_f0; + Vec3f spA0; + f32 sp9C; + s32 pad; + f32 phi_f12; + s32 sp90; + Vec3f sp84; + Vec3f sp78; + MtxF sp38; + + Math_Vec3s_ToVec3f(&spA0, &this->unk_1B4[this->unk_1B0 + 1]); + Math_Vec3f_Diff(&spA0, &this->actor.world.pos, &this->actor.velocity); + + sp9C = Math3D_Vec3fMagnitude(&this->actor.velocity); + if ((sp9C < (this->unk_1A8 * 8.0f)) && (this->unk_1A8 > 2.0f)) { + phi_f0 = ((this->unk_1A8 - 2.0f) * 0.1f) + 2.0f; + phi_f12 = this->unk_1A8 * 0.03f; + } else { + phi_f0 = this->unk_1A8; + phi_f12 = this->unk_1A8 * 0.16f; + } + + Math_StepToF(&this->actor.speedXZ, phi_f0, phi_f12); + + if ((this->actor.speedXZ + 0.05f) < sp9C) { + Math_Vec3f_Scale(&this->actor.velocity, this->actor.speedXZ / sp9C); + this->actor.world.pos.x += this->actor.velocity.x; + this->actor.world.pos.y += this->actor.velocity.y; + this->actor.world.pos.z += this->actor.velocity.z; + } else { + this->actor.speedXZ *= 0.4f; + this->unk_1B0++; + if (this->unk_1B0 >= this->unk_1AC) { + this->unk_1B0 = 0; + } + func_80A811D0(this, this->unk_1B0); + } + + this->actor.floorHeight = + func_800C411C(&globalCtx->colCtx, &this->actor.floorPoly, &sp90, &this->actor, &this->actor.world.pos); + + if (this->actor.flags & 0x40) { + Math3D_CrossProduct(&D_80A845D0[0], &this->actor.velocity, &sp78); + if (func_80A8120C(&sp78, &sp84)) { + SysMatrix_InsertRotationAroundUnitVector_f(this->actor.speedXZ * 0.03125f, &sp84, MTXMODE_NEW); + Matrix_RotateY(this->actor.shape.rot.y, MTXMODE_APPLY); + SysMatrix_InsertXRotation_s(this->actor.shape.rot.x, MTXMODE_APPLY); + SysMatrix_InsertZRotation_s(this->actor.shape.rot.z, MTXMODE_APPLY); + SysMatrix_CopyCurrentState(&sp38); + func_8018219C(&sp38, &this->actor.shape.rot, 0); + } + } +} +#else #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82FC8.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83214.s") +void func_80A83214(ObjMine* this) { + this->actor.flags |= 0x10; + this->actor.draw = func_80A83FBC; + this->actor.shape.shadowDraw = NULL; + this->actor.scale.x = 0.02f; + this->actor.scale.y = 0.02f; + this->actor.scale.z = 0.02f; + this->actionFunc = func_80A83258; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83258.s") +void func_80A83258(ObjMine* this, GlobalContext* globalCtx) { + this->actor.scale.x *= 1.8f; + if (this->actor.scale.x > 0.17495999f) { + Actor_MarkForDeath(&this->actor); + } else { + this->actor.scale.y = this->actor.scale.x; + this->actor.scale.z = this->actor.scale.x; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A832BC.s") +void func_80A832BC(ObjMine* this) { + this->actionFunc = func_80A832D0; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A832D0.s") +void func_80A832D0(ObjMine* this, GlobalContext* globalCtx) { + s32 pad; + s32 spA0 = this->actor.params & 0x3F; + ObjMineUnkStruct* unkStruct = &this->unk_1B8; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83A74.s") + Math_Vec3f_Copy(&unkStruct->unk_24, &unkStruct->unk_0C); + if (func_80A8140C(this)) { + func_80A81384(this, globalCtx); + func_80A81640(this); + func_80A83214(this); + } else { + ObjMineUnkStruct3* temp; + s32 i; + f32 sp90; + f32 sp8C; + f32 sp88; + s16 sp86; + s16 sp84; + s32 pad2; + s32 pad3; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83A88.s") + if (this->collider.base.acFlags & AC_HIT) { + this->collider.base.acFlags &= ~AC_HIT; + unkStruct->unk_48 = 0.04f; + func_80A8146C(this, &unkStruct->unk_4C, &sp84); + sp8C = Math_SinS(sp84) * 150.0f; + sp88 = sp8C; + sp8C = -(sp8C / spA0); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83B14.s") + for (i = 0, temp = &unkStruct->unk_60[0]; i < spA0; i++, temp++) { + temp->unk_02 += (s16)sp88; + temp->unk_02 = CLAMP(temp->unk_02, -800, 800); + sp88 -= sp8C; + } + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83B28.s") + if (unkStruct->unk_48 > 0.0001f) { + sp90 = Math_SinS(unkStruct->unk_4C) * unkStruct->unk_48; + sp8C = Math_CosS(unkStruct->unk_4C) * unkStruct->unk_48; + unkStruct->unk_38 += sp90; + unkStruct->unk_3C += sp8C; + Math_StepToF(&unkStruct->unk_48, 0.0f, 0.02f); + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83CEC.s") + if ((u32)Rand_Next() >> 0x1B == 0) { + unkStruct->unk_50 = Rand_ZeroOne() * unkStruct->unk_58; + unkStruct->unk_54 = (u32)Rand_Next() >> 0x10; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83D00.s") + sp90 = Math_SinS(unkStruct->unk_54) * unkStruct->unk_50; + sp8C = Math_CosS(unkStruct->unk_54) * unkStruct->unk_50; + unkStruct->unk_38 += sp90; + unkStruct->unk_3C += sp8C; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Update.s") + unkStruct->unk_38 += unkStruct->unk_30 * unkStruct->unk_40; + unkStruct->unk_3C += unkStruct->unk_34 * unkStruct->unk_40; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83E7C.s") + unkStruct->unk_38 *= unkStruct->unk_44; + unkStruct->unk_3C *= unkStruct->unk_44; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Draw.s") + unkStruct->unk_30 += unkStruct->unk_38; + unkStruct->unk_34 += unkStruct->unk_3C; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83FBC.s") + unkStruct->unk_30 = CLAMP(unkStruct->unk_30, -5.0f, 5.0f); + unkStruct->unk_34 = CLAMP(unkStruct->unk_34, -5.0f, 5.0f); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A84088.s") + func_80A81A00(this); + func_80A81AA4(this); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A84338.s") + if ((unkStruct->unk_5C > -0.000001f) && + (unkStruct->unk_5C <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, + this->actor.home.pos.x, this->actor.home.pos.z))) { + Actor_UpdateBgCheckInfo(globalCtx, &this->actor, 0.0f, 20.0f, 0.0f, 1); + + if (this->actor.bgCheckFlags & 8) { + if (this->actor.wallPoly != NULL) { + Vec3f sp70; + Vec3f sp64; + Vec3f sp58; + Vec3f sp4C; + f32 sp48; + f32 sp44; + + sp4C.x = unkStruct->unk_38; + sp4C.y = 0.0f; + sp4C.z = unkStruct->unk_3C; + if (func_80A81288(&sp4C, &sp70, &sp48, &sp44)) { + sp58.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); + sp58.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); + sp58.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); + func_80179F64(&sp70, &sp58, &sp64); + sp48 *= 0.5f; + unkStruct->unk_38 = sp64.x * sp48; + unkStruct->unk_3C = sp64.z * sp48; + } else { + unkStruct->unk_38 *= -0.1f; + unkStruct->unk_3C *= -0.1f; + } + func_80A81B14(this); + func_80A81A00(this); + func_80A81AA4(this); + } + } + } + + for (i = 0, temp = &unkStruct->unk_60[0]; i < spA0; i++, temp++) { + sp86 = temp->unk_00 - 0x4000; + sp88 = ((Rand_ZeroOne() * 30.0f) - 15.0f) + (temp->unk_02 + (sp86 * -0.05f)); + sp88 *= 0.995f; + temp->unk_02 = sp88; + temp->unk_00 += temp->unk_02; + } + + func_800B4AEC(globalCtx, &this->actor, 0.0f); + func_80A81818(this); + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + } +} + +void func_80A83A74(ObjMine* this) { + this->actionFunc = func_80A83A88; +} + +void func_80A83A88(ObjMine* this, GlobalContext* globalCtx) { + if (func_80A8140C(this)) { + func_80A81384(this, globalCtx); + func_80A81640(this); + func_80A83214(this); + } else { + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + } +} + +void func_80A83B14(ObjMine* this) { + this->actionFunc = func_80A83B28; +} + +void func_80A83B28(ObjMine* this, GlobalContext* globalCtx) { + ObjMineUnkStruct* ptr; + s16 rand; + + if (func_80A8140C(this)) { + func_80A81384(this, globalCtx); + func_80A81640(this); + func_80A83214(this); + return; + } + + ptr = &this->unk_1B8; + if (this->collider.base.acFlags & AC_HIT) { + this->collider.base.acFlags &= ~AC_HIT; + func_80A81544(this, (Vec3f*)&ptr->unk_00.y); + ptr->unk_0C.y = 7.0f; + Math_Vec3f_Scale((Vec3f*)&ptr->unk_00.y, 7.0f); + } + + if (ptr->unk_0C.y > 0.0001f) { + ptr->unk_0C.y = Math_Vec3f_StepTo((Vec3f*)&ptr->unk_00.y, &D_801D15B0, 2.8f); + } + + ptr->unk_00.x = 0.9f; + ptr->unk_24.x = -0.0002f; + ptr->unk_30 = -0.0002f; + ptr->unk_18.y = 0.003f; + if (!((u32)Rand_Next() >> 0x1B)) { + rand = (u32)Rand_Next() >> 0x10; + ptr->unk_0C.z = Math_SinS(rand) * 1.8f * ptr->unk_18.y; + ptr->unk_18.x = Math_CosS(rand) * 0.2f * ptr->unk_18.y; + *(s16*)((u8*)ptr + 0x20) = (u32)Rand_Next() >> 0x13; + } + + func_80A82C28(this, globalCtx); + func_80A81DEC(this); + func_80A81818(this); + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); +} + +void func_80A83CEC(ObjMine* this) { + this->actionFunc = func_80A83D00; +} + +void func_80A83D00(ObjMine* this, GlobalContext* globalCtx) { + if (func_80A8140C(this)) { + func_80A81384(this, globalCtx); + func_80A81640(this); + func_80A83214(this); + } else { + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + } +} + +void ObjMine_Update(Actor* thisx, GlobalContext* globalCtx) { + s32 pad; + ObjMine* this = THIS; + + if ((this->collider.base.ocFlags2 & OC2_HIT_PLAYER) || (this->collider.base.acFlags & AC_HIT)) { + func_80A8131C(this, globalCtx); + func_80A83214(this); + } + + this->actionFunc(this, globalCtx); + + if (this->actor.update != NULL) { + this->collider.base.ocFlags1 &= ~OC1_HIT; + this->collider.base.acFlags &= ~AC_HIT; + this->collider.base.ocFlags2 &= ~OC2_HIT_PLAYER; + if ((this->actor.flags & 0x40) && (this->actionFunc != func_80A83258)) { + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + } + } +} + +void func_80A83E7C(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + + this->actionFunc(this, globalCtx); +} + +void ObjMine_Draw(Actor* thisx, GlobalContext* globalCtx) { + s32 pad; + ObjMine* this = THIS; + + OPEN_DISPS(globalCtx->state.gfxCtx); + + if (this->actionFunc == func_80A82FC8) { + Collider_UpdateSpheres(0, &this->collider); + } + + func_800B8050(&this->actor, globalCtx, 1); + func_8012C28C(globalCtx->state.gfxCtx); + + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gDPSetRenderMode(POLY_OPA_DISP++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); + gSPDisplayList(POLY_OPA_DISP++, D_06002068); + gSPDisplayList(POLY_OPA_DISP++, D_06002188); + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} + +void func_80A83FBC(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + + OPEN_DISPS(globalCtx->state.gfxCtx); + + func_800B8118(&this->actor, globalCtx, 1); + func_8012C2DC(globalCtx->state.gfxCtx); + + gDPSetRenderMode(POLY_XLU_DISP++, G_RM_PASS, G_RM_AA_ZB_XLU_SURF2); + gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 0, 75); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(POLY_XLU_DISP++, D_06002068); + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} + +void func_80A84088(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + s32 temp_s5 = this->actor.params & 0x3F; + ObjMineUnkStruct3* temp; + ObjMineUnkStruct* ptr = &this->unk_1B8; + s32 pad; + s32 i; + Vec3f sp94; + Vec3f sp88; + Gfx* gfx; + + func_800B8050(&this->actor, globalCtx, 1); + + OPEN_DISPS(globalCtx->state.gfxCtx); + gfx = POLY_OPA_DISP; + + gSPDisplayList(gfx++, &sSetupDL[6 * 25]); + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, D_06000030); + + func_80A81684(ptr); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + if (temp_s5 != 0) { + Math_Vec3f_ScaleAndStore(&ptr->unk_0C, -6.0f, &sp88); + sp94.x = this->actor.home.pos.x - sp88.x; + sp94.y = (this->actor.home.pos.y - 6.0f) - sp88.y; + sp94.z = this->actor.home.pos.z - sp88.z; + Math_Vec3f_ScaleAndStore(&ptr->unk_0C, -12.0f, &sp88); + + for (i = 0, temp = &ptr->unk_60[0]; i < temp_s5; i++, temp++) { + Matrix_RotateY(temp->unk_00, MTXMODE_APPLY); + sp94.x += sp88.x; + sp94.y += sp88.y; + sp94.z += sp88.z; + func_80A8164C(&sp94); + + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, D_06000030); + } + } + + SysMatrix_InsertXRotation_s(0x2000, MTXMODE_APPLY); + func_80A8164C(&this->actor.world.pos); + + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gDPPipeSync(gfx++); + gDPSetRenderMode(gfx++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); + gDPSetEnvColor(gfx++, 0, 0, 0, 255); + gSPDisplayList(gfx++, D_06002068); + gSPDisplayList(gfx++, D_06002188); + + POLY_OPA_DISP = gfx; + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} + +void func_80A84338(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + s32 temp_s7 = this->actor.params & 0x3F; + s32 i; + Gfx* gfx; + ObjMineUnkStruct2* temp; + s32 pad[2]; + + func_800B8050(&this->actor, globalCtx, 1); + + OPEN_DISPS(globalCtx->state.gfxCtx); + gfx = POLY_OPA_DISP; + + gSPDisplayList(gfx++, &sSetupDL[6 * 25]); + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, D_06000030); + + for (i = 0, temp = (ObjMineUnkStruct2*)((u8*)this + 0x1FC); i < temp_s7; i++, temp++) { + func_80A81684((ObjMineUnkStruct*)temp); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, 1); + if ((i & 1) == 0) { + Matrix_RotateY(0x4000, 1); + } + func_80A8164C(&temp->unk_24); + + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, D_06000030); + } + + SysMatrix_InsertXRotation_s(0x2000, 1); + func_80A8164C(&this->actor.world.pos); + + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gDPPipeSync(gfx++); + gDPSetRenderMode(gfx++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); + gDPSetEnvColor(gfx++, 0, 0, 0, 255); + gSPDisplayList(gfx++, D_06002068); + gSPDisplayList(gfx++, D_06002188); + + POLY_OPA_DISP = gfx; + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index 4b7f8ee3d..af2772fda 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -7,11 +7,67 @@ struct ObjMine; typedef void (*ObjMineActionFunc)(struct ObjMine*, GlobalContext*); +// definitely fake +typedef struct { + char unk_00[0x8]; + Vec3f unk_08; + char unk_14[0xC]; + Vec3f unk_20; + char unk_2C[0x1C]; +} NextUnkStruct; // size = 0x48 + +// maybe fake +typedef struct { + /* 0x00 */ s16 unk_00; + /* 0x02 */ s16 unk_02; +} ObjMineUnkStruct3; + +typedef struct { + /* 0x00 */ Vec3f unk_00; + /* 0x0C */ Vec3f unk_0C; + /* 0x18 */ Vec3f unk_18; + ///* 0x24 */ char unk_24[0x3C]; + /* 0x24 */ Vec3f unk_24; + /* 0x30 */ f32 unk_30; + /* 0x34 */ f32 unk_34; + /* 0x38 */ f32 unk_38; + /* 0x3C */ f32 unk_3C; + /* 0x40 */ f32 unk_40; + /* 0x44 */ f32 unk_44; + /* 0x48 */ f32 unk_48; + /* 0x4C */ s16 unk_4C; + /* 0x50 */ f32 unk_50; + /* 0x54 */ s16 unk_54; + /* 0x58 */ f32 unk_58; + /* 0x5C */ f32 unk_5C; + /* 0x60 */ ObjMineUnkStruct3 unk_60[1]; +} ObjMineUnkStruct; // size = ?? 0x44??? 48 array??? + +// probably fake +typedef struct { + /* 0x00 */ Vec3f unk_00; + /* 0x0c */ Vec3f unk_0C; + ///* 0x10 */ f32 unk_10; + ///* 0x14 */ char unk_14[0x4]; + /* 0x18 */ Vec3f unk_18; + ///* 0x1C */ char unk_1C[0x4]; + ///* 0x20 */ f32 unk_20; + /* 0x24 */ Vec3f unk_24; + /* 0x30 */ Vec3f unk_30; + /* 0x3C */ Vec3f unk_3C; +} ObjMineUnkStruct2; // size = 0x48??? + typedef struct ObjMine { /* 0x0000 */ Actor actor; - /* 0x0144 */ char unk_144[0x60]; + /* 0x0144 */ ColliderJntSph collider; + /* 0x0164 */ ColliderJntSphElement colliderElements[1]; /* 0x01A4 */ ObjMineActionFunc actionFunc; - /* 0x01A8 */ char unk_1A8[0x120C]; + /* 0x01A8 */ f32 unk_1A8; + /* 0x01AC */ s32 unk_1AC; + /* 0x01B0 */ s32 unk_1B0; + /* 0x01B4 */ Vec3s* unk_1B4; + /* 0x01B8 */ ObjMineUnkStruct unk_1B8; // array?? + /* 0x021C */ char unk_21C[0x1198]; } ObjMine; // size = 0x13B4 extern const ActorInit Obj_Mine_InitVars; From aa020a6c43023c3a35df19bc79c126e849c2465b Mon Sep 17 00:00:00 2001 From: Maide Date: Tue, 28 Sep 2021 21:01:36 +0100 Subject: [PATCH 02/26] Obj_Mine --- spec | 6 +- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 1052 ++++++++++++++++- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 60 +- 3 files changed, 1054 insertions(+), 64 deletions(-) diff --git a/spec b/spec index 1c64ca1e8..115bce29e 100644 --- a/spec +++ b/spec @@ -3103,9 +3103,11 @@ beginseg name "ovl_Obj_Mine" compress include "build/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.o" - include "build/data/ovl_Obj_Mine/ovl_Obj_Mine.data.o" - include "build/data/ovl_Obj_Mine/ovl_Obj_Mine.bss.o" +#ifdef NON_MATCHING + include "build/src/overlays/actors/ovl_Obj_Mine/ovl_Obj_Mine_reloc.o" +#else include "build/data/ovl_Obj_Mine/ovl_Obj_Mine.reloc.o" +#endif endseg beginseg diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 5b5e80d39..a1a35a780 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -5,6 +5,7 @@ */ #include "z_obj_mine.h" +#include "overlays/actors/ovl_En_Bom/z_en_bom.h" #define FLAGS 0x00000000 @@ -15,7 +16,30 @@ void ObjMine_Destroy(Actor* thisx, GlobalContext* globalCtx); void ObjMine_Update(Actor* thisx, GlobalContext* globalCtx); void ObjMine_Draw(Actor* thisx, GlobalContext* globalCtx); -#if 0 +void func_80A82F84(ObjMine* this); +void func_80A82F98(ObjMine* this, GlobalContext* globalCtx); +void func_80A82FA8(ObjMine* this); +void func_80A82FC8(ObjMine* this, GlobalContext* globalCtx); +void func_80A83258(ObjMine* this, GlobalContext* globalCtx); +void func_80A832BC(ObjMine* this); +void func_80A832D0(ObjMine* this, GlobalContext* globalCtx); +void func_80A83A74(ObjMine* this); +void func_80A83A88(ObjMine* this, GlobalContext* globalCtx); +void func_80A83B14(ObjMine* this); +void func_80A83B28(ObjMine* this, GlobalContext* globalCtx); +void func_80A83CEC(ObjMine* this); +void func_80A83D00(ObjMine* this, GlobalContext* globalCtx); +void func_80A83E7C(Actor* thisx, GlobalContext* globalCtx); +void func_80A83FBC(Actor* thisx, GlobalContext* globalCtx); +void func_80A84088(Actor* thisx, GlobalContext* globalCtx); +void func_80A84338(Actor* thisx, GlobalContext* globalCtx); + +extern Gfx D_06000030[]; +extern Gfx D_06002068[]; +extern Gfx D_06002188[]; + +static s32 D_80A849D0[0xC0]; + const ActorInit Obj_Mine_InitVars = { ACTOR_OBJ_MINE, ACTORCAT_PROP, @@ -28,127 +52,1035 @@ const ActorInit Obj_Mine_InitVars = { (ActorFunc)ObjMine_Draw, }; -// static ColliderJntSphElementInit sJntSphElementsInit[1] = { -static ColliderJntSphElementInit D_80A84570[1] = { +static ColliderJntSphElementInit sJntSphElementsInit[1] = { { - { ELEMTYPE_UNK2, { 0x00000000, 0x00, 0x00 }, { 0x01CBFFBE, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_ON, }, + { + ELEMTYPE_UNK2, + { 0x00000000, 0x00, 0x00 }, + { 0x01CBFFBE, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_ON, + }, { 0, { { 0, 0, 0 }, 30 }, 100 }, }, }; -// static ColliderJntSphInit sJntSphInit = { -static ColliderJntSphInit D_80A84594 = { - { COLTYPE_METAL, AT_NONE, AC_ON | AC_TYPE_PLAYER, OC1_ON | OC1_TYPE_PLAYER | OC1_TYPE_1, OC2_TYPE_1, COLSHAPE_JNTSPH, }, - 1, D_80A84570, // sJntSphElementsInit, +static ColliderJntSphInit sJntSphInit = { + { + COLTYPE_METAL, + AT_NONE, + AC_ON | AC_TYPE_PLAYER, + OC1_ON | OC1_TYPE_PLAYER | OC1_TYPE_1, + OC2_TYPE_1, + COLSHAPE_JNTSPH, + }, + 1, + sJntSphElementsInit, }; -// static InitChainEntry sInitChain[] = { -static InitChainEntry D_80A845E8[] = { +static f32 D_80A845A4[] = { + 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, +}; + +static Vec3f D_80A845C4 = { 1.0f, 0.0f, 0.0f }; + +static Vec3f D_80A845D0[] = { + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 0.0f, 1.0f }, +}; + +static InitChainEntry sInitChain[] = { ICHAIN_F32(uncullZoneForward, 1300, ICHAIN_CONTINUE), ICHAIN_F32(uncullZoneScale, 150, ICHAIN_CONTINUE), ICHAIN_F32(uncullZoneDownward, 100, ICHAIN_CONTINUE), ICHAIN_VEC3F_DIV1000(scale, 10, ICHAIN_STOP), }; +void func_80A811D0(ObjMine* this, s32 arg1) { + Math_Vec3s_ToVec3f(&this->actor.world.pos, &this->unk_1B4[arg1]); +} + +s32 func_80A8120C(Vec3f* arg0, Vec3f* arg1) { + f32 temp_f0 = Math3D_Vec3fMagnitude(arg0); + + if (temp_f0 < 0.001f) { + return false; + } + + arg1->x = arg0->x * (1.0f / temp_f0); + arg1->y = arg0->y * (1.0f / temp_f0); + arg1->z = arg0->z * (1.0f / temp_f0); + return true; +} + +s32 func_80A81288(Vec3f* arg0, Vec3f* arg1, f32* arg2, f32* arg3) { + f32 temp_f0 = Math3D_Vec3fMagnitude(arg0); + + if (temp_f0 < 0.001f) { + return false; + } + + arg1->x = arg0->x * (1.0f / temp_f0); + arg1->y = arg0->y * (1.0f / temp_f0); + arg1->z = arg0->z * (1.0f / temp_f0); + *arg2 = temp_f0; + *arg3 = 1.0f / temp_f0; + + return true; +} + +void func_80A8131C(ObjMine* this, GlobalContext* globalCtx) { + EnBom* bomb = (EnBom*)Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_BOM, this->actor.world.pos.x, + this->actor.world.pos.y - 15.0f, this->actor.world.pos.z, 0, 0, 0, 0); + + if (bomb != NULL) { + bomb->timer = 0; + } +} + +void func_80A81384(ObjMine* this, GlobalContext* globalCtx) { + f32 x = this->collider.elements[0].dim.worldSphere.center.x; + f32 y = this->collider.elements[0].dim.worldSphere.center.y - 15.0f; + f32 z = this->collider.elements[0].dim.worldSphere.center.z; + + EnBom* bom = (EnBom*)Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_BOM, x, y, z, 0, 0, 0, 0); + + if (bom != NULL) { + bom->timer = 0; + } +} + +s32 func_80A8140C(ObjMine* this) { + if (this->collider.base.ocFlags2 & OC2_HIT_PLAYER) { + return true; + } + + if ((this->collider.base.ocFlags1 & OC2_UNK1)) { + Actor* mine = this->collider.base.oc; + + if ((mine->id == ACTOR_OBJ_MINE) && (mine->room == this->actor.room)) { + return true; + } + } + + return false; +} + +void func_80A8146C(ObjMine* this, s16* arg1, s16* arg2) { + s32 pad2[3]; + Vec3f sp40; + s16 sp3E; + s16 pad; + Actor* temp_s0 = this->collider.base.ac; + + Math_Vec3s_ToVec3f(&sp40, &this->collider.elements[0].dim.worldSphere.center); + sp3E = Math_Vec3f_Yaw(&temp_s0->world.pos, &sp40); + + if (this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820) { + *arg1 = temp_s0->shape.rot.y; + *arg2 = temp_s0->shape.rot.y - sp3E; + } else { + Vec3f sp2C; + Vec3s* hitPos = &this->collider.elements[0].info.bumper.hitPos; + + Math_Vec3s_ToVec3f(&sp2C, hitPos); + *arg1 = Actor_YawBetweenActors(temp_s0, &this->actor); + *arg2 = Math_Vec3f_Yaw(&temp_s0->world.pos, &sp2C) - sp3E; + } +} + +#ifdef NON_MATCHING +// stack, 1 var needs to go without changing code gen +void func_80A81544(ObjMine* this, Vec3f* arg1) { + ColliderJntSphElement* element = &this->collider.elements[0]; + Vec3s* sphere = &element->dim.worldSphere.center; + Actor* temp_v1 = this->collider.base.ac; + + if ((element->info.acHitInfo->toucher.dmgFlags & 0x13820)) { + SysMatrix_StatePush(); + Matrix_RotateY(temp_v1->shape.rot.y, MTXMODE_NEW); + SysMatrix_InsertXRotation_s(temp_v1->shape.rot.x, MTXMODE_APPLY); + SysMatrix_GetStateTranslationAndScaledZ(1.0f, arg1); + SysMatrix_StatePop(); + } else { + Vec3f sp20; + + sp20.x = sphere->x - temp_v1->world.pos.x; + sp20.y = sphere->y - temp_v1->world.pos.y; + sp20.z = sphere->z - temp_v1->world.pos.z; + if (!func_80A8120C(&sp20, arg1)) { + Math_Vec3f_Copy(arg1, D_80A845D0); + } + } +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81544.s") #endif -extern ColliderJntSphElementInit D_80A84570[1]; -extern ColliderJntSphInit D_80A84594; -extern InitChainEntry D_80A845E8[]; +void func_80A81640(ObjMine* this) { +} -extern UNK_TYPE D_06000030; -extern UNK_TYPE D_06002068; +void func_80A8164C(Vec3f* arg0) { + MtxF* matrix = SysMatrix_GetCurrentState(); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A811D0.s") + matrix->mf[3][0] = arg0->x; + matrix->mf[3][1] = arg0->y; + matrix->mf[3][2] = arg0->z; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8120C.s") +void func_80A81684(ObjMineUnkStruct* arg0) { + MtxF* matrix = SysMatrix_GetCurrentState(); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81288.s") + matrix->mf[0][0] = arg0->unk_00.x; + matrix->mf[0][1] = arg0->unk_00.y; + matrix->mf[0][2] = arg0->unk_00.z; + matrix->mf[0][3] = 0.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8131C.s") + matrix->mf[1][0] = arg0->unk_0C.x; + matrix->mf[1][1] = arg0->unk_0C.y; + matrix->mf[1][2] = arg0->unk_0C.z; + matrix->mf[1][3] = 0.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81384.s") + matrix->mf[2][0] = arg0->unk_18.x; + matrix->mf[2][1] = arg0->unk_18.y; + matrix->mf[2][2] = arg0->unk_18.z; + matrix->mf[2][3] = 0.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8140C.s") + matrix->mf[3][0] = 0.0f; + matrix->mf[3][1] = 0.0f; + matrix->mf[3][2] = 0.0f; + matrix->mf[3][3] = 1.0f; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8146C.s") +s32 func_80A81714(Vec3f* arg0, Vec3f* arg1, f32 arg2) { + Vec3f sp3C; + Vec3f sp30; + Vec3f sp24; + f32 sp20 = Math3D_Parallel(arg0, arg1); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81544.s") + if (cos_rad(arg2) <= sp20) { + Math_Vec3f_Copy(arg0, arg1); + return true; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81640.s") + SysMatrix_StatePush(); + Math_Vec3f_Copy(&sp30, arg0); + Math3D_CrossProduct(arg0, arg1, &sp3C); + if (func_80A8120C(&sp3C, &sp24)) { + SysMatrix_InsertRotationAroundUnitVector_s(arg2 * 10430.378f, &sp24, MTXMODE_NEW); + SysMatrix_MultiplyVector3fByState(&sp30, arg0); + } else { + SysMatrix_SetStateXRotation(arg2); + SysMatrix_MultiplyVector3fByState(&sp30, arg0); + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A8164C.s") + SysMatrix_StatePop(); + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81684.s") +void func_80A81818(ObjMine* this) { + this->collider.elements->dim.worldSphere.center.x = this->actor.world.pos.x; + this->collider.elements->dim.worldSphere.center.y = this->actor.world.pos.y; + this->collider.elements->dim.worldSphere.center.z = this->actor.world.pos.z; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81714.s") +void func_80A81868(ObjMine* this, s32 arg1) { + s32 i; + ObjMineUnkStruct* ptr = &this->unk_1B8; + ObjMineUnkStruct3* unkStruct; + f32 arg = arg1; + f32 temp_f12 = this->actor.home.rot.z * 5.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81818.s") + ptr->unk_00.x = 1.0f; + ptr->unk_0C.y = 1.0f; + ptr->unk_18.z = 1.0f; + ptr->unk_24.y = 1.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81868.s") + if (arg1 > 0) { + ptr->unk_40 = -sqrtf(0.001984f / arg); + ptr->unk_44 = (0.00031746097f * arg) + 0.95f; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A819A4.s") + ptr->unk_58 = 0.0002f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81A00.s") + for (i = 0, unkStruct = &ptr->unk_60[0]; i < arg1; i++, unkStruct++) { + unkStruct->unk_00 = 0x4000; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81AA4.s") + if (temp_f12 < 0.0f) { + ptr->unk_5C = -1.0f; + } else if (temp_f12 <= 21.0f) { + ptr->unk_5C = 0.0f; + } else { + ptr->unk_5C = SQ(temp_f12 - 20.0f); + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81B14.s") +void func_80A819A4(ObjMine* this, s32 arg1) { + SysMatrix_InsertTranslation(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, MTXMODE_NEW); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + Collider_UpdateSpheres(0, &this->collider); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81B7C.s") +void func_80A81A00(ObjMine* this) { + ObjMineUnkStruct* ptr = &this->unk_1B8; + Vec3f sp28; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81D70.s") + sp28.x = -ptr->unk_30; + sp28.y = 1.0f; + sp28.z = -ptr->unk_34; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81DEC.s") + func_80A8120C(&sp28, &ptr->unk_0C); + Math3D_CrossProduct(&D_80A845C4, &ptr->unk_0C, &sp28); + func_80A8120C(&sp28, &ptr->unk_18); + Math3D_CrossProduct(&ptr->unk_0C, &ptr->unk_18, &sp28); + func_80A8120C(&sp28, &ptr->unk_00); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81E7C.s") +void func_80A81AA4(ObjMine* this) { + s32 params = this->actor.params & 0x3F; + f32 temp_f0 = -((params * 12.0f) + 10.0f); + + this->actor.world.pos.x = (this->unk_1B8.unk_0C.x * temp_f0) + this->actor.home.pos.x; + this->actor.world.pos.y = (this->unk_1B8.unk_0C.y * temp_f0) + this->actor.home.pos.y; + this->actor.world.pos.z = (this->unk_1B8.unk_0C.z * temp_f0) + this->actor.home.pos.z; +} + +void func_80A81B14(ObjMine* this) { + s32 params = this->actor.params & 0x3F; + f32 temp_f0 = 1.0f / ((params * 12.0f) + 10.0f); + f32 x = this->actor.world.pos.x - this->actor.home.pos.x; + f32 z = this->actor.world.pos.z - this->actor.home.pos.z; + + this->unk_1B8.unk_30 = x * temp_f0; + this->unk_1B8.unk_34 = z * temp_f0; +} + +void func_80A81B7C(ObjMine* this, s32 arg1) { + ObjMineUnkStruct* ptr = &this->unk_1B8; + ObjMineUnkStruct2* unkStruct; + s32 i; + f32 sp58 = this->actor.home.rot.z * 5.0f; + f32 temp_f24; + f32 temp_f26; + + ptr->unk_00.x = 0.9f; + ptr->unk_18.y = 0.003f; + + *(s16*)((u8*)ptr + 0x20) = (u32)Rand_Next() >> 0x13; + ptr->unk_24.x = -0.0002f; + ptr->unk_30 = -0.0002f; + + temp_f26 = ptr->unk_18.y * 6.0f; + temp_f24 = this->actor.home.pos.y; + + unkStruct = (ObjMineUnkStruct2*)&ptr->unk_44; + for (i = 0; i < arg1; i++, unkStruct++) { + temp_f24 += 12.0f; + unkStruct->unk_00.x = 1.0f; + unkStruct->unk_0C.y = 1.0f; + unkStruct->unk_18.z = 1.0f; + unkStruct->unk_24.x = this->actor.home.pos.x; + unkStruct->unk_24.y = temp_f24; + unkStruct->unk_24.z = this->actor.home.pos.z; + unkStruct->unk_30.x = (Rand_ZeroOne() - 0.5f) * temp_f26; + unkStruct->unk_30.y = (Rand_ZeroOne() - 0.5f) * temp_f26; + unkStruct->unk_30.z = (Rand_ZeroOne() - 0.5f) * temp_f26; + } + + ptr->unk_24.y = temp_f24; + ptr->unk_24.z = temp_f24 * 0.97f; + temp_f24 = temp_f24 - 18.0f; + + if (ptr->unk_24.z < temp_f24) { + ptr->unk_24.z = temp_f24; + } + + if (sp58 < 0.0f) { + ptr->unk_34 = -1.0f; + } else if (sp58 <= 37.0f) { + ptr->unk_34 = 0.0f; + } else { + ptr->unk_34 = SQ(sp58 - 36.0f); + } +} + +void func_80A81D70(ObjMine* this, s32 arg1) { + SysMatrix_InsertTranslation(this->actor.home.pos.x, this->actor.home.pos.y + (arg1 * 12.0f) + 10.0f, + this->actor.home.pos.z, MTXMODE_NEW); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + Collider_UpdateSpheres(0, &this->collider); +} + +void func_80A81DEC(ObjMine* this) { + s32 pad[2]; + s32 temp_v0 = this->actor.params & 0x3F; + NextUnkStruct* temp_v1 = &((NextUnkStruct*)&this->unk_1B8)[temp_v0]; + + if (temp_v0 == 0) { + this->actor.world.pos.y = (this->actor.home.pos.y + 12.0f) + 10.0f; + } else { + Vec3f sp1C; + + Math_Vec3f_ScaleAndStore(&temp_v1->unk_08, 10.0f, &sp1C); + Math_Vec3f_Sum(&temp_v1->unk_20, &sp1C, &this->actor.world.pos); + } +} + +void func_80A81E7C(ObjMine* this, GlobalContext* globalCtx) { + ObjMineUnkStruct* temp_v1 = &this->unk_1B8; + s32 pad; + Vec3f sp7C; + Vec3f sp70; + Vec3f sp64; + Vec3f sp58; + Vec3f sp4C; + CollisionPoly* sp48; + u32 sp44; + f32 sp40; + f32 sp3C; + + *(s8*)(&temp_v1->unk_40) = 0; + if (temp_v1->unk_34 > -0.000001f) { + if (temp_v1->unk_34 <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, + this->actor.world.pos.x, this->actor.world.pos.z)) { + sp58.x = this->actor.world.pos.x - this->actor.home.pos.x; + sp58.y = 0.0f; + sp58.z = this->actor.world.pos.z - this->actor.home.pos.z; + if (func_80A81288(&sp58, &sp4C, &sp40, &sp3C)) { + sp70.x = this->actor.world.pos.x + (sp4C.x * 36.0f); + sp70.y = this->actor.world.pos.y; + sp70.z = this->actor.world.pos.z + (sp4C.z * 36.0f); + sp7C.x = this->actor.home.pos.x; + sp7C.y = this->actor.world.pos.y; + sp7C.z = this->actor.home.pos.z; + if (func_800C55C4(&globalCtx->colCtx, &sp7C, &sp70, &sp64, &sp48, 1, 0, 0, 1, &sp44)) { + *(s8*)(&temp_v1->unk_40) = 1; + temp_v1->unk_38 = sp4C.x * -0.2f; + temp_v1->unk_3C = sp4C.z * -0.2f; + } + } + } + } +} #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81FFC.s") -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A828A8.s") +void func_80A828A8(ObjMine* this) { + s32 pad; + Vec3f spE0; + Vec3f spD4; + Vec3f spC8; + s32 spC4 = this->actor.params & 0x3F; + s32 i = 0; + s32 phi_s5; + Vec3f* phi_s3 = NULL; + ObjMineUnkStruct* sp70 = &this->unk_1B8; + Vec3f spA8; + Vec3f sp9C; + Vec3f sp90; + Vec3f sp84; + ObjMineUnkStruct2* temp_s0 = (ObjMineUnkStruct2*)&sp70->unk_44; + f32 sp7C; + f32 sp78; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82C28.s") + sp84.x = this->actor.home.pos.x; + sp84.y = this->actor.home.pos.y + 6.0f; + sp84.z = this->actor.home.pos.z; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Init.s") + for (; i < spC4; i++, temp_s0++) { + phi_s5 = false; + temp_s0->unk_30.x += temp_s0->unk_3C.x; + temp_s0->unk_30.y += temp_s0->unk_3C.y; + temp_s0->unk_30.z += temp_s0->unk_3C.z; + Math_Vec3f_Scale(&temp_s0->unk_30, sp70->unk_00.x); + Math_Vec3f_Copy(&sp90, &temp_s0->unk_24); + temp_s0->unk_24.x += temp_s0->unk_30.x; + temp_s0->unk_24.y += temp_s0->unk_30.y; + temp_s0->unk_24.z += temp_s0->unk_30.z; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Destroy.s") + if ((temp_s0->unk_24.y <= this->actor.home.pos.y) && (temp_s0->unk_30.y < 0.0f)) { + temp_s0->unk_30.y *= 0.1f; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82F84.s") + Math_Vec3f_Diff(&temp_s0->unk_24, &sp84, &spA8); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82F98.s") + if (func_80A81288(&spA8, &sp9C, &sp7C, &sp78) && (sp7C > 4.0f)) { + Math_Vec3f_Copy(&spD4, &temp_s0->unk_0C); + func_80A81714(&spD4, &sp9C, 0.10471976f); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82FA8.s") + Math3D_CrossProduct((phi_s3 == NULL) ? &D_80A845C4 : phi_s3, &spD4, &spA8); + if (func_80A8120C(&spA8, &spE0)) { + Math3D_CrossProduct(&spD4, &spE0, &spA8); + if (func_80A8120C(&spA8, &spC8)) { + phi_s5 = true; + } + } + } + + if (phi_s5) { + Math_Vec3f_Copy(&temp_s0->unk_00, &spC8); + Math_Vec3f_Copy(&temp_s0->unk_0C, &spD4); + Math_Vec3f_Copy(&temp_s0->unk_18, &spE0); + } else { + sp7C = 4.0f; + } + + if (sp7C >= 6.0f) { + temp_s0->unk_24.x = (temp_s0->unk_0C.x * 6.0f) + sp84.x; + temp_s0->unk_24.y = (temp_s0->unk_0C.y * 6.0f) + sp84.y; + temp_s0->unk_24.z = (temp_s0->unk_0C.z * 6.0f) + sp84.z; + } else { + temp_s0->unk_24.x = (temp_s0->unk_0C.x * sp7C) + sp84.x; + temp_s0->unk_24.y = (temp_s0->unk_0C.y * sp7C) + sp84.y; + temp_s0->unk_24.z = (temp_s0->unk_0C.z * sp7C) + sp84.z; + } + + sp84.x = temp_s0->unk_24.x + (temp_s0->unk_0C.x * 6.0f); + sp84.y = temp_s0->unk_24.y + (temp_s0->unk_0C.y * 6.0f); + sp84.z = temp_s0->unk_24.z + (temp_s0->unk_0C.z * 6.0f); + + phi_s3 = &temp_s0->unk_00; + } +} + +void func_80A81FFC(ObjMine* this); + +void func_80A82C28(ObjMine* this, GlobalContext* globalCtx) { + func_80A81E7C(this, globalCtx); + func_80A81FFC(this); + func_80A828A8(this); +} + +void ObjMine_Init(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + s32 pad; + s32 sp44 = this->actor.params & 0xFF; + Path* path; + s32 sp3C; + s32 sp38 = (this->actor.params >> 0xC) & 3; + s32 sp34; + + Actor_ProcessInitChain(&this->actor, sInitChain); + this->actor.shape.rot.z = 0; + this->actor.world.rot.z = 0; + Collider_InitJntSph(globalCtx, &this->collider); + Collider_SetJntSph(globalCtx, &this->collider, &this->actor, &sJntSphInit, this->colliderElements); + + if (sp38 == 0) { + ActorShape_Init(&this->actor.shape, 0.0f, func_800B3FC0, 45.0f); + this->actor.shape.shadowAlpha = 140; + this->unk_1A8 = D_80A845A4[(this->actor.params >> 8) & 7]; + if (sp44 == 0xFF) { + func_80A82F84(this); + } else { + path = &globalCtx->setupPathList[sp44]; + this->unk_1B0 = 0; + this->unk_1AC = path->count - 1; + this->unk_1B4 = (Vec3s*)Lib_SegmentedToVirtual(path->points); + func_80A811D0(this, this->unk_1B0); + func_80A82FA8(this); + } + SysMatrix_SetStateRotationAndTranslation(this->actor.world.pos.x, this->actor.world.pos.y, + this->actor.world.pos.z, &this->actor.shape.rot); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + Collider_UpdateSpheres(0, &this->collider); + this->actor.floorHeight = + func_800C411C(&globalCtx->colCtx, &this->actor.floorPoly, &sp3C, &this->actor, &this->actor.world.pos); + } else { + sp34 = this->actor.params & 0x3F; + this->actor.update = func_80A83E7C; + this->actor.uncullZoneScale = (sp34 * 21.0f) + 150.0f; + this->actor.uncullZoneDownward = (sp34 * 21.0f) + 150.0f; + ActorShape_Init(&this->actor.shape, 0.0f, func_800B3FC0, 45.0f); + this->actor.shape.shadowAlpha = 0x8C; + + if (sp38 == 1) { + this->actor.draw = func_80A84088; + func_80A81868(this, sp34); + this->actor.world.pos.y = (-10.0f - (sp34 * 12.0f)) + this->actor.home.pos.y; + func_80A819A4(this, sp34); + func_800B4AEC(globalCtx, &this->actor, 0.0f); + if (sp34 == 0) { + func_80A83A74(this); + } else { + func_80A832BC(this); + } + } else { + this->actor.draw = func_80A84338; + func_80A81B7C(this, sp34); + this->actor.world.pos.y = (sp34 * 12.0f) + 10.0f + this->actor.home.pos.y; + func_80A81D70(this, sp34); + if (sp34 == 0) { + func_80A83CEC(this); + } else { + func_80A83B14(this); + } + } + } +} + +void ObjMine_Destroy(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + + Collider_DestroyJntSph(globalCtx, &this->collider); +} + +void func_80A82F84(ObjMine* this) { + this->actionFunc = func_80A82F98; +} + +void func_80A82F98(ObjMine* this, GlobalContext* globalCtx) { +} + +void func_80A82FA8(ObjMine* this) { + this->actor.flags |= 0x10; + this->actionFunc = func_80A82FC8; +} + +#ifdef NON_MATCHING +// stack +void func_80A82FC8(ObjMine* this, GlobalContext* globalCtx) { + f32 phi_f0; + Vec3f spA0; + f32 sp9C; + s32 pad; + f32 phi_f12; + s32 sp90; + Vec3f sp84; + Vec3f sp78; + MtxF sp38; + + Math_Vec3s_ToVec3f(&spA0, &this->unk_1B4[this->unk_1B0 + 1]); + Math_Vec3f_Diff(&spA0, &this->actor.world.pos, &this->actor.velocity); + + sp9C = Math3D_Vec3fMagnitude(&this->actor.velocity); + if ((sp9C < (this->unk_1A8 * 8.0f)) && (this->unk_1A8 > 2.0f)) { + phi_f0 = ((this->unk_1A8 - 2.0f) * 0.1f) + 2.0f; + phi_f12 = this->unk_1A8 * 0.03f; + } else { + phi_f0 = this->unk_1A8; + phi_f12 = this->unk_1A8 * 0.16f; + } + + Math_StepToF(&this->actor.speedXZ, phi_f0, phi_f12); + + if ((this->actor.speedXZ + 0.05f) < sp9C) { + Math_Vec3f_Scale(&this->actor.velocity, this->actor.speedXZ / sp9C); + this->actor.world.pos.x += this->actor.velocity.x; + this->actor.world.pos.y += this->actor.velocity.y; + this->actor.world.pos.z += this->actor.velocity.z; + } else { + this->actor.speedXZ *= 0.4f; + this->unk_1B0++; + if (this->unk_1B0 >= this->unk_1AC) { + this->unk_1B0 = 0; + } + func_80A811D0(this, this->unk_1B0); + } + + this->actor.floorHeight = + func_800C411C(&globalCtx->colCtx, &this->actor.floorPoly, &sp90, &this->actor, &this->actor.world.pos); + + if (this->actor.flags & 0x40) { + Math3D_CrossProduct(&D_80A845D0[0], &this->actor.velocity, &sp78); + if (func_80A8120C(&sp78, &sp84)) { + SysMatrix_InsertRotationAroundUnitVector_f(this->actor.speedXZ * 0.03125f, &sp84, MTXMODE_NEW); + Matrix_RotateY(this->actor.shape.rot.y, MTXMODE_APPLY); + SysMatrix_InsertXRotation_s(this->actor.shape.rot.x, MTXMODE_APPLY); + SysMatrix_InsertZRotation_s(this->actor.shape.rot.z, MTXMODE_APPLY); + SysMatrix_CopyCurrentState(&sp38); + func_8018219C(&sp38, &this->actor.shape.rot, 0); + } + } +} +#else #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82FC8.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83214.s") +void func_80A83214(ObjMine* this) { + this->actor.flags |= 0x10; + this->actor.draw = func_80A83FBC; + this->actor.shape.shadowDraw = NULL; + this->actor.scale.x = 0.02f; + this->actor.scale.y = 0.02f; + this->actor.scale.z = 0.02f; + this->actionFunc = func_80A83258; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83258.s") +void func_80A83258(ObjMine* this, GlobalContext* globalCtx) { + this->actor.scale.x *= 1.8f; + if (this->actor.scale.x > 0.17495999f) { + Actor_MarkForDeath(&this->actor); + } else { + this->actor.scale.y = this->actor.scale.x; + this->actor.scale.z = this->actor.scale.x; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A832BC.s") +void func_80A832BC(ObjMine* this) { + this->actionFunc = func_80A832D0; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A832D0.s") +void func_80A832D0(ObjMine* this, GlobalContext* globalCtx) { + s32 pad; + s32 spA0 = this->actor.params & 0x3F; + ObjMineUnkStruct* unkStruct = &this->unk_1B8; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83A74.s") + Math_Vec3f_Copy(&unkStruct->unk_24, &unkStruct->unk_0C); + if (func_80A8140C(this)) { + func_80A81384(this, globalCtx); + func_80A81640(this); + func_80A83214(this); + } else { + ObjMineUnkStruct3* temp; + s32 i; + f32 sp90; + f32 sp8C; + f32 sp88; + s16 sp86; + s16 sp84; + s32 pad2; + s32 pad3; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83A88.s") + if (this->collider.base.acFlags & AC_HIT) { + this->collider.base.acFlags &= ~AC_HIT; + unkStruct->unk_48 = 0.04f; + func_80A8146C(this, &unkStruct->unk_4C, &sp84); + sp8C = Math_SinS(sp84) * 150.0f; + sp88 = sp8C; + sp8C = -(sp8C / spA0); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83B14.s") + for (i = 0, temp = &unkStruct->unk_60[0]; i < spA0; i++, temp++) { + temp->unk_02 += (s16)sp88; + temp->unk_02 = CLAMP(temp->unk_02, -800, 800); + sp88 -= sp8C; + } + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83B28.s") + if (unkStruct->unk_48 > 0.0001f) { + sp90 = Math_SinS(unkStruct->unk_4C) * unkStruct->unk_48; + sp8C = Math_CosS(unkStruct->unk_4C) * unkStruct->unk_48; + unkStruct->unk_38 += sp90; + unkStruct->unk_3C += sp8C; + Math_StepToF(&unkStruct->unk_48, 0.0f, 0.02f); + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83CEC.s") + if ((u32)Rand_Next() >> 0x1B == 0) { + unkStruct->unk_50 = Rand_ZeroOne() * unkStruct->unk_58; + unkStruct->unk_54 = (u32)Rand_Next() >> 0x10; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83D00.s") + sp90 = Math_SinS(unkStruct->unk_54) * unkStruct->unk_50; + sp8C = Math_CosS(unkStruct->unk_54) * unkStruct->unk_50; + unkStruct->unk_38 += sp90; + unkStruct->unk_3C += sp8C; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Update.s") + unkStruct->unk_38 += unkStruct->unk_30 * unkStruct->unk_40; + unkStruct->unk_3C += unkStruct->unk_34 * unkStruct->unk_40; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83E7C.s") + unkStruct->unk_38 *= unkStruct->unk_44; + unkStruct->unk_3C *= unkStruct->unk_44; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Draw.s") + unkStruct->unk_30 += unkStruct->unk_38; + unkStruct->unk_34 += unkStruct->unk_3C; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A83FBC.s") + unkStruct->unk_30 = CLAMP(unkStruct->unk_30, -5.0f, 5.0f); + unkStruct->unk_34 = CLAMP(unkStruct->unk_34, -5.0f, 5.0f); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A84088.s") + func_80A81A00(this); + func_80A81AA4(this); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A84338.s") + if ((unkStruct->unk_5C > -0.000001f) && + (unkStruct->unk_5C <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, + this->actor.home.pos.x, this->actor.home.pos.z))) { + Actor_UpdateBgCheckInfo(globalCtx, &this->actor, 0.0f, 20.0f, 0.0f, 1); + + if (this->actor.bgCheckFlags & 8) { + if (this->actor.wallPoly != NULL) { + Vec3f sp70; + Vec3f sp64; + Vec3f sp58; + Vec3f sp4C; + f32 sp48; + f32 sp44; + + sp4C.x = unkStruct->unk_38; + sp4C.y = 0.0f; + sp4C.z = unkStruct->unk_3C; + if (func_80A81288(&sp4C, &sp70, &sp48, &sp44)) { + sp58.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); + sp58.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); + sp58.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); + func_80179F64(&sp70, &sp58, &sp64); + sp48 *= 0.5f; + unkStruct->unk_38 = sp64.x * sp48; + unkStruct->unk_3C = sp64.z * sp48; + } else { + unkStruct->unk_38 *= -0.1f; + unkStruct->unk_3C *= -0.1f; + } + func_80A81B14(this); + func_80A81A00(this); + func_80A81AA4(this); + } + } + } + + for (i = 0, temp = &unkStruct->unk_60[0]; i < spA0; i++, temp++) { + sp86 = temp->unk_00 - 0x4000; + sp88 = ((Rand_ZeroOne() * 30.0f) - 15.0f) + (temp->unk_02 + (sp86 * -0.05f)); + sp88 *= 0.995f; + temp->unk_02 = sp88; + temp->unk_00 += temp->unk_02; + } + + func_800B4AEC(globalCtx, &this->actor, 0.0f); + func_80A81818(this); + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + } +} + +void func_80A83A74(ObjMine* this) { + this->actionFunc = func_80A83A88; +} + +void func_80A83A88(ObjMine* this, GlobalContext* globalCtx) { + if (func_80A8140C(this)) { + func_80A81384(this, globalCtx); + func_80A81640(this); + func_80A83214(this); + } else { + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + } +} + +void func_80A83B14(ObjMine* this) { + this->actionFunc = func_80A83B28; +} + +void func_80A83B28(ObjMine* this, GlobalContext* globalCtx) { + ObjMineUnkStruct* ptr; + s16 rand; + + if (func_80A8140C(this)) { + func_80A81384(this, globalCtx); + func_80A81640(this); + func_80A83214(this); + return; + } + + ptr = &this->unk_1B8; + if (this->collider.base.acFlags & AC_HIT) { + this->collider.base.acFlags &= ~AC_HIT; + func_80A81544(this, (Vec3f*)&ptr->unk_00.y); + ptr->unk_0C.y = 7.0f; + Math_Vec3f_Scale((Vec3f*)&ptr->unk_00.y, 7.0f); + } + + if (ptr->unk_0C.y > 0.0001f) { + ptr->unk_0C.y = Math_Vec3f_StepTo((Vec3f*)&ptr->unk_00.y, &D_801D15B0, 2.8f); + } + + ptr->unk_00.x = 0.9f; + ptr->unk_24.x = -0.0002f; + ptr->unk_30 = -0.0002f; + ptr->unk_18.y = 0.003f; + if (!((u32)Rand_Next() >> 0x1B)) { + rand = (u32)Rand_Next() >> 0x10; + ptr->unk_0C.z = Math_SinS(rand) * 1.8f * ptr->unk_18.y; + ptr->unk_18.x = Math_CosS(rand) * 0.2f * ptr->unk_18.y; + *(s16*)((u8*)ptr + 0x20) = (u32)Rand_Next() >> 0x13; + } + + func_80A82C28(this, globalCtx); + func_80A81DEC(this); + func_80A81818(this); + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); +} + +void func_80A83CEC(ObjMine* this) { + this->actionFunc = func_80A83D00; +} + +void func_80A83D00(ObjMine* this, GlobalContext* globalCtx) { + if (func_80A8140C(this)) { + func_80A81384(this, globalCtx); + func_80A81640(this); + func_80A83214(this); + } else { + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + } +} + +void ObjMine_Update(Actor* thisx, GlobalContext* globalCtx) { + s32 pad; + ObjMine* this = THIS; + + if ((this->collider.base.ocFlags2 & OC2_HIT_PLAYER) || (this->collider.base.acFlags & AC_HIT)) { + func_80A8131C(this, globalCtx); + func_80A83214(this); + } + + this->actionFunc(this, globalCtx); + + if (this->actor.update != NULL) { + this->collider.base.ocFlags1 &= ~OC1_HIT; + this->collider.base.acFlags &= ~AC_HIT; + this->collider.base.ocFlags2 &= ~OC2_HIT_PLAYER; + if ((this->actor.flags & 0x40) && (this->actionFunc != func_80A83258)) { + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base); + } + } +} + +void func_80A83E7C(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + + this->actionFunc(this, globalCtx); +} + +void ObjMine_Draw(Actor* thisx, GlobalContext* globalCtx) { + s32 pad; + ObjMine* this = THIS; + + OPEN_DISPS(globalCtx->state.gfxCtx); + + if (this->actionFunc == func_80A82FC8) { + Collider_UpdateSpheres(0, &this->collider); + } + + func_800B8050(&this->actor, globalCtx, 1); + func_8012C28C(globalCtx->state.gfxCtx); + + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gDPSetRenderMode(POLY_OPA_DISP++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); + gSPDisplayList(POLY_OPA_DISP++, D_06002068); + gSPDisplayList(POLY_OPA_DISP++, D_06002188); + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} + +void func_80A83FBC(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + + OPEN_DISPS(globalCtx->state.gfxCtx); + + func_800B8118(&this->actor, globalCtx, 1); + func_8012C2DC(globalCtx->state.gfxCtx); + + gDPSetRenderMode(POLY_XLU_DISP++, G_RM_PASS, G_RM_AA_ZB_XLU_SURF2); + gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 0, 75); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(POLY_XLU_DISP++, D_06002068); + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} + +void func_80A84088(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + s32 temp_s5 = this->actor.params & 0x3F; + ObjMineUnkStruct3* temp; + ObjMineUnkStruct* ptr = &this->unk_1B8; + s32 pad; + s32 i; + Vec3f sp94; + Vec3f sp88; + Gfx* gfx; + + func_800B8050(&this->actor, globalCtx, 1); + + OPEN_DISPS(globalCtx->state.gfxCtx); + gfx = POLY_OPA_DISP; + + gSPDisplayList(gfx++, &sSetupDL[6 * 25]); + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, D_06000030); + + func_80A81684(ptr); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + if (temp_s5 != 0) { + Math_Vec3f_ScaleAndStore(&ptr->unk_0C, -6.0f, &sp88); + sp94.x = this->actor.home.pos.x - sp88.x; + sp94.y = (this->actor.home.pos.y - 6.0f) - sp88.y; + sp94.z = this->actor.home.pos.z - sp88.z; + Math_Vec3f_ScaleAndStore(&ptr->unk_0C, -12.0f, &sp88); + + for (i = 0, temp = &ptr->unk_60[0]; i < temp_s5; i++, temp++) { + Matrix_RotateY(temp->unk_00, MTXMODE_APPLY); + sp94.x += sp88.x; + sp94.y += sp88.y; + sp94.z += sp88.z; + func_80A8164C(&sp94); + + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, D_06000030); + } + } + + SysMatrix_InsertXRotation_s(0x2000, MTXMODE_APPLY); + func_80A8164C(&this->actor.world.pos); + + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gDPPipeSync(gfx++); + gDPSetRenderMode(gfx++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); + gDPSetEnvColor(gfx++, 0, 0, 0, 255); + gSPDisplayList(gfx++, D_06002068); + gSPDisplayList(gfx++, D_06002188); + + POLY_OPA_DISP = gfx; + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} + +void func_80A84338(Actor* thisx, GlobalContext* globalCtx) { + ObjMine* this = THIS; + s32 temp_s7 = this->actor.params & 0x3F; + s32 i; + Gfx* gfx; + ObjMineUnkStruct2* temp; + s32 pad[2]; + + func_800B8050(&this->actor, globalCtx, 1); + + OPEN_DISPS(globalCtx->state.gfxCtx); + gfx = POLY_OPA_DISP; + + gSPDisplayList(gfx++, &sSetupDL[6 * 25]); + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, D_06000030); + + for (i = 0, temp = (ObjMineUnkStruct2*)((u8*)this + 0x1FC); i < temp_s7; i++, temp++) { + func_80A81684((ObjMineUnkStruct*)temp); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, 1); + if ((i & 1) == 0) { + Matrix_RotateY(0x4000, 1); + } + func_80A8164C(&temp->unk_24); + + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, D_06000030); + } + + SysMatrix_InsertXRotation_s(0x2000, 1); + func_80A8164C(&this->actor.world.pos); + + gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gDPPipeSync(gfx++); + gDPSetRenderMode(gfx++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); + gDPSetEnvColor(gfx++, 0, 0, 0, 255); + gSPDisplayList(gfx++, D_06002068); + gSPDisplayList(gfx++, D_06002188); + + POLY_OPA_DISP = gfx; + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index 4b7f8ee3d..af2772fda 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -7,11 +7,67 @@ struct ObjMine; typedef void (*ObjMineActionFunc)(struct ObjMine*, GlobalContext*); +// definitely fake +typedef struct { + char unk_00[0x8]; + Vec3f unk_08; + char unk_14[0xC]; + Vec3f unk_20; + char unk_2C[0x1C]; +} NextUnkStruct; // size = 0x48 + +// maybe fake +typedef struct { + /* 0x00 */ s16 unk_00; + /* 0x02 */ s16 unk_02; +} ObjMineUnkStruct3; + +typedef struct { + /* 0x00 */ Vec3f unk_00; + /* 0x0C */ Vec3f unk_0C; + /* 0x18 */ Vec3f unk_18; + ///* 0x24 */ char unk_24[0x3C]; + /* 0x24 */ Vec3f unk_24; + /* 0x30 */ f32 unk_30; + /* 0x34 */ f32 unk_34; + /* 0x38 */ f32 unk_38; + /* 0x3C */ f32 unk_3C; + /* 0x40 */ f32 unk_40; + /* 0x44 */ f32 unk_44; + /* 0x48 */ f32 unk_48; + /* 0x4C */ s16 unk_4C; + /* 0x50 */ f32 unk_50; + /* 0x54 */ s16 unk_54; + /* 0x58 */ f32 unk_58; + /* 0x5C */ f32 unk_5C; + /* 0x60 */ ObjMineUnkStruct3 unk_60[1]; +} ObjMineUnkStruct; // size = ?? 0x44??? 48 array??? + +// probably fake +typedef struct { + /* 0x00 */ Vec3f unk_00; + /* 0x0c */ Vec3f unk_0C; + ///* 0x10 */ f32 unk_10; + ///* 0x14 */ char unk_14[0x4]; + /* 0x18 */ Vec3f unk_18; + ///* 0x1C */ char unk_1C[0x4]; + ///* 0x20 */ f32 unk_20; + /* 0x24 */ Vec3f unk_24; + /* 0x30 */ Vec3f unk_30; + /* 0x3C */ Vec3f unk_3C; +} ObjMineUnkStruct2; // size = 0x48??? + typedef struct ObjMine { /* 0x0000 */ Actor actor; - /* 0x0144 */ char unk_144[0x60]; + /* 0x0144 */ ColliderJntSph collider; + /* 0x0164 */ ColliderJntSphElement colliderElements[1]; /* 0x01A4 */ ObjMineActionFunc actionFunc; - /* 0x01A8 */ char unk_1A8[0x120C]; + /* 0x01A8 */ f32 unk_1A8; + /* 0x01AC */ s32 unk_1AC; + /* 0x01B0 */ s32 unk_1B0; + /* 0x01B4 */ Vec3s* unk_1B4; + /* 0x01B8 */ ObjMineUnkStruct unk_1B8; // array?? + /* 0x021C */ char unk_21C[0x1198]; } ObjMine; // size = 0x13B4 extern const ActorInit Obj_Mine_InitVars; From 5ce086ffe5685979b808b208d573447c76d911f0 Mon Sep 17 00:00:00 2001 From: Kelebek1 Date: Thu, 14 Apr 2022 02:18:01 +0100 Subject: [PATCH 03/26] Fixups --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index a1a35a780..c2b644cef 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -198,11 +198,11 @@ void func_80A81544(ObjMine* this, Vec3f* arg1) { Actor* temp_v1 = this->collider.base.ac; if ((element->info.acHitInfo->toucher.dmgFlags & 0x13820)) { - SysMatrix_StatePush(); + Matrix_StatePush(); Matrix_RotateY(temp_v1->shape.rot.y, MTXMODE_NEW); - SysMatrix_InsertXRotation_s(temp_v1->shape.rot.x, MTXMODE_APPLY); - SysMatrix_GetStateTranslationAndScaledZ(1.0f, arg1); - SysMatrix_StatePop(); + Matrix_InsertXRotation_s(temp_v1->shape.rot.x, MTXMODE_APPLY); + Matrix_GetStateTranslationAndScaledZ(1.0f, arg1); + Matrix_StatePop(); } else { Vec3f sp20; @@ -222,7 +222,7 @@ void func_80A81640(ObjMine* this) { } void func_80A8164C(Vec3f* arg0) { - MtxF* matrix = SysMatrix_GetCurrentState(); + MtxF* matrix = Matrix_GetCurrentState(); matrix->mf[3][0] = arg0->x; matrix->mf[3][1] = arg0->y; @@ -230,7 +230,7 @@ void func_80A8164C(Vec3f* arg0) { } void func_80A81684(ObjMineUnkStruct* arg0) { - MtxF* matrix = SysMatrix_GetCurrentState(); + MtxF* matrix = Matrix_GetCurrentState(); matrix->mf[0][0] = arg0->unk_00.x; matrix->mf[0][1] = arg0->unk_00.y; @@ -264,18 +264,18 @@ s32 func_80A81714(Vec3f* arg0, Vec3f* arg1, f32 arg2) { return true; } - SysMatrix_StatePush(); + Matrix_StatePush(); Math_Vec3f_Copy(&sp30, arg0); Math3D_CrossProduct(arg0, arg1, &sp3C); if (func_80A8120C(&sp3C, &sp24)) { - SysMatrix_InsertRotationAroundUnitVector_s(arg2 * 10430.378f, &sp24, MTXMODE_NEW); - SysMatrix_MultiplyVector3fByState(&sp30, arg0); + Matrix_InsertRotationAroundUnitVector_s(arg2 * 10430.378f, &sp24, MTXMODE_NEW); + Matrix_MultiplyVector3fByState(&sp30, arg0); } else { - SysMatrix_SetStateXRotation(arg2); - SysMatrix_MultiplyVector3fByState(&sp30, arg0); + Matrix_SetStateXRotation(arg2); + Matrix_MultiplyVector3fByState(&sp30, arg0); } - SysMatrix_StatePop(); + Matrix_StatePop(); return false; } @@ -318,7 +318,7 @@ void func_80A81868(ObjMine* this, s32 arg1) { } void func_80A819A4(ObjMine* this, s32 arg1) { - SysMatrix_InsertTranslation(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, MTXMODE_NEW); + Matrix_InsertTranslation(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, MTXMODE_NEW); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); } @@ -407,8 +407,8 @@ void func_80A81B7C(ObjMine* this, s32 arg1) { } void func_80A81D70(ObjMine* this, s32 arg1) { - SysMatrix_InsertTranslation(this->actor.home.pos.x, this->actor.home.pos.y + (arg1 * 12.0f) + 10.0f, - this->actor.home.pos.z, MTXMODE_NEW); + Matrix_InsertTranslation(this->actor.home.pos.x, this->actor.home.pos.y + (arg1 * 12.0f) + 10.0f, + this->actor.home.pos.z, MTXMODE_NEW); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); } @@ -437,7 +437,7 @@ void func_80A81E7C(ObjMine* this, GlobalContext* globalCtx) { Vec3f sp58; Vec3f sp4C; CollisionPoly* sp48; - u32 sp44; + s32 sp44; f32 sp40; f32 sp3C; @@ -455,7 +455,7 @@ void func_80A81E7C(ObjMine* this, GlobalContext* globalCtx) { sp7C.x = this->actor.home.pos.x; sp7C.y = this->actor.world.pos.y; sp7C.z = this->actor.home.pos.z; - if (func_800C55C4(&globalCtx->colCtx, &sp7C, &sp70, &sp64, &sp48, 1, 0, 0, 1, &sp44)) { + if (BgCheck_EntityLineTest1(&globalCtx->colCtx, &sp7C, &sp70, &sp64, &sp48, 1, 0, 0, 1, &sp44)) { *(s8*)(&temp_v1->unk_40) = 1; temp_v1->unk_38 = sp4C.x * -0.2f; temp_v1->unk_3C = sp4C.z * -0.2f; @@ -570,7 +570,7 @@ void ObjMine_Init(Actor* thisx, GlobalContext* globalCtx) { Collider_SetJntSph(globalCtx, &this->collider, &this->actor, &sJntSphInit, this->colliderElements); if (sp38 == 0) { - ActorShape_Init(&this->actor.shape, 0.0f, func_800B3FC0, 45.0f); + ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 45.0f); this->actor.shape.shadowAlpha = 140; this->unk_1A8 = D_80A845A4[(this->actor.params >> 8) & 7]; if (sp44 == 0xFF) { @@ -583,18 +583,18 @@ void ObjMine_Init(Actor* thisx, GlobalContext* globalCtx) { func_80A811D0(this, this->unk_1B0); func_80A82FA8(this); } - SysMatrix_SetStateRotationAndTranslation(this->actor.world.pos.x, this->actor.world.pos.y, - this->actor.world.pos.z, &this->actor.shape.rot); + Matrix_SetStateRotationAndTranslation(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, + &this->actor.shape.rot); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); - this->actor.floorHeight = - func_800C411C(&globalCtx->colCtx, &this->actor.floorPoly, &sp3C, &this->actor, &this->actor.world.pos); + this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &this->actor.floorPoly, &sp3C, + &this->actor, &this->actor.world.pos); } else { sp34 = this->actor.params & 0x3F; this->actor.update = func_80A83E7C; this->actor.uncullZoneScale = (sp34 * 21.0f) + 150.0f; this->actor.uncullZoneDownward = (sp34 * 21.0f) + 150.0f; - ActorShape_Init(&this->actor.shape, 0.0f, func_800B3FC0, 45.0f); + ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 45.0f); this->actor.shape.shadowAlpha = 0x8C; if (sp38 == 1) { @@ -681,17 +681,17 @@ void func_80A82FC8(ObjMine* this, GlobalContext* globalCtx) { func_80A811D0(this, this->unk_1B0); } - this->actor.floorHeight = - func_800C411C(&globalCtx->colCtx, &this->actor.floorPoly, &sp90, &this->actor, &this->actor.world.pos); + this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &this->actor.floorPoly, &sp90, + &this->actor, &this->actor.world.pos); if (this->actor.flags & 0x40) { Math3D_CrossProduct(&D_80A845D0[0], &this->actor.velocity, &sp78); if (func_80A8120C(&sp78, &sp84)) { - SysMatrix_InsertRotationAroundUnitVector_f(this->actor.speedXZ * 0.03125f, &sp84, MTXMODE_NEW); + Matrix_InsertRotationAroundUnitVector_f(this->actor.speedXZ * 0.03125f, &sp84, MTXMODE_NEW); Matrix_RotateY(this->actor.shape.rot.y, MTXMODE_APPLY); - SysMatrix_InsertXRotation_s(this->actor.shape.rot.x, MTXMODE_APPLY); - SysMatrix_InsertZRotation_s(this->actor.shape.rot.z, MTXMODE_APPLY); - SysMatrix_CopyCurrentState(&sp38); + Matrix_InsertXRotation_s(this->actor.shape.rot.x, MTXMODE_APPLY); + Matrix_InsertZRotation_s(this->actor.shape.rot.z, MTXMODE_APPLY); + Matrix_CopyCurrentState(&sp38); func_8018219C(&sp38, &this->actor.shape.rot, 0); } } @@ -883,7 +883,7 @@ void func_80A83B28(ObjMine* this, GlobalContext* globalCtx) { } if (ptr->unk_0C.y > 0.0001f) { - ptr->unk_0C.y = Math_Vec3f_StepTo((Vec3f*)&ptr->unk_00.y, &D_801D15B0, 2.8f); + ptr->unk_0C.y = Math_Vec3f_StepTo((Vec3f*)&ptr->unk_00.y, &gZeroVec3f, 2.8f); } ptr->unk_00.x = 0.9f; @@ -1026,7 +1026,7 @@ void func_80A84088(Actor* thisx, GlobalContext* globalCtx) { } } - SysMatrix_InsertXRotation_s(0x2000, MTXMODE_APPLY); + Matrix_InsertXRotation_s(0x2000, MTXMODE_APPLY); func_80A8164C(&this->actor.world.pos); gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); @@ -1070,7 +1070,7 @@ void func_80A84338(Actor* thisx, GlobalContext* globalCtx) { gSPDisplayList(gfx++, D_06000030); } - SysMatrix_InsertXRotation_s(0x2000, 1); + Matrix_InsertXRotation_s(0x2000, 1); func_80A8164C(&this->actor.world.pos); gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); From 75d5eae12f4017edf5e9880458f055daf0992f63 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sun, 21 Aug 2022 20:50:59 -0700 Subject: [PATCH 04/26] Nonmatchings + cleanup --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 100 ++++++++---------- 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 1d4403c14..109a2b486 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -190,27 +190,27 @@ void func_80A8146C(ObjMine* this, s16* arg1, s16* arg2) { } } +#define NON_MATCHING #ifdef NON_MATCHING // stack, 1 var needs to go without changing code gen void func_80A81544(ObjMine* this, Vec3f* arg1) { - ColliderJntSphElement* element = &this->collider.elements[0]; - Vec3s* sphere = &element->dim.worldSphere.center; - Actor* temp_v1 = this->collider.base.ac; + Actor* ac = this->collider.base.ac; + Vec3f sp20; - if ((element->info.acHitInfo->toucher.dmgFlags & 0x13820)) { + if ((this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820)) { Matrix_Push(); - Matrix_RotateYS(temp_v1->shape.rot.y, MTXMODE_NEW); - Matrix_RotateXS(temp_v1->shape.rot.x, MTXMODE_APPLY); + Matrix_RotateYS(ac->shape.rot.y, MTXMODE_NEW); + Matrix_RotateXS(ac->shape.rot.x, MTXMODE_APPLY); Matrix_MultVecZ(1.0f, arg1); Matrix_Pop(); } else { - Vec3f sp20; + Sphere16* sphere = &this->collider.elements[0].dim.worldSphere; - sp20.x = sphere->x - temp_v1->world.pos.x; - sp20.y = sphere->y - temp_v1->world.pos.y; - sp20.z = sphere->z - temp_v1->world.pos.z; + sp20.x = sphere->center.x - ac->world.pos.x; + sp20.y = sphere->center.y - ac->world.pos.y; + sp20.z = sphere->center.z - ac->world.pos.z; if (!func_80A8120C(&sp20, arg1)) { - Math_Vec3f_Copy(arg1, D_80A845D0); + Math_Vec3f_Copy(arg1, &D_80A845D0[0]); } } } @@ -218,6 +218,7 @@ void func_80A81544(ObjMine* this, Vec3f* arg1) { void func_80A81544(ObjMine* this, Vec3f* arg1); #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81544.s") #endif +#undef NON_MATCHING void func_80A81640(ObjMine* this) { } @@ -369,7 +370,7 @@ void func_80A81B7C(ObjMine* this, s32 arg1) { ptr->unk_00.x = 0.9f; ptr->unk_18.y = 0.003f; - *(s16*)((u8*)ptr + 0x20) = (u32)Rand_Next() >> 0x13; + *(s16*)((u8*)ptr + 0x20) = Rand_Next() >> 0x13; ptr->unk_24.x = -0.0002f; ptr->unk_30 = -0.0002f; @@ -637,69 +638,58 @@ void func_80A82F98(ObjMine* this, PlayState* play) { } void func_80A82FA8(ObjMine* this) { - this->actor.flags |= 0x10; + this->actor.flags |= ACTOR_FLAG_10; this->actionFunc = func_80A82FC8; } -#ifdef NON_MATCHING -// stack void func_80A82FC8(ObjMine* this, PlayState* play) { - f32 phi_f0; + Actor* thisx = &this->actor; Vec3f spA0; - f32 sp9C; - s32 pad; - f32 phi_f12; + f32 speed; + f32 step; + f32 target; s32 sp90; Vec3f sp84; Vec3f sp78; MtxF sp38; Math_Vec3s_ToVec3f(&spA0, &this->unk_1B4[this->unk_1B0 + 1]); - Math_Vec3f_Diff(&spA0, &this->actor.world.pos, &this->actor.velocity); - - sp9C = Math3D_Vec3fMagnitude(&this->actor.velocity); - if ((sp9C < (this->unk_1A8 * 8.0f)) && (this->unk_1A8 > 2.0f)) { - phi_f0 = ((this->unk_1A8 - 2.0f) * 0.1f) + 2.0f; - phi_f12 = this->unk_1A8 * 0.03f; + Math_Vec3f_Diff(&spA0, &thisx->world.pos, &thisx->velocity); + speed = Math3D_Vec3fMagnitude(&thisx->velocity); + if ((speed < (this->unk_1A8 * 8.0f)) && (this->unk_1A8 > 2.0f)) { + target = ((this->unk_1A8 - 2.0f) * 0.1f) + 2.0f; + step = this->unk_1A8 * 0.03f; } else { - phi_f0 = this->unk_1A8; - phi_f12 = this->unk_1A8 * 0.16f; + target = this->unk_1A8; + step = this->unk_1A8 * 0.16f; } - - Math_StepToF(&this->actor.speedXZ, phi_f0, phi_f12); - - if ((this->actor.speedXZ + 0.05f) < sp9C) { - Math_Vec3f_Scale(&this->actor.velocity, this->actor.speedXZ / sp9C); - this->actor.world.pos.x += this->actor.velocity.x; - this->actor.world.pos.y += this->actor.velocity.y; - this->actor.world.pos.z += this->actor.velocity.z; + Math_StepToF(&thisx->speedXZ, target, step); + if ((thisx->speedXZ + 0.05f) < speed) { + Math_Vec3f_Scale(&thisx->velocity, thisx->speedXZ / speed); + thisx->world.pos.x += thisx->velocity.x; + thisx->world.pos.y += thisx->velocity.y; + thisx->world.pos.z += thisx->velocity.z; } else { - this->actor.speedXZ *= 0.4f; + thisx->speedXZ *= 0.4f; this->unk_1B0++; if (this->unk_1B0 >= this->unk_1AC) { this->unk_1B0 = 0; } func_80A811D0(this, this->unk_1B0); } - - this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &sp90, - &this->actor, &this->actor.world.pos); - - if (this->actor.flags & 0x40) { - Math3D_CrossProduct(&D_80A845D0[0], &this->actor.velocity, &sp78); + thisx->floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &thisx->floorPoly, &sp90, thisx, &thisx->world.pos); + if (thisx->flags & 0x40) { + Math3D_CrossProduct(&D_80A845D0[0], &thisx->velocity, &sp78); if (func_80A8120C(&sp78, &sp84)) { - Matrix_RotateAxisF(this->actor.speedXZ * 0.03125f, &sp84, MTXMODE_NEW); - Matrix_RotateYS(this->actor.shape.rot.y, MTXMODE_APPLY); - Matrix_RotateXS(this->actor.shape.rot.x, MTXMODE_APPLY); - Matrix_RotateZS(this->actor.shape.rot.z, MTXMODE_APPLY); + Matrix_RotateAxisF(thisx->speedXZ * 0.03125f, &sp84, MTXMODE_NEW); + Matrix_RotateYS(thisx->shape.rot.y, MTXMODE_APPLY); + Matrix_RotateXS(thisx->shape.rot.x, MTXMODE_APPLY); + Matrix_RotateZS(thisx->shape.rot.z, MTXMODE_APPLY); Matrix_Get(&sp38); - Matrix_MtxFToYXZRot(&sp38, &this->actor.shape.rot, 0); + Matrix_MtxFToYXZRot(&sp38, &thisx->shape.rot, false); } } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A82FC8.s") -#endif void func_80A83214(ObjMine* this) { this->actor.flags |= 0x10; @@ -769,9 +759,9 @@ void func_80A832D0(ObjMine* this, PlayState* play) { Math_StepToF(&unkStruct->unk_48, 0.0f, 0.02f); } - if ((u32)Rand_Next() >> 0x1B == 0) { + if ((Rand_Next() >> 0x1B) == 0) { unkStruct->unk_50 = Rand_ZeroOne() * unkStruct->unk_58; - unkStruct->unk_54 = (u32)Rand_Next() >> 0x10; + unkStruct->unk_54 = Rand_Next() >> 0x10; } sp90 = Math_SinS(unkStruct->unk_54) * unkStruct->unk_50; @@ -891,11 +881,11 @@ void func_80A83B28(ObjMine* this, PlayState* play) { ptr->unk_24.x = -0.0002f; ptr->unk_30 = -0.0002f; ptr->unk_18.y = 0.003f; - if (!((u32)Rand_Next() >> 0x1B)) { - rand = (u32)Rand_Next() >> 0x10; + if ((Rand_Next() >> 0x1B) == 0) { + rand = Rand_Next() >> 0x10; ptr->unk_0C.z = Math_SinS(rand) * 1.8f * ptr->unk_18.y; ptr->unk_18.x = Math_CosS(rand) * 0.2f * ptr->unk_18.y; - *(s16*)((u8*)ptr + 0x20) = (u32)Rand_Next() >> 0x13; + *(s16*)((u8*)ptr + 0x20) = Rand_Next() >> 0x13; } func_80A82C28(this, play); From 6c35387e82114e3cdb30ec1b213aa13edd86a661 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Thu, 15 Sep 2022 16:29:24 -0700 Subject: [PATCH 05/26] Small cleanup --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 109a2b486..40bc5c57c 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -6,6 +6,7 @@ #include "z_obj_mine.h" #include "overlays/actors/ovl_En_Bom/z_en_bom.h" +#include "assets/objects/object_ny/object_ny.h" #define FLAGS 0x00000000 @@ -34,9 +35,9 @@ void func_80A83FBC(Actor* thisx, PlayState* play); void func_80A84088(Actor* thisx, PlayState* play); void func_80A84338(Actor* thisx, PlayState* play); -extern Gfx D_06000030[]; -extern Gfx D_06002068[]; -extern Gfx D_06002188[]; +extern Gfx object_ny_DL_000030[]; +extern Gfx object_ny_DL_002068[]; +extern Gfx object_ny_DL_002188[]; static s32 D_80A849D0[0xC0]; @@ -190,9 +191,6 @@ void func_80A8146C(ObjMine* this, s16* arg1, s16* arg2) { } } -#define NON_MATCHING -#ifdef NON_MATCHING -// stack, 1 var needs to go without changing code gen void func_80A81544(ObjMine* this, Vec3f* arg1) { Actor* ac = this->collider.base.ac; Vec3f sp20; @@ -214,11 +212,6 @@ void func_80A81544(ObjMine* this, Vec3f* arg1) { } } } -#else -void func_80A81544(ObjMine* this, Vec3f* arg1); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81544.s") -#endif -#undef NON_MATCHING void func_80A81640(ObjMine* this) { } @@ -954,8 +947,8 @@ void ObjMine_Draw(Actor* thisx, PlayState* play) { gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gDPSetRenderMode(POLY_OPA_DISP++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); - gSPDisplayList(POLY_OPA_DISP++, D_06002068); - gSPDisplayList(POLY_OPA_DISP++, D_06002188); + gSPDisplayList(POLY_OPA_DISP++, object_ny_DL_002068); + gSPDisplayList(POLY_OPA_DISP++, object_ny_DL_002188); CLOSE_DISPS(play->state.gfxCtx); } @@ -971,7 +964,7 @@ void func_80A83FBC(Actor* thisx, PlayState* play) { gDPSetRenderMode(POLY_XLU_DISP++, G_RM_PASS, G_RM_AA_ZB_XLU_SURF2); gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 0, 75); gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(POLY_XLU_DISP++, D_06002068); + gSPDisplayList(POLY_XLU_DISP++, object_ny_DL_002068); CLOSE_DISPS(play->state.gfxCtx); } @@ -994,7 +987,7 @@ void func_80A84088(Actor* thisx, PlayState* play) { gSPDisplayList(gfx++, &sSetupDL[6 * 25]); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gfx++, D_06000030); + gSPDisplayList(gfx++, object_ny_DL_000030); func_80A81684(ptr); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); @@ -1013,7 +1006,7 @@ void func_80A84088(Actor* thisx, PlayState* play) { func_80A8164C(&sp94); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gfx++, D_06000030); + gSPDisplayList(gfx++, object_ny_DL_000030); } } @@ -1024,8 +1017,8 @@ void func_80A84088(Actor* thisx, PlayState* play) { gDPPipeSync(gfx++); gDPSetRenderMode(gfx++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); gDPSetEnvColor(gfx++, 0, 0, 0, 255); - gSPDisplayList(gfx++, D_06002068); - gSPDisplayList(gfx++, D_06002188); + gSPDisplayList(gfx++, object_ny_DL_002068); + gSPDisplayList(gfx++, object_ny_DL_002188); POLY_OPA_DISP = gfx; @@ -1047,7 +1040,7 @@ void func_80A84338(Actor* thisx, PlayState* play) { gSPDisplayList(gfx++, &sSetupDL[6 * 25]); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gfx++, D_06000030); + gSPDisplayList(gfx++, object_ny_DL_000030); for (i = 0, temp = (ObjMineUnkStruct2*)((u8*)this + 0x1FC); i < temp_s7; i++, temp++) { func_80A81684((ObjMineUnkStruct*)temp); @@ -1058,7 +1051,7 @@ void func_80A84338(Actor* thisx, PlayState* play) { func_80A8164C(&temp->unk_24); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gfx++, D_06000030); + gSPDisplayList(gfx++, object_ny_DL_000030); } Matrix_RotateXS(0x2000, 1); @@ -1068,8 +1061,8 @@ void func_80A84338(Actor* thisx, PlayState* play) { gDPPipeSync(gfx++); gDPSetRenderMode(gfx++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); gDPSetEnvColor(gfx++, 0, 0, 0, 255); - gSPDisplayList(gfx++, D_06002068); - gSPDisplayList(gfx++, D_06002188); + gSPDisplayList(gfx++, object_ny_DL_002068); + gSPDisplayList(gfx++, object_ny_DL_002188); POLY_OPA_DISP = gfx; From a141c9bc8e8b5009551931c3158d731e2422258e Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Thu, 15 Sep 2022 16:33:30 -0700 Subject: [PATCH 06/26] externs --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 40bc5c57c..3959be087 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -35,10 +35,6 @@ void func_80A83FBC(Actor* thisx, PlayState* play); void func_80A84088(Actor* thisx, PlayState* play); void func_80A84338(Actor* thisx, PlayState* play); -extern Gfx object_ny_DL_000030[]; -extern Gfx object_ny_DL_002068[]; -extern Gfx object_ny_DL_002188[]; - static s32 D_80A849D0[0xC0]; const ActorInit Obj_Mine_InitVars = { From 1b82352a6b4d99ddb2c8ac37b0ec37353a41af1c Mon Sep 17 00:00:00 2001 From: petrie911 Date: Thu, 29 Sep 2022 04:48:27 -0500 Subject: [PATCH 07/26] structs complete --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 523 ++++++++++-------- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 53 +- 2 files changed, 330 insertions(+), 246 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 3959be087..41634e383 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -35,7 +35,7 @@ void func_80A83FBC(Actor* thisx, PlayState* play); void func_80A84088(Actor* thisx, PlayState* play); void func_80A84338(Actor* thisx, PlayState* play); -static s32 D_80A849D0[0xC0]; +static Vec3f D_80A849D0[0x40]; const ActorInit Obj_Mine_InitVars = { ACTOR_OBJ_MINE, @@ -220,22 +220,22 @@ void func_80A8164C(Vec3f* arg0) { matrix->mf[3][2] = arg0->z; } -void func_80A81684(ObjMineUnkStruct* arg0) { +void func_80A81684(ObjMineMtxF3* arg0) { MtxF* matrix = Matrix_GetCurrent(); - matrix->mf[0][0] = arg0->unk_00.x; - matrix->mf[0][1] = arg0->unk_00.y; - matrix->mf[0][2] = arg0->unk_00.z; + matrix->mf[0][0] = arg0->x.x; + matrix->mf[0][1] = arg0->x.y; + matrix->mf[0][2] = arg0->x.z; matrix->mf[0][3] = 0.0f; - matrix->mf[1][0] = arg0->unk_0C.x; - matrix->mf[1][1] = arg0->unk_0C.y; - matrix->mf[1][2] = arg0->unk_0C.z; + matrix->mf[1][0] = arg0->y.x; + matrix->mf[1][1] = arg0->y.y; + matrix->mf[1][2] = arg0->y.z; matrix->mf[1][3] = 0.0f; - matrix->mf[2][0] = arg0->unk_18.x; - matrix->mf[2][1] = arg0->unk_18.y; - matrix->mf[2][2] = arg0->unk_18.z; + matrix->mf[2][0] = arg0->z.x; + matrix->mf[2][1] = arg0->z.y; + matrix->mf[2][2] = arg0->z.z; matrix->mf[2][3] = 0.0f; matrix->mf[3][0] = 0.0f; @@ -278,24 +278,24 @@ void func_80A81818(ObjMine* this) { void func_80A81868(ObjMine* this, s32 arg1) { s32 i; - ObjMineUnkStruct* ptr = &this->unk_1B8; + ObjMineUnkStruct* ptr = &this->chain1; ObjMineUnkStruct3* unkStruct; f32 arg = arg1; f32 temp_f12 = this->actor.home.rot.z * 5.0f; - ptr->unk_00.x = 1.0f; - ptr->unk_0C.y = 1.0f; - ptr->unk_18.z = 1.0f; + ptr->unk_00.x.x = 1.0f; + ptr->unk_00.y.y = 1.0f; + ptr->unk_00.z.z = 1.0f; ptr->unk_24.y = 1.0f; if (arg1 > 0) { - ptr->unk_40 = -sqrtf(0.001984f / arg); - ptr->unk_44 = (0.00031746097f * arg) + 0.95f; + ptr->unk_40 = -sqrtf(0.001984f / arg); // approx 1/504 = 1/8 * 1/63 + ptr->unk_44 = (0.00031746097f * arg) + 0.95f; // approx 1/3150 = 1/50 * 1/63 } ptr->unk_58 = 0.0002f; - for (i = 0, unkStruct = &ptr->unk_60[0]; i < arg1; i++, unkStruct++) { + for (i = 0, unkStruct = ptr->unk_60; i < arg1; i++, unkStruct++) { unkStruct->unk_00 = 0x4000; } @@ -315,27 +315,27 @@ void func_80A819A4(ObjMine* this, s32 arg1) { } void func_80A81A00(ObjMine* this) { - ObjMineUnkStruct* ptr = &this->unk_1B8; + ObjMineUnkStruct* ptr = &this->chain1; Vec3f sp28; sp28.x = -ptr->unk_30; sp28.y = 1.0f; sp28.z = -ptr->unk_34; - func_80A8120C(&sp28, &ptr->unk_0C); - Math3D_CrossProduct(&D_80A845C4, &ptr->unk_0C, &sp28); - func_80A8120C(&sp28, &ptr->unk_18); - Math3D_CrossProduct(&ptr->unk_0C, &ptr->unk_18, &sp28); - func_80A8120C(&sp28, &ptr->unk_00); + func_80A8120C(&sp28, &ptr->unk_00.y); + Math3D_CrossProduct(&D_80A845C4, &ptr->unk_00.y, &sp28); + func_80A8120C(&sp28, &ptr->unk_00.z); + Math3D_CrossProduct(&ptr->unk_00.y, &ptr->unk_00.z, &sp28); + func_80A8120C(&sp28, &ptr->unk_00.x); } void func_80A81AA4(ObjMine* this) { s32 params = this->actor.params & 0x3F; f32 temp_f0 = -((params * 12.0f) + 10.0f); - this->actor.world.pos.x = (this->unk_1B8.unk_0C.x * temp_f0) + this->actor.home.pos.x; - this->actor.world.pos.y = (this->unk_1B8.unk_0C.y * temp_f0) + this->actor.home.pos.y; - this->actor.world.pos.z = (this->unk_1B8.unk_0C.z * temp_f0) + this->actor.home.pos.z; + this->actor.world.pos.x = (this->chain1.unk_00.y.x * temp_f0) + this->actor.home.pos.x; + this->actor.world.pos.y = (this->chain1.unk_00.y.y * temp_f0) + this->actor.home.pos.y; + this->actor.world.pos.z = (this->chain1.unk_00.y.z * temp_f0) + this->actor.home.pos.z; } void func_80A81B14(ObjMine* this) { @@ -344,34 +344,34 @@ void func_80A81B14(ObjMine* this) { f32 x = this->actor.world.pos.x - this->actor.home.pos.x; f32 z = this->actor.world.pos.z - this->actor.home.pos.z; - this->unk_1B8.unk_30 = x * temp_f0; - this->unk_1B8.unk_34 = z * temp_f0; + this->chain1.unk_30 = x * temp_f0; + this->chain1.unk_34 = z * temp_f0; } void func_80A81B7C(ObjMine* this, s32 arg1) { - ObjMineUnkStruct* ptr = &this->unk_1B8; + ObjMineTestStruct2* ptr = &this->chain2; ObjMineUnkStruct2* unkStruct; s32 i; f32 sp58 = this->actor.home.rot.z * 5.0f; f32 temp_f24; f32 temp_f26; - ptr->unk_00.x = 0.9f; - ptr->unk_18.y = 0.003f; + ptr->unk_00 = 0.9f; + ptr->unk_1C = 0.003f; - *(s16*)((u8*)ptr + 0x20) = Rand_Next() >> 0x13; - ptr->unk_24.x = -0.0002f; + ptr->unk_20 = Rand_Next() >> 0x13; + ptr->unk_24 = -0.0002f; ptr->unk_30 = -0.0002f; - temp_f26 = ptr->unk_18.y * 6.0f; + temp_f26 = ptr->unk_1C * 6.0f; temp_f24 = this->actor.home.pos.y; - unkStruct = (ObjMineUnkStruct2*)&ptr->unk_44; + unkStruct = ptr->unk_44; for (i = 0; i < arg1; i++, unkStruct++) { temp_f24 += 12.0f; - unkStruct->unk_00.x = 1.0f; - unkStruct->unk_0C.y = 1.0f; - unkStruct->unk_18.z = 1.0f; + unkStruct->unk_00.x.x = 1.0f; + unkStruct->unk_00.y.y = 1.0f; + unkStruct->unk_00.z.z = 1.0f; unkStruct->unk_24.x = this->actor.home.pos.x; unkStruct->unk_24.y = temp_f24; unkStruct->unk_24.z = this->actor.home.pos.z; @@ -380,12 +380,12 @@ void func_80A81B7C(ObjMine* this, s32 arg1) { unkStruct->unk_30.z = (Rand_ZeroOne() - 0.5f) * temp_f26; } - ptr->unk_24.y = temp_f24; - ptr->unk_24.z = temp_f24 * 0.97f; - temp_f24 = temp_f24 - 18.0f; + ptr->unk_28 = temp_f24; + ptr->unk_2C = temp_f24 * 0.97f; + temp_f24 -= 18.0f; - if (ptr->unk_24.z < temp_f24) { - ptr->unk_24.z = temp_f24; + if (ptr->unk_2C < temp_f24) { + ptr->unk_2C = temp_f24; } if (sp58 < 0.0f) { @@ -405,22 +405,24 @@ void func_80A81D70(ObjMine* this, s32 arg1) { } void func_80A81DEC(ObjMine* this) { - s32 pad[2]; + ObjMineTestStruct2* ptr = &this->chain2; + s32 pad; s32 temp_v0 = this->actor.params & 0x3F; - NextUnkStruct* temp_v1 = &((NextUnkStruct*)&this->unk_1B8)[temp_v0]; + if (temp_v0 == 0) { this->actor.world.pos.y = (this->actor.home.pos.y + 12.0f) + 10.0f; } else { + ObjMineUnkStruct2* ptr2 = &ptr->unk_44[temp_v0 - 1]; Vec3f sp1C; - Math_Vec3f_ScaleAndStore(&temp_v1->unk_08, 10.0f, &sp1C); - Math_Vec3f_Sum(&temp_v1->unk_20, &sp1C, &this->actor.world.pos); + Math_Vec3f_ScaleAndStore(&ptr2->unk_00.y, 10.0f, &sp1C); + Math_Vec3f_Sum(&ptr2->unk_24, &sp1C, &this->actor.world.pos); } } void func_80A81E7C(ObjMine* this, PlayState* play) { - ObjMineUnkStruct* temp_v1 = &this->unk_1B8; + ObjMineTestStruct2* temp_v1 = &this->chain2; s32 pad; Vec3f sp7C; Vec3f sp70; @@ -432,47 +434,122 @@ void func_80A81E7C(ObjMine* this, PlayState* play) { f32 sp40; f32 sp3C; - *(s8*)(&temp_v1->unk_40) = 0; - if (temp_v1->unk_34 > -0.000001f) { - if (temp_v1->unk_34 <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, - this->actor.world.pos.x, this->actor.world.pos.z)) { - sp58.x = this->actor.world.pos.x - this->actor.home.pos.x; - sp58.y = 0.0f; - sp58.z = this->actor.world.pos.z - this->actor.home.pos.z; - if (func_80A81288(&sp58, &sp4C, &sp40, &sp3C)) { - sp70.x = this->actor.world.pos.x + (sp4C.x * 36.0f); - sp70.y = this->actor.world.pos.y; - sp70.z = this->actor.world.pos.z + (sp4C.z * 36.0f); - sp7C.x = this->actor.home.pos.x; - sp7C.y = this->actor.world.pos.y; - sp7C.z = this->actor.home.pos.z; - if (BgCheck_EntityLineTest1(&play->colCtx, &sp7C, &sp70, &sp64, &sp48, 1, 0, 0, 1, &sp44)) { - *(s8*)(&temp_v1->unk_40) = 1; - temp_v1->unk_38 = sp4C.x * -0.2f; - temp_v1->unk_3C = sp4C.z * -0.2f; - } + temp_v1->unk_40 = 0; + if ((-0.000001f < temp_v1->unk_34) && (temp_v1->unk_34 <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, + this->actor.world.pos.x, this->actor.world.pos.z))) { + sp58.x = this->actor.world.pos.x - this->actor.home.pos.x; + sp58.y = 0.0f; + sp58.z = this->actor.world.pos.z - this->actor.home.pos.z; + if (func_80A81288(&sp58, &sp4C, &sp40, &sp3C)) { + sp70.x = this->actor.world.pos.x + (sp4C.x * 36.0f); + sp70.y = this->actor.world.pos.y; + sp70.z = this->actor.world.pos.z + (sp4C.z * 36.0f); + sp7C.x = this->actor.home.pos.x; + sp7C.y = this->actor.world.pos.y; + sp7C.z = this->actor.home.pos.z; + if (BgCheck_EntityLineTest1(&play->colCtx, &sp7C, &sp70, &sp64, &sp48, 1, 0, 0, 1, &sp44)) { + temp_v1->unk_40 = 1; + temp_v1->unk_38 = sp4C.x * -0.2f; + temp_v1->unk_3C = sp4C.z * -0.2f; } } } } +#ifdef NON_MATCHING +void func_80A81FFC(ObjMine *this) { + s32 i; + ObjMineTestStruct2 *temp_s1 = &this->chain2; + ObjMineUnkStruct2 *var_s0; + s32 temp_s6 = this->actor.params & 0x3F; + s16 var_s3 = 0; + f32 temp_fs2 = 1.0f / (f32) temp_s6; + Vec3f sp90; + f32 temp_fs0 = (temp_s1->unk_44[temp_s6 - 1].unk_24.y - temp_s1->unk_2C) * temp_s1->unk_30; + f32 temp_ft4; + + for(i = 0, var_s0 = temp_s1->unk_44; i < temp_s6; i++, var_s0++) { + Math_Vec3f_Copy(&D_80A849D0[i], &var_s0->unk_3C); + if (var_s0->unk_24.y <= this->actor.home.pos.y) { + var_s0->unk_3C.y = temp_s1->unk_30 * -96.0f; + } else if (temp_fs0 > 0.0f) { + var_s0->unk_3C.y = (i + 1) * temp_fs2 * (temp_fs0 / 0.3f); + } else { + var_s0->unk_3C.y = temp_fs0; + } + var_s0->unk_3C.x = (var_s0->unk_24.x - this->actor.home.pos.x) * temp_s1->unk_24; + var_s0->unk_3C.z = (var_s0->unk_24.z - this->actor.home.pos.z) * temp_s1->unk_24; + var_s0->unk_3C.x += temp_s1->unk_14 * Math_SinS(var_s3); + var_s0->unk_3C.y += temp_s1->unk_18; + var_s0->unk_3C.z += temp_s1->unk_14 * Math_CosS(var_s3); + var_s3 += temp_s1->unk_20; + } + if (temp_s1->unk_10 > 0.0001f) { + for(i = 0, var_s0 = temp_s1->unk_44; i < temp_s6; i++, var_s0++) { + temp_ft4 = SQ((temp_s6 - i) * temp_fs2); + var_s0->unk_3C.x += temp_s1->unk_04.x * temp_ft4; + var_s0->unk_3C.y += temp_s1->unk_04.y * temp_ft4; + var_s0->unk_3C.z += temp_s1->unk_04.z * temp_ft4; + } + } + if (temp_s1->unk_40) { + for(i = 0, var_s0 = temp_s1->unk_44; i < temp_s6; i++, var_s0++) { + var_s0->unk_3C.x += temp_s1->unk_38; + var_s0->unk_3C.z += temp_s1->unk_3C; + } + } + + for(i = 0, var_s0 = temp_s1->unk_44; i < temp_s6; i++, var_s0++) { + Math_Vec3f_Copy(&sp90, &gZeroVec3f); + if(i - 2 >= 0) { + sp90.x += D_80A849D0[i - 2].x * 0.075f; + sp90.y += D_80A849D0[i - 2].y * 0.075f; + sp90.z += D_80A849D0[i - 2].z * 0.075f; + } + if(i - 1 >= 0) { + sp90.x += D_80A849D0[i - 1].x * 0.15f; + sp90.y += D_80A849D0[i - 1].y * 0.15f; + sp90.z += D_80A849D0[i - 1].z * 0.15f; + } + sp90.x += D_80A849D0[i].x * 0.3f; + sp90.y += D_80A849D0[i].y * 0.3f; + sp90.z += D_80A849D0[i].z * 0.3f; + if(i + 1 < temp_s6) { + sp90.x += D_80A849D0[i + 1].x * 0.15f; + sp90.y += D_80A849D0[i + 1].y * 0.15f; + sp90.z += D_80A849D0[i + 1].z * 0.15f; + } + if(i + 2 < temp_s6) { + sp90.x += D_80A849D0[i + 2].x * 0.075f; + sp90.y += D_80A849D0[i + 2].y * 0.075f; + sp90.z += D_80A849D0[i + 2].z * 0.075f; + } + var_s0->unk_3C.x += sp90.x; + var_s0->unk_3C.y += sp90.y; + var_s0->unk_3C.z += sp90.z; + } + +} +#else +void func_80A81FFC(ObjMine* this); #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81FFC.s") +#endif void func_80A828A8(ObjMine* this) { - s32 pad; + s32 i; Vec3f spE0; Vec3f spD4; Vec3f spC8; s32 spC4 = this->actor.params & 0x3F; - s32 i = 0; + ObjMineTestStruct2* sp70 = &this->chain2; + ObjMineUnkStruct2* temp_s0; + Vec3f* phi_s3; s32 phi_s5; - Vec3f* phi_s3 = NULL; - ObjMineUnkStruct* sp70 = &this->unk_1B8; Vec3f spA8; Vec3f sp9C; Vec3f sp90; Vec3f sp84; - ObjMineUnkStruct2* temp_s0 = (ObjMineUnkStruct2*)&sp70->unk_44; + s32 pad; f32 sp7C; f32 sp78; @@ -480,12 +557,12 @@ void func_80A828A8(ObjMine* this) { sp84.y = this->actor.home.pos.y + 6.0f; sp84.z = this->actor.home.pos.z; - for (; i < spC4; i++, temp_s0++) { + for (i = 0, phi_s3 = NULL, temp_s0 = sp70->unk_44; i < spC4; i++, phi_s3 = &temp_s0->unk_00.x, temp_s0++) { phi_s5 = false; temp_s0->unk_30.x += temp_s0->unk_3C.x; temp_s0->unk_30.y += temp_s0->unk_3C.y; temp_s0->unk_30.z += temp_s0->unk_3C.z; - Math_Vec3f_Scale(&temp_s0->unk_30, sp70->unk_00.x); + Math_Vec3f_Scale(&temp_s0->unk_30, sp70->unk_00); Math_Vec3f_Copy(&sp90, &temp_s0->unk_24); temp_s0->unk_24.x += temp_s0->unk_30.x; temp_s0->unk_24.y += temp_s0->unk_30.y; @@ -498,7 +575,7 @@ void func_80A828A8(ObjMine* this) { Math_Vec3f_Diff(&temp_s0->unk_24, &sp84, &spA8); if (func_80A81288(&spA8, &sp9C, &sp7C, &sp78) && (sp7C > 4.0f)) { - Math_Vec3f_Copy(&spD4, &temp_s0->unk_0C); + Math_Vec3f_Copy(&spD4, &temp_s0->unk_00.y); func_80A81714(&spD4, &sp9C, 0.10471976f); Math3D_CrossProduct((phi_s3 == NULL) ? &D_80A845C4 : phi_s3, &spD4, &spA8); @@ -512,33 +589,29 @@ void func_80A828A8(ObjMine* this) { } if (phi_s5) { - Math_Vec3f_Copy(&temp_s0->unk_00, &spC8); - Math_Vec3f_Copy(&temp_s0->unk_0C, &spD4); - Math_Vec3f_Copy(&temp_s0->unk_18, &spE0); + Math_Vec3f_Copy(&temp_s0->unk_00.x, &spC8); + Math_Vec3f_Copy(&temp_s0->unk_00.y, &spD4); + Math_Vec3f_Copy(&temp_s0->unk_00.z, &spE0); } else { sp7C = 4.0f; } if (sp7C >= 6.0f) { - temp_s0->unk_24.x = (temp_s0->unk_0C.x * 6.0f) + sp84.x; - temp_s0->unk_24.y = (temp_s0->unk_0C.y * 6.0f) + sp84.y; - temp_s0->unk_24.z = (temp_s0->unk_0C.z * 6.0f) + sp84.z; + temp_s0->unk_24.x = sp84.x + (temp_s0->unk_00.y.x * 6.0f); + temp_s0->unk_24.y = sp84.y + (temp_s0->unk_00.y.y * 6.0f); + temp_s0->unk_24.z = sp84.z + (temp_s0->unk_00.y.z * 6.0f); } else { - temp_s0->unk_24.x = (temp_s0->unk_0C.x * sp7C) + sp84.x; - temp_s0->unk_24.y = (temp_s0->unk_0C.y * sp7C) + sp84.y; - temp_s0->unk_24.z = (temp_s0->unk_0C.z * sp7C) + sp84.z; + temp_s0->unk_24.x = sp84.x + (temp_s0->unk_00.y.x * sp7C); + temp_s0->unk_24.y = sp84.y + (temp_s0->unk_00.y.y * sp7C); + temp_s0->unk_24.z = sp84.z + (temp_s0->unk_00.y.z * sp7C); } - sp84.x = temp_s0->unk_24.x + (temp_s0->unk_0C.x * 6.0f); - sp84.y = temp_s0->unk_24.y + (temp_s0->unk_0C.y * 6.0f); - sp84.z = temp_s0->unk_24.z + (temp_s0->unk_0C.z * 6.0f); - - phi_s3 = &temp_s0->unk_00; + sp84.x = temp_s0->unk_24.x + (temp_s0->unk_00.y.x * 6.0f); + sp84.y = temp_s0->unk_24.y + (temp_s0->unk_00.y.y * 6.0f); + sp84.z = temp_s0->unk_24.z + (temp_s0->unk_00.y.z * 6.0f); } } -void func_80A81FFC(ObjMine* this); - void func_80A82C28(ObjMine* this, PlayState* play) { func_80A81E7C(this, play); func_80A81FFC(this); @@ -707,121 +780,118 @@ void func_80A832BC(ObjMine* this) { void func_80A832D0(ObjMine* this, PlayState* play) { s32 pad; s32 spA0 = this->actor.params & 0x3F; - ObjMineUnkStruct* unkStruct = &this->unk_1B8; + ObjMineUnkStruct* unkStruct = &this->chain1; + ObjMineUnkStruct3* temp; + s32 i; + f32 sp90; + f32 sp8C; + f32 sp88; + s16 sp86; + s16 sp84; + s32 pad2; + s32 pad3; - Math_Vec3f_Copy(&unkStruct->unk_24, &unkStruct->unk_0C); + Math_Vec3f_Copy(&unkStruct->unk_24, &unkStruct->unk_00.y); if (func_80A8140C(this)) { func_80A81384(this, play); func_80A81640(this); func_80A83214(this); - } else { - ObjMineUnkStruct3* temp; - s32 i; - f32 sp90; - f32 sp8C; - f32 sp88; - s16 sp86; - s16 sp84; - s32 pad2; - s32 pad3; + return; + } - if (this->collider.base.acFlags & AC_HIT) { - this->collider.base.acFlags &= ~AC_HIT; - unkStruct->unk_48 = 0.04f; - func_80A8146C(this, &unkStruct->unk_4C, &sp84); - sp8C = Math_SinS(sp84) * 150.0f; - sp88 = sp8C; - sp8C = -(sp8C / spA0); + if (this->collider.base.acFlags & AC_HIT) { + this->collider.base.acFlags &= ~AC_HIT; + unkStruct->unk_48 = 0.04f; + func_80A8146C(this, &unkStruct->unk_4C, &sp84); + sp88 = sp8C = Math_SinS(sp84) * 150.0f; + sp8C = -(sp8C / spA0); - for (i = 0, temp = &unkStruct->unk_60[0]; i < spA0; i++, temp++) { - temp->unk_02 += (s16)sp88; - temp->unk_02 = CLAMP(temp->unk_02, -800, 800); - sp88 -= sp8C; - } + for (i = 0, temp = unkStruct->unk_60; i < spA0; i++, temp++) { + temp->unk_02 += (s16)sp88; + temp->unk_02 = CLAMP(temp->unk_02, -800, 800); + sp88 -= sp8C; } + } - if (unkStruct->unk_48 > 0.0001f) { - sp90 = Math_SinS(unkStruct->unk_4C) * unkStruct->unk_48; - sp8C = Math_CosS(unkStruct->unk_4C) * unkStruct->unk_48; - unkStruct->unk_38 += sp90; - unkStruct->unk_3C += sp8C; - Math_StepToF(&unkStruct->unk_48, 0.0f, 0.02f); - } - - if ((Rand_Next() >> 0x1B) == 0) { - unkStruct->unk_50 = Rand_ZeroOne() * unkStruct->unk_58; - unkStruct->unk_54 = Rand_Next() >> 0x10; - } - - sp90 = Math_SinS(unkStruct->unk_54) * unkStruct->unk_50; - sp8C = Math_CosS(unkStruct->unk_54) * unkStruct->unk_50; + if (unkStruct->unk_48 > 0.0001f) { + sp90 = Math_SinS(unkStruct->unk_4C) * unkStruct->unk_48; + sp8C = Math_CosS(unkStruct->unk_4C) * unkStruct->unk_48; unkStruct->unk_38 += sp90; unkStruct->unk_3C += sp8C; - - unkStruct->unk_38 += unkStruct->unk_30 * unkStruct->unk_40; - unkStruct->unk_3C += unkStruct->unk_34 * unkStruct->unk_40; - - unkStruct->unk_38 *= unkStruct->unk_44; - unkStruct->unk_3C *= unkStruct->unk_44; - - unkStruct->unk_30 += unkStruct->unk_38; - unkStruct->unk_34 += unkStruct->unk_3C; - - unkStruct->unk_30 = CLAMP(unkStruct->unk_30, -5.0f, 5.0f); - unkStruct->unk_34 = CLAMP(unkStruct->unk_34, -5.0f, 5.0f); - - func_80A81A00(this); - func_80A81AA4(this); - - if ((unkStruct->unk_5C > -0.000001f) && - (unkStruct->unk_5C <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, - this->actor.home.pos.x, this->actor.home.pos.z))) { - Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, 20.0f, 0.0f, 1); - - if (this->actor.bgCheckFlags & 8) { - if (this->actor.wallPoly != NULL) { - Vec3f sp70; - Vec3f sp64; - Vec3f sp58; - Vec3f sp4C; - f32 sp48; - f32 sp44; - - sp4C.x = unkStruct->unk_38; - sp4C.y = 0.0f; - sp4C.z = unkStruct->unk_3C; - if (func_80A81288(&sp4C, &sp70, &sp48, &sp44)) { - sp58.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); - sp58.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); - sp58.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); - func_80179F64(&sp70, &sp58, &sp64); - sp48 *= 0.5f; - unkStruct->unk_38 = sp64.x * sp48; - unkStruct->unk_3C = sp64.z * sp48; - } else { - unkStruct->unk_38 *= -0.1f; - unkStruct->unk_3C *= -0.1f; - } - func_80A81B14(this); - func_80A81A00(this); - func_80A81AA4(this); - } - } - } - - for (i = 0, temp = &unkStruct->unk_60[0]; i < spA0; i++, temp++) { - sp86 = temp->unk_00 - 0x4000; - sp88 = ((Rand_ZeroOne() * 30.0f) - 15.0f) + (temp->unk_02 + (sp86 * -0.05f)); - sp88 *= 0.995f; - temp->unk_02 = sp88; - temp->unk_00 += temp->unk_02; - } - - func_800B4AEC(play, &this->actor, 0.0f); - func_80A81818(this); - CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); - CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); + Math_StepToF(&unkStruct->unk_48, 0.0f, 0.02f); } + + if ((Rand_Next() >> 0x1B) == 0) { + unkStruct->unk_50 = Rand_ZeroOne() * unkStruct->unk_58; + unkStruct->unk_54 = Rand_Next() >> 0x10; + } + + sp90 = Math_SinS(unkStruct->unk_54) * unkStruct->unk_50; + sp8C = Math_CosS(unkStruct->unk_54) * unkStruct->unk_50; + unkStruct->unk_38 += sp90; + unkStruct->unk_3C += sp8C; + + unkStruct->unk_38 += unkStruct->unk_30 * unkStruct->unk_40; + unkStruct->unk_3C += unkStruct->unk_34 * unkStruct->unk_40; + + unkStruct->unk_38 *= unkStruct->unk_44; + unkStruct->unk_3C *= unkStruct->unk_44; + + unkStruct->unk_30 += unkStruct->unk_38; + unkStruct->unk_34 += unkStruct->unk_3C; + + unkStruct->unk_30 = CLAMP(unkStruct->unk_30, -5.0f, 5.0f); + unkStruct->unk_34 = CLAMP(unkStruct->unk_34, -5.0f, 5.0f); + + func_80A81A00(this); + func_80A81AA4(this); + + if ((unkStruct->unk_5C > -0.000001f) && + (unkStruct->unk_5C <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, + this->actor.home.pos.x, this->actor.home.pos.z))) { + Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, 20.0f, 0.0f, 1); + + if ((this->actor.bgCheckFlags & 8) && (this->actor.wallPoly != NULL)) { + Vec3f sp70; + Vec3f sp64; + Vec3f sp58; + Vec3f sp4C; + f32 sp48; + f32 sp44; + + sp4C.x = unkStruct->unk_38; + sp4C.y = 0.0f; + sp4C.z = unkStruct->unk_3C; + if (func_80A81288(&sp4C, &sp70, &sp48, &sp44)) { + sp58.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); + sp58.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); + sp58.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); + func_80179F64(&sp70, &sp58, &sp64); + sp48 *= 0.5f; + unkStruct->unk_38 = sp64.x * sp48; + unkStruct->unk_3C = sp64.z * sp48; + } else { + unkStruct->unk_38 *= -0.1f; + unkStruct->unk_3C *= -0.1f; + } + func_80A81B14(this); + func_80A81A00(this); + func_80A81AA4(this); + } + } + + for (i = 0, temp = unkStruct->unk_60; i < spA0; i++, temp++) { + sp86 = temp->unk_00 - 0x4000; + sp88 = temp->unk_02 + (sp86 * -0.05f) + ((Rand_ZeroOne() * 30.0f) - 15.0f); + sp88 *= 0.995f; + temp->unk_02 = sp88; + temp->unk_00 += temp->unk_02; + } + + func_800B4AEC(play, &this->actor, 0.0f); + func_80A81818(this); + CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); } void func_80A83A74(ObjMine* this) { @@ -833,10 +903,11 @@ void func_80A83A88(ObjMine* this, PlayState* play) { func_80A81384(this, play); func_80A81640(this); func_80A83214(this); - } else { - CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); - CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); + return; } + + CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); } void func_80A83B14(ObjMine* this) { @@ -844,8 +915,7 @@ void func_80A83B14(ObjMine* this) { } void func_80A83B28(ObjMine* this, PlayState* play) { - ObjMineUnkStruct* ptr; - s16 rand; + ObjMineTestStruct2* ptr = &this->chain2; if (func_80A8140C(this)) { func_80A81384(this, play); @@ -854,27 +924,27 @@ void func_80A83B28(ObjMine* this, PlayState* play) { return; } - ptr = &this->unk_1B8; if (this->collider.base.acFlags & AC_HIT) { this->collider.base.acFlags &= ~AC_HIT; - func_80A81544(this, (Vec3f*)&ptr->unk_00.y); - ptr->unk_0C.y = 7.0f; - Math_Vec3f_Scale((Vec3f*)&ptr->unk_00.y, 7.0f); + func_80A81544(this, &ptr->unk_04); + ptr->unk_10 = 7.0f; + Math_Vec3f_Scale(&ptr->unk_04, 7.0f); } - if (ptr->unk_0C.y > 0.0001f) { - ptr->unk_0C.y = Math_Vec3f_StepTo((Vec3f*)&ptr->unk_00.y, &gZeroVec3f, 2.8f); + if (ptr->unk_10 > 0.0001f) { + ptr->unk_10 = Math_Vec3f_StepTo( &ptr->unk_04, &gZeroVec3f, 2.8f); } - ptr->unk_00.x = 0.9f; - ptr->unk_24.x = -0.0002f; + ptr->unk_00 = 0.9f; + ptr->unk_24 = -0.0002f; ptr->unk_30 = -0.0002f; - ptr->unk_18.y = 0.003f; + ptr->unk_1C = 0.003f; if ((Rand_Next() >> 0x1B) == 0) { - rand = Rand_Next() >> 0x10; - ptr->unk_0C.z = Math_SinS(rand) * 1.8f * ptr->unk_18.y; - ptr->unk_18.x = Math_CosS(rand) * 0.2f * ptr->unk_18.y; - *(s16*)((u8*)ptr + 0x20) = Rand_Next() >> 0x13; + s16 rand = Rand_Next() >> 0x10; + + ptr->unk_14 = Math_SinS(rand) * 1.8f * ptr->unk_1C; + ptr->unk_18 = Math_CosS(rand) * 0.2f * ptr->unk_1C; + ptr->unk_20 = Rand_Next() >> 0x13; } func_80A82C28(this, play); @@ -893,10 +963,12 @@ void func_80A83D00(ObjMine* this, PlayState* play) { func_80A81384(this, play); func_80A81640(this); func_80A83214(this); - } else { - CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); - CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); + return; } + + CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); + CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); + } void ObjMine_Update(Actor* thisx, PlayState* play) { @@ -966,11 +1038,11 @@ void func_80A83FBC(Actor* thisx, PlayState* play) { } void func_80A84088(Actor* thisx, PlayState* play) { + s32 pad; ObjMine* this = THIS; s32 temp_s5 = this->actor.params & 0x3F; ObjMineUnkStruct3* temp; - ObjMineUnkStruct* ptr = &this->unk_1B8; - s32 pad; + ObjMineUnkStruct* ptr = &this->chain1; s32 i; Vec3f sp94; Vec3f sp88; @@ -985,16 +1057,16 @@ void func_80A84088(Actor* thisx, PlayState* play) { gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); - func_80A81684(ptr); + func_80A81684(&ptr->unk_00); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); if (temp_s5 != 0) { - Math_Vec3f_ScaleAndStore(&ptr->unk_0C, -6.0f, &sp88); + Math_Vec3f_ScaleAndStore(&ptr->unk_00.y, -6.0f, &sp88); sp94.x = this->actor.home.pos.x - sp88.x; sp94.y = (this->actor.home.pos.y - 6.0f) - sp88.y; sp94.z = this->actor.home.pos.z - sp88.z; - Math_Vec3f_ScaleAndStore(&ptr->unk_0C, -12.0f, &sp88); + Math_Vec3f_ScaleAndStore(&ptr->unk_00.y, -12.0f, &sp88); - for (i = 0, temp = &ptr->unk_60[0]; i < temp_s5; i++, temp++) { + for (i = 0, temp = ptr->unk_60; i < temp_s5; i++, temp++) { Matrix_RotateYS(temp->unk_00, MTXMODE_APPLY); sp94.x += sp88.x; sp94.y += sp88.y; @@ -1022,12 +1094,13 @@ void func_80A84088(Actor* thisx, PlayState* play) { } void func_80A84338(Actor* thisx, PlayState* play) { + s32 pad1; ObjMine* this = THIS; s32 temp_s7 = this->actor.params & 0x3F; + ObjMineTestStruct2* pad2 = &this->chain2; s32 i; Gfx* gfx; ObjMineUnkStruct2* temp; - s32 pad[2]; func_800B8050(&this->actor, play, 1); @@ -1038,8 +1111,8 @@ void func_80A84338(Actor* thisx, PlayState* play) { gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); - for (i = 0, temp = (ObjMineUnkStruct2*)((u8*)this + 0x1FC); i < temp_s7; i++, temp++) { - func_80A81684((ObjMineUnkStruct*)temp); + for (i = 0, temp = pad2->unk_44; i < temp_s7; i++, temp++) { + func_80A81684(&temp->unk_00); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, 1); if ((i & 1) == 0) { Matrix_RotateYS(0x4000, MTXMODE_APPLY); diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index be5f1bb58..ac4fb0182 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -7,26 +7,22 @@ struct ObjMine; typedef void (*ObjMineActionFunc)(struct ObjMine*, PlayState*); -// definitely fake typedef struct { - char unk_00[0x8]; - Vec3f unk_08; - char unk_14[0xC]; - Vec3f unk_20; - char unk_2C[0x1C]; -} NextUnkStruct; // size = 0x48 + Vec3f x; + Vec3f y; + Vec3f z; + // Vec3f w; +} ObjMineMtxF3; -// maybe fake typedef struct { /* 0x00 */ s16 unk_00; /* 0x02 */ s16 unk_02; } ObjMineUnkStruct3; typedef struct { - /* 0x00 */ Vec3f unk_00; - /* 0x0C */ Vec3f unk_0C; - /* 0x18 */ Vec3f unk_18; - ///* 0x24 */ char unk_24[0x3C]; + /* 0x00 */ ObjMineMtxF3 unk_00; + // /* 0x0C */ Vec3f unk_0C; + // /* 0x18 */ Vec3f unk_18; /* 0x24 */ Vec3f unk_24; /* 0x30 */ f32 unk_30; /* 0x34 */ f32 unk_34; @@ -45,18 +41,33 @@ typedef struct { // probably fake typedef struct { - /* 0x00 */ Vec3f unk_00; - /* 0x0c */ Vec3f unk_0C; - ///* 0x10 */ f32 unk_10; - ///* 0x14 */ char unk_14[0x4]; - /* 0x18 */ Vec3f unk_18; - ///* 0x1C */ char unk_1C[0x4]; - ///* 0x20 */ f32 unk_20; + /* 0x00 */ ObjMineMtxF3 unk_00; + // /* 0x0c */ Vec3f unk_0C; + // /* 0x18 */ Vec3f unk_18; /* 0x24 */ Vec3f unk_24; /* 0x30 */ Vec3f unk_30; /* 0x3C */ Vec3f unk_3C; } ObjMineUnkStruct2; // size = 0x48??? +typedef struct { + f32 unk_00; + Vec3f unk_04; + f32 unk_10; + f32 unk_14; + f32 unk_18; + f32 unk_1C; + s16 unk_20; + f32 unk_24; + f32 unk_28; + f32 unk_2C; + f32 unk_30; + f32 unk_34; + f32 unk_38; + f32 unk_3C; + s8 unk_40; + ObjMineUnkStruct2 unk_44[0x3F]; +} ObjMineTestStruct2; + typedef struct ObjMine { /* 0x0000 */ Actor actor; /* 0x0144 */ ColliderJntSph collider; @@ -66,8 +77,8 @@ typedef struct ObjMine { /* 0x01AC */ s32 unk_1AC; /* 0x01B0 */ s32 unk_1B0; /* 0x01B4 */ Vec3s* unk_1B4; - /* 0x01B8 */ ObjMineUnkStruct unk_1B8; // array?? - /* 0x021C */ char unk_21C[0x1198]; + // ObjMineTestStruct2 chain2; + union { ObjMineTestStruct2 chain2; ObjMineUnkStruct chain1;}; } ObjMine; // size = 0x13B4 extern const ActorInit Obj_Mine_InitVars; From cb6549e3213f522e668281f654347a05fb289367 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Mon, 24 Oct 2022 08:17:36 -0500 Subject: [PATCH 08/26] wew --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 46 ++++++++++--------- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 7 ++- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 41634e383..15a51f3c7 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -1,7 +1,7 @@ /* * File: z_obj_mine.c * Overlay: ovl_Obj_Mine - * Description: Spike metal Mine + * Description: Spike metal mine */ #include "z_obj_mine.h" @@ -141,10 +141,10 @@ void func_80A81384(ObjMine* this, PlayState* play) { f32 y = this->collider.elements[0].dim.worldSphere.center.y - 15.0f; f32 z = this->collider.elements[0].dim.worldSphere.center.z; - EnBom* bom = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, x, y, z, 0, 0, 0, 0); + EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, x, y, z, 0, 0, 0, 0); - if (bom != NULL) { - bom->timer = 0; + if (bomb != NULL) { + bomb->timer = 0; } } @@ -153,10 +153,10 @@ s32 func_80A8140C(ObjMine* this) { return true; } - if ((this->collider.base.ocFlags1 & OC2_UNK1)) { - Actor* mine = this->collider.base.oc; + if ((this->collider.base.ocFlags1 & OC1_HIT)) { + Actor* hitActor = this->collider.base.oc; - if ((mine->id == ACTOR_OBJ_MINE) && (mine->room == this->actor.room)) { + if ((hitActor->id == ACTOR_OBJ_MINE) && (hitActor->room == this->actor.room)) { return true; } } @@ -189,8 +189,8 @@ void func_80A8146C(ObjMine* this, s16* arg1, s16* arg2) { void func_80A81544(ObjMine* this, Vec3f* arg1) { Actor* ac = this->collider.base.ac; - Vec3f sp20; + // dmgFlag check is (DMG_DEKU_BUBBLE | DMG_FIRE_ARROW | DMG_ICE_ARROW | DMG_FIRE_ARROW | DMG_NORMAL_ARROW) if ((this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820)) { Matrix_Push(); Matrix_RotateYS(ac->shape.rot.y, MTXMODE_NEW); @@ -198,6 +198,7 @@ void func_80A81544(ObjMine* this, Vec3f* arg1) { Matrix_MultVecZ(1.0f, arg1); Matrix_Pop(); } else { + Vec3f sp20; Sphere16* sphere = &this->collider.elements[0].dim.worldSphere; sp20.x = sphere->center.x - ac->world.pos.x; @@ -259,7 +260,7 @@ s32 func_80A81714(Vec3f* arg0, Vec3f* arg1, f32 arg2) { Math_Vec3f_Copy(&sp30, arg0); Math3D_CrossProduct(arg0, arg1, &sp3C); if (func_80A8120C(&sp3C, &sp24)) { - Matrix_RotateAxisS(arg2 * 10430.378f, &sp24, MTXMODE_NEW); + Matrix_RotateAxisS(RADF_TO_BINANG(arg2), &sp24, MTXMODE_NEW); Matrix_MultVec3f(&sp30, arg0); } else { Matrix_RotateXFNew(arg2); @@ -330,7 +331,7 @@ void func_80A81A00(ObjMine* this) { } void func_80A81AA4(ObjMine* this) { - s32 params = this->actor.params & 0x3F; + s32 params = OBJMINE_GET_PARAM_003F(&this->actor); f32 temp_f0 = -((params * 12.0f) + 10.0f); this->actor.world.pos.x = (this->chain1.unk_00.y.x * temp_f0) + this->actor.home.pos.x; @@ -339,7 +340,7 @@ void func_80A81AA4(ObjMine* this) { } void func_80A81B14(ObjMine* this) { - s32 params = this->actor.params & 0x3F; + s32 params = OBJMINE_GET_PARAM_003F(&this->actor); f32 temp_f0 = 1.0f / ((params * 12.0f) + 10.0f); f32 x = this->actor.world.pos.x - this->actor.home.pos.x; f32 z = this->actor.world.pos.z - this->actor.home.pos.z; @@ -407,11 +408,11 @@ void func_80A81D70(ObjMine* this, s32 arg1) { void func_80A81DEC(ObjMine* this) { ObjMineTestStruct2* ptr = &this->chain2; s32 pad; - s32 temp_v0 = this->actor.params & 0x3F; + s32 temp_v0 = OBJMINE_GET_PARAM_003F(&this->actor); if (temp_v0 == 0) { - this->actor.world.pos.y = (this->actor.home.pos.y + 12.0f) + 10.0f; + this->actor.world.pos.y = this->actor.home.pos.y + 12.0f + 10.0f; } else { ObjMineUnkStruct2* ptr2 = &ptr->unk_44[temp_v0 - 1]; Vec3f sp1C; @@ -457,11 +458,12 @@ void func_80A81E7C(ObjMine* this, PlayState* play) { } #ifdef NON_MATCHING +// Probably equivalent, but nightmare loop unrolls. void func_80A81FFC(ObjMine *this) { s32 i; ObjMineTestStruct2 *temp_s1 = &this->chain2; ObjMineUnkStruct2 *var_s0; - s32 temp_s6 = this->actor.params & 0x3F; + s32 temp_s6 = OBJMINE_GET_PARAM_003F(&this->actor); s16 var_s3 = 0; f32 temp_fs2 = 1.0f / (f32) temp_s6; Vec3f sp90; @@ -540,7 +542,7 @@ void func_80A828A8(ObjMine* this) { Vec3f spE0; Vec3f spD4; Vec3f spC8; - s32 spC4 = this->actor.params & 0x3F; + s32 spC4 = OBJMINE_GET_PARAM_003F(&this->actor); ObjMineTestStruct2* sp70 = &this->chain2; ObjMineUnkStruct2* temp_s0; Vec3f* phi_s3; @@ -621,10 +623,10 @@ void func_80A82C28(ObjMine* this, PlayState* play) { void ObjMine_Init(Actor* thisx, PlayState* play) { ObjMine* this = THIS; s32 pad; - s32 sp44 = this->actor.params & 0xFF; + s32 sp44 = OBJMINE_GET_PARAM_00FF(&this->actor); Path* path; s32 sp3C; - s32 sp38 = (this->actor.params >> 0xC) & 3; + s32 sp38 = OBJMINE_GET_PARAM_3000(&this->actor); s32 sp34; Actor_ProcessInitChain(&this->actor, sInitChain); @@ -636,7 +638,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { if (sp38 == 0) { ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 45.0f); this->actor.shape.shadowAlpha = 140; - this->unk_1A8 = D_80A845A4[(this->actor.params >> 8) & 7]; + this->unk_1A8 = D_80A845A4[OBJMINE_GET_PARAM_0700(&this->actor)]; if (sp44 == 0xFF) { func_80A82F84(this); } else { @@ -654,7 +656,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &sp3C, &this->actor, &this->actor.world.pos); } else { - sp34 = this->actor.params & 0x3F; + sp34 = OBJMINE_GET_PARAM_003F(&this->actor); this->actor.update = func_80A83E7C; this->actor.uncullZoneScale = (sp34 * 21.0f) + 150.0f; this->actor.uncullZoneDownward = (sp34 * 21.0f) + 150.0f; @@ -779,7 +781,7 @@ void func_80A832BC(ObjMine* this) { void func_80A832D0(ObjMine* this, PlayState* play) { s32 pad; - s32 spA0 = this->actor.params & 0x3F; + s32 spA0 = OBJMINE_GET_PARAM_003F(&this->actor); ObjMineUnkStruct* unkStruct = &this->chain1; ObjMineUnkStruct3* temp; s32 i; @@ -1040,7 +1042,7 @@ void func_80A83FBC(Actor* thisx, PlayState* play) { void func_80A84088(Actor* thisx, PlayState* play) { s32 pad; ObjMine* this = THIS; - s32 temp_s5 = this->actor.params & 0x3F; + s32 temp_s5 = OBJMINE_GET_PARAM_003F(&this->actor); ObjMineUnkStruct3* temp; ObjMineUnkStruct* ptr = &this->chain1; s32 i; @@ -1096,7 +1098,7 @@ void func_80A84088(Actor* thisx, PlayState* play) { void func_80A84338(Actor* thisx, PlayState* play) { s32 pad1; ObjMine* this = THIS; - s32 temp_s7 = this->actor.params & 0x3F; + s32 temp_s7 = OBJMINE_GET_PARAM_003F(&this->actor); ObjMineTestStruct2* pad2 = &this->chain2; s32 i; Gfx* gfx; diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index ac4fb0182..70c406f49 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -7,6 +7,11 @@ struct ObjMine; typedef void (*ObjMineActionFunc)(struct ObjMine*, PlayState*); +#define OBJMINE_GET_PARAM_003F(thisx) ((thisx)->params & 0x3F) +#define OBJMINE_GET_PARAM_00FF(thisx) ((thisx)->params & 0xFF) +#define OBJMINE_GET_PARAM_0700(thisx) ((thisx)->params >> 8 & 7) +#define OBJMINE_GET_PARAM_3000(thisx) ((thisx)->params >> 0xC & 3) + typedef struct { Vec3f x; Vec3f y; @@ -36,7 +41,7 @@ typedef struct { /* 0x54 */ s16 unk_54; /* 0x58 */ f32 unk_58; /* 0x5C */ f32 unk_5C; - /* 0x60 */ ObjMineUnkStruct3 unk_60[1]; + /* 0x60 */ ObjMineUnkStruct3* unk_60; } ObjMineUnkStruct; // size = ?? 0x44??? 48 array??? // probably fake From ee4e186def6306944461ef20cfa0f34ce7b1e40e Mon Sep 17 00:00:00 2001 From: petrie911 Date: Mon, 24 Oct 2022 14:33:10 -0500 Subject: [PATCH 09/26] some docs. still baffling --- include/macros.h | 4 + src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 1040 +++++++++-------- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 91 +- tools/disasm/functions.txt | 84 +- 4 files changed, 624 insertions(+), 595 deletions(-) diff --git a/include/macros.h b/include/macros.h index ad963153f..5dc4ca943 100644 --- a/include/macros.h +++ b/include/macros.h @@ -129,6 +129,7 @@ extern GraphicsContext* __gfxCtx; #define ALIGN256(val) (((val) + 0xFF) & ~0xFF) #define SQ(x) ((x) * (x)) +#define CUBE(x) ((x) * (x) * (x)) #define ABS(x) ((x) >= 0 ? (x) : -(x)) #define ABS_ALT(x) ((x) < 0 ? -(x) : (x)) #define DECR(x) ((x) == 0 ? 0 : --(x)) @@ -137,6 +138,9 @@ extern GraphicsContext* __gfxCtx; #define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x)) #define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x)) +#define RAND_BITS(n) ((s32)Rand_Next() >> (0x20 - n)) +#define RANDU_BITS(n) (Rand_Next() >> (0x20 - n)) + #define ROUND(x) (s32)(((x) >= 0.0) ? ((x) + 0.5) : ((x) - 0.5)) #define SWAP(type, a, b) \ diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 9e894807b..d83a4a04f 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -14,28 +14,27 @@ void ObjMine_Init(Actor* thisx, PlayState* play); void ObjMine_Destroy(Actor* thisx, PlayState* play); -void ObjMine_Update(Actor* thisx, PlayState* play); -void ObjMine_Draw(Actor* thisx, PlayState* play); +void ObjMine_Path_Update(Actor* thisx, PlayState* play); +void ObjMine_Path_Draw(Actor* thisx, PlayState* play); -void func_80A82F84(ObjMine* this); -void func_80A82F98(ObjMine* this, PlayState* play); -void func_80A82FA8(ObjMine* this); -void func_80A82FC8(ObjMine* this, PlayState* play); -void func_80A83258(ObjMine* this, PlayState* play); -void func_80A832BC(ObjMine* this); -void func_80A832D0(ObjMine* this, PlayState* play); -void func_80A83A74(ObjMine* this); -void func_80A83A88(ObjMine* this, PlayState* play); -void func_80A83B14(ObjMine* this); -void func_80A83B28(ObjMine* this, PlayState* play); -void func_80A83CEC(ObjMine* this); -void func_80A83D00(ObjMine* this, PlayState* play); -void func_80A83E7C(Actor* thisx, PlayState* play); -void func_80A83FBC(Actor* thisx, PlayState* play); -void func_80A84088(Actor* thisx, PlayState* play); -void func_80A84338(Actor* thisx, PlayState* play); +void ObjMine_Path_SetupStationary(ObjMine* this); +void ObjMine_Path_Stationary(ObjMine* this, PlayState* play); +void ObjMine_Path_SetupMove(ObjMine* this); +void ObjMine_Path_Move(ObjMine* this, PlayState* play); +void ObjMine_Explode(ObjMine* this, PlayState* play); +void ObjMine_Air_SetupChained(ObjMine* this); +void ObjMine_Air_Chained(ObjMine* this, PlayState* play); +void ObjMine_Air_SetupStationary(ObjMine* this); +void ObjMine_Air_Stationary(ObjMine* this, PlayState* play); +void ObjMine_Water_SetupChained(ObjMine* this); +void ObjMine_Water_Chained(ObjMine* this, PlayState* play); +void ObjMine_Water_SetupStationary(ObjMine* this); +void ObjMine_Water_Stationary(ObjMine* this, PlayState* play); -static Vec3f D_80A849D0[0x40]; +void ObjMine_AirWater_Update(Actor* thisx, PlayState* play); +void ObjMine_DrawExplosion(Actor* thisx, PlayState* play); +void ObjMine_Air_Draw(Actor* thisx, PlayState* play); +void ObjMine_Water_Draw(Actor* thisx, PlayState* play); ActorInit Obj_Mine_InitVars = { ACTOR_OBJ_MINE, @@ -45,8 +44,8 @@ ActorInit Obj_Mine_InitVars = { sizeof(ObjMine), (ActorFunc)ObjMine_Init, (ActorFunc)ObjMine_Destroy, - (ActorFunc)ObjMine_Update, - (ActorFunc)ObjMine_Draw, + (ActorFunc)ObjMine_Path_Update, + (ActorFunc)ObjMine_Path_Draw, }; static ColliderJntSphElementInit sJntSphElementsInit[1] = { @@ -76,13 +75,12 @@ static ColliderJntSphInit sJntSphInit = { sJntSphElementsInit, }; -static f32 D_80A845A4[] = { +static f32 sPathSpeeds[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, }; -static Vec3f D_80A845C4 = { 1.0f, 0.0f, 0.0f }; - -static Vec3f D_80A845D0[] = { +static ObjMineMtxF3 sStandardBasis = { + { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f }, }; @@ -94,61 +92,61 @@ static InitChainEntry sInitChain[] = { ICHAIN_VEC3F_DIV1000(scale, 10, ICHAIN_STOP), }; -void func_80A811D0(ObjMine* this, s32 arg1) { - Math_Vec3s_ToVec3f(&this->actor.world.pos, &this->unk_1B4[arg1]); +void ObjMine_Path_MoveToWaypoint(ObjMine* this, s32 index) { + Math_Vec3s_ToVec3f(&this->actor.world.pos, &this->waypoints[index]); } -s32 func_80A8120C(Vec3f* arg0, Vec3f* arg1) { - f32 temp_f0 = Math3D_Vec3fMagnitude(arg0); +s32 ObjMine_GetUnitVec3f(Vec3f* src, Vec3f* dst) { + f32 temp_f0 = Math3D_Vec3fMagnitude(src); if (temp_f0 < 0.001f) { return false; } - arg1->x = arg0->x * (1.0f / temp_f0); - arg1->y = arg0->y * (1.0f / temp_f0); - arg1->z = arg0->z * (1.0f / temp_f0); + dst->x = src->x * (1.0f / temp_f0); + dst->y = src->y * (1.0f / temp_f0); + dst->z = src->z * (1.0f / temp_f0); return true; } -s32 func_80A81288(Vec3f* arg0, Vec3f* arg1, f32* arg2, f32* arg3) { - f32 temp_f0 = Math3D_Vec3fMagnitude(arg0); +s32 ObjMine_GetUnitVec3fNorm(Vec3f* src, Vec3f* dst, f32* norm, f32* invNorm) { + f32 magnitude = Math3D_Vec3fMagnitude(src); - if (temp_f0 < 0.001f) { + if (magnitude < 0.001f) { return false; } - arg1->x = arg0->x * (1.0f / temp_f0); - arg1->y = arg0->y * (1.0f / temp_f0); - arg1->z = arg0->z * (1.0f / temp_f0); - *arg2 = temp_f0; - *arg3 = 1.0f / temp_f0; + dst->x = src->x * (1.0f / magnitude); + dst->y = src->y * (1.0f / magnitude); + dst->z = src->z * (1.0f / magnitude); + *norm = magnitude; + *invNorm = 1.0f / magnitude; return true; } -void func_80A8131C(ObjMine* this, PlayState* play) { +void ObjMine_Path_SpawnBomb(ObjMine* this, PlayState* play) { EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, this->actor.world.pos.x, - this->actor.world.pos.y - 15.0f, this->actor.world.pos.z, 0, 0, 0, 0); + this->actor.world.pos.y - 15.0f, this->actor.world.pos.z, 0, 0, 0, ENBOM_0); if (bomb != NULL) { bomb->timer = 0; } } -void func_80A81384(ObjMine* this, PlayState* play) { +void ObjMine_AirWater_SpawnBomb(ObjMine* this, PlayState* play) { f32 x = this->collider.elements[0].dim.worldSphere.center.x; f32 y = this->collider.elements[0].dim.worldSphere.center.y - 15.0f; f32 z = this->collider.elements[0].dim.worldSphere.center.z; - EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, x, y, z, 0, 0, 0, 0); + EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, x, y, z, 0, 0, 0, ENBOM_0); if (bomb != NULL) { bomb->timer = 0; } } -s32 func_80A8140C(ObjMine* this) { +s32 ObjMine_AirWater_CheckOC(ObjMine* this) { if (this->collider.base.ocFlags2 & OC2_HIT_PLAYER) { return true; } @@ -164,79 +162,80 @@ s32 func_80A8140C(ObjMine* this) { return false; } -void func_80A8146C(ObjMine* this, s16* arg1, s16* arg2) { - s32 pad2[3]; - Vec3f sp40; +void ObjMine_Air_CheckAC(ObjMine* this, s16* arg1, s16* arg2) { + s32 pad[2]; + Vec3s* centerPos3s = &this->collider.elements[0].dim.worldSphere.center; + Vec3f centerPos; s16 sp3E; - s16 pad; - Actor* temp_s0 = this->collider.base.ac; + Actor* attackActor = this->collider.base.ac; - Math_Vec3s_ToVec3f(&sp40, &this->collider.elements[0].dim.worldSphere.center); - sp3E = Math_Vec3f_Yaw(&temp_s0->world.pos, &sp40); + Math_Vec3s_ToVec3f(¢erPos, centerPos3s); + sp3E = Math_Vec3f_Yaw(&attackActor->world.pos, ¢erPos); + // dmgFlag check is (DMG_DEKU_BUBBLE | DMG_FIRE_ARROW | DMG_ICE_ARROW | DMG_FIRE_ARROW | DMG_NORMAL_ARROW) if (this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820) { - *arg1 = temp_s0->shape.rot.y; - *arg2 = temp_s0->shape.rot.y - sp3E; + *arg1 = attackActor->shape.rot.y; + *arg2 = attackActor->shape.rot.y - sp3E; } else { - Vec3f sp2C; - Vec3s* hitPos = &this->collider.elements[0].info.bumper.hitPos; + Vec3f hitPos; + Vec3s* hitPos3s = &this->collider.elements[0].info.bumper.hitPos; - Math_Vec3s_ToVec3f(&sp2C, hitPos); - *arg1 = Actor_YawBetweenActors(temp_s0, &this->actor); - *arg2 = Math_Vec3f_Yaw(&temp_s0->world.pos, &sp2C) - sp3E; + Math_Vec3s_ToVec3f(&hitPos, hitPos3s); + *arg1 = Actor_YawBetweenActors(attackActor, &this->actor); + *arg2 = Math_Vec3f_Yaw(&attackActor->world.pos, &hitPos) - sp3E; } } -void func_80A81544(ObjMine* this, Vec3f* arg1) { - Actor* ac = this->collider.base.ac; +void ObjMine_Water_CheckAC(ObjMine* this, Vec3f* arg1) { + Actor* attackActor = this->collider.base.ac; // dmgFlag check is (DMG_DEKU_BUBBLE | DMG_FIRE_ARROW | DMG_ICE_ARROW | DMG_FIRE_ARROW | DMG_NORMAL_ARROW) if ((this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820)) { Matrix_Push(); - Matrix_RotateYS(ac->shape.rot.y, MTXMODE_NEW); - Matrix_RotateXS(ac->shape.rot.x, MTXMODE_APPLY); + Matrix_RotateYS(attackActor->shape.rot.y, MTXMODE_NEW); + Matrix_RotateXS(attackActor->shape.rot.x, MTXMODE_APPLY); Matrix_MultVecZ(1.0f, arg1); Matrix_Pop(); } else { - Vec3f sp20; + Vec3f sp20; Sphere16* sphere = &this->collider.elements[0].dim.worldSphere; - sp20.x = sphere->center.x - ac->world.pos.x; - sp20.y = sphere->center.y - ac->world.pos.y; - sp20.z = sphere->center.z - ac->world.pos.z; - if (!func_80A8120C(&sp20, arg1)) { - Math_Vec3f_Copy(arg1, &D_80A845D0[0]); + sp20.x = sphere->center.x - attackActor->world.pos.x; + sp20.y = sphere->center.y - attackActor->world.pos.y; + sp20.z = sphere->center.z - attackActor->world.pos.z; + if (!ObjMine_GetUnitVec3f(&sp20, arg1)) { + Math_Vec3f_Copy(arg1, &sStandardBasis.y); } } } -void func_80A81640(ObjMine* this) { +void ObjMine_AirWater_Noop(ObjMine* this) { } -void func_80A8164C(Vec3f* arg0) { +void ObjMine_ReplaceTranslation(Vec3f* translation) { MtxF* matrix = Matrix_GetCurrent(); - matrix->mf[3][0] = arg0->x; - matrix->mf[3][1] = arg0->y; - matrix->mf[3][2] = arg0->z; + matrix->mf[3][0] = translation->x; + matrix->mf[3][1] = translation->y; + matrix->mf[3][2] = translation->z; } -void func_80A81684(ObjMineMtxF3* arg0) { +void ObjMine_ReplaceRotation(ObjMineMtxF3* rotation) { MtxF* matrix = Matrix_GetCurrent(); - matrix->mf[0][0] = arg0->x.x; - matrix->mf[0][1] = arg0->x.y; - matrix->mf[0][2] = arg0->x.z; + matrix->mf[0][0] = rotation->x.x; + matrix->mf[0][1] = rotation->x.y; + matrix->mf[0][2] = rotation->x.z; matrix->mf[0][3] = 0.0f; - matrix->mf[1][0] = arg0->y.x; - matrix->mf[1][1] = arg0->y.y; - matrix->mf[1][2] = arg0->y.z; + matrix->mf[1][0] = rotation->y.x; + matrix->mf[1][1] = rotation->y.y; + matrix->mf[1][2] = rotation->y.z; matrix->mf[1][3] = 0.0f; - matrix->mf[2][0] = arg0->z.x; - matrix->mf[2][1] = arg0->z.y; - matrix->mf[2][2] = arg0->z.z; + matrix->mf[2][0] = rotation->z.x; + matrix->mf[2][1] = rotation->z.y; + matrix->mf[2][2] = rotation->z.z; matrix->mf[2][3] = 0.0f; matrix->mf[3][0] = 0.0f; @@ -245,263 +244,267 @@ void func_80A81684(ObjMineMtxF3* arg0) { matrix->mf[3][3] = 1.0f; } -s32 func_80A81714(Vec3f* arg0, Vec3f* arg1, f32 arg2) { +s32 ObjMine_StepUntilParallel(Vec3f* value, Vec3f* target, f32 angleStep) { Vec3f sp3C; Vec3f sp30; Vec3f sp24; - f32 sp20 = Math3D_Parallel(arg0, arg1); + f32 sp20 = Math3D_Parallel(value, target); - if (cos_rad(arg2) <= sp20) { - Math_Vec3f_Copy(arg0, arg1); + if (cos_rad(angleStep) <= sp20) { + Math_Vec3f_Copy(value, target); return true; } Matrix_Push(); - Math_Vec3f_Copy(&sp30, arg0); - Math3D_CrossProduct(arg0, arg1, &sp3C); - if (func_80A8120C(&sp3C, &sp24)) { - Matrix_RotateAxisS(RADF_TO_BINANG(arg2), &sp24, MTXMODE_NEW); - Matrix_MultVec3f(&sp30, arg0); + Math_Vec3f_Copy(&sp30, value); + Math3D_CrossProduct(value, target, &sp3C); + if (ObjMine_GetUnitVec3f(&sp3C, &sp24)) { + Matrix_RotateAxisS(RADF_TO_BINANG(angleStep), &sp24, MTXMODE_NEW); + Matrix_MultVec3f(&sp30, value); } else { - Matrix_RotateXFNew(arg2); - Matrix_MultVec3f(&sp30, arg0); + Matrix_RotateXFNew(angleStep); + Matrix_MultVec3f(&sp30, value); } Matrix_Pop(); return false; } -void func_80A81818(ObjMine* this) { - this->collider.elements->dim.worldSphere.center.x = this->actor.world.pos.x; - this->collider.elements->dim.worldSphere.center.y = this->actor.world.pos.y; - this->collider.elements->dim.worldSphere.center.z = this->actor.world.pos.z; +void ObjMine_UpdateCollider(ObjMine* this) { + this->collider.elements[0].dim.worldSphere.center.x = this->actor.world.pos.x; + this->collider.elements[0].dim.worldSphere.center.y = this->actor.world.pos.y; + this->collider.elements[0].dim.worldSphere.center.z = this->actor.world.pos.z; } -void func_80A81868(ObjMine* this, s32 arg1) { +void ObjMine_Air_InitChain(ObjMine* this, s32 linkCount) { + f32 arg1f = linkCount; + ObjMineAirChain* chain1 = &this->chain.air; + ObjMineAirLink* link1; s32 i; - ObjMineUnkStruct* ptr = &this->chain1; - ObjMineUnkStruct3* unkStruct; - f32 arg = arg1; f32 temp_f12 = this->actor.home.rot.z * 5.0f; - ptr->unk_00.x.x = 1.0f; - ptr->unk_00.y.y = 1.0f; - ptr->unk_00.z.z = 1.0f; - ptr->unk_24.y = 1.0f; + chain1->basis.x.x = 1.0f; + chain1->basis.y.y = 1.0f; + chain1->basis.z.z = 1.0f; + chain1->unk_24.y = 1.0f; - if (arg1 > 0) { - ptr->unk_40 = -sqrtf(0.001984f / arg); // approx 1/504 = 1/8 * 1/63 - ptr->unk_44 = (0.00031746097f * arg) + 0.95f; // approx 1/3150 = 1/50 * 1/63 + if (linkCount > 0) { + chain1->unk_40 = -sqrtf(0.001984f / arg1f); // approx 1/504 = 1/8 * 1/63 + chain1->unk_44 = 0.95f + (0.00031746097f * arg1f); // approx 1/3150 = 1/50 * 1/63 } - ptr->unk_58 = 0.0002f; + chain1->unk_58 = 0.0002f; - for (i = 0, unkStruct = ptr->unk_60; i < arg1; i++, unkStruct++) { - unkStruct->unk_00 = 0x4000; + for (i = 0, link1 = chain1->links; i < linkCount; i++, link1++) { + link1->unk_00 = 0x4000; } if (temp_f12 < 0.0f) { - ptr->unk_5C = -1.0f; + chain1->unk_5C = -1.0f; } else if (temp_f12 <= 21.0f) { - ptr->unk_5C = 0.0f; + chain1->unk_5C = 0.0f; } else { - ptr->unk_5C = SQ(temp_f12 - 20.0f); + chain1->unk_5C = SQ(temp_f12 - 20.0f); } } -void func_80A819A4(ObjMine* this, s32 arg1) { +void ObjMine_Air_SetCollider(ObjMine* this, s32 linkCount) { Matrix_Translate(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, MTXMODE_NEW); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); } -void func_80A81A00(ObjMine* this) { - ObjMineUnkStruct* ptr = &this->chain1; +void ObjMine_Air_SetBasis(ObjMine* this) { + ObjMineAirChain* chain1 = &this->chain.air; Vec3f sp28; - sp28.x = -ptr->unk_30; + sp28.x = -chain1->unk_30; sp28.y = 1.0f; - sp28.z = -ptr->unk_34; + sp28.z = -chain1->unk_34; - func_80A8120C(&sp28, &ptr->unk_00.y); - Math3D_CrossProduct(&D_80A845C4, &ptr->unk_00.y, &sp28); - func_80A8120C(&sp28, &ptr->unk_00.z); - Math3D_CrossProduct(&ptr->unk_00.y, &ptr->unk_00.z, &sp28); - func_80A8120C(&sp28, &ptr->unk_00.x); + ObjMine_GetUnitVec3f(&sp28, &chain1->basis.y); + Math3D_CrossProduct(&sStandardBasis.x, &chain1->basis.y, &sp28); + ObjMine_GetUnitVec3f(&sp28, &chain1->basis.z); + Math3D_CrossProduct(&chain1->basis.y, &chain1->basis.z, &sp28); + ObjMine_GetUnitVec3f(&sp28, &chain1->basis.x); } -void func_80A81AA4(ObjMine* this) { - s32 params = OBJMINE_GET_PARAM_003F(&this->actor); - f32 temp_f0 = -((params * 12.0f) + 10.0f); +void ObjMine_Air_SetWorld(ObjMine* this) { + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); + f32 temp_f0 = 10.0f + (linkCount * 12.0f); - this->actor.world.pos.x = (this->chain1.unk_00.y.x * temp_f0) + this->actor.home.pos.x; - this->actor.world.pos.y = (this->chain1.unk_00.y.y * temp_f0) + this->actor.home.pos.y; - this->actor.world.pos.z = (this->chain1.unk_00.y.z * temp_f0) + this->actor.home.pos.z; + this->actor.world.pos.x = (this->chain.air.basis.y.x * -temp_f0) + this->actor.home.pos.x; + this->actor.world.pos.y = (this->chain.air.basis.y.y * -temp_f0) + this->actor.home.pos.y; + this->actor.world.pos.z = (this->chain.air.basis.y.z * -temp_f0) + this->actor.home.pos.z; } -void func_80A81B14(ObjMine* this) { - s32 params = OBJMINE_GET_PARAM_003F(&this->actor); - f32 temp_f0 = 1.0f / ((params * 12.0f) + 10.0f); - f32 x = this->actor.world.pos.x - this->actor.home.pos.x; - f32 z = this->actor.world.pos.z - this->actor.home.pos.z; +void ObjMine_Air_SetChain3034(ObjMine* this) { + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); + f32 temp_f0 = 1.0f / (10.0f + (linkCount * 12.0f)); + f32 dx = this->actor.world.pos.x - this->actor.home.pos.x; + f32 dz = this->actor.world.pos.z - this->actor.home.pos.z; - this->chain1.unk_30 = x * temp_f0; - this->chain1.unk_34 = z * temp_f0; + this->chain.air.unk_30 = dx * temp_f0; + this->chain.air.unk_34 = dz * temp_f0; } -void func_80A81B7C(ObjMine* this, s32 arg1) { - ObjMineTestStruct2* ptr = &this->chain2; - ObjMineUnkStruct2* unkStruct; +void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { + ObjMineWaterChain* chain2 = &this->chain.water; + ObjMineWaterLink* link2; s32 i; f32 sp58 = this->actor.home.rot.z * 5.0f; f32 temp_f24; f32 temp_f26; - ptr->unk_00 = 0.9f; - ptr->unk_1C = 0.003f; + chain2->unk_00 = 0.9f; + chain2->unk_1C = 0.003f; - ptr->unk_20 = Rand_Next() >> 0x13; - ptr->unk_24 = -0.0002f; - ptr->unk_30 = -0.0002f; + chain2->unk_20 = RANDU_BITS(13); + chain2->unk_24 = -0.0002f; + chain2->unk_30 = -0.0002f; - temp_f26 = ptr->unk_1C * 6.0f; + temp_f26 = chain2->unk_1C * 6.0f; temp_f24 = this->actor.home.pos.y; - unkStruct = ptr->unk_44; - for (i = 0; i < arg1; i++, unkStruct++) { + for (i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { temp_f24 += 12.0f; - unkStruct->unk_00.x.x = 1.0f; - unkStruct->unk_00.y.y = 1.0f; - unkStruct->unk_00.z.z = 1.0f; - unkStruct->unk_24.x = this->actor.home.pos.x; - unkStruct->unk_24.y = temp_f24; - unkStruct->unk_24.z = this->actor.home.pos.z; - unkStruct->unk_30.x = (Rand_ZeroOne() - 0.5f) * temp_f26; - unkStruct->unk_30.y = (Rand_ZeroOne() - 0.5f) * temp_f26; - unkStruct->unk_30.z = (Rand_ZeroOne() - 0.5f) * temp_f26; + link2->basis.x.x = 1.0f; + link2->basis.y.y = 1.0f; + link2->basis.z.z = 1.0f; + link2->unk_24.x = this->actor.home.pos.x; + link2->unk_24.y = temp_f24; + link2->unk_24.z = this->actor.home.pos.z; + link2->unk_30.x = (Rand_ZeroOne() - 0.5f) * temp_f26; + link2->unk_30.y = (Rand_ZeroOne() - 0.5f) * temp_f26; + link2->unk_30.z = (Rand_ZeroOne() - 0.5f) * temp_f26; } - ptr->unk_28 = temp_f24; - ptr->unk_2C = temp_f24 * 0.97f; + chain2->unk_28 = temp_f24; + chain2->unk_2C = temp_f24 * 0.97f; temp_f24 -= 18.0f; - if (ptr->unk_2C < temp_f24) { - ptr->unk_2C = temp_f24; + if (chain2->unk_2C < temp_f24) { + chain2->unk_2C = temp_f24; } if (sp58 < 0.0f) { - ptr->unk_34 = -1.0f; + chain2->unk_34 = -1.0f; } else if (sp58 <= 37.0f) { - ptr->unk_34 = 0.0f; + chain2->unk_34 = 0.0f; } else { - ptr->unk_34 = SQ(sp58 - 36.0f); + chain2->unk_34 = SQ(sp58 - 36.0f); } } -void func_80A81D70(ObjMine* this, s32 arg1) { - Matrix_Translate(this->actor.home.pos.x, this->actor.home.pos.y + (arg1 * 12.0f) + 10.0f, +void ObjMine_Water_SetCollider(ObjMine* this, s32 linkCount) { + Matrix_Translate(this->actor.home.pos.x, this->actor.home.pos.y + (linkCount * 12.0f) + 10.0f, this->actor.home.pos.z, MTXMODE_NEW); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); } -void func_80A81DEC(ObjMine* this) { - ObjMineTestStruct2* ptr = &this->chain2; +void ObjMine_Water_SetWorld(ObjMine* this) { s32 pad; - s32 temp_v0 = OBJMINE_GET_PARAM_003F(&this->actor); + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); + ObjMineWaterChain* chain2 = &this->chain.water; - - if (temp_v0 == 0) { + if (linkCount == 0) { this->actor.world.pos.y = this->actor.home.pos.y + 12.0f + 10.0f; } else { - ObjMineUnkStruct2* ptr2 = &ptr->unk_44[temp_v0 - 1]; + ObjMineWaterLink* link2 = &chain2->links[linkCount - 1]; Vec3f sp1C; - Math_Vec3f_ScaleAndStore(&ptr2->unk_00.y, 10.0f, &sp1C); - Math_Vec3f_Sum(&ptr2->unk_24, &sp1C, &this->actor.world.pos); + Math_Vec3f_ScaleAndStore(&link2->basis.y, 10.0f, &sp1C); + Math_Vec3f_Sum(&link2->unk_24, &sp1C, &this->actor.world.pos); } } void func_80A81E7C(ObjMine* this, PlayState* play) { - ObjMineTestStruct2* temp_v1 = &this->chain2; s32 pad; - Vec3f sp7C; - Vec3f sp70; - Vec3f sp64; - Vec3f sp58; - Vec3f sp4C; - CollisionPoly* sp48; - s32 sp44; - f32 sp40; - f32 sp3C; - - temp_v1->unk_40 = 0; - if ((-0.000001f < temp_v1->unk_34) && (temp_v1->unk_34 <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, + ObjMineWaterChain* chain2 = &this->chain.water; + + chain2->unk_40 = false; + if ((-0.000001f < chain2->unk_34) && (chain2->unk_34 <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, this->actor.world.pos.x, this->actor.world.pos.z))) { - sp58.x = this->actor.world.pos.x - this->actor.home.pos.x; - sp58.y = 0.0f; - sp58.z = this->actor.world.pos.z - this->actor.home.pos.z; - if (func_80A81288(&sp58, &sp4C, &sp40, &sp3C)) { - sp70.x = this->actor.world.pos.x + (sp4C.x * 36.0f); + Vec3f sp7C; + Vec3f sp70; + Vec3f sp64; + Vec3f xzDistFromHome; + Vec3f xzDirFromHome; + CollisionPoly* dummyPoly; + s32 dummyBgId; + f32 dummyNorm; + f32 dummyInvNorm; + + xzDistFromHome.x = this->actor.world.pos.x - this->actor.home.pos.x; + xzDistFromHome.y = 0.0f; + xzDistFromHome.z = this->actor.world.pos.z - this->actor.home.pos.z; + + if (ObjMine_GetUnitVec3fNorm(&xzDistFromHome, &xzDirFromHome, &dummyNorm, &dummyInvNorm)) { + + sp70.x = this->actor.world.pos.x + (xzDirFromHome.x * 36.0f); sp70.y = this->actor.world.pos.y; - sp70.z = this->actor.world.pos.z + (sp4C.z * 36.0f); + sp70.z = this->actor.world.pos.z + (xzDirFromHome.z * 36.0f); + sp7C.x = this->actor.home.pos.x; sp7C.y = this->actor.world.pos.y; sp7C.z = this->actor.home.pos.z; - if (BgCheck_EntityLineTest1(&play->colCtx, &sp7C, &sp70, &sp64, &sp48, 1, 0, 0, 1, &sp44)) { - temp_v1->unk_40 = 1; - temp_v1->unk_38 = sp4C.x * -0.2f; - temp_v1->unk_3C = sp4C.z * -0.2f; + + if (BgCheck_EntityLineTest1(&play->colCtx, &sp7C, &sp70, &sp64, &dummyPoly, 1, 0, 0, 1, &dummyBgId)) { + chain2->unk_40 = true; + chain2->unk_38 = xzDirFromHome.x * -0.2f; + chain2->unk_3C = xzDirFromHome.z * -0.2f; } } } } #ifdef NON_MATCHING -// Probably equivalent, but nightmare loop unrolls. +// Probably equivalent, but nightmare loop unrolls. void func_80A81FFC(ObjMine *this) { + static Vec3f D_80A849D0[0x40]; + ObjMineWaterChain *chain2 = &this->chain.water; + ObjMineWaterLink *link2; s32 i; - ObjMineTestStruct2 *temp_s1 = &this->chain2; - ObjMineUnkStruct2 *var_s0; - s32 temp_s6 = OBJMINE_GET_PARAM_003F(&this->actor); - s16 var_s3 = 0; - f32 temp_fs2 = 1.0f / (f32) temp_s6; + s16 var_s3; + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); + f32 invLinkCount = 1.0f / (f32) linkCount; + f32 temp_fs0 = (chain2->links[linkCount - 1].unk_24.y - chain2->unk_2C) * chain2->unk_30; Vec3f sp90; - f32 temp_fs0 = (temp_s1->unk_44[temp_s6 - 1].unk_24.y - temp_s1->unk_2C) * temp_s1->unk_30; f32 temp_ft4; - - for(i = 0, var_s0 = temp_s1->unk_44; i < temp_s6; i++, var_s0++) { - Math_Vec3f_Copy(&D_80A849D0[i], &var_s0->unk_3C); - if (var_s0->unk_24.y <= this->actor.home.pos.y) { - var_s0->unk_3C.y = temp_s1->unk_30 * -96.0f; + + for(i = 0, link2 = chain2->links, var_s3 = 0; i < linkCount; i++, link2++, var_s3 += chain2->unk_20) { + Math_Vec3f_Copy(&D_80A849D0[i], &link2->unk_3C); + if (link2->unk_24.y <= this->actor.home.pos.y) { + link2->unk_3C.y = chain2->unk_30 * -96.0f; } else if (temp_fs0 > 0.0f) { - var_s0->unk_3C.y = (i + 1) * temp_fs2 * (temp_fs0 / 0.3f); + link2->unk_3C.y = (i + 1) * invLinkCount * (temp_fs0 / 0.3f); } else { - var_s0->unk_3C.y = temp_fs0; + link2->unk_3C.y = temp_fs0; } - var_s0->unk_3C.x = (var_s0->unk_24.x - this->actor.home.pos.x) * temp_s1->unk_24; - var_s0->unk_3C.z = (var_s0->unk_24.z - this->actor.home.pos.z) * temp_s1->unk_24; - var_s0->unk_3C.x += temp_s1->unk_14 * Math_SinS(var_s3); - var_s0->unk_3C.y += temp_s1->unk_18; - var_s0->unk_3C.z += temp_s1->unk_14 * Math_CosS(var_s3); - var_s3 += temp_s1->unk_20; + link2->unk_3C.x = (link2->unk_24.x - this->actor.home.pos.x) * chain2->unk_24; + link2->unk_3C.z = (link2->unk_24.z - this->actor.home.pos.z) * chain2->unk_24; + link2->unk_3C.x += chain2->unk_14 * Math_SinS(var_s3); + link2->unk_3C.y += chain2->unk_18; + link2->unk_3C.z += chain2->unk_14 * Math_CosS(var_s3); } - if (temp_s1->unk_10 > 0.0001f) { - for(i = 0, var_s0 = temp_s1->unk_44; i < temp_s6; i++, var_s0++) { - temp_ft4 = SQ((temp_s6 - i) * temp_fs2); - var_s0->unk_3C.x += temp_s1->unk_04.x * temp_ft4; - var_s0->unk_3C.y += temp_s1->unk_04.y * temp_ft4; - var_s0->unk_3C.z += temp_s1->unk_04.z * temp_ft4; + if (chain2->unk_10 > 0.0001f) { + for(i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { + temp_ft4 = SQ((linkCount - i) * invLinkCount); + + link2->unk_3C.x += chain2->unk_04.x * temp_ft4; + link2->unk_3C.y += chain2->unk_04.y * temp_ft4; + link2->unk_3C.z += chain2->unk_04.z * temp_ft4; } } - if (temp_s1->unk_40) { - for(i = 0, var_s0 = temp_s1->unk_44; i < temp_s6; i++, var_s0++) { - var_s0->unk_3C.x += temp_s1->unk_38; - var_s0->unk_3C.z += temp_s1->unk_3C; + if (chain2->unk_40) { + for(i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { + link2->unk_3C.x += chain2->unk_38; + link2->unk_3C.z += chain2->unk_3C; } } - for(i = 0, var_s0 = temp_s1->unk_44; i < temp_s6; i++, var_s0++) { + for(i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { Math_Vec3f_Copy(&sp90, &gZeroVec3f); if(i - 2 >= 0) { sp90.x += D_80A849D0[i - 2].x * 0.075f; @@ -513,176 +516,186 @@ void func_80A81FFC(ObjMine *this) { sp90.y += D_80A849D0[i - 1].y * 0.15f; sp90.z += D_80A849D0[i - 1].z * 0.15f; } - sp90.x += D_80A849D0[i].x * 0.3f; - sp90.y += D_80A849D0[i].y * 0.3f; - sp90.z += D_80A849D0[i].z * 0.3f; - if(i + 1 < temp_s6) { + sp90.x += D_80A849D0[i].x * 0.3f; + sp90.y += D_80A849D0[i].y * 0.3f; + sp90.z += D_80A849D0[i].z * 0.3f; + if(i + 1 < linkCount) { sp90.x += D_80A849D0[i + 1].x * 0.15f; sp90.y += D_80A849D0[i + 1].y * 0.15f; sp90.z += D_80A849D0[i + 1].z * 0.15f; } - if(i + 2 < temp_s6) { + if(i + 2 < linkCount) { sp90.x += D_80A849D0[i + 2].x * 0.075f; sp90.y += D_80A849D0[i + 2].y * 0.075f; sp90.z += D_80A849D0[i + 2].z * 0.075f; } - var_s0->unk_3C.x += sp90.x; - var_s0->unk_3C.y += sp90.y; - var_s0->unk_3C.z += sp90.z; + link2->unk_3C.x += sp90.x; + link2->unk_3C.y += sp90.y; + link2->unk_3C.z += sp90.z; } } #else +Vec3f D_80A849D0[0x40]; void func_80A81FFC(ObjMine* this); #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81FFC.s") #endif void func_80A828A8(ObjMine* this) { - s32 i; + s32 pad; Vec3f spE0; Vec3f spD4; Vec3f spC8; - s32 spC4 = OBJMINE_GET_PARAM_003F(&this->actor); - ObjMineTestStruct2* sp70 = &this->chain2; - ObjMineUnkStruct2* temp_s0; + s32 spC4 = OBJMINE_GET_LINK_COUNT(&this->actor); + ObjMineWaterChain* chain2 = &this->chain.water; + ObjMineWaterLink* link2; + s32 i; Vec3f* phi_s3; - s32 phi_s5; Vec3f spA8; Vec3f sp9C; Vec3f sp90; Vec3f sp84; - s32 pad; + s32 phi_s5; f32 sp7C; f32 sp78; + Vec3f* phi_x; sp84.x = this->actor.home.pos.x; sp84.y = this->actor.home.pos.y + 6.0f; sp84.z = this->actor.home.pos.z; - for (i = 0, phi_s3 = NULL, temp_s0 = sp70->unk_44; i < spC4; i++, phi_s3 = &temp_s0->unk_00.x, temp_s0++) { + for (i = 0, phi_s3 = NULL, link2 = chain2->links; i < spC4; i++, phi_s3 = &link2->basis.x, link2++) { phi_s5 = false; - temp_s0->unk_30.x += temp_s0->unk_3C.x; - temp_s0->unk_30.y += temp_s0->unk_3C.y; - temp_s0->unk_30.z += temp_s0->unk_3C.z; - Math_Vec3f_Scale(&temp_s0->unk_30, sp70->unk_00); - Math_Vec3f_Copy(&sp90, &temp_s0->unk_24); - temp_s0->unk_24.x += temp_s0->unk_30.x; - temp_s0->unk_24.y += temp_s0->unk_30.y; - temp_s0->unk_24.z += temp_s0->unk_30.z; - if ((temp_s0->unk_24.y <= this->actor.home.pos.y) && (temp_s0->unk_30.y < 0.0f)) { - temp_s0->unk_30.y *= 0.1f; + link2->unk_30.x += link2->unk_3C.x; + link2->unk_30.y += link2->unk_3C.y; + link2->unk_30.z += link2->unk_3C.z; + + Math_Vec3f_Scale(&link2->unk_30, chain2->unk_00); + Math_Vec3f_Copy(&sp90, &link2->unk_24); + + link2->unk_24.x += link2->unk_30.x; + link2->unk_24.y += link2->unk_30.y; + link2->unk_24.z += link2->unk_30.z; + + if ((link2->unk_24.y <= this->actor.home.pos.y) && (link2->unk_30.y < 0.0f)) { + link2->unk_30.y *= 0.1f; } - Math_Vec3f_Diff(&temp_s0->unk_24, &sp84, &spA8); + Math_Vec3f_Diff(&link2->unk_24, &sp84, &spA8); - if (func_80A81288(&spA8, &sp9C, &sp7C, &sp78) && (sp7C > 4.0f)) { - Math_Vec3f_Copy(&spD4, &temp_s0->unk_00.y); - func_80A81714(&spD4, &sp9C, 0.10471976f); + if (ObjMine_GetUnitVec3fNorm(&spA8, &sp9C, &sp7C, &sp78) && (sp7C > 4.0f)) { + Math_Vec3f_Copy(&spD4, &link2->basis.y); + ObjMine_StepUntilParallel(&spD4, &sp9C, M_PI / 30); + phi_x = (phi_s3 == NULL) ? &sStandardBasis.x : phi_s3; - Math3D_CrossProduct((phi_s3 == NULL) ? &D_80A845C4 : phi_s3, &spD4, &spA8); + Math3D_CrossProduct(phi_x, &spD4, &spA8); - if (func_80A8120C(&spA8, &spE0)) { + if (ObjMine_GetUnitVec3f(&spA8, &spE0)) { Math3D_CrossProduct(&spD4, &spE0, &spA8); - if (func_80A8120C(&spA8, &spC8)) { + if (ObjMine_GetUnitVec3f(&spA8, &spC8)) { phi_s5 = true; } } } if (phi_s5) { - Math_Vec3f_Copy(&temp_s0->unk_00.x, &spC8); - Math_Vec3f_Copy(&temp_s0->unk_00.y, &spD4); - Math_Vec3f_Copy(&temp_s0->unk_00.z, &spE0); + Math_Vec3f_Copy(&link2->basis.x, &spC8); + Math_Vec3f_Copy(&link2->basis.y, &spD4); + Math_Vec3f_Copy(&link2->basis.z, &spE0); } else { sp7C = 4.0f; } if (sp7C >= 6.0f) { - temp_s0->unk_24.x = sp84.x + (temp_s0->unk_00.y.x * 6.0f); - temp_s0->unk_24.y = sp84.y + (temp_s0->unk_00.y.y * 6.0f); - temp_s0->unk_24.z = sp84.z + (temp_s0->unk_00.y.z * 6.0f); + link2->unk_24.x = sp84.x + (link2->basis.y.x * 6.0f); + link2->unk_24.y = sp84.y + (link2->basis.y.y * 6.0f); + link2->unk_24.z = sp84.z + (link2->basis.y.z * 6.0f); } else { - temp_s0->unk_24.x = sp84.x + (temp_s0->unk_00.y.x * sp7C); - temp_s0->unk_24.y = sp84.y + (temp_s0->unk_00.y.y * sp7C); - temp_s0->unk_24.z = sp84.z + (temp_s0->unk_00.y.z * sp7C); + link2->unk_24.x = sp84.x + (link2->basis.y.x * sp7C); + link2->unk_24.y = sp84.y + (link2->basis.y.y * sp7C); + link2->unk_24.z = sp84.z + (link2->basis.y.z * sp7C); } - sp84.x = temp_s0->unk_24.x + (temp_s0->unk_00.y.x * 6.0f); - sp84.y = temp_s0->unk_24.y + (temp_s0->unk_00.y.y * 6.0f); - sp84.z = temp_s0->unk_24.z + (temp_s0->unk_00.y.z * 6.0f); + sp84.x = link2->unk_24.x + (link2->basis.y.x * 6.0f); + sp84.y = link2->unk_24.y + (link2->basis.y.y * 6.0f); + sp84.z = link2->unk_24.z + (link2->basis.y.z * 6.0f); } } -void func_80A82C28(ObjMine* this, PlayState* play) { +void ObjMine_Water_UpdateChain(ObjMine* this, PlayState* play) { func_80A81E7C(this, play); func_80A81FFC(this); func_80A828A8(this); } void ObjMine_Init(Actor* thisx, PlayState* play) { - ObjMine* this = THIS; s32 pad; - s32 sp44 = OBJMINE_GET_PARAM_00FF(&this->actor); + ObjMine* this = THIS; + s32 pathIndex = OBJMINE_GET_PATH(&this->actor); Path* path; - s32 sp3C; - s32 sp38 = OBJMINE_GET_PARAM_3000(&this->actor); - s32 sp34; + s32 dummyBgId; + s32 type = OBJMINE_GET_TYPE(&this->actor); Actor_ProcessInitChain(&this->actor, sInitChain); + this->actor.shape.rot.z = 0; this->actor.world.rot.z = 0; + Collider_InitJntSph(play, &this->collider); Collider_SetJntSph(play, &this->collider, &this->actor, &sJntSphInit, this->colliderElements); - if (sp38 == 0) { + if (type == OBJMINE_TYPE_PATH) { ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 45.0f); this->actor.shape.shadowAlpha = 140; - this->unk_1A8 = D_80A845A4[OBJMINE_GET_PARAM_0700(&this->actor)]; - if (sp44 == 0xFF) { - func_80A82F84(this); + this->pathSpeed = sPathSpeeds[OBJMINE_GET_PATH_SPEED(&this->actor)]; + if (pathIndex == 0xFF) { + ObjMine_Path_SetupStationary(this); } else { - path = &play->setupPathList[sp44]; - this->unk_1B0 = 0; - this->unk_1AC = path->count - 1; - this->unk_1B4 = (Vec3s*)Lib_SegmentedToVirtual(path->points); - func_80A811D0(this, this->unk_1B0); - func_80A82FA8(this); + path = &play->setupPathList[pathIndex]; + + this->waypointIndex = 0; + this->waypointCount = path->count - 1; + this->waypoints = (Vec3s*)Lib_SegmentedToVirtual(path->points); + + ObjMine_Path_MoveToWaypoint(this, this->waypointIndex); + ObjMine_Path_SetupMove(this); } Matrix_SetTranslateRotateYXZ(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, &this->actor.shape.rot); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); - this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &sp3C, + this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &dummyBgId, &this->actor, &this->actor.world.pos); } else { - sp34 = OBJMINE_GET_PARAM_003F(&this->actor); - this->actor.update = func_80A83E7C; - this->actor.uncullZoneScale = (sp34 * 21.0f) + 150.0f; - this->actor.uncullZoneDownward = (sp34 * 21.0f) + 150.0f; - ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 45.0f); - this->actor.shape.shadowAlpha = 0x8C; + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - if (sp38 == 1) { - this->actor.draw = func_80A84088; - func_80A81868(this, sp34); - this->actor.world.pos.y = (-10.0f - (sp34 * 12.0f)) + this->actor.home.pos.y; - func_80A819A4(this, sp34); + this->actor.update = ObjMine_AirWater_Update; + this->actor.uncullZoneScale = 150.0f + (linkCount * 21.0f); + this->actor.uncullZoneDownward = 150.0f + (linkCount * 21.0f); + ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 45.0f); + this->actor.shape.shadowAlpha = 140; + + if (type == OBJMINE_TYPE_AIR) { + this->actor.draw = ObjMine_Air_Draw; + ObjMine_Air_InitChain(this, linkCount); + this->actor.world.pos.y = -10.0f - (linkCount * 12.0f) + this->actor.home.pos.y; + ObjMine_Air_SetCollider(this, linkCount); func_800B4AEC(play, &this->actor, 0.0f); - if (sp34 == 0) { - func_80A83A74(this); + if (linkCount == 0) { + ObjMine_Air_SetupStationary(this); } else { - func_80A832BC(this); + ObjMine_Air_SetupChained(this); } } else { - this->actor.draw = func_80A84338; - func_80A81B7C(this, sp34); - this->actor.world.pos.y = (sp34 * 12.0f) + 10.0f + this->actor.home.pos.y; - func_80A81D70(this, sp34); - if (sp34 == 0) { - func_80A83CEC(this); + this->actor.draw = ObjMine_Water_Draw; + ObjMine_Water_InitChain(this, linkCount); + this->actor.world.pos.y = 10.0f + (linkCount * 12.0f) + this->actor.home.pos.y; + ObjMine_Water_SetCollider(this, linkCount); + if (linkCount == 0) { + ObjMine_Water_SetupStationary(this); } else { - func_80A83B14(this); + ObjMine_Water_SetupChained(this); } } } @@ -694,217 +707,223 @@ void ObjMine_Destroy(Actor* thisx, PlayState* play) { Collider_DestroyJntSph(play, &this->collider); } -void func_80A82F84(ObjMine* this) { - this->actionFunc = func_80A82F98; +void ObjMine_Path_SetupStationary(ObjMine* this) { + this->actionFunc = ObjMine_Path_Stationary; } -void func_80A82F98(ObjMine* this, PlayState* play) { +void ObjMine_Path_Stationary(ObjMine* this, PlayState* play) { } -void func_80A82FA8(ObjMine* this) { +void ObjMine_Path_SetupMove(ObjMine* this) { this->actor.flags |= ACTOR_FLAG_10; - this->actionFunc = func_80A82FC8; + this->actionFunc = ObjMine_Path_Move; } -void func_80A82FC8(ObjMine* this, PlayState* play) { - Actor* thisx = &this->actor; - Vec3f spA0; +void ObjMine_Path_Move(ObjMine* this, PlayState* play) { + Actor* thisx = &this->actor; // pos and velocity need this, though it can replace all `this->actor`s and match + Vec3f nextWaypoint; f32 speed; f32 step; f32 target; - s32 sp90; - Vec3f sp84; - Vec3f sp78; - MtxF sp38; + s32 dummyBgVec; - Math_Vec3s_ToVec3f(&spA0, &this->unk_1B4[this->unk_1B0 + 1]); - Math_Vec3f_Diff(&spA0, &thisx->world.pos, &thisx->velocity); + Math_Vec3s_ToVec3f(&nextWaypoint, &this->waypoints[this->waypointIndex + 1]); + Math_Vec3f_Diff(&nextWaypoint, &thisx->world.pos, &thisx->velocity); speed = Math3D_Vec3fMagnitude(&thisx->velocity); - if ((speed < (this->unk_1A8 * 8.0f)) && (this->unk_1A8 > 2.0f)) { - target = ((this->unk_1A8 - 2.0f) * 0.1f) + 2.0f; - step = this->unk_1A8 * 0.03f; + if ((speed < (this->pathSpeed * 8.0f)) && (this->pathSpeed > 2.0f)) { + target = 2.0f + ((this->pathSpeed - 2.0f) * 0.1f); + step = this->pathSpeed * 0.03f; } else { - target = this->unk_1A8; - step = this->unk_1A8 * 0.16f; + target = this->pathSpeed; + step = this->pathSpeed * 0.16f; } - Math_StepToF(&thisx->speedXZ, target, step); - if ((thisx->speedXZ + 0.05f) < speed) { - Math_Vec3f_Scale(&thisx->velocity, thisx->speedXZ / speed); - thisx->world.pos.x += thisx->velocity.x; - thisx->world.pos.y += thisx->velocity.y; - thisx->world.pos.z += thisx->velocity.z; + Math_StepToF(&this->actor.speedXZ, target, step); + if ((this->actor.speedXZ + 0.05f) < speed) { + Math_Vec3f_Scale(&thisx->velocity, this->actor.speedXZ / speed); + this->actor.world.pos.x += thisx->velocity.x; + this->actor.world.pos.y += thisx->velocity.y; + this->actor.world.pos.z += thisx->velocity.z; } else { - thisx->speedXZ *= 0.4f; - this->unk_1B0++; - if (this->unk_1B0 >= this->unk_1AC) { - this->unk_1B0 = 0; + this->actor.speedXZ *= 0.4f; + this->waypointIndex++; + if (this->waypointIndex >= this->waypointCount) { + this->waypointIndex = 0; } - func_80A811D0(this, this->unk_1B0); + ObjMine_Path_MoveToWaypoint(this, this->waypointIndex); } - thisx->floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &thisx->floorPoly, &sp90, thisx, &thisx->world.pos); - if (thisx->flags & 0x40) { - Math3D_CrossProduct(&D_80A845D0[0], &thisx->velocity, &sp78); - if (func_80A8120C(&sp78, &sp84)) { - Matrix_RotateAxisF(thisx->speedXZ * 0.03125f, &sp84, MTXMODE_NEW); - Matrix_RotateYS(thisx->shape.rot.y, MTXMODE_APPLY); - Matrix_RotateXS(thisx->shape.rot.x, MTXMODE_APPLY); - Matrix_RotateZS(thisx->shape.rot.z, MTXMODE_APPLY); - Matrix_Get(&sp38); - Matrix_MtxFToYXZRot(&sp38, &thisx->shape.rot, false); + this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &dummyBgVec, &this->actor, &thisx->world.pos); + if (this->actor.flags & ACTOR_FLAG_40) { + Vec3f rotAxis; + Vec3f yhatCrossV; + MtxF rotMtxF; + + Math3D_CrossProduct(&sStandardBasis.y, &thisx->velocity, &yhatCrossV); + if (ObjMine_GetUnitVec3f(&yhatCrossV, &rotAxis)) { + Matrix_RotateAxisF(this->actor.speedXZ / 32.0f, &rotAxis, MTXMODE_NEW); + Matrix_RotateYS(this->actor.shape.rot.y, MTXMODE_APPLY); + Matrix_RotateXS(this->actor.shape.rot.x, MTXMODE_APPLY); + Matrix_RotateZS(this->actor.shape.rot.z, MTXMODE_APPLY); + Matrix_Get(&rotMtxF); + Matrix_MtxFToYXZRot(&rotMtxF, &this->actor.shape.rot, false); } } } -void func_80A83214(ObjMine* this) { - this->actor.flags |= 0x10; - this->actor.draw = func_80A83FBC; +void ObjMine_SetupExplode(ObjMine* this) { + this->actor.flags |= ACTOR_FLAG_10; + this->actor.draw = ObjMine_DrawExplosion; this->actor.shape.shadowDraw = NULL; this->actor.scale.x = 0.02f; this->actor.scale.y = 0.02f; this->actor.scale.z = 0.02f; - this->actionFunc = func_80A83258; + this->actionFunc = ObjMine_Explode; } -void func_80A83258(ObjMine* this, PlayState* play) { +void ObjMine_Explode(ObjMine* this, PlayState* play) { this->actor.scale.x *= 1.8f; - if (this->actor.scale.x > 0.17495999f) { - Actor_MarkForDeath(&this->actor); + if (this->actor.scale.x > 30.0f * 0.001f * CUBE(1.8f)) { + Actor_Kill(&this->actor); } else { this->actor.scale.y = this->actor.scale.x; this->actor.scale.z = this->actor.scale.x; } } -void func_80A832BC(ObjMine* this) { - this->actionFunc = func_80A832D0; +void ObjMine_Air_SetupChained(ObjMine* this) { + this->actionFunc = ObjMine_Air_Chained; } -void func_80A832D0(ObjMine* this, PlayState* play) { +void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { s32 pad; - s32 spA0 = OBJMINE_GET_PARAM_003F(&this->actor); - ObjMineUnkStruct* unkStruct = &this->chain1; - ObjMineUnkStruct3* temp; + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); + ObjMineAirChain* chain1 = &this->chain.air; + ObjMineAirLink* link1; s32 i; f32 sp90; f32 sp8C; f32 sp88; s16 sp86; s16 sp84; - s32 pad2; - s32 pad3; - Math_Vec3f_Copy(&unkStruct->unk_24, &unkStruct->unk_00.y); - if (func_80A8140C(this)) { - func_80A81384(this, play); - func_80A81640(this); - func_80A83214(this); + Math_Vec3f_Copy(&chain1->unk_24, &chain1->basis.y); + if (ObjMine_AirWater_CheckOC(this)) { + ObjMine_AirWater_SpawnBomb(this, play); + ObjMine_AirWater_Noop(this); + ObjMine_SetupExplode(this); return; } if (this->collider.base.acFlags & AC_HIT) { this->collider.base.acFlags &= ~AC_HIT; - unkStruct->unk_48 = 0.04f; - func_80A8146C(this, &unkStruct->unk_4C, &sp84); + chain1->unk_48 = 0.04f; + ObjMine_Air_CheckAC(this, &chain1->unk_4C, &sp84); sp88 = sp8C = Math_SinS(sp84) * 150.0f; - sp8C = -(sp8C / spA0); + sp8C = -(sp8C / linkCount); - for (i = 0, temp = unkStruct->unk_60; i < spA0; i++, temp++) { - temp->unk_02 += (s16)sp88; - temp->unk_02 = CLAMP(temp->unk_02, -800, 800); + for (i = 0, link1 = chain1->links; i < linkCount; i++, link1++) { + link1->unk_02 += (s16)sp88; + link1->unk_02 = CLAMP(link1->unk_02, -800, 800); sp88 -= sp8C; } } - if (unkStruct->unk_48 > 0.0001f) { - sp90 = Math_SinS(unkStruct->unk_4C) * unkStruct->unk_48; - sp8C = Math_CosS(unkStruct->unk_4C) * unkStruct->unk_48; - unkStruct->unk_38 += sp90; - unkStruct->unk_3C += sp8C; - Math_StepToF(&unkStruct->unk_48, 0.0f, 0.02f); + if (chain1->unk_48 > 0.0001f) { + sp90 = Math_SinS(chain1->unk_4C) * chain1->unk_48; + sp8C = Math_CosS(chain1->unk_4C) * chain1->unk_48; + chain1->unk_38 += sp90; + chain1->unk_3C += sp8C; + Math_StepToF(&chain1->unk_48, 0.0f, 0.02f); } - if ((Rand_Next() >> 0x1B) == 0) { - unkStruct->unk_50 = Rand_ZeroOne() * unkStruct->unk_58; - unkStruct->unk_54 = Rand_Next() >> 0x10; + if (RANDU_BITS(5) == 0) { + chain1->unk_50 = Rand_ZeroOne() * chain1->unk_58; + chain1->unk_54 = RANDU_BITS(16); } - sp90 = Math_SinS(unkStruct->unk_54) * unkStruct->unk_50; - sp8C = Math_CosS(unkStruct->unk_54) * unkStruct->unk_50; - unkStruct->unk_38 += sp90; - unkStruct->unk_3C += sp8C; + sp90 = Math_SinS(chain1->unk_54) * chain1->unk_50; + sp8C = Math_CosS(chain1->unk_54) * chain1->unk_50; + chain1->unk_38 += sp90; + chain1->unk_3C += sp8C; - unkStruct->unk_38 += unkStruct->unk_30 * unkStruct->unk_40; - unkStruct->unk_3C += unkStruct->unk_34 * unkStruct->unk_40; + chain1->unk_38 += chain1->unk_30 * chain1->unk_40; + chain1->unk_3C += chain1->unk_34 * chain1->unk_40; - unkStruct->unk_38 *= unkStruct->unk_44; - unkStruct->unk_3C *= unkStruct->unk_44; + chain1->unk_38 *= chain1->unk_44; + chain1->unk_3C *= chain1->unk_44; - unkStruct->unk_30 += unkStruct->unk_38; - unkStruct->unk_34 += unkStruct->unk_3C; + chain1->unk_30 += chain1->unk_38; + chain1->unk_34 += chain1->unk_3C; - unkStruct->unk_30 = CLAMP(unkStruct->unk_30, -5.0f, 5.0f); - unkStruct->unk_34 = CLAMP(unkStruct->unk_34, -5.0f, 5.0f); + chain1->unk_30 = CLAMP(chain1->unk_30, -5.0f, 5.0f); + chain1->unk_34 = CLAMP(chain1->unk_34, -5.0f, 5.0f); - func_80A81A00(this); - func_80A81AA4(this); + ObjMine_Air_SetBasis(this); + ObjMine_Air_SetWorld(this); - if ((unkStruct->unk_5C > -0.000001f) && - (unkStruct->unk_5C <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, - this->actor.home.pos.x, this->actor.home.pos.z))) { - Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, 20.0f, 0.0f, 1); + if (chain1->unk_5C > -0.000001f) { + Vec3f* world = &this->actor.world.pos; + Vec3f* home = &this->actor.home.pos; - if ((this->actor.bgCheckFlags & 8) && (this->actor.wallPoly != NULL)) { - Vec3f sp70; - Vec3f sp64; - Vec3f sp58; - Vec3f sp4C; - f32 sp48; - f32 sp44; + if (chain1->unk_5C <= Math3D_XZDistanceSquared(world->x, world->z, home->x, home->z)) { - sp4C.x = unkStruct->unk_38; - sp4C.y = 0.0f; - sp4C.z = unkStruct->unk_3C; - if (func_80A81288(&sp4C, &sp70, &sp48, &sp44)) { - sp58.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); - sp58.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); - sp58.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); - func_80179F64(&sp70, &sp58, &sp64); - sp48 *= 0.5f; - unkStruct->unk_38 = sp64.x * sp48; - unkStruct->unk_3C = sp64.z * sp48; - } else { - unkStruct->unk_38 *= -0.1f; - unkStruct->unk_3C *= -0.1f; + Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, 20.0f, 0.0f, 1); + + if ((this->actor.bgCheckFlags & 8) && (this->actor.wallPoly != NULL)) { + Vec3f sp70; + Vec3f sp64; + Vec3f sp58; + Vec3f sp4C; + f32 sp48; + f32 sp44; + + sp4C.x = chain1->unk_38; + sp4C.y = 0.0f; + sp4C.z = chain1->unk_3C; + + if (ObjMine_GetUnitVec3fNorm(&sp4C, &sp70, &sp48, &sp44)) { + sp58.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); + sp58.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); + sp58.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); + + func_80179F64(&sp70, &sp58, &sp64); + + sp48 *= 0.5f; + chain1->unk_38 = sp64.x * sp48; + chain1->unk_3C = sp64.z * sp48; + } else { + chain1->unk_38 *= -0.1f; + chain1->unk_3C *= -0.1f; + } + ObjMine_Air_SetChain3034(this); + ObjMine_Air_SetBasis(this); + ObjMine_Air_SetWorld(this); } - func_80A81B14(this); - func_80A81A00(this); - func_80A81AA4(this); } } - for (i = 0, temp = unkStruct->unk_60; i < spA0; i++, temp++) { - sp86 = temp->unk_00 - 0x4000; - sp88 = temp->unk_02 + (sp86 * -0.05f) + ((Rand_ZeroOne() * 30.0f) - 15.0f); + for (i = 0, link1 = chain1->links; i < linkCount; i++, link1++) { + sp86 = link1->unk_00 - 0x4000; + sp88 = link1->unk_02 + (sp86 * -0.05f) + ((Rand_ZeroOne() * 30.0f) - 15.0f); sp88 *= 0.995f; - temp->unk_02 = sp88; - temp->unk_00 += temp->unk_02; + link1->unk_02 = sp88; + link1->unk_00 += link1->unk_02; } func_800B4AEC(play, &this->actor, 0.0f); - func_80A81818(this); + ObjMine_UpdateCollider(this); CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); } -void func_80A83A74(ObjMine* this) { - this->actionFunc = func_80A83A88; +void ObjMine_Air_SetupStationary(ObjMine* this) { + this->actionFunc = ObjMine_Air_Stationary; } -void func_80A83A88(ObjMine* this, PlayState* play) { - if (func_80A8140C(this)) { - func_80A81384(this, play); - func_80A81640(this); - func_80A83214(this); +void ObjMine_Air_Stationary(ObjMine* this, PlayState* play) { + if (ObjMine_AirWater_CheckOC(this)) { + ObjMine_AirWater_SpawnBomb(this, play); + ObjMine_AirWater_Noop(this); + ObjMine_SetupExplode(this); return; } @@ -912,59 +931,60 @@ void func_80A83A88(ObjMine* this, PlayState* play) { CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); } -void func_80A83B14(ObjMine* this) { - this->actionFunc = func_80A83B28; +void ObjMine_Water_SetupChained(ObjMine* this) { + this->actionFunc = ObjMine_Water_Chained; } -void func_80A83B28(ObjMine* this, PlayState* play) { - ObjMineTestStruct2* ptr = &this->chain2; +void ObjMine_Water_Chained(ObjMine* this, PlayState* play) { + ObjMineWaterChain* chain2 = &this->chain.water; - if (func_80A8140C(this)) { - func_80A81384(this, play); - func_80A81640(this); - func_80A83214(this); + if (ObjMine_AirWater_CheckOC(this)) { + ObjMine_AirWater_SpawnBomb(this, play); + ObjMine_AirWater_Noop(this); + ObjMine_SetupExplode(this); return; } if (this->collider.base.acFlags & AC_HIT) { this->collider.base.acFlags &= ~AC_HIT; - func_80A81544(this, &ptr->unk_04); - ptr->unk_10 = 7.0f; - Math_Vec3f_Scale(&ptr->unk_04, 7.0f); + ObjMine_Water_CheckAC(this, &chain2->unk_04); + chain2->unk_10 = 7.0f; + Math_Vec3f_Scale(&chain2->unk_04, 7.0f); } - if (ptr->unk_10 > 0.0001f) { - ptr->unk_10 = Math_Vec3f_StepTo( &ptr->unk_04, &gZeroVec3f, 2.8f); + if (chain2->unk_10 > 0.0001f) { + chain2->unk_10 = Math_Vec3f_StepTo(&chain2->unk_04, &gZeroVec3f, 2.8f); } - ptr->unk_00 = 0.9f; - ptr->unk_24 = -0.0002f; - ptr->unk_30 = -0.0002f; - ptr->unk_1C = 0.003f; - if ((Rand_Next() >> 0x1B) == 0) { - s16 rand = Rand_Next() >> 0x10; + chain2->unk_00 = 0.9f; + chain2->unk_24 = -0.0002f; + chain2->unk_30 = -0.0002f; + chain2->unk_1C = 0.003f; - ptr->unk_14 = Math_SinS(rand) * 1.8f * ptr->unk_1C; - ptr->unk_18 = Math_CosS(rand) * 0.2f * ptr->unk_1C; - ptr->unk_20 = Rand_Next() >> 0x13; + if (RANDU_BITS(5) == 0) { + s16 randAngle = RANDU_BITS(16); + + chain2->unk_14 = Math_SinS(randAngle) * 1.8f * chain2->unk_1C; + chain2->unk_18 = Math_CosS(randAngle) * 0.2f * chain2->unk_1C; + chain2->unk_20 = RANDU_BITS(13); } - func_80A82C28(this, play); - func_80A81DEC(this); - func_80A81818(this); + ObjMine_Water_UpdateChain(this, play); + ObjMine_Water_SetWorld(this); + ObjMine_UpdateCollider(this); CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); } -void func_80A83CEC(ObjMine* this) { - this->actionFunc = func_80A83D00; +void ObjMine_Water_SetupStationary(ObjMine* this) { + this->actionFunc = ObjMine_Water_Stationary; } -void func_80A83D00(ObjMine* this, PlayState* play) { - if (func_80A8140C(this)) { - func_80A81384(this, play); - func_80A81640(this); - func_80A83214(this); +void ObjMine_Water_Stationary(ObjMine* this, PlayState* play) { + if (ObjMine_AirWater_CheckOC(this)) { + ObjMine_AirWater_SpawnBomb(this, play); + ObjMine_AirWater_Noop(this); + ObjMine_SetupExplode(this); return; } @@ -973,13 +993,13 @@ void func_80A83D00(ObjMine* this, PlayState* play) { } -void ObjMine_Update(Actor* thisx, PlayState* play) { +void ObjMine_Path_Update(Actor* thisx, PlayState* play) { s32 pad; ObjMine* this = THIS; if ((this->collider.base.ocFlags2 & OC2_HIT_PLAYER) || (this->collider.base.acFlags & AC_HIT)) { - func_80A8131C(this, play); - func_80A83214(this); + ObjMine_Path_SpawnBomb(this, play); + ObjMine_SetupExplode(this); } this->actionFunc(this, play); @@ -988,26 +1008,26 @@ void ObjMine_Update(Actor* thisx, PlayState* play) { this->collider.base.ocFlags1 &= ~OC1_HIT; this->collider.base.acFlags &= ~AC_HIT; this->collider.base.ocFlags2 &= ~OC2_HIT_PLAYER; - if ((this->actor.flags & 0x40) && (this->actionFunc != func_80A83258)) { + if ((this->actor.flags & ACTOR_FLAG_40) && (this->actionFunc != ObjMine_Explode)) { CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); } } } -void func_80A83E7C(Actor* thisx, PlayState* play) { +void ObjMine_AirWater_Update(Actor* thisx, PlayState* play) { ObjMine* this = THIS; this->actionFunc(this, play); } -void ObjMine_Draw(Actor* thisx, PlayState* play) { +void ObjMine_Path_Draw(Actor* thisx, PlayState* play) { s32 pad; ObjMine* this = THIS; OPEN_DISPS(play->state.gfxCtx); - if (this->actionFunc == func_80A82FC8) { + if (this->actionFunc == ObjMine_Path_Move) { Collider_UpdateSpheres(0, &this->collider); } @@ -1023,12 +1043,12 @@ void ObjMine_Draw(Actor* thisx, PlayState* play) { CLOSE_DISPS(play->state.gfxCtx); } -void func_80A83FBC(Actor* thisx, PlayState* play) { - ObjMine* this = THIS; +void ObjMine_DrawExplosion(Actor* thisx, PlayState* play) { + s32 pad; // This could be thisx recast or playstate recast. OPEN_DISPS(play->state.gfxCtx); - func_800B8118(&this->actor, play, 1); + func_800B8118(thisx, play, 1); func_8012C2DC(play->state.gfxCtx); gDPSetRenderMode(POLY_XLU_DISP++, G_RM_PASS, G_RM_AA_ZB_XLU_SURF2); @@ -1039,12 +1059,12 @@ void func_80A83FBC(Actor* thisx, PlayState* play) { CLOSE_DISPS(play->state.gfxCtx); } -void func_80A84088(Actor* thisx, PlayState* play) { +void ObjMine_Air_Draw(Actor* thisx, PlayState* play) { s32 pad; ObjMine* this = THIS; - s32 temp_s5 = OBJMINE_GET_PARAM_003F(&this->actor); - ObjMineUnkStruct3* temp; - ObjMineUnkStruct* ptr = &this->chain1; + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); + ObjMineAirChain* chain1 = &this->chain.air; + ObjMineAirLink* link1; s32 i; Vec3f sp94; Vec3f sp88; @@ -1059,21 +1079,21 @@ void func_80A84088(Actor* thisx, PlayState* play) { gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); - func_80A81684(&ptr->unk_00); + ObjMine_ReplaceRotation(&chain1->basis); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); - if (temp_s5 != 0) { - Math_Vec3f_ScaleAndStore(&ptr->unk_00.y, -6.0f, &sp88); + if (linkCount != 0) { + Math_Vec3f_ScaleAndStore(&chain1->basis.y, -6.0f, &sp88); sp94.x = this->actor.home.pos.x - sp88.x; - sp94.y = (this->actor.home.pos.y - 6.0f) - sp88.y; + sp94.y = this->actor.home.pos.y - 6.0f - sp88.y; sp94.z = this->actor.home.pos.z - sp88.z; - Math_Vec3f_ScaleAndStore(&ptr->unk_00.y, -12.0f, &sp88); + Math_Vec3f_ScaleAndStore(&chain1->basis.y, -12.0f, &sp88); - for (i = 0, temp = ptr->unk_60; i < temp_s5; i++, temp++) { - Matrix_RotateYS(temp->unk_00, MTXMODE_APPLY); + for (i = 0, link1 = chain1->links; i < linkCount; i++, link1++) { + Matrix_RotateYS(link1->unk_00, MTXMODE_APPLY); sp94.x += sp88.x; sp94.y += sp88.y; sp94.z += sp88.z; - func_80A8164C(&sp94); + ObjMine_ReplaceTranslation(&sp94); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); @@ -1081,7 +1101,7 @@ void func_80A84088(Actor* thisx, PlayState* play) { } Matrix_RotateXS(0x2000, MTXMODE_APPLY); - func_80A8164C(&this->actor.world.pos); + ObjMine_ReplaceTranslation(&this->actor.world.pos); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gDPPipeSync(gfx++); @@ -1095,14 +1115,14 @@ void func_80A84088(Actor* thisx, PlayState* play) { CLOSE_DISPS(play->state.gfxCtx); } -void func_80A84338(Actor* thisx, PlayState* play) { - s32 pad1; +void ObjMine_Water_Draw(Actor* thisx, PlayState* play) { + s32 pad; ObjMine* this = THIS; - s32 temp_s7 = OBJMINE_GET_PARAM_003F(&this->actor); - ObjMineTestStruct2* pad2 = &this->chain2; + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); + ObjMineWaterChain* chain2 = &this->chain.water; + ObjMineWaterLink* link2; s32 i; Gfx* gfx; - ObjMineUnkStruct2* temp; func_800B8050(&this->actor, play, 1); @@ -1113,20 +1133,20 @@ void func_80A84338(Actor* thisx, PlayState* play) { gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); - for (i = 0, temp = pad2->unk_44; i < temp_s7; i++, temp++) { - func_80A81684(&temp->unk_00); - Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, 1); - if ((i & 1) == 0) { + for (i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { + ObjMine_ReplaceRotation(&link2->basis); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + if ((i % 2) == 0) { Matrix_RotateYS(0x4000, MTXMODE_APPLY); } - func_80A8164C(&temp->unk_24); + ObjMine_ReplaceTranslation(&link2->unk_24); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); } - Matrix_RotateXS(0x2000, 1); - func_80A8164C(&this->actor.world.pos); + Matrix_RotateXS(0x2000, MTXMODE_APPLY); + ObjMine_ReplaceTranslation(&this->actor.world.pos); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gDPPipeSync(gfx++); diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index 467509cd4..bcee16c65 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -7,27 +7,33 @@ struct ObjMine; typedef void (*ObjMineActionFunc)(struct ObjMine*, PlayState*); -#define OBJMINE_GET_PARAM_003F(thisx) ((thisx)->params & 0x3F) -#define OBJMINE_GET_PARAM_00FF(thisx) ((thisx)->params & 0xFF) -#define OBJMINE_GET_PARAM_0700(thisx) ((thisx)->params >> 8 & 7) -#define OBJMINE_GET_PARAM_3000(thisx) ((thisx)->params >> 0xC & 3) +#define OBJMINE_GET_LINK_COUNT(thisx) ((thisx)->params & 0x3F) +#define OBJMINE_GET_PATH(thisx) ((thisx)->params & 0xFF) +#define OBJMINE_GET_PATH_SPEED(thisx) (((thisx)->params >> 8) & 7) +#define OBJMINE_GET_TYPE(thisx) (((thisx)->params >> 12) & 3) + +#define OBJMINE_SET_PARAM0(pathIndex, pathSpeed, type) ((pathIndex) | ((pathSpeed) << 8)) +#define OBJMINE_SET_PARAM12(linkCount, type) ((linkCount) | ((type) << 0xC)) + +typedef enum { + /* 0 */ OBJMINE_TYPE_PATH, + /* 1 */ OBJMINE_TYPE_AIR, + /* 2 */ OBJMINE_TYPE_WATER +} ObjMineType; typedef struct { - Vec3f x; - Vec3f y; - Vec3f z; - // Vec3f w; -} ObjMineMtxF3; + /* 0x00 */ Vec3f x; + /* 0x0C */ Vec3f y; + /* 0x18 */ Vec3f z; +} ObjMineMtxF3; // size = 0x24 typedef struct { /* 0x00 */ s16 unk_00; /* 0x02 */ s16 unk_02; -} ObjMineUnkStruct3; +} ObjMineAirLink; // size = 0x4 typedef struct { - /* 0x00 */ ObjMineMtxF3 unk_00; - // /* 0x0C */ Vec3f unk_0C; - // /* 0x18 */ Vec3f unk_18; + /* 0x00 */ ObjMineMtxF3 basis; /* 0x24 */ Vec3f unk_24; /* 0x30 */ f32 unk_30; /* 0x34 */ f32 unk_34; @@ -41,49 +47,48 @@ typedef struct { /* 0x54 */ s16 unk_54; /* 0x58 */ f32 unk_58; /* 0x5C */ f32 unk_5C; - /* 0x60 */ ObjMineUnkStruct3* unk_60; -} ObjMineUnkStruct; // size = ?? 0x44??? 48 array??? + /* 0x60 */ ObjMineAirLink links[0x3F]; +} ObjMineAirChain; // size = 0x15C -// probably fake typedef struct { - /* 0x00 */ ObjMineMtxF3 unk_00; - // /* 0x0c */ Vec3f unk_0C; - // /* 0x18 */ Vec3f unk_18; + /* 0x00 */ ObjMineMtxF3 basis; /* 0x24 */ Vec3f unk_24; /* 0x30 */ Vec3f unk_30; /* 0x3C */ Vec3f unk_3C; -} ObjMineUnkStruct2; // size = 0x48??? +} ObjMineWaterLink; // size = 0x48 typedef struct { - f32 unk_00; - Vec3f unk_04; - f32 unk_10; - f32 unk_14; - f32 unk_18; - f32 unk_1C; - s16 unk_20; - f32 unk_24; - f32 unk_28; - f32 unk_2C; - f32 unk_30; - f32 unk_34; - f32 unk_38; - f32 unk_3C; - s8 unk_40; - ObjMineUnkStruct2 unk_44[0x3F]; -} ObjMineTestStruct2; + /* 0x0000 */ f32 unk_00; + /* 0x0004 */ Vec3f unk_04; + /* 0x0010 */ f32 unk_10; + /* 0x0014 */ f32 unk_14; + /* 0x0018 */ f32 unk_18; + /* 0x001C */ f32 unk_1C; + /* 0x0020 */ s16 unk_20; + /* 0x0024 */ f32 unk_24; + /* 0x0028 */ f32 unk_28; + /* 0x002C */ f32 unk_2C; + /* 0x0030 */ f32 unk_30; + /* 0x0034 */ f32 unk_34; + /* 0x0038 */ f32 unk_38; + /* 0x003C */ f32 unk_3C; + /* 0x0040 */ s8 unk_40; + /* 0x0044 */ ObjMineWaterLink links[0x3F]; +} ObjMineWaterChain; // size = 0x11FC typedef struct ObjMine { /* 0x0000 */ Actor actor; /* 0x0144 */ ColliderJntSph collider; /* 0x0164 */ ColliderJntSphElement colliderElements[1]; /* 0x01A4 */ ObjMineActionFunc actionFunc; - /* 0x01A8 */ f32 unk_1A8; - /* 0x01AC */ s32 unk_1AC; - /* 0x01B0 */ s32 unk_1B0; - /* 0x01B4 */ Vec3s* unk_1B4; - // ObjMineTestStruct2 chain2; - union { ObjMineTestStruct2 chain2; ObjMineUnkStruct chain1;}; + /* 0x01A8 */ f32 pathSpeed; + /* 0x01AC */ s32 waypointCount; + /* 0x01B0 */ s32 waypointIndex; + /* 0x01B4 */ Vec3s* waypoints; + /* 0x01B8 */ union { + ObjMineAirChain air; + ObjMineWaterChain water; + } chain; } ObjMine; // size = 0x13B4 #endif // Z_OBJ_MINE_H diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 0e450dfa2..38b9b34da 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -11150,53 +11150,53 @@ 0x80A80508:("func_80A80508",), 0x80A80750:("func_80A80750",), 0x80A80904:("func_80A80904",), - 0x80A811D0:("func_80A811D0",), - 0x80A8120C:("func_80A8120C",), - 0x80A81288:("func_80A81288",), - 0x80A8131C:("func_80A8131C",), - 0x80A81384:("func_80A81384",), - 0x80A8140C:("func_80A8140C",), - 0x80A8146C:("func_80A8146C",), - 0x80A81544:("func_80A81544",), - 0x80A81640:("func_80A81640",), - 0x80A8164C:("func_80A8164C",), - 0x80A81684:("func_80A81684",), - 0x80A81714:("func_80A81714",), - 0x80A81818:("func_80A81818",), - 0x80A81868:("func_80A81868",), - 0x80A819A4:("func_80A819A4",), - 0x80A81A00:("func_80A81A00",), - 0x80A81AA4:("func_80A81AA4",), - 0x80A81B14:("func_80A81B14",), - 0x80A81B7C:("func_80A81B7C",), - 0x80A81D70:("func_80A81D70",), - 0x80A81DEC:("func_80A81DEC",), + 0x80A811D0:("ObjMine_Path_MoveToWaypoint",), + 0x80A8120C:("ObjMine_GetUnitVec3f",), + 0x80A81288:("ObjMine_GetUnitVec3fNorm",), + 0x80A8131C:("ObjMine_Path_SpawnBomb",), + 0x80A81384:("ObjMine_AirWater_SpawnBomb",), + 0x80A8140C:("ObjMine_AirWater_CheckOC",), + 0x80A8146C:("ObjMine_Air_CheckAC",), + 0x80A81544:("ObjMine_Water_CheckAC",), + 0x80A81640:("ObjMine_AirWater_Noop",), + 0x80A8164C:("ObjMine_ReplaceTranslation",), + 0x80A81684:("ObjMine_ReplaceRotation",), + 0x80A81714:("ObjMine_StepUntilParallel",), + 0x80A81818:("ObjMine_UpdateCollider",), + 0x80A81868:("ObjMine_Air_InitChain",), + 0x80A819A4:("ObjMine_Air_SetCollider",), + 0x80A81A00:("ObjMine_Air_SetBasis",), + 0x80A81AA4:("ObjMine_Air_SetWorld",), + 0x80A81B14:("ObjMine_Air_SetChain3034",), + 0x80A81B7C:("ObjMine_Water_InitChain",), + 0x80A81D70:("ObjMine_Water_SetCollider",), + 0x80A81DEC:("ObjMine_Water_SetWorld",), 0x80A81E7C:("func_80A81E7C",), 0x80A81FFC:("func_80A81FFC",), 0x80A828A8:("func_80A828A8",), - 0x80A82C28:("func_80A82C28",), + 0x80A82C28:("ObjMine_Water_UpdateChain",), 0x80A82C5C:("ObjMine_Init",), 0x80A82F58:("ObjMine_Destroy",), - 0x80A82F84:("func_80A82F84",), - 0x80A82F98:("func_80A82F98",), - 0x80A82FA8:("func_80A82FA8",), - 0x80A82FC8:("func_80A82FC8",), - 0x80A83214:("func_80A83214",), - 0x80A83258:("func_80A83258",), - 0x80A832BC:("func_80A832BC",), - 0x80A832D0:("func_80A832D0",), - 0x80A83A74:("func_80A83A74",), - 0x80A83A88:("func_80A83A88",), - 0x80A83B14:("func_80A83B14",), - 0x80A83B28:("func_80A83B28",), - 0x80A83CEC:("func_80A83CEC",), - 0x80A83D00:("func_80A83D00",), - 0x80A83D8C:("ObjMine_Update",), - 0x80A83E7C:("func_80A83E7C",), - 0x80A83EA0:("ObjMine_Draw",), - 0x80A83FBC:("func_80A83FBC",), - 0x80A84088:("func_80A84088",), - 0x80A84338:("func_80A84338",), + 0x80A82F84:("ObjMine_Path_SetupStationary",), + 0x80A82F98:("ObjMine_Path_Stationary",), + 0x80A82FA8:("ObjMine_Path_SetupMove",), + 0x80A82FC8:("ObjMine_Path_Move",), + 0x80A83214:("ObjMine_SetupExplode",), + 0x80A83258:("ObjMine_Explode",), + 0x80A832BC:("ObjMine_Air_SetupChained",), + 0x80A832D0:("ObjMine_Air_Chained",), + 0x80A83A74:("ObjMine_Air_SetupStationary",), + 0x80A83A88:("ObjMine_Air_Stationary",), + 0x80A83B14:("ObjMine_Water_SetupChained",), + 0x80A83B28:("ObjMine_Water_Chained",), + 0x80A83CEC:("ObjMine_Water_SetupStationary",), + 0x80A83D00:("ObjMine_Water_Stationary",), + 0x80A83D8C:("ObjMine_Path_Update",), + 0x80A83E7C:("ObjMine_AirWater_Update",), + 0x80A83EA0:("ObjMine_Path_Draw",), + 0x80A83FBC:("ObjMine_DrawExplosion",), + 0x80A84088:("ObjMine_Air_Draw",), + 0x80A84338:("ObjMine_Water_Draw",), 0x80A84CD0:("ObjPurify_SetSysMatrix",), 0x80A84CF8:("ObjPurify_IsPurified",), 0x80A84D68:("ObjPurify_Init",), From 2fdce40d9cc3fd8049ab5ead5d978d29f0453019 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Fri, 3 Feb 2023 09:43:32 -0600 Subject: [PATCH 10/26] documented physics stuff --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 725 +++++++++--------- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 122 +-- tools/disasm/functions.txt | 2 +- 3 files changed, 407 insertions(+), 442 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index d83a4a04f..6f828f4ce 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -12,6 +12,15 @@ #define THIS ((ObjMine*)thisx) +#define LINK_SIZE 12.0f +#define ATTACH_OFFSET 10.0f +#define AIR_RADIUS 24.0f +#define WATER_RADIUS 36.0f +#define BOMB_SPAWN_OFFSET 15.0f + +#define RAND_PLUSMINUS(limit) (Rand_ZeroOne()*(2.0f * (limit)) - (limit)) +#define RAND_PLUSMINUSALT(limit) ((Rand_ZeroOne() - 0.5f) * (2.0f * limit)) + void ObjMine_Init(Actor* thisx, PlayState* play); void ObjMine_Destroy(Actor* thisx, PlayState* play); void ObjMine_Path_Update(Actor* thisx, PlayState* play); @@ -97,15 +106,15 @@ void ObjMine_Path_MoveToWaypoint(ObjMine* this, s32 index) { } s32 ObjMine_GetUnitVec3f(Vec3f* src, Vec3f* dst) { - f32 temp_f0 = Math3D_Vec3fMagnitude(src); + f32 mag = Math3D_Vec3fMagnitude(src); - if (temp_f0 < 0.001f) { + if (mag < 0.001f) { return false; } - dst->x = src->x * (1.0f / temp_f0); - dst->y = src->y * (1.0f / temp_f0); - dst->z = src->z * (1.0f / temp_f0); + dst->x = src->x * (1.0f / mag); + dst->y = src->y * (1.0f / mag); + dst->z = src->z * (1.0f / mag); return true; } @@ -162,49 +171,50 @@ s32 ObjMine_AirWater_CheckOC(ObjMine* this) { return false; } -void ObjMine_Air_CheckAC(ObjMine* this, s16* arg1, s16* arg2) { +void ObjMine_Air_CheckAC(ObjMine* this, s16* hitAngle, s16* hitTorque) { s32 pad[2]; Vec3s* centerPos3s = &this->collider.elements[0].dim.worldSphere.center; Vec3f centerPos; - s16 sp3E; + s16 yawToAttack; Actor* attackActor = this->collider.base.ac; Math_Vec3s_ToVec3f(¢erPos, centerPos3s); - sp3E = Math_Vec3f_Yaw(&attackActor->world.pos, ¢erPos); + yawToAttack = Math_Vec3f_Yaw(&attackActor->world.pos, ¢erPos); // dmgFlag check is (DMG_DEKU_BUBBLE | DMG_FIRE_ARROW | DMG_ICE_ARROW | DMG_FIRE_ARROW | DMG_NORMAL_ARROW) if (this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820) { - *arg1 = attackActor->shape.rot.y; - *arg2 = attackActor->shape.rot.y - sp3E; + *hitAngle = attackActor->shape.rot.y; + *hitTorque = attackActor->shape.rot.y - yawToAttack; } else { Vec3f hitPos; Vec3s* hitPos3s = &this->collider.elements[0].info.bumper.hitPos; Math_Vec3s_ToVec3f(&hitPos, hitPos3s); - *arg1 = Actor_YawBetweenActors(attackActor, &this->actor); - *arg2 = Math_Vec3f_Yaw(&attackActor->world.pos, &hitPos) - sp3E; + *hitAngle = Actor_YawBetweenActors(attackActor, &this->actor); + *hitTorque = Math_Vec3f_Yaw(&attackActor->world.pos, &hitPos) - yawToAttack; } } -void ObjMine_Water_CheckAC(ObjMine* this, Vec3f* arg1) { +void ObjMine_Water_CheckAC(ObjMine* this, Vec3f* knockbackDir) { Actor* attackActor = this->collider.base.ac; - // dmgFlag check is (DMG_DEKU_BUBBLE | DMG_FIRE_ARROW | DMG_ICE_ARROW | DMG_FIRE_ARROW | DMG_NORMAL_ARROW) + // dmgFlag check is (DMG_DEKU_BUBBLE | DMG_LIGHT_ARROW | DMG_ICE_ARROW | DMG_FIRE_ARROW | DMG_NORMAL_ARROW) if ((this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820)) { Matrix_Push(); Matrix_RotateYS(attackActor->shape.rot.y, MTXMODE_NEW); Matrix_RotateXS(attackActor->shape.rot.x, MTXMODE_APPLY); - Matrix_MultVecZ(1.0f, arg1); + Matrix_MultVecZ(1.0f, knockbackDir); Matrix_Pop(); } else { - Vec3f sp20; + Vec3f posDiff; Sphere16* sphere = &this->collider.elements[0].dim.worldSphere; - sp20.x = sphere->center.x - attackActor->world.pos.x; - sp20.y = sphere->center.y - attackActor->world.pos.y; - sp20.z = sphere->center.z - attackActor->world.pos.z; - if (!ObjMine_GetUnitVec3f(&sp20, arg1)) { - Math_Vec3f_Copy(arg1, &sStandardBasis.y); + posDiff.x = sphere->center.x - attackActor->world.pos.x; + posDiff.y = sphere->center.y - attackActor->world.pos.y; + posDiff.z = sphere->center.z - attackActor->world.pos.z; + + if (!ObjMine_GetUnitVec3f(&posDiff, knockbackDir)) { + Math_Vec3f_Copy(knockbackDir, &sStandardBasis.y); } } } @@ -245,25 +255,25 @@ void ObjMine_ReplaceRotation(ObjMineMtxF3* rotation) { } s32 ObjMine_StepUntilParallel(Vec3f* value, Vec3f* target, f32 angleStep) { - Vec3f sp3C; - Vec3f sp30; - Vec3f sp24; - f32 sp20 = Math3D_Parallel(value, target); + Vec3f perpVec; + Vec3f prevValue; + Vec3f perpNormal; + f32 cosAngle = Math3D_Parallel(value, target); - if (cos_rad(angleStep) <= sp20) { + if (cos_rad(angleStep) <= cosAngle) { Math_Vec3f_Copy(value, target); return true; } Matrix_Push(); - Math_Vec3f_Copy(&sp30, value); - Math3D_CrossProduct(value, target, &sp3C); - if (ObjMine_GetUnitVec3f(&sp3C, &sp24)) { - Matrix_RotateAxisS(RADF_TO_BINANG(angleStep), &sp24, MTXMODE_NEW); - Matrix_MultVec3f(&sp30, value); + Math_Vec3f_Copy(&prevValue, value); + Math3D_CrossProduct(value, target, &perpVec); + if (ObjMine_GetUnitVec3f(&perpVec, &perpNormal)) { + Matrix_RotateAxisS(RADF_TO_BINANG(angleStep), &perpNormal, MTXMODE_NEW); + Matrix_MultVec3f(&prevValue, value); } else { Matrix_RotateXFNew(angleStep); - Matrix_MultVec3f(&sp30, value); + Matrix_MultVec3f(&prevValue, value); } Matrix_Pop(); @@ -277,34 +287,34 @@ void ObjMine_UpdateCollider(ObjMine* this) { } void ObjMine_Air_InitChain(ObjMine* this, s32 linkCount) { - f32 arg1f = linkCount; - ObjMineAirChain* chain1 = &this->chain.air; - ObjMineAirLink* link1; + f32 linkCountF = linkCount; + ObjMineAirChain* airChain = &this->chain.air; + ObjMineAirLink* airLink; s32 i; - f32 temp_f12 = this->actor.home.rot.z * 5.0f; + f32 wallCheckRadius = this->actor.home.rot.z * 5.0f; - chain1->basis.x.x = 1.0f; - chain1->basis.y.y = 1.0f; - chain1->basis.z.z = 1.0f; - chain1->unk_24.y = 1.0f; + airChain->basis.x.x = 1.0f; + airChain->basis.y.y = 1.0f; + airChain->basis.z.z = 1.0f; + airChain->translation.y = 1.0f; if (linkCount > 0) { - chain1->unk_40 = -sqrtf(0.001984f / arg1f); // approx 1/504 = 1/8 * 1/63 - chain1->unk_44 = 0.95f + (0.00031746097f * arg1f); // approx 1/3150 = 1/50 * 1/63 + airChain->restore = -sqrtf(0.001984f / linkCountF); // approx 1/504 = 1/8 * 1/63 + airChain->drag = 0.95f + (0.00031746097f * linkCountF); // approx 1/3150 = 1/50 * 1/63 } - chain1->unk_58 = 0.0002f; + airChain->wobble = 0.0002f; - for (i = 0, link1 = chain1->links; i < linkCount; i++, link1++) { - link1->unk_00 = 0x4000; + for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { + airLink->twist = 0x4000; } - if (temp_f12 < 0.0f) { - chain1->unk_5C = -1.0f; - } else if (temp_f12 <= 21.0f) { - chain1->unk_5C = 0.0f; + if (wallCheckRadius < 0.0f) { + airChain->wallCheckDist = -1.0f; + } else if (wallCheckRadius <= 20.0f + 1.0f) { + airChain->wallCheckDist = 0.0f; } else { - chain1->unk_5C = SQ(temp_f12 - 20.0f); + airChain->wallCheckDist = SQ(wallCheckRadius - 20.0f); } } @@ -315,88 +325,88 @@ void ObjMine_Air_SetCollider(ObjMine* this, s32 linkCount) { } void ObjMine_Air_SetBasis(ObjMine* this) { - ObjMineAirChain* chain1 = &this->chain.air; - Vec3f sp28; + ObjMineAirChain* airChain = &this->chain.air; + Vec3f tempVec; - sp28.x = -chain1->unk_30; - sp28.y = 1.0f; - sp28.z = -chain1->unk_34; + tempVec.x = -airChain->xDiff; + tempVec.y = 1.0f; + tempVec.z = -airChain->zDiff; - ObjMine_GetUnitVec3f(&sp28, &chain1->basis.y); - Math3D_CrossProduct(&sStandardBasis.x, &chain1->basis.y, &sp28); - ObjMine_GetUnitVec3f(&sp28, &chain1->basis.z); - Math3D_CrossProduct(&chain1->basis.y, &chain1->basis.z, &sp28); - ObjMine_GetUnitVec3f(&sp28, &chain1->basis.x); + ObjMine_GetUnitVec3f(&tempVec, &airChain->basis.y); + Math3D_CrossProduct(&sStandardBasis.x, &airChain->basis.y, &tempVec); + ObjMine_GetUnitVec3f(&tempVec, &airChain->basis.z); + Math3D_CrossProduct(&airChain->basis.y, &airChain->basis.z, &tempVec); + ObjMine_GetUnitVec3f(&tempVec, &airChain->basis.x); } void ObjMine_Air_SetWorld(ObjMine* this) { s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - f32 temp_f0 = 10.0f + (linkCount * 12.0f); + f32 chainLength = 10.0f + (linkCount * 12.0f); - this->actor.world.pos.x = (this->chain.air.basis.y.x * -temp_f0) + this->actor.home.pos.x; - this->actor.world.pos.y = (this->chain.air.basis.y.y * -temp_f0) + this->actor.home.pos.y; - this->actor.world.pos.z = (this->chain.air.basis.y.z * -temp_f0) + this->actor.home.pos.z; + this->actor.world.pos.x = (this->chain.air.basis.y.x * -chainLength) + this->actor.home.pos.x; + this->actor.world.pos.y = (this->chain.air.basis.y.y * -chainLength) + this->actor.home.pos.y; + this->actor.world.pos.z = (this->chain.air.basis.y.z * -chainLength) + this->actor.home.pos.z; } void ObjMine_Air_SetChain3034(ObjMine* this) { s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - f32 temp_f0 = 1.0f / (10.0f + (linkCount * 12.0f)); + f32 invLength = 1.0f / (10.0f + (linkCount * 12.0f)); f32 dx = this->actor.world.pos.x - this->actor.home.pos.x; f32 dz = this->actor.world.pos.z - this->actor.home.pos.z; - this->chain.air.unk_30 = dx * temp_f0; - this->chain.air.unk_34 = dz * temp_f0; + this->chain.air.xDiff = dx * invLength; + this->chain.air.zDiff = dz * invLength; } void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { - ObjMineWaterChain* chain2 = &this->chain.water; - ObjMineWaterLink* link2; + ObjMineWaterChain* waterChain = &this->chain.water; + ObjMineWaterLink* waterLink; s32 i; - f32 sp58 = this->actor.home.rot.z * 5.0f; - f32 temp_f24; - f32 temp_f26; + f32 wallCheckRadius = this->actor.home.rot.z * 5.0f; + f32 linkY; + f32 wobbleVel; - chain2->unk_00 = 0.9f; - chain2->unk_1C = 0.003f; + waterChain->drag = 0.9f; + waterChain->wobble = 0.003f; - chain2->unk_20 = RANDU_BITS(13); - chain2->unk_24 = -0.0002f; - chain2->unk_30 = -0.0002f; + waterChain->wobblePhaseVel = RANDU_BITS(13); + waterChain->restoreX = -0.0002f; + waterChain->restoreY = -0.0002f; - temp_f26 = chain2->unk_1C * 6.0f; - temp_f24 = this->actor.home.pos.y; + wobbleVel = waterChain->wobble * 6.0f; + linkY = this->actor.home.pos.y; - for (i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { - temp_f24 += 12.0f; - link2->basis.x.x = 1.0f; - link2->basis.y.y = 1.0f; - link2->basis.z.z = 1.0f; - link2->unk_24.x = this->actor.home.pos.x; - link2->unk_24.y = temp_f24; - link2->unk_24.z = this->actor.home.pos.z; - link2->unk_30.x = (Rand_ZeroOne() - 0.5f) * temp_f26; - link2->unk_30.y = (Rand_ZeroOne() - 0.5f) * temp_f26; - link2->unk_30.z = (Rand_ZeroOne() - 0.5f) * temp_f26; + for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { + linkY += 12.0f; + waterLink->basis.x.x = 1.0f; + waterLink->basis.y.y = 1.0f; + waterLink->basis.z.z = 1.0f; + waterLink->pos.x = this->actor.home.pos.x; + waterLink->pos.y = linkY; + waterLink->pos.z = this->actor.home.pos.z; + waterLink->vel.x = (Rand_ZeroOne() - 0.5f) * wobbleVel; + waterLink->vel.y = (Rand_ZeroOne() - 0.5f) * wobbleVel; + waterLink->vel.z = (Rand_ZeroOne() - 0.5f) * wobbleVel; + } + waterChain->maxY = linkY; + + waterChain->restY = waterChain->maxY * 0.97f; + linkY -= 18.0f; + + if (waterChain->restY < linkY) { + waterChain->restY = linkY; } - chain2->unk_28 = temp_f24; - chain2->unk_2C = temp_f24 * 0.97f; - temp_f24 -= 18.0f; - - if (chain2->unk_2C < temp_f24) { - chain2->unk_2C = temp_f24; - } - - if (sp58 < 0.0f) { - chain2->unk_34 = -1.0f; - } else if (sp58 <= 37.0f) { - chain2->unk_34 = 0.0f; + if (wallCheckRadius < 0.0f) { + waterChain->wallCheckDist = -1.0f; + } else if (wallCheckRadius <= 36.0f + 1.0f) { + waterChain->wallCheckDist = 0.0f; } else { - chain2->unk_34 = SQ(sp58 - 36.0f); + waterChain->wallCheckDist = SQ(wallCheckRadius - 36.0f); } } -void ObjMine_Water_SetCollider(ObjMine* this, s32 linkCount) { +void ObjMine_Water_InitCollider(ObjMine* this, s32 linkCount) { Matrix_Translate(this->actor.home.pos.x, this->actor.home.pos.y + (linkCount * 12.0f) + 10.0f, this->actor.home.pos.z, MTXMODE_NEW); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); @@ -406,227 +416,227 @@ void ObjMine_Water_SetCollider(ObjMine* this, s32 linkCount) { void ObjMine_Water_SetWorld(ObjMine* this) { s32 pad; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - ObjMineWaterChain* chain2 = &this->chain.water; + ObjMineWaterChain* waterChain = &this->chain.water; if (linkCount == 0) { this->actor.world.pos.y = this->actor.home.pos.y + 12.0f + 10.0f; } else { - ObjMineWaterLink* link2 = &chain2->links[linkCount - 1]; - Vec3f sp1C; + ObjMineWaterLink* lastLink = &waterChain->links[linkCount - 1]; + Vec3f mineOffset; - Math_Vec3f_ScaleAndStore(&link2->basis.y, 10.0f, &sp1C); - Math_Vec3f_Sum(&link2->unk_24, &sp1C, &this->actor.world.pos); + Math_Vec3f_ScaleAndStore(&lastLink->basis.y, 10.0f, &mineOffset); + Math_Vec3f_Sum(&lastLink->pos, &mineOffset, &this->actor.world.pos); } } -void func_80A81E7C(ObjMine* this, PlayState* play) { +void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { s32 pad; - ObjMineWaterChain* chain2 = &this->chain.water; + ObjMineWaterChain* waterChain = &this->chain.water; - chain2->unk_40 = false; - if ((-0.000001f < chain2->unk_34) && (chain2->unk_34 <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, - this->actor.world.pos.x, this->actor.world.pos.z))) { - Vec3f sp7C; - Vec3f sp70; - Vec3f sp64; - Vec3f xzDistFromHome; - Vec3f xzDirFromHome; - CollisionPoly* dummyPoly; - s32 dummyBgId; - f32 dummyNorm; - f32 dummyInvNorm; + waterChain->touchWall = false; + if (waterChain->wallCheckDist > -1e-6f) { + if (waterChain->wallCheckDist <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, + this->actor.world.pos.x, this->actor.world.pos.z)) { + Vec3f centerPos; + Vec3f offsetPos; + Vec3f dummyResult; + Vec3f xzDistFromHome; + Vec3f xzDirFromHome; + CollisionPoly* dummyPoly; + s32 dummyBgId; + f32 dummyNorm; + f32 dummyInvNorm; - xzDistFromHome.x = this->actor.world.pos.x - this->actor.home.pos.x; - xzDistFromHome.y = 0.0f; - xzDistFromHome.z = this->actor.world.pos.z - this->actor.home.pos.z; + xzDistFromHome.x = this->actor.world.pos.x - this->actor.home.pos.x; + xzDistFromHome.y = 0.0f; + xzDistFromHome.z = this->actor.world.pos.z - this->actor.home.pos.z; - if (ObjMine_GetUnitVec3fNorm(&xzDistFromHome, &xzDirFromHome, &dummyNorm, &dummyInvNorm)) { + if (ObjMine_GetUnitVec3fNorm(&xzDistFromHome, &xzDirFromHome, &dummyNorm, &dummyInvNorm)) { - sp70.x = this->actor.world.pos.x + (xzDirFromHome.x * 36.0f); - sp70.y = this->actor.world.pos.y; - sp70.z = this->actor.world.pos.z + (xzDirFromHome.z * 36.0f); + offsetPos.x = this->actor.world.pos.x + (xzDirFromHome.x * 36.0f); + offsetPos.y = this->actor.world.pos.y; + offsetPos.z = this->actor.world.pos.z + (xzDirFromHome.z * 36.0f); - sp7C.x = this->actor.home.pos.x; - sp7C.y = this->actor.world.pos.y; - sp7C.z = this->actor.home.pos.z; + centerPos.x = this->actor.home.pos.x; + centerPos.y = this->actor.world.pos.y; + centerPos.z = this->actor.home.pos.z; - if (BgCheck_EntityLineTest1(&play->colCtx, &sp7C, &sp70, &sp64, &dummyPoly, 1, 0, 0, 1, &dummyBgId)) { - chain2->unk_40 = true; - chain2->unk_38 = xzDirFromHome.x * -0.2f; - chain2->unk_3C = xzDirFromHome.z * -0.2f; + if (BgCheck_EntityLineTest1(&play->colCtx, ¢erPos, &offsetPos, &dummyResult, &dummyPoly, true, false, false, true, &dummyBgId)) { + waterChain->touchWall = true; + waterChain->wallEjectX = xzDirFromHome.x * -0.2f; + waterChain->wallEjectZ = xzDirFromHome.z * -0.2f; + } } } } } -#ifdef NON_MATCHING +#if 0 // Probably equivalent, but nightmare loop unrolls. -void func_80A81FFC(ObjMine *this) { - static Vec3f D_80A849D0[0x40]; - ObjMineWaterChain *chain2 = &this->chain.water; - ObjMineWaterLink *link2; +void ObjMine_Water_ApplyForces(ObjMine *this) { + static Vec3f sLinkAccel[0x40]; + ObjMineWaterChain *waterChain = &this->chain.water; + ObjMineWaterLink *waterLink; s32 i; - s16 var_s3; + s16 wobblePhase; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - f32 invLinkCount = 1.0f / (f32) linkCount; - f32 temp_fs0 = (chain2->links[linkCount - 1].unk_24.y - chain2->unk_2C) * chain2->unk_30; - Vec3f sp90; - f32 temp_ft4; + f32 inverseCount = 1.0f / (f32) linkCount; + f32 restoreY = (waterChain->links[linkCount - 1].pos.y - waterChain->restY) * waterChain->restoreY; + Vec3f tension; + f32 scaledKnockback; - for(i = 0, link2 = chain2->links, var_s3 = 0; i < linkCount; i++, link2++, var_s3 += chain2->unk_20) { - Math_Vec3f_Copy(&D_80A849D0[i], &link2->unk_3C); - if (link2->unk_24.y <= this->actor.home.pos.y) { - link2->unk_3C.y = chain2->unk_30 * -96.0f; - } else if (temp_fs0 > 0.0f) { - link2->unk_3C.y = (i + 1) * invLinkCount * (temp_fs0 / 0.3f); + for(i = 0, waterLink = waterChain->links, wobblePhase = 0; i < linkCount; i++, waterLink++, wobblePhase += waterChain->wobblePhaseVel) { + Math_Vec3f_Copy(&sLinkAccel[i], &waterLink->accel); + if (waterLink->pos.y <= this->actor.home.pos.y) { + waterLink->accel.y = waterChain->restoreY * -96.0f; + } else if (restoreY > 0.0f) { + waterLink->accel.y = (i + 1) * inverseCount * (restoreY / 0.3f); } else { - link2->unk_3C.y = temp_fs0; + waterLink->accel.y = restoreY; } - link2->unk_3C.x = (link2->unk_24.x - this->actor.home.pos.x) * chain2->unk_24; - link2->unk_3C.z = (link2->unk_24.z - this->actor.home.pos.z) * chain2->unk_24; - link2->unk_3C.x += chain2->unk_14 * Math_SinS(var_s3); - link2->unk_3C.y += chain2->unk_18; - link2->unk_3C.z += chain2->unk_14 * Math_CosS(var_s3); + waterLink->accel.x = (waterLink->pos.x - this->actor.home.pos.x) * waterChain->restoreX; + waterLink->accel.z = (waterLink->pos.z - this->actor.home.pos.z) * waterChain->restoreX; + waterLink->accel.x += waterChain->wobbleXZ * Math_SinS(wobblePhase); + waterLink->accel.y += waterChain->wobbleY; + waterLink->accel.z += waterChain->wobbleXZ * Math_CosS(wobblePhase); } - if (chain2->unk_10 > 0.0001f) { - for(i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { - temp_ft4 = SQ((linkCount - i) * invLinkCount); + if (waterChain->knockback > 0.0001f) { + for(i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { + scaledKnockback = SQ((linkCount - i) * inverseCount); - link2->unk_3C.x += chain2->unk_04.x * temp_ft4; - link2->unk_3C.y += chain2->unk_04.y * temp_ft4; - link2->unk_3C.z += chain2->unk_04.z * temp_ft4; + waterLink->accel.x += waterChain->knockbackDir.x * scaledKnockback; + waterLink->accel.y += waterChain->knockbackDir.y * scaledKnockback; + waterLink->accel.z += waterChain->knockbackDir.z * scaledKnockback; } } - if (chain2->unk_40) { - for(i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { - link2->unk_3C.x += chain2->unk_38; - link2->unk_3C.z += chain2->unk_3C; + if (waterChain->touchWall) { + for(i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { + waterLink->accel.x += waterChain->wallEjectX; + waterLink->accel.z += waterChain->wallEjectZ; } } - for(i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { - Math_Vec3f_Copy(&sp90, &gZeroVec3f); + for(i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { + Math_Vec3f_Copy(&tension, &gZeroVec3f); if(i - 2 >= 0) { - sp90.x += D_80A849D0[i - 2].x * 0.075f; - sp90.y += D_80A849D0[i - 2].y * 0.075f; - sp90.z += D_80A849D0[i - 2].z * 0.075f; + tension.x += sLinkAccel[i - 2].x * 0.075f; + tension.y += sLinkAccel[i - 2].y * 0.075f; + tension.z += sLinkAccel[i - 2].z * 0.075f; } if(i - 1 >= 0) { - sp90.x += D_80A849D0[i - 1].x * 0.15f; - sp90.y += D_80A849D0[i - 1].y * 0.15f; - sp90.z += D_80A849D0[i - 1].z * 0.15f; + tension.x += sLinkAccel[i - 1].x * 0.15f; + tension.y += sLinkAccel[i - 1].y * 0.15f; + tension.z += sLinkAccel[i - 1].z * 0.15f; } - sp90.x += D_80A849D0[i].x * 0.3f; - sp90.y += D_80A849D0[i].y * 0.3f; - sp90.z += D_80A849D0[i].z * 0.3f; + tension.x += sLinkAccel[i].x * 0.3f; + tension.y += sLinkAccel[i].y * 0.3f; + tension.z += sLinkAccel[i].z * 0.3f; if(i + 1 < linkCount) { - sp90.x += D_80A849D0[i + 1].x * 0.15f; - sp90.y += D_80A849D0[i + 1].y * 0.15f; - sp90.z += D_80A849D0[i + 1].z * 0.15f; + tension.x += sLinkAccel[i + 1].x * 0.15f; + tension.y += sLinkAccel[i + 1].y * 0.15f; + tension.z += sLinkAccel[i + 1].z * 0.15f; } if(i + 2 < linkCount) { - sp90.x += D_80A849D0[i + 2].x * 0.075f; - sp90.y += D_80A849D0[i + 2].y * 0.075f; - sp90.z += D_80A849D0[i + 2].z * 0.075f; + tension.x += sLinkAccel[i + 2].x * 0.075f; + tension.y += sLinkAccel[i + 2].y * 0.075f; + tension.z += sLinkAccel[i + 2].z * 0.075f; } - link2->unk_3C.x += sp90.x; - link2->unk_3C.y += sp90.y; - link2->unk_3C.z += sp90.z; + waterLink->accel.x += tension.x; + waterLink->accel.y += tension.y; + waterLink->accel.z += tension.z; } } #else Vec3f D_80A849D0[0x40]; -void func_80A81FFC(ObjMine* this); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/func_80A81FFC.s") +void ObjMine_Water_ApplyForces(ObjMine* this); +#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Water_ApplyForces.s") #endif -void func_80A828A8(ObjMine* this) { +void ObjMine_Water_UpdateLinks(ObjMine* this) { s32 pad; - Vec3f spE0; - Vec3f spD4; - Vec3f spC8; - s32 spC4 = OBJMINE_GET_LINK_COUNT(&this->actor); - ObjMineWaterChain* chain2 = &this->chain.water; - ObjMineWaterLink* link2; + ObjMineMtxF3 newBasis; + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); + ObjMineWaterChain* waterChain = &this->chain.water; + ObjMineWaterLink* waterLink; s32 i; - Vec3f* phi_s3; - Vec3f spA8; - Vec3f sp9C; - Vec3f sp90; - Vec3f sp84; - s32 phi_s5; - f32 sp7C; - f32 sp78; - Vec3f* phi_x; + Vec3f* lastBasisX; + Vec3f tempVec; + Vec3f diffDir; + Vec3f unusedLinkPos; + Vec3f lastLinkPos; + s32 changeBasis; + f32 diffNorm; + f32 dummyInvNorm; + Vec3f* tempBasisX; - sp84.x = this->actor.home.pos.x; - sp84.y = this->actor.home.pos.y + 6.0f; - sp84.z = this->actor.home.pos.z; + lastLinkPos.x = this->actor.home.pos.x; + lastLinkPos.y = this->actor.home.pos.y + 6.0f; + lastLinkPos.z = this->actor.home.pos.z; - for (i = 0, phi_s3 = NULL, link2 = chain2->links; i < spC4; i++, phi_s3 = &link2->basis.x, link2++) { - phi_s5 = false; + for (i = 0, lastBasisX = NULL, waterLink = waterChain->links; i < linkCount; i++, lastBasisX = &waterLink->basis.x, waterLink++) { + changeBasis = false; - link2->unk_30.x += link2->unk_3C.x; - link2->unk_30.y += link2->unk_3C.y; - link2->unk_30.z += link2->unk_3C.z; + waterLink->vel.x += waterLink->accel.x; + waterLink->vel.y += waterLink->accel.y; + waterLink->vel.z += waterLink->accel.z; - Math_Vec3f_Scale(&link2->unk_30, chain2->unk_00); - Math_Vec3f_Copy(&sp90, &link2->unk_24); + Math_Vec3f_Scale(&waterLink->vel, waterChain->drag); + Math_Vec3f_Copy(&unusedLinkPos, &waterLink->pos); - link2->unk_24.x += link2->unk_30.x; - link2->unk_24.y += link2->unk_30.y; - link2->unk_24.z += link2->unk_30.z; + waterLink->pos.x += waterLink->vel.x; + waterLink->pos.y += waterLink->vel.y; + waterLink->pos.z += waterLink->vel.z; - if ((link2->unk_24.y <= this->actor.home.pos.y) && (link2->unk_30.y < 0.0f)) { - link2->unk_30.y *= 0.1f; + if ((waterLink->pos.y <= this->actor.home.pos.y) && (waterLink->vel.y < 0.0f)) { + waterLink->vel.y *= 0.1f; } - Math_Vec3f_Diff(&link2->unk_24, &sp84, &spA8); + Math_Vec3f_Diff(&waterLink->pos, &lastLinkPos, &tempVec); - if (ObjMine_GetUnitVec3fNorm(&spA8, &sp9C, &sp7C, &sp78) && (sp7C > 4.0f)) { - Math_Vec3f_Copy(&spD4, &link2->basis.y); - ObjMine_StepUntilParallel(&spD4, &sp9C, M_PI / 30); - phi_x = (phi_s3 == NULL) ? &sStandardBasis.x : phi_s3; + if (ObjMine_GetUnitVec3fNorm(&tempVec, &diffDir, &diffNorm, &dummyInvNorm) && (diffNorm > 4.0f)) { + Math_Vec3f_Copy(&newBasis.y, &waterLink->basis.y); + ObjMine_StepUntilParallel(&newBasis.y, &diffDir, M_PI / 30); + tempBasisX = (lastBasisX == NULL) ? &sStandardBasis.x : lastBasisX; - Math3D_CrossProduct(phi_x, &spD4, &spA8); + Math3D_CrossProduct(tempBasisX, &newBasis.y, &tempVec); - if (ObjMine_GetUnitVec3f(&spA8, &spE0)) { - Math3D_CrossProduct(&spD4, &spE0, &spA8); - if (ObjMine_GetUnitVec3f(&spA8, &spC8)) { - phi_s5 = true; + if (ObjMine_GetUnitVec3f(&tempVec, &newBasis.z)) { + Math3D_CrossProduct(&newBasis.y, &newBasis.z, &tempVec); + if (ObjMine_GetUnitVec3f(&tempVec, &newBasis.x)) { + changeBasis = true; } } } - if (phi_s5) { - Math_Vec3f_Copy(&link2->basis.x, &spC8); - Math_Vec3f_Copy(&link2->basis.y, &spD4); - Math_Vec3f_Copy(&link2->basis.z, &spE0); + if (changeBasis) { + Math_Vec3f_Copy(&waterLink->basis.x, &newBasis.x); + Math_Vec3f_Copy(&waterLink->basis.y, &newBasis.y); + Math_Vec3f_Copy(&waterLink->basis.z, &newBasis.z); } else { - sp7C = 4.0f; + diffNorm = 4.0f; } - if (sp7C >= 6.0f) { - link2->unk_24.x = sp84.x + (link2->basis.y.x * 6.0f); - link2->unk_24.y = sp84.y + (link2->basis.y.y * 6.0f); - link2->unk_24.z = sp84.z + (link2->basis.y.z * 6.0f); + if (diffNorm >= 6.0f) { + waterLink->pos.x = lastLinkPos.x + (waterLink->basis.y.x * 6.0f); + waterLink->pos.y = lastLinkPos.y + (waterLink->basis.y.y * 6.0f); + waterLink->pos.z = lastLinkPos.z + (waterLink->basis.y.z * 6.0f); } else { - link2->unk_24.x = sp84.x + (link2->basis.y.x * sp7C); - link2->unk_24.y = sp84.y + (link2->basis.y.y * sp7C); - link2->unk_24.z = sp84.z + (link2->basis.y.z * sp7C); + waterLink->pos.x = lastLinkPos.x + (waterLink->basis.y.x * diffNorm); + waterLink->pos.y = lastLinkPos.y + (waterLink->basis.y.y * diffNorm); + waterLink->pos.z = lastLinkPos.z + (waterLink->basis.y.z * diffNorm); } - sp84.x = link2->unk_24.x + (link2->basis.y.x * 6.0f); - sp84.y = link2->unk_24.y + (link2->basis.y.y * 6.0f); - sp84.z = link2->unk_24.z + (link2->basis.y.z * 6.0f); + lastLinkPos.x = waterLink->pos.x + (waterLink->basis.y.x * 6.0f); + lastLinkPos.y = waterLink->pos.y + (waterLink->basis.y.y * 6.0f); + lastLinkPos.z = waterLink->pos.z + (waterLink->basis.y.z * 6.0f); } } void ObjMine_Water_UpdateChain(ObjMine* this, PlayState* play) { - func_80A81E7C(this, play); - func_80A81FFC(this); - func_80A828A8(this); + ObjMine_Water_WallCheck(this, play); + ObjMine_Water_ApplyForces(this); // ObjMine_Water_ApplyForces + ObjMine_Water_UpdateLinks(this); } void ObjMine_Init(Actor* thisx, PlayState* play) { @@ -691,7 +701,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { this->actor.draw = ObjMine_Water_Draw; ObjMine_Water_InitChain(this, linkCount); this->actor.world.pos.y = 10.0f + (linkCount * 12.0f) + this->actor.home.pos.y; - ObjMine_Water_SetCollider(this, linkCount); + ObjMine_Water_InitCollider(this, linkCount); if (linkCount == 0) { ObjMine_Water_SetupStationary(this); } else { @@ -796,16 +806,15 @@ void ObjMine_Air_SetupChained(ObjMine* this) { void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { s32 pad; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - ObjMineAirChain* chain1 = &this->chain.air; - ObjMineAirLink* link1; + ObjMineAirChain* airChain = &this->chain.air; + ObjMineAirLink* airLink; s32 i; - f32 sp90; - f32 sp8C; - f32 sp88; - s16 sp86; - s16 sp84; + f32 xAccel; + f32 zAccel; + f32 torque; + s16 twistDiff; - Math_Vec3f_Copy(&chain1->unk_24, &chain1->basis.y); + Math_Vec3f_Copy(&airChain->translation, &airChain->basis.y); if (ObjMine_AirWater_CheckOC(this)) { ObjMine_AirWater_SpawnBomb(this, play); ObjMine_AirWater_Noop(this); @@ -813,86 +822,90 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { return; } - if (this->collider.base.acFlags & AC_HIT) { + if (this->collider.base.acFlags & AC_HIT) { // initial knockback calc + s16 torqueAngle; + f32 torque; + f32 torqueDiff; + this->collider.base.acFlags &= ~AC_HIT; - chain1->unk_48 = 0.04f; - ObjMine_Air_CheckAC(this, &chain1->unk_4C, &sp84); - sp88 = sp8C = Math_SinS(sp84) * 150.0f; - sp8C = -(sp8C / linkCount); + airChain->knockback = 0.04f; + ObjMine_Air_CheckAC(this, &airChain->knockbackAngle, &torqueAngle); + torque = Math_SinS(torqueAngle) * 150.0f; + torqueDiff = -(torque / linkCount); - for (i = 0, link1 = chain1->links; i < linkCount; i++, link1++) { - link1->unk_02 += (s16)sp88; - link1->unk_02 = CLAMP(link1->unk_02, -800, 800); - sp88 -= sp8C; + for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { + airLink->spin += (s16)torque; + airLink->spin = CLAMP(airLink->spin, -800, 800); + torque -= torqueDiff; } } - if (chain1->unk_48 > 0.0001f) { - sp90 = Math_SinS(chain1->unk_4C) * chain1->unk_48; - sp8C = Math_CosS(chain1->unk_4C) * chain1->unk_48; - chain1->unk_38 += sp90; - chain1->unk_3C += sp8C; - Math_StepToF(&chain1->unk_48, 0.0f, 0.02f); + if (airChain->knockback > 0.0001f) { // residual knockback calc + xAccel = Math_SinS(airChain->knockbackAngle) * airChain->knockback; + zAccel = Math_CosS(airChain->knockbackAngle) * airChain->knockback; + airChain->xVel += xAccel; + airChain->zVel += zAccel; + Math_StepToF(&airChain->knockback, 0.0f, 0.02f); } - if (RANDU_BITS(5) == 0) { - chain1->unk_50 = Rand_ZeroOne() * chain1->unk_58; - chain1->unk_54 = RANDU_BITS(16); + if (RANDU_BITS(5) == 0) { // wobble + airChain->wobbleSize = Rand_ZeroOne() * airChain->wobble; + airChain->wobblePhase = RANDU_BITS(16); } - sp90 = Math_SinS(chain1->unk_54) * chain1->unk_50; - sp8C = Math_CosS(chain1->unk_54) * chain1->unk_50; - chain1->unk_38 += sp90; - chain1->unk_3C += sp8C; + xAccel = Math_SinS(airChain->wobblePhase) * airChain->wobbleSize; + zAccel = Math_CosS(airChain->wobblePhase) * airChain->wobbleSize; + airChain->xVel += xAccel; + airChain->zVel += zAccel; - chain1->unk_38 += chain1->unk_30 * chain1->unk_40; - chain1->unk_3C += chain1->unk_34 * chain1->unk_40; + airChain->xVel += airChain->xDiff * airChain->restore; + airChain->zVel += airChain->zDiff * airChain->restore; - chain1->unk_38 *= chain1->unk_44; - chain1->unk_3C *= chain1->unk_44; + airChain->xVel *= airChain->drag; + airChain->zVel *= airChain->drag; - chain1->unk_30 += chain1->unk_38; - chain1->unk_34 += chain1->unk_3C; + airChain->xDiff += airChain->xVel; + airChain->zDiff += airChain->zVel; - chain1->unk_30 = CLAMP(chain1->unk_30, -5.0f, 5.0f); - chain1->unk_34 = CLAMP(chain1->unk_34, -5.0f, 5.0f); + airChain->xDiff = CLAMP(airChain->xDiff, -5.0f, 5.0f); + airChain->zDiff = CLAMP(airChain->zDiff, -5.0f, 5.0f); ObjMine_Air_SetBasis(this); ObjMine_Air_SetWorld(this); - if (chain1->unk_5C > -0.000001f) { - Vec3f* world = &this->actor.world.pos; - Vec3f* home = &this->actor.home.pos; + if (airChain->wallCheckDist > -1e-6f) { + // Vec3f* world = &this->actor.world.pos; + // Vec3f* home = &this->actor.home.pos; - if (chain1->unk_5C <= Math3D_XZDistanceSquared(world->x, world->z, home->x, home->z)) { + if (airChain->wallCheckDist <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, this->actor.home.pos.x, this->actor.home.pos.z)) { Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, 20.0f, 0.0f, 1); if ((this->actor.bgCheckFlags & 8) && (this->actor.wallPoly != NULL)) { - Vec3f sp70; - Vec3f sp64; - Vec3f sp58; - Vec3f sp4C; - f32 sp48; - f32 sp44; + Vec3f xzDir; + Vec3f reflectedDir; + Vec3f wallNormal; + Vec3f xzVel; + f32 xzSpeed; + f32 dummyInvNorm; - sp4C.x = chain1->unk_38; - sp4C.y = 0.0f; - sp4C.z = chain1->unk_3C; + xzVel.x = airChain->xVel; + xzVel.y = 0.0f; + xzVel.z = airChain->zVel; - if (ObjMine_GetUnitVec3fNorm(&sp4C, &sp70, &sp48, &sp44)) { - sp58.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); - sp58.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); - sp58.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); + if (ObjMine_GetUnitVec3fNorm(&xzVel, &xzDir, &xzSpeed, &dummyInvNorm)) { + wallNormal.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); + wallNormal.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); + wallNormal.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); - func_80179F64(&sp70, &sp58, &sp64); + func_80179F64(&xzDir, &wallNormal, &reflectedDir); - sp48 *= 0.5f; - chain1->unk_38 = sp64.x * sp48; - chain1->unk_3C = sp64.z * sp48; + xzSpeed /= 2.0f; + airChain->xVel = reflectedDir.x * xzSpeed; + airChain->zVel = reflectedDir.z * xzSpeed; } else { - chain1->unk_38 *= -0.1f; - chain1->unk_3C *= -0.1f; + airChain->xVel *= -0.1f; + airChain->zVel *= -0.1f; } ObjMine_Air_SetChain3034(this); ObjMine_Air_SetBasis(this); @@ -901,12 +914,12 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { } } - for (i = 0, link1 = chain1->links; i < linkCount; i++, link1++) { - sp86 = link1->unk_00 - 0x4000; - sp88 = link1->unk_02 + (sp86 * -0.05f) + ((Rand_ZeroOne() * 30.0f) - 15.0f); - sp88 *= 0.995f; - link1->unk_02 = sp88; - link1->unk_00 += link1->unk_02; + for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { + twistDiff = airLink->twist - 0x4000; + torque = airLink->spin + (twistDiff * -0.05f) + RAND_PLUSMINUS(15.0f); + torque *= 0.995f; + airLink->spin = torque; + airLink->twist += airLink->spin; } func_800B4AEC(play, &this->actor, 0.0f); @@ -936,7 +949,7 @@ void ObjMine_Water_SetupChained(ObjMine* this) { } void ObjMine_Water_Chained(ObjMine* this, PlayState* play) { - ObjMineWaterChain* chain2 = &this->chain.water; + ObjMineWaterChain* waterChain = &this->chain.water; if (ObjMine_AirWater_CheckOC(this)) { ObjMine_AirWater_SpawnBomb(this, play); @@ -947,26 +960,26 @@ void ObjMine_Water_Chained(ObjMine* this, PlayState* play) { if (this->collider.base.acFlags & AC_HIT) { this->collider.base.acFlags &= ~AC_HIT; - ObjMine_Water_CheckAC(this, &chain2->unk_04); - chain2->unk_10 = 7.0f; - Math_Vec3f_Scale(&chain2->unk_04, 7.0f); + ObjMine_Water_CheckAC(this, &waterChain->knockbackDir); + waterChain->knockback = 7.0f; + Math_Vec3f_Scale(&waterChain->knockbackDir, 7.0f); } - if (chain2->unk_10 > 0.0001f) { - chain2->unk_10 = Math_Vec3f_StepTo(&chain2->unk_04, &gZeroVec3f, 2.8f); + if (waterChain->knockback > 0.0001f) { + waterChain->knockback = Math_Vec3f_StepTo(&waterChain->knockbackDir, &gZeroVec3f, 2.8f); } - chain2->unk_00 = 0.9f; - chain2->unk_24 = -0.0002f; - chain2->unk_30 = -0.0002f; - chain2->unk_1C = 0.003f; + waterChain->drag = 0.9f; + waterChain->restoreX = -0.0002f; + waterChain->restoreY = -0.0002f; + waterChain->wobble = 0.003f; if (RANDU_BITS(5) == 0) { s16 randAngle = RANDU_BITS(16); - chain2->unk_14 = Math_SinS(randAngle) * 1.8f * chain2->unk_1C; - chain2->unk_18 = Math_CosS(randAngle) * 0.2f * chain2->unk_1C; - chain2->unk_20 = RANDU_BITS(13); + waterChain->wobbleXZ = Math_SinS(randAngle) * 1.8f * waterChain->wobble; + waterChain->wobbleY = Math_CosS(randAngle) * 0.2f * waterChain->wobble; + waterChain->wobblePhaseVel = RANDU_BITS(13); } ObjMine_Water_UpdateChain(this, play); @@ -1031,7 +1044,7 @@ void ObjMine_Path_Draw(Actor* thisx, PlayState* play) { Collider_UpdateSpheres(0, &this->collider); } - func_800B8050(&this->actor, play, 1); + func_800B8050(&this->actor, play, true); func_8012C28C(play->state.gfxCtx); gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); @@ -1048,7 +1061,7 @@ void ObjMine_DrawExplosion(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); - func_800B8118(thisx, play, 1); + func_800B8118(thisx, play, true); func_8012C2DC(play->state.gfxCtx); gDPSetRenderMode(POLY_XLU_DISP++, G_RM_PASS, G_RM_AA_ZB_XLU_SURF2); @@ -1063,14 +1076,14 @@ void ObjMine_Air_Draw(Actor* thisx, PlayState* play) { s32 pad; ObjMine* this = THIS; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - ObjMineAirChain* chain1 = &this->chain.air; - ObjMineAirLink* link1; + ObjMineAirChain* airChain = &this->chain.air; + ObjMineAirLink* airLink; s32 i; - Vec3f sp94; - Vec3f sp88; + Vec3f linkPos; + Vec3f linkOffset; Gfx* gfx; - func_800B8050(&this->actor, play, 1); + func_800B8050(&this->actor, play, true); OPEN_DISPS(play->state.gfxCtx); gfx = POLY_OPA_DISP; @@ -1079,21 +1092,21 @@ void ObjMine_Air_Draw(Actor* thisx, PlayState* play) { gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); - ObjMine_ReplaceRotation(&chain1->basis); + ObjMine_ReplaceRotation(&airChain->basis); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); if (linkCount != 0) { - Math_Vec3f_ScaleAndStore(&chain1->basis.y, -6.0f, &sp88); - sp94.x = this->actor.home.pos.x - sp88.x; - sp94.y = this->actor.home.pos.y - 6.0f - sp88.y; - sp94.z = this->actor.home.pos.z - sp88.z; - Math_Vec3f_ScaleAndStore(&chain1->basis.y, -12.0f, &sp88); + Math_Vec3f_ScaleAndStore(&airChain->basis.y, -6.0f, &linkOffset); + linkPos.x = this->actor.home.pos.x - linkOffset.x; + linkPos.y = this->actor.home.pos.y - 6.0f - linkOffset.y; + linkPos.z = this->actor.home.pos.z - linkOffset.z; - for (i = 0, link1 = chain1->links; i < linkCount; i++, link1++) { - Matrix_RotateYS(link1->unk_00, MTXMODE_APPLY); - sp94.x += sp88.x; - sp94.y += sp88.y; - sp94.z += sp88.z; - ObjMine_ReplaceTranslation(&sp94); + Math_Vec3f_ScaleAndStore(&airChain->basis.y, -12.0f, &linkOffset); + for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { + Matrix_RotateYS(airLink->twist, MTXMODE_APPLY); + linkPos.x += linkOffset.x; + linkPos.y += linkOffset.y; + linkPos.z += linkOffset.z; + ObjMine_ReplaceTranslation(&linkPos); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); @@ -1119,12 +1132,12 @@ void ObjMine_Water_Draw(Actor* thisx, PlayState* play) { s32 pad; ObjMine* this = THIS; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - ObjMineWaterChain* chain2 = &this->chain.water; - ObjMineWaterLink* link2; + ObjMineWaterChain* waterChain = &this->chain.water; + ObjMineWaterLink* waterLink; s32 i; Gfx* gfx; - func_800B8050(&this->actor, play, 1); + func_800B8050(&this->actor, play, true); OPEN_DISPS(play->state.gfxCtx); gfx = POLY_OPA_DISP; @@ -1133,13 +1146,13 @@ void ObjMine_Water_Draw(Actor* thisx, PlayState* play) { gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); - for (i = 0, link2 = chain2->links; i < linkCount; i++, link2++) { - ObjMine_ReplaceRotation(&link2->basis); + for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { + ObjMine_ReplaceRotation(&waterLink->basis); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); if ((i % 2) == 0) { Matrix_RotateYS(0x4000, MTXMODE_APPLY); } - ObjMine_ReplaceTranslation(&link2->unk_24); + ObjMine_ReplaceTranslation(&waterLink->pos); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index 680e766cb..cfc2ff2f2 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -15,6 +15,8 @@ typedef void (*ObjMineActionFunc)(struct ObjMine*, PlayState*); #define OBJMINE_SET_PARAM0(pathIndex, pathSpeed, type) ((pathIndex) | ((pathSpeed) << 8)) #define OBJMINE_SET_PARAM12(linkCount, type) ((linkCount) | ((type) << 0xC)) +#define OBJMINE_CHAIN_MAX 63 + typedef enum { /* 0 */ OBJMINE_TYPE_PATH, /* 1 */ OBJMINE_TYPE_AIR, @@ -28,104 +30,54 @@ typedef struct { } ObjMineMtxF3; // size = 0x24 typedef struct { - /* 0x00 */ s16 unk_00; - /* 0x02 */ s16 unk_02; + /* 0x00 */ s16 twist; + /* 0x02 */ s16 spin; } ObjMineAirLink; // size = 0x4 typedef struct { /* 0x00 */ ObjMineMtxF3 basis; - /* 0x24 */ Vec3f unk_24; - /* 0x30 */ f32 unk_30; - /* 0x34 */ f32 unk_34; - /* 0x38 */ f32 unk_38; - /* 0x3C */ f32 unk_3C; - /* 0x40 */ f32 unk_40; - /* 0x44 */ f32 unk_44; - /* 0x48 */ f32 unk_48; - /* 0x4C */ s16 unk_4C; - /* 0x50 */ f32 unk_50; - /* 0x54 */ s16 unk_54; - /* 0x58 */ f32 unk_58; - /* 0x5C */ f32 unk_5C; - /* 0x60 */ ObjMineAirLink links[0x3F]; + /* 0x24 */ Vec3f translation; + /* 0x30 */ f32 xDiff; + /* 0x34 */ f32 zDiff; + /* 0x38 */ f32 xVel; + /* 0x3C */ f32 zVel; + /* 0x40 */ f32 restore; + /* 0x44 */ f32 drag; + /* 0x48 */ f32 knockback; + /* 0x4C */ s16 knockbackAngle; + /* 0x50 */ f32 wobbleSize; + /* 0x54 */ s16 wobblePhase; + /* 0x58 */ f32 wobble; + /* 0x5C */ f32 wallCheckDist; + /* 0x60 */ ObjMineAirLink links[OBJMINE_CHAIN_MAX]; } ObjMineAirChain; // size = 0x15C typedef struct { /* 0x00 */ ObjMineMtxF3 basis; - /* 0x24 */ Vec3f unk_24; - /* 0x30 */ Vec3f unk_30; - /* 0x3C */ Vec3f unk_3C; + /* 0x24 */ Vec3f pos; + /* 0x30 */ Vec3f vel; + /* 0x3C */ Vec3f accel; } ObjMineWaterLink; // size = 0x48 typedef struct { - /* 0x0000 */ f32 unk_00; - /* 0x0004 */ Vec3f unk_04; - /* 0x0010 */ f32 unk_10; - /* 0x0014 */ f32 unk_14; - /* 0x0018 */ f32 unk_18; - /* 0x001C */ f32 unk_1C; - /* 0x0020 */ s16 unk_20; - /* 0x0024 */ f32 unk_24; - /* 0x0028 */ f32 unk_28; - /* 0x002C */ f32 unk_2C; - /* 0x0030 */ f32 unk_30; - /* 0x0034 */ f32 unk_34; - /* 0x0038 */ f32 unk_38; - /* 0x003C */ f32 unk_3C; - /* 0x0040 */ s8 unk_40; - /* 0x0044 */ ObjMineWaterLink links[0x3F]; + /* 0x00 */ f32 drag; + /* 0x04 */ Vec3f knockbackDir; + /* 0x10 */ f32 knockback; + /* 0x14 */ f32 wobbleXZ; + /* 0x18 */ f32 wobbleY; + /* 0x1C */ f32 wobble; + /* 0x20 */ s16 wobblePhaseVel; + /* 0x24 */ f32 restoreX; + /* 0x28 */ f32 maxY; + /* 0x2C */ f32 restY; + /* 0x30 */ f32 restoreY; + /* 0x34 */ f32 wallCheckDist; + /* 0x38 */ f32 wallEjectX; + /* 0x3C */ f32 wallEjectZ; + /* 0x40 */ s8 touchWall; + /* 0x44 */ ObjMineWaterLink links[OBJMINE_CHAIN_MAX]; } ObjMineWaterChain; // size = 0x11FC -// definitely fake -typedef struct { - char unk_00[0x8]; - Vec3f unk_08; - char unk_14[0xC]; - Vec3f unk_20; - char unk_2C[0x1C]; -} NextUnkStruct; // size = 0x48 - -// maybe fake -typedef struct { - /* 0x00 */ s16 unk_00; - /* 0x02 */ s16 unk_02; -} ObjMineUnkStruct3; - -typedef struct { - /* 0x00 */ Vec3f unk_00; - /* 0x0C */ Vec3f unk_0C; - /* 0x18 */ Vec3f unk_18; - ///* 0x24 */ char unk_24[0x3C]; - /* 0x24 */ Vec3f unk_24; - /* 0x30 */ f32 unk_30; - /* 0x34 */ f32 unk_34; - /* 0x38 */ f32 unk_38; - /* 0x3C */ f32 unk_3C; - /* 0x40 */ f32 unk_40; - /* 0x44 */ f32 unk_44; - /* 0x48 */ f32 unk_48; - /* 0x4C */ s16 unk_4C; - /* 0x50 */ f32 unk_50; - /* 0x54 */ s16 unk_54; - /* 0x58 */ f32 unk_58; - /* 0x5C */ f32 unk_5C; - /* 0x60 */ ObjMineUnkStruct3 unk_60[1]; -} ObjMineUnkStruct; // size = ?? 0x44??? 48 array??? - -// probably fake -typedef struct { - /* 0x00 */ Vec3f unk_00; - /* 0x0c */ Vec3f unk_0C; - ///* 0x10 */ f32 unk_10; - ///* 0x14 */ char unk_14[0x4]; - /* 0x18 */ Vec3f unk_18; - ///* 0x1C */ char unk_1C[0x4]; - ///* 0x20 */ f32 unk_20; - /* 0x24 */ Vec3f unk_24; - /* 0x30 */ Vec3f unk_30; - /* 0x3C */ Vec3f unk_3C; -} ObjMineUnkStruct2; // size = 0x48??? - typedef struct ObjMine { /* 0x0000 */ Actor actor; /* 0x0144 */ ColliderJntSph collider; diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 8e6ddd36f..8b9684c49 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -11172,7 +11172,7 @@ 0x80A81D70:("ObjMine_Water_SetCollider",), 0x80A81DEC:("ObjMine_Water_SetWorld",), 0x80A81E7C:("func_80A81E7C",), - 0x80A81FFC:("func_80A81FFC",), + 0x80A81FFC:("ObjMine_Water_ApplyForces",), 0x80A828A8:("func_80A828A8",), 0x80A82C28:("ObjMine_Water_UpdateChain",), 0x80A82C5C:("ObjMine_Init",), From 8b9625483fda154e90db4607bf7b1a17eece7079 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Mon, 6 Feb 2023 12:28:37 -0600 Subject: [PATCH 11/26] docs. physics be wack --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 266 ++++++++++-------- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 4 +- 2 files changed, 153 insertions(+), 117 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 6f828f4ce..e85f60503 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -13,10 +13,14 @@ #define THIS ((ObjMine*)thisx) #define LINK_SIZE 12.0f +// #define (LINK_SIZE / 2.0f) (LINK_SIZE / 2.0f) #define ATTACH_OFFSET 10.0f -#define AIR_RADIUS 24.0f +#define PATH_RADIUS 32.0f +#define AIR_RADIUS 20.0f #define WATER_RADIUS 36.0f #define BOMB_SPAWN_OFFSET 15.0f +#define WATER_KNOCKBACK 7.0f +#define AIR_KNOCKBACK 0.04f #define RAND_PLUSMINUS(limit) (Rand_ZeroOne()*(2.0f * (limit)) - (limit)) #define RAND_PLUSMINUSALT(limit) ((Rand_ZeroOne() - 0.5f) * (2.0f * limit)) @@ -136,7 +140,7 @@ s32 ObjMine_GetUnitVec3fNorm(Vec3f* src, Vec3f* dst, f32* norm, f32* invNorm) { void ObjMine_Path_SpawnBomb(ObjMine* this, PlayState* play) { EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, this->actor.world.pos.x, - this->actor.world.pos.y - 15.0f, this->actor.world.pos.z, 0, 0, 0, ENBOM_0); + this->actor.world.pos.y - BOMB_SPAWN_OFFSET, this->actor.world.pos.z, 0, 0, 0, ENBOM_0); if (bomb != NULL) { bomb->timer = 0; @@ -145,9 +149,8 @@ void ObjMine_Path_SpawnBomb(ObjMine* this, PlayState* play) { void ObjMine_AirWater_SpawnBomb(ObjMine* this, PlayState* play) { f32 x = this->collider.elements[0].dim.worldSphere.center.x; - f32 y = this->collider.elements[0].dim.worldSphere.center.y - 15.0f; + f32 y = this->collider.elements[0].dim.worldSphere.center.y - BOMB_SPAWN_OFFSET; f32 z = this->collider.elements[0].dim.worldSphere.center.z; - EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, x, y, z, 0, 0, 0, ENBOM_0); if (bomb != NULL) { @@ -171,7 +174,7 @@ s32 ObjMine_AirWater_CheckOC(ObjMine* this) { return false; } -void ObjMine_Air_CheckAC(ObjMine* this, s16* hitAngle, s16* hitTorque) { +void ObjMine_Air_CheckAC(ObjMine* this, s16* hitAngle, s16* torqueAngle) { s32 pad[2]; Vec3s* centerPos3s = &this->collider.elements[0].dim.worldSphere.center; Vec3f centerPos; @@ -184,14 +187,14 @@ void ObjMine_Air_CheckAC(ObjMine* this, s16* hitAngle, s16* hitTorque) { // dmgFlag check is (DMG_DEKU_BUBBLE | DMG_FIRE_ARROW | DMG_ICE_ARROW | DMG_FIRE_ARROW | DMG_NORMAL_ARROW) if (this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820) { *hitAngle = attackActor->shape.rot.y; - *hitTorque = attackActor->shape.rot.y - yawToAttack; + *torqueAngle = attackActor->shape.rot.y - yawToAttack; } else { Vec3f hitPos; Vec3s* hitPos3s = &this->collider.elements[0].info.bumper.hitPos; Math_Vec3s_ToVec3f(&hitPos, hitPos3s); *hitAngle = Actor_YawBetweenActors(attackActor, &this->actor); - *hitTorque = Math_Vec3f_Yaw(&attackActor->world.pos, &hitPos) - yawToAttack; + *torqueAngle = Math_Vec3f_Yaw(&attackActor->world.pos, &hitPos) - yawToAttack; } } @@ -230,22 +233,22 @@ void ObjMine_ReplaceTranslation(Vec3f* translation) { matrix->mf[3][2] = translation->z; } -void ObjMine_ReplaceRotation(ObjMineMtxF3* rotation) { +void ObjMine_ReplaceRotation(ObjMineMtxF3* basis) { MtxF* matrix = Matrix_GetCurrent(); - matrix->mf[0][0] = rotation->x.x; - matrix->mf[0][1] = rotation->x.y; - matrix->mf[0][2] = rotation->x.z; + matrix->mf[0][0] = basis->x.x; + matrix->mf[0][1] = basis->x.y; + matrix->mf[0][2] = basis->x.z; matrix->mf[0][3] = 0.0f; - matrix->mf[1][0] = rotation->y.x; - matrix->mf[1][1] = rotation->y.y; - matrix->mf[1][2] = rotation->y.z; + matrix->mf[1][0] = basis->y.x; + matrix->mf[1][1] = basis->y.y; + matrix->mf[1][2] = basis->y.z; matrix->mf[1][3] = 0.0f; - matrix->mf[2][0] = rotation->z.x; - matrix->mf[2][1] = rotation->z.y; - matrix->mf[2][2] = rotation->z.z; + matrix->mf[2][0] = basis->z.x; + matrix->mf[2][1] = basis->z.y; + matrix->mf[2][2] = basis->z.z; matrix->mf[2][3] = 0.0f; matrix->mf[3][0] = 0.0f; @@ -296,25 +299,28 @@ void ObjMine_Air_InitChain(ObjMine* this, s32 linkCount) { airChain->basis.x.x = 1.0f; airChain->basis.y.y = 1.0f; airChain->basis.z.z = 1.0f; + airChain->translation.y = 1.0f; + // Sets restoring force and drag. Longer chains have lower frequency and less drag. if (linkCount > 0) { - airChain->restore = -sqrtf(0.001984f / linkCountF); // approx 1/504 = 1/8 * 1/63 - airChain->drag = 0.95f + (0.00031746097f * linkCountF); // approx 1/3150 = 1/50 * 1/63 + airChain->restore = -sqrtf((0.124992f / (63.0f)) / linkCountF); // constant is close to 1/8 + airChain->drag = 0.95f + ((0.02000004f / (63.0f)) * linkCountF); // constant is close to 1/50 } airChain->wobble = 0.0002f; + // Consecutive chain links are offset 90 degrees. for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { airLink->twist = 0x4000; } if (wallCheckRadius < 0.0f) { airChain->wallCheckDist = -1.0f; - } else if (wallCheckRadius <= 20.0f + 1.0f) { + } else if (wallCheckRadius <= AIR_RADIUS + 1.0f) { airChain->wallCheckDist = 0.0f; } else { - airChain->wallCheckDist = SQ(wallCheckRadius - 20.0f); + airChain->wallCheckDist = SQ(wallCheckRadius - AIR_RADIUS); } } @@ -341,16 +347,16 @@ void ObjMine_Air_SetBasis(ObjMine* this) { void ObjMine_Air_SetWorld(ObjMine* this) { s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - f32 chainLength = 10.0f + (linkCount * 12.0f); + f32 chainLength = ATTACH_OFFSET + (linkCount * LINK_SIZE); this->actor.world.pos.x = (this->chain.air.basis.y.x * -chainLength) + this->actor.home.pos.x; this->actor.world.pos.y = (this->chain.air.basis.y.y * -chainLength) + this->actor.home.pos.y; this->actor.world.pos.z = (this->chain.air.basis.y.z * -chainLength) + this->actor.home.pos.z; } -void ObjMine_Air_SetChain3034(ObjMine* this) { +void ObjMine_Air_SetChainXZ(ObjMine* this) { s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - f32 invLength = 1.0f / (10.0f + (linkCount * 12.0f)); + f32 invLength = 1.0f / (ATTACH_OFFSET + (linkCount * LINK_SIZE)); f32 dx = this->actor.world.pos.x - this->actor.home.pos.x; f32 dz = this->actor.world.pos.z - this->actor.home.pos.z; @@ -370,14 +376,14 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { waterChain->wobble = 0.003f; waterChain->wobblePhaseVel = RANDU_BITS(13); - waterChain->restoreX = -0.0002f; + waterChain->restoreXZ = -0.0002f; waterChain->restoreY = -0.0002f; - wobbleVel = waterChain->wobble * 6.0f; + wobbleVel = waterChain->wobble * (LINK_SIZE / 2.0f); linkY = this->actor.home.pos.y; for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { - linkY += 12.0f; + linkY += LINK_SIZE; waterLink->basis.x.x = 1.0f; waterLink->basis.y.y = 1.0f; waterLink->basis.z.z = 1.0f; @@ -390,24 +396,24 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { } waterChain->maxY = linkY; + // Rest position is slightly below max chain length to give slack. waterChain->restY = waterChain->maxY * 0.97f; - linkY -= 18.0f; - - if (waterChain->restY < linkY) { + linkY -= LINK_SIZE * 1.5f; + if (waterChain->restY < linkY) { // This should only happen if linkCount > 50 waterChain->restY = linkY; } if (wallCheckRadius < 0.0f) { waterChain->wallCheckDist = -1.0f; - } else if (wallCheckRadius <= 36.0f + 1.0f) { + } else if (wallCheckRadius <= WATER_RADIUS + 1.0f) { waterChain->wallCheckDist = 0.0f; } else { - waterChain->wallCheckDist = SQ(wallCheckRadius - 36.0f); + waterChain->wallCheckDist = SQ(wallCheckRadius - WATER_RADIUS); } } void ObjMine_Water_InitCollider(ObjMine* this, s32 linkCount) { - Matrix_Translate(this->actor.home.pos.x, this->actor.home.pos.y + (linkCount * 12.0f) + 10.0f, + Matrix_Translate(this->actor.home.pos.x, this->actor.home.pos.y + (linkCount * LINK_SIZE) + ATTACH_OFFSET, this->actor.home.pos.z, MTXMODE_NEW); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); @@ -419,12 +425,12 @@ void ObjMine_Water_SetWorld(ObjMine* this) { ObjMineWaterChain* waterChain = &this->chain.water; if (linkCount == 0) { - this->actor.world.pos.y = this->actor.home.pos.y + 12.0f + 10.0f; + this->actor.world.pos.y = this->actor.home.pos.y + LINK_SIZE + ATTACH_OFFSET; } else { ObjMineWaterLink* lastLink = &waterChain->links[linkCount - 1]; Vec3f mineOffset; - Math_Vec3f_ScaleAndStore(&lastLink->basis.y, 10.0f, &mineOffset); + Math_Vec3f_ScaleAndStore(&lastLink->basis.y, ATTACH_OFFSET, &mineOffset); Math_Vec3f_Sum(&lastLink->pos, &mineOffset, &this->actor.world.pos); } } @@ -435,27 +441,28 @@ void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { waterChain->touchWall = false; if (waterChain->wallCheckDist > -1e-6f) { + // Checks for walls if mine is sufficiently far from home. if (waterChain->wallCheckDist <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, this->actor.world.pos.x, this->actor.world.pos.z)) { Vec3f centerPos; Vec3f offsetPos; Vec3f dummyResult; - Vec3f xzDistFromHome; + Vec3f xzFromHome; Vec3f xzDirFromHome; CollisionPoly* dummyPoly; s32 dummyBgId; f32 dummyNorm; f32 dummyInvNorm; - xzDistFromHome.x = this->actor.world.pos.x - this->actor.home.pos.x; - xzDistFromHome.y = 0.0f; - xzDistFromHome.z = this->actor.world.pos.z - this->actor.home.pos.z; + xzFromHome.x = this->actor.world.pos.x - this->actor.home.pos.x; + xzFromHome.y = 0.0f; + xzFromHome.z = this->actor.world.pos.z - this->actor.home.pos.z; - if (ObjMine_GetUnitVec3fNorm(&xzDistFromHome, &xzDirFromHome, &dummyNorm, &dummyInvNorm)) { + if (ObjMine_GetUnitVec3fNorm(&xzFromHome, &xzDirFromHome, &dummyNorm, &dummyInvNorm)) { - offsetPos.x = this->actor.world.pos.x + (xzDirFromHome.x * 36.0f); + offsetPos.x = this->actor.world.pos.x + (xzDirFromHome.x * WATER_RADIUS); offsetPos.y = this->actor.world.pos.y; - offsetPos.z = this->actor.world.pos.z + (xzDirFromHome.z * 36.0f); + offsetPos.z = this->actor.world.pos.z + (xzDirFromHome.z * WATER_RADIUS); centerPos.x = this->actor.home.pos.x; centerPos.y = this->actor.world.pos.y; @@ -474,7 +481,7 @@ void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { #if 0 // Probably equivalent, but nightmare loop unrolls. void ObjMine_Water_ApplyForces(ObjMine *this) { - static Vec3f sLinkAccel[0x40]; + static Vec3f sLastLinkAccel[0x40]; ObjMineWaterChain *waterChain = &this->chain.water; ObjMineWaterLink *waterLink; s32 i; @@ -485,8 +492,9 @@ void ObjMine_Water_ApplyForces(ObjMine *this) { Vec3f tension; f32 scaledKnockback; + // Applies the buoyant force and sway from the water. for(i = 0, waterLink = waterChain->links, wobblePhase = 0; i < linkCount; i++, waterLink++, wobblePhase += waterChain->wobblePhaseVel) { - Math_Vec3f_Copy(&sLinkAccel[i], &waterLink->accel); + Math_Vec3f_Copy(&sLastLinkAccel[i], &waterLink->accel); if (waterLink->pos.y <= this->actor.home.pos.y) { waterLink->accel.y = waterChain->restoreY * -96.0f; } else if (restoreY > 0.0f) { @@ -494,12 +502,14 @@ void ObjMine_Water_ApplyForces(ObjMine *this) { } else { waterLink->accel.y = restoreY; } - waterLink->accel.x = (waterLink->pos.x - this->actor.home.pos.x) * waterChain->restoreX; - waterLink->accel.z = (waterLink->pos.z - this->actor.home.pos.z) * waterChain->restoreX; + waterLink->accel.x = (waterLink->pos.x - this->actor.home.pos.x) * waterChain->restoreXZ; + waterLink->accel.z = (waterLink->pos.z - this->actor.home.pos.z) * waterChain->restoreXZ; waterLink->accel.x += waterChain->wobbleXZ * Math_SinS(wobblePhase); waterLink->accel.y += waterChain->wobbleY; waterLink->accel.z += waterChain->wobbleXZ * Math_CosS(wobblePhase); } + + // Applies knockback force. Knockback on the links is scaled quadratically, possibly to account for link rotations being cumulative if (waterChain->knockback > 0.0001f) { for(i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { scaledKnockback = SQ((linkCount - i) * inverseCount); @@ -509,6 +519,8 @@ void ObjMine_Water_ApplyForces(ObjMine *this) { waterLink->accel.z += waterChain->knockbackDir.z * scaledKnockback; } } + + // Links that intersect walls are ejected from them. if (waterChain->touchWall) { for(i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { waterLink->accel.x += waterChain->wallEjectX; @@ -516,30 +528,33 @@ void ObjMine_Water_ApplyForces(ObjMine *this) { } } + // Forces on the links from other links. This is simulated by a triangle filter on the forces from the previous frame. for(i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { Math_Vec3f_Copy(&tension, &gZeroVec3f); if(i - 2 >= 0) { - tension.x += sLinkAccel[i - 2].x * 0.075f; - tension.y += sLinkAccel[i - 2].y * 0.075f; - tension.z += sLinkAccel[i - 2].z * 0.075f; + tension.x += sLastLinkAccel[i - 2].x * 0.075f; + tension.y += sLastLinkAccel[i - 2].y * 0.075f; + tension.z += sLastLinkAccel[i - 2].z * 0.075f; } if(i - 1 >= 0) { - tension.x += sLinkAccel[i - 1].x * 0.15f; - tension.y += sLinkAccel[i - 1].y * 0.15f; - tension.z += sLinkAccel[i - 1].z * 0.15f; + tension.x += sLastLinkAccel[i - 1].x * 0.15f; + tension.y += sLastLinkAccel[i - 1].y * 0.15f; + tension.z += sLastLinkAccel[i - 1].z * 0.15f; } - tension.x += sLinkAccel[i].x * 0.3f; - tension.y += sLinkAccel[i].y * 0.3f; - tension.z += sLinkAccel[i].z * 0.3f; + + tension.x += sLastLinkAccel[i].x * 0.3f; + tension.y += sLastLinkAccel[i].y * 0.3f; + tension.z += sLastLinkAccel[i].z * 0.3f; + if(i + 1 < linkCount) { - tension.x += sLinkAccel[i + 1].x * 0.15f; - tension.y += sLinkAccel[i + 1].y * 0.15f; - tension.z += sLinkAccel[i + 1].z * 0.15f; + tension.x += sLastLinkAccel[i + 1].x * 0.15f; + tension.y += sLastLinkAccel[i + 1].y * 0.15f; + tension.z += sLastLinkAccel[i + 1].z * 0.15f; } if(i + 2 < linkCount) { - tension.x += sLinkAccel[i + 2].x * 0.075f; - tension.y += sLinkAccel[i + 2].y * 0.075f; - tension.z += sLinkAccel[i + 2].z * 0.075f; + tension.x += sLastLinkAccel[i + 2].x * 0.075f; + tension.y += sLastLinkAccel[i + 2].y * 0.075f; + tension.z += sLastLinkAccel[i + 2].z * 0.075f; } waterLink->accel.x += tension.x; waterLink->accel.y += tension.y; @@ -560,21 +575,22 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { ObjMineWaterChain* waterChain = &this->chain.water; ObjMineWaterLink* waterLink; s32 i; - Vec3f* lastBasisX; + Vec3f* jointBasisX; Vec3f tempVec; Vec3f diffDir; Vec3f unusedLinkPos; - Vec3f lastLinkPos; + Vec3f jointPos; s32 changeBasis; f32 diffNorm; f32 dummyInvNorm; Vec3f* tempBasisX; - lastLinkPos.x = this->actor.home.pos.x; - lastLinkPos.y = this->actor.home.pos.y + 6.0f; - lastLinkPos.z = this->actor.home.pos.z; + // The joint between the current link and next link is half the link's length from its center. The first link is assumed to be vertical and centered on home. + jointPos.x = this->actor.home.pos.x; + jointPos.y = this->actor.home.pos.y + (LINK_SIZE / 2.0f); + jointPos.z = this->actor.home.pos.z; - for (i = 0, lastBasisX = NULL, waterLink = waterChain->links; i < linkCount; i++, lastBasisX = &waterLink->basis.x, waterLink++) { + for (i = 0, jointBasisX = NULL, waterLink = waterChain->links; i < linkCount; i++, jointBasisX = &waterLink->basis.x, waterLink++) { changeBasis = false; waterLink->vel.x += waterLink->accel.x; @@ -592,12 +608,13 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { waterLink->vel.y *= 0.1f; } - Math_Vec3f_Diff(&waterLink->pos, &lastLinkPos, &tempVec); + // If the calculated position is less than 1/3 of the link's length from the joint, the chain is considered slack and the link keeps the same basis. Otherwise the basis is updated with the new position relative to the joint. The StepUntilParallel causes the chain to straighten over time. + Math_Vec3f_Diff(&waterLink->pos, &jointPos, &tempVec); - if (ObjMine_GetUnitVec3fNorm(&tempVec, &diffDir, &diffNorm, &dummyInvNorm) && (diffNorm > 4.0f)) { + if (ObjMine_GetUnitVec3fNorm(&tempVec, &diffDir, &diffNorm, &dummyInvNorm) && (diffNorm > LINK_SIZE / 3.0f)) { Math_Vec3f_Copy(&newBasis.y, &waterLink->basis.y); ObjMine_StepUntilParallel(&newBasis.y, &diffDir, M_PI / 30); - tempBasisX = (lastBasisX == NULL) ? &sStandardBasis.x : lastBasisX; + tempBasisX = (jointBasisX == NULL) ? &sStandardBasis.x : jointBasisX; Math3D_CrossProduct(tempBasisX, &newBasis.y, &tempVec); @@ -614,28 +631,28 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { Math_Vec3f_Copy(&waterLink->basis.y, &newBasis.y); Math_Vec3f_Copy(&waterLink->basis.z, &newBasis.z); } else { - diffNorm = 4.0f; + diffNorm = LINK_SIZE / 3.0f; } - if (diffNorm >= 6.0f) { - waterLink->pos.x = lastLinkPos.x + (waterLink->basis.y.x * 6.0f); - waterLink->pos.y = lastLinkPos.y + (waterLink->basis.y.y * 6.0f); - waterLink->pos.z = lastLinkPos.z + (waterLink->basis.y.z * 6.0f); + if (diffNorm >= (LINK_SIZE / 2.0f)) { + waterLink->pos.x = jointPos.x + (waterLink->basis.y.x * (LINK_SIZE / 2.0f)); + waterLink->pos.y = jointPos.y + (waterLink->basis.y.y * (LINK_SIZE / 2.0f)); + waterLink->pos.z = jointPos.z + (waterLink->basis.y.z * (LINK_SIZE / 2.0f)); } else { - waterLink->pos.x = lastLinkPos.x + (waterLink->basis.y.x * diffNorm); - waterLink->pos.y = lastLinkPos.y + (waterLink->basis.y.y * diffNorm); - waterLink->pos.z = lastLinkPos.z + (waterLink->basis.y.z * diffNorm); + waterLink->pos.x = jointPos.x + (waterLink->basis.y.x * diffNorm); + waterLink->pos.y = jointPos.y + (waterLink->basis.y.y * diffNorm); + waterLink->pos.z = jointPos.z + (waterLink->basis.y.z * diffNorm); } - lastLinkPos.x = waterLink->pos.x + (waterLink->basis.y.x * 6.0f); - lastLinkPos.y = waterLink->pos.y + (waterLink->basis.y.y * 6.0f); - lastLinkPos.z = waterLink->pos.z + (waterLink->basis.y.z * 6.0f); + jointPos.x = waterLink->pos.x + (waterLink->basis.y.x * (LINK_SIZE / 2.0f)); + jointPos.y = waterLink->pos.y + (waterLink->basis.y.y * (LINK_SIZE / 2.0f)); + jointPos.z = waterLink->pos.z + (waterLink->basis.y.z * (LINK_SIZE / 2.0f)); } } void ObjMine_Water_UpdateChain(ObjMine* this, PlayState* play) { ObjMine_Water_WallCheck(this, play); - ObjMine_Water_ApplyForces(this); // ObjMine_Water_ApplyForces + ObjMine_Water_ApplyForces(this); ObjMine_Water_UpdateLinks(this); } @@ -658,7 +675,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { if (type == OBJMINE_TYPE_PATH) { ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 45.0f); this->actor.shape.shadowAlpha = 140; - this->pathSpeed = sPathSpeeds[OBJMINE_GET_PATH_SPEED(&this->actor)]; + this->pathSpeed = sPathSpeeds[OBJMINE_GET_PATH_SPEED(&this->actor)]; // sPathSpeeds[i] = i + 1.0f if (pathIndex == 0xFF) { ObjMine_Path_SetupStationary(this); } else { @@ -681,15 +698,15 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); this->actor.update = ObjMine_AirWater_Update; - this->actor.uncullZoneScale = 150.0f + (linkCount * 21.0f); - this->actor.uncullZoneDownward = 150.0f + (linkCount * 21.0f); + this->actor.uncullZoneScale = 150.0f + (linkCount * (LINK_SIZE * 1.75f)); + this->actor.uncullZoneDownward = 150.0f + (linkCount * (LINK_SIZE * 1.75f)); ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 45.0f); this->actor.shape.shadowAlpha = 140; if (type == OBJMINE_TYPE_AIR) { this->actor.draw = ObjMine_Air_Draw; ObjMine_Air_InitChain(this, linkCount); - this->actor.world.pos.y = -10.0f - (linkCount * 12.0f) + this->actor.home.pos.y; + this->actor.world.pos.y = -ATTACH_OFFSET - (linkCount * LINK_SIZE) + this->actor.home.pos.y; ObjMine_Air_SetCollider(this, linkCount); func_800B4AEC(play, &this->actor, 0.0f); if (linkCount == 0) { @@ -700,7 +717,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { } else { this->actor.draw = ObjMine_Water_Draw; ObjMine_Water_InitChain(this, linkCount); - this->actor.world.pos.y = 10.0f + (linkCount * 12.0f) + this->actor.home.pos.y; + this->actor.world.pos.y = ATTACH_OFFSET + (linkCount * LINK_SIZE) + this->actor.home.pos.y; ObjMine_Water_InitCollider(this, linkCount); if (linkCount == 0) { ObjMine_Water_SetupStationary(this); @@ -725,22 +742,24 @@ void ObjMine_Path_Stationary(ObjMine* this, PlayState* play) { } void ObjMine_Path_SetupMove(ObjMine* this) { - this->actor.flags |= ACTOR_FLAG_10; + this->actor.flags |= ACTOR_FLAG_10; // @bug? Sets flag 10, but later checks flag 40. this->actionFunc = ObjMine_Path_Move; } void ObjMine_Path_Move(ObjMine* this, PlayState* play) { Actor* thisx = &this->actor; // pos and velocity need this, though it can replace all `this->actor`s and match Vec3f nextWaypoint; - f32 speed; + f32 distToWaypoint; f32 step; f32 target; s32 dummyBgVec; Math_Vec3s_ToVec3f(&nextWaypoint, &this->waypoints[this->waypointIndex + 1]); Math_Vec3f_Diff(&nextWaypoint, &thisx->world.pos, &thisx->velocity); - speed = Math3D_Vec3fMagnitude(&thisx->velocity); - if ((speed < (this->pathSpeed * 8.0f)) && (this->pathSpeed > 2.0f)) { + distToWaypoint = Math3D_Vec3fMagnitude(&thisx->velocity); + + // Mine slows to 2.0f speed when 8 frames away from the next waypoint + if ((distToWaypoint < (this->pathSpeed * 8.0f)) && (this->pathSpeed > 2.0f)) { target = 2.0f + ((this->pathSpeed - 2.0f) * 0.1f); step = this->pathSpeed * 0.03f; } else { @@ -748,8 +767,11 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { step = this->pathSpeed * 0.16f; } Math_StepToF(&this->actor.speedXZ, target, step); - if ((this->actor.speedXZ + 0.05f) < speed) { - Math_Vec3f_Scale(&thisx->velocity, this->actor.speedXZ / speed); + + // Checks if mine will reach the waypoint next frame + if ((this->actor.speedXZ + 0.05f) < distToWaypoint) { + // Scales thisx->velocity to be equal in magnitude to speedXZ + Math_Vec3f_Scale(&thisx->velocity, this->actor.speedXZ / distToWaypoint); this->actor.world.pos.x += thisx->velocity.x; this->actor.world.pos.y += thisx->velocity.y; this->actor.world.pos.z += thisx->velocity.z; @@ -767,9 +789,10 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { Vec3f yhatCrossV; MtxF rotMtxF; + // Makes mines appear to roll while traversing the path Math3D_CrossProduct(&sStandardBasis.y, &thisx->velocity, &yhatCrossV); if (ObjMine_GetUnitVec3f(&yhatCrossV, &rotAxis)) { - Matrix_RotateAxisF(this->actor.speedXZ / 32.0f, &rotAxis, MTXMODE_NEW); + Matrix_RotateAxisF(this->actor.speedXZ / PATH_RADIUS, &rotAxis, MTXMODE_NEW); Matrix_RotateYS(this->actor.shape.rot.y, MTXMODE_APPLY); Matrix_RotateXS(this->actor.shape.rot.x, MTXMODE_APPLY); Matrix_RotateZS(this->actor.shape.rot.z, MTXMODE_APPLY); @@ -791,7 +814,7 @@ void ObjMine_SetupExplode(ObjMine* this) { void ObjMine_Explode(ObjMine* this, PlayState* play) { this->actor.scale.x *= 1.8f; - if (this->actor.scale.x > 30.0f * 0.001f * CUBE(1.8f)) { + if (this->actor.scale.x > 0.02f * 1.5f * 5.832f) { // 5.832 = 1.8^3 Actor_Kill(&this->actor); } else { this->actor.scale.y = this->actor.scale.x; @@ -815,6 +838,8 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { s16 twistDiff; Math_Vec3f_Copy(&airChain->translation, &airChain->basis.y); + + // Explodes if collision with Player or another mine is detected. if (ObjMine_AirWater_CheckOC(this)) { ObjMine_AirWater_SpawnBomb(this, play); ObjMine_AirWater_Noop(this); @@ -822,48 +847,53 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { return; } - if (this->collider.base.acFlags & AC_HIT) { // initial knockback calc + // Calculates initial knockback and torque from hit scaled to chain length + if (this->collider.base.acFlags & AC_HIT) { s16 torqueAngle; f32 torque; f32 torqueDiff; this->collider.base.acFlags &= ~AC_HIT; - airChain->knockback = 0.04f; + airChain->knockback = AIR_KNOCKBACK; ObjMine_Air_CheckAC(this, &airChain->knockbackAngle, &torqueAngle); - torque = Math_SinS(torqueAngle) * 150.0f; + torque = Math_SinS(torqueAngle) * 0x96; torqueDiff = -(torque / linkCount); for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { airLink->spin += (s16)torque; - airLink->spin = CLAMP(airLink->spin, -800, 800); + airLink->spin = CLAMP(airLink->spin, -0x320, 0x320); torque -= torqueDiff; } } - if (airChain->knockback > 0.0001f) { // residual knockback calc + // Applies knockback force. Knockback applies over two frames, with the second at half strength + if (airChain->knockback > 0.0001f) { xAccel = Math_SinS(airChain->knockbackAngle) * airChain->knockback; zAccel = Math_CosS(airChain->knockbackAngle) * airChain->knockback; airChain->xVel += xAccel; airChain->zVel += zAccel; - Math_StepToF(&airChain->knockback, 0.0f, 0.02f); + Math_StepToF(&airChain->knockback, 0.0f, AIR_KNOCKBACK * 0.5f); } - if (RANDU_BITS(5) == 0) { // wobble + // Applies chain sway, choosing a new sway randomly about every 32 frames + if (RANDU_BITS(5) == 0) { airChain->wobbleSize = Rand_ZeroOne() * airChain->wobble; airChain->wobblePhase = RANDU_BITS(16); } - xAccel = Math_SinS(airChain->wobblePhase) * airChain->wobbleSize; zAccel = Math_CosS(airChain->wobblePhase) * airChain->wobbleSize; airChain->xVel += xAccel; airChain->zVel += zAccel; + // Applies the restoring force of gravity and chain tension using small-angle approximation airChain->xVel += airChain->xDiff * airChain->restore; airChain->zVel += airChain->zDiff * airChain->restore; + // Applies linear drag airChain->xVel *= airChain->drag; airChain->zVel *= airChain->drag; + // Updates scaled position and does a safety clamp to 5.0f. airChain->xDiff += airChain->xVel; airChain->zDiff += airChain->zVel; @@ -873,13 +903,11 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { ObjMine_Air_SetBasis(this); ObjMine_Air_SetWorld(this); + // Checks for wall collisions if sufficiently far from home. If collision detected, bounce off the wall at half speed. If speed is close to zero when hitting wall, weakly eject it instead. if (airChain->wallCheckDist > -1e-6f) { - // Vec3f* world = &this->actor.world.pos; - // Vec3f* home = &this->actor.home.pos; - if (airChain->wallCheckDist <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, this->actor.home.pos.x, this->actor.home.pos.z)) { - Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, 20.0f, 0.0f, 1); + Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, AIR_RADIUS, 0.0f, 1); if ((this->actor.bgCheckFlags & 8) && (this->actor.wallPoly != NULL)) { Vec3f xzDir; @@ -907,13 +935,14 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { airChain->xVel *= -0.1f; airChain->zVel *= -0.1f; } - ObjMine_Air_SetChain3034(this); + ObjMine_Air_SetChainXZ(this); ObjMine_Air_SetBasis(this); ObjMine_Air_SetWorld(this); } } } + // Applies three torques to individual chain links. The restoring torque towards the default twist of 0x4000, a random torque for variance, and a linear drag. for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { twistDiff = airLink->twist - 0x4000; torque = airLink->spin + (twistDiff * -0.05f) + RAND_PLUSMINUS(15.0f); @@ -933,6 +962,7 @@ void ObjMine_Air_SetupStationary(ObjMine* this) { } void ObjMine_Air_Stationary(ObjMine* this, PlayState* play) { + // Explodes if collision with Player or another mine is detected. if (ObjMine_AirWater_CheckOC(this)) { ObjMine_AirWater_SpawnBomb(this, play); ObjMine_AirWater_Noop(this); @@ -951,6 +981,7 @@ void ObjMine_Water_SetupChained(ObjMine* this) { void ObjMine_Water_Chained(ObjMine* this, PlayState* play) { ObjMineWaterChain* waterChain = &this->chain.water; + // Explodes if collision with Player or another mine is detected. if (ObjMine_AirWater_CheckOC(this)) { ObjMine_AirWater_SpawnBomb(this, play); ObjMine_AirWater_Noop(this); @@ -958,19 +989,21 @@ void ObjMine_Water_Chained(ObjMine* this, PlayState* play) { return; } + // Calculates knockback from AC hits if (this->collider.base.acFlags & AC_HIT) { this->collider.base.acFlags &= ~AC_HIT; ObjMine_Water_CheckAC(this, &waterChain->knockbackDir); - waterChain->knockback = 7.0f; - Math_Vec3f_Scale(&waterChain->knockbackDir, 7.0f); + waterChain->knockback = WATER_KNOCKBACK; + Math_Vec3f_Scale(&waterChain->knockbackDir, WATER_KNOCKBACK); } + // Reduces knockback each frame. Effectively makes knockback 60% on the first frame and 20% on the second. if (waterChain->knockback > 0.0001f) { - waterChain->knockback = Math_Vec3f_StepTo(&waterChain->knockbackDir, &gZeroVec3f, 2.8f); + waterChain->knockback = Math_Vec3f_StepTo(&waterChain->knockbackDir, &gZeroVec3f, WATER_KNOCKBACK * 0.4f); } waterChain->drag = 0.9f; - waterChain->restoreX = -0.0002f; + waterChain->restoreXZ = -0.0002f; waterChain->restoreY = -0.0002f; waterChain->wobble = 0.003f; @@ -994,6 +1027,7 @@ void ObjMine_Water_SetupStationary(ObjMine* this) { } void ObjMine_Water_Stationary(ObjMine* this, PlayState* play) { + // Explodes if collision with Player or another mine is detected. if (ObjMine_AirWater_CheckOC(this)) { ObjMine_AirWater_SpawnBomb(this, play); ObjMine_AirWater_Noop(this); @@ -1095,12 +1129,13 @@ void ObjMine_Air_Draw(Actor* thisx, PlayState* play) { ObjMine_ReplaceRotation(&airChain->basis); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); if (linkCount != 0) { - Math_Vec3f_ScaleAndStore(&airChain->basis.y, -6.0f, &linkOffset); + // Sets pivot point to be half a chain link length below home + Math_Vec3f_ScaleAndStore(&airChain->basis.y, -(LINK_SIZE / 2.0f), &linkOffset); linkPos.x = this->actor.home.pos.x - linkOffset.x; - linkPos.y = this->actor.home.pos.y - 6.0f - linkOffset.y; + linkPos.y = this->actor.home.pos.y - (LINK_SIZE / 2.0f) - linkOffset.y; linkPos.z = this->actor.home.pos.z - linkOffset.z; + Math_Vec3f_ScaleAndStore(&airChain->basis.y, -LINK_SIZE, &linkOffset); - Math_Vec3f_ScaleAndStore(&airChain->basis.y, -12.0f, &linkOffset); for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { Matrix_RotateYS(airLink->twist, MTXMODE_APPLY); linkPos.x += linkOffset.x; @@ -1149,6 +1184,7 @@ void ObjMine_Water_Draw(Actor* thisx, PlayState* play) { for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { ObjMine_ReplaceRotation(&waterLink->basis); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + // Consecutive chain links are offset 90 degrees. if ((i % 2) == 0) { Matrix_RotateYS(0x4000, MTXMODE_APPLY); } diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index cfc2ff2f2..92176d36a 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -36,7 +36,7 @@ typedef struct { typedef struct { /* 0x00 */ ObjMineMtxF3 basis; - /* 0x24 */ Vec3f translation; + /* 0x24 */ Vec3f translation; // unused /* 0x30 */ f32 xDiff; /* 0x34 */ f32 zDiff; /* 0x38 */ f32 xVel; @@ -67,7 +67,7 @@ typedef struct { /* 0x18 */ f32 wobbleY; /* 0x1C */ f32 wobble; /* 0x20 */ s16 wobblePhaseVel; - /* 0x24 */ f32 restoreX; + /* 0x24 */ f32 restoreXZ; /* 0x28 */ f32 maxY; /* 0x2C */ f32 restY; /* 0x30 */ f32 restoreY; From 058246cb4411d39990708e704599718ec128522e Mon Sep 17 00:00:00 2001 From: petrie911 Date: Mon, 6 Feb 2023 12:31:32 -0600 Subject: [PATCH 12/26] forgot some things --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 1 - tools/disasm/functions.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index e85f60503..8c08f9ff3 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -13,7 +13,6 @@ #define THIS ((ObjMine*)thisx) #define LINK_SIZE 12.0f -// #define (LINK_SIZE / 2.0f) (LINK_SIZE / 2.0f) #define ATTACH_OFFSET 10.0f #define PATH_RADIUS 32.0f #define AIR_RADIUS 20.0f diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 8b9684c49..0ef8fe70f 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -11167,7 +11167,7 @@ 0x80A819A4:("ObjMine_Air_SetCollider",), 0x80A81A00:("ObjMine_Air_SetBasis",), 0x80A81AA4:("ObjMine_Air_SetWorld",), - 0x80A81B14:("ObjMine_Air_SetChain3034",), + 0x80A81B14:("ObjMine_Air_SetChainXZ",), 0x80A81B7C:("ObjMine_Water_InitChain",), 0x80A81D70:("ObjMine_Water_SetCollider",), 0x80A81DEC:("ObjMine_Water_SetWorld",), From ed68e1cccf5d472363962c1245eeee46504a1a14 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Tue, 7 Feb 2023 05:28:45 -0600 Subject: [PATCH 13/26] format --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 61 +++++++++++-------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 8c08f9ff3..2af6aaa9b 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -21,7 +21,7 @@ #define WATER_KNOCKBACK 7.0f #define AIR_KNOCKBACK 0.04f -#define RAND_PLUSMINUS(limit) (Rand_ZeroOne()*(2.0f * (limit)) - (limit)) +#define RAND_PLUSMINUS(limit) (Rand_ZeroOne() * (2.0f * (limit)) - (limit)) #define RAND_PLUSMINUSALT(limit) ((Rand_ZeroOne() - 0.5f) * (2.0f * limit)) void ObjMine_Init(Actor* thisx, PlayState* play); @@ -138,8 +138,9 @@ s32 ObjMine_GetUnitVec3fNorm(Vec3f* src, Vec3f* dst, f32* norm, f32* invNorm) { } void ObjMine_Path_SpawnBomb(ObjMine* this, PlayState* play) { - EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, this->actor.world.pos.x, - this->actor.world.pos.y - BOMB_SPAWN_OFFSET, this->actor.world.pos.z, 0, 0, 0, ENBOM_0); + EnBom* bomb = + (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, this->actor.world.pos.x, + this->actor.world.pos.y - BOMB_SPAWN_OFFSET, this->actor.world.pos.z, 0, 0, 0, ENBOM_0); if (bomb != NULL) { bomb->timer = 0; @@ -303,8 +304,8 @@ void ObjMine_Air_InitChain(ObjMine* this, s32 linkCount) { // Sets restoring force and drag. Longer chains have lower frequency and less drag. if (linkCount > 0) { - airChain->restore = -sqrtf((0.124992f / (63.0f)) / linkCountF); // constant is close to 1/8 - airChain->drag = 0.95f + ((0.02000004f / (63.0f)) * linkCountF); // constant is close to 1/50 + airChain->restore = -sqrtf((0.124992f / (63.0f)) / linkCountF); // constant is close to 1/8 + airChain->drag = 0.95f + ((0.02000004f / (63.0f)) * linkCountF); // constant is close to 1/50 } airChain->wobble = 0.0002f; @@ -394,7 +395,7 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { waterLink->vel.z = (Rand_ZeroOne() - 0.5f) * wobbleVel; } waterChain->maxY = linkY; - + // Rest position is slightly below max chain length to give slack. waterChain->restY = waterChain->maxY * 0.97f; linkY -= LINK_SIZE * 1.5f; @@ -413,7 +414,7 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { void ObjMine_Water_InitCollider(ObjMine* this, s32 linkCount) { Matrix_Translate(this->actor.home.pos.x, this->actor.home.pos.y + (linkCount * LINK_SIZE) + ATTACH_OFFSET, - this->actor.home.pos.z, MTXMODE_NEW); + this->actor.home.pos.z, MTXMODE_NEW); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); } @@ -422,7 +423,7 @@ void ObjMine_Water_SetWorld(ObjMine* this) { s32 pad; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); ObjMineWaterChain* waterChain = &this->chain.water; - + if (linkCount == 0) { this->actor.world.pos.y = this->actor.home.pos.y + LINK_SIZE + ATTACH_OFFSET; } else { @@ -437,12 +438,12 @@ void ObjMine_Water_SetWorld(ObjMine* this) { void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { s32 pad; ObjMineWaterChain* waterChain = &this->chain.water; - + waterChain->touchWall = false; if (waterChain->wallCheckDist > -1e-6f) { // Checks for walls if mine is sufficiently far from home. if (waterChain->wallCheckDist <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, - this->actor.world.pos.x, this->actor.world.pos.z)) { + this->actor.world.pos.x, this->actor.world.pos.z)) { Vec3f centerPos; Vec3f offsetPos; Vec3f dummyResult; @@ -467,7 +468,8 @@ void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { centerPos.y = this->actor.world.pos.y; centerPos.z = this->actor.home.pos.z; - if (BgCheck_EntityLineTest1(&play->colCtx, ¢erPos, &offsetPos, &dummyResult, &dummyPoly, true, false, false, true, &dummyBgId)) { + if (BgCheck_EntityLineTest1(&play->colCtx, ¢erPos, &offsetPos, &dummyResult, &dummyPoly, true, + false, false, true, &dummyBgId)) { waterChain->touchWall = true; waterChain->wallEjectX = xzDirFromHome.x * -0.2f; waterChain->wallEjectZ = xzDirFromHome.z * -0.2f; @@ -584,12 +586,14 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { f32 dummyInvNorm; Vec3f* tempBasisX; - // The joint between the current link and next link is half the link's length from its center. The first link is assumed to be vertical and centered on home. + // The joint between the current link and next link is half the link's length from its center. The first link is + // assumed to be vertical and centered on home. jointPos.x = this->actor.home.pos.x; jointPos.y = this->actor.home.pos.y + (LINK_SIZE / 2.0f); jointPos.z = this->actor.home.pos.z; - for (i = 0, jointBasisX = NULL, waterLink = waterChain->links; i < linkCount; i++, jointBasisX = &waterLink->basis.x, waterLink++) { + for (i = 0, jointBasisX = NULL, waterLink = waterChain->links; i < linkCount; + i++, jointBasisX = &waterLink->basis.x, waterLink++) { changeBasis = false; waterLink->vel.x += waterLink->accel.x; @@ -607,7 +611,9 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { waterLink->vel.y *= 0.1f; } - // If the calculated position is less than 1/3 of the link's length from the joint, the chain is considered slack and the link keeps the same basis. Otherwise the basis is updated with the new position relative to the joint. The StepUntilParallel causes the chain to straighten over time. + // If the calculated position is less than 1/3 of the link's length from the joint, the chain is considered + // slack and the link keeps the same basis. Otherwise the basis is updated with the new position relative to the + // joint. The StepUntilParallel causes the chain to straighten over time. Math_Vec3f_Diff(&waterLink->pos, &jointPos, &tempVec); if (ObjMine_GetUnitVec3fNorm(&tempVec, &diffDir, &diffNorm, &dummyInvNorm) && (diffNorm > LINK_SIZE / 3.0f)) { @@ -667,7 +673,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { this->actor.shape.rot.z = 0; this->actor.world.rot.z = 0; - + Collider_InitJntSph(play, &this->collider); Collider_SetJntSph(play, &this->collider, &this->actor, &sJntSphInit, this->colliderElements); @@ -688,7 +694,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { ObjMine_Path_SetupMove(this); } Matrix_SetTranslateRotateYXZ(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, - &this->actor.shape.rot); + &this->actor.shape.rot); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &dummyBgId, @@ -716,7 +722,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { } else { this->actor.draw = ObjMine_Water_Draw; ObjMine_Water_InitChain(this, linkCount); - this->actor.world.pos.y = ATTACH_OFFSET + (linkCount * LINK_SIZE) + this->actor.home.pos.y; + this->actor.world.pos.y = ATTACH_OFFSET + (linkCount * LINK_SIZE) + this->actor.home.pos.y; ObjMine_Water_InitCollider(this, linkCount); if (linkCount == 0) { ObjMine_Water_SetupStationary(this); @@ -751,12 +757,12 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { f32 distToWaypoint; f32 step; f32 target; - s32 dummyBgVec; + s32 dummyBgVec; Math_Vec3s_ToVec3f(&nextWaypoint, &this->waypoints[this->waypointIndex + 1]); Math_Vec3f_Diff(&nextWaypoint, &thisx->world.pos, &thisx->velocity); distToWaypoint = Math3D_Vec3fMagnitude(&thisx->velocity); - + // Mine slows to 2.0f speed when 8 frames away from the next waypoint if ((distToWaypoint < (this->pathSpeed * 8.0f)) && (this->pathSpeed > 2.0f)) { target = 2.0f + ((this->pathSpeed - 2.0f) * 0.1f); @@ -782,7 +788,8 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { } ObjMine_Path_MoveToWaypoint(this, this->waypointIndex); } - this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &dummyBgVec, &this->actor, &thisx->world.pos); + this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &dummyBgVec, + &this->actor, &thisx->world.pos); if (this->actor.flags & ACTOR_FLAG_40) { Vec3f rotAxis; Vec3f yhatCrossV; @@ -851,7 +858,7 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { s16 torqueAngle; f32 torque; f32 torqueDiff; - + this->collider.base.acFlags &= ~AC_HIT; airChain->knockback = AIR_KNOCKBACK; ObjMine_Air_CheckAC(this, &airChain->knockbackAngle, &torqueAngle); @@ -902,9 +909,11 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { ObjMine_Air_SetBasis(this); ObjMine_Air_SetWorld(this); - // Checks for wall collisions if sufficiently far from home. If collision detected, bounce off the wall at half speed. If speed is close to zero when hitting wall, weakly eject it instead. + // Checks for wall collisions if sufficiently far from home. If collision detected, bounce off the wall at half + // speed. If speed is close to zero when hitting wall, weakly eject it instead. if (airChain->wallCheckDist > -1e-6f) { - if (airChain->wallCheckDist <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, this->actor.home.pos.x, this->actor.home.pos.z)) { + if (airChain->wallCheckDist <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, + this->actor.home.pos.x, this->actor.home.pos.z)) { Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, AIR_RADIUS, 0.0f, 1); @@ -941,7 +950,8 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { } } - // Applies three torques to individual chain links. The restoring torque towards the default twist of 0x4000, a random torque for variance, and a linear drag. + // Applies three torques to individual chain links. The restoring torque towards the default twist of 0x4000, a + // random torque for variance, and a linear drag. for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { twistDiff = airLink->twist - 0x4000; torque = airLink->spin + (twistDiff * -0.05f) + RAND_PLUSMINUS(15.0f); @@ -1011,7 +1021,7 @@ void ObjMine_Water_Chained(ObjMine* this, PlayState* play) { waterChain->wobbleXZ = Math_SinS(randAngle) * 1.8f * waterChain->wobble; waterChain->wobbleY = Math_CosS(randAngle) * 0.2f * waterChain->wobble; - waterChain->wobblePhaseVel = RANDU_BITS(13); + waterChain->wobblePhaseVel = RANDU_BITS(13); } ObjMine_Water_UpdateChain(this, play); @@ -1036,7 +1046,6 @@ void ObjMine_Water_Stationary(ObjMine* this, PlayState* play) { CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base); CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base); - } void ObjMine_Path_Update(Actor* thisx, PlayState* play) { From 6d047a7b7d92a18d0d3294e52067913039a0086c Mon Sep 17 00:00:00 2001 From: petrie911 Date: Thu, 13 Apr 2023 08:50:46 -0500 Subject: [PATCH 14/26] more cleanup --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 42 +++++++++---------- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 14 +++---- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 2af6aaa9b..970b1050e 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -308,7 +308,7 @@ void ObjMine_Air_InitChain(ObjMine* this, s32 linkCount) { airChain->drag = 0.95f + ((0.02000004f / (63.0f)) * linkCountF); // constant is close to 1/50 } - airChain->wobble = 0.0002f; + airChain->swayMax = 0.0002f; // Consecutive chain links are offset 90 degrees. for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { @@ -370,16 +370,16 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { s32 i; f32 wallCheckRadius = this->actor.home.rot.z * 5.0f; f32 linkY; - f32 wobbleVel; + f32 swayVel; waterChain->drag = 0.9f; - waterChain->wobble = 0.003f; + waterChain->swayMax = 0.003f; - waterChain->wobblePhaseVel = RANDU_BITS(13); + waterChain->swayPhaseVel = RANDU_BITS(13); waterChain->restoreXZ = -0.0002f; waterChain->restoreY = -0.0002f; - wobbleVel = waterChain->wobble * (LINK_SIZE / 2.0f); + swayVel = waterChain->swayMax * (LINK_SIZE / 2.0f); linkY = this->actor.home.pos.y; for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { @@ -390,9 +390,9 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { waterLink->pos.x = this->actor.home.pos.x; waterLink->pos.y = linkY; waterLink->pos.z = this->actor.home.pos.z; - waterLink->vel.x = (Rand_ZeroOne() - 0.5f) * wobbleVel; - waterLink->vel.y = (Rand_ZeroOne() - 0.5f) * wobbleVel; - waterLink->vel.z = (Rand_ZeroOne() - 0.5f) * wobbleVel; + waterLink->vel.x = (Rand_ZeroOne() - 0.5f) * swayVel; + waterLink->vel.y = (Rand_ZeroOne() - 0.5f) * swayVel; + waterLink->vel.z = (Rand_ZeroOne() - 0.5f) * swayVel; } waterChain->maxY = linkY; @@ -486,7 +486,7 @@ void ObjMine_Water_ApplyForces(ObjMine *this) { ObjMineWaterChain *waterChain = &this->chain.water; ObjMineWaterLink *waterLink; s32 i; - s16 wobblePhase; + s16 swayPhase; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); f32 inverseCount = 1.0f / (f32) linkCount; f32 restoreY = (waterChain->links[linkCount - 1].pos.y - waterChain->restY) * waterChain->restoreY; @@ -494,7 +494,7 @@ void ObjMine_Water_ApplyForces(ObjMine *this) { f32 scaledKnockback; // Applies the buoyant force and sway from the water. - for(i = 0, waterLink = waterChain->links, wobblePhase = 0; i < linkCount; i++, waterLink++, wobblePhase += waterChain->wobblePhaseVel) { + for(i = 0, waterLink = waterChain->links, swayPhase = 0; i < linkCount; i++, waterLink++, swayPhase += waterChain->swayPhaseVel) { Math_Vec3f_Copy(&sLastLinkAccel[i], &waterLink->accel); if (waterLink->pos.y <= this->actor.home.pos.y) { waterLink->accel.y = waterChain->restoreY * -96.0f; @@ -505,9 +505,9 @@ void ObjMine_Water_ApplyForces(ObjMine *this) { } waterLink->accel.x = (waterLink->pos.x - this->actor.home.pos.x) * waterChain->restoreXZ; waterLink->accel.z = (waterLink->pos.z - this->actor.home.pos.z) * waterChain->restoreXZ; - waterLink->accel.x += waterChain->wobbleXZ * Math_SinS(wobblePhase); - waterLink->accel.y += waterChain->wobbleY; - waterLink->accel.z += waterChain->wobbleXZ * Math_CosS(wobblePhase); + waterLink->accel.x += waterChain->swayXZ * Math_SinS(swayPhase); + waterLink->accel.y += waterChain->swayY; + waterLink->accel.z += waterChain->swayXZ * Math_CosS(swayPhase); } // Applies knockback force. Knockback on the links is scaled quadratically, possibly to account for link rotations being cumulative @@ -883,11 +883,11 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { // Applies chain sway, choosing a new sway randomly about every 32 frames if (RANDU_BITS(5) == 0) { - airChain->wobbleSize = Rand_ZeroOne() * airChain->wobble; - airChain->wobblePhase = RANDU_BITS(16); + airChain->swaySize = Rand_ZeroOne() * airChain->swayMax; + airChain->swayPhase = RANDU_BITS(16); } - xAccel = Math_SinS(airChain->wobblePhase) * airChain->wobbleSize; - zAccel = Math_CosS(airChain->wobblePhase) * airChain->wobbleSize; + xAccel = Math_SinS(airChain->swayPhase) * airChain->swaySize; + zAccel = Math_CosS(airChain->swayPhase) * airChain->swaySize; airChain->xVel += xAccel; airChain->zVel += zAccel; @@ -1014,14 +1014,14 @@ void ObjMine_Water_Chained(ObjMine* this, PlayState* play) { waterChain->drag = 0.9f; waterChain->restoreXZ = -0.0002f; waterChain->restoreY = -0.0002f; - waterChain->wobble = 0.003f; + waterChain->swayMax = 0.003f; if (RANDU_BITS(5) == 0) { s16 randAngle = RANDU_BITS(16); - waterChain->wobbleXZ = Math_SinS(randAngle) * 1.8f * waterChain->wobble; - waterChain->wobbleY = Math_CosS(randAngle) * 0.2f * waterChain->wobble; - waterChain->wobblePhaseVel = RANDU_BITS(13); + waterChain->swayXZ = Math_SinS(randAngle) * 1.8f * waterChain->swayMax; + waterChain->swayY = Math_CosS(randAngle) * 0.2f * waterChain->swayMax; + waterChain->swayPhaseVel = RANDU_BITS(13); } ObjMine_Water_UpdateChain(this, play); diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index 92176d36a..05a4e1a40 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -45,9 +45,9 @@ typedef struct { /* 0x44 */ f32 drag; /* 0x48 */ f32 knockback; /* 0x4C */ s16 knockbackAngle; - /* 0x50 */ f32 wobbleSize; - /* 0x54 */ s16 wobblePhase; - /* 0x58 */ f32 wobble; + /* 0x50 */ f32 swaySize; + /* 0x54 */ s16 swayPhase; + /* 0x58 */ f32 swayMax; /* 0x5C */ f32 wallCheckDist; /* 0x60 */ ObjMineAirLink links[OBJMINE_CHAIN_MAX]; } ObjMineAirChain; // size = 0x15C @@ -63,10 +63,10 @@ typedef struct { /* 0x00 */ f32 drag; /* 0x04 */ Vec3f knockbackDir; /* 0x10 */ f32 knockback; - /* 0x14 */ f32 wobbleXZ; - /* 0x18 */ f32 wobbleY; - /* 0x1C */ f32 wobble; - /* 0x20 */ s16 wobblePhaseVel; + /* 0x14 */ f32 swayXZ; + /* 0x18 */ f32 swayY; + /* 0x1C */ f32 swayMax; + /* 0x20 */ s16 swayPhaseVel; /* 0x24 */ f32 restoreXZ; /* 0x28 */ f32 maxY; /* 0x2C */ f32 restY; From 1789fe5a854fc00bba3234194885b767383ff8ff Mon Sep 17 00:00:00 2001 From: petrie911 Date: Thu, 13 Apr 2023 17:41:26 -0500 Subject: [PATCH 15/26] merge and such --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 970b1050e..d1c68f41b 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -140,7 +140,7 @@ s32 ObjMine_GetUnitVec3fNorm(Vec3f* src, Vec3f* dst, f32* norm, f32* invNorm) { void ObjMine_Path_SpawnBomb(ObjMine* this, PlayState* play) { EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, this->actor.world.pos.x, - this->actor.world.pos.y - BOMB_SPAWN_OFFSET, this->actor.world.pos.z, 0, 0, 0, ENBOM_0); + this->actor.world.pos.y - BOMB_SPAWN_OFFSET, this->actor.world.pos.z, 0, 0, 0, BOMB_TYPE_BODY); if (bomb != NULL) { bomb->timer = 0; @@ -151,7 +151,7 @@ void ObjMine_AirWater_SpawnBomb(ObjMine* this, PlayState* play) { f32 x = this->collider.elements[0].dim.worldSphere.center.x; f32 y = this->collider.elements[0].dim.worldSphere.center.y - BOMB_SPAWN_OFFSET; f32 z = this->collider.elements[0].dim.worldSphere.center.z; - EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, x, y, z, 0, 0, 0, ENBOM_0); + EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, x, y, z, 0, 0, 0, BOMB_TYPE_BODY); if (bomb != NULL) { bomb->timer = 0; @@ -193,7 +193,7 @@ void ObjMine_Air_CheckAC(ObjMine* this, s16* hitAngle, s16* torqueAngle) { Vec3s* hitPos3s = &this->collider.elements[0].info.bumper.hitPos; Math_Vec3s_ToVec3f(&hitPos, hitPos3s); - *hitAngle = Actor_YawBetweenActors(attackActor, &this->actor); + *hitAngle = Actor_WorldYawTowardActor(attackActor, &this->actor); *torqueAngle = Math_Vec3f_Yaw(&attackActor->world.pos, &hitPos) - yawToAttack; } } @@ -771,17 +771,17 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { target = this->pathSpeed; step = this->pathSpeed * 0.16f; } - Math_StepToF(&this->actor.speedXZ, target, step); + Math_StepToF(&this->actor.speed, target, step); // Checks if mine will reach the waypoint next frame - if ((this->actor.speedXZ + 0.05f) < distToWaypoint) { - // Scales thisx->velocity to be equal in magnitude to speedXZ - Math_Vec3f_Scale(&thisx->velocity, this->actor.speedXZ / distToWaypoint); + if ((this->actor.speed + 0.05f) < distToWaypoint) { + // Scales thisx->velocity to be equal in magnitude to speed + Math_Vec3f_Scale(&thisx->velocity, this->actor.speed / distToWaypoint); this->actor.world.pos.x += thisx->velocity.x; this->actor.world.pos.y += thisx->velocity.y; this->actor.world.pos.z += thisx->velocity.z; } else { - this->actor.speedXZ *= 0.4f; + this->actor.speed *= 0.4f; this->waypointIndex++; if (this->waypointIndex >= this->waypointCount) { this->waypointIndex = 0; @@ -798,7 +798,7 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { // Makes mines appear to roll while traversing the path Math3D_CrossProduct(&sStandardBasis.y, &thisx->velocity, &yhatCrossV); if (ObjMine_GetUnitVec3f(&yhatCrossV, &rotAxis)) { - Matrix_RotateAxisF(this->actor.speedXZ / PATH_RADIUS, &rotAxis, MTXMODE_NEW); + Matrix_RotateAxisF(this->actor.speed / PATH_RADIUS, &rotAxis, MTXMODE_NEW); Matrix_RotateYS(this->actor.shape.rot.y, MTXMODE_APPLY); Matrix_RotateXS(this->actor.shape.rot.x, MTXMODE_APPLY); Matrix_RotateZS(this->actor.shape.rot.z, MTXMODE_APPLY); From 279e3049e5524988a4a579a1ae543ebae0af5591 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Fri, 14 Apr 2023 08:48:19 -0500 Subject: [PATCH 16/26] format --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index d1c68f41b..f9ec833c5 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -138,9 +138,9 @@ s32 ObjMine_GetUnitVec3fNorm(Vec3f* src, Vec3f* dst, f32* norm, f32* invNorm) { } void ObjMine_Path_SpawnBomb(ObjMine* this, PlayState* play) { - EnBom* bomb = - (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, this->actor.world.pos.x, - this->actor.world.pos.y - BOMB_SPAWN_OFFSET, this->actor.world.pos.z, 0, 0, 0, BOMB_TYPE_BODY); + EnBom* bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, this->actor.world.pos.x, + this->actor.world.pos.y - BOMB_SPAWN_OFFSET, this->actor.world.pos.z, 0, 0, 0, + BOMB_TYPE_BODY); if (bomb != NULL) { bomb->timer = 0; From a635b540ee9096478af3786e9ca4617e7e19a766 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Fri, 14 Apr 2023 11:35:58 -0500 Subject: [PATCH 17/26] more format and cleanup --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 229 ++++++++++-------- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 21 +- 2 files changed, 132 insertions(+), 118 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index f9ec833c5..cc3ee9fd7 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -109,15 +109,15 @@ void ObjMine_Path_MoveToWaypoint(ObjMine* this, s32 index) { } s32 ObjMine_GetUnitVec3f(Vec3f* src, Vec3f* dst) { - f32 mag = Math3D_Vec3fMagnitude(src); + f32 magnitude = Math3D_Vec3fMagnitude(src); - if (mag < 0.001f) { + if (magnitude < 0.001f) { return false; } - dst->x = src->x * (1.0f / mag); - dst->y = src->y * (1.0f / mag); - dst->z = src->z * (1.0f / mag); + dst->x = src->x * (1.0f / magnitude); + dst->y = src->y * (1.0f / magnitude); + dst->z = src->z * (1.0f / magnitude); return true; } @@ -290,7 +290,7 @@ void ObjMine_UpdateCollider(ObjMine* this) { } void ObjMine_Air_InitChain(ObjMine* this, s32 linkCount) { - f32 linkCountF = linkCount; + f32 linkCountF = (f32)linkCount; ObjMineAirChain* airChain = &this->chain.air; ObjMineAirLink* airLink; s32 i; @@ -304,8 +304,8 @@ void ObjMine_Air_InitChain(ObjMine* this, s32 linkCount) { // Sets restoring force and drag. Longer chains have lower frequency and less drag. if (linkCount > 0) { - airChain->restore = -sqrtf((0.124992f / (63.0f)) / linkCountF); // constant is close to 1/8 - airChain->drag = 0.95f + ((0.02000004f / (63.0f)) * linkCountF); // constant is close to 1/50 + airChain->restore = -sqrtf((0.124992f / OBJMINE_CHAIN_MAX) / linkCountF); // constant is close to 1/8 + airChain->drag = 0.95f + ((0.02000004f / OBJMINE_CHAIN_MAX) * linkCountF); // constant is close to 1/50 } airChain->swayMax = 0.0002f; @@ -316,15 +316,15 @@ void ObjMine_Air_InitChain(ObjMine* this, s32 linkCount) { } if (wallCheckRadius < 0.0f) { - airChain->wallCheckDist = -1.0f; + airChain->wallCheckDistSq = -1.0f; } else if (wallCheckRadius <= AIR_RADIUS + 1.0f) { - airChain->wallCheckDist = 0.0f; + airChain->wallCheckDistSq = 0.0f; } else { - airChain->wallCheckDist = SQ(wallCheckRadius - AIR_RADIUS); + airChain->wallCheckDistSq = SQ(wallCheckRadius - AIR_RADIUS); } } -void ObjMine_Air_SetCollider(ObjMine* this, s32 linkCount) { +void ObjMine_Air_InitCollider(ObjMine* this, s32 linkCount) { Matrix_Translate(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, MTXMODE_NEW); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); @@ -334,13 +334,15 @@ void ObjMine_Air_SetBasis(ObjMine* this) { ObjMineAirChain* airChain = &this->chain.air; Vec3f tempVec; - tempVec.x = -airChain->xDiff; + tempVec.x = -airChain->displacement.x; tempVec.y = 1.0f; - tempVec.z = -airChain->zDiff; + tempVec.z = -airChain->displacement.z; ObjMine_GetUnitVec3f(&tempVec, &airChain->basis.y); + Math3D_CrossProduct(&sStandardBasis.x, &airChain->basis.y, &tempVec); ObjMine_GetUnitVec3f(&tempVec, &airChain->basis.z); + Math3D_CrossProduct(&airChain->basis.y, &airChain->basis.z, &tempVec); ObjMine_GetUnitVec3f(&tempVec, &airChain->basis.x); } @@ -360,8 +362,8 @@ void ObjMine_Air_SetChainXZ(ObjMine* this) { f32 dx = this->actor.world.pos.x - this->actor.home.pos.x; f32 dz = this->actor.world.pos.z - this->actor.home.pos.z; - this->chain.air.xDiff = dx * invLength; - this->chain.air.zDiff = dz * invLength; + this->chain.air.displacement.x = dx * invLength; + this->chain.air.displacement.z = dz * invLength; } void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { @@ -390,9 +392,9 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { waterLink->pos.x = this->actor.home.pos.x; waterLink->pos.y = linkY; waterLink->pos.z = this->actor.home.pos.z; - waterLink->vel.x = (Rand_ZeroOne() - 0.5f) * swayVel; - waterLink->vel.y = (Rand_ZeroOne() - 0.5f) * swayVel; - waterLink->vel.z = (Rand_ZeroOne() - 0.5f) * swayVel; + waterLink->velocity.x = (Rand_ZeroOne() - 0.5f) * swayVel; + waterLink->velocity.y = (Rand_ZeroOne() - 0.5f) * swayVel; + waterLink->velocity.z = (Rand_ZeroOne() - 0.5f) * swayVel; } waterChain->maxY = linkY; @@ -404,11 +406,11 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { } if (wallCheckRadius < 0.0f) { - waterChain->wallCheckDist = -1.0f; + waterChain->wallCheckDistSq = -1.0f; } else if (wallCheckRadius <= WATER_RADIUS + 1.0f) { - waterChain->wallCheckDist = 0.0f; + waterChain->wallCheckDistSq = 0.0f; } else { - waterChain->wallCheckDist = SQ(wallCheckRadius - WATER_RADIUS); + waterChain->wallCheckDistSq = SQ(wallCheckRadius - WATER_RADIUS); } } @@ -420,9 +422,9 @@ void ObjMine_Water_InitCollider(ObjMine* this, s32 linkCount) { } void ObjMine_Water_SetWorld(ObjMine* this) { - s32 pad; - s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); + s32 pad; // Could be recast to thisx as in ObjMine_Path_Move ObjMineWaterChain* waterChain = &this->chain.water; + s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); if (linkCount == 0) { this->actor.world.pos.y = this->actor.home.pos.y + LINK_SIZE + ATTACH_OFFSET; @@ -436,14 +438,14 @@ void ObjMine_Water_SetWorld(ObjMine* this) { } void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { - s32 pad; + s32 pad; // Could be recast to thisx as in ObjMine_Path_Move ObjMineWaterChain* waterChain = &this->chain.water; waterChain->touchWall = false; - if (waterChain->wallCheckDist > -1e-6f) { + if (waterChain->wallCheckDistSq > -1e-6f) { // Checks for walls if mine is sufficiently far from home. - if (waterChain->wallCheckDist <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, - this->actor.world.pos.x, this->actor.world.pos.z)) { + if (waterChain->wallCheckDistSq <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, + this->actor.world.pos.x, this->actor.world.pos.z)) { Vec3f centerPos; Vec3f offsetPos; Vec3f dummyResult; @@ -471,30 +473,33 @@ void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { if (BgCheck_EntityLineTest1(&play->colCtx, ¢erPos, &offsetPos, &dummyResult, &dummyPoly, true, false, false, true, &dummyBgId)) { waterChain->touchWall = true; - waterChain->wallEjectX = xzDirFromHome.x * -0.2f; - waterChain->wallEjectZ = xzDirFromHome.z * -0.2f; + waterChain->wallEject.x = xzDirFromHome.x * -0.2f; + waterChain->wallEject.z = xzDirFromHome.z * -0.2f; } } } } } -#if 0 -// Probably equivalent, but nightmare loop unrolls. -void ObjMine_Water_ApplyForces(ObjMine *this) { - static Vec3f sLastLinkAccel[0x40]; - ObjMineWaterChain *waterChain = &this->chain.water; - ObjMineWaterLink *waterLink; +#ifdef NON_MATCHING +// Probably equivalent, but nightmare loop unrolls. The tension section also has weird comparisons. It should be +// equivalent to what's written, but it seems the actual code comparisons were implemented differently. ASM suggests +// multiple index variables were used at once. +void ObjMine_Water_ApplyForces(ObjMine* this) { + static Vec3f sLastLinkAccel[OBJMINE_CHAIN_MAX + 1]; + ObjMineWaterChain* waterChain = &this->chain.water; + ObjMineWaterLink* waterLink; s32 i; s16 swayPhase; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - f32 inverseCount = 1.0f / (f32) linkCount; + f32 inverseCount = 1.0f / (f32)linkCount; f32 restoreY = (waterChain->links[linkCount - 1].pos.y - waterChain->restY) * waterChain->restoreY; Vec3f tension; f32 scaledKnockback; // Applies the buoyant force and sway from the water. - for(i = 0, waterLink = waterChain->links, swayPhase = 0; i < linkCount; i++, waterLink++, swayPhase += waterChain->swayPhaseVel) { + for (i = 0, waterLink = waterChain->links, swayPhase = 0; i < linkCount; + i++, waterLink++, swayPhase += waterChain->swayPhaseVel) { Math_Vec3f_Copy(&sLastLinkAccel[i], &waterLink->accel); if (waterLink->pos.y <= this->actor.home.pos.y) { waterLink->accel.y = waterChain->restoreY * -96.0f; @@ -510,49 +515,51 @@ void ObjMine_Water_ApplyForces(ObjMine *this) { waterLink->accel.z += waterChain->swayXZ * Math_CosS(swayPhase); } - // Applies knockback force. Knockback on the links is scaled quadratically, possibly to account for link rotations being cumulative + // Applies knockback force. Knockback on the links is scaled quadratically, possibly to account for link rotations + // being cumulative if (waterChain->knockback > 0.0001f) { - for(i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { + for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { scaledKnockback = SQ((linkCount - i) * inverseCount); - + waterLink->accel.x += waterChain->knockbackDir.x * scaledKnockback; waterLink->accel.y += waterChain->knockbackDir.y * scaledKnockback; waterLink->accel.z += waterChain->knockbackDir.z * scaledKnockback; } } - // Links that intersect walls are ejected from them. + // Moves chain away from wall if mine is intersecting one if (waterChain->touchWall) { - for(i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { - waterLink->accel.x += waterChain->wallEjectX; - waterLink->accel.z += waterChain->wallEjectZ; + for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { + waterLink->accel.x += waterChain->wallEject.x; + waterLink->accel.z += waterChain->wallEject.z; } } - // Forces on the links from other links. This is simulated by a triangle filter on the forces from the previous frame. - for(i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { + // Forces on the links from other links. This is simulated by a triangle filter on the forces from the previous + // frame. + for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { Math_Vec3f_Copy(&tension, &gZeroVec3f); - if(i - 2 >= 0) { + if (i - 2 >= 0) { tension.x += sLastLinkAccel[i - 2].x * 0.075f; tension.y += sLastLinkAccel[i - 2].y * 0.075f; tension.z += sLastLinkAccel[i - 2].z * 0.075f; } - if(i - 1 >= 0) { + if (i - 1 >= 0) { tension.x += sLastLinkAccel[i - 1].x * 0.15f; tension.y += sLastLinkAccel[i - 1].y * 0.15f; tension.z += sLastLinkAccel[i - 1].z * 0.15f; } - tension.x += sLastLinkAccel[i].x * 0.3f; - tension.y += sLastLinkAccel[i].y * 0.3f; - tension.z += sLastLinkAccel[i].z * 0.3f; + tension.x += sLastLinkAccel[i].x * 0.3f; + tension.y += sLastLinkAccel[i].y * 0.3f; + tension.z += sLastLinkAccel[i].z * 0.3f; - if(i + 1 < linkCount) { + if (i + 1 < linkCount) { tension.x += sLastLinkAccel[i + 1].x * 0.15f; tension.y += sLastLinkAccel[i + 1].y * 0.15f; tension.z += sLastLinkAccel[i + 1].z * 0.15f; } - if(i + 2 < linkCount) { + if (i + 2 < linkCount) { tension.x += sLastLinkAccel[i + 2].x * 0.075f; tension.y += sLastLinkAccel[i + 2].y * 0.075f; tension.z += sLastLinkAccel[i + 2].z * 0.075f; @@ -561,7 +568,6 @@ void ObjMine_Water_ApplyForces(ObjMine *this) { waterLink->accel.y += tension.y; waterLink->accel.z += tension.z; } - } #else Vec3f D_80A849D0[0x40]; @@ -570,13 +576,13 @@ void ObjMine_Water_ApplyForces(ObjMine* this); #endif void ObjMine_Water_UpdateLinks(ObjMine* this) { - s32 pad; + s32 pad; // Could be recast to thisx as in ObjMine_Path_Move ObjMineMtxF3 newBasis; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); ObjMineWaterChain* waterChain = &this->chain.water; ObjMineWaterLink* waterLink; s32 i; - Vec3f* jointBasisX; + Vec3f* prevBasisX; Vec3f tempVec; Vec3f diffDir; Vec3f unusedLinkPos; @@ -592,23 +598,24 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { jointPos.y = this->actor.home.pos.y + (LINK_SIZE / 2.0f); jointPos.z = this->actor.home.pos.z; - for (i = 0, jointBasisX = NULL, waterLink = waterChain->links; i < linkCount; - i++, jointBasisX = &waterLink->basis.x, waterLink++) { + for (i = 0, prevBasisX = NULL, waterLink = waterChain->links; i < linkCount; + i++, prevBasisX = &waterLink->basis.x, waterLink++) { changeBasis = false; - waterLink->vel.x += waterLink->accel.x; - waterLink->vel.y += waterLink->accel.y; - waterLink->vel.z += waterLink->accel.z; + waterLink->velocity.x += waterLink->accel.x; + waterLink->velocity.y += waterLink->accel.y; + waterLink->velocity.z += waterLink->accel.z; - Math_Vec3f_Scale(&waterLink->vel, waterChain->drag); + Math_Vec3f_Scale(&waterLink->velocity, waterChain->drag); Math_Vec3f_Copy(&unusedLinkPos, &waterLink->pos); - waterLink->pos.x += waterLink->vel.x; - waterLink->pos.y += waterLink->vel.y; - waterLink->pos.z += waterLink->vel.z; + waterLink->pos.x += waterLink->velocity.x; + waterLink->pos.y += waterLink->velocity.y; + waterLink->pos.z += waterLink->velocity.z; - if ((waterLink->pos.y <= this->actor.home.pos.y) && (waterLink->vel.y < 0.0f)) { - waterLink->vel.y *= 0.1f; + // Heavily reduce velocity if link is below home and moving downward. + if ((waterLink->pos.y <= this->actor.home.pos.y) && (waterLink->velocity.y < 0.0f)) { + waterLink->velocity.y *= 0.1f; } // If the calculated position is less than 1/3 of the link's length from the joint, the chain is considered @@ -619,10 +626,12 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { if (ObjMine_GetUnitVec3fNorm(&tempVec, &diffDir, &diffNorm, &dummyInvNorm) && (diffNorm > LINK_SIZE / 3.0f)) { Math_Vec3f_Copy(&newBasis.y, &waterLink->basis.y); ObjMine_StepUntilParallel(&newBasis.y, &diffDir, M_PI / 30); - tempBasisX = (jointBasisX == NULL) ? &sStandardBasis.x : jointBasisX; + + tempBasisX = (prevBasisX == NULL) ? &sStandardBasis.x : prevBasisX; Math3D_CrossProduct(tempBasisX, &newBasis.y, &tempVec); + // Skips change of basis if any of the basis vectors would be zero. if (ObjMine_GetUnitVec3f(&tempVec, &newBasis.z)) { Math3D_CrossProduct(&newBasis.y, &newBasis.z, &tempVec); if (ObjMine_GetUnitVec3f(&tempVec, &newBasis.x)) { @@ -639,6 +648,8 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { diffNorm = LINK_SIZE / 3.0f; } + // Sets new link position from calculated rotation basis. The check ensures displacement from the previous link + // doesn't cause the links to separate if (diffNorm >= (LINK_SIZE / 2.0f)) { waterLink->pos.x = jointPos.x + (waterLink->basis.y.x * (LINK_SIZE / 2.0f)); waterLink->pos.y = jointPos.y + (waterLink->basis.y.y * (LINK_SIZE / 2.0f)); @@ -649,6 +660,7 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { waterLink->pos.z = jointPos.z + (waterLink->basis.y.z * diffNorm); } + // Calculate the position of the joint with the next link. jointPos.x = waterLink->pos.x + (waterLink->basis.y.x * (LINK_SIZE / 2.0f)); jointPos.y = waterLink->pos.y + (waterLink->basis.y.y * (LINK_SIZE / 2.0f)); jointPos.z = waterLink->pos.z + (waterLink->basis.y.z * (LINK_SIZE / 2.0f)); @@ -662,7 +674,7 @@ void ObjMine_Water_UpdateChain(ObjMine* this, PlayState* play) { } void ObjMine_Init(Actor* thisx, PlayState* play) { - s32 pad; + s32 pad; // Can be playstate recast. Must be gamestate recast. ObjMine* this = THIS; s32 pathIndex = OBJMINE_GET_PATH(&this->actor); Path* path; @@ -712,7 +724,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { this->actor.draw = ObjMine_Air_Draw; ObjMine_Air_InitChain(this, linkCount); this->actor.world.pos.y = -ATTACH_OFFSET - (linkCount * LINK_SIZE) + this->actor.home.pos.y; - ObjMine_Air_SetCollider(this, linkCount); + ObjMine_Air_InitCollider(this, linkCount); func_800B4AEC(play, &this->actor, 0.0f); if (linkCount == 0) { ObjMine_Air_SetupStationary(this); @@ -735,6 +747,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { void ObjMine_Destroy(Actor* thisx, PlayState* play) { ObjMine* this = THIS; + // PlayState* play = play2; // must be in this order to match with recast Collider_DestroyJntSph(play, &this->collider); } @@ -747,7 +760,7 @@ void ObjMine_Path_Stationary(ObjMine* this, PlayState* play) { } void ObjMine_Path_SetupMove(ObjMine* this) { - this->actor.flags |= ACTOR_FLAG_10; // @bug? Sets flag 10, but later checks flag 40. + this->actor.flags |= ACTOR_FLAG_10; this->actionFunc = ObjMine_Path_Move; } @@ -757,8 +770,9 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { f32 distToWaypoint; f32 step; f32 target; - s32 dummyBgVec; + s32 dummyBgId; + // thisx->velocity is temporarily set to the vector difference to the next waypoint. Math_Vec3s_ToVec3f(&nextWaypoint, &this->waypoints[this->waypointIndex + 1]); Math_Vec3f_Diff(&nextWaypoint, &thisx->world.pos, &thisx->velocity); distToWaypoint = Math3D_Vec3fMagnitude(&thisx->velocity); @@ -775,7 +789,7 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { // Checks if mine will reach the waypoint next frame if ((this->actor.speed + 0.05f) < distToWaypoint) { - // Scales thisx->velocity to be equal in magnitude to speed + // Rescales thisx->velocity to be equal in magnitude to speed Math_Vec3f_Scale(&thisx->velocity, this->actor.speed / distToWaypoint); this->actor.world.pos.x += thisx->velocity.x; this->actor.world.pos.y += thisx->velocity.y; @@ -788,8 +802,8 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { } ObjMine_Path_MoveToWaypoint(this, this->waypointIndex); } - this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &dummyBgVec, - &this->actor, &thisx->world.pos); + this->actor.floorHeight = + BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &dummyBgId, &this->actor, &thisx->world.pos); if (this->actor.flags & ACTOR_FLAG_40) { Vec3f rotAxis; Vec3f yhatCrossV; @@ -833,14 +847,14 @@ void ObjMine_Air_SetupChained(ObjMine* this) { } void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { - s32 pad; + s32 pad; // Could be recast to thisx as in ObjMine_Path_Move s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); ObjMineAirChain* airChain = &this->chain.air; ObjMineAirLink* airLink; s32 i; f32 xAccel; f32 zAccel; - f32 torque; + f32 spin; s16 twistDiff; Math_Vec3f_Copy(&airChain->translation, &airChain->basis.y); @@ -876,8 +890,8 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { if (airChain->knockback > 0.0001f) { xAccel = Math_SinS(airChain->knockbackAngle) * airChain->knockback; zAccel = Math_CosS(airChain->knockbackAngle) * airChain->knockback; - airChain->xVel += xAccel; - airChain->zVel += zAccel; + airChain->velocity.x += xAccel; + airChain->velocity.z += zAccel; Math_StepToF(&airChain->knockback, 0.0f, AIR_KNOCKBACK * 0.5f); } @@ -888,32 +902,32 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { } xAccel = Math_SinS(airChain->swayPhase) * airChain->swaySize; zAccel = Math_CosS(airChain->swayPhase) * airChain->swaySize; - airChain->xVel += xAccel; - airChain->zVel += zAccel; + airChain->velocity.x += xAccel; + airChain->velocity.z += zAccel; // Applies the restoring force of gravity and chain tension using small-angle approximation - airChain->xVel += airChain->xDiff * airChain->restore; - airChain->zVel += airChain->zDiff * airChain->restore; + airChain->velocity.x += airChain->displacement.x * airChain->restore; + airChain->velocity.z += airChain->displacement.z * airChain->restore; // Applies linear drag - airChain->xVel *= airChain->drag; - airChain->zVel *= airChain->drag; + airChain->velocity.x *= airChain->drag; + airChain->velocity.z *= airChain->drag; // Updates scaled position and does a safety clamp to 5.0f. - airChain->xDiff += airChain->xVel; - airChain->zDiff += airChain->zVel; + airChain->displacement.x += airChain->velocity.x; + airChain->displacement.z += airChain->velocity.z; - airChain->xDiff = CLAMP(airChain->xDiff, -5.0f, 5.0f); - airChain->zDiff = CLAMP(airChain->zDiff, -5.0f, 5.0f); + airChain->displacement.x = CLAMP(airChain->displacement.x, -5.0f, 5.0f); + airChain->displacement.z = CLAMP(airChain->displacement.z, -5.0f, 5.0f); ObjMine_Air_SetBasis(this); ObjMine_Air_SetWorld(this); // Checks for wall collisions if sufficiently far from home. If collision detected, bounce off the wall at half // speed. If speed is close to zero when hitting wall, weakly eject it instead. - if (airChain->wallCheckDist > -1e-6f) { - if (airChain->wallCheckDist <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, - this->actor.home.pos.x, this->actor.home.pos.z)) { + if (airChain->wallCheckDistSq > -1e-6f) { + if (airChain->wallCheckDistSq <= Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, + this->actor.home.pos.x, this->actor.home.pos.z)) { Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, AIR_RADIUS, 0.0f, 1); @@ -925,9 +939,9 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { f32 xzSpeed; f32 dummyInvNorm; - xzVel.x = airChain->xVel; + xzVel.x = airChain->velocity.x; xzVel.y = 0.0f; - xzVel.z = airChain->zVel; + xzVel.z = airChain->velocity.z; if (ObjMine_GetUnitVec3fNorm(&xzVel, &xzDir, &xzSpeed, &dummyInvNorm)) { wallNormal.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); @@ -937,11 +951,11 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { func_80179F64(&xzDir, &wallNormal, &reflectedDir); xzSpeed /= 2.0f; - airChain->xVel = reflectedDir.x * xzSpeed; - airChain->zVel = reflectedDir.z * xzSpeed; + airChain->velocity.x = reflectedDir.x * xzSpeed; + airChain->velocity.z = reflectedDir.z * xzSpeed; } else { - airChain->xVel *= -0.1f; - airChain->zVel *= -0.1f; + airChain->velocity.x *= -0.1f; + airChain->velocity.z *= -0.1f; } ObjMine_Air_SetChainXZ(this); ObjMine_Air_SetBasis(this); @@ -954,9 +968,9 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { // random torque for variance, and a linear drag. for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { twistDiff = airLink->twist - 0x4000; - torque = airLink->spin + (twistDiff * -0.05f) + RAND_PLUSMINUS(15.0f); - torque *= 0.995f; - airLink->spin = torque; + spin = airLink->spin + (twistDiff * -0.05f) + (30.0f * Rand_ZeroOne() - 15.0f); + spin *= 0.995f; + airLink->spin = spin; airLink->twist += airLink->spin; } @@ -1016,6 +1030,7 @@ void ObjMine_Water_Chained(ObjMine* this, PlayState* play) { waterChain->restoreY = -0.0002f; waterChain->swayMax = 0.003f; + // Chooses a new sway randomly about every 32 frames. if (RANDU_BITS(5) == 0) { s16 randAngle = RANDU_BITS(16); @@ -1049,7 +1064,7 @@ void ObjMine_Water_Stationary(ObjMine* this, PlayState* play) { } void ObjMine_Path_Update(Actor* thisx, PlayState* play) { - s32 pad; + s32 pad; // Can be playstate recast. ObjMine* this = THIS; if ((this->collider.base.ocFlags2 & OC2_HIT_PLAYER) || (this->collider.base.acFlags & AC_HIT)) { @@ -1077,7 +1092,7 @@ void ObjMine_AirWater_Update(Actor* thisx, PlayState* play) { } void ObjMine_Path_Draw(Actor* thisx, PlayState* play) { - s32 pad; + s32 pad; // Can be playstate recast ObjMine* this = THIS; OPEN_DISPS(play->state.gfxCtx); @@ -1099,7 +1114,7 @@ void ObjMine_Path_Draw(Actor* thisx, PlayState* play) { } void ObjMine_DrawExplosion(Actor* thisx, PlayState* play) { - s32 pad; // This could be thisx recast or playstate recast. + s32 pad; // This could be thisx recast or playstate recast. Not enough room on stack for both. OPEN_DISPS(play->state.gfxCtx); @@ -1115,7 +1130,7 @@ void ObjMine_DrawExplosion(Actor* thisx, PlayState* play) { } void ObjMine_Air_Draw(Actor* thisx, PlayState* play) { - s32 pad; + s32 pad; // Can be playstate recast ObjMine* this = THIS; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); ObjMineAirChain* airChain = &this->chain.air; @@ -1172,7 +1187,7 @@ void ObjMine_Air_Draw(Actor* thisx, PlayState* play) { } void ObjMine_Water_Draw(Actor* thisx, PlayState* play) { - s32 pad; + s32 pad; // Can be playstate recast ObjMine* this = THIS; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); ObjMineWaterChain* waterChain = &this->chain.water; diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index 05a4e1a40..5338602e2 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -12,8 +12,10 @@ typedef void (*ObjMineActionFunc)(struct ObjMine*, PlayState*); #define OBJMINE_GET_PATH_SPEED(thisx) (((thisx)->params >> 8) & 7) #define OBJMINE_GET_TYPE(thisx) (((thisx)->params >> 12) & 3) -#define OBJMINE_SET_PARAM0(pathIndex, pathSpeed, type) ((pathIndex) | ((pathSpeed) << 8)) -#define OBJMINE_SET_PARAM12(linkCount, type) ((linkCount) | ((type) << 0xC)) +#define OBJMINE_SET_PARAM(type, linkCount, pathIndex, pathSpeed) (((type) << 0xC) | ((type == OBJMINE_TYPE_PATH) ? ((pathIndex) | ((pathSpeed) << 8)) : (linkCount))) +#define OBJMINE_PATH_SET_PARAM(pathIndex, pathSpeed) OBJMINE_SET_PARAM(OBJMINE_TYPE_PATH, 0, pathIndex, pathSpeed) +#define OBJMINE_AIR_SET_PARAM(linkCount) OBJMINE_SET_PARAM(OBJMINE_TYPE_AIR, linkCount, 0, 0) +#define OBJMINE_WATER_SET_PARAM(linkCount) OBJMINE_SET_PARAM(OBJMINE_TYPE_WATER, linkCount, 0, 0) #define OBJMINE_CHAIN_MAX 63 @@ -37,10 +39,8 @@ typedef struct { typedef struct { /* 0x00 */ ObjMineMtxF3 basis; /* 0x24 */ Vec3f translation; // unused - /* 0x30 */ f32 xDiff; - /* 0x34 */ f32 zDiff; - /* 0x38 */ f32 xVel; - /* 0x3C */ f32 zVel; + /* 0x30 */ Vec2f displacement; + /* 0x38 */ Vec2f velocity; /* 0x40 */ f32 restore; /* 0x44 */ f32 drag; /* 0x48 */ f32 knockback; @@ -48,14 +48,14 @@ typedef struct { /* 0x50 */ f32 swaySize; /* 0x54 */ s16 swayPhase; /* 0x58 */ f32 swayMax; - /* 0x5C */ f32 wallCheckDist; + /* 0x5C */ f32 wallCheckDistSq; /* 0x60 */ ObjMineAirLink links[OBJMINE_CHAIN_MAX]; } ObjMineAirChain; // size = 0x15C typedef struct { /* 0x00 */ ObjMineMtxF3 basis; /* 0x24 */ Vec3f pos; - /* 0x30 */ Vec3f vel; + /* 0x30 */ Vec3f velocity; /* 0x3C */ Vec3f accel; } ObjMineWaterLink; // size = 0x48 @@ -71,9 +71,8 @@ typedef struct { /* 0x28 */ f32 maxY; /* 0x2C */ f32 restY; /* 0x30 */ f32 restoreY; - /* 0x34 */ f32 wallCheckDist; - /* 0x38 */ f32 wallEjectX; - /* 0x3C */ f32 wallEjectZ; + /* 0x34 */ f32 wallCheckDistSq; + /* 0x38 */ Vec2f wallEject; /* 0x40 */ s8 touchWall; /* 0x44 */ ObjMineWaterLink links[OBJMINE_CHAIN_MAX]; } ObjMineWaterChain; // size = 0x11FC From e74f9e07829e92d25ae213555dd1ff2623cd4354 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Fri, 14 Apr 2023 11:39:02 -0500 Subject: [PATCH 18/26] asm stuff --- tools/disasm/functions.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index ac3f30ada..2f0a5158d 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -11171,9 +11171,9 @@ 0x80A81B7C:("ObjMine_Water_InitChain",), 0x80A81D70:("ObjMine_Water_SetCollider",), 0x80A81DEC:("ObjMine_Water_SetWorld",), - 0x80A81E7C:("func_80A81E7C",), + 0x80A81E7C:("ObjMine_Water_WallCheck",), 0x80A81FFC:("ObjMine_Water_ApplyForces",), - 0x80A828A8:("func_80A828A8",), + 0x80A828A8:("ObjMine_Water_UpdateLinks",), 0x80A82C28:("ObjMine_Water_UpdateChain",), 0x80A82C5C:("ObjMine_Init",), 0x80A82F58:("ObjMine_Destroy",), From 5d9d496f0297aa3ed9cb1429a54a8bcade4b5a11 Mon Sep 17 00:00:00 2001 From: petrie911 <69443847+petrie911@users.noreply.github.com> Date: Fri, 14 Apr 2023 12:50:31 -0500 Subject: [PATCH 19/26] Update src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c Co-authored-by: Anghelo Carvajal --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index cc3ee9fd7..24c8bbd9c 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -163,7 +163,7 @@ s32 ObjMine_AirWater_CheckOC(ObjMine* this) { return true; } - if ((this->collider.base.ocFlags1 & OC1_HIT)) { + if (this->collider.base.ocFlags1 & OC1_HIT) { Actor* hitActor = this->collider.base.oc; if ((hitActor->id == ACTOR_OBJ_MINE) && (hitActor->room == this->actor.room)) { From 9e3cd5054475bfb88e9e29387eb3725266cd1dc3 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Fri, 14 Apr 2023 14:14:57 -0500 Subject: [PATCH 20/26] now with decomp.me --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 8 +++++--- tools/disasm/variables.txt | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index cc3ee9fd7..228f44527 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -6,7 +6,7 @@ #include "z_obj_mine.h" #include "overlays/actors/ovl_En_Bom/z_en_bom.h" -#include "assets/objects/object_ny/object_ny.h" +#include "objects/object_ny/object_ny.h" #define FLAGS 0x00000000 @@ -482,9 +482,11 @@ void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { } #ifdef NON_MATCHING +// https://decomp.me/scratch/BW51G // Probably equivalent, but nightmare loop unrolls. The tension section also has weird comparisons. It should be // equivalent to what's written, but it seems the actual code comparisons were implemented differently. ASM suggests // multiple index variables were used at once. + void ObjMine_Water_ApplyForces(ObjMine* this) { static Vec3f sLastLinkAccel[OBJMINE_CHAIN_MAX + 1]; ObjMineWaterChain* waterChain = &this->chain.water; @@ -492,7 +494,7 @@ void ObjMine_Water_ApplyForces(ObjMine* this) { s32 i; s16 swayPhase; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); - f32 inverseCount = 1.0f / (f32)linkCount; + f32 inverseCount = 1.0f / linkCount; f32 restoreY = (waterChain->links[linkCount - 1].pos.y - waterChain->restY) * waterChain->restoreY; Vec3f tension; f32 scaledKnockback; @@ -570,7 +572,7 @@ void ObjMine_Water_ApplyForces(ObjMine* this) { } } #else -Vec3f D_80A849D0[0x40]; +Vec3f sLastLinkAccel[OBJMINE_CHAIN_MAX + 1]; void ObjMine_Water_ApplyForces(ObjMine* this); #pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Water_ApplyForces.s") #endif diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index 0b44baae3..c8d56bead 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -12311,7 +12311,7 @@ 0x80A84698:("D_80A84698","f32","",0x4), 0x80A8469C:("D_80A8469C","f32","",0x4), 0x80A846A0:("D_80A846A0","f32","",0x4), - 0x80A849D0:("D_80A849D0","UNK_TYPE4","",0x4), + 0x80A849D0:("sLastLinkAccel","Vec3f[]","",0x4), 0x80A85460:("Obj_Purify_InitVars","UNK_TYPE1","",0x1), 0x80A85480:("ObjPurifyInfoList","UNK_TYPE1","",0x1), 0x80A854A0:("D_80A854A0","UNK_TYPE1","",0x1), From b2b18bed98ddb3f1b0e18c760de4d922b3b618a9 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Fri, 14 Apr 2023 15:07:39 -0500 Subject: [PATCH 21/26] removed some extraneous macros I didn't end up using --- include/macros.h | 1 - src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 3 --- 2 files changed, 4 deletions(-) diff --git a/include/macros.h b/include/macros.h index 0f372fcc0..5b1a31112 100644 --- a/include/macros.h +++ b/include/macros.h @@ -132,7 +132,6 @@ extern GraphicsContext* __gfxCtx; (void)0 #define SQ(x) ((x) * (x)) -#define CUBE(x) ((x) * (x) * (x)) #define ABS(x) ((x) >= 0 ? (x) : -(x)) #define ABS_ALT(x) ((x) < 0 ? -(x) : (x)) #define DECR(x) ((x) == 0 ? 0 : --(x)) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index f05ccdff0..b63b9dc31 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -21,9 +21,6 @@ #define WATER_KNOCKBACK 7.0f #define AIR_KNOCKBACK 0.04f -#define RAND_PLUSMINUS(limit) (Rand_ZeroOne() * (2.0f * (limit)) - (limit)) -#define RAND_PLUSMINUSALT(limit) ((Rand_ZeroOne() - 0.5f) * (2.0f * limit)) - void ObjMine_Init(Actor* thisx, PlayState* play); void ObjMine_Destroy(Actor* thisx, PlayState* play); void ObjMine_Path_Update(Actor* thisx, PlayState* play); From 3ff090636befbb72f6804848eee9540e149ba700 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Wed, 19 Apr 2023 09:29:43 -0500 Subject: [PATCH 22/26] fixes and formats --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 94 ++++++++++--------- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h | 12 +-- 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index b63b9dc31..75cb23af7 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -199,7 +199,7 @@ void ObjMine_Water_CheckAC(ObjMine* this, Vec3f* knockbackDir) { Actor* attackActor = this->collider.base.ac; // dmgFlag check is (DMG_DEKU_BUBBLE | DMG_LIGHT_ARROW | DMG_ICE_ARROW | DMG_FIRE_ARROW | DMG_NORMAL_ARROW) - if ((this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820)) { + if (this->collider.elements[0].info.acHitInfo->toucher.dmgFlags & 0x13820) { Matrix_Push(); Matrix_RotateYS(attackActor->shape.rot.y, MTXMODE_NEW); Matrix_RotateXS(attackActor->shape.rot.x, MTXMODE_APPLY); @@ -225,33 +225,33 @@ void ObjMine_AirWater_Noop(ObjMine* this) { void ObjMine_ReplaceTranslation(Vec3f* translation) { MtxF* matrix = Matrix_GetCurrent(); - matrix->mf[3][0] = translation->x; - matrix->mf[3][1] = translation->y; - matrix->mf[3][2] = translation->z; + matrix->xw = translation->x; + matrix->yw = translation->y; + matrix->zw = translation->z; } -void ObjMine_ReplaceRotation(ObjMineMtxF3* basis) { +void ObjMine_SetRotation(ObjMineMtxF3* basis) { MtxF* matrix = Matrix_GetCurrent(); - matrix->mf[0][0] = basis->x.x; - matrix->mf[0][1] = basis->x.y; - matrix->mf[0][2] = basis->x.z; - matrix->mf[0][3] = 0.0f; + matrix->xx = basis->x.x; + matrix->yx = basis->x.y; + matrix->zx = basis->x.z; + matrix->wx = 0.0f; - matrix->mf[1][0] = basis->y.x; - matrix->mf[1][1] = basis->y.y; - matrix->mf[1][2] = basis->y.z; - matrix->mf[1][3] = 0.0f; + matrix->xy = basis->y.x; + matrix->yy = basis->y.y; + matrix->zy = basis->y.z; + matrix->wy = 0.0f; - matrix->mf[2][0] = basis->z.x; - matrix->mf[2][1] = basis->z.y; - matrix->mf[2][2] = basis->z.z; - matrix->mf[2][3] = 0.0f; + matrix->xz = basis->z.x; + matrix->yz = basis->z.y; + matrix->zz = basis->z.z; + matrix->wz = 0.0f; - matrix->mf[3][0] = 0.0f; - matrix->mf[3][1] = 0.0f; - matrix->mf[3][2] = 0.0f; - matrix->mf[3][3] = 1.0f; + matrix->xw = 0.0f; + matrix->yw = 0.0f; + matrix->zw = 0.0f; + matrix->ww = 1.0f; } s32 ObjMine_StepUntilParallel(Vec3f* value, Vec3f* target, f32 angleStep) { @@ -269,7 +269,7 @@ s32 ObjMine_StepUntilParallel(Vec3f* value, Vec3f* target, f32 angleStep) { Math_Vec3f_Copy(&prevValue, value); Math3D_CrossProduct(value, target, &perpVec); if (ObjMine_GetUnitVec3f(&perpVec, &perpNormal)) { - Matrix_RotateAxisS(RADF_TO_BINANG(angleStep), &perpNormal, MTXMODE_NEW); + Matrix_RotateAxisS(RAD_TO_BINANG(angleStep), &perpNormal, MTXMODE_NEW); Matrix_MultVec3f(&prevValue, value); } else { Matrix_RotateXFNew(angleStep); @@ -313,7 +313,7 @@ void ObjMine_Air_InitChain(ObjMine* this, s32 linkCount) { } if (wallCheckRadius < 0.0f) { - airChain->wallCheckDistSq = -1.0f; + airChain->wallCheckDistSq = -1.0f; // Negative value means skip wall collision checks } else if (wallCheckRadius <= AIR_RADIUS + 1.0f) { airChain->wallCheckDistSq = 0.0f; } else { @@ -403,7 +403,7 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { } if (wallCheckRadius < 0.0f) { - waterChain->wallCheckDistSq = -1.0f; + waterChain->wallCheckDistSq = -1.0f; // Negative value means skip wall collision checks } else if (wallCheckRadius <= WATER_RADIUS + 1.0f) { waterChain->wallCheckDistSq = 0.0f; } else { @@ -440,24 +440,24 @@ void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { waterChain->touchWall = false; if (waterChain->wallCheckDistSq > -1e-6f) { - // Checks for walls if mine is sufficiently far from home. + // Checks for walls if mine is sufficiently far from home. If found, sets ejection force towards home. if (waterChain->wallCheckDistSq <= Math3D_XZDistanceSquared(this->actor.home.pos.x, this->actor.home.pos.z, this->actor.world.pos.x, this->actor.world.pos.z)) { Vec3f centerPos; Vec3f offsetPos; - Vec3f dummyResult; + Vec3f result; // not used Vec3f xzFromHome; Vec3f xzDirFromHome; - CollisionPoly* dummyPoly; - s32 dummyBgId; - f32 dummyNorm; - f32 dummyInvNorm; + CollisionPoly* poly; // not used + s32 bgId; // not used + f32 norm; // not used + f32 invNorm; // not used xzFromHome.x = this->actor.world.pos.x - this->actor.home.pos.x; xzFromHome.y = 0.0f; xzFromHome.z = this->actor.world.pos.z - this->actor.home.pos.z; - if (ObjMine_GetUnitVec3fNorm(&xzFromHome, &xzDirFromHome, &dummyNorm, &dummyInvNorm)) { + if (ObjMine_GetUnitVec3fNorm(&xzFromHome, &xzDirFromHome, &norm, &invNorm)) { offsetPos.x = this->actor.world.pos.x + (xzDirFromHome.x * WATER_RADIUS); offsetPos.y = this->actor.world.pos.y; @@ -467,8 +467,8 @@ void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { centerPos.y = this->actor.world.pos.y; centerPos.z = this->actor.home.pos.z; - if (BgCheck_EntityLineTest1(&play->colCtx, ¢erPos, &offsetPos, &dummyResult, &dummyPoly, true, - false, false, true, &dummyBgId)) { + if (BgCheck_EntityLineTest1(&play->colCtx, ¢erPos, &offsetPos, &result, &poly, true, false, false, + true, &bgId)) { waterChain->touchWall = true; waterChain->wallEject.x = xzDirFromHome.x * -0.2f; waterChain->wallEject.z = xzDirFromHome.z * -0.2f; @@ -588,7 +588,7 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { Vec3f jointPos; s32 changeBasis; f32 diffNorm; - f32 dummyInvNorm; + f32 invNorm; // not used Vec3f* tempBasisX; // The joint between the current link and next link is half the link's length from its center. The first link is @@ -622,7 +622,7 @@ void ObjMine_Water_UpdateLinks(ObjMine* this) { // joint. The StepUntilParallel causes the chain to straighten over time. Math_Vec3f_Diff(&waterLink->pos, &jointPos, &tempVec); - if (ObjMine_GetUnitVec3fNorm(&tempVec, &diffDir, &diffNorm, &dummyInvNorm) && (diffNorm > LINK_SIZE / 3.0f)) { + if (ObjMine_GetUnitVec3fNorm(&tempVec, &diffDir, &diffNorm, &invNorm) && (diffNorm > LINK_SIZE / 3.0f)) { Math_Vec3f_Copy(&newBasis.y, &waterLink->basis.y); ObjMine_StepUntilParallel(&newBasis.y, &diffDir, M_PI / 30); @@ -677,7 +677,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { ObjMine* this = THIS; s32 pathIndex = OBJMINE_GET_PATH(&this->actor); Path* path; - s32 dummyBgId; + s32 bgId; // not used s32 type = OBJMINE_GET_TYPE(&this->actor); Actor_ProcessInitChain(&this->actor, sInitChain); @@ -708,7 +708,7 @@ void ObjMine_Init(Actor* thisx, PlayState* play) { &this->actor.shape.rot); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); Collider_UpdateSpheres(0, &this->collider); - this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &dummyBgId, + this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &bgId, &this->actor, &this->actor.world.pos); } else { s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); @@ -769,7 +769,7 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { f32 distToWaypoint; f32 step; f32 target; - s32 dummyBgId; + s32 bgId; // not used // thisx->velocity is temporarily set to the vector difference to the next waypoint. Math_Vec3s_ToVec3f(&nextWaypoint, &this->waypoints[this->waypointIndex + 1]); @@ -802,7 +802,7 @@ void ObjMine_Path_Move(ObjMine* this, PlayState* play) { ObjMine_Path_MoveToWaypoint(this, this->waypointIndex); } this->actor.floorHeight = - BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &dummyBgId, &this->actor, &thisx->world.pos); + BgCheck_EntityRaycastFloor5(&play->colCtx, &this->actor.floorPoly, &bgId, &this->actor, &thisx->world.pos); if (this->actor.flags & ACTOR_FLAG_40) { Vec3f rotAxis; Vec3f yhatCrossV; @@ -930,19 +930,19 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { Actor_UpdateBgCheckInfo(play, &this->actor, 0.0f, AIR_RADIUS, 0.0f, 1); - if ((this->actor.bgCheckFlags & 8) && (this->actor.wallPoly != NULL)) { + if ((this->actor.bgCheckFlags & BGCHECKFLAG_WALL) && (this->actor.wallPoly != NULL)) { Vec3f xzDir; Vec3f reflectedDir; Vec3f wallNormal; Vec3f xzVel; f32 xzSpeed; - f32 dummyInvNorm; + f32 invNorm; // not used xzVel.x = airChain->velocity.x; xzVel.y = 0.0f; xzVel.z = airChain->velocity.z; - if (ObjMine_GetUnitVec3fNorm(&xzVel, &xzDir, &xzSpeed, &dummyInvNorm)) { + if (ObjMine_GetUnitVec3fNorm(&xzVel, &xzDir, &xzSpeed, &invNorm)) { wallNormal.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); wallNormal.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); wallNormal.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); @@ -963,8 +963,10 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { } } - // Applies three torques to individual chain links. The restoring torque towards the default twist of 0x4000, a - // random torque for variance, and a linear drag. + // Applies three torques to individual chain links: + // - restoring torque towards the default twist of 0x4000 + // - random torque for variance + // - linear drag torque for (i = 0, airLink = airChain->links; i < linkCount; i++, airLink++) { twistDiff = airLink->twist - 0x4000; spin = airLink->spin + (twistDiff * -0.05f) + (30.0f * Rand_ZeroOne() - 15.0f); @@ -1148,7 +1150,7 @@ void ObjMine_Air_Draw(Actor* thisx, PlayState* play) { gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); - ObjMine_ReplaceRotation(&airChain->basis); + ObjMine_SetRotation(&airChain->basis); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); if (linkCount != 0) { // Sets pivot point to be half a chain link length below home @@ -1204,7 +1206,7 @@ void ObjMine_Water_Draw(Actor* thisx, PlayState* play) { gSPDisplayList(gfx++, object_ny_DL_000030); for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { - ObjMine_ReplaceRotation(&waterLink->basis); + ObjMine_SetRotation(&waterLink->basis); Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); // Consecutive chain links are offset 90 degrees. if ((i % 2) == 0) { diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h index 5338602e2..26b93be37 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.h @@ -12,10 +12,10 @@ typedef void (*ObjMineActionFunc)(struct ObjMine*, PlayState*); #define OBJMINE_GET_PATH_SPEED(thisx) (((thisx)->params >> 8) & 7) #define OBJMINE_GET_TYPE(thisx) (((thisx)->params >> 12) & 3) -#define OBJMINE_SET_PARAM(type, linkCount, pathIndex, pathSpeed) (((type) << 0xC) | ((type == OBJMINE_TYPE_PATH) ? ((pathIndex) | ((pathSpeed) << 8)) : (linkCount))) -#define OBJMINE_PATH_SET_PARAM(pathIndex, pathSpeed) OBJMINE_SET_PARAM(OBJMINE_TYPE_PATH, 0, pathIndex, pathSpeed) -#define OBJMINE_AIR_SET_PARAM(linkCount) OBJMINE_SET_PARAM(OBJMINE_TYPE_AIR, linkCount, 0, 0) -#define OBJMINE_WATER_SET_PARAM(linkCount) OBJMINE_SET_PARAM(OBJMINE_TYPE_WATER, linkCount, 0, 0) +#define OBJMINE_PARAM(type, linkCount, pathIndex, pathSpeed) (((type) << 0xC) | ((type == OBJMINE_TYPE_PATH) ? ((pathIndex) | ((pathSpeed) << 8)) : (linkCount))) +#define OBJMINE_PATH_PARAM(pathIndex, pathSpeed) OBJMINE_PARAM(OBJMINE_TYPE_PATH, 0, pathIndex, pathSpeed) +#define OBJMINE_AIR_PARAM(linkCount) OBJMINE_PARAM(OBJMINE_TYPE_AIR, linkCount, 0, 0) +#define OBJMINE_WATER_PARAM(linkCount) OBJMINE_PARAM(OBJMINE_TYPE_WATER, linkCount, 0, 0) #define OBJMINE_CHAIN_MAX 63 @@ -32,8 +32,8 @@ typedef struct { } ObjMineMtxF3; // size = 0x24 typedef struct { - /* 0x00 */ s16 twist; - /* 0x02 */ s16 spin; + /* 0x0 */ s16 twist; + /* 0x2 */ s16 spin; } ObjMineAirLink; // size = 0x4 typedef struct { From 82324a84f7b378c6cb3a399557d0e841987bfd4e Mon Sep 17 00:00:00 2001 From: petrie911 Date: Thu, 8 Jun 2023 06:39:57 -0500 Subject: [PATCH 23/26] merge --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 75cb23af7..25c07120a 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -260,7 +260,7 @@ s32 ObjMine_StepUntilParallel(Vec3f* value, Vec3f* target, f32 angleStep) { Vec3f perpNormal; f32 cosAngle = Math3D_Parallel(value, target); - if (cos_rad(angleStep) <= cosAngle) { + if (Math_CosF(angleStep) <= cosAngle) { Math_Vec3f_Copy(value, target); return true; } @@ -1103,7 +1103,7 @@ void ObjMine_Path_Draw(Actor* thisx, PlayState* play) { } func_800B8050(&this->actor, play, true); - func_8012C28C(play->state.gfxCtx); + Gfx_SetupDL25_Opa(play->state.gfxCtx); gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gDPSetRenderMode(POLY_OPA_DISP++, G_RM_PASS, G_RM_AA_ZB_OPA_SURF2); @@ -1120,7 +1120,7 @@ void ObjMine_DrawExplosion(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); func_800B8118(thisx, play, true); - func_8012C2DC(play->state.gfxCtx); + Gfx_SetupDL25_Xlu(play->state.gfxCtx); gDPSetRenderMode(POLY_XLU_DISP++, G_RM_PASS, G_RM_AA_ZB_XLU_SURF2); gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 0, 75); @@ -1146,7 +1146,7 @@ void ObjMine_Air_Draw(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); gfx = POLY_OPA_DISP; - gSPDisplayList(gfx++, &sSetupDL[6 * 25]); + gSPDisplayList(gfx++, &gSetupDLs[SETUPDL_25]); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); @@ -1201,7 +1201,7 @@ void ObjMine_Water_Draw(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); gfx = POLY_OPA_DISP; - gSPDisplayList(gfx++, &sSetupDL[6 * 25]); + gSPDisplayList(gfx++, &gSetupDLs[SETUPDL_25]); gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfx++, object_ny_DL_000030); From a1f4906aa0453c7bd148087816f1c9345badeaf8 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Thu, 8 Jun 2023 17:41:07 -0500 Subject: [PATCH 24/26] my god, it matches --- spec | 4 -- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 50 +++++++++---------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/spec b/spec index 9f7cb3dd4..bb4a78b66 100644 --- a/spec +++ b/spec @@ -2926,11 +2926,7 @@ beginseg name "ovl_Obj_Mine" compress include "build/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.o" -#ifdef NON_MATCHING include "build/src/overlays/actors/ovl_Obj_Mine/ovl_Obj_Mine_reloc.o" -#else - include "build/data/ovl_Obj_Mine/ovl_Obj_Mine.reloc.o" -#endif endseg beginseg diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 25c07120a..23c520b31 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -478,28 +478,27 @@ void ObjMine_Water_WallCheck(ObjMine* this, PlayState* play) { } } -#ifdef NON_MATCHING -// https://decomp.me/scratch/BW51G -// Probably equivalent, but nightmare loop unrolls. The tension section also has weird comparisons. It should be -// equivalent to what's written, but it seems the actual code comparisons were implemented differently. ASM suggests -// multiple index variables were used at once. +Vec3f sLastLinkAccel[OBJMINE_CHAIN_MAX + 1]; void ObjMine_Water_ApplyForces(ObjMine* this) { - static Vec3f sLastLinkAccel[OBJMINE_CHAIN_MAX + 1]; ObjMineWaterChain* waterChain = &this->chain.water; ObjMineWaterLink* waterLink; s32 i; - s16 swayPhase; + s16 swayPhase = 0; s32 linkCount = OBJMINE_GET_LINK_COUNT(&this->actor); f32 inverseCount = 1.0f / linkCount; f32 restoreY = (waterChain->links[linkCount - 1].pos.y - waterChain->restY) * waterChain->restoreY; Vec3f tension; f32 scaledKnockback; + s32 index; + s32 pad; + Vec3f* lastLinkAccel; // Applies the buoyant force and sway from the water. - for (i = 0, waterLink = waterChain->links, swayPhase = 0; i < linkCount; - i++, waterLink++, swayPhase += waterChain->swayPhaseVel) { - Math_Vec3f_Copy(&sLastLinkAccel[i], &waterLink->accel); + for (i = 0, waterLink = waterChain->links, lastLinkAccel = sLastLinkAccel; i < linkCount; + i++, waterLink++, swayPhase += waterChain->swayPhaseVel, lastLinkAccel++) { + Math_Vec3f_Copy(lastLinkAccel, &waterLink->accel); + if (waterLink->pos.y <= this->actor.home.pos.y) { waterLink->accel.y = waterChain->restoreY * -96.0f; } else if (restoreY > 0.0f) { @@ -507,6 +506,7 @@ void ObjMine_Water_ApplyForces(ObjMine* this) { } else { waterLink->accel.y = restoreY; } + waterLink->accel.x = (waterLink->pos.x - this->actor.home.pos.x) * waterChain->restoreXZ; waterLink->accel.z = (waterLink->pos.z - this->actor.home.pos.z) * waterChain->restoreXZ; waterLink->accel.x += waterChain->swayXZ * Math_SinS(swayPhase); @@ -538,12 +538,14 @@ void ObjMine_Water_ApplyForces(ObjMine* this) { // frame. for (i = 0, waterLink = waterChain->links; i < linkCount; i++, waterLink++) { Math_Vec3f_Copy(&tension, &gZeroVec3f); - if (i - 2 >= 0) { + + if (i >= 2) { tension.x += sLastLinkAccel[i - 2].x * 0.075f; tension.y += sLastLinkAccel[i - 2].y * 0.075f; tension.z += sLastLinkAccel[i - 2].z * 0.075f; } - if (i - 1 >= 0) { + + if (i >= 1) { tension.x += sLastLinkAccel[i - 1].x * 0.15f; tension.y += sLastLinkAccel[i - 1].y * 0.15f; tension.z += sLastLinkAccel[i - 1].z * 0.15f; @@ -553,26 +555,24 @@ void ObjMine_Water_ApplyForces(ObjMine* this) { tension.y += sLastLinkAccel[i].y * 0.3f; tension.z += sLastLinkAccel[i].z * 0.3f; - if (i + 1 < linkCount) { - tension.x += sLastLinkAccel[i + 1].x * 0.15f; - tension.y += sLastLinkAccel[i + 1].y * 0.15f; - tension.z += sLastLinkAccel[i + 1].z * 0.15f; + index = i + 1; + if (index < linkCount) { + tension.x += sLastLinkAccel[index].x * 0.15f; + tension.y += sLastLinkAccel[index].y * 0.15f; + tension.z += sLastLinkAccel[index].z * 0.15f; } - if (i + 2 < linkCount) { - tension.x += sLastLinkAccel[i + 2].x * 0.075f; - tension.y += sLastLinkAccel[i + 2].y * 0.075f; - tension.z += sLastLinkAccel[i + 2].z * 0.075f; + + index = i + 2; + if (index < linkCount) { + tension.x += sLastLinkAccel[index].x * 0.075f; + tension.y += sLastLinkAccel[index].y * 0.075f; + tension.z += sLastLinkAccel[index].z * 0.075f; } waterLink->accel.x += tension.x; waterLink->accel.y += tension.y; waterLink->accel.z += tension.z; } } -#else -Vec3f sLastLinkAccel[OBJMINE_CHAIN_MAX + 1]; -void ObjMine_Water_ApplyForces(ObjMine* this); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Obj_Mine/ObjMine_Water_ApplyForces.s") -#endif void ObjMine_Water_UpdateLinks(ObjMine* this) { s32 pad; // Could be recast to thisx as in ObjMine_Path_Move From e1b7794f33375d37e672b9a0f8977e62dd7950bd Mon Sep 17 00:00:00 2001 From: petrie911 Date: Thu, 8 Jun 2023 17:41:49 -0500 Subject: [PATCH 25/26] format --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 23c520b31..072371f53 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -561,7 +561,7 @@ void ObjMine_Water_ApplyForces(ObjMine* this) { tension.y += sLastLinkAccel[index].y * 0.15f; tension.z += sLastLinkAccel[index].z * 0.15f; } - + index = i + 2; if (index < linkCount) { tension.x += sLastLinkAccel[index].x * 0.075f; From 924cf524bcebb57dd26bb8424e54f114a825ca2a Mon Sep 17 00:00:00 2001 From: petrie911 Date: Thu, 15 Jun 2023 07:22:05 -0500 Subject: [PATCH 26/26] removed macros --- include/macros.h | 3 --- src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c | 12 ++++++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/macros.h b/include/macros.h index 43f526f24..d2b98dec5 100644 --- a/include/macros.h +++ b/include/macros.h @@ -94,9 +94,6 @@ #define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x)) #define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x)) -#define RAND_BITS(n) ((s32)Rand_Next() >> (0x20 - n)) -#define RANDU_BITS(n) (Rand_Next() >> (0x20 - n)) - #define RGBA16_GET_R(pixel) (((pixel) >> 11) & 0x1F) #define RGBA16_GET_G(pixel) (((pixel) >> 6) & 0x1F) #define RGBA16_GET_B(pixel) (((pixel) >> 1) & 0x1F) diff --git a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c index 072371f53..35df2c5a3 100644 --- a/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c +++ b/src/overlays/actors/ovl_Obj_Mine/z_obj_mine.c @@ -374,7 +374,7 @@ void ObjMine_Water_InitChain(ObjMine* this, s32 linkCount) { waterChain->drag = 0.9f; waterChain->swayMax = 0.003f; - waterChain->swayPhaseVel = RANDU_BITS(13); + waterChain->swayPhaseVel = Rand_Next() >> (0x20 - 13); waterChain->restoreXZ = -0.0002f; waterChain->restoreY = -0.0002f; @@ -895,9 +895,9 @@ void ObjMine_Air_Chained(ObjMine* this, PlayState* play) { } // Applies chain sway, choosing a new sway randomly about every 32 frames - if (RANDU_BITS(5) == 0) { + if ((Rand_Next() >> (0x20 - 5)) == 0) { airChain->swaySize = Rand_ZeroOne() * airChain->swayMax; - airChain->swayPhase = RANDU_BITS(16); + airChain->swayPhase = Rand_Next() >> (0x20 - 16); } xAccel = Math_SinS(airChain->swayPhase) * airChain->swaySize; zAccel = Math_CosS(airChain->swayPhase) * airChain->swaySize; @@ -1032,12 +1032,12 @@ void ObjMine_Water_Chained(ObjMine* this, PlayState* play) { waterChain->swayMax = 0.003f; // Chooses a new sway randomly about every 32 frames. - if (RANDU_BITS(5) == 0) { - s16 randAngle = RANDU_BITS(16); + if (Rand_Next() >> (0x20 - 5) == 0) { + s16 randAngle = Rand_Next() >> (0x20 - 16); waterChain->swayXZ = Math_SinS(randAngle) * 1.8f * waterChain->swayMax; waterChain->swayY = Math_CosS(randAngle) * 0.2f * waterChain->swayMax; - waterChain->swayPhaseVel = RANDU_BITS(13); + waterChain->swayPhaseVel = Rand_Next() >> (0x20 - 13); } ObjMine_Water_UpdateChain(this, play);