From 2241635ac5230254a3c1ee67b1364a86959fec25 Mon Sep 17 00:00:00 2001 From: Cardboy777 <22593559+Cardboy777@users.noreply.github.com> Date: Tue, 14 Feb 2023 21:14:42 -0500 Subject: [PATCH] Option for link's models reflect the projectile weapon he's holding (Bow/Slingshot) (#2454) * Link's models reflect the projectile weapon he's holding extracted logic from months-old PR * apply bow/slingshot model changes only if 'gBowSlingShotAmmoFix' is enabled * Apply suggestions from code review Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com> * whitespace --------- Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com> --- soh/include/functions.h | 2 + soh/src/code/z_player_lib.c | 56 ++++++++++++++++--- .../actors/ovl_player_actor/z_player.c | 10 ++-- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/soh/include/functions.h b/soh/include/functions.h index 1befbf8aa..ac6375e5d 100644 --- a/soh/include/functions.h +++ b/soh/include/functions.h @@ -1120,6 +1120,8 @@ s32 Player_HasMirrorShieldEquipped(PlayState* play); s32 Player_HasMirrorShieldSetToDraw(PlayState* play); s32 Player_ActionToMagicSpell(Player* player, s32 actionParam); s32 Player_HoldsHookshot(Player* player); +s32 Player_HoldsBow(Player* player); +s32 Player_HoldsSlingshot(Player* player); s32 func_8008F128(Player* player); s32 Player_ActionToSword(s32 actionParam); s32 Player_GetSwordHeld(Player* player); diff --git a/soh/src/code/z_player_lib.c b/soh/src/code/z_player_lib.c index da7dff3e5..2ea70cdde 100644 --- a/soh/src/code/z_player_lib.c +++ b/soh/src/code/z_player_lib.c @@ -380,13 +380,23 @@ void Player_SetModelsForHoldingShield(Player* this) { } void Player_SetModels(Player* this, s32 modelGroup) { + // Left hand this->leftHandType = gPlayerModelTypes[modelGroup][1]; + this->leftHandDLists = &sPlayerDListGroups[this->leftHandType][gSaveContext.linkAge]; + + // Right hand this->rightHandType = gPlayerModelTypes[modelGroup][2]; - this->sheathType = gPlayerModelTypes[modelGroup][3]; + this->rightHandDLists = &sPlayerDListGroups[this->rightHandType][gSaveContext.linkAge]; - this->leftHandDLists = &sPlayerDListGroups[gPlayerModelTypes[modelGroup][1]][gSaveContext.linkAge]; - this->rightHandDLists = &sPlayerDListGroups[gPlayerModelTypes[modelGroup][2]][gSaveContext.linkAge]; - this->sheathDLists = &sPlayerDListGroups[gPlayerModelTypes[modelGroup][3]][gSaveContext.linkAge]; + if (CVarGetInteger("gBowSlingShotAmmoFix", 0) && this->rightHandType == 11) { // If holding Bow/Slingshot + this->rightHandDLists = &sPlayerDListGroups[this->rightHandType][Player_HoldsSlingshot(this)]; + } + + // Sheath + this->sheathType = gPlayerModelTypes[modelGroup][3]; + this->sheathDLists = &sPlayerDListGroups[this->sheathType][gSaveContext.linkAge]; + + // Waist this->waistDLists = &sPlayerDListGroups[gPlayerModelTypes[modelGroup][4]][gSaveContext.linkAge]; Player_SetModelsForHoldingShield(this); @@ -539,6 +549,22 @@ s32 Player_HoldsHookshot(Player* this) { return (this->heldItemAction == PLAYER_IA_HOOKSHOT) || (this->heldItemAction == PLAYER_IA_LONGSHOT); } +s32 Player_HoldsBow(Player* this) { + switch(this->heldItemAction){ + case PLAYER_IA_BOW: + case PLAYER_IA_BOW_FIRE: + case PLAYER_IA_BOW_ICE: + case PLAYER_IA_BOW_LIGHT: + return true; + default: + return false; + } +} + +s32 Player_HoldsSlingshot(Player* this) { + return this->heldItemAction == PLAYER_IA_SLINGSHOT; +} + s32 func_8008F128(Player* this) { return Player_HoldsHookshot(this) && (this->heldActor == NULL); } @@ -1067,14 +1093,26 @@ s32 func_800902F0(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s } else if (limbIndex == PLAYER_LIMB_L_FOREARM) { *dList = sArmOutDLs[gSaveContext.linkAge]; } else if (limbIndex == PLAYER_LIMB_L_HAND) { - *dList = sHandOutDLs[gSaveContext.linkAge]; + s32 handOutDlIndex = gSaveContext.linkAge; + if (CVarGetInteger("gBowSlingShotAmmoFix", 0) && LINK_IS_ADULT && Player_HoldsSlingshot(this)) { + handOutDlIndex = 1; + } + *dList = sHandOutDLs[handOutDlIndex]; } else if (limbIndex == PLAYER_LIMB_R_SHOULDER) { *dList = sRightShoulderNearDLs[gSaveContext.linkAge]; } else if (limbIndex == PLAYER_LIMB_R_FOREARM) { *dList = D_80125F30[gSaveContext.linkAge]; } else if (limbIndex == PLAYER_LIMB_R_HAND) { + s32 firstPersonWeaponIndex = gSaveContext.linkAge; + if (CVarGetInteger("gBowSlingShotAmmoFix", 0)) { + if (Player_HoldsBow(this)) { + firstPersonWeaponIndex = 0; + } else if (Player_HoldsSlingshot(this)) { + firstPersonWeaponIndex = 1; + } + } *dList = Player_HoldsHookshot(this) ? gLinkAdultRightHandHoldingHookshotFarDL - : sHoldingFirstPersonWeaponDLs[gSaveContext.linkAge]; + : sHoldingFirstPersonWeaponDLs[firstPersonWeaponIndex]; } else { *dList = NULL; } @@ -1447,7 +1485,11 @@ void func_80090D20(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void if (this->rightHandType == 0xFF) { Matrix_Get(&this->shieldMf); } else if ((this->rightHandType == 11) || (this->rightHandType == 12)) { - BowStringData* stringData = &sBowStringData[gSaveContext.linkAge]; + s32 stringModelToUse = gSaveContext.linkAge; + if(CVarGetInteger("gBowSlingShotAmmoFix", 0)){ + stringModelToUse = Player_HoldsSlingshot(this); + } + BowStringData* stringData = &sBowStringData[stringModelToUse]; OPEN_DISPS(play->state.gfxCtx); diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 438d5f7d0..830cc6013 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -4920,11 +4920,13 @@ s32 func_8083AD4C(PlayState* play, Player* this) { if (this->unk_6AD == 2) { if (func_8002DD6C(this)) { - if (LINK_IS_ADULT) { - cameraMode = CAM_MODE_BOWARROW; - } else { - cameraMode = CAM_MODE_SLINGSHOT; + bool shouldUseBowCamera = LINK_IS_ADULT; + + if(CVarGetInteger("gBowSlingShotAmmoFix", 0)){ + shouldUseBowCamera = this->heldItemAction != PLAYER_IA_SLINGSHOT; } + + cameraMode = shouldUseBowCamera ? CAM_MODE_BOWARROW : CAM_MODE_SLINGSHOT; } else { cameraMode = CAM_MODE_BOOMERANG; }