diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.cpp new file mode 100644 index 0000000000..027f91a463 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.cpp @@ -0,0 +1,37 @@ +/* Badge Check + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_BadgeCheck.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +bool badge_check_wanted(StoryCheckLevel level){ + return level == StoryCheckLevel::TESTING || level == StoryCheckLevel::THOROUGH; +} + +std::string badge_check_failure(BadgeReading reading, std::string_view badge){ + if (reading == BadgeReading::PRESENT){ + return ""; + } + if (reading == BadgeReading::UNREADABLE){ + return std::format( + "The Trainer Card could not be read, so the {} is not confirmed (the card's screenshot is kept).", + badge + ); + } + return std::format( + "The Trainer Card has no {}: the battle that ended the step was not the gym leader's.", + badge + ); +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h new file mode 100644 index 0000000000..b2f4c76dcf --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h @@ -0,0 +1,47 @@ +/* Badge Check + * + * From: https://github.com/PokemonAutomation/ + * + * After a gym leader's battle, a thorough run opens the Trainer Card and + * checks the badge is on it: a battle can end with a win that was not the + * leader's (BDSP 01.04, lab-B 2026-11-12: the second gym trainer was taken + * for Roark and 01.05 saved with no badge). Each game reads its own card + * and says what it saw; the verdict and the wording are shared. + * + */ + +#ifndef PokemonAutomation_Pokemon_BadgeCheck_H +#define PokemonAutomation_Pokemon_BadgeCheck_H + +#include +#include +#include "Pokemon_StoryCheckLevel.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// What a game's Trainer Card reader saw for one badge. +enum class BadgeReading{ + PRESENT, + MISSING, + // The reader has no reference for the card yet, or the card was not on + // screen. A badge not seen is not a badge confirmed: this fails too. + UNREADABLE, +}; + +// Whether a run at `level` opens the Trainer Card after a leader's battle: +// the levels that check everything for the user. +bool badge_check_wanted(StoryCheckLevel level); + +// The failure text when the badge is missing or the card was not read, "" +// when the badge was seen. The check runs only at the levels that check +// everything (badge_check_wanted()), and there an unreadable card must not +// pass as a badge confirmed; the caller keeps the card's screenshot. +std::string badge_check_failure(BadgeReading reading, std::string_view badge); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp index b328d00fe2..f919f1af5b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp @@ -9,6 +9,7 @@ * */ +#include #include #include #include @@ -17,6 +18,7 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Filesystem/Filesystem.h" +#include "Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" @@ -24,16 +26,20 @@ #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h" #include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_BattleMenuReader.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryTrainers.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" #include "PokemonBDSP_AutoStory_BagScreen.h" +#include "PokemonBDSP_AutoStory_Battle.h" #include "PokemonBDSP_AutoStory_BattleMoves.h" #include "PokemonBDSP_AutoStory_Center.h" #include "PokemonBDSP_AutoStory_Events.h" +#include "PokemonBDSP_AutoStory_GymOpponent.h" #include "PokemonBDSP_AutoStory_IntroProbe.h" #include "PokemonBDSP_AutoStory_IntroSteps.h" #include "PokemonBDSP_AutoStory_LitDoorway.h" #include "PokemonBDSP_AutoStory_NewGame.h" +#include "PokemonBDSP_AutoStory_TalkOver.h" #include "PokemonBDSP_AutoStory_Actions_Tests.h" namespace PokemonAutomation{ @@ -493,6 +499,150 @@ UnitTestResult test_asks_someone_else(Logger&){ return true; } +// The overworld after a won battle, replayed look by look through the +// talk-over's judge as the console runs it; returns the looks with a box. +size_t replay_after_battle(const std::vector& looks){ + using Pokemon::ScreenEvent; + TalkOverTally judge; + WallClock now = WallClock{} + std::chrono::hours(1); + for (const Pokemon::ScreenEvents& look : looks){ + if (judge.look(look, now) == SceneMove::DONE){ + return judge.box_looks(); + } + now += TALK_OVER_HOLD + TALK_OVER_RELEASE; + } + const Pokemon::ScreenEvents quiet{ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::SCREEN_STILL}; + for (size_t i = 0; i < 20; i++){ + if (judge.look(quiet, now) == SceneMove::DONE){ + return judge.box_looks(); + } + now += TALK_OVER_HOLD + TALK_OVER_RELEASE; + } + return judge.box_looks(); +} + +// 01.04 (lab-B, 2026-11-13 01:17, French): Roark is told from a gym trainer +// by what happens after the battle, not by reading its intro text. A +// trainer's battle ends straight on a quiet overworld (22:49, the cleanup +// over in 7.8 s); Roark talks there for about 40 s (01:16:43 to 01:17:25), +// with a pause for the badge fanfare. +UnitTestResult test_gym_opponent_from_the_talk_after(Logger&){ + using Pokemon::ScreenEvent; + using Pokemon::ScreenEvents; + const ScreenEvents box{ScreenEvent::DIALOG_BOX}; + const ScreenEvents fanfare{ScreenEvent::PLAYER_CAN_MOVE}; + struct Case{ std::string_view name; std::vector looks; GymOpponent opponent; }; + std::vector roark(20, box); + roark.insert(roark.end(), 3, fanfare); + roark.insert(roark.end(), 12, box); + const Case cases[] = { + {"a trainer: the overworld comes back quiet", {}, GymOpponent::TRAINER}, + {"a trainer: one stray look with a box", {box}, GymOpponent::TRAINER}, + {"Roark: the badge and TM speech, a fanfare pause between", roark, GymOpponent::LEADER}, + }; + for (const Case& c : cases){ + const size_t looks = replay_after_battle(c.looks); + const GymOpponent opponent = gym_opponent_after_battle(looks); + if (opponent != c.opponent){ + return std::format("{}: {} look(s) with a box read as {}, not {}.", c.name, looks, + gym_opponent_name(opponent), gym_opponent_name(c.opponent)); + } + } + return true; +} + +// The column's time estimate is a hint only now: it must still count and +// restart, and a negative walk adds nothing. +UnitTestResult test_gym_column_is_a_hint(Logger&){ + GymColumn column(6, 9, 240ms); + if (column.leader_here() || column.tiles() != 0){ + return "At the entrance the hint is a trainer's tile."; + } + column.walked_north(240ms * 8); + if (!column.leader_here()){ + return "Past the halfway point to Roark the hint says his tile."; + } + column.walked_north(-100ms); + if (column.tiles() != 8){ + return "A negative walk must not move the hint."; + } + column.restart(); + if (column.leader_here()){ + return "After a restart the hint is a trainer's tile."; + } + return true; +} + +// Roark, lab-B 2026-11-12 23:49: four Potions at 26%, 26%, 29%, 29%. A Potion +// that gained nothing ends the Potions of the battle. +UnitTestResult test_potion_ledger_stops_without_gain(Logger&){ + PotionLedger potions; + potions.observe(0.26); + if (!potions.may_use()){ + return "The first Potion must be allowed."; + } + potions.used(0.26); + if (!potions.pending()){ + return "A Potion waits for its HP read."; + } + potions.observe(-1); + if (!potions.pending() || potions.stalled()){ + return "An unread bar must not settle a Potion."; + } + potions.observe(0.26); + if (!potions.stalled() || potions.may_use()){ + return "No gain (26% then 26%) must stop the Potions."; + } + // The gain case: a Potion that raised HP allows the next while it is low. + PotionLedger gaining; + gaining.used(0.20); + gaining.observe(0.45); + if (gaining.stalled() || !gaining.may_use()){ + return "A Potion that gained HP must not stop the Potions."; + } + // At most the cap, and none after the Bag runs out. + for (size_t n = 1; n < PotionLedger::MAX_POTIONS; n++){ + gaining.used(0.20); + gaining.observe(0.20 + 0.01 * (double)n); + } + if (gaining.may_use()){ + return "No more than the cap of Potions in a battle."; + } + PotionLedger empty; + empty.out_of_potions(); + if (empty.may_use()){ + return "No Potion once the Bag has none."; + } + return true; +} + +// The Trainer Card check runs for the levels that check everything and fails +// on a missing badge and on a card the reader cannot read. +UnitTestResult test_badge_check(Logger&){ + using Pokemon::BadgeReading; + using Pokemon::StoryCheckLevel; + for (StoryCheckLevel level : {StoryCheckLevel::TESTING, StoryCheckLevel::THOROUGH}){ + if (!Pokemon::badge_check_wanted(level)){ + return "A thorough run must check the badge."; + } + } + for (StoryCheckLevel level : {StoryCheckLevel::DEFAULT, StoryCheckLevel::FAST, StoryCheckLevel::SPEEDRUN}){ + if (Pokemon::badge_check_wanted(level)){ + return "A run below thorough must not open the Trainer Card."; + } + } + if (Pokemon::badge_check_failure(BadgeReading::MISSING, "Coal Badge").find("Coal Badge") == std::string::npos){ + return "A missing badge must fail and name the badge."; + } + if (!Pokemon::badge_check_failure(BadgeReading::PRESENT, "Coal Badge").empty()){ + return "A present badge must not fail."; + } + if (Pokemon::badge_check_failure(BadgeReading::UNREADABLE, "Coal Badge").find("Coal Badge") == std::string::npos){ + return "An unreadable card must fail and name the badge."; + } + return true; +} + UnitTestResult test_choose_move(Logger&){ struct Case{ std::string_view name; std::vector slots; size_t best; }; const Case cases[] = { @@ -675,6 +825,22 @@ const AutoStoryActionsCase AUTO_STORY_ACTIONS_CASES[] = { .input = {"wanderer talk: no ask from a tile that faces a sign (00.05b, the Poketch Company's sign first)", test_asks_someone_else}, .expectation = {}, }, + { + .input = {"01.04 gym: Roark is told by the talk on the overworld after the battle, in any language (lab-B 2026-11-13)", test_gym_opponent_from_the_talk_after}, + .expectation = {}, + }, + { + .input = {"01.04 gym: the column's tile estimate is a hint only", test_gym_column_is_a_hint}, + .expectation = {}, + }, + { + .input = {"Battle: a Potion that gained no HP ends the Potions of the battle (Roark, lab-B 2026-11-12 23:49)", test_potion_ledger_stops_without_gain}, + .expectation = {}, + }, + { + .input = {"badge check: thorough levels open the Trainer Card and a missing badge fails", test_badge_check}, + .expectation = {}, + }, { .input = {"battle moves: move menu screenshots in each language", test_move_menu_screenshots}, .expectation = {}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BadgeCheck.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BadgeCheck.cpp new file mode 100644 index 0000000000..f0a3686db2 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BadgeCheck.cpp @@ -0,0 +1,62 @@ +/* BDSP AutoStory - Badge Check + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/PrettyPrint.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_TrainerCardReader.h" +#include "PokemonBDSP_AutoStory_Actions.h" +#include "PokemonBDSP_AutoStory_BadgeCheck.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; + + +void verify_badge( + VideoStream& stream, ProControllerContext& context, + Pokemon::StoryCheckLevel level, size_t index, std::string_view badge, int menu_icons +){ + if (!Pokemon::badge_check_wanted(level)){ + return; + } + open_menu(stream, context, MenuCursorPosition::CARD, menu_icons); + // The card slides in. + context.wait_for(2000ms); + context.wait_for_all_requests(); + const VideoSnapshot card = stream.video().snapshot(); + if (!card){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, + "Badge check: no frame of the Trainer Card.", stream); + } + // Kept for the reader's fixtures (Pokemon::BadgeReading). + const std::string folder = SCREENSHOTS_PATH() + "AutoStory/cards/"; + Filesystem::create_directories(Filesystem::Path(folder)); + const std::string path = folder + now_to_filestring() + ".png"; + card.frame->save(path); + stream.log("Trainer Card screenshot: " + path); + + const Pokemon::BadgeReading reading = read_trainer_card_badge(*card.frame, index); + const std::string failure = Pokemon::badge_check_failure(reading, badge); + if (!failure.empty()){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, failure, stream); + } + pbf_mash_button(context, BUTTON_B, 3000ms); + context.wait_for_all_requests(); + stream.log(std::string("Badge check: the ") + std::string(badge) + " is on the Trainer Card."); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BadgeCheck.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BadgeCheck.h new file mode 100644 index 0000000000..0371d14752 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BadgeCheck.h @@ -0,0 +1,39 @@ +/* BDSP AutoStory - Badge Check + * + * From: https://github.com/PokemonAutomation/ + * + * Opens the Trainer Card and checks a badge is on it. The shared verdict is + * Pokemon_BadgeCheck.h's. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_BadgeCheck_H +#define PokemonAutomation_PokemonBDSP_AutoStory_BadgeCheck_H + +#include +#include +#include "CommonFramework/Tools/VideoStream.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// When `level` asks for it, opens the Trainer Card from the overworld, saves +// its screenshot, reads badge `index` (menu with `menu_icons` icons, see +// open_menu()) and backs out to the overworld. Fails +// the step with a screenshot when the badge is missing or the card cannot be +// read: nothing is passed unseen. +void verify_badge( + VideoStream& stream, ProControllerContext& context, + Pokemon::StoryCheckLevel level, size_t index, std::string_view badge, int menu_icons +); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Battle.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Battle.cpp index e177f711a6..88de25eb91 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Battle.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Battle.cpp @@ -216,10 +216,21 @@ enum class BattleHeal{ NOT_NEEDED, USED, NONE_LEFT }; // from the Bag on the lead, which takes the turn. Otherwise the // battle menu is left up. BattleHeal battle_heal_if_low(VideoStream& stream, ProControllerContext& context, - BattleType battle_type, double heal_below, const std::string& label){ + BattleType battle_type, double heal_below, const std::string& label, PotionLedger& potions){ + // The menu comes up after the turn's animations; the bar settles a + // moment later, so read it after a short wait when a Potion is settling. + if (potions.pending()){ + pbf_wait(context, 600ms); + } const double hp = read_battle_hp(stream, context); stream.log("[" + label + "] Our HP bar reads " + std::to_string((int)(hp * 100)) + "%."); - if (hp < 0 || hp >= heal_below){ + const size_t before_count = potions.count(); + potions.observe(hp); + if (potions.stalled() && before_count > 0){ + stream.log("[" + label + "] The last Potion gained no HP (read " + std::to_string((int)(hp * 100)) + + "%): the foe's hits take it back, or it was not used. No more Potions this battle; fighting on.", COLOR_ORANGE); + } + if (hp < 0 || hp >= heal_below || !potions.may_use()){ return BattleHeal::NOT_NEEDED; } if (!cursor_to_bag(stream, context, battle_type)){ @@ -240,6 +251,7 @@ BattleHeal battle_heal_if_low(VideoStream& stream, ProControllerContext& context pbf_press_button(context, BUTTON_A, 80ms, 1500ms); pbf_press_button(context, BUTTON_A, 80ms, 2500ms); context.wait_for_all_requests(); + potions.used(hp); return BattleHeal::USED; } @@ -255,8 +267,7 @@ struct BestMoveBattle{ // What a battle has done so far, across turns. struct BattleProgress{ bool battle_menu_seen = false; - bool out_of_potions = false; - size_t potions_used = 0; + PotionLedger potions; size_t turns = 0; size_t faint_switches = 0; }; @@ -276,13 +287,14 @@ void take_turn( } stream.log("[AutoStory] Battle menu detected.", COLOR_BLUE); // A trainer battle we may lose: a Potion when HP is low. - if (battle.battle_type == BattleType::TRAINER && !progress.out_of_potions && progress.potions_used < 4){ - const BattleHeal heal = battle_heal_if_low(stream, context, battle.battle_type, 0.35, label); + if (battle.battle_type == BattleType::TRAINER && progress.potions.may_use()){ + const BattleHeal heal = battle_heal_if_low(stream, context, battle.battle_type, 0.35, label, progress.potions); if (heal == BattleHeal::USED){ - progress.potions_used++; return; } - progress.out_of_potions = heal == BattleHeal::NONE_LEFT; + if (heal == BattleHeal::NONE_LEFT){ + progress.potions.out_of_potions(); + } } stream.log("[" + label + "] Move list position 1: use move 0."); use_best_move(stream, context, battle.battle_type, label); @@ -296,7 +308,7 @@ void take_turn( // The battle has ended: its text to the overworld, which must stay // dialogue-free for four seconds. -void finish_battle(VideoStream& stream, ProControllerContext& context, const std::string& label){ +size_t finish_battle(VideoStream& stream, ProControllerContext& context, const std::string& label){ stream.log("[AutoStory] " + label + " battle complete.", COLOR_GREEN); OverworldWatcher overworld; const int cleanup_ret = run_until(stream, context, @@ -308,7 +320,7 @@ void finish_battle(VideoStream& stream, ProControllerContext& context, const std label + ": Post-battle cleanup timed out.", stream); } context.wait_for_all_requests(); - confirm_battle_overworld(stream, context, label + " cleanup"); + return confirm_battle_overworld(stream, context, label + " cleanup"); } // B through the battle's text until its menu, its end, or a move-learning @@ -341,7 +353,7 @@ int wait_for_battle_screen( } // Fights the battle on screen to its end and the overworld after it. -void fight_with_best_move(VideoStream& stream, ProControllerContext& context, const BestMoveBattle& battle, const std::string& label){ +size_t fight_with_best_move(VideoStream& stream, ProControllerContext& context, const BestMoveBattle& battle, const std::string& label){ stream.log("[AutoStory] Starting " + label + " battle...", COLOR_BLUE); // Preserve the existing early-game transition delay. pbf_wait(context, 5000ms); @@ -352,8 +364,7 @@ void fight_with_best_move(VideoStream& stream, ProControllerContext& context, co if (ret == 0){ take_turn(stream, context, battle, progress, label); }else if (ret == 1){ - finish_battle(stream, context, label); - return; + return finish_battle(stream, context, label); }else if (ret == 2){ stream.log("[" + label + "] Declining move learning; preserving scripted move positions."); pbf_move_right_joystick(context, {0, -1}, 160ms, 840ms); @@ -376,14 +387,14 @@ void fight_with_best_move(VideoStream& stream, ProControllerContext& context, co } // namespace -void confirm_battle_overworld(VideoStream& stream, ProControllerContext& context, +size_t confirm_battle_overworld(VideoStream& stream, ProControllerContext& context, const std::string& label){ - talk_over(stream, context, label); + return talk_over_seen(stream, context, label).box_looks; } -void fight_story_battle(VideoStream& stream, ProControllerContext& context, const std::string& label, BattleFormat format){ +size_t fight_story_battle(VideoStream& stream, ProControllerContext& context, const std::string& label, BattleFormat format){ // The best move each turn; the next Pokemon after a faint; no new moves. - fight_with_best_move(stream, context, {.battle_type = BattleType::TRAINER, .format = format, .switch_on_faint = true}, label); + return fight_with_best_move(stream, context, {.battle_type = BattleType::TRAINER, .format = format, .switch_on_faint = true}, label); } void fight_trainer(VideoStream& stream, ProControllerContext& context, const std::string& label){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Battle.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Battle.h index 371ab3877e..5c39e2df31 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Battle.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Battle.h @@ -35,18 +35,75 @@ enum class BattleFormat{ DOUBLES, }; +// Whether Potions are working in a battle. A Potion takes the turn; when our +// HP at the next battle menu is no higher than before it, the heal is lost to +// the foe's hits (or the Bag flow did not use it), and more Potions would only +// hand over turns (Roark, lab-B 2026-11-12 23:49: 26%, 26%, 29%, 29% over four +// Potions). FRLG's battle policy skips a futile heal the same way, from the +// foe's mean hit; BDSP has no foe model, so the HP read after the turn is the +// net of the heal and the hit. After a Potion that gained nothing, none is +// used again this battle: the fight goes on with moves. +class PotionLedger{ +public: + // At a battle menu with our HP read (-1 unread). Settles the last + // Potion, if any: it gained when `hp` is above the HP it was used at. + void observe(double hp){ + if (m_before < 0 || hp < 0){ + // Nothing to settle, or an unread bar: no verdict either way. + return; + } + m_stalled = hp <= m_before; + m_before = -1; + } + // Whether a Potion may be used now. + bool may_use() const{ + return !m_stalled && !m_out && m_used < MAX_POTIONS; + } + // A Potion was used while our HP read `hp_before` (-1 unread). + void used(double hp_before){ + m_used++; + m_before = hp_before; + } + // The Bag has no Potion left. + void out_of_potions(){ + m_out = true; + } + // Whether the last Potion gained nothing (log text for the caller). + bool stalled() const{ + return m_stalled; + } + size_t count() const{ + return m_used; + } + // Whether a Potion is waiting for the HP read that settles it. + bool pending() const{ + return m_before >= 0; + } + + static constexpr size_t MAX_POTIONS = 4; + +private: + size_t m_used = 0; + double m_before = -1; + bool m_stalled = false; + bool m_out = false; +}; + // The speeches after a battle, to their end: talk_over(), B through the // lines until the overworld is quiet. Roark's badge lines pause for the // fanfare, and someone may walk off before the next line, so a moment // with no box is not the end. Fails with a screenshot after two minutes. -void confirm_battle_overworld(VideoStream& stream, ProControllerContext& context, const std::string& label); +// Returns how many looks showed a box: someone talked after the battle. +size_t confirm_battle_overworld(VideoStream& stream, ProControllerContext& context, const std::string& label); // A story battle that may go badly: the best move each turn, Potions // under 35 %, the next Pokemon when one faints, and "Keep old moves" // on level-up prompts. `doubles` confirms the default target each // turn in DOUBLES. Returns once the battle has ended, -// won or lost; after a loss we stand in the last Pokemon Center. -void fight_story_battle(VideoStream& stream, ProControllerContext& context, const std::string& label, BattleFormat format); +// won or lost; after a loss we stand in the last Pokemon Center. Returns how +// many looks showed a box on the overworld after the battle +// (confirm_battle_overworld()): who talked after it, in any language. +size_t fight_story_battle(VideoStream& stream, ProControllerContext& context, const std::string& label, BattleFormat format); // Any trainer battle, whatever the starter: the best move on the menu each // turn until the battle ends, then the text after it. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Oreburgh.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Oreburgh.cpp index 6ce669a041..e2e1c4f8a9 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Oreburgh.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Oreburgh.cpp @@ -9,13 +9,21 @@ * */ +#include +#include +#include #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryTrainers.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" +#include "PokemonBDSP_AutoStory_BadgeCheck.h" +#include "PokemonBDSP_AutoStory_GymOpponent.h" +#include "PokemonBDSP_AutoStory_TalkFight.h" #include "PokemonBDSP_AutoStory_Talks.h" #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" #include "PokemonBDSP_AutoStory_WildBattle.h" @@ -66,26 +74,82 @@ void oreburgh_street_to_gym(VideoStream& stream, ProControllerContext& context){ fail_step(stream, "Oreburgh: no column near the gym's door went in."); } +// The gym's column as tiles north of the entrance: where the farthest gym +// trainer stops us, and the tile in front of Roark. +GymColumn oreburgh_gym_column(){ + const Pokemon::TilePos entrance = map_point("OreburghGym", "entrance"); + const Pokemon::TilePos roark = map_point("OreburghGym", "roark"); + int last_trainer = 0; + for (const TrainerSight& trainer : oreburgh_gym_trainer_sights()){ + last_trainer = std::max(last_trainer, entrance.y - trainer.pos.y); + } + return GymColumn(last_trainer, entrance.y - roark.y - 1, ROUTE_MS_PER_TILE_UP_DOWN); +} + +// How a meeting with someone in the gym ended. +enum class GymMeeting{ + TALKED, // No battle: someone beaten, or a line only. + LOST, // A whiteout; we are in the Pokemon Center. + TRAINER_WON, + LEADER_WON, +}; + +// A talk has opened. Who it was is told after a won battle by whether +// anyone talked on the overworld (gym_opponent_after_battle()): Roark's +// badge speech, in any language. Never the count of trainers beaten or the +// distance walked (lab-B, 2026-11-12 22:50: the second trainer, met by a +// blocked walk and an A press, was fought as Roark, and 01.05 saved with no +// badge; 23:49: after a reload Roark was "Gym trainer 1"), and not the +// intro text, which OCR read in English only (01:17, French). The column +// only hints, and says how to wait: Roark's lines pause for more than 4 s +// before the battle (r210d: "only talked"), so up at his tile a battle is +// expected. +GymMeeting meet_gym_opponent(VideoStream& stream, ProControllerContext& context, const GymColumn& column){ + const bool leader_hint = column.leader_here(); + stream.log(std::format("[01.04] About {:.1f} tiles up the gym (a hint, not the opponent: {}).", + column.tiles(), leader_hint ? "Roark's tile" : "a trainer's")); + // His badge speech is over when talk_or_fight_who() returns (confirm_battle_overworld()). + const TalkFight met = talk_or_fight_who(stream, context, "Gym opponent", leader_hint ? TalkExpect::BATTLE : TalkExpect::TALK_OR_BATTLE); + if (!met.fought){ + return GymMeeting::TALKED; + } + if (in_pokemon_center(stream)){ + return GymMeeting::LOST; + } + const GymOpponent opponent = gym_opponent_after_battle(met.box_looks_after); + stream.log(std::format("[01.04] Beat {}: a box on the overworld after the battle in {} look(s).", + gym_opponent_name(opponent), met.box_looks_after)); + return opponent == GymOpponent::LEADER ? GymMeeting::LEADER_WON : GymMeeting::TRAINER_WON; +} + // Inside the Oreburgh Gym: straight up the middle, fighting the trainers // who stop us, to Roark on the top tier. Returns whether Roark was beaten; // false after a whiteout, which leaves us in the Pokemon Center. // Walking straight up meets both gym trainers (one at the entrance, one on // the second tier); their experience helps an under-levelled team, and -// after a whiteout they stay beaten. Butters' route goes round them. -bool oreburgh_gym_battles(VideoStream& stream, ProControllerContext& context){ +// after a whiteout they stay beaten. Butters' +// route goes round them. +bool oreburgh_gym_battles(VideoStream& stream, ProControllerContext& context, GymColumn& column){ + column.restart(); // The entry camera pans for about 7.5 s (Butters' reference video). context.wait_for(8000ms); if (dialogue_opens(stream, context, 3000ms)){ - if (talk_or_fight(stream, context, "Gym trainer at the entrance") && in_pokemon_center(stream)){ + if (meet_gym_opponent(stream, context, column) == GymMeeting::LOST){ return false; } } size_t stuck = 0; for (size_t leg = 0; leg < 10; leg++){ const WalkResult up = walk_until_no_wild(stream, context, {0, 1}, 8000ms, "north up the gym"); + column.walked_north(up.walked); if (up.stop == WalkStop::DIALOG){ - if (talk_or_fight(stream, context, "Gym trainer") && in_pokemon_center(stream)){ + switch (meet_gym_opponent(stream, context, column)){ + case GymMeeting::LOST: return false; + case GymMeeting::LEADER_WON: + return true; + default: + break; } continue; } @@ -93,16 +157,18 @@ bool oreburgh_gym_battles(VideoStream& stream, ProControllerContext& context){ continue; } // Roark stands at the top facing us; a wall or a stair edge says - // nothing to A. Only Roark starts a battle from our A here. The walk - // left us facing north: a turn tap that way would be a step. + // nothing to A. Whoever answers is the next opponent in line, which + // is a gym trainer until both are beaten. The walk left us facing + // north: a turn tap that way would be a step. pbf_press_button(context, BUTTON_A, 80ms, 200ms); if (dialogue_opens(stream, context, 3000ms)){ - // His lines pause for more than 4 s before the battle (r210d: "only - // talked"), so the battle is expected. - // His badge speech is over when talk_or_fight() returns: the - // battle ends with its speeches (confirm_battle_overworld()). - if (talk_or_fight(stream, context, "Roark", TalkExpect::BATTLE)){ - return !in_pokemon_center(stream); + switch (meet_gym_opponent(stream, context, column)){ + case GymMeeting::LOST: + return false; + case GymMeeting::LEADER_WON: + return true; + default: + break; } continue; } @@ -114,14 +180,15 @@ bool oreburgh_gym_battles(VideoStream& stream, ProControllerContext& context){ } // 01.04: west along the row into the gym and up it to Roark, again from the Center after a loss. -void gym_until_roark_beaten(VideoStream& stream, ProControllerContext& context){ +void gym_until_roark_beaten(VideoStream& stream, ProControllerContext& context, Pokemon::StoryCheckLevel checks){ // Losing costs some money and keeps the experience, so each try comes // back stronger: Roark won twice by hand against Piplup Lv 10 and 14 and // lost the third time. + GymColumn column = oreburgh_gym_column(); bool won = false; for (size_t attempt = 0; attempt < 5 && !won; attempt++){ oreburgh_street_to_gym(stream, context); - won = oreburgh_gym_battles(stream, context); + won = oreburgh_gym_battles(stream, context, column); if (!won){ stream.log("[01.04] Lost in the gym (try " + std::to_string(attempt + 1) + "); back from the Center.", COLOR_ORANGE); walk_out_of_center(stream, context, "Oreburgh"); @@ -130,13 +197,18 @@ void gym_until_roark_beaten(VideoStream& stream, ProControllerContext& context){ if (!won){ fail_step(stream, "Oreburgh Gym: lost to Roark five times."); } + // The Coal Badge is the gym's first (menu with 5 icons: no Map yet). + verify_badge(stream, context, checks, 0, "Coal Badge", 5); } } // namespace void add_oreburgh_events(StoryEvents& events){ - events.emplace("gym_until_roark_beaten", console_event(gym_until_roark_beaten)); + events.emplace("gym_until_roark_beaten", [](StoryExecutor& executor, Pokemon::RunState&, const Pokemon::StoryStep&){ + gym_until_roark_beaten(executor.stream(), executor.context(), executor.env().checks); + return Pokemon::outcome_ok(); + }); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_GymOpponent.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_GymOpponent.h new file mode 100644 index 0000000000..e7db3a5e99 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_GymOpponent.h @@ -0,0 +1,103 @@ +/* BDSP AutoStory - Gym opponent + * + * From: https://github.com/PokemonAutomation/ + * + * Who the person in front of us is on the way up the Oreburgh Gym. 01.04 + * walks straight up the middle column and is stopped by the gym trainers; + * when a blocked walk and an A press opened a talk, the talk was taken for + * Roark's, and the second trainer's fight ended the step with no badge + * (lab-B, 2026-11-12 22:50). A count of trainers beaten fixed that, but the + * count is run state: a reload, or a save made mid-gym, restarts it at zero + * and Roark was called "Gym trainer 1 of 2" (lab-B, 23:49). + * + * Position is not identity either: it is dead reckoning from the time held, + * so it is only a hint (a log line, and whether to expect Roark's long + * pause). Nor is the intro text: read by OCR, it held only in the + * languages it had word tables for, and a French game fought both gym + * battles and Roark's blind, then failed (lab-B, 2026-11-13 01:17). Who the + * opponent was is told by what happens after the battle, in any language: + * Roark talks on the overworld (the Coal Badge, then the TM, about 40 s of + * lines at 01:16), while a gym trainer's lines are all in the battle and + * the overworld comes back quiet (lab-B 2026-11-12 22:49: the trainer's + * cleanup was over in 7.8 s, the fade and the 5 s quiet). + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_GymOpponent_H +#define PokemonAutomation_PokemonBDSP_AutoStory_GymOpponent_H + +#include +#include +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Who a won gym battle was against. +enum class GymOpponent{ + TRAINER, + LEADER, +}; +inline std::string_view gym_opponent_name(GymOpponent opponent){ + return opponent == GymOpponent::LEADER ? "Roark" : "a gym trainer"; +} + +// This many looks with a box on the overworld after a won battle are the +// leader's speech. Roark's lines fill dozens of looks; one look is allowed +// to be a stray read of the battle's last frame. +constexpr size_t GYM_LEADER_TALK_LOOKS = 2; + +// Who a won gym battle was against, from the looks with a box on the +// overworld after it (confirm_battle_overworld()). +inline GymOpponent gym_opponent_after_battle(size_t box_looks_after){ + return box_looks_after >= GYM_LEADER_TALK_LOOKS ? GymOpponent::LEADER : GymOpponent::TRAINER; +} + +// Where we stand on the way up the gym's column, in tiles north of the +// entrance, estimated from the time walked north: a hint, not who is there. +class GymColumn{ +public: + // `last_trainer_tiles`: how far north of the entrance the farthest gym + // trainer stops us. `leader_tiles`: the same for the tile in front of + // the leader. `ms_per_tile`: the pace walking north. + GymColumn(double last_trainer_tiles, double leader_tiles, std::chrono::milliseconds ms_per_tile) + : m_last_trainer(last_trainer_tiles) + , m_leader(leader_tiles) + , m_ms_per_tile(ms_per_tile.count() > 0 ? ms_per_tile.count() : 1) + {} + + // A try starts again at the entrance (the first, or after a whiteout). + void restart(){ + m_walked_ms = 0; + } + // A walk north held for `walked`. + void walked_north(std::chrono::milliseconds walked){ + if (walked.count() > 0){ + m_walked_ms += walked.count(); + } + } + // Tiles north of the entrance, estimated. + double tiles() const{ + return (double)m_walked_ms / (double)m_ms_per_tile; + } + // Whether the person in front of us is the leader: past the halfway + // point between the last trainer's stop and the leader's. + bool leader_here() const{ + return tiles() >= (m_last_trainer + m_leader) / 2; + } + +private: + double m_last_trainer; + double m_leader; + long long m_ms_per_tile; + long long m_walked_ms = 0; +}; + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkFight.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkFight.h new file mode 100644 index 0000000000..436a8339f1 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkFight.h @@ -0,0 +1,37 @@ +/* BDSP AutoStory - Talk Fight + * + * From: https://github.com/PokemonAutomation/ + * + * A talk that may end in a trainer's battle, with whether anyone talked on + * the overworld after the battle. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_TalkFight_H +#define PokemonAutomation_PokemonBDSP_AutoStory_TalkFight_H + +#include "PokemonBDSP_AutoStory_Talks.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// How a talk ended, and what was said after its battle. +struct TalkFight{ + bool fought = false; + // Looks with a box on the overworld after the battle (0 with none). + size_t box_looks_after = 0; +}; +// talk_or_fight() that also says whether anyone talked after the battle. +TalkFight talk_or_fight_who( + VideoStream& stream, ProControllerContext& context, const std::string& label, + TalkExpect expect = TalkExpect::TALK_OR_BATTLE, BattleFormat format = BattleFormat::SINGLES +); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp index 9871501ec0..546b853a59 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp @@ -18,20 +18,24 @@ namespace PokemonBDSP{ TalkOverEnd talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec){ + return talk_over_seen(stream, context, label, spec).end; +} + +TalkOverSeen talk_over_seen(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec){ const WallClock deadline = current_time() + TALK_OVER_LIMIT; - TalkOver judge(spec.rule); + TalkOverTally judge(spec.rule); BdspScreenObserver eyes(spec.watch == TalkOverWatch::TRAINER ? BattleCue::TRAINER : BattleCue::WILD_MENU, spec.banner); while (current_time() < deadline){ context.wait_for_all_requests(); const WallClock now = current_time(); switch (judge.look(eyes.observe(stream.video().snapshot(), now), now)){ case SceneMove::DONE: - stream.log(std::format("[Talk-over] {}: over; {}.", label, judge.describe())); - return TalkOverEnd::QUIET; + stream.log(std::format("[Talk-over] {}: over; {}; a box in {} look(s).", label, judge.describe(), judge.box_looks())); + return {.end = TalkOverEnd::QUIET, .box_looks = judge.box_looks()}; case SceneMove::BATTLE: if (spec.watch == TalkOverWatch::TRAINER){ stream.log("[Talk-over] " + label + ": a battle started."); - return TalkOverEnd::BATTLE; + return {.end = TalkOverEnd::BATTLE, .box_looks = judge.box_looks()}; } stream.log("[Talk-over] " + label + ": in a wild battle; fleeing."); run_from_wild_battle(stream, context); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h index 9469c3954c..4f94cde719 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h @@ -77,8 +77,45 @@ enum class TalkOverEnd{ BATTLE, // Only with TalkOverWatch::TRAINER. }; +// TalkOver's judgement, with how many looks showed a box: what was said, +// in any language, without reading it. Pure: tests replay looks through it. +class TalkOverTally{ +public: + explicit TalkOverTally(TalkOverRule rule = {}) + : m_judge(rule) + {} + SceneMove look(const Pokemon::ScreenEvents& events, WallClock now){ + const SceneMove move = m_judge.look(events, now); + if (move == SceneMove::NEXT){ + m_box_looks++; + } + return move; + } + size_t box_looks() const{ + return m_box_looks; + } + bool warped() const{ + return m_judge.warped(); + } + std::string describe() const{ + return m_judge.describe(); + } + +private: + TalkOver m_judge; + size_t m_box_looks = 0; +}; + +// How talk_over_seen() ended, and how many of its looks showed a box. +struct TalkOverSeen{ + TalkOverEnd end = TalkOverEnd::QUIET; + size_t box_looks = 0; +}; + // Presses through any text and scene on the console until TalkOver says it // is over. Fails with a screenshot after TALK_OVER_LIMIT. +TalkOverSeen talk_over_seen(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec = {}); +// talk_over_seen() without the count. TalkOverEnd talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec = {}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp index e8eb07f10d..338745aa5f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp @@ -33,6 +33,7 @@ #include "PokemonBDSP_AutoStory_TalkOver.h" #include "PokemonBDSP_AutoStory_WildBattle.h" #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" +#include "PokemonBDSP_AutoStory_TalkFight.h" #include "PokemonBDSP_AutoStory_Talks.h" namespace PokemonAutomation{ @@ -56,22 +57,26 @@ bool dialogue_opens(VideoStream& stream, ProControllerContext& context, Millisec } bool talk_or_fight(VideoStream& stream, ProControllerContext& context, const std::string& label, TalkExpect expect, BattleFormat format){ + return talk_or_fight_who(stream, context, label, expect, format).fought; +} + +TalkFight talk_or_fight_who(VideoStream& stream, ProControllerContext& context, const std::string& label, TalkExpect expect, BattleFormat format){ const TalkOverEnd end = talk_over(stream, context, label, { .rule = {.end_on_quiet = expect != TalkExpect::BATTLE}, .watch = TalkOverWatch::TRAINER, }); if (end == TalkOverEnd::QUIET){ route_status(stream, label + " only talked."); - return false; + return {}; } route_status(stream, "Fighting " + label + "."); // The battle ends with its speeches over (confirm_battle_overworld()): // Roark's badge lines keep the Potion's menu from opening until then. - fight_story_battle(stream, context, label, format); + const size_t box_looks_after = fight_story_battle(stream, context, label, format); if (!in_pokemon_center(stream)){ use_potion_first_pokemon(stream, context, 0.8); } - return true; + return {.fought = true, .box_looks_after = box_looks_after}; } // A rough check that we stand in a Pokemon Center: its floor fills the lower diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_TrainerCardReader.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_TrainerCardReader.cpp new file mode 100644 index 0000000000..3e6160a09f --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_TrainerCardReader.cpp @@ -0,0 +1,23 @@ +/* BDSP AutoStory - Trainer Card Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_TrainerCardReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +Pokemon::BadgeReading read_trainer_card_badge(const ImageViewRGB32&, size_t){ + // See the header: the badge boxes wait for a fixture. + return Pokemon::BadgeReading::UNREADABLE; +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_TrainerCardReader.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_TrainerCardReader.h new file mode 100644 index 0000000000..356581510b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_TrainerCardReader.h @@ -0,0 +1,37 @@ +/* BDSP AutoStory - Trainer Card Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Reads the badges on the Trainer Card (menu icon CARD). + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_TrainerCardReader_H +#define PokemonAutomation_PokemonBDSP_AutoStory_TrainerCardReader_H + +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Whether badge `index` (0 = Coal Badge, in the order the gyms are beaten) +// is on the card shown on `screen`. +// +// TODO: no Trainer Card screenshot exists yet (CommandLineTests has none and +// the lab has only save-prompt shots), so the badge boxes are not known and +// this reads UNREADABLE, which fails the thorough check (nothing is passed +// unseen): until it is built 01.04 cannot pass at those levels. verify_badge() saves the card it opened to +// Screenshots/AutoStory/cards/; a card with 0 badges and one with 1 badge +// from console B are the fixtures to draw the boxes and thresholds from. +Pokemon::BadgeReading read_trainer_card_badge(const ImageViewRGB32& screen, size_t index); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp index 9e10c1ac1f..7fa21d38ea 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp @@ -246,7 +246,7 @@ void BDSPAutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerCo // The reads that use text (Location.h) take the game's language from here. set_story_language(RUN.language()); - StoryEnv story{env, context, STARTER, PLAYER_NAME}; + StoryEnv story{env, context, STARTER, PLAYER_NAME, RUN.check_level()}; StoryExecutor executor(story); executor.set_stop_rows(rows_that_stop(checkpoints)); // A start with a save always loads it first, so the run never walks diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h index 9cb816bf64..c9655a2046 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h @@ -42,6 +42,7 @@ #include "Pokemon/AutoStory/Pokemon_StorySegments.h" #include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "Pokemon/AutoStory/Types/Pokemon_GridPose.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryStep.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h" @@ -88,6 +89,8 @@ struct StoryEnv{ ProControllerContext& context; StarterChoice starter = StarterChoice::CHIMCHAR; std::string player_name; + // How much the steps confirm on screen (StoryRunOptions::check_level()). + Pokemon::StoryCheckLevel checks = Pokemon::StoryCheckLevel::DEFAULT; }; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 25156664aa..47fac311f7 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1654,6 +1654,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg_Tests.h Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h + Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.cpp + Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h @@ -1723,6 +1725,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.h + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BadgeCheck.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BadgeCheck.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagItemReader.cpp @@ -1741,6 +1745,7 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Oreburgh.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Route204.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Sandgem.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_GymOpponent.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroProbe.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroSteps.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_LitDoorway.h @@ -1750,6 +1755,7 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkFight.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp @@ -1788,6 +1794,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_ScreenEvents.cpp Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_ScreenEvents.h + Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_TrainerCardReader.cpp + Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_TrainerCardReader.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp