From ba9c60552b7a879d05a15aee102b502333b6bb41 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Thu, 10 Oct 2024 02:22:52 +0200 Subject: [PATCH 1/3] Player doc: some rotation logic/data (#1443) * Docs: some player rotation logic/data * Improve misleading comment * rename temps * unk_6AE_rotFlags * format * disasm metadata --- include/z64player.h | 22 +- src/code/z_actor.c | 2 +- src/code/z_player_lib.c | 24 +- src/overlays/actors/ovl_En_Horse/z_en_horse.c | 2 +- .../actors/ovl_player_actor/z_player.c | 259 ++++++++++-------- 5 files changed, 169 insertions(+), 140 deletions(-) diff --git a/include/z64player.h b/include/z64player.h index 1f92088ad9..a081506178 100644 --- a/include/z64player.h +++ b/include/z64player.h @@ -748,6 +748,16 @@ typedef void (*PlayerActionFunc)(struct Player*, struct PlayState*); typedef s32 (*UpperActionFunc)(struct Player*, struct PlayState*); typedef void (*AfterPutAwayFunc)(struct PlayState*, struct Player*); +#define UNK6AE_ROT_FOCUS_X (1 << 0) +#define UNK6AE_ROT_FOCUS_Y (1 << 1) +#define UNK6AE_ROT_FOCUS_Z (1 << 2) +#define UNK6AE_ROT_HEAD_X (1 << 3) +#define UNK6AE_ROT_HEAD_Y (1 << 4) +#define UNK6AE_ROT_HEAD_Z (1 << 5) +#define UNK6AE_ROT_UPPER_X (1 << 6) +#define UNK6AE_ROT_UPPER_Y (1 << 7) +#define UNK6AE_ROT_UPPER_Z (1 << 8) + typedef struct Player { /* 0x0000 */ Actor actor; /* 0x014C */ s8 currentTunic; // current tunic from `PlayerTunic` @@ -838,15 +848,11 @@ typedef struct Player { /* 0x06A8 */ Actor* unk_6A8; /* 0x06AC */ s8 idleType; /* 0x06AD */ u8 unk_6AD; - /* 0x06AE */ u16 unk_6AE; - /* 0x06B0 */ s16 unk_6B0; + /* 0x06AE */ u16 unk_6AE_rotFlags; // See `UNK6AE_ROT_` macros. If its flag isn't set, a rot steps to 0. + /* 0x06B0 */ s16 upperLimbYawSecondary; /* 0x06B2 */ char unk_6B4[0x004]; - /* 0x06B6 */ s16 unk_6B6; - /* 0x06B8 */ s16 unk_6B8; - /* 0x06BA */ s16 unk_6BA; - /* 0x06BC */ s16 unk_6BC; - /* 0x06BE */ s16 unk_6BE; - /* 0x06C0 */ s16 unk_6C0; + /* 0x06B6 */ Vec3s headLimbRot; + /* 0x06BC */ Vec3s upperLimbRot; /* 0x06C2 */ s16 unk_6C2; /* 0x06C4 */ f32 unk_6C4; /* 0x06C8 */ SkelAnime upperSkelAnime; diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 71e25d9530..cbe84c927e 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1098,7 +1098,7 @@ int func_8002DD6C(Player* player) { } int func_8002DD78(Player* player) { - return func_8002DD6C(player) && player->unk_834; + return func_8002DD6C(player) && (player->unk_834 != 0); } int func_8002DDA8(PlayState* play) { diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index c9815c3137..d7ec54bd03 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -1295,22 +1295,22 @@ s32 Player_OverrideLimbDrawGameplayCommon(PlayState* play, s32 limbIndex, Gfx** } if (limbIndex == PLAYER_LIMB_HEAD) { - rot->x += this->unk_6BA; - rot->y -= this->unk_6B8; - rot->z += this->unk_6B6; + rot->x += this->headLimbRot.z; + rot->y -= this->headLimbRot.y; + rot->z += this->headLimbRot.x; } else if (limbIndex == PLAYER_LIMB_UPPER) { - if (this->unk_6B0 != 0) { + if (this->upperLimbYawSecondary != 0) { Matrix_RotateZ(BINANG_TO_RAD(0x44C), MTXMODE_APPLY); - Matrix_RotateY(BINANG_TO_RAD(this->unk_6B0), MTXMODE_APPLY); + Matrix_RotateY(BINANG_TO_RAD(this->upperLimbYawSecondary), MTXMODE_APPLY); } - if (this->unk_6BE != 0) { - Matrix_RotateY(BINANG_TO_RAD(this->unk_6BE), MTXMODE_APPLY); + if (this->upperLimbRot.y != 0) { + Matrix_RotateY(BINANG_TO_RAD(this->upperLimbRot.y), MTXMODE_APPLY); } - if (this->unk_6BC != 0) { - Matrix_RotateX(BINANG_TO_RAD(this->unk_6BC), MTXMODE_APPLY); + if (this->upperLimbRot.x != 0) { + Matrix_RotateX(BINANG_TO_RAD(this->upperLimbRot.x), MTXMODE_APPLY); } - if (this->unk_6C0 != 0) { - Matrix_RotateZ(BINANG_TO_RAD(this->unk_6C0), MTXMODE_APPLY); + if (this->upperLimbRot.z != 0) { + Matrix_RotateZ(BINANG_TO_RAD(this->upperLimbRot.z), MTXMODE_APPLY); } } else if (limbIndex == PLAYER_LIMB_L_THIGH) { s32 pad; @@ -1788,7 +1788,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList, Ve Matrix_MtxFToYXZRotS(&sp44, &heldActor->world.rot, 0); heldActor->shape.rot = heldActor->world.rot; - if (func_8002DD78(this) != 0) { + if (func_8002DD78(this)) { Matrix_Translate(500.0f, 300.0f, 0.0f, MTXMODE_APPLY); Player_DrawHookshotReticle(play, this, (this->heldItemAction == PLAYER_IA_HOOKSHOT) ? 38600.0f : 77600.0f); diff --git a/src/overlays/actors/ovl_En_Horse/z_en_horse.c b/src/overlays/actors/ovl_En_Horse/z_en_horse.c index fb57ef0148..d02d1b5fa4 100644 --- a/src/overlays/actors/ovl_En_Horse/z_en_horse.c +++ b/src/overlays/actors/ovl_En_Horse/z_en_horse.c @@ -724,7 +724,7 @@ void EnHorse_ResetRace(EnHorse* this, PlayState* play) { s32 EnHorse_PlayerCanMove(EnHorse* this, PlayState* play) { Player* player = GET_PLAYER(play); - if ((player->stateFlags1 & PLAYER_STATE1_0) || func_8002DD78(GET_PLAYER(play)) == 1 || + if ((player->stateFlags1 & PLAYER_STATE1_0) || func_8002DD78(GET_PLAYER(play)) == true || (player->stateFlags1 & PLAYER_STATE1_20) || ((this->stateFlags & ENHORSE_FLAG_19) && !this->inRace) || this->action == ENHORSE_ACT_HBA || player->actor.flags & ACTOR_FLAG_TALK || play->csCtx.state != CS_STATE_IDLE) { diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 82afb14714..10aa62442d 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -3141,8 +3141,8 @@ s32 func_808351D4(Player* this, PlayState* play) { sp2C = 1; } - Math_ScaledStepToS(&this->unk_6C0, 1200, 400); - this->unk_6AE |= 0x100; + Math_ScaledStepToS(&this->upperLimbRot.z, 1200, 400); + this->unk_6AE_rotFlags |= UNK6AE_ROT_UPPER_Z; if ((this->unk_836 == 0) && (Player_CheckForIdleAnim(this) == IDLE_ANIM_NONE) && (this->skelAnime.animation == &gPlayerAnim_link_bow_side_walk)) { @@ -3675,7 +3675,7 @@ s32 Player_UpdateUpperBody(Player* this, PlayState* play) { this->yaw = this->actor.shape.rot.y; this->actor.bgCheckFlags &= ~BGCHECKFLAG_GROUND; this->hoverBootsTimer = 0; - this->unk_6AE |= 0x43; + this->unk_6AE_rotFlags |= UNK6AE_ROT_FOCUS_X | UNK6AE_ROT_FOCUS_Y | UNK6AE_ROT_UPPER_X; Player_PlayVoiceSfx(this, NA_SE_VO_LI_LASH); return true; } @@ -3763,48 +3763,68 @@ void Player_UpdateShapeYaw(Player* this, PlayState* play) { this->unk_87C = this->actor.shape.rot.y - previousYaw; } -s32 func_808369C8(s16* pValue, s16 arg1, s16 arg2, s16 arg3, s16 arg4, s16 arg5) { - s16 temp1; - s16 temp2; - s16 temp3; +/** + * Step a value by `step` to a `target` value. + * Constrains the value to be no further than `constraintRange` from `constraintMid` (accounting for wrapping). + * Constrains the value to be no further than `overflowRange` from 0. + * If this second constraint is enforced, return how much the value was past by the range, or return 0. + * + * @return The amount by which the value overflowed the absolute range defined by `overflowRange` + */ +s32 Player_ScaledStepBinangClamped(s16* pValue, s16 target, s16 step, s16 overflowRange, s16 constraintMid, + s16 constraintRange) { + s16 diff; + s16 clampedDiff; + s16 valueBeforeOverflowClamp; - temp1 = temp2 = arg4 - *pValue; - temp2 = CLAMP(temp2, -arg5, arg5); - *pValue += (s16)(temp1 - temp2); + // Clamp value to [constraintMid - constraintRange , constraintMid + constraintRange] + // This is more involved than a simple `CLAMP`, to account for binang wrapping + diff = clampedDiff = constraintMid - *pValue; + clampedDiff = CLAMP(clampedDiff, -constraintRange, constraintRange); + *pValue += (s16)(diff - clampedDiff); - Math_ScaledStepToS(pValue, arg1, arg2); + Math_ScaledStepToS(pValue, target, step); - temp3 = *pValue; - if (*pValue < -arg3) { - *pValue = -arg3; - } else if (*pValue > arg3) { - *pValue = arg3; + valueBeforeOverflowClamp = *pValue; + if (*pValue < -overflowRange) { + *pValue = -overflowRange; + } else if (*pValue > overflowRange) { + *pValue = overflowRange; } - return temp3 - *pValue; + return valueBeforeOverflowClamp - *pValue; } s32 func_80836AB8(Player* this, s32 arg1) { - s16 sp36; - s16 var; + s16 targetUpperBodyYaw; + s16 yaw; - var = this->actor.shape.rot.y; - if (arg1 != 0) { - var = this->actor.focus.rot.y; - this->unk_6BC = this->actor.focus.rot.x; - this->unk_6AE |= 0x41; + yaw = this->actor.shape.rot.y; + if (arg1) { + yaw = this->actor.focus.rot.y; + this->upperLimbRot.x = this->actor.focus.rot.x; + this->unk_6AE_rotFlags |= UNK6AE_ROT_FOCUS_X | UNK6AE_ROT_UPPER_X; } else { - func_808369C8(&this->unk_6BC, - func_808369C8(&this->unk_6B6, this->actor.focus.rot.x, 600, 10000, this->actor.focus.rot.x, 0), - 200, 4000, this->unk_6B6, 10000); - sp36 = this->actor.focus.rot.y - var; - func_808369C8(&sp36, 0, 200, 24000, this->unk_6BE, 8000); - var = this->actor.focus.rot.y - sp36; - func_808369C8(&this->unk_6B8, sp36 - this->unk_6BE, 200, 8000, sp36, 8000); - func_808369C8(&this->unk_6BE, sp36, 200, 8000, this->unk_6B8, 8000); - this->unk_6AE |= 0xD9; + // Step the head pitch to the focus pitch. + // If the head cannot be pitched enough, pitch the upper body. + Player_ScaledStepBinangClamped(&this->upperLimbRot.x, + Player_ScaledStepBinangClamped(&this->headLimbRot.x, this->actor.focus.rot.x, + 600, 10000, this->actor.focus.rot.x, 0), + 200, 4000, this->headLimbRot.x, 10000); + + // Step the upper body and head yaw to the focus yaw. + // Eventually prefers turning the upper body rather than the head. + targetUpperBodyYaw = this->actor.focus.rot.y - yaw; + Player_ScaledStepBinangClamped(&targetUpperBodyYaw, 0, 200, 24000, this->upperLimbRot.y, 8000); + yaw = this->actor.focus.rot.y - targetUpperBodyYaw; + Player_ScaledStepBinangClamped(&this->headLimbRot.y, targetUpperBodyYaw - this->upperLimbRot.y, 200, 8000, + targetUpperBodyYaw, 8000); + Player_ScaledStepBinangClamped(&this->upperLimbRot.y, targetUpperBodyYaw, 200, 8000, this->headLimbRot.y, 8000); + + this->unk_6AE_rotFlags |= + UNK6AE_ROT_FOCUS_X | UNK6AE_ROT_HEAD_X | UNK6AE_ROT_HEAD_Y | UNK6AE_ROT_UPPER_X | UNK6AE_ROT_UPPER_Y; } - return var; + return yaw; } /** @@ -4241,7 +4261,7 @@ s32 Player_TryActionHandlerList(PlayState* play, Player* this, s8* actionHandler } if (func_8008F128(this)) { - this->unk_6AE |= 0x41; + this->unk_6AE_rotFlags |= UNK6AE_ROT_FOCUS_X | UNK6AE_ROT_UPPER_X; return true; } @@ -5925,8 +5945,8 @@ void func_8083AF44(PlayState* play, Player* this, s32 magicSpell) { } void func_8083B010(Player* this) { - this->actor.focus.rot.x = this->actor.focus.rot.z = this->unk_6B6 = this->unk_6B8 = this->unk_6BA = this->unk_6BC = - this->unk_6BE = this->unk_6C0 = 0; + this->actor.focus.rot.x = this->actor.focus.rot.z = this->headLimbRot.x = this->headLimbRot.y = + this->headLimbRot.z = this->upperLimbRot.x = this->upperLimbRot.y = this->upperLimbRot.z = 0; this->actor.focus.rot.y = this->actor.shape.rot.y; } @@ -6472,7 +6492,7 @@ s32 Player_ActionHandler_11(Player* this, PlayState* play) { this->unk_86C = 0.0f; func_80833C3C(this); } - this->unk_6BC = this->unk_6BE = this->unk_6C0 = 0; + this->upperLimbRot.x = this->upperLimbRot.y = this->upperLimbRot.z = 0; } frame = Animation_GetLastFrame(anim); @@ -7019,18 +7039,21 @@ void func_8083D6EC(PlayState* play, Player* this) { s32 func_8083DB98(Player* this, s32 arg1) { Actor* focusActor = this->focusActor; - Vec3f sp30; - s16 sp2E; - s16 sp2C; + Vec3f playerHeadPos; + s16 targetFocusRotX; + s16 targetFocusRotY; - sp30.x = this->actor.world.pos.x; - sp30.y = this->bodyPartsPos[PLAYER_BODYPART_HEAD].y + 3.0f; - sp30.z = this->actor.world.pos.z; - sp2E = Math_Vec3f_Pitch(&sp30, &focusActor->focus.pos); - sp2C = Math_Vec3f_Yaw(&sp30, &focusActor->focus.pos); - Math_SmoothStepToS(&this->actor.focus.rot.y, sp2C, 4, 10000, 0); - Math_SmoothStepToS(&this->actor.focus.rot.x, sp2E, 4, 10000, 0); - this->unk_6AE |= 2; + playerHeadPos.x = this->actor.world.pos.x; + playerHeadPos.y = this->bodyPartsPos[PLAYER_BODYPART_HEAD].y + 3.0f; + playerHeadPos.z = this->actor.world.pos.z; + + targetFocusRotX = Math_Vec3f_Pitch(&playerHeadPos, &focusActor->focus.pos); + targetFocusRotY = Math_Vec3f_Yaw(&playerHeadPos, &focusActor->focus.pos); + + Math_SmoothStepToS(&this->actor.focus.rot.y, targetFocusRotY, 4, 10000, 0); + Math_SmoothStepToS(&this->actor.focus.rot.x, targetFocusRotX, 4, 10000, 0); + + this->unk_6AE_rotFlags |= UNK6AE_ROT_FOCUS_Y; return func_80836AB8(this, arg1); } @@ -7045,9 +7068,9 @@ void func_8083DC54(Player* this, PlayState* play) { if (this->focusActor != NULL) { if (func_8002DD78(this) || func_808334B4(this)) { - func_8083DB98(this, 1); + func_8083DB98(this, true); } else { - func_8083DB98(this, 0); + func_8083DB98(this, false); } return; } @@ -7070,22 +7093,22 @@ void func_8083DC54(Player* this, PlayState* play) { void func_8083DDC8(Player* this, PlayState* play) { if (!func_8002DD78(this) && !func_808334B4(this) && (this->speedXZ > 5.0f)) { - s16 temp1; - s16 temp2; + s16 targetPitch; + s16 targetRoll; - temp1 = this->speedXZ * 200.0f; - temp2 = (s16)(this->yaw - this->actor.shape.rot.y) * this->speedXZ * 0.1f; + targetPitch = this->speedXZ * 200.0f; + targetRoll = (s16)(this->yaw - this->actor.shape.rot.y) * this->speedXZ * 0.1f; - temp1 = CLAMP(temp1, -4000, 4000); - temp2 = CLAMP(-temp2, -4000, 4000); + targetPitch = CLAMP(targetPitch, -4000, 4000); + targetRoll = CLAMP(-targetRoll, -4000, 4000); - Math_ScaledStepToS(&this->unk_6BC, temp1, 900); - this->unk_6B6 = -(f32)this->unk_6BC * 0.5f; + Math_ScaledStepToS(&this->upperLimbRot.x, targetPitch, 900); + this->headLimbRot.x = -(f32)this->upperLimbRot.x * 0.5f; - Math_ScaledStepToS(&this->unk_6BA, temp2, 300); - Math_ScaledStepToS(&this->unk_6C0, temp2, 200); + Math_ScaledStepToS(&this->headLimbRot.z, targetRoll, 300); + Math_ScaledStepToS(&this->upperLimbRot.z, targetRoll, 200); - this->unk_6AE |= 0x168; + this->unk_6AE_rotFlags |= UNK6AE_ROT_HEAD_X | UNK6AE_ROT_HEAD_Z | UNK6AE_ROT_UPPER_X | UNK6AE_ROT_UPPER_Z; } else { func_8083DC54(this, play); } @@ -7854,10 +7877,10 @@ s32 func_8083FD78(Player* this, f32* arg1, s16* arg2, PlayState* play) { } if (this->focusActor != NULL) { - func_8083DB98(this, 1); + func_8083DB98(this, true); } else { Math_SmoothStepToS(&this->actor.focus.rot.x, sControlInput->rel.stick_y * 240.0f, 14, 4000, 30); - func_80836AB8(this, 1); + func_80836AB8(this, true); } } else { if (this->focusActor != NULL) { @@ -8868,7 +8891,7 @@ s32 func_808428D8(Player* this, PlayState* play) { Player_AnimPlayOnce(play, this, &gPlayerAnim_link_normal_defense_kiru); this->av1.actionVar1 = 1; this->meleeWeaponAnimation = PLAYER_MWA_STAB_1H; - this->yaw = this->actor.shape.rot.y + this->unk_6BE; + this->yaw = this->actor.shape.rot.y + this->upperLimbRot.y; return 1; } @@ -9104,14 +9127,14 @@ void Player_Action_80843188(Player* this, PlayState* play) { sp48 = 100; } - sp46 = ABS(sp4A - this->unk_6BE) * 0.25f; + sp46 = ABS(sp4A - this->upperLimbRot.y) * 0.25f; if (sp46 < 50) { sp46 = 50; } Math_ScaledStepToS(&this->actor.focus.rot.x, sp4C, sp48); - this->unk_6BC = this->actor.focus.rot.x; - Math_ScaledStepToS(&this->unk_6BE, sp4A, sp46); + this->upperLimbRot.x = this->actor.focus.rot.x; + Math_ScaledStepToS(&this->upperLimbRot.y, sp4A, sp46); if (this->av1.actionVar1 != 0) { if (!func_80842DF4(play, this)) { @@ -9153,7 +9176,7 @@ void Player_Action_80843188(Player* this, PlayState* play) { this->stateFlags1 |= PLAYER_STATE1_22; Player_SetModelsForHoldingShield(this); - this->unk_6AE |= 0xC1; + this->unk_6AE_rotFlags |= UNK6AE_ROT_FOCUS_X | UNK6AE_ROT_UPPER_X | UNK6AE_ROT_UPPER_Y; } void Player_Action_808435C4(Player* this, PlayState* play) { @@ -10701,60 +10724,60 @@ void Player_Init(Actor* thisx, PlayState* play2) { MREG(64) = 0; } -void func_808471F4(s16* pValue) { +void Player_ApproachZeroBinang(s16* pValue) { s16 step; - step = (ABS(*pValue) * 100.0f) / 1000.0f; + step = ABS(*pValue) * 100.0f / 1000.0f; step = CLAMP(step, 400, 4000); Math_ScaledStepToS(pValue, 0, step); } void func_80847298(Player* this) { - if (!(this->unk_6AE & 2)) { - s16 sp26 = this->actor.focus.rot.y - this->actor.shape.rot.y; + if (!(this->unk_6AE_rotFlags & UNK6AE_ROT_FOCUS_Y)) { + s16 diff = this->actor.focus.rot.y - this->actor.shape.rot.y; - func_808471F4(&sp26); - this->actor.focus.rot.y = this->actor.shape.rot.y + sp26; + Player_ApproachZeroBinang(&diff); + this->actor.focus.rot.y = this->actor.shape.rot.y + diff; } - if (!(this->unk_6AE & 1)) { - func_808471F4(&this->actor.focus.rot.x); + if (!(this->unk_6AE_rotFlags & UNK6AE_ROT_FOCUS_X)) { + Player_ApproachZeroBinang(&this->actor.focus.rot.x); } - if (!(this->unk_6AE & 8)) { - func_808471F4(&this->unk_6B6); + if (!(this->unk_6AE_rotFlags & UNK6AE_ROT_HEAD_X)) { + Player_ApproachZeroBinang(&this->headLimbRot.x); } - if (!(this->unk_6AE & 0x40)) { - func_808471F4(&this->unk_6BC); + if (!(this->unk_6AE_rotFlags & UNK6AE_ROT_UPPER_X)) { + Player_ApproachZeroBinang(&this->upperLimbRot.x); } - if (!(this->unk_6AE & 4)) { - func_808471F4(&this->actor.focus.rot.z); + if (!(this->unk_6AE_rotFlags & UNK6AE_ROT_FOCUS_Z)) { + Player_ApproachZeroBinang(&this->actor.focus.rot.z); } - if (!(this->unk_6AE & 0x10)) { - func_808471F4(&this->unk_6B8); + if (!(this->unk_6AE_rotFlags & UNK6AE_ROT_HEAD_Y)) { + Player_ApproachZeroBinang(&this->headLimbRot.y); } - if (!(this->unk_6AE & 0x20)) { - func_808471F4(&this->unk_6BA); + if (!(this->unk_6AE_rotFlags & UNK6AE_ROT_HEAD_Z)) { + Player_ApproachZeroBinang(&this->headLimbRot.z); } - if (!(this->unk_6AE & 0x80)) { - if (this->unk_6B0 != 0) { - func_808471F4(&this->unk_6B0); + if (!(this->unk_6AE_rotFlags & UNK6AE_ROT_UPPER_Y)) { + if (this->upperLimbYawSecondary != 0) { + Player_ApproachZeroBinang(&this->upperLimbYawSecondary); } else { - func_808471F4(&this->unk_6BE); + Player_ApproachZeroBinang(&this->upperLimbRot.y); } } - if (!(this->unk_6AE & 0x100)) { - func_808471F4(&this->unk_6C0); + if (!(this->unk_6AE_rotFlags & UNK6AE_ROT_UPPER_Z)) { + Player_ApproachZeroBinang(&this->upperLimbRot.z); } - this->unk_6AE = 0; + this->unk_6AE_rotFlags = 0; } static f32 D_80854784[] = { 120.0f, 240.0f, 360.0f }; @@ -12234,7 +12257,7 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { s16 temp2; s16 temp3; - if (!func_8002DD78(this) && !func_808334B4(this) && (arg2 == 0)) { + if (!func_8002DD78(this) && !func_808334B4(this) && !arg2) { temp2 = sControlInput->rel.stick_y * 240.0f; Math_SmoothStepToS(&this->actor.focus.rot.x, temp2, 14, 4000, 30); @@ -12256,7 +12279,7 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { this->actor.focus.rot.y = CLAMP(temp2, -temp1, temp1) + this->actor.shape.rot.y; } - this->unk_6AE |= 2; + this->unk_6AE_rotFlags |= UNK6AE_ROT_FOCUS_Y; return func_80836AB8(this, (play->shootingGalleryStatus != 0) || func_8002DD78(this) || func_808334B4(this)) - arg3; } @@ -12377,9 +12400,9 @@ void Player_Action_8084B1D8(Player* this, PlayState* play) { Sfx_PlaySfxCentered(NA_SE_SY_CAMERA_ZOOM_UP); } else if ((DECR(this->av2.actionVar2) == 0) || (this->unk_6AD != 2)) { if (func_8008F128(this)) { - this->unk_6AE |= 0x43; + this->unk_6AE_rotFlags |= UNK6AE_ROT_FOCUS_X | UNK6AE_ROT_FOCUS_Y | UNK6AE_ROT_UPPER_X; } else { - this->actor.shape.rot.y = func_8084ABD8(play, this, 0, 0); + this->actor.shape.rot.y = func_8084ABD8(play, this, false, 0); } } @@ -12471,7 +12494,7 @@ void Player_Action_8084B530(Player* this, PlayState* play) { } if (this->focusActor != NULL) { - this->yaw = this->actor.shape.rot.y = func_8083DB98(this, 0); + this->yaw = this->actor.shape.rot.y = func_8083DB98(this, false); } } @@ -13232,9 +13255,9 @@ void Player_Action_8084CC98(Player* this, PlayState* play) { this->unk_6AD = 0; this->stateFlags1 &= ~PLAYER_STATE1_20; } else { - this->unk_6BE = func_8084ABD8(play, this, 1, -5000) - this->actor.shape.rot.y; - this->unk_6BE += 5000; - this->unk_6B0 = -5000; + this->upperLimbRot.y = func_8084ABD8(play, this, true, -5000) - this->actor.shape.rot.y; + this->upperLimbRot.y += 5000; + this->upperLimbYawSecondary = -5000; } return; } @@ -13242,20 +13265,20 @@ void Player_Action_8084CC98(Player* this, PlayState* play) { if ((this->csAction != PLAYER_CSACTION_NONE) || (!func_8084C9BC(this, play) && !Player_ActionHandler_13(this, play))) { if (this->focusActor != NULL) { - if (func_8002DD78(this) != 0) { - this->unk_6BE = func_8083DB98(this, 1) - this->actor.shape.rot.y; - this->unk_6BE = CLAMP(this->unk_6BE, -0x4AAA, 0x4AAA); - this->actor.focus.rot.y = this->actor.shape.rot.y + this->unk_6BE; - this->unk_6BE += 5000; - this->unk_6AE |= 0x80; + if (func_8002DD78(this)) { + this->upperLimbRot.y = func_8083DB98(this, true) - this->actor.shape.rot.y; + this->upperLimbRot.y = CLAMP(this->upperLimbRot.y, -0x4AAA, 0x4AAA); + this->actor.focus.rot.y = this->actor.shape.rot.y + this->upperLimbRot.y; + this->upperLimbRot.y += 5000; + this->unk_6AE_rotFlags |= UNK6AE_ROT_UPPER_Y; } else { - func_8083DB98(this, 0); + func_8083DB98(this, false); } } else { - if (func_8002DD78(this) != 0) { - this->unk_6BE = func_8084ABD8(play, this, 1, -5000) - this->actor.shape.rot.y; - this->unk_6BE += 5000; - this->unk_6B0 = -5000; + if (func_8002DD78(this)) { + this->upperLimbRot.y = func_8084ABD8(play, this, true, -5000) - this->actor.shape.rot.y; + this->upperLimbRot.y += 5000; + this->upperLimbYawSecondary = -5000; } } } @@ -14078,7 +14101,7 @@ void Player_Action_8084F104(Player* this, PlayState* play) { } if ((this->av1.actionVar1 == 0) && (this->focusActor != NULL)) { - this->yaw = this->actor.shape.rot.y = func_8083DB98(this, 0); + this->yaw = this->actor.shape.rot.y = func_8083DB98(this, false); } } @@ -14258,8 +14281,8 @@ void Player_Action_8084FA54(Player* this, PlayState* play) { LinkAnimation_Update(play, &this->skelAnime); Player_UpdateUpperBody(this, play); - this->unk_6BE = func_8084ABD8(play, this, 1, 0) - this->actor.shape.rot.y; - this->unk_6AE |= 0x80; + this->upperLimbRot.y = func_8084ABD8(play, this, true, 0) - this->actor.shape.rot.y; + this->unk_6AE_rotFlags |= UNK6AE_ROT_UPPER_Y; if (play->shootingGalleryStatus < 0) { play->shootingGalleryStatus++; @@ -14536,7 +14559,7 @@ void Player_Action_808502D0(Player* this, PlayState* play) { sp2C = this->actor.world.pos.y - shockwavePos.y; Math_ScaledStepToS(&this->actor.focus.rot.x, Math_Atan2S(45.0f, sp2C), 800); - func_80836AB8(this, 1); + func_80836AB8(this, true); if ((((this->meleeWeaponAnimation == PLAYER_MWA_HAMMER_FORWARD) && LinkAnimation_OnFrame(&this->skelAnime, 7.0f)) || @@ -15154,7 +15177,7 @@ void func_80851314(Player* this) { this->focusActor = this->csActor; if (this->focusActor != NULL) { - this->actor.shape.rot.y = func_8083DB98(this, 0); + this->actor.shape.rot.y = func_8083DB98(this, false); } } From 33251ccb511d3a96504fd1cd95cc7e955858bb28 Mon Sep 17 00:00:00 2001 From: fig02 Date: Wed, 9 Oct 2024 21:37:33 -0400 Subject: [PATCH 2/3] name action wrappers (#2261) --- .../actors/ovl_player_actor/z_player.c | 66 ++++++++++++------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 10aa62442d..a8ec061289 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -3453,23 +3453,41 @@ s32 Player_SetupAction(PlayState* play, Player* this, PlayerActionFunc actionFun return 1; } -void func_80835DAC(PlayState* play, Player* this, PlayerActionFunc actionFunc, s32 flags) { - s32 temp; +/** + * Calls `Player_SetupAction` to setup a new action, but takes extra measures to + * preserve AnimMovement while doing so. + */ +void Player_SetupActionPreserveAnimMovement(PlayState* play, Player* this, PlayerActionFunc actionFunc, s32 flags) { + s32 savedMovementFlags; - temp = this->skelAnime.movementFlags; + savedMovementFlags = this->skelAnime.movementFlags; + + // Setting `skelAnime.movementFlags` to 0 will prevent `Player_FinishAnimMovement` from ending + // AnimMovement when `Player_SetupAction` is called. this->skelAnime.movementFlags = 0; + Player_SetupAction(play, this, actionFunc, flags); - this->skelAnime.movementFlags = temp; + this->skelAnime.movementFlags = savedMovementFlags; } -void func_80835DE4(PlayState* play, Player* this, PlayerActionFunc actionFunc, s32 flags) { - s32 temp; +/** + * Calls `Player_SetupAction` to setup a new action, but takes extra measures to + * preserve the current itemAction while doing so. + * + * Note that `itemAction` must be PLAYER_IA_NONE or higher for the action change to take place. + */ +void Player_SetupActionPreserveItemAction(PlayState* play, Player* this, PlayerActionFunc actionFunc, s32 flags) { + s32 savedItemAction; - if (this->itemAction >= 0) { - temp = this->itemAction; + if (this->itemAction >= PLAYER_IA_NONE) { + savedItemAction = this->itemAction; + + // Setting `itemAction` to `heldItemAction` will prevent `func_8008EC70` from running when + // `Player_SetupAction` is called. this->itemAction = this->heldItemAction; + Player_SetupAction(play, this, actionFunc, flags); - this->itemAction = temp; + this->itemAction = savedItemAction; Player_SetModels(this, Player_ActionToModelGroup(this, this->itemAction)); } } @@ -5617,7 +5635,7 @@ void func_8083A0F4(PlayState* play, Player* this) { } void func_8083A2F8(PlayState* play, Player* this) { - func_80835DAC(play, this, Player_Action_8084B530, 0); + Player_SetupActionPreserveAnimMovement(play, this, Player_Action_8084B530, 0); this->stateFlags1 |= PLAYER_STATE1_6 | PLAYER_STATE1_29; @@ -5628,7 +5646,7 @@ void func_8083A2F8(PlayState* play, Player* this) { } void func_8083A360(PlayState* play, Player* this) { - func_80835DAC(play, this, Player_Action_8084CC98, 0); + Player_SetupActionPreserveAnimMovement(play, this, Player_Action_8084CC98, 0); } void func_8083A388(PlayState* play, Player* this) { @@ -5639,7 +5657,7 @@ void func_8083A3B0(PlayState* play, Player* this) { s32 sp1C = this->av2.actionVar2; s32 sp18 = this->av1.actionVar1; - func_80835DAC(play, this, Player_Action_8084BF1C, 0); + Player_SetupActionPreserveAnimMovement(play, this, Player_Action_8084BF1C, 0); this->actor.velocity.y = 0.0f; this->av2.actionVar2 = sp1C; @@ -5647,11 +5665,11 @@ void func_8083A3B0(PlayState* play, Player* this) { } void func_8083A40C(PlayState* play, Player* this) { - func_80835DAC(play, this, Player_Action_8084C760, 0); + Player_SetupActionPreserveAnimMovement(play, this, Player_Action_8084C760, 0); } void func_8083A434(PlayState* play, Player* this) { - func_80835DAC(play, this, Player_Action_8084E6D4, 0); + Player_SetupActionPreserveAnimMovement(play, this, Player_Action_8084E6D4, 0); this->stateFlags1 |= PLAYER_STATE1_10 | PLAYER_STATE1_29; @@ -5922,7 +5940,7 @@ void func_8083AE40(Player* this, s16 objectId) { } void func_8083AF44(PlayState* play, Player* this, s32 magicSpell) { - func_80835DE4(play, this, Player_Action_808507F4, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_808507F4, 0); this->av1.actionVar1 = magicSpell - 3; @@ -6025,7 +6043,7 @@ s32 Player_ActionHandler_13(Player* this, PlayState* play) { (this->exchangeItemId == EXCH_ITEM_BOTTLE_BLUE_FIRE))))))) { if ((play->actorCtx.titleCtx.delayTimer == 0) && (play->actorCtx.titleCtx.alpha == 0)) { - func_80835DE4(play, this, Player_Action_8084F104, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_8084F104, 0); if (sp2C >= 0) { giEntry = &sGetItemTable[D_80854528[sp2C] - 1]; @@ -6052,7 +6070,7 @@ s32 Player_ActionHandler_13(Player* this, PlayState* play) { (this->itemAction == PLAYER_IA_MAGIC_BEAN))) { if (this->exchangeItemId == EXCH_ITEM_MAGIC_BEAN) { Inventory_ChangeAmmo(ITEM_MAGIC_BEAN, -1); - func_80835DE4(play, this, Player_Action_8084279C, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_8084279C, 0); this->stateFlags1 |= PLAYER_STATE1_29; this->av2.actionVar2 = 0x50; this->av1.actionVar1 = -1; @@ -6087,20 +6105,20 @@ s32 Player_ActionHandler_13(Player* this, PlayState* play) { sp2C = Player_ActionToBottle(this, this->itemAction); if (sp2C >= 0) { if (sp2C == 0xC) { - func_80835DE4(play, this, Player_Action_8084EED8, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_8084EED8, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_bug_out); func_80835EA4(play, 3); } else if ((sp2C > 0) && (sp2C < 4)) { - func_80835DE4(play, this, Player_Action_8084EFC0, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_8084EFC0, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_fish_out); func_80835EA4(play, (sp2C == 1) ? 1 : 5); } else { - func_80835DE4(play, this, Player_Action_8084EAC0, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_8084EAC0, 0); Player_AnimChangeOnceMorphAdjusted(play, this, &gPlayerAnim_link_bottle_drink_demo_start); func_80835EA4(play, 2); } } else { - func_80835DE4(play, this, Player_Action_8084E3C4, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_8084E3C4, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_normal_okarina_start); this->stateFlags2 |= PLAYER_STATE2_27; func_80835EA4(play, (this->unk_6A8 != NULL) ? 0x5B : 0x5A); @@ -7540,7 +7558,7 @@ s32 func_8083EC18(Player* this, PlayState* play, u32 wallFlags) { } void func_8083F070(Player* this, LinkAnimationHeader* anim, PlayState* play) { - func_80835DAC(play, this, Player_Action_8084C5F8, 0); + Player_SetupActionPreserveAnimMovement(play, this, Player_Action_8084C5F8, 0); LinkAnimation_PlayOnceSetSpeed(play, &this->skelAnime, anim, (4.0f / 3.0f)); } @@ -8103,7 +8121,7 @@ void Player_Action_808407CC(Player* this, PlayState* play) { } if (!Player_FriendlyLockOnOrParallel(this)) { - func_80835DAC(play, this, Player_Action_80840BC8, 1); + Player_SetupActionPreserveAnimMovement(play, this, Player_Action_80840BC8, 1); this->yaw = this->actor.shape.rot.y; return; } @@ -13030,7 +13048,7 @@ s32 func_8084C9BC(Player* this, PlayState* play) { if (EN_HORSE_CHECK_1(rideActor) || (EN_HORSE_CHECK_4(rideActor) && CHECK_BTN_ALL(sControlInput->press.button, BTN_A))) { rideActor->actor.child = NULL; - func_80835DAC(play, this, Player_Action_8084D3E4, 0); + Player_SetupActionPreserveAnimMovement(play, this, Player_Action_8084D3E4, 0); this->unk_878 = sp34 - rideActor->actor.world.pos.y; Player_AnimPlayOnce(play, this, (this->mountSide < 0) ? &gPlayerAnim_link_uma_left_down From 869bae342932cae89e3bb7ac8db7d2f736013f96 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Thu, 10 Oct 2024 04:09:58 +0200 Subject: [PATCH 3/3] Pause doc: misc, fixups (#2265) * use missed reg macros * do action indexing cleanup * misc * doc fixup ish in KaleidoScope_SetPageVertices * newline_police * `43` -> `(PAGE_BG_QUADS + WORLD_MAP_QUAD_28)` --- src/code/z_construct.c | 35 +++++++-------- src/code/z_kaleido_setup.c | 2 +- src/code/z_message.c | 2 +- src/code/z_parameter.c | 4 +- .../ovl_file_choose/z_file_choose.c | 5 ++- .../ovl_kaleido_scope/z_kaleido_collect.c | 2 +- .../misc/ovl_kaleido_scope/z_kaleido_map.c | 43 +++++++++++-------- .../misc/ovl_kaleido_scope/z_kaleido_scope.c | 29 +++++++------ 8 files changed, 70 insertions(+), 52 deletions(-) diff --git a/src/code/z_construct.c b/src/code/z_construct.c index 0720bc8b9a..374665d385 100644 --- a/src/code/z_construct.c +++ b/src/code/z_construct.c @@ -52,17 +52,17 @@ void Interface_Init(PlayState* play) { #if OOT_NTSC if (gSaveContext.language == LANGUAGE_JPN) { - doActionOffset = LANGUAGE_JPN * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_JPN * DO_ACTION_MAX + DO_ACTION_ATTACK) * DO_ACTION_TEX_SIZE; } else { - doActionOffset = LANGUAGE_ENG * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_ENG * DO_ACTION_MAX + DO_ACTION_ATTACK) * DO_ACTION_TEX_SIZE; } #else if (gSaveContext.language == LANGUAGE_ENG) { - doActionOffset = LANGUAGE_ENG * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_ENG * DO_ACTION_MAX + DO_ACTION_ATTACK) * DO_ACTION_TEX_SIZE; } else if (gSaveContext.language == LANGUAGE_GER) { - doActionOffset = LANGUAGE_GER * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_GER * DO_ACTION_MAX + DO_ACTION_ATTACK) * DO_ACTION_TEX_SIZE; } else { - doActionOffset = LANGUAGE_FRA * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_FRA * DO_ACTION_MAX + DO_ACTION_ATTACK) * DO_ACTION_TEX_SIZE; } #endif @@ -71,17 +71,17 @@ void Interface_Init(PlayState* play) { #if OOT_NTSC if (gSaveContext.language == LANGUAGE_JPN) { - doActionOffset = 3 * DO_ACTION_TEX_SIZE + LANGUAGE_JPN * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_JPN * DO_ACTION_MAX + DO_ACTION_RETURN) * DO_ACTION_TEX_SIZE; } else { - doActionOffset = 3 * DO_ACTION_TEX_SIZE + LANGUAGE_ENG * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_ENG * DO_ACTION_MAX + DO_ACTION_RETURN) * DO_ACTION_TEX_SIZE; } #else if (gSaveContext.language == LANGUAGE_ENG) { - doActionOffset = 3 * DO_ACTION_TEX_SIZE + LANGUAGE_ENG * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_ENG * DO_ACTION_MAX + DO_ACTION_RETURN) * DO_ACTION_TEX_SIZE; } else if (gSaveContext.language == LANGUAGE_GER) { - doActionOffset = 3 * DO_ACTION_TEX_SIZE + LANGUAGE_GER * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_GER * DO_ACTION_MAX + DO_ACTION_RETURN) * DO_ACTION_TEX_SIZE; } else { - doActionOffset = 3 * DO_ACTION_TEX_SIZE + LANGUAGE_FRA * DO_ACTION_MAX * DO_ACTION_TEX_SIZE; + doActionOffset = (LANGUAGE_FRA * DO_ACTION_MAX + DO_ACTION_RETURN) * DO_ACTION_TEX_SIZE; } #endif @@ -326,7 +326,7 @@ void Regs_InitDataImpl(void) { ZREG(10) = 200; ZREG(11) = 0; ZREG(12) = 200; - ZREG(13) = 0; + R_PAUSE_PAGE_SWITCH_FRAME_ADVANCE_ON = false; ZREG(14) = 110; ZREG(15) = 56; ZREG(16) = 1; @@ -619,11 +619,12 @@ void Regs_InitDataImpl(void) { R_MINIMAP_COLOR(2) = 255; } - VREG(21) = 0; - VREG(22) = 0; - VREG(23) = 0; - VREG(24) = 0; - VREG(25) = 0; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_A) = 0; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_DOWN) = 0; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_RIGHT) = 0; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_LEFT) = 0; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_UP) = 0; + VREG(26) = 0; VREG(27) = 0; R_OCARINA_BUTTONS_XPOS = 98; @@ -649,7 +650,7 @@ void Regs_InitDataImpl(void) { R_OCARINA_BUTTONS_YPOS(2) = 176; R_OCARINA_BUTTONS_YPOS(3) = 172; R_OCARINA_BUTTONS_YPOS(4) = 170; - VREG(50) = 30; + R_OCARINA_BUTTONS_APPEAR_ALPHA_STEP = 30; R_OCARINA_BUTTONS_YPOS_OFFSET = 0; VREG(52) = -16; VREG(53) = 230; diff --git a/src/code/z_kaleido_setup.c b/src/code/z_kaleido_setup.c index 1079cd0838..990b1c0405 100644 --- a/src/code/z_kaleido_setup.c +++ b/src/code/z_kaleido_setup.c @@ -144,7 +144,7 @@ void KaleidoSetup_Init(PlayState* play) { pauseCtx->cursorPoint[PAUSE_ITEM] = 0; pauseCtx->cursorPoint[PAUSE_MAP] = VREG(30) + 3; - pauseCtx->cursorPoint[PAUSE_QUEST] = 0; + pauseCtx->cursorPoint[PAUSE_QUEST] = QUEST_MEDALLION_FOREST; pauseCtx->cursorPoint[PAUSE_EQUIP] = 1; pauseCtx->cursorPoint[PAUSE_WORLD_MAP] = 10; diff --git a/src/code/z_message.c b/src/code/z_message.c index fe60644dd5..1bd060944f 100644 --- a/src/code/z_message.c +++ b/src/code/z_message.c @@ -3889,7 +3889,7 @@ void Message_DrawMain(PlayState* play, Gfx** p) { if (1) {} if (sOcarinaButtonAlphaValues[i] != 255) { - sOcarinaButtonAlphaValues[i] += VREG(50); + sOcarinaButtonAlphaValues[i] += R_OCARINA_BUTTONS_APPEAR_ALPHA_STEP; if (sOcarinaButtonAlphaValues[i] >= 255) { sOcarinaButtonAlphaValues[i] = 255; } diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index c7289316cc..a2959e0ade 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2125,9 +2125,9 @@ void Interface_LoadActionLabel(InterfaceContext* interfaceCtx, u16 action, s16 l #endif #if OOT_VERSION < PAL_1_0 - if ((action != DO_ACTION_NONE) && (action != DO_ACTION_MAX + DO_ACTION_NONE)) + if ((action != 0 * DO_ACTION_MAX + DO_ACTION_NONE) && (action != 1 * DO_ACTION_MAX + DO_ACTION_NONE)) #else - if ((action != DO_ACTION_NONE) && (action != DO_ACTION_MAX + DO_ACTION_NONE) && + if ((action != 0 * DO_ACTION_MAX + DO_ACTION_NONE) && (action != 1 * DO_ACTION_MAX + DO_ACTION_NONE) && (action != 2 * DO_ACTION_MAX + DO_ACTION_NONE)) #endif { diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 61a2eb1f61..ef4d6cd779 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1135,7 +1135,10 @@ static void* sQuestItemTextures[] = { static s16 sQuestItemRed[] = { 255, 255, 255, 0, 255, 0, 255, 200, 200 }; static s16 sQuestItemGreen[] = { 255, 255, 255, 255, 60, 100, 130, 50, 200 }; static s16 sQuestItemBlue[] = { 255, 255, 255, 0, 0, 255, 0, 255, 0 }; -static s16 sQuestItemFlags[] = { 0x0012, 0x0013, 0x0014, 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005 }; +static s16 sQuestItemFlags[] = { + QUEST_KOKIRI_EMERALD, QUEST_GORON_RUBY, QUEST_ZORA_SAPPHIRE, QUEST_MEDALLION_FOREST, QUEST_MEDALLION_FIRE, + QUEST_MEDALLION_WATER, QUEST_MEDALLION_SPIRIT, QUEST_MEDALLION_SHADOW, QUEST_MEDALLION_LIGHT, +}; #if OOT_NTSC && OOT_VERSION < GC_JP_CE static void* sSaveXTextures[] = { gFileSelSaveXJPNTex, gFileSelSaveXENGTex }; diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c index 7a9d3b5e78..4828f726eb 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c @@ -578,7 +578,7 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { sHpPrimBlue = sHpPrimColors[sHpPrimState][2]; sHpPrimAlpha = sHpPrimColors[sHpPrimState][3]; sHpPrimTimer = ZREG(24 + sHpPrimState); - if (++sHpPrimState >= 4) { + if (++sHpPrimState >= ARRAY_COUNT(sHpPrimColors)) { sHpPrimState = 0; } } diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_map.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_map.c index 4b964dff86..b873337030 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_map.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_map.c @@ -648,7 +648,7 @@ void KaleidoScope_DrawWorldMap(PlayState* play, GraphicsContext* gfxCtx) { gDPSetTextureLUT(POLY_OPA_DISP++, G_TT_RGBA16); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, pauseCtx->alpha); - gSPVertex(POLY_OPA_DISP++, &pauseCtx->mapPageVtx[188], 32, 0); + gSPVertex(POLY_OPA_DISP++, &pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_IMAGE_FIRST) * 4], 32, 0); for (j = t = i = 0; i < 8; i++, t++, j += 4) { gDPLoadTextureBlock( @@ -659,7 +659,7 @@ void KaleidoScope_DrawWorldMap(PlayState* play, GraphicsContext* gfxCtx) { gSP1Quadrangle(POLY_OPA_DISP++, j, j + 2, j + 3, j + 1, 0); } - gSPVertex(POLY_OPA_DISP++, &pauseCtx->mapPageVtx[220], 28, 0); + gSPVertex(POLY_OPA_DISP++, &pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_IMAGE_FIRST + 8) * 4], 28, 0); for (j = i = 0; i < 6; i++, t++, j += 4) { gDPLoadTextureBlock( @@ -681,8 +681,9 @@ void KaleidoScope_DrawWorldMap(PlayState* play, GraphicsContext* gfxCtx) { gSPLoadUcodeL(gfx++, gspS2DEX2d_fifo); - Room_DrawBackground2D(&gfx, gWorldMapImageTex, gWorldMapImageTLUT, 216, 128, G_IM_FMT_CI, G_IM_SIZ_8b, - G_TT_RGBA16, 256, HREG(13) / 100.0f, HREG(14) / 100.0f); + Room_DrawBackground2D(&gfx, gWorldMapImageTex, gWorldMapImageTLUT, WORLD_MAP_IMAGE_WIDTH, + WORLD_MAP_IMAGE_HEIGHT, G_IM_FMT_CI, G_IM_SIZ_8b, G_TT_RGBA16, 256, HREG(13) / 100.0f, + HREG(14) / 100.0f); gSPLoadUcode(gfx++, SysUcode_GetUCode(), SysUcode_GetUCodeData()); @@ -764,25 +765,33 @@ void KaleidoScope_DrawWorldMap(PlayState* play, GraphicsContext* gfxCtx) { // Quad PAGE_BG_QUADS + WORLD_MAP_QUAD_28 - pauseCtx->mapPageVtx[172].v.ob[0] = pauseCtx->mapPageVtx[174].v.ob[0] = - areaBoxPosX[((void)0, gSaveContext.worldMapArea)]; + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 0].v.ob[0] = + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 2].v.ob[0] = + areaBoxPosX[((void)0, gSaveContext.worldMapArea)]; - pauseCtx->mapPageVtx[173].v.ob[0] = pauseCtx->mapPageVtx[175].v.ob[0] = - pauseCtx->mapPageVtx[172].v.ob[0] + areaBoxWidths[((void)0, gSaveContext.worldMapArea)]; + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 1].v.ob[0] = + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 3].v.ob[0] = + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 0].v.ob[0] + + areaBoxWidths[((void)0, gSaveContext.worldMapArea)]; - pauseCtx->mapPageVtx[172].v.ob[1] = pauseCtx->mapPageVtx[173].v.ob[1] = - areaBoxPosY[((void)0, gSaveContext.worldMapArea)] + pauseCtx->pagesYOrigin1; + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 0].v.ob[1] = + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 1].v.ob[1] = + areaBoxPosY[((void)0, gSaveContext.worldMapArea)] + pauseCtx->pagesYOrigin1; - pauseCtx->mapPageVtx[174].v.ob[1] = pauseCtx->mapPageVtx[175].v.ob[1] = - pauseCtx->mapPageVtx[172].v.ob[1] - areaBoxHeights[((void)0, gSaveContext.worldMapArea)]; + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 2].v.ob[1] = + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 3].v.ob[1] = + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 0].v.ob[1] - + areaBoxHeights[((void)0, gSaveContext.worldMapArea)]; - pauseCtx->mapPageVtx[173].v.tc[0] = pauseCtx->mapPageVtx[175].v.tc[0] = - areaBoxWidths[((void)0, gSaveContext.worldMapArea)] << 5; + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 1].v.tc[0] = + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 3].v.tc[0] = + areaBoxWidths[((void)0, gSaveContext.worldMapArea)] << 5; - pauseCtx->mapPageVtx[174].v.tc[1] = pauseCtx->mapPageVtx[175].v.tc[1] = - areaBoxHeights[((void)0, gSaveContext.worldMapArea)] << 5; + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 2].v.tc[1] = + pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4 + 3].v.tc[1] = + areaBoxHeights[((void)0, gSaveContext.worldMapArea)] << 5; - gSPVertex(POLY_OPA_DISP++, &pauseCtx->mapPageVtx[172], 4, 0); + gSPVertex(POLY_OPA_DISP++, &pauseCtx->mapPageVtx[(PAGE_BG_QUADS + WORLD_MAP_QUAD_28) * 4], 4, 0); gDPSetCombineMode(POLY_OPA_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 100, 255, 255, pauseCtx->alpha); diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c index 3ae7c53313..71104dd545 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope.c @@ -2494,10 +2494,12 @@ s16 KaleidoScope_SetPageVertices(PlayState* play, Vtx* vtx, s16 vtxPage, s16 num pageBgQuadX = 0 - (PAGE_BG_COLS * PAGE_BG_QUAD_WIDTH) / 2 - PAGE_BG_QUAD_WIDTH; - for (bufI = 0, j = 0; j < 3; j++) { + // For each column + for (bufI = 0, j = 0; j < PAGE_BG_COLS; j++) { pageBgQuadX += PAGE_BG_QUAD_WIDTH; - for (pageBgQuadY = (PAGE_BG_ROWS * PAGE_BG_QUAD_HEIGHT) / 2, i = 0; i < 5; + // For each row + for (pageBgQuadY = (PAGE_BG_ROWS * PAGE_BG_QUAD_HEIGHT) / 2, i = 0; i < PAGE_BG_ROWS; i++, bufI += 4, pageBgQuadY -= PAGE_BG_QUAD_HEIGHT) { vtx[bufI + 0].v.ob[0] = vtx[bufI + 2].v.ob[0] = pageBgQuadX; @@ -2579,9 +2581,9 @@ s16 KaleidoScope_SetPageVertices(PlayState* play, Vtx* vtx, s16 vtxPage, s16 num } if (vtxPage == VTX_PAGE_MAP_WORLD) { - // For world map page, initialize vtx beyond VTX_PAGE_MAP_WORLD_QUADS + // WORLD_MAP_QUAD_TRADE_QUEST_MARKER - bufI -= 12; + bufI -= ((VTX_PAGE_MAP_WORLD_QUADS - WORLD_MAP_QUAD_TRADE_QUEST_MARKER) * 4); j = gSaveContext.worldMapArea; @@ -2595,7 +2597,7 @@ s16 KaleidoScope_SetPageVertices(PlayState* play, Vtx* vtx, s16 vtxPage, s16 num vtx[bufI + 2].v.ob[1] = vtx[bufI + 3].v.ob[1] = vtx[bufI + 0].v.ob[1] - sVtxMapWorldAreaHeight[j]; - bufI += 12; + bufI += ((VTX_PAGE_MAP_WORLD_QUADS - WORLD_MAP_QUAD_TRADE_QUEST_MARKER) * 4); if (pauseCtx->tradeQuestMarker != TRADE_QUEST_MARKER_NONE) { if (sTradeQuestMarkerBobTimer == 0) { @@ -2893,7 +2895,7 @@ void KaleidoScope_SetVertices(PlayState* play, GraphicsContext* gfxCtx) { pauseCtx->questPageVtx = GRAPH_ALLOC(gfxCtx, ((PAGE_BG_QUADS + VTX_PAGE_QUEST_QUADS) * 4) * sizeof(Vtx)); KaleidoScope_SetPageVertices(play, pauseCtx->questPageVtx, VTX_PAGE_QUEST, VTX_PAGE_QUEST_QUADS); - pauseCtx->cursorVtx = GRAPH_ALLOC(gfxCtx, PAUSE_CURSOR_QUAD_MAX * 4 * sizeof(Vtx)); + pauseCtx->cursorVtx = GRAPH_ALLOC(gfxCtx, (PAUSE_CURSOR_QUAD_MAX * 4) * sizeof(Vtx)); for (i = 0; i < (PAUSE_CURSOR_QUAD_MAX * 4); i++) { pauseCtx->cursorVtx[i].v.ob[0] = pauseCtx->cursorVtx[i].v.ob[1] = pauseCtx->cursorVtx[i].v.ob[2] = 0; @@ -2925,6 +2927,7 @@ void KaleidoScope_SetVertices(PlayState* play, GraphicsContext* gfxCtx) { pauseCtx->itemVtx = GRAPH_ALLOC(gfxCtx, (ITEM_QUAD_MAX * 4) * sizeof(Vtx)); // ITEM_QUAD_GRID_FIRST to ITEM_QUAD_GRID_LAST + for (k = 0, i = 0, y = (ITEM_GRID_ROWS * ITEM_GRID_CELL_HEIGHT) / 2 - 6; k < ITEM_GRID_ROWS; k++, y -= ITEM_GRID_CELL_HEIGHT) { for (x = 0 - (ITEM_GRID_COLS * ITEM_GRID_CELL_WIDTH) / 2, j = 0; j < ITEM_GRID_COLS; @@ -3396,11 +3399,11 @@ void KaleidoScope_UpdateOpening(PlayState* play) { func_80084BF4(play, 1); - gSaveContext.buttonStatus[0] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex][0]; - gSaveContext.buttonStatus[1] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex][1]; - gSaveContext.buttonStatus[2] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex][2]; - gSaveContext.buttonStatus[3] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex][3]; - gSaveContext.buttonStatus[4] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex][4]; + gSaveContext.buttonStatus[0] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex + PAGE_SWITCH_PT_LEFT][0]; + gSaveContext.buttonStatus[1] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex + PAGE_SWITCH_PT_LEFT][1]; + gSaveContext.buttonStatus[2] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex + PAGE_SWITCH_PT_LEFT][2]; + gSaveContext.buttonStatus[3] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex + PAGE_SWITCH_PT_LEFT][3]; + gSaveContext.buttonStatus[4] = gPageSwitchNextButtonStatus[pauseCtx->pageIndex + PAGE_SWITCH_PT_LEFT][4]; pauseCtx->pageIndex = sPageSwitchNextPageIndex[pauseCtx->nextPageMode]; @@ -3583,8 +3586,10 @@ void KaleidoScope_Update(PlayState* play) { if ((((u32)pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE) || (pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE_CURSOR_ON_SONG)) && (pauseCtx->state == PAUSE_STATE_MAIN)) { + pauseCtx->stickAdjX = input->rel.stick_x; pauseCtx->stickAdjY = input->rel.stick_y; + KaleidoScope_UpdateCursorVtx(play); KaleidoScope_HandlePageToggles(pauseCtx, input); } else if ((pauseCtx->pageIndex == PAUSE_QUEST) && ((pauseCtx->mainState < PAUSE_MAIN_STATE_3) || @@ -4028,7 +4033,7 @@ void KaleidoScope_Update(PlayState* play) { break; case PAUSE_MAIN_STATE_SWITCHING_PAGE: - KaleidoScope_UpdatePageSwitch(play, play->state.input); + KaleidoScope_UpdatePageSwitch(play, &play->state.input[0]); break; case PAUSE_MAIN_STATE_SONG_PLAYBACK: