diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp index 431763d87c..01bad40e56 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp @@ -149,7 +149,7 @@ BBQOption::BBQOption(OCR::LanguageOCROption* language_option) 1000 ) , SAVE_NUM_QUESTS( - "Save and reset the game after attempting this many quests:
This preserves progress and prevents potential game lags from long runs.
0 disables this option.", + "Save and reset the game after completing this many quests:
This preserves progress and prevents potential game lags from long runs.
0 disables this option.", LockMode::UNLOCK_WHILE_RUNNING, 50 ) , INVERTED_FLIGHT( diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp index 3a4fd0dce2..7cd2c4c15e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp @@ -123,6 +123,13 @@ bool exclusions_leave_a_blue_quest(const BBQOption& options){ // language is wrong so no quest is read, or there is no BP left to reroll. const size_t MAX_READS_WITHOUT_DOABLE_QUEST = 30; +// Whether a round that took the completed count from previous_completed +// to completed crossed a nonzero multiple of the save interval. +bool bbq_save_due(uint64_t previous_completed, uint64_t completed, uint64_t interval){ + return interval != 0 && completed > previous_completed + && completed / interval > previous_completed / interval; +} + } void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& game){ @@ -179,6 +186,7 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga quest_list.clear(); } + const uint64_t completed_before_round = num_completed_quests; for (auto current_quest : quests_to_do){ //Check if quest was already completed (ex. 500 meters completed while navigating to take a photo) quest_list = read_panel(); @@ -205,7 +213,8 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga quests_to_do.clear(); uint64_t temp_save_num_option = options.SAVE_NUM_QUESTS; - game.end_round(temp_save_num_option != 0 && num_completed_quests % temp_save_num_option == 0); + // A round can cross a milestone without ending at an exact multiple. + game.end_round(bbq_save_due(completed_before_round, num_completed_quests, temp_save_num_option)); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index ff90ca3503..bc137c2967 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -373,7 +373,7 @@ static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ .expected = "read process " + round_of_3 + " end", }, { - .name = "saves at exact multiples", + .name = "saves at each milestone", .num_quests = 6, .save_num_quests = 3, .expected_completed = 6, @@ -387,9 +387,7 @@ static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ .expected = "", }, - // The ways the loop gets stuck or loses time. Scenarios named - // "today:" state the current behavior, so that each fix shows up as a - // change to one of them. + // The ways the loop used to get stuck or lose time. { // sneak-up fails in round 1 and is still on the panel in round 2, // where only the two new quests are attempted. @@ -419,23 +417,24 @@ static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ .expected = read_30_times + "error", }, { - // Today: the save check only looks for exact multiples, so going - // from 0 to 3 skips the milestone at 2 without saving. - .name = "today: a round that skips past a milestone does not save", + // 0 -> 3 crosses the milestone at 2 without landing on it. + .name = "saves when a round skips past a milestone", .num_quests = 6, .save_num_quests = 2, .expected_completed = 6, - .expected = round_of_3 + " end " + round_of_3 + " end(save)", + .expected = round_of_3 + " end(save) " + round_of_3 + " end(save)", }, { - // Today: round 1 completes nothing, but 0 is a multiple of 2, so - // it saves anyway. Every quest failed, so the farmer then stops. - .name = "today: a round without completions saves", + // Round 1 completes nothing. It must not save, even though the + // count (0) is a multiple of the interval. + // Every quest fails, so nothing doable is left and the farmer + // stops, but the round with no completions doesn't save. + .name = "round without completions does not save", .num_quests = 3, .save_num_quests = 2, .outcomes = {false, false, false}, .expected_completed = 0, - .expected = "read process read do read do read do end(save) read process", + .expected = "read process read do read do read do end read process", }, { // sneak-up fails, then leaves the panel along with make-tm. Round 2