From f2a2abc0fdcd7c26ed2e374067a4d2950ee1869f Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 01:45:52 -0800 Subject: [PATCH 1/2] PokemonLZA AutoStory: start load, launch from HOME, Confirm Choices and the zone gate walk --- .../PokemonLZA/PokemonLZA_Tests.cpp | 4 + .../PokemonLZA_AutoStoryConfirmChoices.cpp | 89 +++++++ .../PokemonLZA_AutoStoryConfirmChoices.h | 41 ++++ .../Actions/PokemonLZA_AutoStoryGateWalk.cpp | 143 +++++++++++ .../Actions/PokemonLZA_AutoStoryGateWalk.h | 66 ++++++ .../PokemonLZA_AutoStoryZoneGateReader.cpp | 139 +++++++++++ .../PokemonLZA_AutoStoryZoneGateReader.h | 48 ++++ ...kemonLZA_AutoStoryZoneGateReader_Tests.cpp | 204 ++++++++++++++++ ...PokemonLZA_AutoStoryZoneGateReader_Tests.h | 26 ++ .../AutoStory/PokemonLZA_AutoStoryLaunch.cpp | 115 +++++++++ .../AutoStory/PokemonLZA_AutoStoryLaunch.h | 40 ++++ .../PokemonLZA_AutoStoryStartLoad.cpp | 64 +++++ .../AutoStory/PokemonLZA_AutoStoryStartLoad.h | 96 ++++++++ .../PokemonLZA_AutoStoryStartLoad_Tests.cpp | 222 ++++++++++++++++++ .../PokemonLZA_AutoStoryStartLoad_Tests.h | 26 ++ SerialPrograms/cmake/SourceFiles.cmake | 14 ++ 16 files changed, 1337 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index bc8bfd99cc..88955de021 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -22,11 +22,13 @@ #include "Inference/PokemonLZA_PartyBarDetector.h" #include "Inference/PokemonLZA_SelectionArrowDetector.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryFailures.h" +#include "Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader_Tests.h" +#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h" @@ -58,8 +60,10 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStoryConfirmChoicesReader(database); add_tests_AutoStoryDialogChoiceBox(database); add_tests_AutoStoryObjectiveMarkerReader(database); + add_tests_AutoStoryZoneGateReader(database); add_tests_AutoStoryFailures(database); add_tests_AutoStoryDialogs(database); + add_tests_AutoStoryStartLoad(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp new file mode 100644 index 0000000000..e956410c03 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp @@ -0,0 +1,89 @@ +/* PokemonLZA AutoStory - Confirm Choices + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/Tools/DebugDumper.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h" +#include "PokemonLZA_AutoStoryConfirmChoices.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// The "Confirm Choices" highlight on the screen now, reading a few frames +// over `window` with no press. Nullopt if none of them is the screen. +// `dump`: save the frame read to DebugDumps under that name. +std::optional read_confirm_choices_now( + ConsoleHandle& console, ProControllerContext& context, Milliseconds window, const std::string& dump +){ + const WallClock deadline = current_time() + window; + while (true){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + const std::optional cursor = frame ? read_confirm_choices_cursor(frame) : std::nullopt; + if (cursor || current_time() >= deadline){ + if (frame){ + dump_debug_image(console, "PokemonLZA/AutoStory/Intro", dump, frame); + } + return cursor; + } + context.wait_for(250ms); + } +} + +} // namespace + + +size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& context){ + const std::optional cursor = read_confirm_choices_now(console, context, 2000ms, "confirm-choices"); + if (!cursor){ + throw UserSetupError( + console, + "AutoStory: 01.00 starts on the new game's \"Confirm Choices\" screen, with the language, look and name " + "already chosen by hand. It is not on screen; nothing was pressed." + ); + } + console.log(std::format("AutoStory intro: Confirm Choices on screen, row {} highlighted.", *cursor)); + return *cursor; +} + +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context){ + std::optional cursor = require_confirm_choices(console, context); + for (size_t press = 0; press < 6 && cursor; press++){ + if (*cursor == CONFIRM_CHOICES_READY_ROW){ + console.log("AutoStory intro: Confirm Choices: A on \"Ready!\"."); + pbf_press_button(context, BUTTON_A, 160ms, 2000ms); + context.wait_for_all_requests(); + return; + } + console.log("AutoStory intro: Confirm Choices: DOWN."); + pbf_press_dpad(context, DPAD_DOWN, 160ms, 500ms); + cursor = read_confirm_choices_now(console, context, 1000ms, "confirm-choices-moved"); + if (cursor){ + console.log(std::format("AutoStory intro: Confirm Choices: the highlight is on row {}.", *cursor)); + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "AutoStory intro: the Confirm Choices highlight was not read on \"Ready!\".", + console + ); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h new file mode 100644 index 0000000000..e9c40d6812 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h @@ -0,0 +1,41 @@ +/* PokemonLZA AutoStory - Confirm Choices + * + * From: https://github.com/PokemonAutomation/ + * + * 01.00's start: the new game's "Confirm Choices" screen, after the + * language, look and name were chosen by hand. Its reader is in + * Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryConfirmChoices_H +#define PokemonAutomation_PokemonLZA_AutoStoryConfirmChoices_H + +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The highlighted row of "Confirm Choices", read from frames over up to +// 2 s with no press. Throws UserSetupError if the screen does not show. +size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& context); + +// 01.00's first step: the new game's language, look and name were chosen +// by hand and "Confirm Choices" is on screen. Checks that screen first +// (require_confirm_choices()): on any other screen throws UserSetupError +// and presses nothing. Then moves the highlight to "Ready!" one DOWN at a +// time, reading it after each, and presses A there: the save's only +// change is this press, on a screen it has read. Throws +// OperationFailedException if the highlight is lost on the way. +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.cpp new file mode 100644 index 0000000000..ed143ac6e2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.cpp @@ -0,0 +1,143 @@ +/* PokemonLZA AutoStory - Walk to a wild zone's gate + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.h" +#include "PokemonLZA_AutoStoryGateWalk.h" +#include "PokemonLZA_AutoStoryMoves.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryFailures.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; + + +namespace{ + +// One slice of the walk between looks, as walk_to_prompt()'s. +constexpr Milliseconds GATE_WALK_SLICE(250); +// Walking this long without a look at the gate fails the walk. From +// Wild Zone 1's catch spot at 60 the far gate is small at first: 1 s +// missed it once. +constexpr Milliseconds GATE_FIRST_SEEN_WITHIN(3000); +// The screen's width in degrees of view, for the steer: a guess. +constexpr double VIEW_DEGREES = 60; +// Closer to the middle than this, the gate is dead ahead. +constexpr double DEAD_AHEAD = 0.02; + +// The gate's readings on a look, if any. +struct GateRead{ + int x = 0; + int width = 0; +}; + +std::optional gate_on(const Pokemon::Observation& look){ + const auto x = look.readings.find(ZONE_GATE_X_READING); + const auto width = look.readings.find(ZONE_GATE_WIDTH_READING); + if (x == look.readings.end() || width == look.readings.end()){ + return std::nullopt; + } + return GateRead{.x = x->second, .width = width->second}; +} + +// "gate on 3 of 5 looks, last at x = 0.520 width 0.150", or "no gate on 5 looks". +std::string gate_readings(size_t seen, size_t looks, const std::optional& last){ + if (!last){ + return std::format("no gate on {} looks", looks); + } + return std::format("gate on {} of {} looks, last at x = {:.3f} width {:.3f}", seen, looks, last->x / 1000.0, last->width / 1000.0); +} + +// The stick's angle, degrees clockwise of straight on, toward a gate at +// `x` (0 to 1) on screen. +double gate_steer_degrees(double x){ + const double off = x - 0.5; + if (std::abs(off) < DEAD_AHEAD){ + return 0; + } + return std::round(off * VIEW_DEGREES); +} + +} // namespace + + +PlzaReader zone_gate_reader(){ + return [](PlzaBackend&, Pokemon::Observation& look){ + if (!look.frame || !look.frame->frame){ + return; + } + const std::optional gate = read_zone_gate(*look.frame->frame); + if (!gate){ + return; + } + look.readings[std::string(ZONE_GATE_X_READING)] = (int)std::lround(gate->x * 1000); + look.readings[std::string(ZONE_GATE_WIDTH_READING)] = (int)std::lround(gate->width * 1000); + }; +} + +Pokemon::Outcome walk_to_zone_gate_entrance( + PlzaBackend& backend, const PlzaReader& heading, const PlzaReader& gate, const GateWalk& walk +){ + if (walk.heading){ + const Pokemon::Outcome faced = face_heading(backend, heading, *walk.heading, 10.0); + if (!faced.succeeded()){ + return faced; + } + } + Milliseconds walked(0); + double angle = 0; + size_t looks = 0; + size_t seen = 0; + std::optional last; + while (true){ + backend.scope().throw_if_cancelled(); + Pokemon::Observation look = backend.observe(); + if (gate){ + gate(backend, look); + } + looks++; + if (look.events.has(PokemonAutomation::ScreenEvent::INTERACT_PROMPT)){ + // The heading at the prompt: the street's way through the gate, + // for a plan's `heading` (none read: -1). + if (heading){ + heading(backend, look); + } + backend.log(std::format( + "[PLZA] walk_to_zone_gate_entrance: the A prompt shows after {} ms ({}), heading {}", + walked.count(), gate_readings(seen, looks, last), Pokemon::story_heading(look).value_or(-1) + )); + return Pokemon::outcome_ok(); + } + const std::optional read = gate_on(look); + if (read){ + seen++; + last = read; + angle = gate_steer_degrees(read->x / 1000.0); + } + if (!last && walked >= GATE_FIRST_SEEN_WITHIN){ + return plza_failed("gate_not_seen", std::format( + "walk_to_zone_gate_entrance: {} in {} ms of walking", gate_readings(seen, looks, last), walked.count() + )); + } + if (walked >= walk.timeout){ + return plza_failed("no_prompt", std::format( + "walk_to_zone_gate_entrance: no A prompt in {} ms of walking, {}", walk.timeout.count(), gate_readings(seen, looks, last) + )); + } + backend.stick(angle, GATE_WALK_SLICE, 0ms, Pokemon::StoryPace::WALK); + walked += GATE_WALK_SLICE; + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.h new file mode 100644 index 0000000000..4cdb7de934 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.h @@ -0,0 +1,66 @@ +/* PokemonLZA AutoStory - Walk to a wild zone's gate + * + * From: https://github.com/PokemonAutomation/ + * + * The walk up the street to a wild zone's entrance gate, steered by the + * gate's pillars on screen (read_zone_gate()) until the gate's A prompt + * shows: 03.06's walk into Wild Zone 1. Timed turns from the Pokemon + * Center ended pointing along the sidewalk, and a straight walk from + * there ran 10 s into the zone's wall. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryGateWalk_H +#define PokemonAutomation_PokemonLZA_AutoStoryGateWalk_H + +#include +#include +#include "Common/Cpp/Time.h" +#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The reading (ScreenObservation::readings) of a wild zone's entrance +// gate's middle on a look (read_zone_gate()), in thousandths of the +// screen's width; none when no gate shows. +inline constexpr std::string_view ZONE_GATE_X_READING = "walk.zone_gate_x"; +// The reading of the gate's width, as ZONE_GATE_X_READING. +inline constexpr std::string_view ZONE_GATE_WIDTH_READING = "walk.zone_gate_width"; + +// Sets a look's ZONE_GATE_X_READING and ZONE_GATE_WIDTH_READING from its +// frame (read_zone_gate()); nothing on a look with no frame or no gate. +PlzaReader zone_gate_reader(); + +// What walk_to_zone_gate_entrance() does. +struct GateWalk{ + // The compass heading to face first (face_heading(), by `heading`'s + // reader), along the street to the gate; none: no turn first. + std::optional heading = std::nullopt; + // Walking this long with no A prompt fails the walk. + Milliseconds timeout = Milliseconds(15000); +}; + +// Faces `walk`'s heading, then walks in slices toward the gate, the stick +// turned toward it on each look the gate shows (`gate` sets its +// readings): 0 within 2% of the middle, else the gate's offset from the +// middle times the screen's ~60 degrees of view (a guess, NEEDS CONSOLE), +// rounded, 30 at most at the edges. On until the gate's A prompt (INTERACT_PROMPT) shows; none +// when it shows already. Once the gate is lost (too close: its pillars +// leave the screen), the last angle holds. Fails as "gate_not_seen" when +// the first second of looks shows no gate (the player faces away from +// it; walking on ran into the zone's wall), and as "no_prompt" after the +// timeout, each with how many looks saw the gate and its last reading. +Pokemon::Outcome walk_to_zone_gate_entrance( + PlzaBackend& backend, const PlzaReader& heading, const PlzaReader& gate, const GateWalk& walk +); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.cpp new file mode 100644 index 0000000000..813323750a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.cpp @@ -0,0 +1,139 @@ +/* PokemonLZA AutoStory - Zone gate reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "CommonTools/Images/BinaryImage_FilterRgb32.h" +#include "Kernels/Waterfill/Kernels_Waterfill_Session.h" +#include "PokemonLZA_AutoStoryZoneGateReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace Kernels::Waterfill; + + +namespace{ + +// The pillars' lime, about (180, 250, 85) on the console, as ARGB bounds: +// red 100-225, green 215-255, blue 0-135. The statues on top read as +// their own blobs. The wall's stripes are this green too. +constexpr uint32_t LIME_MIN = 0xff64d700; +constexpr uint32_t LIME_MAX = 0xffe1ff87; + +bool lime(uint32_t pixel){ + for (int shift = 0; shift < 24; shift += 8){ + const uint32_t channel = (pixel >> shift) & 0xff; + if (channel < ((LIME_MIN >> shift) & 0xff) || channel > ((LIME_MAX >> shift) & 0xff)){ + return false; + } + } + return true; +} + +// A pillar's share of its box that is lime: 0.59 and 0.64 on the gate +// from mid-street; the wall's tallest blobs fill 0.31 to 0.53 of theirs. +constexpr double PILLAR_FILL = 0.55; + +// A solid lime blob at least twice as tall as wide (ten times at most), +// at least 6% of the screen's height. +bool pillar_shaped(const WaterfillObject& blob, size_t screen_height){ + const double width = (double)blob.width(); + const double height = (double)blob.height(); + return height >= 0.06 * (double)screen_height + && height >= 2 * width && height <= 10 * width + && (double)blob.area >= PILLAR_FILL * width * height; +} + +bool within_ratio(double a, double b, double ratio){ + return a <= b * ratio && b <= a * ratio; +} + +// The share of lime pixels between `left` and `right`, over the pillars' +// height: the gate's opening shows the street through its barrier. +double lime_between(const ImageViewRGB32& screen, const WaterfillObject& left, const WaterfillObject& right){ + const size_t min_y = std::max(left.min_y, right.min_y); + const size_t max_y = std::min(left.max_y, right.max_y); + if (right.min_x <= left.max_x || max_y <= min_y){ + return 1; + } + size_t count = 0; + for (size_t y = min_y; y < max_y; y++){ + for (size_t x = left.max_x; x < right.min_x; x++){ + count += lime(screen.pixel(x, y)) ? 1 : 0; + } + } + return (double)count / (double)((right.min_x - left.max_x) * (max_y - min_y)); +} + +// Whether `left` and `right` are a gate's two pillars: about the same +// size, their feet on about the same line, 1.5 to 8 widths apart, and +// less than 10% lime between them. +bool gate_pair(const ImageViewRGB32& screen, const WaterfillObject& left, const WaterfillObject& right){ + const double width = ((double)left.width() + (double)right.width()) / 2; + const double height = ((double)left.height() + (double)right.height()) / 2; + if (!within_ratio((double)left.width(), (double)right.width(), 1.4) + || !within_ratio((double)left.height(), (double)right.height(), 1.33) + ){ + return false; + } + if (std::abs((double)left.max_y - (double)right.max_y) > 0.25 * height){ + return false; + } + const double gap = (double)right.min_x - (double)left.max_x; + if (gap < 1.5 * width || gap > 8 * width){ + return false; + } + return lime_between(screen, left, right) < 0.10; +} + +} // namespace + + +std::optional read_zone_gate(const ImageViewRGB32& screen){ + if (!screen || screen.width() < 16 || screen.height() < 16){ + return std::nullopt; + } + const double scale = (double)screen.height() / 1080.0; + PackedBinaryMatrix matrix = compress_rgb32_to_binary_range(screen, LIME_MIN, LIME_MAX); + std::unique_ptr session = make_WaterfillSession(matrix); + std::unique_ptr iter = session->make_iterator((size_t)std::max(1.0, 300 * scale * scale)); + std::vector pillars; + WaterfillObject blob; + while (iter->find_next(blob, false)){ + if (pillar_shaped(blob, screen.height())){ + pillars.push_back(blob); + } + } + std::sort(pillars.begin(), pillars.end(), [](const WaterfillObject& a, const WaterfillObject& b){ + return a.min_x < b.min_x; + }); + std::optional best; + size_t best_area = 0; + for (size_t i = 0; i < pillars.size(); i++){ + for (size_t j = i + 1; j < pillars.size(); j++){ + const WaterfillObject& left = pillars[i]; + const WaterfillObject& right = pillars[j]; + if (left.area + right.area <= best_area || !gate_pair(screen, left, right)){ + continue; + } + best_area = left.area + right.area; + best = ZoneGateSighting{ + .x = ((double)left.min_x + (double)right.max_x) / 2 / (double)screen.width(), + .width = ((double)right.max_x - (double)left.min_x) / (double)screen.width(), + }; + } + } + return best; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.h new file mode 100644 index 0000000000..8ec3735f90 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.h @@ -0,0 +1,48 @@ +/* PokemonLZA AutoStory - Zone gate reader + * + * From: https://github.com/PokemonAutomation/ + * + * A wild zone's entrance gate in the overworld, by colour and shape. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryZoneGateReader_H +#define PokemonAutomation_PokemonLZA_AutoStoryZoneGateReader_H + +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// A wild zone's entrance gate: two tall pillars of the zone's saturated +// lime green, a statue on each, with the zone's emblem hanging between +// them. From mid-street ~20 m before Wild Zone 1's gate each pillar is +// ~3% of the width wide and ~18% of the height tall, ~3 widths apart +//. +struct ZoneGateSighting{ + // Halfway between the pillars' outer edges, 0 (left edge) to 1 (right + // edge). + double x = 0; + // From the left pillar's left edge to the right pillar's right edge, + // as a share of the screen's width: it grows as the player nears. + double width = 0; +}; + +// The gate on `screen`, if it shows: the largest pair of pillar-shaped +// lime blobs (solid, at least twice as tall as wide) of about the same +// size, standing on about the same line, 1.5 to 8 widths apart with +// little lime between them. The zone's wall, the same green, is many +// thin stripes and a grid: its blobs are not solid, and those that come +// near touch or overlap (a walk's miss beside the wall). +// Language-independent: no text is read. +std::optional read_zone_gate(const ImageViewRGB32& screen); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.cpp new file mode 100644 index 0000000000..888e394b4f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.cpp @@ -0,0 +1,204 @@ +/* PokemonLZA AutoStory - Zone gate reader Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Synthetic 1920x1080 frames with the pillars' lime drawn as bars, and + * console frames from CommandLineTests/PokemonLZA/AutoStoryDetectors/ + * Zone1Gate/: the gate ahead from mid-street (1920x1080) + * and a walk's miss beside the zone's wall (kept resized + * to 640x360). + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "VideoGames/PokemonLZA/Inference/Map/PokemonLZA_DirectionArrowDetector.h" +#include "PokemonLZA_AutoStoryZoneGateReader.h" +#include "PokemonLZA_AutoStoryZoneGateReader_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +constexpr uint32_t STREET = 0xff606870; +// The pillars' lime on the console. +constexpr uint32_t LIME = 0xffb4fa55; + +// A filled bar of the pillars' lime, in pixels of a 1920x1080 frame. +struct Bar{ + size_t x; + size_t y; + size_t width; + size_t height; +}; + +ImageRGB32 frame_with(const std::vector& bars){ + ImageRGB32 image(1920, 1080); + image.fill(STREET); + for (const Bar& bar : bars){ + for (size_t y = bar.y; y < bar.y + bar.height; y++){ + for (size_t x = bar.x; x < bar.x + bar.width; x++){ + image.pixel(x, y) = LIME; + } + } + } + return image; +} + +// Thin stripes `pitch` apart from `x` to `x + width`, as the zone's wall. +std::vector stripes(size_t x, size_t width, size_t pitch){ + std::vector bars; + for (size_t at = x; at < x + width; at += pitch){ + bars.push_back({at, 300, 3, 500}); + } + return bars; +} + +// A console frame of the Zone1Gate folder. +ImageRGB32 console_frame(std::string_view name){ + return ImageRGB32(std::format("{}PokemonLZA/AutoStoryDetectors/Zone1Gate/{}", UNIT_TEST_RESOURCE_PATH(), name)); +} + +std::string describe(const std::optional& gate){ + return gate ? std::format("a gate at x = {:.3f} width {:.3f}", gate->x, gate->width) : std::string("no gate"); +} + + +struct GateFrameCase{ + std::string name; + struct Input{ + std::function frame; + }; + Input input; + struct Expectation{ + // The gate; none: no gate. Within 0.01 on x, 0.02 on width. + std::optional gate; + // The minimap arrow's heading (DirectionArrowDetector), within 5 + // degrees; none: not checked. + std::optional heading = std::nullopt; + }; + Expectation expectation; +}; + +const GateFrameCase GATE_FRAME_CASES[] = { + { + .name = "two pillars in the middle", + .input = {.frame = []{ return frame_with({{800, 220, 56, 200}, {1020, 220, 56, 200}}); }}, + .expectation = {.gate = ZoneGateSighting{.x = 0.489, .width = 0.144}}, + }, + { + .name = "two pillars right of the middle", + .input = {.frame = []{ return frame_with({{1300, 300, 40, 150}, {1460, 300, 40, 150}}); }}, + .expectation = {.gate = ZoneGateSighting{.x = 0.7292, .width = 0.104}}, + }, + { + .name = "one pillar", + .input = {.frame = []{ return frame_with({{800, 220, 56, 200}}); }}, + .expectation = {.gate = std::nullopt}, + }, + { + .name = "two pillars touching", + .input = {.frame = []{ return frame_with({{800, 220, 56, 200}, {858, 220, 56, 200}}); }}, + .expectation = {.gate = std::nullopt}, + }, + { + .name = "two pillars too far apart", + .input = {.frame = []{ return frame_with({{200, 220, 56, 200}, {1600, 220, 56, 200}}); }}, + .expectation = {.gate = std::nullopt}, + }, + { + .name = "two pillars of different heights", + .input = {.frame = []{ return frame_with({{800, 220, 56, 200}, {1020, 320, 56, 100}}); }}, + .expectation = {.gate = std::nullopt}, + }, + { + .name = "two pillars with lime between them", + .input = {.frame = []{ return frame_with({{800, 220, 56, 200}, {1020, 220, 56, 200}, {856, 220, 164, 60}}); }}, + .expectation = {.gate = std::nullopt}, + }, + { + .name = "the wall's thin stripes", + .input = {.frame = []{ return frame_with(stripes(900, 900, 24)); }}, + .expectation = {.gate = std::nullopt}, + }, + {.name = "no lime", .input = {.frame = []{ return frame_with({}); }}, .expectation = {.gate = std::nullopt}}, + {.name = "an empty frame", .input = {.frame = []{ return ImageRGB32(); }}, .expectation = {.gate = std::nullopt}}, + {.name = "a 1 x 1 frame", .input = {.frame = []{ return ImageRGB32(1, 1); }}, .expectation = {.gate = std::nullopt}}, + { + .name = "console: Wild Zone 1's gate ahead from mid-street", + .input = {.frame = []{ return console_frame("gate_ahead.png"); }}, + // 246: the street's heading toward the gate, which 03.06's + // to_zone_1_gate faces first. + .expectation = {.gate = ZoneGateSighting{.x = 0.486, .width = 0.150}, .heading = 246}, + }, + { + .name = "console: beside the zone's wall, the gate out of view (a walk's miss)", + .input = {.frame = []{ return console_frame("beside_wall_640.png"); }}, + .expectation = {.gate = std::nullopt}, + }, +}; + +class Test_ZoneGateFrame : public UnitTest{ +public: + explicit Test_ZoneGateFrame(const GateFrameCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - Zone gate reader: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const ImageRGB32 frame = m_test.input.frame(); + const std::optional gate = read_zone_gate(frame); + logger.log(describe(gate)); + const std::optional& want = m_test.expectation.gate; + const bool same = gate.has_value() == want.has_value() + && (!gate || (std::abs(gate->x - want->x) < 0.01 && std::abs(gate->width - want->width) < 0.02)); + if (!same){ + return std::format("Expected {}, read {}.", describe(want), describe(gate)); + } + if (m_test.expectation.heading){ + return check_heading(frame, *m_test.expectation.heading); + } + return true; + } + +private: + static UnitTestResult check_heading(const ImageRGB32& frame, double heading){ + DirectionArrowDetector arrow; + if (!arrow.detect(frame)){ + return "No minimap arrow."; + } + double off = std::abs(arrow.detected_angle_deg() - heading); + off = std::min(off, 360 - off); + if (off > 5){ + return std::format("Expected the heading {:.0f} +/- 5, read {:.1f}.", heading, arrow.detected_angle_deg()); + } + return true; + } + + const GateFrameCase& m_test; +}; + +} // namespace + + +void add_tests_AutoStoryZoneGateReader(UnitTestDatabase& database){ + for (const GateFrameCase& test : GATE_FRAME_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.h new file mode 100644 index 0000000000..549fdcba82 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.h @@ -0,0 +1,26 @@ +/* PokemonLZA AutoStory - Zone gate reader Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryZoneGateReader_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryZoneGateReader_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the zone gate reader's tests: synthetic frames, and console +// frames from CommandLineTests/PokemonLZA/AutoStoryDetectors/Zone1Gate/. +void add_tests_AutoStoryZoneGateReader(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp new file mode 100644 index 0000000000..009fb6eb96 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp @@ -0,0 +1,115 @@ +/* PokemonLZA AutoStory - Launch + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "CommonFramework/Language.h" +#include "Pokemon/AutoStory/Pokemon_StorySwitchPrompts.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_DialogDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h" +#include "PokemonLZA_AutoStoryLaunch.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; +using Pokemon::StoryLaunchPolicy; +using Pokemon::StoryLaunchPress; +using Pokemon::StoryLaunchPrompt; + + +namespace{ + +// The name HOME shows above the game's tile, in the console's language. +// A launch that took any tile opened FireRed once +// it had been played last and moved to the first tile. +constexpr std::string_view HOME_TILE_NAME = "Pokémon Legends: Z-A"; +constexpr Language HOME_LANGUAGE = Language::English; + +// Where the title's "use the backup save?" arrow shows (reset_game_from_home()). +const ImageFloatBox BACKUP_ARROW_BOX{0.2, 0.5, 0.6, 0.3}; + +// The game's own prompts on the way, read only after the launch: the +// backup save's arrow (A) and a dialog box (B). +std::vector plza_prompts(){ + auto arrow = std::make_shared(COLOR_BLUE, nullptr, SelectionArrowType::RIGHT, BACKUP_ARROW_BOX); + auto dialog = std::make_shared(COLOR_YELLOW); + return { + {.name = "backup save arrow", + .matches = [arrow](const ScreenObservation& look){ + return look.frame && look.frame->frame && arrow->detect(*look.frame->frame); + }, + .press = {.button = BUTTON_A, .hold = 160ms, .release = 240ms}, .after_launch = true}, + {.name = "dialog", + .matches = [dialog](const ScreenObservation& look){ + return look.frame && look.frame->frame && dialog->detect(*look.frame->frame); + }, + .press = {.button = BUTTON_B, .hold = 160ms, .release = 240ms}, .after_launch = true}, + }; +} + +} // namespace + + +// No INTERACT_PROMPT veto: the title's "PRESS (A) BUTTON" reads as one, +// and the overworld's prompts show with the party bar, which vetoes. +bool plza_title(const ScreenObservation& look){ + if (!look.frame || !look.frame->frame){ + return false; + } + for (ScreenEvent event : { + ScreenEvent::FADE_BLACK, ScreenEvent::FADE_WHITE, ScreenEvent::PLAYER_CAN_MOVE, + ScreenEvent::BATTLE_STARTED, + }){ + if (look.events.has(event)){ + return false; + } + } + return true; +} + +StoryLaunchPolicy plza_launch_policy(ConsoleHandle& console){ + StoryLaunchPolicy policy; + policy.game = "plza"; + policy.tile_selected = Pokemon::switch_home_tile_named(HOME_LANGUAGE, std::string(HOME_TILE_NAME)); + policy.title = plza_title; + policy.title_after_launch = true; + policy.title_press = {.button = BUTTON_A, .hold = 160ms, .release = 1000ms}; + // Up, B and X held together: Up first, then B + X, only shows the + // title again and its A loads the latest save. + // Held together they open the BACKUP card, whose "start from the + // backup" the title press then takes. + policy.backup_save = { + StoryLaunchPress{.button = BUTTON_UP | BUTTON_B | BUTTON_X, .hold = 1500ms, .release = 1500ms}, + }; + // The backup save's buttons only on the title's "PRESS (A) BUTTON", + // which reads as an A prompt: the boot's logos pass plza_title() too. + policy.backup_title = [](const ScreenObservation& look){ + return look.events.has(ScreenEvent::INTERACT_PROMPT) && plza_title(look); + }; + policy.prompts = Pokemon::switch_launch_prompts(console); + for (StoryLaunchPrompt& prompt : plza_prompts()){ + policy.prompts.push_back(std::move(prompt)); + } + // The title takes A through the boot's logos too, a second apart. + policy.presses_per_screen = 12; + // After the title's A, the load's black, then + // a tips screen (a blue band, a spinner) that plza_title() passes for + // 10 s and more. 30 looks of 500 ms or more: longer than the boot's + // 12 s black, which an A on a logo is followed by too. + policy.title_load_looks = 30; + return policy; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h new file mode 100644 index 0000000000..5910e560da --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h @@ -0,0 +1,40 @@ +/* PokemonLZA AutoStory - Launch + * + * From: https://github.com/PokemonAutomation/ + * + * How PLZA's screens look on the way from HOME to the overworld, for the + * shared launch (Pokemon/AutoStory/Engine/Pokemon_StoryLaunch.h). + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryLaunch_H +#define PokemonAutomation_PokemonLZA_AutoStoryLaunch_H + +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryLaunch.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Whether `look`, read after the launch, counts as PLZA's title: a frame +// that is not a fade, the overworld (the party bar) or a battle. An A +// prompt alone counts: the title's centred "PRESS (A) BUTTON" reads as one +//, and the overworld's prompts come with the +// party bar. +bool plza_title(const ScreenObservation& look); + +// PLZA on `console`: the Switch's prompts, then the game's own, as +// reset_game_from_home() answered them: the backup save's arrow takes A, +// a dialog box B. The title (plza_title()) takes A; the backup save is Up, +// B and X held together on it. No HOME tile reader yet: the tile +// under the cursor is taken as PLZA's, as reset_game_from_home() did. +Pokemon::StoryLaunchPolicy plza_launch_policy(ConsoleHandle& console); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.cpp new file mode 100644 index 0000000000..e6a1dcae28 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.cpp @@ -0,0 +1,64 @@ +/* PokemonLZA AutoStory - Start load + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonLZA_AutoStoryStartLoad.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +Pokemon::StoryLaunchRequest start_launch_request(StartSave save){ + using Pokemon::StoryLaunchRequest; + switch (save){ + case StartSave::LATEST: + return {.save = StoryLaunchRequest::Save::LATEST, .running = StoryLaunchRequest::Running::RESTART}; + case StartSave::BACKUP: + return {.save = StoryLaunchRequest::Save::BACKUP, .running = StoryLaunchRequest::Running::RESTART}; + case StartSave::RUNNING: + return {.save = StoryLaunchRequest::Save::LATEST, .running = StoryLaunchRequest::Running::KEEP}; + } + return {}; +} + +StartLoadAction next_start_load_action(StartFrom from, std::span loads){ + if (loads.empty()){ + switch (from){ + case StartFrom::LATEST_SAVE: + return StartLoadAction::LOAD_LATEST; + case StartFrom::BACKUP_SAVE: + return StartLoadAction::LOAD_BACKUP; + case StartFrom::RUNNING_GAME: + return StartLoadAction::RESUME; + } + return StartLoadAction::STOP; + } + const StartLoad& last = loads.back(); + if (!last.at_start || *last.at_start){ + const bool after_latest_failed = loads.size() >= 2 && loads[loads.size() - 2].save == StartSave::LATEST; + if (last.save == StartSave::BACKUP && last.at_start && after_latest_failed){ + return StartLoadAction::REPORT_THEN_START; + } + return StartLoadAction::START; + } + if (last.save == StartSave::LATEST){ + return StartLoadAction::LOAD_BACKUP; + } + return StartLoadAction::STOP; +} + +std::optional checkpoint_start_sign(std::string_view row){ + if (row == "03.06"){ + return StartSign{.event = ScreenEvent::INTERACT_PROMPT, .place = "the Pokemon Center counter"}; + } + return std::nullopt; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.h new file mode 100644 index 0000000000..b70ff39012 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.h @@ -0,0 +1,96 @@ +/* PokemonLZA AutoStory - Start load + * + * From: https://github.com/PokemonAutomation/ + * + * Which save a run loads to reach its first checkpoint's start: the + * latest, or the backup save when the game autosaved past the start; or + * none, the game kept as it runs. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryStartLoad_H +#define PokemonAutomation_PokemonLZA_AutoStoryStartLoad_H + +#include +#include +#include +#include "CommonTools/ScreenEvents/ScreenEventTypes.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryLaunch.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The save a load brings back: the latest, or the backup save (the title +// screen's Up + B + X: the one before the latest); RUNNING loads none, +// the game is kept as it runs, resumed from HOME if need be. +enum class StartSave{ + LATEST, + BACKUP, + RUNNING, +}; + +// The shared launch's request for `save`: LATEST and BACKUP close a +// running game and load that save; RUNNING keeps a game on the overworld. +Pokemon::StoryLaunchRequest start_launch_request(StartSave save); + +// Where a run takes its first checkpoint's start from, as the user set it. +enum class StartFrom{ + // The latest save, then the backup save when the latest is past the + // start. + LATEST_SAVE, + // The backup save only (START_FROM_BACKUP_SAVE). + BACKUP_SAVE, + // The game as it runs, no reload (RELOAD_AT_START off). + RUNNING_GAME, +}; + +// One load of a run's start save and its start check: whether the game +// showed the checkpoint's start; nothing when the checkpoint has no check. +struct StartLoad{ + StartSave save = StartSave::LATEST; + std::optional at_start; +}; + +// What a run does next while loading its start. +enum class StartLoadAction{ + LOAD_LATEST, + LOAD_BACKUP, + // Keep the running game (StartSave::RUNNING). + RESUME, + START, + // Save with the menu's Report, then start: the latest save is the + // start again, so the next run of the checkpoint loads it. + REPORT_THEN_START, + STOP, +}; + +// The next action after `loads`: the save `from` names first (RESUME for +// RUNNING_GAME), then the backup save when the latest's start check +// failed (the game autosaved past the start: catches, heals), and STOP +// when the last load's check failed otherwise: a kept game is never +// reloaded. START after a load whose check passed or that has no check, +// REPORT_THEN_START when that load is the backup save after the latest's +// check failed. Never a save without a passed check: no save from an +// unknown spot. +StartLoadAction next_start_load_action(StartFrom from, std::span loads); + +// What a checkpoint's start check looks for: the screen event its start +// shows, and the place that puts the player at, for the log. +struct StartSign{ + ScreenEvent event; + std::string_view place; +}; + +// `row`'s start sign; nothing when `row` has no start check. 03.06 +// starts at the Pokemon Center counter, facing the nurse: her "A" talk +// prompt shows. +std::optional checkpoint_start_sign(std::string_view row); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.cpp new file mode 100644 index 0000000000..7ffaa560e3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.cpp @@ -0,0 +1,222 @@ +/* PokemonLZA AutoStory - Start load Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonLZA_AutoStoryStartLoad.h" +#include "PokemonLZA_AutoStoryStartLoad_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +namespace{ + + +// next_start_load_action(): the loads a run makes before its first +// checkpoint, from the start checks each load gives. +struct StartLoadCase{ + std::string name; + struct Input{ + StartFrom from; + // The start check after each load, in order; nothing: no check. + std::vector> checks; + }; + Input input; + struct Expectation{ + std::vector actions; + }; + Expectation expectation; +}; + +using enum StartLoadAction; + +const StartLoadCase START_LOAD_CASES[] = { + {.name = "the latest save at the start: start", .input = {.from = StartFrom::LATEST_SAVE, .checks = {true}}, .expectation = {.actions = {LOAD_LATEST, START}}}, + {.name = "no start check: start from the latest save", .input = {.from = StartFrom::LATEST_SAVE, .checks = {std::nullopt}}, .expectation = {.actions = {LOAD_LATEST, START}}}, + // A catch in 03.08 autosaved in zone 1; the + // backup was the run's start, and the Report makes it the latest again. + {.name = "the latest save past the start, the backup at it: save, then start", .input = {.from = StartFrom::LATEST_SAVE, .checks = {false, true}}, .expectation = {.actions = {LOAD_LATEST, LOAD_BACKUP, REPORT_THEN_START}}}, + {.name = "the latest save past the start, the backup with no check: start, no save", .input = {.from = StartFrom::LATEST_SAVE, .checks = {false, std::nullopt}}, .expectation = {.actions = {LOAD_LATEST, LOAD_BACKUP, START}}}, + {.name = "neither save at the start: stop", .input = {.from = StartFrom::LATEST_SAVE, .checks = {false, false}}, .expectation = {.actions = {LOAD_LATEST, LOAD_BACKUP, STOP}}}, + {.name = "backup first, at the start: start", .input = {.from = StartFrom::BACKUP_SAVE, .checks = {true}}, .expectation = {.actions = {LOAD_BACKUP, START}}}, + {.name = "backup first, not at the start: stop", .input = {.from = StartFrom::BACKUP_SAVE, .checks = {false}}, .expectation = {.actions = {LOAD_BACKUP, STOP}}}, + // The game already at the run's start, the + // Pokemon Center counter; RELOAD_AT_START off keeps it. + {.name = "running game at the start: start", .input = {.from = StartFrom::RUNNING_GAME, .checks = {true}}, .expectation = {.actions = {RESUME, START}}}, + {.name = "running game, no start check: start", .input = {.from = StartFrom::RUNNING_GAME, .checks = {std::nullopt}}, .expectation = {.actions = {RESUME, START}}}, + {.name = "running game not at the start: stop, no reload", .input = {.from = StartFrom::RUNNING_GAME, .checks = {false}}, .expectation = {.actions = {RESUME, STOP}}}, +}; + +std::string_view action_name(StartLoadAction action){ + switch (action){ + case LOAD_LATEST: + return "load latest"; + case LOAD_BACKUP: + return "load backup"; + case RESUME: + return "resume"; + case START: + return "start"; + case REPORT_THEN_START: + return "report, then start"; + case STOP: + return "stop"; + } + return "?"; +} + +std::string action_names(const std::vector& actions){ + std::string out; + for (StartLoadAction action : actions){ + out += std::format("{}{}", out.empty() ? "" : ", ", action_name(action)); + } + return out; +} + +class Test_StartLoad : public UnitTest{ +public: + explicit Test_StartLoad(const StartLoadCase& test_case) + : UnitTest(std::format("PokemonLZA::AutoStoryEngine - start load: {}", test_case.name)) + , m_case(test_case) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + std::vector loads; + std::vector actions; + while (actions.size() < 5){ + const StartLoadAction action = next_start_load_action(m_case.input.from, loads); + actions.push_back(action); + if (action == START || action == REPORT_THEN_START || action == STOP){ + break; + } + if (loads.size() >= m_case.input.checks.size()){ + return std::format("Loaded more than the {} checks given: {}.", m_case.input.checks.size(), action_names(actions)); + } + const StartSave save = action == LOAD_BACKUP ? StartSave::BACKUP : action == RESUME ? StartSave::RUNNING : StartSave::LATEST; + loads.push_back({.save = save, .at_start = m_case.input.checks[loads.size()]}); + } + if (actions != m_case.expectation.actions){ + return std::format("Expected [{}], got [{}].", action_names(m_case.expectation.actions), action_names(actions)); + } + return true; + } + +private: + const StartLoadCase& m_case; +}; + + +// start_launch_request(): what the shared launch does for each start +// save. Only RUNNING keeps the game: RELOAD_AT_START off. +struct StartLaunchCase{ + std::string name; + struct Input{ + StartSave save; + }; + Input input; + struct Expectation{ + Pokemon::StoryLaunchRequest::Save save; + Pokemon::StoryLaunchRequest::Running running; + }; + Expectation expectation; +}; + +const StartLaunchCase START_LAUNCH_CASES[] = { + {.name = "the latest save restarts", .input = {.save = StartSave::LATEST}, + .expectation = {.save = Pokemon::StoryLaunchRequest::Save::LATEST, .running = Pokemon::StoryLaunchRequest::Running::RESTART}}, + {.name = "the backup save restarts", .input = {.save = StartSave::BACKUP}, + .expectation = {.save = Pokemon::StoryLaunchRequest::Save::BACKUP, .running = Pokemon::StoryLaunchRequest::Running::RESTART}}, + {.name = "the running game is kept", .input = {.save = StartSave::RUNNING}, + .expectation = {.save = Pokemon::StoryLaunchRequest::Save::LATEST, .running = Pokemon::StoryLaunchRequest::Running::KEEP}}, +}; + +class Test_StartLaunch : public UnitTest{ +public: + explicit Test_StartLaunch(const StartLaunchCase& test_case) + : UnitTest(std::format("PokemonLZA::AutoStoryEngine - start launch: {}", test_case.name)) + , m_case(test_case) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const Pokemon::StoryLaunchRequest request = start_launch_request(m_case.input.save); + if (request.save != m_case.expectation.save || request.running != m_case.expectation.running){ + return "Unexpected launch request."; + } + return true; + } + +private: + const StartLaunchCase& m_case; +}; + +// checkpoint_start_sign(): what each checkpoint's start check looks for. +// 03.06 starts at the Pokemon Center counter; 03.08 has no check. +struct StartSignCase{ + std::string name; + struct Input{ + std::string row; + }; + Input input; + struct Expectation{ + std::optional event; + }; + Expectation expectation; +}; + +const StartSignCase START_SIGN_CASES[] = { + {.name = "03.06 starts at the counter", .input = {.row = "03.06"}, .expectation = {.event = ScreenEvent::INTERACT_PROMPT}}, + {.name = "03.08 has no start check", .input = {.row = "03.08"}, .expectation = {.event = std::nullopt}}, +}; + +class Test_StartSign : public UnitTest{ +public: + explicit Test_StartSign(const StartSignCase& test_case) + : UnitTest(std::format("PokemonLZA::AutoStoryEngine - start sign: {}", test_case.name)) + , m_case(test_case) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::optional sign = checkpoint_start_sign(m_case.input.row); + const std::optional event = sign ? std::optional(sign->event) : std::nullopt; + if (event != m_case.expectation.event){ + return std::format("Expected {}, got {}.", + m_case.expectation.event ? screen_event_name(*m_case.expectation.event) : "no check", + event ? screen_event_name(*event) : "no check" + ); + } + if (sign && sign->place.empty()){ + return "The sign names no place for the log."; + } + return true; + } + +private: + const StartSignCase& m_case; +}; + + +} // namespace + + +void add_tests_AutoStoryStartLoad(UnitTestDatabase& database){ + for (const StartLoadCase& item : START_LOAD_CASES){ + database.add(item); + } + for (const StartLaunchCase& item : START_LAUNCH_CASES){ + database.add(item); + } + for (const StartSignCase& item : START_SIGN_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.h new file mode 100644 index 0000000000..5725c57dc9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.h @@ -0,0 +1,26 @@ +/* PokemonLZA AutoStory - Start load Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryStartLoad_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryStartLoad_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The loads a run makes before its first checkpoint and the shared +// launch's request for each: no console. +void add_tests_AutoStoryStartLoad(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index f1bf515b81..a67b8db299 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2400,10 +2400,14 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/PokemonLZA_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -2450,17 +2454,27 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryFailures.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryFailures.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryFailures_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h Source/VideoGames/PokemonLZA/Programs/Farming/PokemonLZA_DonutMaker.cpp From edf57e282288b2bd5d469b2732be5d547fefb43b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 12:27:08 -0800 Subject: [PATCH 2/2] PokemonLZA AutoStory: drop the shared-launch policy reset_game_from_home() answers the backup save's arrow and the dialogs itself. StartLoad keeps StartSave. --- .../AutoStory/PokemonLZA_AutoStoryLaunch.cpp | 115 ------------------ .../AutoStory/PokemonLZA_AutoStoryLaunch.h | 40 ------ .../PokemonLZA_AutoStoryStartLoad.cpp | 12 -- .../AutoStory/PokemonLZA_AutoStoryStartLoad.h | 5 +- .../PokemonLZA_AutoStoryStartLoad_Tests.cpp | 45 ------- SerialPrograms/cmake/SourceFiles.cmake | 2 - 6 files changed, 1 insertion(+), 218 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp deleted file mode 100644 index 009fb6eb96..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* PokemonLZA AutoStory - Launch - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include -#include -#include "CommonFramework/Language.h" -#include "Pokemon/AutoStory/Pokemon_StorySwitchPrompts.h" -#include "VideoGames/PokemonLZA/Inference/PokemonLZA_DialogDetector.h" -#include "VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h" -#include "PokemonLZA_AutoStoryLaunch.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - -using namespace std::chrono_literals; -using Pokemon::StoryLaunchPolicy; -using Pokemon::StoryLaunchPress; -using Pokemon::StoryLaunchPrompt; - - -namespace{ - -// The name HOME shows above the game's tile, in the console's language. -// A launch that took any tile opened FireRed once -// it had been played last and moved to the first tile. -constexpr std::string_view HOME_TILE_NAME = "Pokémon Legends: Z-A"; -constexpr Language HOME_LANGUAGE = Language::English; - -// Where the title's "use the backup save?" arrow shows (reset_game_from_home()). -const ImageFloatBox BACKUP_ARROW_BOX{0.2, 0.5, 0.6, 0.3}; - -// The game's own prompts on the way, read only after the launch: the -// backup save's arrow (A) and a dialog box (B). -std::vector plza_prompts(){ - auto arrow = std::make_shared(COLOR_BLUE, nullptr, SelectionArrowType::RIGHT, BACKUP_ARROW_BOX); - auto dialog = std::make_shared(COLOR_YELLOW); - return { - {.name = "backup save arrow", - .matches = [arrow](const ScreenObservation& look){ - return look.frame && look.frame->frame && arrow->detect(*look.frame->frame); - }, - .press = {.button = BUTTON_A, .hold = 160ms, .release = 240ms}, .after_launch = true}, - {.name = "dialog", - .matches = [dialog](const ScreenObservation& look){ - return look.frame && look.frame->frame && dialog->detect(*look.frame->frame); - }, - .press = {.button = BUTTON_B, .hold = 160ms, .release = 240ms}, .after_launch = true}, - }; -} - -} // namespace - - -// No INTERACT_PROMPT veto: the title's "PRESS (A) BUTTON" reads as one, -// and the overworld's prompts show with the party bar, which vetoes. -bool plza_title(const ScreenObservation& look){ - if (!look.frame || !look.frame->frame){ - return false; - } - for (ScreenEvent event : { - ScreenEvent::FADE_BLACK, ScreenEvent::FADE_WHITE, ScreenEvent::PLAYER_CAN_MOVE, - ScreenEvent::BATTLE_STARTED, - }){ - if (look.events.has(event)){ - return false; - } - } - return true; -} - -StoryLaunchPolicy plza_launch_policy(ConsoleHandle& console){ - StoryLaunchPolicy policy; - policy.game = "plza"; - policy.tile_selected = Pokemon::switch_home_tile_named(HOME_LANGUAGE, std::string(HOME_TILE_NAME)); - policy.title = plza_title; - policy.title_after_launch = true; - policy.title_press = {.button = BUTTON_A, .hold = 160ms, .release = 1000ms}; - // Up, B and X held together: Up first, then B + X, only shows the - // title again and its A loads the latest save. - // Held together they open the BACKUP card, whose "start from the - // backup" the title press then takes. - policy.backup_save = { - StoryLaunchPress{.button = BUTTON_UP | BUTTON_B | BUTTON_X, .hold = 1500ms, .release = 1500ms}, - }; - // The backup save's buttons only on the title's "PRESS (A) BUTTON", - // which reads as an A prompt: the boot's logos pass plza_title() too. - policy.backup_title = [](const ScreenObservation& look){ - return look.events.has(ScreenEvent::INTERACT_PROMPT) && plza_title(look); - }; - policy.prompts = Pokemon::switch_launch_prompts(console); - for (StoryLaunchPrompt& prompt : plza_prompts()){ - policy.prompts.push_back(std::move(prompt)); - } - // The title takes A through the boot's logos too, a second apart. - policy.presses_per_screen = 12; - // After the title's A, the load's black, then - // a tips screen (a blue band, a spinner) that plza_title() passes for - // 10 s and more. 30 looks of 500 ms or more: longer than the boot's - // 12 s black, which an A on a logo is followed by too. - policy.title_load_looks = 30; - return policy; -} - - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h deleted file mode 100644 index 5910e560da..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h +++ /dev/null @@ -1,40 +0,0 @@ -/* PokemonLZA AutoStory - Launch - * - * From: https://github.com/PokemonAutomation/ - * - * How PLZA's screens look on the way from HOME to the overworld, for the - * shared launch (Pokemon/AutoStory/Engine/Pokemon_StoryLaunch.h). - * - */ - -#ifndef PokemonAutomation_PokemonLZA_AutoStoryLaunch_H -#define PokemonAutomation_PokemonLZA_AutoStoryLaunch_H - -#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" -#include "Pokemon/AutoStory/Engine/Pokemon_StoryLaunch.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -// Whether `look`, read after the launch, counts as PLZA's title: a frame -// that is not a fade, the overworld (the party bar) or a battle. An A -// prompt alone counts: the title's centred "PRESS (A) BUTTON" reads as one -//, and the overworld's prompts come with the -// party bar. -bool plza_title(const ScreenObservation& look); - -// PLZA on `console`: the Switch's prompts, then the game's own, as -// reset_game_from_home() answered them: the backup save's arrow takes A, -// a dialog box B. The title (plza_title()) takes A; the backup save is Up, -// B and X held together on it. No HOME tile reader yet: the tile -// under the cursor is taken as PLZA's, as reset_game_from_home() did. -Pokemon::StoryLaunchPolicy plza_launch_policy(ConsoleHandle& console); - - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.cpp index e6a1dcae28..fe10de8a2a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.cpp @@ -11,18 +11,6 @@ namespace NintendoSwitch{ namespace PokemonLZA{ -Pokemon::StoryLaunchRequest start_launch_request(StartSave save){ - using Pokemon::StoryLaunchRequest; - switch (save){ - case StartSave::LATEST: - return {.save = StoryLaunchRequest::Save::LATEST, .running = StoryLaunchRequest::Running::RESTART}; - case StartSave::BACKUP: - return {.save = StoryLaunchRequest::Save::BACKUP, .running = StoryLaunchRequest::Running::RESTART}; - case StartSave::RUNNING: - return {.save = StoryLaunchRequest::Save::LATEST, .running = StoryLaunchRequest::Running::KEEP}; - } - return {}; -} StartLoadAction next_start_load_action(StartFrom from, std::span loads){ if (loads.empty()){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.h index b70ff39012..5578912afd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad.h @@ -15,7 +15,7 @@ #include #include #include "CommonTools/ScreenEvents/ScreenEventTypes.h" -#include "Pokemon/AutoStory/Engine/Pokemon_StoryLaunch.h" + namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -31,9 +31,6 @@ enum class StartSave{ RUNNING, }; -// The shared launch's request for `save`: LATEST and BACKUP close a -// running game and load that save; RUNNING keeps a game on the overworld. -Pokemon::StoryLaunchRequest start_launch_request(StartSave save); // Where a run takes its first checkpoint's start from, as the user set it. enum class StartFrom{ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.cpp index 7ffaa560e3..8579dd1665 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStartLoad_Tests.cpp @@ -113,48 +113,6 @@ class Test_StartLoad : public UnitTest{ }; -// start_launch_request(): what the shared launch does for each start -// save. Only RUNNING keeps the game: RELOAD_AT_START off. -struct StartLaunchCase{ - std::string name; - struct Input{ - StartSave save; - }; - Input input; - struct Expectation{ - Pokemon::StoryLaunchRequest::Save save; - Pokemon::StoryLaunchRequest::Running running; - }; - Expectation expectation; -}; - -const StartLaunchCase START_LAUNCH_CASES[] = { - {.name = "the latest save restarts", .input = {.save = StartSave::LATEST}, - .expectation = {.save = Pokemon::StoryLaunchRequest::Save::LATEST, .running = Pokemon::StoryLaunchRequest::Running::RESTART}}, - {.name = "the backup save restarts", .input = {.save = StartSave::BACKUP}, - .expectation = {.save = Pokemon::StoryLaunchRequest::Save::BACKUP, .running = Pokemon::StoryLaunchRequest::Running::RESTART}}, - {.name = "the running game is kept", .input = {.save = StartSave::RUNNING}, - .expectation = {.save = Pokemon::StoryLaunchRequest::Save::LATEST, .running = Pokemon::StoryLaunchRequest::Running::KEEP}}, -}; - -class Test_StartLaunch : public UnitTest{ -public: - explicit Test_StartLaunch(const StartLaunchCase& test_case) - : UnitTest(std::format("PokemonLZA::AutoStoryEngine - start launch: {}", test_case.name)) - , m_case(test_case) - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const Pokemon::StoryLaunchRequest request = start_launch_request(m_case.input.save); - if (request.save != m_case.expectation.save || request.running != m_case.expectation.running){ - return "Unexpected launch request."; - } - return true; - } - -private: - const StartLaunchCase& m_case; -}; - // checkpoint_start_sign(): what each checkpoint's start check looks for. // 03.06 starts at the Pokemon Center counter; 03.08 has no check. struct StartSignCase{ @@ -207,9 +165,6 @@ void add_tests_AutoStoryStartLoad(UnitTestDatabase& database){ for (const StartLoadCase& item : START_LOAD_CASES){ database.add(item); } - for (const StartLaunchCase& item : START_LAUNCH_CASES){ - database.add(item); - } for (const StartSignCase& item : START_SIGN_CASES){ database.add(item); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index a202eb049a..4e10e968b9 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2447,8 +2447,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryFailures.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryFailures.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryFailures_Tests.cpp - Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.cpp - Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryLaunch.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h