Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fly from Pokenav #5679

Open
wants to merge 15 commits into
base: upcoming
Choose a base branch
from
Open

Fly from Pokenav #5679

wants to merge 15 commits into from

Conversation

khbsd
Copy link

@khbsd khbsd commented Nov 18, 2024

Lets the player press 'R' over locations they have visited to fly to them from the PokeNav Region Map.

Description

  • refactored some logic from CB_ExitFlyMap() to allow setting the fly destination correctly from other files
  • added OW_FLAG_POKE_RIDER to allow this feature to be disabled
  • added gSkipShowMonAnim as an EWRAM variable to control whether the ShowMon animation plays or not
  • added new Looped Task in pokenav_region_map.c to handle flying
  • added new function UpdateRegionMapHelpBarText() so the HelpBarText can be easily synced with cursor movement and loading the map from the menu
  • added new inputs to both ProcessRegionMapInput_* functions
  • added new zoomed in and out text strings with the R button and the text 'FLY' for when the cursor is over a flyable location in the region map
  • adjusted some #includes and changed some static functions to non-static so they could be declared in the header files
  • uhhhhh probs more but i forgor

remade the branch and manually copy-pasted the correct changes. cleaned, compiled, tested.

Feature(s) this PR does NOT handle:

Adding other interactions in the overworld to handle other HM moves, this is specifically for Fly

Discord contact info

@khbsd

@AlexOn1ine AlexOn1ine added the new-feature Adds a feature label Nov 18, 2024
@AlexOn1ine AlexOn1ine added this to the 1.11 milestone Nov 18, 2024
@AlexOn1ine AlexOn1ine self-assigned this Nov 18, 2024
@AlexOn1ine AlexOn1ine removed their assignment Dec 3, 2024
@AlexOn1ine
Copy link
Collaborator

Could you also make it work with the Town Map item?

@hedara90
Copy link
Collaborator

