Bug fix: setfollowernpc macro no longer runs when FNPC_ENABLE_NPC_FOLLOWERS is FALSE (#6755)

Co-authored-by: Bassoonian <iasperbassoonian@gmail.com>
This commit is contained in:
Bivurnum 2025-05-30 10:41:02 -05:00 committed by GitHub
parent 38ba41b324
commit 37669e62ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 31 deletions

View File

@ -2573,28 +2573,37 @@
@ Follower flags are defined in include/constants/follower_npc.h
@ If you want to specify a battle partner without specifying a custom script, you can set the script parameter to 0.
.macro setfollowernpc localId:req, flags:req, script=0, battlePartner=0
checkfollowernpc
goto_if_eq VAR_RESULT, TRUE, 1f
hidefollower
delay 16
callnative ScriptSetFollowerNPC
.if \script == 0
.set setScript, FALSE
.if FNPC_ENABLE_NPC_FOLLOWERS
checkfollowernpc
compare VAR_RESULT, FALSE
goto_if_ne 1f
hidefollower
waitmovement OBJ_EVENT_ID_FOLLOWER
callnative ScriptSetFollowerNPC
.if \script == 0
.set setScript, FALSE
.else
.set setScript, TRUE
.endif
.byte \localId
.2byte \flags
.byte setScript
.2byte \battlePartner
.4byte \script
updatefollowingmon
1:
.else
.set setScript, TRUE
.error "setfollowernpc unavailable with FNPC_ENABLE_NPC_FOLLOWERS defined as FALSE"
.endif
.byte \localId
.2byte \flags
.byte setScript
.2byte \battlePartner
.4byte \script
updatefollowingmon
1:
.endm
@ Remove the follower NPC (assumes there will only ever be one).
.macro destroyfollowernpc
callnative ScriptDestroyFollowerNPC
.if FNPC_ENABLE_NPC_FOLLOWERS
callnative ScriptDestroyFollowerNPC
.else
.error "destroyfollowernpc unavailable with FNPC_ENABLE_NPC_FOLLOWERS defined as FALSE"
.endif
.endm
@ Makes the player and follower NPC face one another.

View File

@ -1628,25 +1628,27 @@ void ScriptSetFollowerNPC(struct ScriptContext *ctx)
void ScriptDestroyFollowerNPC(struct ScriptContext *ctx)
{
if (PlayerHasFollowerNPC())
{
RemoveObjectEvent(&gObjectEvents[GetFollowerNPCData(FNPC_DATA_OBJ_ID)]);
FlagSet(GetFollowerNPCData(FNPC_DATA_EVENT_FLAG));
ClearFollowerNPCData();
}
if (!PlayerHasFollowerNPC())
return;
RemoveObjectEvent(&gObjectEvents[GetFollowerNPCData(FNPC_DATA_OBJ_ID)]);
FlagSet(GetFollowerNPCData(FNPC_DATA_EVENT_FLAG));
ClearFollowerNPCData();
UpdateFollowingPokemon();
}
void ScriptFaceFollowerNPC(struct ScriptContext *ctx)
{
if (PlayerHasFollowerNPC())
{
u32 playerDirection, followerDirection;
struct ObjectEvent *player, *follower;
if (!FNPC_ENABLE_NPC_FOLLOWERS || !PlayerHasFollowerNPC())
return;
player = &gObjectEvents[gPlayerAvatar.objectEventId];
follower = &gObjectEvents[GetFollowerNPCData(FNPC_DATA_OBJ_ID)];
u32 playerDirection, followerDirection;
struct ObjectEvent *player, *follower;
player = &gObjectEvents[gPlayerAvatar.objectEventId];
follower = &gObjectEvents[GetFollowerNPCData(FNPC_DATA_OBJ_ID)];
if (follower->invisible == FALSE)
{
playerDirection = DetermineFollowerNPCDirection(player, follower);
followerDirection = playerDirection;
@ -1682,10 +1684,13 @@ static const u8 *const FollowerNPCHideMovementsSpeedTable[][4] =
void ScriptHideNPCFollower(struct ScriptContext *ctx)
{
if (!FNPC_ENABLE_NPC_FOLLOWERS || !PlayerHasFollowerNPC())
return;
u32 walkSpeed = ScriptReadByte(ctx);
struct ObjectEvent *npc = &gObjectEvents[GetFollowerNPCObjectId()];
if (PlayerHasFollowerNPC() && npc->invisible == FALSE)
if (npc->invisible == FALSE)
{
u32 direction = DetermineFollowerNPCDirection(&gObjectEvents[gPlayerAvatar.objectEventId], npc);
@ -1709,8 +1714,10 @@ void ScriptUpdateFollowingMon(struct ScriptContext *ctx)
void ScriptChangeFollowerNPCBattlePartner(struct ScriptContext *ctx)
{
if (!FNPC_ENABLE_NPC_FOLLOWERS || !PlayerHasFollowerNPC())
return;
u32 newBattlePartner = ScriptReadHalfword(ctx);
if (PlayerHasFollowerNPC())
SetFollowerNPCData(FNPC_DATA_BATTLE_PARTNER, newBattlePartner);
SetFollowerNPCData(FNPC_DATA_BATTLE_PARTNER, newBattlePartner);
}