From fb60c5c97878f7e118ef9e1e555ea1bf3354c7bc Mon Sep 17 00:00:00 2001 From: Pablo <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:08:51 +0100 Subject: [PATCH 1/8] Document Player_Action_8084EAC0 --- include/z64player.h | 1 + .../actors/ovl_player_actor/z_player.c | 88 ++++++++++++------- 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/include/z64player.h b/include/z64player.h index d44da08ae8e..6d3749206ef 100644 --- a/include/z64player.h +++ b/include/z64player.h @@ -927,6 +927,7 @@ typedef struct Player { s16 csDelayTimer; // Player_Action_WaitForCutscene: Number of frames to wait before responding to a cutscene s16 playedLandingSfx; // Player_Action_BlueWarpArrive: Played sfx when landing on the ground s16 appearTimer; // Player_Action_FaroresWindArrive: Counts up, appear at 20 frames (1 second) + s16 drinkingState; // Player_Action_DrinkFromBottle: Uses values 0-2 to determine which part of the drinking action is currently active } av2; // "Action Variable 2": context dependent variable that has different meanings depending on what action is currently running /* 0x0854 */ f32 unk_854; diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 8ce71a84804..68667ac8049 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -304,7 +304,7 @@ void Player_Action_8084E3C4(Player* this, PlayState* play); void Player_Action_8084E604(Player* this, PlayState* play); void Player_Action_8084E6D4(Player* this, PlayState* play); void Player_Action_TimeTravelEnd(Player* this, PlayState* play); -void Player_Action_8084EAC0(Player* this, PlayState* play); +void Player_Action_DrinkFromBottle(Player* this, PlayState* play); void Player_Action_SwingBottle(Player* this, PlayState* play); void Player_Action_8084EED8(Player* this, PlayState* play); void Player_Action_8084EFC0(Player* this, PlayState* play); @@ -6097,7 +6097,7 @@ s32 Player_ActionHandler_13(Player* this, PlayState* play) { Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_fish_out); func_80835EA4(play, (sp2C == 1) ? 1 : 5); } else { - Player_SetupActionPreserveItemAction(play, this, Player_Action_8084EAC0, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_DrinkFromBottle, 0); Player_AnimChangeOnceMorphAdjusted(play, this, &gPlayerAnim_link_bottle_drink_demo_start); func_80835EA4(play, 2); } @@ -6417,7 +6417,7 @@ void func_8083C0B8(Player* this, PlayState* play) { func_8083BF50(this, play); } -void func_8083C0E8(Player* this, PlayState* play) { +void Player_SetupIdleAndPlayIdleAnim(Player* this, PlayState* play) { Player_SetupAction(play, this, Player_Action_Idle, 1); Player_AnimPlayOnce(play, this, Player_GetIdleAnim(this)); this->yaw = this->actor.shape.rot.y; @@ -8660,7 +8660,7 @@ void Player_Action_TurnInPlace(Player* this, PlayState* play) { this->actor.shape.rot.y = yawTarget; func_8083C858(this, play); } else if (Math_ScaledStepToS(&this->actor.shape.rot.y, yawTarget, this->turnRate)) { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); } this->yaw = this->actor.shape.rot.y; @@ -10060,7 +10060,7 @@ void Player_Action_80845668(Player* this, PlayState* play) { } if ((sp3C != 0) || (interruptResult >= PLAYER_INTERRUPT_MOVE)) { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); this->stateFlags1 &= ~(PLAYER_STATE1_14 | PLAYER_STATE1_18); return; } @@ -10268,7 +10268,7 @@ void Player_Action_80845EF8(Player* this, PlayState* play) { this->skelAnime.endFrame = this->skelAnime.animLength - 1.0f; } } else { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); if (play->roomCtx.prevRoom.num >= 0) { Room_FinishRoomChange(play, &play->roomCtx); } @@ -12778,7 +12778,7 @@ void Player_Action_8084BDFC(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { Player_ApplyAnimMovementScaledByAge(this, ANIM_FLAG_UPDATE_XZ); - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); return; } @@ -12967,7 +12967,7 @@ void Player_Action_8084C5F8(Player* this, PlayState* play) { } if ((interruptResult >= PLAYER_INTERRUPT_MOVE) || LinkAnimation_Update(play, &this->skelAnime)) { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); this->stateFlags1 &= ~PLAYER_STATE1_21; return; } @@ -13044,7 +13044,7 @@ void Player_Action_8084C81C(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { // Player is finished exiting the crawlspace and control is returned - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); this->stateFlags2 &= ~PLAYER_STATE2_CRAWLING; return; } @@ -13380,7 +13380,7 @@ void Player_Action_8084D3E4(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { EnHorse* rideActor = (EnHorse*)this->rideActor; - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); this->stateFlags1 &= ~PLAYER_STATE1_23; this->actor.parent = NULL; AREG(6) = 0; @@ -13649,7 +13649,7 @@ void func_8084DF6C(PlayState* play, Player* this) { void func_8084DFAC(PlayState* play, Player* this) { func_8084DF6C(play, this); Player_ApplyYawFromAnim(this); - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); this->yaw = this->actor.shape.rot.y; } @@ -13870,7 +13870,7 @@ void Player_Action_8084E6D4(Player* this, PlayState* play) { if (this->getItemId != GI_ICE_TRAP) { Actor_Spawn(&play->actorCtx, play, ACTOR_EN_CLEAR_TAG, this->actor.world.pos.x, this->actor.world.pos.y + 100.0f, this->actor.world.pos.z, 0, 0, 0, 0); - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); } else { this->actor.colChkInfo.damage = 0; func_80837C0C(play, this, PLAYER_HIT_RESPONSE_ICE_TRAP, 0.0f, 0.0f, 0, 20); @@ -13924,7 +13924,7 @@ void Player_Action_TimeTravelEnd(Player* this, PlayState* play) { this->skelAnime.endFrame = this->skelAnime.animLength - 1.0f; } } else { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); } } else { if (LINK_IS_ADULT && LinkAnimation_OnFrame(&this->skelAnime, 158.0f)) { @@ -13955,13 +13955,24 @@ void Player_Action_TimeTravelEnd(Player* this, PlayState* play) { } } -void Player_Action_8084EAC0(Player* this, PlayState* play) { - if (LinkAnimation_Update(play, &this->skelAnime)) { - if (this->av2.actionVar2 == 0) { - static u8 D_808549FC[] = { - 0x01, 0x03, 0x02, 0x04, 0x04, - }; +// Restores 14 hearts, is overriden by BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL +#define BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG 0x01 +// Fully restores magic +#define BOTTLE_CONTENT_DRINK_FLAG_MAGIC 0x02 +// Restores 5 hearts, overrides BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG +#define BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL 0x04 +typedef enum DrinkingState { + /* 0 */ DRINGING_STATE_SETUP, + /* 1 */ DRINGING_STATE_DRINKING, + /* 2 */ DRINGING_STATE_FINISHED +} DrinkingState; + +void Player_Action_DrinkFromBottle(Player* this, PlayState* play) { + // When an animation finishes (gPlayerAnim_link_bottle_drink_demo_start when drinkingState == DRINGING_STATE_SETUP, gPlayerAnim_link_bottle_drink_demo_end otherwise) + if (LinkAnimation_Update(play, &this->skelAnime)) { + if (this->av2.drinkingState == DRINGING_STATE_SETUP) { + // Special handling for the poe bottle if (this->itemAction == PLAYER_IA_BOTTLE_POE) { s32 rand = Rand_S16Offset(-1, 3); @@ -13969,6 +13980,7 @@ void Player_Action_8084EAC0(Player* this, PlayState* play) { rand = 3; } + // Prevents the drinking the poe from killing you if ((rand < 0) && (gSaveContext.save.info.playerData.health <= 0x10)) { rand = 3; } @@ -13979,35 +13991,43 @@ void Player_Action_8084EAC0(Player* this, PlayState* play) { gSaveContext.healthAccumulator = rand * 0x10; } } else { - s32 sp28 = D_808549FC[this->itemAction - PLAYER_IA_BOTTLE_POTION_RED]; + static u8 sBottleContentDrinkFlags[] = { + /* PLAYER_IA_BOTTLE_POTION_RED */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG, + /* PLAYER_IA_BOTTLE_POTION_BLUE */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG | BOTTLE_CONTENT_DRINK_FLAG_MAGIC, + /* PLAYER_IA_BOTTLE_POTION_GREEN */ BOTTLE_CONTENT_DRINK_FLAG_MAGIC, + /* PLAYER_IA_BOTTLE_MILK_FULL */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL, + /* PLAYER_IA_BOTTLE_MILK_HALF */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL, + }; + + s32 flags = sBottleContentDrinkFlags[this->itemAction - PLAYER_IA_BOTTLE_POTION_RED]; - if (sp28 & 1) { + if (flags & BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG) { gSaveContext.healthAccumulator = 0x140; } - if (sp28 & 2) { + if (flags & BOTTLE_CONTENT_DRINK_FLAG_MAGIC) { Magic_Fill(play); } - if (sp28 & 4) { + if (flags & BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL) { gSaveContext.healthAccumulator = 0x50; } } Player_AnimPlayLoopAdjusted(play, this, &gPlayerAnim_link_bottle_drink_demo_wait); - this->av2.actionVar2 = 1; + this->av2.drinkingState = DRINGING_STATE_DRINKING; } else { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); } - } else if (this->av2.actionVar2 == 1) { + } else if (this->av2.drinkingState == DRINGING_STATE_DRINKING) { if ((gSaveContext.healthAccumulator == 0) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { Player_AnimChangeOnceMorphAdjusted(play, this, &gPlayerAnim_link_bottle_drink_demo_end); - this->av2.actionVar2 = 2; + this->av2.drinkingState = DRINGING_STATE_FINISHED; Player_UpdateBottleHeld(play, this, ITEM_BOTTLE_EMPTY, PLAYER_IA_BOTTLE); } Player_PlayVoiceSfx(this, NA_SE_VO_LI_DRINK - SFX_FLAG); - } else if ((this->av2.actionVar2 == 2) && LinkAnimation_OnFrame(&this->skelAnime, 29.0f)) { + } else if ((this->av2.drinkingState == DRINGING_STATE_FINISHED) && LinkAnimation_OnFrame(&this->skelAnime, 29.0f)) { Player_PlayVoiceSfx(this, NA_SE_VO_LI_BREATH_DRINK); } } @@ -14054,7 +14074,7 @@ void Player_Action_SwingBottle(Player* this, PlayState* play) { Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); } } else { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); } } else if (this->av1.bottleCatchType == BOTTLE_CATCH_NONE) { s32 activeFrame = this->skelAnime.curFrame - swingEntry->firstActiveFrame; @@ -14093,7 +14113,7 @@ void Player_Action_SwingBottle(Player* this, PlayState* play) { } } - //! @bug If the animation is changed at any point above (such as by func_8083C0E8() or + //! @bug If the animation is changed at any point above (such as by Player_SetupIdleAndPlayIdleAnim() or //! Player_AnimPlayOnceAdjusted()), it will change the curFrame to 0. This causes this flag to be set for one frame, //! at a time when it does not look like Player is swinging the bottle. if (this->skelAnime.curFrame <= 7.0f) { @@ -14105,7 +14125,7 @@ static Vec3f D_80854A1C = { 0.0f, 0.0f, 5.0f }; void Player_Action_8084EED8(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); return; } @@ -14135,7 +14155,7 @@ void Player_Action_8084EFC0(Player* this, PlayState* play) { Player_DecelerateToZero(this); if (LinkAnimation_Update(play, &this->skelAnime)) { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); } else if (LinkAnimation_OnFrame(&this->skelAnime, 76.0f)) { BottleDropInfo* dropInfo = &D_80854A28[this->itemAction - PLAYER_IA_BOTTLE_FISH]; @@ -14160,7 +14180,7 @@ void Player_Action_ExchangeItem(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { if (this->av2.actionVar2 < 0) { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); } else if (this->exchangeItemId == EXCH_ITEM_NONE) { Actor* talkActor = this->talkActor; @@ -14195,7 +14215,7 @@ void Player_Action_ExchangeItem(Player* this, PlayState* play) { Player_AnimPlayOnce(play, this, &gPlayerAnim_link_bottle_read_end); this->av2.actionVar2 = -1; } else { - func_8083C0E8(this, play); + Player_SetupIdleAndPlayIdleAnim(this, play); } Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); From 3a0ac4a1ff975bfea8e562d9d9548f6df6e738c4 Mon Sep 17 00:00:00 2001 From: Pablo <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:16:46 +0100 Subject: [PATCH 2/8] Document Player_Action_8084EFC0 --- .../actors/ovl_player_actor/z_player.c | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 68667ac8049..4a455affa24 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -49,11 +49,6 @@ typedef struct ExplosiveInfo { /* 0x02 */ s16 actorId; } ExplosiveInfo; // size = 0x04 -typedef struct BottleDropInfo { - /* 0x00 */ s16 actorId; - /* 0x02 */ s16 actorParams; -} BottleDropInfo; // size = 0x04 - typedef struct FallImpactInfo { /* 0x00 */ s8 damage; /* 0x01 */ u8 rumbleStrength; @@ -307,7 +302,7 @@ void Player_Action_TimeTravelEnd(Player* this, PlayState* play); void Player_Action_DrinkFromBottle(Player* this, PlayState* play); void Player_Action_SwingBottle(Player* this, PlayState* play); void Player_Action_8084EED8(Player* this, PlayState* play); -void Player_Action_8084EFC0(Player* this, PlayState* play); +void Player_Action_DropFromBottle(Player* this, PlayState* play); void Player_Action_ExchangeItem(Player* this, PlayState* play); void Player_Action_SlideOnSlope(Player* this, PlayState* play); void Player_Action_WaitForCutscene(Player* this, PlayState* play); @@ -6093,7 +6088,7 @@ s32 Player_ActionHandler_13(Player* this, PlayState* play) { Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_bug_out); func_80835EA4(play, 3); } else if ((sp2C > 0) && (sp2C < 4)) { - Player_SetupActionPreserveItemAction(play, this, Player_Action_8084EFC0, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_DropFromBottle, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_fish_out); func_80835EA4(play, (sp2C == 1) ? 1 : 5); } else { @@ -14140,25 +14135,28 @@ void Player_Action_8084EED8(Player* this, PlayState* play) { } } -static BottleDropInfo D_80854A28[] = { - { ACTOR_EN_FISH, FISH_DROPPED }, - { ACTOR_EN_ICE_HONO, 0 }, - { ACTOR_EN_INSECT, INSECT_TYPE_FIRST_DROPPED }, -}; - -static AnimSfxEntry D_80854A34[] = { - { NA_SE_VO_LI_AUTO_JUMP, ANIMSFX_DATA(ANIMSFX_TYPE_VOICE, 38) }, - { NA_SE_EV_BOTTLE_CAP_OPEN, -ANIMSFX_DATA(ANIMSFX_TYPE_GENERAL, 40) }, -}; +typedef struct BottleDropInfo { + /* 0x00 */ s16 actorId; + /* 0x02 */ s16 actorParams; +} BottleDropInfo; // size = 0x04 -void Player_Action_8084EFC0(Player* this, PlayState* play) { +/** + * Drops an actor (fish, insects or blue fire) from a bottle. + */ +void Player_Action_DropFromBottle(Player* this, PlayState* play) { Player_DecelerateToZero(this); if (LinkAnimation_Update(play, &this->skelAnime)) { Player_SetupIdleAndPlayIdleAnim(this, play); Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); } else if (LinkAnimation_OnFrame(&this->skelAnime, 76.0f)) { - BottleDropInfo* dropInfo = &D_80854A28[this->itemAction - PLAYER_IA_BOTTLE_FISH]; + static BottleDropInfo sBottleDropInfos[] = { + /* PLAYER_IA_BOTTLE_FISH */ { ACTOR_EN_FISH, FISH_DROPPED }, + /* PLAYER_IA_BOTTLE_FIRE */ { ACTOR_EN_ICE_HONO, 0 }, + /* PLAYER_IA_BOTTLE_BUG */ { ACTOR_EN_INSECT, INSECT_TYPE_FIRST_DROPPED }, + }; + + BottleDropInfo* dropInfo = &sBottleDropInfos[this->itemAction - PLAYER_IA_BOTTLE_FISH]; Actor_Spawn(&play->actorCtx, play, dropInfo->actorId, (Math_SinS(this->actor.shape.rot.y) * 5.0f) + this->leftHandPos.x, this->leftHandPos.y, @@ -14167,7 +14165,12 @@ void Player_Action_8084EFC0(Player* this, PlayState* play) { Player_UpdateBottleHeld(play, this, ITEM_BOTTLE_EMPTY, PLAYER_IA_BOTTLE); } else { - Player_ProcessAnimSfxList(this, D_80854A34); + static AnimSfxEntry sBottleDropAnimSfx[] = { + { NA_SE_VO_LI_AUTO_JUMP, ANIMSFX_DATA(ANIMSFX_TYPE_VOICE, 38) }, + { NA_SE_EV_BOTTLE_CAP_OPEN, -ANIMSFX_DATA(ANIMSFX_TYPE_GENERAL, 40) }, + }; + + Player_ProcessAnimSfxList(this, sBottleDropAnimSfx); } } @@ -16067,7 +16070,7 @@ void Player_Action_CsAction(Player* this, PlayState* play) { int Player_IsDroppingFish(PlayState* play) { Player* this = GET_PLAYER(play); - return (Player_Action_8084EFC0 == this->actionFunc) && (this->itemAction == PLAYER_IA_BOTTLE_FISH); + return (Player_Action_DropFromBottle == this->actionFunc) && (this->itemAction == PLAYER_IA_BOTTLE_FISH); } s32 Player_StartFishing(PlayState* play) { From f47487a96cd82fab10de8e0c617fa4a5c1d5894a Mon Sep 17 00:00:00 2001 From: Pablo <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:20:38 +0100 Subject: [PATCH 3/8] Document Player_Action_8084EED8 --- src/overlays/actors/ovl_player_actor/z_player.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 4a455affa24..4bb995af379 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -301,7 +301,7 @@ void Player_Action_8084E6D4(Player* this, PlayState* play); void Player_Action_TimeTravelEnd(Player* this, PlayState* play); void Player_Action_DrinkFromBottle(Player* this, PlayState* play); void Player_Action_SwingBottle(Player* this, PlayState* play); -void Player_Action_8084EED8(Player* this, PlayState* play); +void Player_Action_UseFairyFromBottle(Player* this, PlayState* play); void Player_Action_DropFromBottle(Player* this, PlayState* play); void Player_Action_ExchangeItem(Player* this, PlayState* play); void Player_Action_SlideOnSlope(Player* this, PlayState* play); @@ -6084,7 +6084,7 @@ s32 Player_ActionHandler_13(Player* this, PlayState* play) { sp2C = Player_ActionToBottle(this, this->itemAction); if (sp2C >= 0) { if (sp2C == 0xC) { - Player_SetupActionPreserveItemAction(play, this, Player_Action_8084EED8, 0); + Player_SetupActionPreserveItemAction(play, this, Player_Action_UseFairyFromBottle, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_bug_out); func_80835EA4(play, 3); } else if ((sp2C > 0) && (sp2C < 4)) { @@ -14116,9 +14116,7 @@ void Player_Action_SwingBottle(Player* this, PlayState* play) { } } -static Vec3f D_80854A1C = { 0.0f, 0.0f, 5.0f }; - -void Player_Action_8084EED8(Player* this, PlayState* play) { +void Player_Action_UseFairyFromBottle(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { Player_SetupIdleAndPlayIdleAnim(this, play); Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); @@ -14126,7 +14124,9 @@ void Player_Action_8084EED8(Player* this, PlayState* play) { } if (LinkAnimation_OnFrame(&this->skelAnime, 37.0f)) { - Player_SpawnFairy(play, this, &this->leftHandPos, &D_80854A1C, FAIRY_REVIVE_BOTTLE); + static Vec3f sPositionOffset = { 0.0f, 0.0f, 5.0f }; + + Player_SpawnFairy(play, this, &this->leftHandPos, &sPositionOffset, FAIRY_REVIVE_BOTTLE); Player_UpdateBottleHeld(play, this, ITEM_BOTTLE_EMPTY, PLAYER_IA_BOTTLE); Player_PlaySfx(this, NA_SE_EV_BOTTLE_CAP_OPEN); Player_PlaySfx(this, NA_SE_EV_FIATY_HEAL - SFX_FLAG); From 0f390cfd7e3df3a62d820a0f9376ba66bbcd8a8b Mon Sep 17 00:00:00 2001 From: Pablo <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:58:51 +0100 Subject: [PATCH 4/8] Cleanup --- .../actors/ovl_player_actor/z_player.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 4bb995af379..9f284beb510 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -302,7 +302,7 @@ void Player_Action_TimeTravelEnd(Player* this, PlayState* play); void Player_Action_DrinkFromBottle(Player* this, PlayState* play); void Player_Action_SwingBottle(Player* this, PlayState* play); void Player_Action_UseFairyFromBottle(Player* this, PlayState* play); -void Player_Action_DropFromBottle(Player* this, PlayState* play); +void Player_Action_DropActorFromBottle(Player* this, PlayState* play); void Player_Action_ExchangeItem(Player* this, PlayState* play); void Player_Action_SlideOnSlope(Player* this, PlayState* play); void Player_Action_WaitForCutscene(Player* this, PlayState* play); @@ -6082,13 +6082,14 @@ s32 Player_ActionHandler_13(Player* this, PlayState* play) { } sp2C = Player_ActionToBottle(this, this->itemAction); - if (sp2C >= 0) { - if (sp2C == 0xC) { + #define ACTION_TO_BOTTLE_ACTION(action) (action - PLAYER_IA_BOTTLE) + if (sp2C >= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE)) { + if (sp2C == ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_FAIRY)) { Player_SetupActionPreserveItemAction(play, this, Player_Action_UseFairyFromBottle, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_bug_out); func_80835EA4(play, 3); - } else if ((sp2C > 0) && (sp2C < 4)) { - Player_SetupActionPreserveItemAction(play, this, Player_Action_DropFromBottle, 0); + } else if ((sp2C >= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_FISH)) && (sp2C <= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_BUG))) { + Player_SetupActionPreserveItemAction(play, this, Player_Action_DropActorFromBottle, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_fish_out); func_80835EA4(play, (sp2C == 1) ? 1 : 5); } else { @@ -14140,10 +14141,7 @@ typedef struct BottleDropInfo { /* 0x02 */ s16 actorParams; } BottleDropInfo; // size = 0x04 -/** - * Drops an actor (fish, insects or blue fire) from a bottle. - */ -void Player_Action_DropFromBottle(Player* this, PlayState* play) { +void Player_Action_DropActorFromBottle(Player* this, PlayState* play) { Player_DecelerateToZero(this); if (LinkAnimation_Update(play, &this->skelAnime)) { @@ -16070,7 +16068,7 @@ void Player_Action_CsAction(Player* this, PlayState* play) { int Player_IsDroppingFish(PlayState* play) { Player* this = GET_PLAYER(play); - return (Player_Action_DropFromBottle == this->actionFunc) && (this->itemAction == PLAYER_IA_BOTTLE_FISH); + return (Player_Action_DropActorFromBottle == this->actionFunc) && (this->itemAction == PLAYER_IA_BOTTLE_FISH); } s32 Player_StartFishing(PlayState* play) { From cf024497a27b1cee951cb40942d80fc293a6473b Mon Sep 17 00:00:00 2001 From: Pablo <72659707+Pepe20129@users.noreply.github.com> Date: Sat, 14 Dec 2024 00:49:48 +0100 Subject: [PATCH 5/8] Revert naming func_8083C0E8 --- .../actors/ovl_player_actor/z_player.c | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 9f284beb510..bf055ba36dc 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -6413,7 +6413,7 @@ void func_8083C0B8(Player* this, PlayState* play) { func_8083BF50(this, play); } -void Player_SetupIdleAndPlayIdleAnim(Player* this, PlayState* play) { +void func_8083C0E8(Player* this, PlayState* play) { Player_SetupAction(play, this, Player_Action_Idle, 1); Player_AnimPlayOnce(play, this, Player_GetIdleAnim(this)); this->yaw = this->actor.shape.rot.y; @@ -8656,7 +8656,7 @@ void Player_Action_TurnInPlace(Player* this, PlayState* play) { this->actor.shape.rot.y = yawTarget; func_8083C858(this, play); } else if (Math_ScaledStepToS(&this->actor.shape.rot.y, yawTarget, this->turnRate)) { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); } this->yaw = this->actor.shape.rot.y; @@ -10056,7 +10056,7 @@ void Player_Action_80845668(Player* this, PlayState* play) { } if ((sp3C != 0) || (interruptResult >= PLAYER_INTERRUPT_MOVE)) { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); this->stateFlags1 &= ~(PLAYER_STATE1_14 | PLAYER_STATE1_18); return; } @@ -10264,7 +10264,7 @@ void Player_Action_80845EF8(Player* this, PlayState* play) { this->skelAnime.endFrame = this->skelAnime.animLength - 1.0f; } } else { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); if (play->roomCtx.prevRoom.num >= 0) { Room_FinishRoomChange(play, &play->roomCtx); } @@ -12774,7 +12774,7 @@ void Player_Action_8084BDFC(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { Player_ApplyAnimMovementScaledByAge(this, ANIM_FLAG_UPDATE_XZ); - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); return; } @@ -12963,7 +12963,7 @@ void Player_Action_8084C5F8(Player* this, PlayState* play) { } if ((interruptResult >= PLAYER_INTERRUPT_MOVE) || LinkAnimation_Update(play, &this->skelAnime)) { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); this->stateFlags1 &= ~PLAYER_STATE1_21; return; } @@ -13040,7 +13040,7 @@ void Player_Action_8084C81C(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { // Player is finished exiting the crawlspace and control is returned - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); this->stateFlags2 &= ~PLAYER_STATE2_CRAWLING; return; } @@ -13376,7 +13376,7 @@ void Player_Action_8084D3E4(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { EnHorse* rideActor = (EnHorse*)this->rideActor; - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); this->stateFlags1 &= ~PLAYER_STATE1_23; this->actor.parent = NULL; AREG(6) = 0; @@ -13645,7 +13645,7 @@ void func_8084DF6C(PlayState* play, Player* this) { void func_8084DFAC(PlayState* play, Player* this) { func_8084DF6C(play, this); Player_ApplyYawFromAnim(this); - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); this->yaw = this->actor.shape.rot.y; } @@ -13866,7 +13866,7 @@ void Player_Action_8084E6D4(Player* this, PlayState* play) { if (this->getItemId != GI_ICE_TRAP) { Actor_Spawn(&play->actorCtx, play, ACTOR_EN_CLEAR_TAG, this->actor.world.pos.x, this->actor.world.pos.y + 100.0f, this->actor.world.pos.z, 0, 0, 0, 0); - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); } else { this->actor.colChkInfo.damage = 0; func_80837C0C(play, this, PLAYER_HIT_RESPONSE_ICE_TRAP, 0.0f, 0.0f, 0, 20); @@ -13920,7 +13920,7 @@ void Player_Action_TimeTravelEnd(Player* this, PlayState* play) { this->skelAnime.endFrame = this->skelAnime.animLength - 1.0f; } } else { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); } } else { if (LINK_IS_ADULT && LinkAnimation_OnFrame(&this->skelAnime, 158.0f)) { @@ -14013,7 +14013,7 @@ void Player_Action_DrinkFromBottle(Player* this, PlayState* play) { Player_AnimPlayLoopAdjusted(play, this, &gPlayerAnim_link_bottle_drink_demo_wait); this->av2.drinkingState = DRINGING_STATE_DRINKING; } else { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); } } else if (this->av2.drinkingState == DRINGING_STATE_DRINKING) { @@ -14070,7 +14070,7 @@ void Player_Action_SwingBottle(Player* this, PlayState* play) { Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); } } else { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); } } else if (this->av1.bottleCatchType == BOTTLE_CATCH_NONE) { s32 activeFrame = this->skelAnime.curFrame - swingEntry->firstActiveFrame; @@ -14109,7 +14109,7 @@ void Player_Action_SwingBottle(Player* this, PlayState* play) { } } - //! @bug If the animation is changed at any point above (such as by Player_SetupIdleAndPlayIdleAnim() or + //! @bug If the animation is changed at any point above (such as by func_8083C0E8() or //! Player_AnimPlayOnceAdjusted()), it will change the curFrame to 0. This causes this flag to be set for one frame, //! at a time when it does not look like Player is swinging the bottle. if (this->skelAnime.curFrame <= 7.0f) { @@ -14119,7 +14119,7 @@ void Player_Action_SwingBottle(Player* this, PlayState* play) { void Player_Action_UseFairyFromBottle(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); return; } @@ -14145,7 +14145,7 @@ void Player_Action_DropActorFromBottle(Player* this, PlayState* play) { Player_DecelerateToZero(this); if (LinkAnimation_Update(play, &this->skelAnime)) { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); } else if (LinkAnimation_OnFrame(&this->skelAnime, 76.0f)) { static BottleDropInfo sBottleDropInfos[] = { @@ -14181,7 +14181,7 @@ void Player_Action_ExchangeItem(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { if (this->av2.actionVar2 < 0) { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); } else if (this->exchangeItemId == EXCH_ITEM_NONE) { Actor* talkActor = this->talkActor; @@ -14216,7 +14216,7 @@ void Player_Action_ExchangeItem(Player* this, PlayState* play) { Player_AnimPlayOnce(play, this, &gPlayerAnim_link_bottle_read_end); this->av2.actionVar2 = -1; } else { - Player_SetupIdleAndPlayIdleAnim(this, play); + func_8083C0E8(this, play); } Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); From 1b54055813b154b286dd022e8fe09176adf080f5 Mon Sep 17 00:00:00 2001 From: Pablo <72659707+Pepe20129@users.noreply.github.com> Date: Sat, 14 Dec 2024 01:23:56 +0100 Subject: [PATCH 6/8] Hopefully fix build --- .../actors/ovl_player_actor/z_player.c | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index bf055ba36dc..8b8ce1fe97b 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -13968,6 +13968,14 @@ void Player_Action_DrinkFromBottle(Player* this, PlayState* play) { // When an animation finishes (gPlayerAnim_link_bottle_drink_demo_start when drinkingState == DRINGING_STATE_SETUP, gPlayerAnim_link_bottle_drink_demo_end otherwise) if (LinkAnimation_Update(play, &this->skelAnime)) { if (this->av2.drinkingState == DRINGING_STATE_SETUP) { + static u8 sBottleContentDrinkFlags[] = { + /* PLAYER_IA_BOTTLE_POTION_RED */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG, + /* PLAYER_IA_BOTTLE_POTION_BLUE */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG | BOTTLE_CONTENT_DRINK_FLAG_MAGIC, + /* PLAYER_IA_BOTTLE_POTION_GREEN */ BOTTLE_CONTENT_DRINK_FLAG_MAGIC, + /* PLAYER_IA_BOTTLE_MILK_FULL */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL, + /* PLAYER_IA_BOTTLE_MILK_HALF */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL, + }; + // Special handling for the poe bottle if (this->itemAction == PLAYER_IA_BOTTLE_POE) { s32 rand = Rand_S16Offset(-1, 3); @@ -13987,14 +13995,6 @@ void Player_Action_DrinkFromBottle(Player* this, PlayState* play) { gSaveContext.healthAccumulator = rand * 0x10; } } else { - static u8 sBottleContentDrinkFlags[] = { - /* PLAYER_IA_BOTTLE_POTION_RED */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG, - /* PLAYER_IA_BOTTLE_POTION_BLUE */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG | BOTTLE_CONTENT_DRINK_FLAG_MAGIC, - /* PLAYER_IA_BOTTLE_POTION_GREEN */ BOTTLE_CONTENT_DRINK_FLAG_MAGIC, - /* PLAYER_IA_BOTTLE_MILK_FULL */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL, - /* PLAYER_IA_BOTTLE_MILK_HALF */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL, - }; - s32 flags = sBottleContentDrinkFlags[this->itemAction - PLAYER_IA_BOTTLE_POTION_RED]; if (flags & BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG) { @@ -14117,6 +14117,8 @@ void Player_Action_SwingBottle(Player* this, PlayState* play) { } } +static Vec3f sBottleFairyPositionOffset = { 0.0f, 0.0f, 5.0f }; + void Player_Action_UseFairyFromBottle(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { func_8083C0E8(this, play); @@ -14125,9 +14127,7 @@ void Player_Action_UseFairyFromBottle(Player* this, PlayState* play) { } if (LinkAnimation_OnFrame(&this->skelAnime, 37.0f)) { - static Vec3f sPositionOffset = { 0.0f, 0.0f, 5.0f }; - - Player_SpawnFairy(play, this, &this->leftHandPos, &sPositionOffset, FAIRY_REVIVE_BOTTLE); + Player_SpawnFairy(play, this, &this->leftHandPos, &sBottleFairyPositionOffset, FAIRY_REVIVE_BOTTLE); Player_UpdateBottleHeld(play, this, ITEM_BOTTLE_EMPTY, PLAYER_IA_BOTTLE); Player_PlaySfx(this, NA_SE_EV_BOTTLE_CAP_OPEN); Player_PlaySfx(this, NA_SE_EV_FIATY_HEAL - SFX_FLAG); @@ -14141,6 +14141,17 @@ typedef struct BottleDropInfo { /* 0x02 */ s16 actorParams; } BottleDropInfo; // size = 0x04 +static BottleDropInfo sBottleDropInfos[] = { + /* PLAYER_IA_BOTTLE_FISH */ { ACTOR_EN_FISH, FISH_DROPPED }, + /* PLAYER_IA_BOTTLE_FIRE */ { ACTOR_EN_ICE_HONO, 0 }, + /* PLAYER_IA_BOTTLE_BUG */ { ACTOR_EN_INSECT, INSECT_TYPE_FIRST_DROPPED }, +}; + +static AnimSfxEntry sBottleDropAnimSfx[] = { + { NA_SE_VO_LI_AUTO_JUMP, ANIMSFX_DATA(ANIMSFX_TYPE_VOICE, 38) }, + { NA_SE_EV_BOTTLE_CAP_OPEN, -ANIMSFX_DATA(ANIMSFX_TYPE_GENERAL, 40) }, +}; + void Player_Action_DropActorFromBottle(Player* this, PlayState* play) { Player_DecelerateToZero(this); @@ -14148,12 +14159,6 @@ void Player_Action_DropActorFromBottle(Player* this, PlayState* play) { func_8083C0E8(this, play); Camera_SetFinishedFlag(Play_GetCamera(play, CAM_ID_MAIN)); } else if (LinkAnimation_OnFrame(&this->skelAnime, 76.0f)) { - static BottleDropInfo sBottleDropInfos[] = { - /* PLAYER_IA_BOTTLE_FISH */ { ACTOR_EN_FISH, FISH_DROPPED }, - /* PLAYER_IA_BOTTLE_FIRE */ { ACTOR_EN_ICE_HONO, 0 }, - /* PLAYER_IA_BOTTLE_BUG */ { ACTOR_EN_INSECT, INSECT_TYPE_FIRST_DROPPED }, - }; - BottleDropInfo* dropInfo = &sBottleDropInfos[this->itemAction - PLAYER_IA_BOTTLE_FISH]; Actor_Spawn(&play->actorCtx, play, dropInfo->actorId, @@ -14163,11 +14168,6 @@ void Player_Action_DropActorFromBottle(Player* this, PlayState* play) { Player_UpdateBottleHeld(play, this, ITEM_BOTTLE_EMPTY, PLAYER_IA_BOTTLE); } else { - static AnimSfxEntry sBottleDropAnimSfx[] = { - { NA_SE_VO_LI_AUTO_JUMP, ANIMSFX_DATA(ANIMSFX_TYPE_VOICE, 38) }, - { NA_SE_EV_BOTTLE_CAP_OPEN, -ANIMSFX_DATA(ANIMSFX_TYPE_GENERAL, 40) }, - }; - Player_ProcessAnimSfxList(this, sBottleDropAnimSfx); } } From 24c974661e0ffcfeb96e1bee55a8607bd72c6e68 Mon Sep 17 00:00:00 2001 From: Pablo <72659707+Pepe20129@users.noreply.github.com> Date: Sat, 14 Dec 2024 01:52:20 +0100 Subject: [PATCH 7/8] Format --- src/overlays/actors/ovl_player_actor/z_player.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 8b8ce1fe97b..b797bec193a 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -6082,13 +6082,14 @@ s32 Player_ActionHandler_13(Player* this, PlayState* play) { } sp2C = Player_ActionToBottle(this, this->itemAction); - #define ACTION_TO_BOTTLE_ACTION(action) (action - PLAYER_IA_BOTTLE) +#define ACTION_TO_BOTTLE_ACTION(action) (action - PLAYER_IA_BOTTLE) if (sp2C >= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE)) { if (sp2C == ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_FAIRY)) { Player_SetupActionPreserveItemAction(play, this, Player_Action_UseFairyFromBottle, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_bug_out); func_80835EA4(play, 3); - } else if ((sp2C >= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_FISH)) && (sp2C <= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_BUG))) { + } else if ((sp2C >= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_FISH)) && + (sp2C <= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_BUG))) { Player_SetupActionPreserveItemAction(play, this, Player_Action_DropActorFromBottle, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_fish_out); func_80835EA4(play, (sp2C == 1) ? 1 : 5); @@ -13965,12 +13966,14 @@ typedef enum DrinkingState { } DrinkingState; void Player_Action_DrinkFromBottle(Player* this, PlayState* play) { - // When an animation finishes (gPlayerAnim_link_bottle_drink_demo_start when drinkingState == DRINGING_STATE_SETUP, gPlayerAnim_link_bottle_drink_demo_end otherwise) + // When an animation finishes (gPlayerAnim_link_bottle_drink_demo_start when drinkingState == DRINGING_STATE_SETUP, + // gPlayerAnim_link_bottle_drink_demo_end otherwise) if (LinkAnimation_Update(play, &this->skelAnime)) { if (this->av2.drinkingState == DRINGING_STATE_SETUP) { static u8 sBottleContentDrinkFlags[] = { /* PLAYER_IA_BOTTLE_POTION_RED */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG, - /* PLAYER_IA_BOTTLE_POTION_BLUE */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG | BOTTLE_CONTENT_DRINK_FLAG_MAGIC, + /* PLAYER_IA_BOTTLE_POTION_BLUE */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_BIG | + BOTTLE_CONTENT_DRINK_FLAG_MAGIC, /* PLAYER_IA_BOTTLE_POTION_GREEN */ BOTTLE_CONTENT_DRINK_FLAG_MAGIC, /* PLAYER_IA_BOTTLE_MILK_FULL */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL, /* PLAYER_IA_BOTTLE_MILK_HALF */ BOTTLE_CONTENT_DRINK_FLAG_HEALTH_SMALL, From 1cc97faf195dc345f47ae7cdf2c601ce29376acd Mon Sep 17 00:00:00 2001 From: Pablo <72659707+Pepe20129@users.noreply.github.com> Date: Thu, 26 Dec 2024 21:32:31 +0100 Subject: [PATCH 8/8] Address review --- include/z64player.h | 4 +++- src/code/z_player_lib.c | 4 ++-- src/overlays/actors/ovl_player_actor/z_player.c | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/z64player.h b/include/z64player.h index 6d3749206ef..03f6cdb0eec 100644 --- a/include/z64player.h +++ b/include/z64player.h @@ -181,6 +181,8 @@ typedef enum PlayerItemAction { /* 0x43 */ PLAYER_IA_MAX } PlayerItemAction; +#define ACTION_TO_BOTTLE(action) (action - PLAYER_IA_BOTTLE) + typedef enum PlayerLimb { /* 0x00 */ PLAYER_LIMB_NONE, /* 0x01 */ PLAYER_LIMB_ROOT, @@ -927,7 +929,7 @@ typedef struct Player { s16 csDelayTimer; // Player_Action_WaitForCutscene: Number of frames to wait before responding to a cutscene s16 playedLandingSfx; // Player_Action_BlueWarpArrive: Played sfx when landing on the ground s16 appearTimer; // Player_Action_FaroresWindArrive: Counts up, appear at 20 frames (1 second) - s16 drinkingState; // Player_Action_DrinkFromBottle: Uses values 0-2 to determine which part of the drinking action is currently active + s16 drinkingState; // Player_Action_DrinkFromBottle: Uses values 0-2 to determine which part of the drinking action is currently active (see DrinkingState enum) } av2; // "Action Variable 2": context dependent variable that has different meanings depending on what action is currently running /* 0x0854 */ f32 unk_854; diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 798ba824620..40aa6b80cc5 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -880,9 +880,9 @@ int Player_HoldsBrokenKnife(Player* this) { } s32 Player_ActionToBottle(Player* this, s32 itemAction) { - s32 bottle = itemAction - PLAYER_IA_BOTTLE; + s32 bottle = ACTION_TO_BOTTLE(itemAction); - if ((bottle >= 0) && (bottle < 13)) { + if ((bottle >= ACTION_TO_BOTTLE(PLAYER_IA_BOTTLE)) && (bottle <= ACTION_TO_BOTTLE(PLAYER_IA_BOTTLE_FAIRY))) { return bottle; } else { return -1; diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index b797bec193a..7344cd1e721 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -6082,14 +6082,14 @@ s32 Player_ActionHandler_13(Player* this, PlayState* play) { } sp2C = Player_ActionToBottle(this, this->itemAction); -#define ACTION_TO_BOTTLE_ACTION(action) (action - PLAYER_IA_BOTTLE) - if (sp2C >= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE)) { - if (sp2C == ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_FAIRY)) { + + if (sp2C >= ACTION_TO_BOTTLE(PLAYER_IA_BOTTLE)) { + if (sp2C == ACTION_TO_BOTTLE(PLAYER_IA_BOTTLE_FAIRY)) { Player_SetupActionPreserveItemAction(play, this, Player_Action_UseFairyFromBottle, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_bug_out); func_80835EA4(play, 3); - } else if ((sp2C >= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_FISH)) && - (sp2C <= ACTION_TO_BOTTLE_ACTION(PLAYER_IA_BOTTLE_BUG))) { + } else if ((sp2C >= ACTION_TO_BOTTLE(PLAYER_IA_BOTTLE_FISH)) && + (sp2C <= ACTION_TO_BOTTLE(PLAYER_IA_BOTTLE_BUG))) { Player_SetupActionPreserveItemAction(play, this, Player_Action_DropActorFromBottle, 0); Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_bottle_fish_out); func_80835EA4(play, (sp2C == 1) ? 1 : 5);