From 2548fd262cdc960f98e5c420e35db272fbb8af61 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 21 Oct 2026 13:07:34 -0700 Subject: [PATCH 1/3] Let the BBQ exclusions table reroll quests the farmer cannot do plan_quests() dropped quests the farmer cannot do (pickup, flying photo and catch) before looking at the exclusions table, so a reroll row for one of them did nothing: the quest stayed on the panel and blocked the slot. Pickup could not be picked in the table at all. The table is now applied first. Reroll and skip rows work for quests the farmer cannot do; a run row for one is ignored, since there is no route for it. Pickup is listed in the table. With nothing to do and nothing rerolled, the first quest the farmer cannot do that has no table row is rerolled instead of every quest, which costs one reroll instead of three or four. Every quest is still rerolled when there is no such quest. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonSV/Options/PokemonSV_BBQOption.cpp | 7 ++-- .../Programs/Farming/PokemonSV_BBQTests.cpp | 36 ++++++++++++++++- .../Farming/PokemonSV_BlueberryQuests.cpp | 39 +++++++++++++++---- .../Farming/PokemonSV_BlueberryQuests.h | 8 ++-- 4 files changed, 75 insertions(+), 15 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp index 008307024b..66e94e4ce4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp @@ -15,7 +15,7 @@ const EnumDropdownDatabase& BBQuests_database(){ static EnumDropdownDatabase database{ {BBQuests::auto_10, "auto-10", "Defeat 10 wild Pokemon using Auto Battle!"}, {BBQuests::make_tm, "make-tm", "Make yourself a TM!"}, - //{BBQuests::pickup_10, "pickup-10", "Pick up items on the ground 10 times!"}, + {BBQuests::pickup_10, "pickup-10", "Pick up items on the ground 10 times!"}, {BBQuests::sneak_up, "sneak-up", "Successfully sneak up on 1 Pokemon and surprise them with a battle!"}, {BBQuests::photo_fly, "photo-fly", "Take a photo of a wild Pokemon in flight!"}, {BBQuests::photo_swim, "photo-swim", "Take a photo of a wild Pokemon that is swimming!"}, @@ -108,8 +108,9 @@ BBQuestTable::BBQuestTable() "Exclude the quests in the table. If you want to skip a quest, select it below. " "(Quests can be explicitly included, but this is not necessary.) " "Do not exclude too many quests, as rerolling costs BP. " - "The program will automatically reroll all quests if none are possible, but will not handle being out of BP. " - "Does not include egg hatching or pickup quests, as eggs are handled in other options and pickup is not possible. ", + "If no quest is possible, the program rerolls one quest it cannot do, or all quests if there is none. " + "Quests the program cannot do, such as pickup, are never run, but can be rerolled or skipped here. " + "Does not include egg hatching, as eggs are handled in other options. ", //"Duplicates of the same quest", //duplicates will work in table order. might lead to weird behavior like rerolling and then marking a quest as complete. //won't break the program though. diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 569af8ee21..367b0326c2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -673,10 +673,42 @@ static void add_tests_BBQuestPlan(UnitTestDatabase& database){ .expected_to_do = {make_tm}, }, { - .name = "nothing doable rerolls all", - .quests = {pickup_10, auto_10, catch_flying}, + // One quest costs less BP to reroll than all of them. + .name = "nothing doable rerolls the first quest not possible", + .quests = {auto_10, pickup_10, catch_flying}, + .expected_reroll_slots = {1}, + }, + { + .name = "nothing doable and nothing not possible rerolls all", + .quests = {auto_10, sneak_up}, + .extra_exclusions = {{sneak_up, BBQAction::skip}}, .expected_reroll_all = true, }, + { + // An undetected quest is not known to be impossible. + .name = "an undetected quest is not rerolled alone", + .quests = {UnableToDetect, auto_10}, + .expected_reroll_all = true, + }, + { + .name = "a skipped quest not possible is not rerolled", + .quests = {pickup_10, auto_10, catch_flying}, + .extra_exclusions = {{pickup_10, BBQAction::skip}}, + .expected_reroll_slots = {2}, + }, + { + .name = "a reroll row rerolls a quest not possible", + .quests = {make_tm, sneak_up, pickup_10}, + .extra_exclusions = {{pickup_10, BBQAction::reroll}}, + .expected_to_do = {make_tm, sneak_up}, + .expected_reroll_slots = {2}, + }, + { + .name = "a run row does not run a quest not possible", + .quests = {make_tm, pickup_10}, + .extra_exclusions = {{pickup_10, BBQAction::run}}, + .expected_to_do = {make_tm}, + }, { // The reroll replaces a quest, so the next read has something new. .name = "a reroll row rerolls that slot", diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 091a6374f4..0d2fad01b4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -175,10 +175,11 @@ void plan_out_of_eggs(Logger& logger, const BBQOption& BBQ_OPTIONS, size_t slot, } //Apply each exclusions table row for the quest, in table order. Returns false if no row is for it. +//A quest the program cannot do is never run, but can still be rerolled or skipped. bool plan_from_exclusions( Logger& logger, const std::vector>& exclusions_table, - BBQuests quest, size_t slot, + BBQuests quest, size_t slot, bool possible, BBQuestPlan& plan ){ bool quest_in_table = false; @@ -190,6 +191,10 @@ bool plan_from_exclusions( quest_in_table = true; switch (row->action){ case BBQAction::run: + if (!possible){ + logger.log("Run selected, but this quest is not possible. Skipping quest."); + break; + } logger.log("Run selected. Adding quest to list."); plan.to_do.push_back(quest); break; @@ -380,11 +385,14 @@ BBQuestPlan plan_quests( BBQuestPlan plan; std::vector> exclusions_table = BBQ_OPTIONS.QUEST_EXCLUSIONS.copy_snapshot(); + //The first quest not possible that has no table row, to reroll if nothing else can be done. + std::optional not_possible_slot; + logger.log("Processing quests."); for (size_t slot = 0; slot < quest_list.size(); slot++){ const BBQuests n = quest_list[slot]; - if (not_possible_quests.contains(n)){ - logger.log("Quest not possible"); + if (n == BBQuests::UnableToDetect){ + logger.log("Quest not detected."); continue; } //Check eggs remaining. @@ -393,15 +401,32 @@ BBQuestPlan plan_quests( plan_out_of_eggs(logger, BBQ_OPTIONS, slot, plan); continue; } - if (!plan_from_exclusions(logger, exclusions_table, n, slot, plan)){ - logger.log("Quest not in inclusion/exclusions table. Adding to list."); - plan.to_do.push_back(n); + const bool possible = !not_possible_quests.contains(n); + if (plan_from_exclusions(logger, exclusions_table, n, slot, possible, plan)){ + continue; + } + if (!possible){ + logger.log("Quest not possible."); + if (!not_possible_slot){ + not_possible_slot = slot; + } + continue; } + logger.log("Quest not in inclusion/exclusions table. Adding to list."); + plan.to_do.push_back(n); } //Check that quests_to_do is not empty (after completing all quests on the list, be sure to erase it. //Lag might be a problem in multi - look into making slots like menu-left navigation - plan.reroll_all = plan.reroll_slots.empty() && plan.to_do.empty(); + if (plan.reroll_slots.empty() && plan.to_do.empty()){ + if (not_possible_slot){ + //Rerolling one quest costs less BP than rerolling all of them. + logger.log("No possible quests! Rerolling a quest that is not possible."); + plan.reroll_slots.push_back(*not_possible_slot); + }else{ + plan.reroll_all = true; + } + } return plan; } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h index 4b45e65e49..2c0b948209 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -65,9 +65,11 @@ struct BBQuestPlan{ bool reroll_all = false; //Nothing to do and nothing rerolled: reroll every slot. }; //Decide what to do with each quest from the options alone, without touching the game, so -//the decision can be tested. Quests not possible are left out. Out-of-egg hatch quests and -//quests set to reroll in the exclusions table are rerolled. A quest with several table rows -//gets the action of each row, in table order. +//the decision can be tested. Quests not possible are left out, unless the exclusions table +//rerolls them. Out-of-egg hatch quests and quests set to reroll in the exclusions table are +//rerolled. A quest with several table rows gets the action of each row, in table order. With +//nothing to do and nothing rerolled, the first quest not possible and not in the table is +//rerolled, or else every quest. BBQuestPlan plan_quests( Logger& logger, const BBQOption& BBQ_OPTIONS, From ba751e5b165fde3715e3f5c6d41a4b450f946d96 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 22 Oct 2026 13:53:13 -0700 Subject: [PATCH 2/3] Reroll BBQ quests the farmer cannot do as soon as they appear plan_quests() left a quest it cannot do (pickup, photo flying, catch flying) on the panel unless the exclusions table had a row for it, and rerolled one only when nothing else was doable. A red photo-flying and a blue catch-flying then held 2 of 4 slots for over 20 minutes, and no new red quest could appear. Reroll each such quest when it is read: 10 BP for a blue, 50 BP for a red, which pays 100-150 BP and blocks the next red while it stays. A table row for the quest still decides instead. With every one of them rerolled, the one-slot fallback has nothing left to pick, so it is removed; reroll-all still covers a panel with nothing doable and nothing rerolled. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/Farming/PokemonSV_BBQTests.cpp | 62 +++++++++++++++++-- .../Farming/PokemonSV_BlueberryQuests.cpp | 20 ++---- .../Farming/PokemonSV_BlueberryQuests.h | 8 +-- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 367b0326c2..e3a7005dea 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -668,15 +668,55 @@ static void add_tests_BBQuestPlan(UnitTestDatabase& database){ .expected_to_do = {make_tm, sneak_up}, }, { - .name = "quests not possible are left out", + // Left alone, it would hold its slot until something else is + // rerolled. A blue reroll costs 10 BP. + .name = "a blue quest not possible is rerolled while others are doable", + .quests = {make_tm, catch_flying, sneak_up}, + .expected_to_do = {make_tm, sneak_up}, + .expected_reroll_slots = {1}, + }, + { + // An undetected quest is neither run nor rerolled. + .name = "a quest not possible is rerolled, an undetected one is not", .quests = {pickup_10, make_tm, UnableToDetect}, .expected_to_do = {make_tm}, + .expected_reroll_slots = {0}, }, { - // One quest costs less BP to reroll than all of them. - .name = "nothing doable rerolls the first quest not possible", - .quests = {auto_10, pickup_10, catch_flying}, - .expected_reroll_slots = {1}, + // A red quest costs 50 BP to reroll, but pays 100-150 BP, and + // the next red quest cannot appear while it stays. + .name = "a red quest not possible is rerolled while the blues are doable", + .quests = {photo_flying, make_tm, sneak_up, travel_500}, + .expected_to_do = {make_tm, sneak_up, travel_500}, + .expected_reroll_slots = {0}, + }, + { + // The board that held 2 of 4 slots for 20 minutes. + .name = "a red and a blue quest not possible are both rerolled", + .quests = {photo_flying, make_tm, catch_flying, sneak_up}, + .expected_to_do = {make_tm, sneak_up}, + .expected_reroll_slots = {0, 2}, + }, + { + // There is no longer a single slot to fall back on: every quest + // not possible was rerolled already, so not every quest is. + .name = "nothing doable rerolls each quest not possible, not all", + .quests = {photo_flying, auto_10, pickup_10, catch_flying}, + .expected_reroll_slots = {0, 2, 3}, + }, + { + .name = "a skip row keeps a red quest not possible", + .quests = {photo_flying, make_tm, catch_flying, sneak_up}, + .extra_exclusions = {{photo_flying, BBQAction::skip}}, + .expected_to_do = {make_tm, sneak_up}, + .expected_reroll_slots = {2}, + }, + { + .name = "a run row keeps a blue quest not possible", + .quests = {photo_flying, make_tm, catch_flying, sneak_up}, + .extra_exclusions = {{catch_flying, BBQAction::run}}, + .expected_to_do = {make_tm, sneak_up}, + .expected_reroll_slots = {0}, }, { .name = "nothing doable and nothing not possible rerolls all", @@ -696,6 +736,16 @@ static void add_tests_BBQuestPlan(UnitTestDatabase& database){ .extra_exclusions = {{pickup_10, BBQAction::skip}}, .expected_reroll_slots = {2}, }, + { + // Only skipped quests left: nothing changes the panel otherwise. + .name = "skip rows on every quest not possible reroll all when nothing is doable", + .quests = {photo_flying, auto_10, catch_flying}, + .extra_exclusions = { + {photo_flying, BBQAction::skip}, + {catch_flying, BBQAction::skip}, + }, + .expected_reroll_all = true, + }, { .name = "a reroll row rerolls a quest not possible", .quests = {make_tm, sneak_up, pickup_10}, @@ -722,7 +772,7 @@ static void add_tests_BBQuestPlan(UnitTestDatabase& database){ .name = "a rerolled slot with nothing doable does not reroll all", .quests = {pickup_10, sneak_up, auto_10}, .extra_exclusions = {{sneak_up, BBQAction::reroll}}, - .expected_reroll_slots = {1}, + .expected_reroll_slots = {0, 1}, }, { // Each row for a quest applies, in table order. diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 0d2fad01b4..49d4aeea10 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -385,9 +385,6 @@ BBQuestPlan plan_quests( BBQuestPlan plan; std::vector> exclusions_table = BBQ_OPTIONS.QUEST_EXCLUSIONS.copy_snapshot(); - //The first quest not possible that has no table row, to reroll if nothing else can be done. - std::optional not_possible_slot; - logger.log("Processing quests."); for (size_t slot = 0; slot < quest_list.size(); slot++){ const BBQuests n = quest_list[slot]; @@ -406,10 +403,11 @@ BBQuestPlan plan_quests( continue; } if (!possible){ - logger.log("Quest not possible."); - if (!not_possible_slot){ - not_possible_slot = slot; - } + //Left on the panel, it holds a slot until something else is rerolled. A red quest + //costs 50 BP to reroll instead of 10, but pays 100-150 BP and keeps the next red + //quest from appearing, so it is rerolled too. + logger.log("Quest not possible. Rerolling quest. New quest will be run in the next batch of quests."); + plan.reroll_slots.push_back(slot); continue; } logger.log("Quest not in inclusion/exclusions table. Adding to list."); @@ -419,13 +417,7 @@ BBQuestPlan plan_quests( //Check that quests_to_do is not empty (after completing all quests on the list, be sure to erase it. //Lag might be a problem in multi - look into making slots like menu-left navigation if (plan.reroll_slots.empty() && plan.to_do.empty()){ - if (not_possible_slot){ - //Rerolling one quest costs less BP than rerolling all of them. - logger.log("No possible quests! Rerolling a quest that is not possible."); - plan.reroll_slots.push_back(*not_possible_slot); - }else{ - plan.reroll_all = true; - } + plan.reroll_all = true; } return plan; } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h index 2c0b948209..280b82b149 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -65,11 +65,11 @@ struct BBQuestPlan{ bool reroll_all = false; //Nothing to do and nothing rerolled: reroll every slot. }; //Decide what to do with each quest from the options alone, without touching the game, so -//the decision can be tested. Quests not possible are left out, unless the exclusions table -//rerolls them. Out-of-egg hatch quests and quests set to reroll in the exclusions table are +//the decision can be tested. Quests not possible are never run. Those not in the exclusions +//table are rerolled, red or blue, so they do not hold a slot; a table row for one decides +//instead. Out-of-egg hatch quests and quests set to reroll in the exclusions table are //rerolled. A quest with several table rows gets the action of each row, in table order. With -//nothing to do and nothing rerolled, the first quest not possible and not in the table is -//rerolled, or else every quest. +//nothing to do and nothing rerolled, every quest is rerolled. BBQuestPlan plan_quests( Logger& logger, const BBQOption& BBQ_OPTIONS, From a45c9dedfd709acb0adfbd3a15f889eb7581c42f Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 22 Oct 2026 17:31:15 -0700 Subject: [PATCH 3/3] Reroll a BBQ quest not possible only when BP covers the reroll Rerolling a quest not possible on sight (C15) spent BP the player might not have: out of BP the reroll did not happen, and the program stopped with "Check that there is enough BP" before the doable quests ran. plan_quests() now takes the BP balance. While other quests are doable, a quest not possible is rerolled only if the BP left after the other planned rerolls covers it (red 50, blue 10); otherwise it is skipped as before C15 and the doable quests run. Unknown BP skips it too. With nothing doable, every quest not possible is still rerolled. process_quest_list() reads BP (one more panel open) only when the board has a quest not possible. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/Farming/PokemonSV_BBQTests.cpp | 47 +++++++++++++- .../Farming/PokemonSV_BlueberryQuests.cpp | 64 +++++++++++++++++-- .../Farming/PokemonSV_BlueberryQuests.h | 16 +++-- 3 files changed, 114 insertions(+), 13 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index e3a7005dea..4f7dc9eb05 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -474,6 +474,7 @@ struct BBQuestPlanScenario{ std::string name; std::vector quests; std::vector> extra_exclusions; + std::optional bp = 1000; uint8_t num_eggs = 1; uint8_t eggs_hatched = 0; BBQOption::OOEggs out_of_eggs = BBQOption::OOEggs::Reroll; @@ -516,7 +517,7 @@ class Test_BBQuestPlan : public UnitTest{ } NullLogger logger; - const BBQuestPlan plan = plan_quests(logger, options, m_scenario.quests, m_scenario.eggs_hatched); + const BBQuestPlan plan = plan_quests(logger, options, m_scenario.quests, m_scenario.eggs_hatched, m_scenario.bp); if (plan.to_do != m_scenario.expected_to_do){ return "Expected quests to do: " + quests_to_string(m_scenario.expected_to_do) + "got: " + quests_to_string(plan.to_do); @@ -718,6 +719,50 @@ static void add_tests_BBQuestPlan(UnitTestDatabase& database){ .expected_to_do = {make_tm, sneak_up}, .expected_reroll_slots = {0}, }, + { + // A red reroll costs 50 BP, a blue one 10. + .name = "BP for a blue reroll but not a red one skips the red quest not possible", + .quests = {photo_flying, make_tm, catch_flying, sneak_up}, + .bp = 49, + .expected_to_do = {make_tm, sneak_up}, + .expected_reroll_slots = {2}, + }, + { + .name = "BP for exactly a red reroll rerolls it and skips the blue one", + .quests = {photo_flying, make_tm, catch_flying, sneak_up}, + .bp = 55, + .expected_to_do = {make_tm, sneak_up}, + .expected_reroll_slots = {0}, + }, + { + // Before, the reroll did not happen and the program stopped. + .name = "BP under a blue reroll skips quests not possible and runs the doable ones", + .quests = {photo_flying, make_tm, catch_flying, sneak_up}, + .bp = 9, + .expected_to_do = {make_tm, sneak_up}, + }, + { + .name = "unknown BP skips quests not possible and runs the doable ones", + .quests = {photo_flying, make_tm, catch_flying, sneak_up}, + .bp = std::nullopt, + .expected_to_do = {make_tm, sneak_up}, + }, + { + // A reroll row is paid for first. + .name = "BP left after a reroll row decides the quests not possible", + .quests = {make_tm, catch_flying, sneak_up, pickup_10}, + .extra_exclusions = {{sneak_up, BBQAction::reroll}}, + .bp = 25, + .expected_to_do = {make_tm}, + .expected_reroll_slots = {1, 2}, + }, + { + // Nothing else changes the panel, so BP does not hold it back. + .name = "nothing doable rerolls each quest not possible whatever the BP", + .quests = {photo_flying, auto_10, catch_flying}, + .bp = 0, + .expected_reroll_slots = {0, 2}, + }, { .name = "nothing doable and nothing not possible rerolls all", .quests = {auto_10, sneak_up}, diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 49d4aeea10..5ea663bd75 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/Tools/ErrorDumper.h" @@ -376,15 +377,23 @@ void reroll_quest_slot( } } +int reroll_cost(BBQuests quest){ + return red_quests.contains(quest) ? 50 : 10; +} + BBQuestPlan plan_quests( Logger& logger, const BBQOption& BBQ_OPTIONS, const std::vector& quest_list, - uint8_t eggs_hatched + uint8_t eggs_hatched, + std::optional bp ){ BBQuestPlan plan; std::vector> exclusions_table = BBQ_OPTIONS.QUEST_EXCLUSIONS.copy_snapshot(); + //Quests not possible and not in the table, in panel order. Rerolled below if BP allows. + std::vector not_possible_slots; + logger.log("Processing quests."); for (size_t slot = 0; slot < quest_list.size(); slot++){ const BBQuests n = quest_list[slot]; @@ -403,17 +412,47 @@ BBQuestPlan plan_quests( continue; } if (!possible){ - //Left on the panel, it holds a slot until something else is rerolled. A red quest - //costs 50 BP to reroll instead of 10, but pays 100-150 BP and keeps the next red - //quest from appearing, so it is rerolled too. - logger.log("Quest not possible. Rerolling quest. New quest will be run in the next batch of quests."); - plan.reroll_slots.push_back(slot); + logger.log("Quest not possible."); + not_possible_slots.push_back(slot); continue; } logger.log("Quest not in inclusion/exclusions table. Adding to list."); plan.to_do.push_back(n); } + if (plan.to_do.empty()){ + //Nothing else to do: a quest not possible only changes by rerolling it. + for (size_t slot : not_possible_slots){ + logger.log("No possible quests! Rerolling quest " + std::to_string(slot + 1) + ", which is not possible."); + plan.reroll_slots.push_back(slot); + } + }else{ + //Left on the panel, a quest not possible holds a slot until something else is rerolled. + //A red quest costs 50 BP to reroll instead of 10, but pays 100-150 BP and keeps the + //next red quest from appearing, so it is rerolled too. Without the BP for it, it is + //skipped and the doable quests run, rather than stopping the program on a reroll + //that does not happen. + int budget = bp.value_or(0); + for (size_t slot : plan.reroll_slots){ + budget -= reroll_cost(quest_list[slot]); + } + for (size_t slot : not_possible_slots){ + const int cost = reroll_cost(quest_list[slot]); + if (!bp || budget < cost){ + logger.log( + "Quest " + std::to_string(slot + 1) + " not possible, but BP (" + + (bp ? std::to_string(*bp) : "unknown") + ") does not cover its " + + std::to_string(cost) + " BP reroll. Skipping it." + ); + continue; + } + logger.log("Quest " + std::to_string(slot + 1) + " not possible. Rerolling quest. New quest will be run in the next batch of quests."); + budget -= cost; + plan.reroll_slots.push_back(slot); + } + } + std::sort(plan.reroll_slots.begin(), plan.reroll_slots.end()); + //Check that quests_to_do is not empty (after completing all quests on the list, be sure to erase it. //Lag might be a problem in multi - look into making slots like menu-left navigation if (plan.reroll_slots.empty() && plan.to_do.empty()){ @@ -429,7 +468,18 @@ std::vector process_quest_list( const std::vector& quest_list, uint8_t eggs_hatched ){ - BBQuestPlan plan = plan_quests(stream.logger(), BBQ_OPTIONS, quest_list, eggs_hatched); + //Read BP only when a quest not possible may be rerolled while others are doable. + std::optional bp; + if (std::any_of(quest_list.begin(), quest_list.end(), [](BBQuests quest){ + return quest != BBQuests::UnableToDetect && not_possible_quests.contains(quest); + })){ + const int read = read_BP(info, stream, context); + if (read >= 0){ + bp = read; + } + stream.log("BP: " + (bp ? std::to_string(*bp) : "unable to read")); + } + BBQuestPlan plan = plan_quests(stream.logger(), BBQ_OPTIONS, quest_list, eggs_hatched, bp); //Each reroll updates the panel the next one checks against. std::vector panel = quest_list; diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h index 280b82b149..f3f91cd04d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -64,17 +64,23 @@ struct BBQuestPlan{ std::vector reroll_slots; //Slots to reroll, in panel order. bool reroll_all = false; //Nothing to do and nothing rerolled: reroll every slot. }; +//BP it costs to reroll one quest: 50 for a red quest, 10 for a blue one. +int reroll_cost(BBQuests quest); //Decide what to do with each quest from the options alone, without touching the game, so //the decision can be tested. Quests not possible are never run. Those not in the exclusions -//table are rerolled, red or blue, so they do not hold a slot; a table row for one decides -//instead. Out-of-egg hatch quests and quests set to reroll in the exclusions table are -//rerolled. A quest with several table rows gets the action of each row, in table order. With -//nothing to do and nothing rerolled, every quest is rerolled. +//table are rerolled, red or blue, so they do not hold a slot, as long as BP (the balance +//read from the panel, if any) still covers their cost after the other planned rerolls; the +//rest are skipped, and the doable quests run. A table row for one decides instead. +//Out-of-egg hatch quests and quests set to reroll in the exclusions table are rerolled. A +//quest with several table rows gets the action of each row, in table order. With nothing to +//do, every quest not possible and not in the table is rerolled whatever the BP, or else +//every quest. BBQuestPlan plan_quests( Logger& logger, const BBQOption& BBQ_OPTIONS, const std::vector& quest_list, - uint8_t eggs_hatched + uint8_t eggs_hatched, + std::optional bp ); //The steps of rerolling one quest on the quest panel. They are injected so that the reroll