Repository navigation
PokemonFRLG: navigation helpers (Sevii Islands Fly, field moves, items, party order) #1905
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| */ | ||
|
|
||
| #include <array> | ||
| #include "Common/Cpp/Exceptions.h" | ||
| #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" | ||
| #include "CommonFramework/VideoPipeline/VideoFeed.h" | ||
| #include "CommonTools/Random.h" | ||
|
|
@@ -950,7 +951,7 @@ void use_teleport_from_overworld(ConsoleHandle& console, ProControllerContext& c | |
| } | ||
| } | ||
|
|
||
| void open_fly_map_from_overworld(ConsoleHandle& console, ProControllerContext& context){ | ||
| void open_fly_map_from_overworld(ConsoleHandle& console, ProControllerContext& context, bool sevii_islands){ | ||
| uint16_t errors = 0; | ||
| while (true){ | ||
| if (errors > 5){ | ||
|
|
@@ -985,25 +986,28 @@ void open_fly_map_from_overworld(ConsoleHandle& console, ProControllerContext& c | |
| } | ||
|
|
||
| // select Fly (2nd option, but maybe other HMs could change this) | ||
| KantoMapWatcher map_opened(COLOR_RED); | ||
| // The Kanto map is checked for Kanto's land; the Sevii Islands maps only for the map's frame. | ||
| KantoMapWatcher kanto_map_opened(COLOR_RED); | ||
| FlyMapWatcher sevii_map_opened(COLOR_RED); | ||
| context.wait_for_all_requests(); | ||
| pbf_move_left_joystick(context, {0, -1}, 200ms, 300ms); | ||
| pbf_press_button(context, BUTTON_A, 200ms, 0ms); | ||
| ret = wait_until( | ||
| console, context, 20000ms, | ||
| {map_opened} | ||
| ); | ||
| if (sevii_islands){ | ||
| ret = wait_until(console, context, 20000ms, {sevii_map_opened}); | ||
| }else{ | ||
| ret = wait_until(console, context, 20000ms, {kanto_map_opened}); | ||
| } | ||
|
|
||
| if (ret < 0){ | ||
| console.log("Failed to detect Kanto map"); | ||
| console.log(sevii_islands ? "Failed to detect Sevii Islands map" : "Failed to detect Kanto map"); | ||
| errors++; | ||
| pbf_mash_button(context, BUTTON_B, 4000ms); | ||
| continue; | ||
| } | ||
|
|
||
| pbf_wait(context, 1000ms); | ||
| context.wait_for_all_requests(); | ||
| console.log("Kanto map detected."); | ||
| console.log(sevii_islands ? "Sevii Islands map detected." : "Kanto map detected."); | ||
| return; | ||
| } | ||
| } | ||
|
|
@@ -1112,6 +1116,266 @@ void fly_from_kanto_map(ConsoleHandle& console, ProControllerContext& context, K | |
|
|
||
| } | ||
|
|
||
| namespace{ | ||
|
|
||
| // A town's cell on its Sevii Islands Fly map page, and the page corner the | ||
| // cursor goes to first. Each page is a 22 x 15 grid and the cursor stops at | ||
| // its edges (region_map_layout_sevii_*.h in the decomp), so a corner is an | ||
| // exact starting point. Each town uses the corner closest to it. | ||
| struct SeviiFlyTarget{ | ||
| const char* name; | ||
| int x; | ||
| int y; | ||
| bool corner_right; | ||
| bool corner_bottom; | ||
| }; | ||
| constexpr int SEVII_MAP_WIDTH = 22; | ||
| constexpr int SEVII_MAP_HEIGHT = 15; | ||
|
|
||
| SeviiFlyTarget sevii_fly_target(SeviiFlyLocation destination){ | ||
| switch (destination){ | ||
| case SeviiFlyLocation::oneisland: | ||
| return {"One Island", 1, 8, false, true}; | ||
| case SeviiFlyLocation::twoisland: | ||
| return {"Two Island", 9, 9, false, true}; | ||
| case SeviiFlyLocation::threeisland: | ||
| return {"Three Island", 18, 12, true, true}; | ||
| case SeviiFlyLocation::fourisland: | ||
| return {"Four Island", 3, 4, false, false}; | ||
| case SeviiFlyLocation::fiveisland: | ||
| return {"Five Island", 16, 11, true, true}; | ||
| case SeviiFlyLocation::sixisland: | ||
| return {"Six Island", 17, 5, true, false}; | ||
| case SeviiFlyLocation::sevenisland: | ||
| return {"Seven Island", 5, 8, false, true}; | ||
| } | ||
| return {"", 0, 0, false, false}; | ||
| } | ||
|
|
||
| // Move the Fly map cursor one cell. (A held direction repeats every 5 | ||
| // frames and can overshoot by a cell; taps don't.) | ||
| void fly_map_cursor_tap(ProControllerContext& context, DpadPosition direction, int count){ | ||
| for (int i = 0; i < count; i++){ | ||
| pbf_press_dpad(context, direction, 50ms, 300ms); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| bool fly_from_sevii_map(ConsoleHandle& console, ProControllerContext& context, SeviiFlyLocation destination){ | ||
| SeviiFlyTarget target = sevii_fly_target(destination); | ||
| console.log(std::string("Flying to ") + target.name + "."); | ||
|
|
||
| // Hold into the corner. From the far side of the page that is 21 cells, | ||
| // about 1.8 seconds. | ||
| pbf_move_left_joystick( | ||
| context, | ||
| {target.corner_right ? +1.0 : -1.0, target.corner_bottom ? -1.0 : +1.0}, | ||
| 2500ms, 300ms | ||
| ); | ||
|
|
||
| // Then tap across to the town. | ||
| int corner_x = target.corner_right ? SEVII_MAP_WIDTH - 1 : 0; | ||
| int corner_y = target.corner_bottom ? SEVII_MAP_HEIGHT - 1 : 0; | ||
| int dx = target.x - corner_x; | ||
| int dy = target.y - corner_y; | ||
| fly_map_cursor_tap(context, dx > 0 ? DPAD_RIGHT : DPAD_LEFT, dx > 0 ? dx : -dx); | ||
| fly_map_cursor_tap(context, dy > 0 ? DPAD_DOWN : DPAD_UP, dy > 0 ? dy : -dy); | ||
|
Comment on lines
+1178
to
+1184
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flying from the Kanto map uses long presses rather than a series of taps, and these tend to be quite consistent. I'd prefer not to have two different approaches for the same thing, and the long presses will be slightly faster |
||
|
|
||
| // A picks the town, A again confirms. The screen fades to black as the | ||
| // flight starts. | ||
| BlackScreenWatcher flying(COLOR_RED); | ||
| context.wait_for_all_requests(); | ||
| int ret = run_until<ProControllerContext>( | ||
| console, context, | ||
| [](ProControllerContext& context){ | ||
| pbf_press_button(context, BUTTON_A, 200ms, 2800ms); | ||
| pbf_press_button(context, BUTTON_A, 200ms, 2800ms); | ||
| }, | ||
| { flying } | ||
| ); | ||
| if (ret < 0){ | ||
| // A does nothing on a place that can't be flown to: a town on another | ||
| // island group's page, or one not visited yet. Close the Fly map, the | ||
| // party menu and the start menu. | ||
| console.log("Could not start flying. Is the town on this island group, and has it been visited?", COLOR_RED); | ||
| pbf_mash_button(context, BUTTON_B, 4000ms); | ||
| pbf_wait(context, 800ms); | ||
| context.wait_for_all_requests(); | ||
| return false; | ||
| } | ||
|
|
||
| pbf_wait(context, 8000ms); | ||
| context.wait_for_all_requests(); | ||
| console.log(std::string("Landed on ") + target.name + "."); | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
| void use_field_move_from_overworld(ConsoleHandle& console, ProControllerContext& context, int from_last, int field_move){ | ||
| uint16_t errors = 0; | ||
|
|
||
| while (true){ | ||
| if (errors > 5){ | ||
| OperationFailedExceptionWithScreenshot::fire( | ||
| ErrorReportMode::SEND_ERROR_REPORT, | ||
| "use_field_move_from_overworld(): Failed to open the Pokemon's menu 5 times in a row.", | ||
| console | ||
| ); | ||
| } | ||
|
|
||
| open_party_menu_from_overworld(console, context); | ||
| // From slot 1, up goes to CANCEL, then to the last slot, then upward. | ||
| for (int i = 0; i < 2 + from_last; i++){ | ||
| pbf_move_left_joystick(context, {0, +1}, 200ms, 300ms); | ||
| } | ||
|
|
||
| PartySelectionWatcher menu_opened(COLOR_RED); | ||
| context.wait_for_all_requests(); | ||
| int ret = run_until<ProControllerContext>( | ||
| console, context, | ||
| [](ProControllerContext& context){ | ||
| pbf_press_button(context, BUTTON_A, 200ms, 1800ms); | ||
| }, | ||
| { menu_opened } | ||
| ); | ||
| if (ret < 0){ | ||
| console.log("Failed to open the Pokemon's menu."); | ||
| errors++; | ||
| pbf_mash_button(context, BUTTON_B, 3000ms); | ||
| continue; | ||
| } | ||
|
|
||
| // The menu lists SUMMARY, then the field moves in the order the | ||
| // Pokemon knows them, then SWITCH, ITEM and CANCEL. | ||
| for (int i = 0; i < 1 + field_move; i++){ | ||
| pbf_move_left_joystick(context, {0, -1}, 200ms, 300ms); | ||
| } | ||
| pbf_press_button(context, BUTTON_A, 200ms, 800ms); | ||
| context.wait_for_all_requests(); | ||
| console.log("Used field move " + std::to_string(field_move + 1) + " of the Pokemon " + std::to_string(from_last) + " from the last."); | ||
| return; | ||
| } | ||
| } | ||
|
Comment on lines
+1216
to
+1260
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a generalization of some existing functions for using Sweet Scent, Teleport, and Fly. Having this separate to avoid repeated code is good, but we should also incorporate it into |
||
|
|
||
|
|
||
| void start_surfing(ConsoleHandle& console, ProControllerContext& context){ | ||
| for (int attempt = 0; attempt < 2; attempt++){ | ||
| WhiteDialogWatcher question(COLOR_RED); | ||
| context.wait_for_all_requests(); | ||
| pbf_press_button(context, BUTTON_A, 200ms, 0ms); | ||
| if (wait_until(console, context, 3000ms, { question }) < 0){ | ||
| console.log("No Surf question. Trying again."); | ||
| continue; | ||
| } | ||
| // "The water is dyed a deep blue... Would you like to SURF?", then | ||
| // YES / NO with YES selected. | ||
| pbf_wait(context, 2000ms); | ||
| pbf_press_button(context, BUTTON_A, 200ms, 1500ms); | ||
| // "X used SURF!", the Pokemon's picture, then the player hops on. | ||
| pbf_press_button(context, BUTTON_B, 200ms, 3500ms); | ||
| context.wait_for_all_requests(); | ||
| console.log("Started surfing."); | ||
| return; | ||
| } | ||
| OperationFailedExceptionWithScreenshot::fire( | ||
| ErrorReportMode::SEND_ERROR_REPORT, | ||
| "start_surfing(): Couldn't start surfing. Is the player facing water, and does a party Pokemon know Surf?", | ||
| console | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| void use_item_from_items_pocket(ConsoleHandle& console, ProControllerContext& context, uint8_t position){ | ||
| open_bag_from_overworld(console, context); | ||
| pbf_wait(context, 500ms); | ||
|
|
||
| // The Items pocket is the leftmost and pockets don't wrap. The item list | ||
| // doesn't wrap either: holding up reaches the first item. | ||
| for (int i = 0; i < 3; i++){ | ||
| pbf_press_dpad(context, DPAD_LEFT, 120ms, 400ms); | ||
| } | ||
| pbf_press_dpad(context, DPAD_UP, 3000ms, 200ms); | ||
| for (uint8_t i = 1; i < position; i++){ | ||
| pbf_press_dpad(context, DPAD_DOWN, 120ms, 250ms); | ||
| } | ||
|
|
||
| // A opens the item's menu with USE first; A again uses it. | ||
| pbf_press_button(context, BUTTON_A, 200ms, 800ms); | ||
| pbf_press_button(context, BUTTON_A, 200ms, 1500ms); | ||
|
|
||
| // Close the message, the bag and the start menu. | ||
| pbf_mash_button(context, BUTTON_B, 4000ms); | ||
| pbf_wait(context, 800ms); | ||
| context.wait_for_all_requests(); | ||
| console.log("Used item " + std::to_string(position) + " of the Items pocket."); | ||
| } | ||
|
|
||
|
|
||
| void swap_party_slots(ConsoleHandle& console, ProControllerContext& context, uint8_t first, uint8_t second){ | ||
| if (first < 1 || second > 6 || first >= second){ | ||
| throw InternalProgramError( | ||
| &console.logger(), PA_CURRENT_FUNCTION, | ||
| "swap_party_slots(): Invalid slots: " + std::to_string(first) + " and " + std::to_string(second) | ||
| ); | ||
| } | ||
| open_party_menu_from_overworld(console, context); | ||
|
|
||
| // Slot 1 is on the left; slots 2 to 6 are a column on the right. The | ||
| // cursor starts on slot 1. | ||
| if (first > 1){ | ||
| pbf_press_dpad(context, DPAD_RIGHT, 150ms, 400ms); | ||
| for (uint8_t i = 2; i < first; i++){ | ||
| pbf_press_dpad(context, DPAD_DOWN, 150ms, 400ms); | ||
| } | ||
| } | ||
|
|
||
| PartySelectionWatcher menu_opened(COLOR_RED); | ||
| context.wait_for_all_requests(); | ||
| int ret = run_until<ProControllerContext>( | ||
| console, context, | ||
| [](ProControllerContext& context){ | ||
| pbf_press_button(context, BUTTON_A, 200ms, 1800ms); | ||
| }, | ||
| { menu_opened } | ||
| ); | ||
| if (ret < 0){ | ||
| OperationFailedExceptionWithScreenshot::fire( | ||
| ErrorReportMode::SEND_ERROR_REPORT, | ||
| "swap_party_slots(): The Pokemon's menu did not open.", | ||
| console | ||
| ); | ||
| } | ||
|
|
||
| // SWITCH is third from the bottom (SWITCH, ITEM, CANCEL), whatever field | ||
| // moves are listed above it, and the menu wraps around: up 3 from SUMMARY. | ||
| for (int i = 0; i < 3; i++){ | ||
| pbf_move_left_joystick(context, {0, +1}, 200ms, 300ms); | ||
| } | ||
| pbf_press_button(context, BUTTON_A, 200ms, 800ms); | ||
|
|
||
| // Pick the second Pokemon. | ||
| if (first == 1){ | ||
| pbf_press_dpad(context, DPAD_RIGHT, 150ms, 400ms); | ||
| for (uint8_t i = 2; i < second; i++){ | ||
| pbf_press_dpad(context, DPAD_DOWN, 150ms, 400ms); | ||
| } | ||
| }else{ | ||
| for (uint8_t i = first; i < second; i++){ | ||
| pbf_press_dpad(context, DPAD_DOWN, 150ms, 400ms); | ||
| } | ||
| } | ||
| pbf_press_button(context, BUTTON_A, 200ms, 2500ms); | ||
|
|
||
| // Close the party menu and the start menu. | ||
| pbf_mash_button(context, BUTTON_B, 3000ms); | ||
| pbf_wait(context, 800ms); | ||
| context.wait_for_all_requests(); | ||
| console.log("Swapped party slots " + std::to_string(first) + " and " + std::to_string(second) + "."); | ||
| } | ||
|
|
||
|
|
||
| void enter_leave_pokecenter(ConsoleHandle& console, ProControllerContext& context, bool leave){ | ||
| uint16_t errors = 0; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Kanto don't have their coordinates directly stored (I just recorded inputs manually and replayed them to test for consistency), and they always start from the top left corner for simplicity. This new approach is fine, but I'd prefer not to have two independent approaches for the same thing. See https://github.com/PokemonAutomation/Arduino-Source/blob/main/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp#L1029-L1079 for the Kanto approach