diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp
index 431763d87c..2658d8da07 100644
--- a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp
+++ b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp
@@ -185,6 +185,11 @@ BBQOption::BBQOption(OCR::LanguageOCROption* language_option)
"Hatch Quest - Fix time for eggs:
Fix the time before doing a hatch egg quest.",
LockMode::UNLOCK_WHILE_RUNNING, false
)
+ , AUTO_BATTLE_HEAL_PERCENT(
+ "Auto Battle Quest - Heal Below HP %:
Between passes, heal at the Pokemon Center only if your lead's HP is below this percentage. "
+ "If its HP could not be read, heal anyway.",
+ LockMode::UNLOCK_WHILE_RUNNING, 50, 0, 100
+ )
, CATCH_ON_WIN(true)
, NUM_RETRIES(
"Number of Retries:
Reattempt a quest this many times if it fails.",
@@ -207,6 +212,7 @@ BBQOption::BBQOption(OCR::LanguageOCROption* language_option)
PA_ADD_OPTION(NUM_EGGS);
PA_ADD_OPTION(OUT_OF_EGGS);
PA_ADD_OPTION(FIX_TIME_FOR_HATCH);
+ PA_ADD_OPTION(AUTO_BATTLE_HEAL_PERCENT);
PA_ADD_OPTION(BATTLE_AI);
PA_ADD_OPTION(CATCH_ON_WIN);
PA_ADD_OPTION(NUM_RETRIES);
diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h
index f5715a10c7..ab37cc67c1 100644
--- a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h
+++ b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h
@@ -93,6 +93,9 @@ class BBQOption : public GroupOption{
EnumDropdownOption OUT_OF_EGGS;
BooleanCheckBoxOption FIX_TIME_FOR_HATCH;
+ //Auto battle quest
+ SimpleIntegerOption AUTO_BATTLE_HEAL_PERCENT;
+
//Tera raid
TeraAIOption BATTLE_AI;
TeraFarmerCatchOnWin CATCH_ON_WIN;
diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp
index 76c24dd021..0ddc6e731d 100644
--- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp
+++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp
@@ -160,6 +160,8 @@ class ScriptedAutoBattle : public BBQAutoBattleActions{
// Kills heard in each clear, in turn. Running past the end throws, which
// also stops a loop that would never end.
std::vector kills_per_clear;
+ // The lead's HP read in each clear, in turn. Past the end, it is unknown.
+ std::vector> hp_per_clear;
std::vector steps;
int seconds = 0;
@@ -180,11 +182,12 @@ class ScriptedAutoBattle : public BBQAutoBattleActions{
}
steps.push_back("clear");
seconds += CLEAR_SECONDS;
+ const std::optional hp = m_clears < hp_per_clear.size() ? hp_per_clear[m_clears] : std::nullopt;
m_kills += kills_per_clear[m_clears++];
if (m_kills >= stop_at_kills){
seconds -= CLEAR_TAIL_SECONDS;
}
- return std::nullopt;
+ return hp;
}
virtual void return_to_plaza() override{
steps.push_back("return");
@@ -205,8 +208,8 @@ const std::string PASS = "fly clear return heal";
// A pass that returns without healing.
const std::string LAST_PASS = "fly clear return";
-std::string passes(int count){
- std::vector ret(count, PASS);
+std::string passes(int count, const std::string& pass = PASS){
+ std::vector ret(count, pass);
return join(ret, " ");
}
@@ -224,6 +227,8 @@ struct BBQAutoBattleScenario{
uint64_t kill_target = 10;
int time_limit_minutes = 35;
std::vector kills_per_clear;
+ std::vector> hp_per_clear = {}; // Unknown when not given.
+ int heal_below_hp_percent = 50;
BBQAutoBattleResult expected_result = BBQAutoBattleResult::TargetReached;
std::string expected_steps;
int expected_seconds = 0;
@@ -240,11 +245,13 @@ class Test_BBQAutoBattle : public UnitTest{
virtual UnitTestResult run(Logger&, CancellableScope&) const override{
ScriptedAutoBattle actions;
actions.kills_per_clear = m_scenario.kills_per_clear;
+ actions.hp_per_clear = m_scenario.hp_per_clear;
RecordingLogger logger;
BBQAutoBattlePolicy policy;
policy.kill_target = m_scenario.kill_target;
policy.time_limit = std::chrono::minutes(m_scenario.time_limit_minutes);
+ policy.heal_below_hp_percent = (uint8_t)m_scenario.heal_below_hp_percent;
BBQAutoBattleResult result;
try{
result = run_auto_battle(logger, actions, policy);
@@ -288,10 +295,10 @@ static void add_tests_BBQAutoBattle(UnitTestDatabase& database){
.expected_steps = passes(4) + " " + LAST_PASS,
.expected_seconds = 5 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS,
.expected_log = {
- "Auto Battle pass 1: 2 kills, 2/10 in total, HP ?, 46 s elapsed. Below the target: return, heal and go again.",
- "Auto Battle pass 2: 2 kills, 4/10 in total, HP ?, 148 s elapsed. Below the target: return, heal and go again.",
- "Auto Battle pass 3: 2 kills, 6/10 in total, HP ?, 250 s elapsed. Below the target: return, heal and go again.",
- "Auto Battle pass 4: 2 kills, 8/10 in total, HP ?, 352 s elapsed. Below the target: return, heal and go again.",
+ "Auto Battle pass 1: 2 kills, 2/10 in total, HP ?, 46 s elapsed. Below the target and HP unknown: return, heal and go again.",
+ "Auto Battle pass 2: 2 kills, 4/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.",
+ "Auto Battle pass 3: 2 kills, 6/10 in total, HP ?, 250 s elapsed. Below the target and HP unknown: return, heal and go again.",
+ "Auto Battle pass 4: 2 kills, 8/10 in total, HP ?, 352 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 5: 2 kills, 10/10 in total, HP ?, 448 s elapsed. Target reached: return without healing.",
},
},
@@ -322,8 +329,8 @@ static void add_tests_BBQAutoBattle(UnitTestDatabase& database){
.expected_steps = passes(2) + " " + LAST_PASS,
.expected_seconds = 3 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
.expected_log = {
- "Auto Battle pass 1: 0 kills, 0/10 in total, HP ?, 46 s elapsed. Below the target: return, heal and go again.",
- "Auto Battle pass 2: 0 kills, 0/10 in total, HP ?, 148 s elapsed. Below the target: return, heal and go again.",
+ "Auto Battle pass 1: 0 kills, 0/10 in total, HP ?, 46 s elapsed. Below the target and HP unknown: return, heal and go again.",
+ "Auto Battle pass 2: 0 kills, 0/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 3: 0 kills, 0/10 in total, HP ?, 250 s elapsed. No kill in 3 passes in a row: return and give up.",
},
},
@@ -344,9 +351,9 @@ static void add_tests_BBQAutoBattle(UnitTestDatabase& database){
.expected_steps = passes(3) + " " + LAST_PASS,
.expected_seconds = 4 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
.expected_log = {
- "Auto Battle pass 1: 1 kills, 1/10 in total, HP ?, 46 s elapsed. Below the target: return, heal and go again.",
- "Auto Battle pass 2: 1 kills, 2/10 in total, HP ?, 148 s elapsed. Below the target: return, heal and go again.",
- "Auto Battle pass 3: 1 kills, 3/10 in total, HP ?, 250 s elapsed. Below the target: return, heal and go again.",
+ "Auto Battle pass 1: 1 kills, 1/10 in total, HP ?, 46 s elapsed. Below the target and HP unknown: return, heal and go again.",
+ "Auto Battle pass 2: 1 kills, 2/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.",
+ "Auto Battle pass 3: 1 kills, 3/10 in total, HP ?, 250 s elapsed. Below the target and HP unknown: return, heal and go again.",
"Auto Battle pass 4: 1 kills, 4/10 in total, HP ?, 352 s elapsed. Time limit of 5 min reached: return and give up.",
},
},
@@ -358,6 +365,91 @@ static void add_tests_BBQAutoBattle(UnitTestDatabase& database){
.expected_steps = passes(3) + " " + LAST_PASS,
.expected_seconds = 4 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS,
},
+ {
+ // Same kills as "auto battle 10 at 2 kills per pass", 4 heals (112 s) faster.
+ .name = "high HP skips the heal",
+ .kills_per_clear = {2, 2, 2, 2, 2},
+ .hp_per_clear = {0.8, 0.8, 0.8, 0.8, 0.8},
+ .expected_steps = passes(5, LAST_PASS),
+ .expected_seconds = 5 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - 4 * ScriptedAutoBattle::HEAL_SECONDS,
+ .expected_log = {
+ "Auto Battle pass 1: 2 kills, 2/10 in total, HP 80%, 46 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
+ "Auto Battle pass 2: 2 kills, 4/10 in total, HP 80%, 120 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
+ "Auto Battle pass 3: 2 kills, 6/10 in total, HP 80%, 194 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
+ "Auto Battle pass 4: 2 kills, 8/10 in total, HP 80%, 268 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
+ "Auto Battle pass 5: 2 kills, 10/10 in total, HP 80%, 336 s elapsed. Target reached: return without healing.",
+ },
+ },
+ {
+ // Same kills as "auto battle 30 at 3 kills per pass", 9 heals (252 s) faster.
+ .name = "high HP skips the heal in auto battle 30",
+ .kill_target = 30,
+ .kills_per_clear = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
+ .hp_per_clear = {0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9},
+ .expected_steps = passes(10, LAST_PASS),
+ .expected_seconds = 10 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - 9 * ScriptedAutoBattle::HEAL_SECONDS,
+ },
+ {
+ .name = "low HP heals",
+ .kills_per_clear = {2, 2, 2, 2, 2},
+ .hp_per_clear = {0.3, 0.3, 0.3, 0.3, 0.3},
+ .expected_steps = passes(4) + " " + LAST_PASS,
+ .expected_seconds = 5 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS,
+ .expected_log = {
+ "Auto Battle pass 1: 2 kills, 2/10 in total, HP 30%, 46 s elapsed. Below the target and HP below 50%: return, heal and go again.",
+ "Auto Battle pass 2: 2 kills, 4/10 in total, HP 30%, 148 s elapsed. Below the target and HP below 50%: return, heal and go again.",
+ "Auto Battle pass 3: 2 kills, 6/10 in total, HP 30%, 250 s elapsed. Below the target and HP below 50%: return, heal and go again.",
+ "Auto Battle pass 4: 2 kills, 8/10 in total, HP 30%, 352 s elapsed. Below the target and HP below 50%: return, heal and go again.",
+ "Auto Battle pass 5: 2 kills, 10/10 in total, HP 30%, 448 s elapsed. Target reached: return without healing.",
+ },
+ },
+ {
+ // Unknown HP heals, as every pass did before the threshold.
+ .name = "unknown HP heals",
+ .kills_per_clear = {2, 2, 2, 2, 2},
+ .hp_per_clear = {0.8, std::nullopt, 0.8, std::nullopt, 0.8},
+ .expected_steps = LAST_PASS + " " + PASS + " " + LAST_PASS + " " + PASS + " " + LAST_PASS,
+ .expected_seconds = 5 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - 2 * ScriptedAutoBattle::HEAL_SECONDS,
+ },
+ {
+ // HP at the threshold skips the heal; just below heals.
+ .name = "heal threshold boundary",
+ .kills_per_clear = {3, 3, 3, 3},
+ .hp_per_clear = {0.5, 0.49, 0.5, 0.5},
+ .expected_steps = LAST_PASS + " " + PASS + " " + LAST_PASS + " " + LAST_PASS,
+ .expected_seconds = 4 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - 2 * ScriptedAutoBattle::HEAL_SECONDS,
+ .expected_log = {
+ "Auto Battle pass 1: 3 kills, 3/10 in total, HP 50%, 46 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
+ "Auto Battle pass 2: 3 kills, 6/10 in total, HP 49%, 120 s elapsed. Below the target and HP below 50%: return, heal and go again.",
+ "Auto Battle pass 3: 3 kills, 9/10 in total, HP 50%, 222 s elapsed. Below the target and HP at or above 50%: return and go again without healing.",
+ "Auto Battle pass 4: 3 kills, 12/10 in total, HP 50%, 290 s elapsed. Target reached: return without healing.",
+ },
+ },
+ {
+ .name = "a threshold of 100% heals unless HP is full",
+ .kills_per_clear = {4, 4, 4},
+ .hp_per_clear = {1.0, 0.99, 1.0},
+ .heal_below_hp_percent = 100,
+ .expected_steps = LAST_PASS + " " + PASS + " " + LAST_PASS,
+ .expected_seconds = 3 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
+ },
+ {
+ .name = "a threshold of 0% heals only when HP is unknown",
+ .kills_per_clear = {4, 4, 4},
+ .hp_per_clear = {0.01, std::nullopt, 0.01},
+ .heal_below_hp_percent = 0,
+ .expected_steps = LAST_PASS + " " + PASS + " " + LAST_PASS,
+ .expected_seconds = 3 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS - ScriptedAutoBattle::HEAL_SECONDS,
+ },
+ {
+ // The limits still end the attempt when no pass heals.
+ .name = "gives up after 3 passes with no kill and high HP",
+ .kills_per_clear = {0, 0, 0},
+ .hp_per_clear = {1.0, 1.0, 1.0},
+ .expected_result = BBQAutoBattleResult::NoKills,
+ .expected_steps = passes(3, LAST_PASS),
+ .expected_seconds = 3 * (PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS),
+ },
};
for (const BBQAutoBattleScenario& scenario : scenarios){
database.add(scenario);
diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp
index 981baf46c7..6fc50a5687 100644
--- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp
+++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp
@@ -1265,10 +1265,22 @@ BBQAutoBattleResult run_auto_battle(
const uint64_t kills = actions.kills();
empty_passes = kills == kills_before ? empty_passes + 1 : 0;
const auto elapsed = std::chrono::duration_cast(actions.now() - start);
+
+ //Unknown HP heals, as every pass did before the threshold existed. The log rounds HP
+ //down, so it shows below the threshold exactly when it is.
+ const bool heal = !hp || *hp * 100 < policy.heal_below_hp_percent;
const std::string hp_text = hp ? std::to_string((int)std::floor(*hp * 100)) + "%" : "?";
+ const std::string threshold_text = std::to_string(policy.heal_below_hp_percent) + "%";
std::optional end;
- std::string next = "Below the target: return, heal and go again.";
+ std::string next;
+ if (!hp){
+ next = "Below the target and HP unknown: return, heal and go again.";
+ }else if (heal){
+ next = "Below the target and HP below " + threshold_text + ": return, heal and go again.";
+ }else{
+ next = "Below the target and HP at or above " + threshold_text + ": return and go again without healing.";
+ }
if (kills >= policy.kill_target){
end = BBQAutoBattleResult::TargetReached;
next = "Target reached: return without healing.";
@@ -1293,7 +1305,11 @@ BBQAutoBattleResult run_auto_battle(
if (end){
return *end;
}
- actions.heal();
+ //Skipping the heal also skips its re-fly: return_to_plaza() already lands on the Central
+ //Plaza fly point, which is where the flight to Chargestone starts from.
+ if (heal){
+ actions.heal();
+ }
}
return BBQAutoBattleResult::TargetReached;
}
@@ -1419,6 +1435,7 @@ void quest_auto_battle(
policy.kill_target = 30;
policy.time_limit = std::chrono::minutes(60);
}
+ policy.heal_below_hp_percent = BBQ_OPTIONS.AUTO_BATTLE_HEAL_PERCENT;
ConsoleBBQAutoBattleActions actions(env, stream, context, stats, tracker, sensors.lets_go_hp);
run_auto_battle(stream.logger(), actions, policy);
diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h
index 6cad2bd92b..94e73c6d1a 100644
--- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h
+++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h
@@ -196,6 +196,8 @@ struct BBQAutoBattlePolicy{
uint64_t max_empty_passes = 3;
//Give up after the pass that ends past this time.
std::chrono::minutes time_limit = std::chrono::minutes(35);
+ //Between passes, heal only if the lead's HP is below this percentage or unknown.
+ uint8_t heal_below_hp_percent = 50;
};
//Why run_auto_battle() returned.