From b663f94007c65e389655d5e988009a7973f40ce2 Mon Sep 17 00:00:00 2001 From: theAstrogoth Date: Fri, 30 Oct 2026 16:50:31 -0500 Subject: [PATCH] FRLG RNG programs: handle false positives for wild encounter detection, fix grass_spin queueing --- .../PokemonFRLG/PokemonFRLG_Navigation.cpp | 19 +++++++++++++++---- .../PokemonFRLG/PokemonFRLG_Navigation.h | 1 + .../PokemonFRLG_RngNavigation.cpp | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp index e0f04d4332..970080ca26 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp @@ -1575,12 +1575,13 @@ int grass_spin(ConsoleHandle& console, ProControllerContext& context, bool leftr context.wait_for_all_requests(); console.log("Starting grass spin."); - WallClock deadline = current_time() + timeout; + + const size_t spins = (size_t)(timeout / 366ms); int ret = run_until( console, context, - [leftright, deadline](ProControllerContext& context){ - while (current_time() < deadline){ + [leftright, spins](ProControllerContext& context){ + for (size_t c = 0; c < spins; c++){ if (leftright){ pbf_move_left_joystick(context, {+1, 0}, 33ms, 150ms); pbf_move_left_joystick(context, {-1, 0}, 33ms, 150ms); @@ -1597,7 +1598,17 @@ int grass_spin(ConsoleHandle& console, ProControllerContext& context, bool leftr return -1; } - bool encounter_shiny = handle_encounter(console, context, true); + bool encounter_shiny; + try{ + encounter_shiny = handle_encounter(console, context, true); + }catch (OperationFailedException&){ + // check to see if it was a false positive + if (!in_overworld(console, context)){ + throw; + } + console.log("grass_spin(): No battle started. Still in the overworld.", COLOR_RED); + return -1; + } return encounter_shiny ? 1 : 0; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h index 5f9eb3959f..e802a4be6d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h @@ -168,6 +168,7 @@ void heal_at_pokecenter(ConsoleHandle& console, ProControllerContext& context); // Can be used to alternate left/right and up/down. It is important that the player is not facing // the same direction as the first thumbstick press. // returns -1 if no encounter is triggered, 0 if a non-shiny is encounter, and 1 if a shiny is encountered +// A spin that stops without starting a battle also returns -1, as long as the player is still in the overworld. int grass_spin(ConsoleHandle& console, ProControllerContext& context, bool leftright, Seconds timeout = 60s); // Trigger encounters by fishing with a registered rod. The player must be facing water. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp index ef1ce62790..498057f0a3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp @@ -485,7 +485,7 @@ int encounter_roamer( context.wait_for_all_requests(); pbf_move_left_joystick(context, {0, +1}, 200ms, 800ms); - int ret = grass_spin(console, context, true, 5s); + int ret = grass_spin(console, context, true, 8s); if (ret < 0){ attempts++; pbf_move_left_joystick(context, {0, -1}, 200ms, 800ms);