From e4a61793c65efae4c6c575cc99e6c21aa35d300a Mon Sep 17 00:00:00 2001 From: jw098 Date: Tue, 10 Dec 2024 20:49:07 -0800 Subject: [PATCH] fix reset_to_pokecenter() --- .../PokemonSV/Programs/PokemonSV_Navigation.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SerialPrograms/Source/PokemonSV/Programs/PokemonSV_Navigation.cpp b/SerialPrograms/Source/PokemonSV/Programs/PokemonSV_Navigation.cpp index 38f6d3599..b4221f6ac 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/PokemonSV_Navigation.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/PokemonSV_Navigation.cpp @@ -773,11 +773,22 @@ void jump_off_wall_until_map_open(const ProgramInfo& info, ConsoleHandle& consol // Open map and teleport back to town pokecenter to reset the hunting path. void reset_to_pokecenter(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){ + size_t MAX_FAILURES = 5; + size_t num_failures = 0; while (true){ try { open_map_from_overworld(info, console, context); fly_to_closest_pokecenter_on_map(info, console, context); + return; }catch (UnexpectedBattleException&){ + num_failures++; + if (num_failures > MAX_FAILURES){ + throw OperationFailedException( + ErrorReport::SEND_ERROR_REPORT, console, + "reset_to_pokecenter(): Failed to reset to pokecenter. Repeatedly stuck in battle.", + true + ); + } run_battle_press_A(console, context, BattleStopCondition::STOP_OVERWORLD); } }