Swapped FLAG_SYS_PC_FROM_POKENAV for gSysPcFromPokenav

voloved 2023-04-15 09:20:53 -04:00
parent a6e5efa0ce
commit 1a1db9783f

@ -238,24 +238,23 @@ static u32 LoopedTask_ReShowDescription(s32 state)
}
```
This is where most of the logic exists. `FLAG_SYS_PC_FROM_POKENAV` is used to stop the start menu from reshowing when the PokeNav closes, to lock the player in place, and to avoid metatile goofiness where accessing the PC would normally change the tile you're facing into a turned on PC.
Since `FLAG_SYS_PC_FROM_POKENAV` doesn't need to be volatile, this can live in a global struct or a global variable that gets stored in EWRAM, if you prefer that in your organization.
This is where most of the logic exists. `gSysPcFromPokenav` is used to stop the start menu from reshowing when the PokeNav closes, to lock the player in place, and to avoid metatile goofiness where accessing the PC would normally change the tile you're facing into a turned on PC.
Define the flag somewhere in `flags.h`. Just swap it with an unused flag.
Add gSysPcFromPokenav into `overworld.h` so it can be in the scope of other functions.
```diff
-------------------------- include/constants/flags.h --------------------------
index 7df3060ed3..282acfcd9c 100644
@@ -46,9 +46,9 @@
#define FLAG_SYS_NO_TRAINER_SEE 0x22 // Unused Flag //DEBUG
#define FLAG_SYS_NO_BAG_USE 0x23 // Unused Flag //DEBUG
#define FLAG_SYS_NO_CATCHING 0x24 // Unused Flag //DEBUG
#define FLAG_SYS_PC_FROM_DEBUG_MENU 0x25 // Unused Flag //DEBUG
-#define FLAG_UNUSED_0x026 0x26 // Unused Flag
+#define FLAG_SYS_PC_FROM_POKENAV 0x26
#define FLAG_UNUSED_0x027 0x27 // Unused Flag
#define FLAG_UNUSED_0x028 0x28 // Unused Flag
#define FLAG_UNUSED_0x029 0x29 // Unused Flag
#define FLAG_UNUSED_0x02A 0x2A // Unused Flag
----------------------------- include/overworld.h -----------------------------
index 1bd0bdd110..5d8176df63 100644
@@ -54,8 +54,9 @@ extern u16 gHeldKeyCodeToSend;
extern void (*gFieldCallback)(void);
extern bool8 (*gFieldCallback2)(void);
extern u8 gLocalLinkPlayerId;
extern u8 gFieldLinkPlayerCount;
+extern bool8 gSysPcFromPokenav;
extern const struct UCoords32 gDirectionToVectors[];
void DoWhiteOut(void);
```
```diff
@ -311,17 +310,6 @@ index b81b4c892..d6b62d021 100644
[POKENAV_MENU_TYPE_CONDITION_SEARCH] =
{
POKENAV_MENUITEM_CONDITION_SEARCH_COOL,
@@ -85,9 +94,9 @@ static const u8 sMenuItems[][MAX_POKENAV_MENUITEMS] =
static u8 GetPokenavMainMenuType(void)
{
u8 menuType = POKENAV_MENU_TYPE_DEFAULT;
- if (FlagGet(FLAG_ADDED_MATCH_CALL_TO_POKENAV))
+ if (FlagGet(FLAG_ADDED_MATCH_CALL_TO_POKENAV))
{
menuType = POKENAV_MENU_TYPE_UNLOCK_MC;
if (FlagGet(FLAG_SYS_RIBBON_GET))
@@ -145,9 +154,9 @@ bool32 PokenavCallback_Init_ConditionMenu(void)
return FALSE;
@ -377,7 +365,7 @@ index b81b4c892..d6b62d021 100644
return POKENAV_MENU_FUNC_OPEN_CONDITION_SEARCH;
+ case POKENAV_MENUITEM_CONDITION_ACCESS_PC:
+ if(Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType)){
+ FlagSet(FLAG_SYS_PC_FROM_POKENAV);
+ gSysPcFromPokenav = TRUE;
+ // Reusing from debug menu to gracefully close PC when done.
+ CreateTask(Task_WaitFadeAccessPC, 0);
+ return POKENAV_MENU_FUNC_EXIT;
@ -405,13 +393,23 @@ index 03f48ee36..1988b103e 100644
#define LOOPED_TASK_DECODE_STATE(action) (action - 5)
#define LOOPED_TASK_ID(primary, secondary) (((secondary) << 16) |(primary))
@@ -204,8 +204,9 @@ const struct PokenavCallbacks PokenavMenuCallbacks[15] =
},
};
EWRAM_DATA u8 gNextLoopedTaskId = 0;
+EWRAM_DATA bool8 gSysPcFromPokenav = 0;
EWRAM_DATA struct PokenavResources *gPokenavResources = NULL;
// code
u32 CreateLoopedTask(LoopedTask loopedTask, u32 priority)
@@ -494,9 +495,13 @@ static void Task_Pokenav(u8 taskId)
FreePokenavResources();
if (calledFromScript)
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
else
- SetMainCallback2(CB2_ReturnToFieldWithOpenMenu);
+ if (FlagGet(FLAG_SYS_PC_FROM_POKENAV))
+ if (gSysPcFromPokenav)
+ SetMainCallback2(CB2_ReturnToField);
+ else
+ SetMainCallback2(CB2_ReturnToFieldWithOpenMenu);
@ -505,7 +503,7 @@ index 03aebb0ce..3a27720f7 100644
static void PCTurnOnEffect_1(s16 isPcTurnedOn, s8 dx, s8 dy)
{
u16 tileId = 0;
+ if(FlagGet(FLAG_SYS_PC_FROM_POKENAV))
+ if(gSysPcFromPokenav)
+ return;
if (isPcTurnedOn)
{
@ -520,8 +518,8 @@ index 03aebb0ce..3a27720f7 100644
s8 dy = 0;
u16 tileId = 0;
u8 playerDirection = GetPlayerFacingDirection();
+ if(FlagGet(FLAG_SYS_PC_FROM_POKENAV)){
+ FlagClear(FLAG_SYS_PC_FROM_POKENAV);
+ if(gSysPcFromPokenav){
+ gSysPcFromPokenav = FALSE;
+ return;
+ }
switch (playerDirection)
@ -531,7 +529,7 @@ index 03aebb0ce..3a27720f7 100644
```
This locks the character in place until you leave the PC and the FLAG_SYS_PC_FROM_POKENAV flag is cleared.
This locks the character in place until you leave the PC and gSysPcFromPokenav is cleared.
```diff
-------------------------- src/field_screen_effect.c --------------------------
index 57f8cc52e..a36f61a25 100644
@ -541,7 +539,7 @@ index 57f8cc52e..a36f61a25 100644
break;
case 1:
- if (WaitForWeatherFadeIn())
+ if (WaitForWeatherFadeIn() && !FlagGet(FLAG_SYS_PC_FROM_POKENAV))
+ if (WaitForWeatherFadeIn() && !gSysPcFromPokenav)
{
UnfreezeObjectEvents();
UnlockPlayerFieldControls();