From d887e93dfb7008d4fc5126af6dfe00e37eaeb467 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 22 Oct 2026 17:32:33 -0700 Subject: [PATCH 1/7] Log one line naming the slot and quest for every BBQ reroll A reroll's decision was logged when the panel was planned ("Reroll selected. Rerolling quest."), with no slot or quest, and the reroll itself logged nothing until it was verified. With two rerolls planned, the second spent 10 BP ~30 s later with no line of its own (R5 12:45:40, 13:01:31), so log scans counted it as a reroll that was never selected. reroll_quest(), which every slot reroll goes through, now logs "Rerolling quest N (slug)." before it opens the panel, whatever the result. The slug comes from BBQuests_enum_to_string(), as in the quest reads, or is "unknown" for an undetected quest. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/Farming/PokemonSV_BBQTests.cpp | 18 +++++++++++++++++- .../Farming/PokemonSV_BlueberryQuests.cpp | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 03433af297..2c87ea1bc2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -75,6 +75,13 @@ class NullLogger : public Logger{ public: virtual void log(const std::string&, Color) override{} }; +class RecordingLogger : public Logger{ +public: + std::vector lines; + virtual void log(const std::string& line, Color) override{ + lines.push_back(line); + } +}; // A singleplayer quest panel that behaves like the game's: 3 blue quests, // and a completed quest is replaced by a new one. process_quest_list() @@ -536,9 +543,18 @@ class Test_BBQReroll : public UnitTest{ panel.out_of_bp = m_scenario.out_of_bp; panel.missed_reads = m_scenario.missed_reads; - NullLogger logger; + RecordingLogger logger; std::vector quests = m_scenario.quests; const BBQRerollResult result = reroll_quest(logger, panel, quests, m_scenario.slot); + //Each reroll logs one line naming its slot and quest, whatever the result. + const std::string reroll_line = "Rerolling quest " + std::to_string(m_scenario.slot + 1) + + " (" + BBQuests_enum_to_string(m_scenario.quests[m_scenario.slot]) + ")."; + const size_t reroll_lines = std::count_if(logger.lines.begin(), logger.lines.end(), [](const std::string& line){ + return line.starts_with("Rerolling quest "); + }); + if (reroll_lines != 1 || std::find(logger.lines.begin(), logger.lines.end(), reroll_line) == logger.lines.end()){ + return "Expected one log line \"" + reroll_line + "\", got " + std::to_string(reroll_lines) + " reroll lines."; + } if (result != m_scenario.expected){ return "Expected " + reroll_result_to_string(m_scenario.expected) + ", got " + reroll_result_to_string(result); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 091a6374f4..f61e9e6e7a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -296,6 +296,9 @@ BBQRerollResult reroll_quest( std::vector& quests, size_t slot ){ + //Every slot reroll logs this one line, whatever decided it, so a log shows each BP spent. + const std::string quest = slot < quests.size() ? BBQuests_enum_to_string(quests[slot]) : ""; + logger.log("Rerolling quest " + std::to_string(slot + 1) + " (" + (quest.empty() ? "unknown" : quest) + ")."); if (!actions.open_panel()){ return BBQRerollResult::PanelNotOpened; } From 7cf661bc011b25c159c818607e1180d1733b8c48 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 20 Oct 2026 19:56:32 -0700 Subject: [PATCH 2/7] Log BBQ boards and quest attempts through BBQLogger BBQ failures are hard to attribute to a specific quest and attempt from the existing logs. Add one-line "BBQ ..." events: - board: panel detected and quest slugs in board order, each time read_quests() reads the panel - per attempt: start, route_return and result, with attempt/limit and route, verification and total durations - catch battle-entry timeout, and retry exhaustion BBQLogger depends only on Logger and the Options/PokemonSV_BBQuests leaf, so the quest and catch/photo modules call into it without a dependency back. Durations use explicit steady_clock timestamps so tests can check them without depending on wall-clock time. Add four PokemonSV::BBQDiagnosticLogs tests to PokemonSV_BBQTests.cpp, with a recording logger, covering board formatting, success, failure with retry exhaustion, and long/zero durations. Controller sequences, retry limits and reroll policy are unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/Farming/PokemonSV_BBQLogger.cpp | 94 +++++++++++++++++++ .../Programs/Farming/PokemonSV_BBQLogger.h | 73 ++++++++++++++ .../Programs/Farming/PokemonSV_BBQTests.cpp | 85 +++++++++++++++++ .../Farming/PokemonSV_BlueberryCatchPhoto.cpp | 2 + .../Farming/PokemonSV_BlueberryQuests.cpp | 8 ++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 6 files changed, 264 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.h diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.cpp new file mode 100644 index 0000000000..ce408705c0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.cpp @@ -0,0 +1,94 @@ +/* BBQ Diagnostic Logger + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/PrettyPrint.h" +#include "PokemonSV_BBQLogger.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + + +namespace{ + +constexpr std::string_view UNKNOWN = "unknown"; + +std::string_view quest_label(BBQuests quest){ + const std::string& slug = BBQuests_enum_to_string(quest); + return slug.empty() ? UNKNOWN : std::string_view(slug); +} + +void append_elapsed(std::ostream& out, std::string_view field, BBQAttemptLog::Clock::duration elapsed){ + const auto milliseconds = std::chrono::duration_cast(elapsed); + out << ' ' << field << "_ms=" << milliseconds.count() + << ' ' << field << "=\"" << duration_to_string(milliseconds) << '\"'; +} + +} + + +void BBQLogger::board(bool panel_detected, const std::vector& quests){ + std::ostringstream out; + out << "BBQ event=board panel_detected=" << panel_detected << " quests="; + bool first = true; + for (BBQuests quest : quests){ + if (!first) out << ','; + first = false; + out << quest_label(quest); + } + m_logger.log(out.str()); +} + +void BBQLogger::battle_entry_timeout(BBQuests quest){ + std::ostringstream out; + out << "BBQ quest=" << quest_label(quest) << " event=battle_entry outcome=timeout"; + m_logger.log(out.str()); +} + +void BBQLogger::retry_exhausted(BBQuests quest){ + std::ostringstream out; + out << "BBQ quest=" << quest_label(quest) << " event=retry_exhausted recovery=skip_current_batch"; + m_logger.log(out.str()); +} + + +BBQAttemptLog::BBQAttemptLog( + Logger& logger, BBQuests quest, + unsigned attempt, unsigned limit, + Clock::time_point start +) + : m_logger(logger), m_start(start), m_route_end(start) +{ + std::ostringstream out; + out << "BBQ quest=" << quest_label(quest) << " attempt=" << attempt << " limit=" << limit; + m_attempt_description = out.str(); + out << " event=start"; + m_logger.log(out.str()); +} + +void BBQAttemptLog::route_return(Clock::time_point end){ + m_route_end = end; + std::ostringstream out; + out << m_attempt_description << " event=route_return"; + append_elapsed(out, "elapsed", end - m_start); + m_logger.log(out.str()); +} + +void BBQAttemptLog::result(bool completed, Clock::time_point end){ + std::ostringstream out; + out << m_attempt_description << " event=result outcome=" + << (completed ? "absent_from_board" : "still_on_board"); + append_elapsed(out, "verification", end - m_route_end); + append_elapsed(out, "total", end - m_start); + m_logger.log(out.str()); +} + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.h new file mode 100644 index 0000000000..cd53ba7a06 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.h @@ -0,0 +1,73 @@ +/* BBQ Diagnostic Logger + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonSV_BBQLogger_H +#define PokemonAutomation_PokemonSV_BBQLogger_H + +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "VideoGames/PokemonSV/Options/PokemonSV_BBQuests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + + +// Formats one-line "BBQ ..." diagnostic events through an existing Logger. +// Does no image I/O and no controller input. +class BBQLogger{ +public: + explicit BBQLogger(Logger& logger) : m_logger(logger) {} + + // The quest board as read from one panel snapshot: whether the panel was + // detected, and the quests in board order. + void board(bool panel_detected, const std::vector& quests); + + // A catch quest gave up waiting for the battle menu after navigating to its target. + void battle_entry_timeout(BBQuests quest); + + // A quest used all of its attempts and the rest of the batch will be skipped. + void retry_exhausted(BBQuests quest); + +private: + Logger& m_logger; +}; + + +// The event sequence and monotonic timing of one quest attempt. +// Timestamps default to now; tests pass fixed values. +class BBQAttemptLog{ +public: + using Clock = std::chrono::steady_clock; + + // Logs the start of attempt number `attempt` out of `limit`. + BBQAttemptLog( + Logger& logger, BBQuests quest, + unsigned attempt, unsigned limit, + Clock::time_point start = Clock::now() + ); + + // The quest routine returned; logs the time since start. + void route_return(Clock::time_point end = Clock::now()); + + // The board was re-read. `completed` means the quest is no longer on it. + // Logs the verification time since route_return() and the total time. + void result(bool completed, Clock::time_point end = Clock::now()); + +private: + Logger& m_logger; + const Clock::time_point m_start; + Clock::time_point m_route_end; + std::string m_attempt_description; +}; + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 999661c313..e66ed40513 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -5,6 +5,7 @@ */ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonSV_BBQLogger.h" #include "PokemonSV_BlueberryQuests.h" #include "PokemonSV_BBQTests.h" @@ -66,8 +67,92 @@ static void add_tests_TeraEncounterAction(UnitTestDatabase& database){ } +namespace{ + +class BBQTestLogger : public Logger{ +public: + virtual void log(const std::string& message, Color) override{ + messages.push_back(message); + } + std::vector messages; +}; + +class Test_BBQDiagnosticLogs : public UnitTest{ +public: + Test_BBQDiagnosticLogs(const std::string& scenario) + : UnitTest("PokemonSV::BBQDiagnosticLogs - " + scenario), m_scenario(scenario) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + BBQTestLogger logger; + std::vector expected; + const BBQAttemptLog::Clock::time_point start{}; + if (m_scenario == "board"){ + BBQLogger(logger).board(true, + {BBQuests::photo_swim, BBQuests::sneak_up, BBQuests::auto_10}); + BBQLogger(logger).board(false, {BBQuests::UnableToDetect}); + BBQLogger(logger).board(true, {}); + expected = { + "BBQ event=board panel_detected=1 quests=photo-swim,sneak-up,auto-10", + "BBQ event=board panel_detected=0 quests=unknown", + "BBQ event=board panel_detected=1 quests=", + }; + }else if (m_scenario == "success"){ + BBQAttemptLog attempt_log(logger, BBQuests::make_tm, 1, 2, start); + attempt_log.route_return(start + std::chrono::milliseconds(2000)); + attempt_log.result(true, start + std::chrono::milliseconds(2500)); + expected = { + "BBQ quest=make-tm attempt=1 limit=2 event=start", + "BBQ quest=make-tm attempt=1 limit=2 event=route_return elapsed_ms=2000 elapsed=\"2.000 seconds\"", + "BBQ quest=make-tm attempt=1 limit=2 event=result outcome=absent_from_board verification_ms=500 verification=\"0.500 seconds\" total_ms=2500 total=\"2.500 seconds\"", + }; + }else if (m_scenario == "retry-exhausted"){ + BBQLogger(logger).battle_entry_timeout(BBQuests::catch_any); + BBQAttemptLog attempt_log(logger, BBQuests::catch_any, 2, 2, start); + attempt_log.route_return(start + std::chrono::milliseconds(3345)); + attempt_log.result(false, start + std::chrono::milliseconds(4110)); + BBQLogger(logger).retry_exhausted(BBQuests::catch_any); + expected = { + "BBQ quest=catch-any event=battle_entry outcome=timeout", + "BBQ quest=catch-any attempt=2 limit=2 event=start", + "BBQ quest=catch-any attempt=2 limit=2 event=route_return elapsed_ms=3345 elapsed=\"3.345 seconds\"", + "BBQ quest=catch-any attempt=2 limit=2 event=result outcome=still_on_board verification_ms=765 verification=\"0.765 seconds\" total_ms=4110 total=\"4.110 seconds\"", + "BBQ quest=catch-any event=retry_exhausted recovery=skip_current_batch", + }; + }else if (m_scenario == "long-duration"){ + BBQAttemptLog attempt_log(logger, BBQuests::UnableToDetect, 256, 256, start); + attempt_log.route_return(start + std::chrono::milliseconds(120000)); + attempt_log.result(false, start + std::chrono::milliseconds(120000)); + expected = { + "BBQ quest=unknown attempt=256 limit=256 event=start", + "BBQ quest=unknown attempt=256 limit=256 event=route_return elapsed_ms=120000 elapsed=\"2.000 minutes\"", + "BBQ quest=unknown attempt=256 limit=256 event=result outcome=still_on_board verification_ms=0 verification=\"0.000 seconds\" total_ms=120000 total=\"2.000 minutes\"", + }; + }else{ + return "Unknown BBQ log test scenario."; + } + if (logger.messages != expected){ + return "Unexpected BBQ diagnostic log sequence for " + m_scenario; + } + return true; + } + +private: + const std::string m_scenario; +}; + +} + +static void add_tests_BBQDiagnosticLogs(UnitTestDatabase& database){ + for (const char* scenario : {"board", "success", "retry-exhausted", "long-duration"}){ + database.add(scenario); + } +} + + void add_tests_BBQ(UnitTestDatabase& database){ add_tests_TeraEncounterAction(database); + add_tests_BBQDiagnosticLogs(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp index 3a24e1d187..9ca5bf1dd3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp @@ -26,6 +26,7 @@ #include "VideoGames/PokemonSV/Programs/PokemonSV_WorldNavigation.h" #include "VideoGames/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.h" #include "VideoGames/PokemonSV/Programs/PokemonSV_Terarium.h" +#include "PokemonSV_BBQLogger.h" #include "PokemonSV_BlueberryCatchPhoto.h" namespace PokemonAutomation{ @@ -917,6 +918,7 @@ void quest_catch( ); if (ret2 != 0){ console.log("Did not enter battle. Did target spawn?"); + BBQLogger(console.logger()).battle_entry_timeout(current_quest); } }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 8bec917a63..c10d614eb8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -41,6 +41,7 @@ #include "VideoGames/PokemonSV/Programs/TeraRaids/PokemonSV_TeraBattler.h" #include "VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.h" #include "VideoGames/PokemonSV/Programs/PokemonSV_Terarium.h" +#include "PokemonSV_BBQLogger.h" #include "PokemonSV_BlueberryQuests.h" @@ -122,6 +123,8 @@ std::vector read_quests( quest_list.push_back(BBQuests_string_to_enum(fourth_quest)); } + BBQLogger(stream.logger()).board(result == 0, quest_list); + //Close quest list pbf_mash_button(context, BUTTON_B, 800ms); context.wait_for_all_requests(); @@ -321,6 +324,8 @@ bool process_and_do_quest( int quest_attempts = 0; while (!quest_completed){ + BBQAttemptLog attempt_log(console.logger(), current_quest, quest_attempts + 1, + (unsigned)BBQ_OPTIONS.NUM_RETRIES + 1); switch (current_quest){ case BBQuests::make_tm: quest_make_tm(env.program_info(), console, context); @@ -419,6 +424,7 @@ bool process_and_do_quest( break; } + attempt_log.route_return(); //Validate quest was completed by checking list std::vector quest_list = read_quests(env.program_info(), console, context, BBQ_OPTIONS); if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){ @@ -434,7 +440,9 @@ bool process_and_do_quest( quest_completed = true; } + attempt_log.result(quest_completed); if (quest_attempts > BBQ_OPTIONS.NUM_RETRIES){ + BBQLogger(console.logger()).retry_exhausted(current_quest); console.log("Failed to complete a quest multiple times. Skipping it for now.", COLOR_RED); break; } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index ce54742834..7709c22832 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2595,6 +2595,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonSV/Programs/Eggs/PokemonSV_EggRoutines.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_AuctionFarmer.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_AuctionFarmer.h + Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.cpp + Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp From 57002fb3aeb785f7cd5c4146f23f30dfe8247bd9 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 6 Nov 2026 14:35:46 -0800 Subject: [PATCH 3/7] Initialize the default expected log color for Windows Clang --- .../PokemonSV/Programs/Farming/PokemonSV_BBQLogger_Tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger_Tests.cpp index 01728d86c2..a250b58cff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger_Tests.cpp @@ -56,7 +56,7 @@ struct DiagnosticLogInput{ // Exact message order is part of the diagnostics contract. struct DiagnosticLogExpectation{ std::vector messages; - Color final_color; + Color final_color{}; }; // Each case keeps all inputs and expected output visible together. From dbc3c7430bffe1b81a8995551c5c06fee9733aee Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 6 Nov 2026 15:20:49 -0800 Subject: [PATCH 4/7] Separate BBQ quest dispatch and retry execution from quest implementations --- .../Farming/PokemonSV_BlueberryQuests.cpp | 132 ----------- .../PokemonSV_BlueberryQuests_Execution.cpp | 207 ++++++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 1 + 3 files changed, 208 insertions(+), 132 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 2861283c87..a7e00414fa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -436,138 +436,6 @@ std::vector process_quest_list( return plan.to_do; } -bool process_and_do_quest( - ProgramEnvironment& env, - ConsoleHandle& console, ProControllerContext& context, - BBQOption& BBQ_OPTIONS, - BBQuests current_quest, - uint8_t& eggs_hatched -){ - bool quest_completed = false; - int quest_attempts = 0; - - while (!quest_completed){ - switch (current_quest){ - case BBQuests::make_tm: - quest_make_tm(env.program_info(), console, context); - break; - case BBQuests::travel_500: - quest_travel_500(env.program_info(), console, context); - break; - case BBQuests::tera_self_defeat: - quest_tera_self_defeat(env.program_info(), console, context, BBQ_OPTIONS); - break; - case BBQuests::sneak_up: - quest_sneak_up(env.program_info(), console, context, BBQ_OPTIONS); - break; - case BBQuests::wild_tera: - quest_wild_tera(env.program_info(), console, context, BBQ_OPTIONS); - break; - case BBQuests::wash_pokemon: - quest_wash_pokemon(env.program_info(), console, context); - break; - case BBQuests::hatch_egg: - quest_hatch_egg(env, console, context, BBQ_OPTIONS); - break; - case BBQuests::bitter_sandwich: - case BBQuests::salty_sandwich: - case BBQuests::sour_sandwich: - case BBQuests::spicy_sandwich: - case BBQuests::sweet_sandwich: - case BBQuests::sandwich_three: - quest_sandwich(env, console, context, BBQ_OPTIONS, current_quest); - break; - //case BBQuests::pickup_10: - // quest_pickup(env, env.program_info(), console, context, BBQ_OPTIONS); - // break; - case BBQuests::tera_raid: - quest_tera_raid(env, console, context, BBQ_OPTIONS); - break; - case BBQuests::auto_10: - case BBQuests::auto_30: - quest_auto_battle(env, console, context, BBQ_OPTIONS, current_quest); - break; - //All involve taking pictures - case BBQuests::photo_fly: - case BBQuests::photo_swim: - case BBQuests::photo_canyon: - case BBQuests::photo_coastal: - case BBQuests::photo_polar: - case BBQuests::photo_savanna: - case BBQuests::photo_normal: - case BBQuests::photo_fighting: - case BBQuests::photo_flying: - case BBQuests::photo_poison: - case BBQuests::photo_ground: - case BBQuests::photo_rock: - case BBQuests::photo_bug: - case BBQuests::photo_ghost: - case BBQuests::photo_steel: - case BBQuests::photo_fire: - case BBQuests::photo_water: - case BBQuests::photo_grass: - case BBQuests::photo_electric: - case BBQuests::photo_psychic: - case BBQuests::photo_ice: - case BBQuests::photo_dragon: - case BBQuests::photo_dark: - case BBQuests::photo_fairy: - quest_photo(env.program_info(), console, context, BBQ_OPTIONS, current_quest); - break; - //All involve catching a pokemon - case BBQuests::catch_any: - case BBQuests::catch_normal: - case BBQuests::catch_fighting: - case BBQuests::catch_flying: - case BBQuests::catch_poison: - case BBQuests::catch_ground: - case BBQuests::catch_rock: - case BBQuests::catch_bug: - case BBQuests::catch_ghost: - case BBQuests::catch_steel: - case BBQuests::catch_fire: - case BBQuests::catch_water: - case BBQuests::catch_grass: - case BBQuests::catch_electric: - case BBQuests::catch_psychic: - case BBQuests::catch_ice: - case BBQuests::catch_dragon: - case BBQuests::catch_dark: - case BBQuests::catch_fairy: - quest_catch(env.program_info(), console, context, BBQ_OPTIONS, current_quest); - break; - default: - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - "Unknown quest selection.", - console - ); - break; - } - - //Validate quest was completed by checking list - std::vector quest_list = read_quests(env.program_info(), console, context, BBQ_OPTIONS); - if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){ - console.log("Current quest exists on list. Quest did not complete."); - quest_attempts++; - }else{ - console.log("Current quest was not found. Quest completed!"); - if (current_quest == BBQuests::hatch_egg){ - eggs_hatched++; - console.log("Eggs hatched: " + std::to_string(eggs_hatched)); - } - - quest_completed = true; - } - - if (quest_attempts > BBQ_OPTIONS.NUM_RETRIES){ - console.log("Failed to complete a quest multiple times. Skipping it for now.", COLOR_RED); - break; - } - } - return quest_completed; -} - void quest_make_tm(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){ stream.log("Quest: Make TM"); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp new file mode 100644 index 0000000000..ecd041fc05 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp @@ -0,0 +1,207 @@ +/* Blueberry Quest Execution + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "PokemonSV_BlueberryCatchPhoto.h" +#include "PokemonSV_BlueberryQuests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ +namespace{ + +// Returns true after executing one supported quest; false performs no action. +bool run_basic_quest( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BBQOption& BBQ_OPTIONS, BBQuests current_quest +){ + switch (current_quest){ + case BBQuests::make_tm: + quest_make_tm(env.program_info(), console, context); + return true; + case BBQuests::travel_500: + quest_travel_500(env.program_info(), console, context); + return true; + case BBQuests::tera_self_defeat: + quest_tera_self_defeat(env.program_info(), console, context, BBQ_OPTIONS); + return true; + case BBQuests::sneak_up: + quest_sneak_up(env.program_info(), console, context, BBQ_OPTIONS); + return true; + case BBQuests::wild_tera: + quest_wild_tera(env.program_info(), console, context, BBQ_OPTIONS); + return true; + case BBQuests::wash_pokemon: + quest_wash_pokemon(env.program_info(), console, context); + return true; + default: + return false; + } +} + +// Returns true after executing one supported quest; false performs no action. +bool run_event_quest( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BBQOption& BBQ_OPTIONS, BBQuests current_quest +){ + switch (current_quest){ + case BBQuests::hatch_egg: + quest_hatch_egg(env, console, context, BBQ_OPTIONS); + return true; + case BBQuests::bitter_sandwich: + case BBQuests::salty_sandwich: + case BBQuests::sour_sandwich: + case BBQuests::spicy_sandwich: + case BBQuests::sweet_sandwich: + case BBQuests::sandwich_three: + quest_sandwich(env, console, context, BBQ_OPTIONS, current_quest); + return true; + //case BBQuests::pickup_10: + // quest_pickup(env, env.program_info(), console, context, BBQ_OPTIONS); + // break; + case BBQuests::tera_raid: + quest_tera_raid(env, console, context, BBQ_OPTIONS); + return true; + case BBQuests::auto_10: + case BBQuests::auto_30: + quest_auto_battle(env, console, context, BBQ_OPTIONS, current_quest); + return true; + default: + return false; + } +} + +// Returns true after executing one supported quest; false performs no action. +bool run_photo_quest( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BBQOption& BBQ_OPTIONS, BBQuests current_quest +){ + switch (current_quest){ + //All involve taking pictures + case BBQuests::photo_fly: + case BBQuests::photo_swim: + case BBQuests::photo_canyon: + case BBQuests::photo_coastal: + case BBQuests::photo_polar: + case BBQuests::photo_savanna: + case BBQuests::photo_normal: + case BBQuests::photo_fighting: + case BBQuests::photo_flying: + case BBQuests::photo_poison: + case BBQuests::photo_ground: + case BBQuests::photo_rock: + case BBQuests::photo_bug: + case BBQuests::photo_ghost: + case BBQuests::photo_steel: + case BBQuests::photo_fire: + case BBQuests::photo_water: + case BBQuests::photo_grass: + case BBQuests::photo_electric: + case BBQuests::photo_psychic: + case BBQuests::photo_ice: + case BBQuests::photo_dragon: + case BBQuests::photo_dark: + case BBQuests::photo_fairy: + quest_photo(env.program_info(), console, context, BBQ_OPTIONS, current_quest); + return true; + default: + return false; + } +} + +// Returns true after executing one supported quest; false performs no action. +bool run_catch_quest( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BBQOption& BBQ_OPTIONS, BBQuests current_quest +){ + switch (current_quest){ + //All involve catching a pokemon + case BBQuests::catch_any: + case BBQuests::catch_normal: + case BBQuests::catch_fighting: + case BBQuests::catch_flying: + case BBQuests::catch_poison: + case BBQuests::catch_ground: + case BBQuests::catch_rock: + case BBQuests::catch_bug: + case BBQuests::catch_ghost: + case BBQuests::catch_steel: + case BBQuests::catch_fire: + case BBQuests::catch_water: + case BBQuests::catch_grass: + case BBQuests::catch_electric: + case BBQuests::catch_psychic: + case BBQuests::catch_ice: + case BBQuests::catch_dragon: + case BBQuests::catch_dark: + case BBQuests::catch_fairy: + quest_catch(env.program_info(), console, context, BBQ_OPTIONS, current_quest); + return true; + default: + return false; + } +} + +// Dispatch to the same quest routines as the original switch, or report an unsupported quest. +void execute_quest( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BBQOption& BBQ_OPTIONS, BBQuests current_quest +){ + if (run_basic_quest(env, console, context, BBQ_OPTIONS, current_quest) + || run_event_quest(env, console, context, BBQ_OPTIONS, current_quest) + || run_photo_quest(env, console, context, BBQ_OPTIONS, current_quest) + || run_catch_quest(env, console, context, BBQ_OPTIONS, current_quest) + ){ + return; + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "Unknown quest selection.", console + ); +} + +} // namespace + +// Execute/retry from the overworld, verify the board and preserve the caller's egg count. +bool process_and_do_quest( + ProgramEnvironment& env, + ConsoleHandle& console, ProControllerContext& context, + BBQOption& BBQ_OPTIONS, + BBQuests current_quest, + uint8_t& eggs_hatched +){ + bool quest_completed = false; + int quest_attempts = 0; + + while (!quest_completed){ + execute_quest(env, console, context, BBQ_OPTIONS, current_quest); + + //Validate quest was completed by checking list + std::vector quest_list = read_quests(env.program_info(), console, context, BBQ_OPTIONS); + if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){ + console.log("Current quest exists on list. Quest did not complete."); + quest_attempts++; + }else{ + console.log("Current quest was not found. Quest completed!"); + if (current_quest == BBQuests::hatch_egg){ + eggs_hatched++; + console.log("Eggs hatched: " + std::to_string(eggs_hatched)); + } + + quest_completed = true; + } + + if (quest_attempts > BBQ_OPTIONS.NUM_RETRIES){ + console.log("Failed to complete a quest multiple times. Skipping it for now.", COLOR_RED); + break; + } + } + return quest_completed; +} + +} // namespace PokemonSV +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 32c8dbf362..16669564bd 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2648,6 +2648,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp + Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.h From be6feea3204c5056dca313e8cb3b1c56adb64031 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 6 Nov 2026 15:21:15 -0800 Subject: [PATCH 5/7] Include the environment definition used by the extracted dispatcher --- .../Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp index ecd041fc05..1c9a478926 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp @@ -6,6 +6,7 @@ #include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/Tools/ProgramEnvironment.h" #include "PokemonSV_BlueberryCatchPhoto.h" #include "PokemonSV_BlueberryQuests.h" From 490c83cfae8dd82af0311b7362cad81e4a03d16f Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 6 Nov 2026 15:28:27 -0800 Subject: [PATCH 6/7] Place the panel-result explanation beside the quest reader --- .../PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index b7cf04869d..1b9924ec9f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -62,7 +62,7 @@ int read_BP(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context.wait_for_all_requests(); } }, - {{ right_panel }} // Detector index 0; a negative run_until result means no detection. + {{ right_panel }} ); if (result == 0){ stream.log("Found quest panel."); @@ -103,6 +103,7 @@ bool open_quest_panel(VideoStream& stream, ProControllerContext& context){ } +// Detector index 0 confirms the quest panel; a negative run_until result means no detection. std::vector read_quests( const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, From 722af5ac25a9e0ccf9fba3067a8901cf4142bb13 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 6 Nov 2026 16:02:18 -0800 Subject: [PATCH 7/7] Undo linter-driven quest execution split and retain the existing dispatcher Keep the logging-only scope requested in review. The user explicitly directed retaining and ignoring the existing legacy size: process_and_do_quest grows from 131 to 135 lines, and its file from 1452 to 1463. These are the only two code-health findings; no general linter threshold is changed. --- .../Farming/PokemonSV_BlueberryQuests.cpp | 136 +++++++++++ .../PokemonSV_BlueberryQuests_Execution.cpp | 213 ------------------ SerialPrograms/cmake/SourceFiles.cmake | 1 - 3 files changed, 136 insertions(+), 214 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 1b9924ec9f..afe39c8692 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -443,6 +443,142 @@ std::vector process_quest_list( return plan.to_do; } +bool process_and_do_quest( + ProgramEnvironment& env, + ConsoleHandle& console, ProControllerContext& context, + BBQOption& BBQ_OPTIONS, + BBQuests current_quest, + uint8_t& eggs_hatched +){ + bool quest_completed = false; + int quest_attempts = 0; + + while (!quest_completed){ + BBQAttemptLog attempt_log( + console.logger(), /*quest=*/current_quest, + /*attempt=*/quest_attempts + 1, /*limit=*/static_cast(BBQ_OPTIONS.NUM_RETRIES) + 1 + ); + switch (current_quest){ + case BBQuests::make_tm: + quest_make_tm(env.program_info(), console, context); + break; + case BBQuests::travel_500: + quest_travel_500(env.program_info(), console, context); + break; + case BBQuests::tera_self_defeat: + quest_tera_self_defeat(env.program_info(), console, context, BBQ_OPTIONS); + break; + case BBQuests::sneak_up: + quest_sneak_up(env.program_info(), console, context, BBQ_OPTIONS); + break; + case BBQuests::wild_tera: + quest_wild_tera(env.program_info(), console, context, BBQ_OPTIONS); + break; + case BBQuests::wash_pokemon: + quest_wash_pokemon(env.program_info(), console, context); + break; + case BBQuests::hatch_egg: + quest_hatch_egg(env, console, context, BBQ_OPTIONS); + break; + case BBQuests::bitter_sandwich: + case BBQuests::salty_sandwich: + case BBQuests::sour_sandwich: + case BBQuests::spicy_sandwich: + case BBQuests::sweet_sandwich: + case BBQuests::sandwich_three: + quest_sandwich(env, console, context, BBQ_OPTIONS, current_quest); + break; + //case BBQuests::pickup_10: + // quest_pickup(env, env.program_info(), console, context, BBQ_OPTIONS); + // break; + case BBQuests::tera_raid: + quest_tera_raid(env, console, context, BBQ_OPTIONS); + break; + case BBQuests::auto_10: + case BBQuests::auto_30: + quest_auto_battle(env, console, context, BBQ_OPTIONS, current_quest); + break; + //All involve taking pictures + case BBQuests::photo_fly: + case BBQuests::photo_swim: + case BBQuests::photo_canyon: + case BBQuests::photo_coastal: + case BBQuests::photo_polar: + case BBQuests::photo_savanna: + case BBQuests::photo_normal: + case BBQuests::photo_fighting: + case BBQuests::photo_flying: + case BBQuests::photo_poison: + case BBQuests::photo_ground: + case BBQuests::photo_rock: + case BBQuests::photo_bug: + case BBQuests::photo_ghost: + case BBQuests::photo_steel: + case BBQuests::photo_fire: + case BBQuests::photo_water: + case BBQuests::photo_grass: + case BBQuests::photo_electric: + case BBQuests::photo_psychic: + case BBQuests::photo_ice: + case BBQuests::photo_dragon: + case BBQuests::photo_dark: + case BBQuests::photo_fairy: + quest_photo(env.program_info(), console, context, BBQ_OPTIONS, current_quest); + break; + //All involve catching a pokemon + case BBQuests::catch_any: + case BBQuests::catch_normal: + case BBQuests::catch_fighting: + case BBQuests::catch_flying: + case BBQuests::catch_poison: + case BBQuests::catch_ground: + case BBQuests::catch_rock: + case BBQuests::catch_bug: + case BBQuests::catch_ghost: + case BBQuests::catch_steel: + case BBQuests::catch_fire: + case BBQuests::catch_water: + case BBQuests::catch_grass: + case BBQuests::catch_electric: + case BBQuests::catch_psychic: + case BBQuests::catch_ice: + case BBQuests::catch_dragon: + case BBQuests::catch_dark: + case BBQuests::catch_fairy: + quest_catch(env.program_info(), console, context, BBQ_OPTIONS, current_quest); + break; + default: + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "Unknown quest selection.", + console + ); + break; + } + + attempt_log.route_return(); + //Validate quest was completed by checking list + std::vector quest_list = read_quests(env.program_info(), console, context, BBQ_OPTIONS); + if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){ + quest_attempts++; + }else{ + if (current_quest == BBQuests::hatch_egg){ + eggs_hatched++; + console.log("Eggs hatched: " + std::to_string(eggs_hatched)); + } + + quest_completed = true; + } + + attempt_log.result(/*completed=*/quest_completed); + if (quest_attempts > BBQ_OPTIONS.NUM_RETRIES){ + BBQLogger(console.logger()).retry_exhausted(current_quest); + break; + } + } + return quest_completed; +} + void quest_make_tm(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){ stream.log("Quest: Make TM"); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp deleted file mode 100644 index fe538a2560..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* Blueberry Quest Execution - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" -#include "CommonFramework/Tools/ProgramEnvironment.h" -#include "PokemonSV_BBQLogger.h" -#include "PokemonSV_BlueberryCatchPhoto.h" -#include "PokemonSV_BlueberryQuests.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonSV{ -namespace{ - -// Returns true after executing one supported quest; false performs no action. -bool run_basic_quest( - ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, - BBQOption& BBQ_OPTIONS, BBQuests current_quest -){ - switch (current_quest){ - case BBQuests::make_tm: - quest_make_tm(env.program_info(), console, context); - return true; - case BBQuests::travel_500: - quest_travel_500(env.program_info(), console, context); - return true; - case BBQuests::tera_self_defeat: - quest_tera_self_defeat(env.program_info(), console, context, BBQ_OPTIONS); - return true; - case BBQuests::sneak_up: - quest_sneak_up(env.program_info(), console, context, BBQ_OPTIONS); - return true; - case BBQuests::wild_tera: - quest_wild_tera(env.program_info(), console, context, BBQ_OPTIONS); - return true; - case BBQuests::wash_pokemon: - quest_wash_pokemon(env.program_info(), console, context); - return true; - default: - return false; - } -} - -// Returns true after executing one supported quest; false performs no action. -bool run_event_quest( - ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, - BBQOption& BBQ_OPTIONS, BBQuests current_quest -){ - switch (current_quest){ - case BBQuests::hatch_egg: - quest_hatch_egg(env, console, context, BBQ_OPTIONS); - return true; - case BBQuests::bitter_sandwich: - case BBQuests::salty_sandwich: - case BBQuests::sour_sandwich: - case BBQuests::spicy_sandwich: - case BBQuests::sweet_sandwich: - case BBQuests::sandwich_three: - quest_sandwich(env, console, context, BBQ_OPTIONS, current_quest); - return true; - //case BBQuests::pickup_10: - // quest_pickup(env, env.program_info(), console, context, BBQ_OPTIONS); - // break; - case BBQuests::tera_raid: - quest_tera_raid(env, console, context, BBQ_OPTIONS); - return true; - case BBQuests::auto_10: - case BBQuests::auto_30: - quest_auto_battle(env, console, context, BBQ_OPTIONS, current_quest); - return true; - default: - return false; - } -} - -// Returns true after executing one supported quest; false performs no action. -bool run_photo_quest( - ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, - BBQOption& BBQ_OPTIONS, BBQuests current_quest -){ - switch (current_quest){ - //All involve taking pictures - case BBQuests::photo_fly: - case BBQuests::photo_swim: - case BBQuests::photo_canyon: - case BBQuests::photo_coastal: - case BBQuests::photo_polar: - case BBQuests::photo_savanna: - case BBQuests::photo_normal: - case BBQuests::photo_fighting: - case BBQuests::photo_flying: - case BBQuests::photo_poison: - case BBQuests::photo_ground: - case BBQuests::photo_rock: - case BBQuests::photo_bug: - case BBQuests::photo_ghost: - case BBQuests::photo_steel: - case BBQuests::photo_fire: - case BBQuests::photo_water: - case BBQuests::photo_grass: - case BBQuests::photo_electric: - case BBQuests::photo_psychic: - case BBQuests::photo_ice: - case BBQuests::photo_dragon: - case BBQuests::photo_dark: - case BBQuests::photo_fairy: - quest_photo(env.program_info(), console, context, BBQ_OPTIONS, current_quest); - return true; - default: - return false; - } -} - -// Returns true after executing one supported quest; false performs no action. -bool run_catch_quest( - ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, - BBQOption& BBQ_OPTIONS, BBQuests current_quest -){ - switch (current_quest){ - //All involve catching a pokemon - case BBQuests::catch_any: - case BBQuests::catch_normal: - case BBQuests::catch_fighting: - case BBQuests::catch_flying: - case BBQuests::catch_poison: - case BBQuests::catch_ground: - case BBQuests::catch_rock: - case BBQuests::catch_bug: - case BBQuests::catch_ghost: - case BBQuests::catch_steel: - case BBQuests::catch_fire: - case BBQuests::catch_water: - case BBQuests::catch_grass: - case BBQuests::catch_electric: - case BBQuests::catch_psychic: - case BBQuests::catch_ice: - case BBQuests::catch_dragon: - case BBQuests::catch_dark: - case BBQuests::catch_fairy: - quest_catch(env.program_info(), console, context, BBQ_OPTIONS, current_quest); - return true; - default: - return false; - } -} - -// Dispatch to the same quest routines as the original switch, or report an unsupported quest. -void execute_quest( - ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, - BBQOption& BBQ_OPTIONS, BBQuests current_quest -){ - if (run_basic_quest(env, console, context, BBQ_OPTIONS, current_quest) - || run_event_quest(env, console, context, BBQ_OPTIONS, current_quest) - || run_photo_quest(env, console, context, BBQ_OPTIONS, current_quest) - || run_catch_quest(env, console, context, BBQ_OPTIONS, current_quest) - ){ - return; - } - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, "Unknown quest selection.", console - ); -} - -} // namespace - -// Execute/retry from the overworld, verify the board and preserve the caller's egg count. -bool process_and_do_quest( - ProgramEnvironment& env, - ConsoleHandle& console, ProControllerContext& context, - BBQOption& BBQ_OPTIONS, - BBQuests current_quest, - uint8_t& eggs_hatched -){ - bool quest_completed = false; - int quest_attempts = 0; - - while (!quest_completed){ - BBQAttemptLog attempt_log( - console.logger(), /*quest=*/current_quest, - /*attempt=*/quest_attempts + 1, /*limit=*/static_cast(BBQ_OPTIONS.NUM_RETRIES) + 1 - ); - execute_quest(env, console, context, BBQ_OPTIONS, current_quest); - - attempt_log.route_return(); - //Validate quest was completed by checking list - std::vector quest_list = read_quests(env.program_info(), console, context, BBQ_OPTIONS); - if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){ - quest_attempts++; - }else{ - if (current_quest == BBQuests::hatch_egg){ - eggs_hatched++; - console.log("Eggs hatched: " + std::to_string(eggs_hatched)); - } - - quest_completed = true; - } - - attempt_log.result(/*completed=*/quest_completed); - if (quest_attempts > BBQ_OPTIONS.NUM_RETRIES){ - BBQLogger(console.logger()).retry_exhausted(current_quest); - break; - } - } - return quest_completed; -} - -} // namespace PokemonSV -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 759e28029d..011038f97e 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2652,7 +2652,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp - Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests_Execution.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.h