diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp index 4067d75fa3..4b50f2fcdf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp @@ -17,7 +17,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!"}, @@ -110,8 +110,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/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index af191304cb..6f184e5a52 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -245,10 +245,42 @@ 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 28e5481912..3fa394a421 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -242,10 +242,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; @@ -257,6 +258,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; @@ -468,11 +473,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. @@ -481,15 +489,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 25a847c154..d32d9fb5cc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -73,9 +73,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,