From df1815cf8f0d83bf02cd7462830747ed826ecc94 Mon Sep 17 00:00:00 2001 From: fig02 Date: Tue, 15 Oct 2024 14:10:21 -0400 Subject: [PATCH] Document `ACTOR_FLAG_THROW_ONLY` (#2274) * document ACTOR_FLAG_THROW_ONLY * flip function name * add comments --- include/z64actor.h | 5 +++-- src/overlays/actors/ovl_En_Ishi/z_en_ishi.c | 2 +- src/overlays/actors/ovl_En_Kusa/z_en_kusa.c | 2 +- src/overlays/actors/ovl_En_Niw/z_en_niw.c | 2 +- .../actors/ovl_Obj_Tsubo/z_obj_tsubo.c | 2 +- .../actors/ovl_player_actor/z_player.c | 21 +++++++++++++------ 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/z64actor.h b/include/z64actor.h index aab5f1039f..662a40efa8 100644 --- a/include/z64actor.h +++ b/include/z64actor.h @@ -184,8 +184,9 @@ typedef struct ActorShape { // ignores point lights but not directional lights (such as environment lights) #define ACTOR_FLAG_IGNORE_POINT_LIGHTS (1 << 22) -// -#define ACTOR_FLAG_23 (1 << 23) +// When Player is carrying this actor, it can only be thrown, not dropped/placed. +// Typically an actor can only be thrown when moving, but this allows an actor to be thrown when standing still. +#define ACTOR_FLAG_THROW_ONLY (1 << 23) // #define ACTOR_FLAG_24 (1 << 24) diff --git a/src/overlays/actors/ovl_En_Ishi/z_en_ishi.c b/src/overlays/actors/ovl_En_Ishi/z_en_ishi.c index a14b34e922..b2f0aa73f7 100644 --- a/src/overlays/actors/ovl_En_Ishi/z_en_ishi.c +++ b/src/overlays/actors/ovl_En_Ishi/z_en_ishi.c @@ -11,7 +11,7 @@ #include "quake.h" #include "terminal.h" -#define FLAGS ACTOR_FLAG_23 +#define FLAGS ACTOR_FLAG_THROW_ONLY void EnIshi_Init(Actor* thisx, PlayState* play); void EnIshi_Destroy(Actor* thisx, PlayState* play2); diff --git a/src/overlays/actors/ovl_En_Kusa/z_en_kusa.c b/src/overlays/actors/ovl_En_Kusa/z_en_kusa.c index eacb01ca3e..f2882cad3d 100644 --- a/src/overlays/actors/ovl_En_Kusa/z_en_kusa.c +++ b/src/overlays/actors/ovl_En_Kusa/z_en_kusa.c @@ -12,7 +12,7 @@ #include "assets/objects/object_kusa/object_kusa.h" #include "terminal.h" -#define FLAGS (ACTOR_FLAG_4 | ACTOR_FLAG_23) +#define FLAGS (ACTOR_FLAG_4 | ACTOR_FLAG_THROW_ONLY) void EnKusa_Init(Actor* thisx, PlayState* play); void EnKusa_Destroy(Actor* thisx, PlayState* play2); diff --git a/src/overlays/actors/ovl_En_Niw/z_en_niw.c b/src/overlays/actors/ovl_En_Niw/z_en_niw.c index c805167093..96c00b42e6 100644 --- a/src/overlays/actors/ovl_En_Niw/z_en_niw.c +++ b/src/overlays/actors/ovl_En_Niw/z_en_niw.c @@ -10,7 +10,7 @@ #include "terminal.h" #include "versions.h" -#define FLAGS (ACTOR_FLAG_4 | ACTOR_FLAG_23) +#define FLAGS (ACTOR_FLAG_4 | ACTOR_FLAG_THROW_ONLY) void EnNiw_Init(Actor* thisx, PlayState* play); void EnNiw_Destroy(Actor* thisx, PlayState* play); diff --git a/src/overlays/actors/ovl_Obj_Tsubo/z_obj_tsubo.c b/src/overlays/actors/ovl_Obj_Tsubo/z_obj_tsubo.c index 9747279d79..d88f5c7142 100644 --- a/src/overlays/actors/ovl_Obj_Tsubo/z_obj_tsubo.c +++ b/src/overlays/actors/ovl_Obj_Tsubo/z_obj_tsubo.c @@ -9,7 +9,7 @@ #include "assets/objects/gameplay_dangeon_keep/gameplay_dangeon_keep.h" #include "assets/objects/object_tsubo/object_tsubo.h" -#define FLAGS (ACTOR_FLAG_4 | ACTOR_FLAG_23) +#define FLAGS (ACTOR_FLAG_4 | ACTOR_FLAG_THROW_ONLY) void ObjTsubo_Init(Actor* thisx, PlayState* play); void ObjTsubo_Destroy(Actor* thisx, PlayState* play2); diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index da5f92ddf0..7102321d58 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -7423,20 +7423,29 @@ void func_8083EA94(Player* this, PlayState* play) { Player_AnimPlayOnce(play, this, GET_PLAYER_ANIM(PLAYER_ANIMGROUP_throw, this->modelAnimType)); } -s32 func_8083EAF0(Player* this, Actor* actor) { - if ((actor != NULL) && !(actor->flags & ACTOR_FLAG_23) && +/** + * Checks if an actor can be thrown or dropped. + * It is assumed that the `actor` argument is the actor currently being carried. + * + * @return true if it can be thrown, false if it can be dropped. + */ +s32 Player_CanThrowCarriedActor(Player* this, Actor* actor) { + // If the actor arg is null, true will be returned. + // It doesn't make sense for a non-existent actor to be thrown or dropped, so + // the safety check should happen before this function is even called. + if ((actor != NULL) && !(actor->flags & ACTOR_FLAG_THROW_ONLY) && ((this->speedXZ < 1.1f) || (actor->id == ACTOR_EN_BOM_CHU))) { - return 0; + return false; } - return 1; + return true; } s32 Player_ActionHandler_9(Player* this, PlayState* play) { if ((this->stateFlags1 & PLAYER_STATE1_CARRYING_ACTOR) && (this->heldActor != NULL) && CHECK_BTN_ANY(sControlInput->press.button, BTN_A | BTN_B | BTN_CLEFT | BTN_CDOWN | BTN_CRIGHT)) { if (!func_80835644(play, this, this->heldActor)) { - if (!func_8083EAF0(this, this->heldActor)) { + if (!Player_CanThrowCarriedActor(this, this->heldActor)) { Player_SetupAction(play, this, Player_Action_808464B0, 1); Player_AnimPlayOnce(play, this, GET_PLAYER_ANIM(PLAYER_ANIMGROUP_put, this->modelAnimType)); } else { @@ -10897,7 +10906,7 @@ void Player_UpdateInterface(PlayState* play, Player* this) { } else if ((this->stateFlags1 & PLAYER_STATE1_CARRYING_ACTOR) && (this->getItemId == GI_NONE) && (heldActor != NULL)) { if ((this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) || (heldActor->id == ACTOR_EN_NIW)) { - if (func_8083EAF0(this, heldActor) == 0) { + if (!Player_CanThrowCarriedActor(this, heldActor)) { doAction = DO_ACTION_DROP; } else { doAction = DO_ACTION_THROW;