From 84b73402afb2dda66647ab33121a4d39934ded4d Mon Sep 17 00:00:00 2001 From: JCog <42006114+JCog@users.noreply.github.com> Date: Mon, 8 Dec 2025 23:53:05 -0600 Subject: [PATCH 1/2] rename isBattle to context and fix associated logic --- src/commands.c | 2 +- src/enums.h | 6 ++++++ src/fp.c | 5 +++-- src/fp/practice/trainer.c | 11 ++++++----- src/fp/warps/bosses.c | 6 +++--- src/pm64.h | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/commands.c b/src/commands.c index 14862ded..46927bfd 100644 --- a/src/commands.c +++ b/src/commands.c @@ -87,7 +87,7 @@ bool fpWarp(enum Areas area, u16 map, u16 entrance) { pm_gGameStatus.entryID = entrance; PRINTF("***** WARP TRIGGERED *****\n"); - if (pm_gGameStatus.isBattle || pm_gPopupState == 1) { + if (pm_gGameStatus.context != CONTEXT_WORLD || pm_gPopupState == 1) { // prevent crashes from warping when in battle menus or with partner/item menu open pm_clear_windows(); } diff --git a/src/enums.h b/src/enums.h index 5cb28c81..9ef9a76c 100644 --- a/src/enums.h +++ b/src/enums.h @@ -987,4 +987,10 @@ enum PlayerStatusAnimFlags { PA_FLAG_80000000 = 0x80000000, }; +enum GameContext { + CONTEXT_WORLD = 0, + CONTEXT_BATTLE = 1, + CONTEXT_PAUSE = 2, +}; + #endif diff --git a/src/fp.c b/src/fp.c index ee13ccb6..83d553fc 100644 --- a/src/fp.c +++ b/src/fp.c @@ -320,7 +320,7 @@ void fpUpdateCheats(void) { pm_gPlayerData.curHP = 1; } if (CHEAT_ACTIVE(CHEAT_AUTO_MASH)) { - if (pm_gGameStatus.isBattle == 1) { + if (pm_gGameStatus.context == CONTEXT_BATTLE) { pm_gActionCommandStatus.barFillLevel = 10000; } } @@ -558,7 +558,8 @@ void fpDraw(void) { trainerDrawPinned(settings->trainerX, settings->trainerY, font, cellWidth, cellHeight, 0xC0C0C0, menuAlpha); } - if (fp.spinTrainerMoving || (settings->trainerSpinBarEnabled && !fp.menuActive && pm_gGameStatus.isBattle == 0)) { + if (fp.spinTrainerMoving || + (settings->trainerSpinBarEnabled && !fp.menuActive && pm_gGameStatus.context == CONTEXT_WORLD)) { trainerDrawSpinBar(settings->trainerSpinX, settings->trainerSpinY, font, 0xC0C0C0, menuAlpha); } diff --git a/src/fp/practice/trainer.c b/src/fp/practice/trainer.c index b2793cef..f2c2e0a1 100644 --- a/src/fp/practice/trainer.c +++ b/src/fp/practice/trainer.c @@ -208,7 +208,7 @@ static s32 spinVisualPositionProc(struct MenuItem *item, enum MenuCallbackReason } static void spinDraw(s32 x, s32 y, struct GfxFont *font, s32 chWidth, s32 chHeight, u32 color, u8 alpha) { - if (pm_gGameStatus.isBattle != 0) { + if (pm_gGameStatus.context != CONTEXT_WORLD) { return; } @@ -508,7 +508,7 @@ static void aceOotInstrProc(struct MenuItem *item, void *data) { } static void updateBowserBlockTrainer(void) { - if (pm_gGameStatus.isBattle) { + if (pm_gGameStatus.context == CONTEXT_BATTLE) { pm_Actor *enemy0 = pm_gBattleStatus.enemyActors[0]; if (enemy0) { bool isBowser = FALSE; @@ -640,7 +640,7 @@ static void updateLzsTrainer(void) { } static void updateSpinTrainer(void) { - if (!(pm_gGameStatus.isBattle != 1 && + if (!(pm_gGameStatus.context != CONTEXT_BATTLE && (settings->trainerSpinBarEnabled || settings->pinnedTrainer == TRAINER_SPIN))) { return; } @@ -737,7 +737,7 @@ static void blockCheckSuccessOrEarly(void) { } static void updateBlockTrainer(void) { - if (settings->trainerAcEnabled && pm_gGameStatus.isBattle) { + if (settings->trainerAcEnabled && pm_gGameStatus.context == CONTEXT_BATTLE) { // blocks switch (pm_gBattleStatus.blockResult) { case BLOCK_EARLY: @@ -828,7 +828,8 @@ static void updateQuickJumpTrainer(void) { static bool waitForNextTurn; static u8 frameWindow; - if (settings->trainerQuickJumpsEnabled && pm_gGameStatus.isBattle && pm_gBattleStatus.playerActor) { + if (settings->trainerQuickJumpsEnabled && pm_gGameStatus.context == CONTEXT_BATTLE && + pm_gBattleStatus.playerActor) { if (pm_gBattleStatus.playerActor->partsTable->curAnimation == 0x10004) { waitForNextTurn = FALSE; jumpFrame = -1; diff --git a/src/fp/warps/bosses.c b/src/fp/warps/bosses.c index 1b1f4649..8104ea52 100644 --- a/src/fp/warps/bosses.c +++ b/src/fp/warps/bosses.c @@ -137,8 +137,8 @@ static void bossWarpProc(struct MenuItem *item, void *data) { battle = (u8)((s32)data & 0xFF); pm_clear_windows(); pm_clear_printers(); - // isBattle is also true when paused, so checking game mode - if (pm_gGameStatus.isBattle && pm_CurGameMode != 10 && pm_CurGameMode != 11) { + // context is also true when paused, so checking game mode + if (pm_gGameStatus.context != CONTEXT_WORLD && pm_CurGameMode != 10 && pm_CurGameMode != 11) { // end battle cleanly so next fight can start fresh pm_gBattleState = 32; // BATTLE_STATE_END_BATTLE pm_gBattleSubState = 2; // BTL_SUBSTATE_END_BATTLE_EXEC_STAGE_SCRIPT @@ -150,7 +150,7 @@ static void bossWarpProc(struct MenuItem *item, void *data) { } void bossesUpdateWarps() { - if (leavingBattle && !pm_gGameStatus.isBattle) { + if (leavingBattle && pm_gGameStatus.context == CONTEXT_WORLD) { leavingBattle = FALSE; bossWarp(); } else if (warpCountdown == 30) { diff --git a/src/pm64.h b/src/pm64.h index 8a6ba411..27eda075 100644 --- a/src/pm64.h +++ b/src/pm64.h @@ -119,7 +119,7 @@ typedef struct pm_GameStatus { /* 0x06A */ s8 demoStickX; /* 0x06B */ s8 demoStickY; /* 0x06C */ s32 mainScriptID; - /* 0x070 */ s8 isBattle; + /* 0x070 */ s8 context; /* 0x071 */ s8 demoState; /* (0 = not demo, 1 = map demo, 2 = demo map changing) */ /* 0x072 */ s8 nextDemoScene; /* which part of the demo to play next */ /* 0x073 */ u8 controllerPlugged; /*needs to be 1 otherwise "no controller" */ From bb50b533d93445ad791a0b8f357e79ebc51481a5 Mon Sep 17 00:00:00 2001 From: JCog <42006114+JCog@users.noreply.github.com> Date: Tue, 9 Dec 2025 00:19:14 -0600 Subject: [PATCH 2/2] simplify updateSpinTrainer guard clause --- src/fp/practice/trainer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fp/practice/trainer.c b/src/fp/practice/trainer.c index f2c2e0a1..73c60393 100644 --- a/src/fp/practice/trainer.c +++ b/src/fp/practice/trainer.c @@ -640,8 +640,8 @@ static void updateLzsTrainer(void) { } static void updateSpinTrainer(void) { - if (!(pm_gGameStatus.context != CONTEXT_BATTLE && - (settings->trainerSpinBarEnabled || settings->pinnedTrainer == TRAINER_SPIN))) { + if (pm_gGameStatus.context == CONTEXT_BATTLE || + !(settings->trainerSpinBarEnabled || settings->pinnedTrainer == TRAINER_SPIN)) { return; }