summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfig02 <fig02srl@gmail.com>2024-04-15 13:02:43 -0400
committerGitHub <noreply@github.com>2024-04-15 13:02:43 -0400
commit295a8669b86e571aecd6509b4e7b86e955f165d6 (patch)
tree7584a3e1e02438281ef41ea4718a1b8afc4f5ce2 /src
parentf643499462f8cf908ddf1ee77b5625ebaff2cf25 (diff)
Player: Document "WaitForPutAway" (#1936)
* document put away delay * functions.txt * add a note on delaying indefinitely * format * typo * delay -> wait for put away * revert unintended formatting change * add comment to struct member * format * fix functions.txt
Diffstat (limited to 'src')
-rw-r--r--src/overlays/actors/ovl_player_actor/z_player.c85
1 files changed, 58 insertions, 27 deletions
diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c
index fd2cc36c4..3f10abec8 100644
--- a/src/overlays/actors/ovl_player_actor/z_player.c
+++ b/src/overlays/actors/ovl_player_actor/z_player.c
@@ -292,7 +292,7 @@ void Player_Action_80844E68(Player* this, PlayState* play);
void Player_Action_80845000(Player* this, PlayState* play);
void Player_Action_80845308(Player* this, PlayState* play);
void Player_Action_80845668(Player* this, PlayState* play);
-void Player_Action_808458D0(Player* this, PlayState* play);
+void Player_Action_WaitForPutAway(Player* this, PlayState* play);
void Player_Action_80845CA4(Player* this, PlayState* play);
void Player_Action_80845EF8(Player* this, PlayState* play);
void Player_Action_80846050(Player* this, PlayState* play);
@@ -1719,12 +1719,16 @@ void func_80832440(PlayState* play, Player* this) {
this->unk_845 = this->unk_844 = 0;
}
-s32 func_80832528(PlayState* play, Player* this) {
+/**
+ * Puts away item currently in hand, if holding any.
+ * @return true if an item needs to be put away, false if not.
+ */
+s32 Player_PutAwayHeldItem(PlayState* play, Player* this) {
if (this->heldItemAction >= PLAYER_IA_FISHING_POLE) {
Player_UseItem(play, this, ITEM_NONE);
- return 1;
+ return true;
} else {
- return 0;
+ return false;
}
}
@@ -2216,7 +2220,7 @@ void Player_InitExplosiveIA(PlayState* play, Player* this) {
Actor* spawnedActor;
if (this->stateFlags1 & PLAYER_STATE1_11) {
- func_80832528(play, this);
+ Player_PutAwayHeldItem(play, this);
return;
}
@@ -3360,7 +3364,7 @@ void func_80836448(PlayState* play, Player* this, LinkAnimationHeader* anim) {
}
int Player_CanUpdateItems(Player* this) {
- return (!(Player_Action_808458D0 == this->actionFunc) ||
+ return (!(Player_Action_WaitForPutAway == this->actionFunc) ||
((this->stateFlags1 & PLAYER_STATE1_START_CHANGING_HELD_ITEM) &&
((this->heldItemId == ITEM_SWORD_CS) || (this->heldItemId == ITEM_NONE)))) &&
(!(Player_UpperAction_ChangeHeldItem == this->upperActionFunc) ||
@@ -3414,11 +3418,21 @@ s32 Player_UpdateUpperBody(Player* this, PlayState* play) {
return 1;
}
-s32 func_80836898(PlayState* play, Player* this, PlayerFuncA74 func) {
- this->func_A74 = func;
- Player_SetupAction(play, this, Player_Action_808458D0, 0);
+/**
+ * Sets up `Player_Action_WaitForPutAway`, which will allow the held item put away process
+ * to complete before moving on to a new action.
+ *
+ * The function provided by the `afterPutAwayFunc` argument will run after the put away is complete.
+ * This function is expected to set a new action and move execution away from `Player_Action_WaitForPutAway`.
+ *
+ * @return From `Player_PutAwayHeldItem`: true if an item needs to be put away, false if not.
+ */
+s32 Player_SetupWaitForPutAway(PlayState* play, Player* this, AfterPutAwayFunc afterPutAwayFunc) {
+ this->afterPutAwayFunc = afterPutAwayFunc;
+ Player_SetupAction(play, this, Player_Action_WaitForPutAway, 0);
this->stateFlags2 |= PLAYER_STATE2_6;
- return func_80832528(play, this);
+
+ return Player_PutAwayHeldItem(play, this);
}
void func_808368EC(Player* this, PlayState* play) {
@@ -4946,7 +4960,7 @@ s32 Player_ActionChange_1(Player* this, PlayState* play) {
}
Player_SetupAction(play, this, Player_Action_80845EF8, 0);
- func_80832528(play, this);
+ Player_PutAwayHeldItem(play, this);
if (doorDirection < 0) {
this->actor.shape.rot.y = doorActor->shape.rot.y;
@@ -5272,7 +5286,7 @@ s32 func_8083A6AC(Player* this, PlayState* play) {
sp50 ? &gPlayerAnim_link_normal_Fclimb_startB : &gPlayerAnim_link_normal_fall);
if (sp50) {
- func_80836898(play, this, func_8083A3B0);
+ Player_SetupWaitForPutAway(play, this, func_8083A3B0);
this->yaw += 0x8000;
this->actor.shape.rot.y = this->yaw;
@@ -6604,7 +6618,7 @@ s32 Player_ActionChange_3(Player* this, PlayState* play) {
sp38 = Math_CosS(rideActor->actor.shape.rot.y);
sp34 = Math_SinS(rideActor->actor.shape.rot.y);
- func_80836898(play, this, func_8083A360);
+ Player_SetupWaitForPutAway(play, this, func_8083A360);
this->stateFlags1 |= PLAYER_STATE1_23;
this->actor.bgCheckFlags &= ~BGCHECKFLAG_WATER;
@@ -6756,7 +6770,7 @@ s32 Player_ActionChange_2(Player* this, PlayState* play) {
func_8083AE40(this, giEntry->objectId);
if (!(this->stateFlags2 & PLAYER_STATE2_10) || (this->currentBoots == PLAYER_BOOTS_IRON)) {
- func_80836898(play, this, func_8083A434);
+ Player_SetupWaitForPutAway(play, this, func_8083A434);
Player_AnimPlayOnceAdjusted(play, this, &gPlayerAnim_link_demo_get_itemB);
func_80835EA4(play, 9);
}
@@ -6783,7 +6797,7 @@ s32 Player_ActionChange_2(Player* this, PlayState* play) {
}
}
- func_80836898(play, this, func_8083A434);
+ Player_SetupWaitForPutAway(play, this, func_8083A434);
this->stateFlags1 |= PLAYER_STATE1_10 | PLAYER_STATE1_11 | PLAYER_STATE1_29;
func_8083AE40(this, giEntry->objectId);
this->actor.world.pos.x =
@@ -6817,7 +6831,7 @@ s32 Player_ActionChange_2(Player* this, PlayState* play) {
this->itemAction = PLAYER_IA_NONE;
this->modelAnimType = PLAYER_ANIMTYPE_0;
this->heldItemAction = this->itemAction;
- func_80836898(play, this, func_8083A0F4);
+ Player_SetupWaitForPutAway(play, this, func_8083A0F4);
if (sp24 == PLAYER_IA_SWORD_MASTER) {
this->nextModelGroup = Player_ActionToModelGroup(this, PLAYER_IA_SWORD_CS);
@@ -6833,7 +6847,7 @@ s32 Player_ActionChange_2(Player* this, PlayState* play) {
return 0;
}
- func_80836898(play, this, func_8083A0F4);
+ Player_SetupWaitForPutAway(play, this, func_8083A0F4);
}
func_80832224(this);
@@ -6945,7 +6959,7 @@ s32 func_8083EC18(Player* this, PlayState* play, u32 wallFlags) {
f32 sp34 = this->distToInteractWall;
LinkAnimationHeader* anim;
- func_80836898(play, this, func_8083A3B0);
+ Player_SetupWaitForPutAway(play, this, func_8083A3B0);
this->stateFlags1 |= PLAYER_STATE1_21;
this->stateFlags1 &= ~PLAYER_STATE1_27;
@@ -7048,7 +7062,7 @@ s32 Player_TryEnteringCrawlspace(Player* this, PlayState* play, u32 interactWall
f32 wallPolyNormalZ = COLPOLY_GET_NORMAL(wallPoly->normal.z);
f32 distToInteractWall = this->distToInteractWall;
- func_80836898(play, this, func_8083A40C);
+ Player_SetupWaitForPutAway(play, this, func_8083A40C);
this->stateFlags2 |= PLAYER_STATE2_CRAWLING;
this->actor.shape.rot.y = this->yaw = this->actor.wallYaw + 0x8000;
this->actor.world.pos.x = xVertex1 + (distToInteractWall * wallPolyNormalX);
@@ -7173,7 +7187,7 @@ s32 Player_TryLeavingCrawlspace(Player* this, PlayState* play) {
}
void func_8083F72C(Player* this, LinkAnimationHeader* anim, PlayState* play) {
- if (!func_80836898(play, this, func_8083A388)) {
+ if (!Player_SetupWaitForPutAway(play, this, func_8083A388)) {
Player_SetupAction(play, this, Player_Action_8084B78C, 0);
}
@@ -7210,7 +7224,7 @@ s32 Player_ActionChange_5(Player* this, PlayState* play) {
return 0;
}
- func_80836898(play, this, func_8083A0F4);
+ Player_SetupWaitForPutAway(play, this, func_8083A0F4);
this->stateFlags1 |= PLAYER_STATE1_11;
this->interactRangeActor = &wallPolyActor->actor;
this->getItemId = GI_NONE;
@@ -9420,13 +9434,30 @@ void Player_Action_80845668(Player* this, PlayState* play) {
}
}
-void Player_Action_808458D0(Player* this, PlayState* play) {
+/**
+ * Allow the held item put away process to complete before running `afterPutAwayFunc`
+ */
+void Player_Action_WaitForPutAway(Player* this, PlayState* play) {
this->stateFlags2 |= PLAYER_STATE2_5 | PLAYER_STATE2_6;
LinkAnimation_Update(play, &this->skelAnime);
+ // Wait for the held item put away process to complete.
+ // Determining if the put away process is complete is a bit complicated:
+ // `Player_UpdateUpperBody` will only return false if the current UpperAction returns false.
+ // The UpperAction responsible for putting away items, `Player_UpperAction_ChangeHeldItem`, constantly
+ // returns true until the item change is done. False won't be returned until the item change is done, and a new
+ // UpperAction is running and can return false itself.
+ // Note that this implementation allows for delaying indefinitely by, for example, holding shield
+ // during the item put away. The shield UpperAction will return true while shielding and targeting.
+ // Meaning, `afterPutAwayFunc` will be delayed until the player decides to let go of shield.
+ // This quirk can contribute to the possibility of other bugs manifesting.
+ //
+ // The other conditions listed will force the put away delay function to run instantly if carrying an actor.
+ // This is necessary because the UpperAction for carrying actors will always return true while holding
+ // the actor, so `!Player_UpdateUpperBody` could never pass.
if (((this->stateFlags1 & PLAYER_STATE1_11) && (this->heldActor != NULL) && (this->getItemId == GI_NONE)) ||
!Player_UpdateUpperBody(this, play)) {
- this->func_A74(play, this);
+ this->afterPutAwayFunc(play, this);
}
}
@@ -15289,7 +15320,7 @@ void func_80853148(PlayState* play, Actor* actor) {
if (actor->textId == 0xFFFF) {
Player_SetCsActionWithHaltedActors(play, actor, PLAYER_CSACTION_1);
actor->flags |= ACTOR_FLAG_TALK;
- func_80832528(play, this);
+ Player_PutAwayHeldItem(play, this);
} else {
if (this->actor.flags & ACTOR_FLAG_TALK) {
this->actor.textId = 0;
@@ -15301,13 +15332,13 @@ void func_80853148(PlayState* play, Actor* actor) {
if (this->stateFlags1 & PLAYER_STATE1_23) {
s32 sp24 = this->av2.actionVar2;
- func_80832528(play, this);
+ Player_PutAwayHeldItem(play, this);
func_8083A2F8(play, this);
this->av2.actionVar2 = sp24;
} else {
if (func_808332B8(this)) {
- func_80836898(play, this, func_8083A2F8);
+ Player_SetupWaitForPutAway(play, this, func_8083A2F8);
Player_AnimChangeLoopSlowMorph(play, this, &gPlayerAnim_link_swimer_swim_wait);
} else if ((actor->category != ACTORCAT_NPC) || (this->heldItemAction == PLAYER_IA_FISHING_POLE)) {
func_8083A2F8(play, this);
@@ -15320,7 +15351,7 @@ void func_80853148(PlayState* play, Actor* actor) {
}
}
} else {
- func_80836898(play, this, func_8083A2F8);
+ Player_SetupWaitForPutAway(play, this, func_8083A2F8);
Player_AnimPlayOnceAdjusted(play, this,
(actor->xzDistToPlayer < 40.0f) ? &gPlayerAnim_link_normal_backspace
: &gPlayerAnim_link_normal_talk_free);