Currently, you can use the PokeNav to fly while indoors (and I'm assuming other areas where flying is usually not possible).

Comment on lines 84 to 88
#define OW_FLAG_PAUSE_TIME 0 // If this flag is set and OW_USE_FAKE_RTC is enabled, seconds on the in-game clock will not advance.
#define OW_FLAG_NO_ENCOUNTER 0 // If this flag is set, wild encounters will be disabled.
#define OW_FLAG_NO_TRAINER_SEE 0 // If this flag is set, trainers will not battle the player unless they're talked to.
#define OW_FLAG_NO_COLLISION 0 // If this flag is set, the player will be able to walk over tiles with collision. Mainly intended for debugging purposes.
#define OW_FLAG_POKE_RIDER 0 // If this flag is set, the player will be able to use fly from the Pokenav Region Map section by pressing 'R' on a city/location they have been to.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define OW_FLAG_PAUSE_TIME 0 // If this flag is set and OW_USE_FAKE_RTC is enabled, seconds on the in-game clock will not advance.
#define OW_FLAG_NO_ENCOUNTER 0 // If this flag is set, wild encounters will be disabled.
#define OW_FLAG_NO_TRAINER_SEE 0 // If this flag is set, trainers will not battle the player unless they're talked to.
#define OW_FLAG_NO_COLLISION 0 // If this flag is set, the player will be able to walk over tiles with collision. Mainly intended for debugging purposes.
#define OW_FLAG_POKE_RIDER 0 // If this flag is set, the player will be able to use fly from the Pokenav Region Map section by pressing 'R' on a city/location they have been to.
#define OW_FLAG_PAUSE_TIME 0 // If this flag is set and OW_USE_FAKE_RTC is enabled, seconds on the in-game clock will not advance.
#define OW_FLAG_NO_ENCOUNTER 0 // If this flag is set, wild encounters will be disabled.
#define OW_FLAG_NO_TRAINER_SEE 0 // If this flag is set, trainers will not battle the player unless they're talked to.
#define OW_FLAG_NO_COLLISION 0 // If this flag is set, the player will be able to walk over tiles with collision. Mainly intended for debugging purposes.
#define OW_FLAG_POKE_RIDER 0 // If this flag is set, the player will be able to use fly from the Pokenav Region Map section by pressing 'R' on a city/location they have been to.

Match previous alignment

{
struct RegionMap* regionMap = GetSubstructPtr(POKENAV_SUBSTRUCT_REGION_MAP);

if (regionMap->mapSecType == MAPSECTYPE_CITY_CANFLY && OW_FLAG_POKE_RIDER)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (regionMap->mapSecType == MAPSECTYPE_CITY_CANFLY && OW_FLAG_POKE_RIDER)
if (regionMap->mapSecType == MAPSECTYPE_CITY_CANFLY && OW_FLAG_POKE_RIDER && Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType))

Handling for prevention of flying indoors etc.

@@ -215,6 +222,9 @@ static u32 HandleRegionMapInput(struct Pokenav_RegionMapMenu *state)
case MAP_INPUT_B_BUTTON:
state->callback = GetExitRegionMapMenuId;
return POKENAV_MAP_FUNC_EXIT;
case MAP_INPUT_R_BUTTON:
if (regionMap->mapSecType == MAPSECTYPE_CITY_CANFLY && OW_FLAG_POKE_RIDER)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (regionMap->mapSecType == MAPSECTYPE_CITY_CANFLY && OW_FLAG_POKE_RIDER)
if (regionMap->mapSecType == MAPSECTYPE_CITY_CANFLY && OW_FLAG_POKE_RIDER && Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE)

@khbsd
Copy link
Author

khbsd commented Dec 19, 2024

addressed @hedara90's comments, looking into the town map item functionality now!

@khbsd
Copy link
Author

khbsd commented Dec 20, 2024

added the prompt for flying from the town map. it replaces HOENN in the region title at the top right; this was the most space-efficient solution i could think of that didnt mean covering up more of the map.

Comment on lines 56 to 57
u8 hoennOffset;
u8 flyOffset;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this outside of a function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i figured it'd be better to set them when the FieldUpdateRegionMap() is called rather than every time the PrintTitleWindowText() function is called to speed up text display

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass them as arguments into PrintTitleWindowText() instead then. We don't define variables outside of functions unless they are globals and those don't need to be globals.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the function FieldUpdateRegionMap is rerun each case which means that they are calculated each time regardless so you aren't gaining any speed improvement with this which means you could just calc it in PrintTitleWindowText which will be better for speed because you aren't recalcing each time FieldUpdateRegionMap is run.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know! i thought it was a big loop inside FieldUpdateRegionMap lol

@@ -45,6 +49,12 @@ static void VBCB_FieldUpdateRegionMap(void);
static void MCB2_FieldUpdateRegionMap(void);
static void FieldUpdateRegionMap(void);
static void PrintRegionMapSecName(void);
static void PrintTitleWindowText(void);

static const u8* const FlyPromptText = COMPOUND_STRING("{R_BUTTON}FLY");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be just a normal text string. We don't use compound strings like that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually straight from the strings used in the pokenav helpbar, though there it's an array.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Compound Strings for non duplicate strings, so single use strings. If you want this to use multiply times it should be a normal string so

static const u8 sFlyPropmtText[] = _("{R_BUTTON}FLY");

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is technically a single use string- should it stay a compound string then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use it twice right?

The reason we use compound strings is because they make code more readable and additionally save a little bit of space so in your case it should be moved where it is needed in the first place. Though iirc we've decided to keep using normal strings for function arguments so you would need to convert it either way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, i see, yeah it's used once in the file, but twice in the function. fixed!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm in this case should it be defined in the PrintTitleWindowText func? since it's only used there?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Comment on lines +226 to +227
if (regionMap->mapSecType == MAPSECTYPE_CITY_CANFLY && FlagGet(OW_FLAG_POKE_RIDER) &&
Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (regionMap->mapSecType == MAPSECTYPE_CITY_CANFLY && FlagGet(OW_FLAG_POKE_RIDER) &&
Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE)
if (regionMap->mapSecType == MAPSECTYPE_CITY_CANFLY && FlagGet(OW_FLAG_POKE_RIDER)
&& Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE)

Copy link
Collaborator

@AlexOn1ine AlexOn1ine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more things. I'll test ingame after that and should be ready for a merge

AddTextPrinterParameterized(WIN_TITLE, FONT_NORMAL, gText_Hoenn, hoennOffset, 1, 0, NULL);
CopyWindowToVram(WIN_TITLE, COPYWIN_FULL);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Comment on lines 190 to 191
if (sFieldRegionMapHandler->regionMap.mapSecType == MAPSECTYPE_CITY_CANFLY &&
FlagGet(OW_FLAG_POKE_RIDER) && Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (sFieldRegionMapHandler->regionMap.mapSecType == MAPSECTYPE_CITY_CANFLY &&
FlagGet(OW_FLAG_POKE_RIDER) && Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE)
if (sFieldRegionMapHandler->regionMap.mapSecType == MAPSECTYPE_CITY_CANFLY
&& FlagGet(OW_FLAG_POKE_RIDER) && Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE)

src/region_map.c Outdated

void SetFlyDestination(struct RegionMap* regionMap)
{
u8 flyDestination = FilterFlyDestination(regionMap);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
u8 flyDestination = FilterFlyDestination(regionMap);
u32 flyDestination = FilterFlyDestination(regionMap);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this one need to be a u8? void SetWarpDestinationToHealLocation(u8 healLocationId);

Copy link
Collaborator

@AlexOn1ine AlexOn1ine Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't. The compiler wastes an instruction and turns it into a u32 anyways so technically it would be better to change the healLocationId argument to a u32.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah rad- will adjust! ty!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should healLocationId-> u32 be included in this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, since you haven't touched the function I wouldn't

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

Comment on lines 234 to 235
u8 hoennOffset = GetStringCenterAlignXOffset(FONT_NORMAL, gText_Hoenn, 0x38);
u8 flyOffset = GetStringCenterAlignXOffset(FONT_NORMAL, FlyPromptText, 0x38);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
u8 hoennOffset = GetStringCenterAlignXOffset(FONT_NORMAL, gText_Hoenn, 0x38);
u8 flyOffset = GetStringCenterAlignXOffset(FONT_NORMAL, FlyPromptText, 0x38);
u32 hoennOffset = GetStringCenterAlignXOffset(FONT_NORMAL, gText_Hoenn, 0x38);
u32 flyOffset = GetStringCenterAlignXOffset(FONT_NORMAL, FlyPromptText, 0x38);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature Adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants