Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
1ce0b56
PokemonLZA: AutoStory: the program, engine glue, detectors and the ne…
dayfine Nov 11, 2026
aae4fd3
Merge origin/autostory/engine into plza/story-base
dayfine Nov 11, 2026
cd4e9a4
PokemonLZA: AutoStory: tutorial cards in mash_scene, A for late choices
dayfine Nov 11, 2026
39649d4
Merge remote-tracking branch 'origin/autostory/declared-pose' into pl…
dayfine Nov 11, 2026
36bd9a0
PokemonLZA: AutoStory: walk legs are TIMED_LEGS, fly takes a place
dayfine Nov 11, 2026
7f3b02f
Merge remote-tracking branch 'origin/autostory/engine' into plza/stor…
dayfine Nov 11, 2026
bb25ca7
Merge autostory/engine into plza/story-base
dayfine Nov 11, 2026
3a1338a
Merge origin/autostory/engine into plza/story-base
dayfine Nov 12, 2026
7f72a5d
Merge remote-tracking branch 'origin/plza/story-detectors' into plza/…
dayfine Nov 12, 2026
c5c608f
PokemonLZA: AutoStory: use shared Pokemon::describe() for scene event…
dayfine Nov 12, 2026
b546f13
Merge branch 'plza/story-detectors' into plza/story-base
dayfine Nov 12, 2026
01a8725
PokemonLZA: AutoStory: use shared screen_observation(), describe(), s…
dayfine Nov 12, 2026
edc9f21
Merge branch 'plza/story-detectors' into plza/story-base
dayfine Nov 12, 2026
a952ccd
Merge branch 'plza/story-detectors' into plza/story-base
dayfine Nov 12, 2026
2eaa048
Merge remote-tracking branch 'origin/plza/story-detectors' into plza/…
dayfine Nov 12, 2026
8592dde
PokemonLZA AutoStory: rename AutoStoryObservation.h to AutoStoryReadi…
dayfine Nov 12, 2026
4fc14a0
Merge branch 'plza/story-detectors' into plza/story-base
dayfine Nov 12, 2026
5e0cdc6
Merge origin/plza/story-detectors into plza/story-base
dayfine Nov 12, 2026
a0143f5
PokemonLZA: AutoStory: new game language, look and name from options …
dayfine Nov 13, 2026
756e463
PokemonLZA: AutoStory: new game presses for the language, look and name
dayfine Nov 13, 2026
7699354
Merge remote-tracking branch 'origin/plza/story-detectors' into plza/…
dayfine Nov 13, 2026
e0bdeb3
PokemonLZA: AutoStory: launch from HOME and read the 2x5 language list
dayfine Nov 13, 2026
222b16e
Merge remote-tracking branch 'origin/switch/system-keyboard' into plz…
dayfine Nov 13, 2026
91fbcb7
PokemonLZA: AutoStory: launch the selected HOME tile; name on the sys…
dayfine Nov 13, 2026
9196de3
PokemonLZA: AutoStory: launch presses HOME once when a game is in front
dayfine Nov 13, 2026
7928e99
PokemonLZA: AutoStory: a run from 01.00 checks the black border on HOME
dayfine Nov 13, 2026
187aa09
PokemonLZA: AutoStory: read the look picker's highlight; A at the ope…
dayfine Nov 13, 2026
0ecbeb5
Merge branch 'plza/story-detectors' into plza/story-base
dayfine Nov 13, 2026
1a7c2a6
Merge remote-tracking branch 'origin/switch/system-keyboard' into plz…
dayfine Nov 13, 2026
a669bd9
Merge branch 'plza/story-detectors' into plza/story-base
dayfine Nov 13, 2026
3f7b01d
PokemonLZA AutoStory: the new game from HOME is 00.00; 01.00 starts o…
dayfine Nov 13, 2026
55ea0b0
PokemonLZA AutoStory: 01.00's Confirm Choices step in its own file
dayfine Nov 13, 2026
0a600e5
PokemonLZA AutoStory: Confirm Choices reads row 1 through the highlig…
dayfine Nov 13, 2026
3d3725f
PokemonLZA AutoStory: read the look picker's highlight by its card's …
dayfine Nov 13, 2026
43279c4
PokemonLZA AutoStory: reload the save at a checkpoint marked reload_w…
dayfine Nov 13, 2026
e79ff9f
PokemonLZA AutoStory: name reload_when_chained when it is not a boolean
dayfine Nov 13, 2026
8bf0063
PokemonLZA AutoStory: a scene step fails when its scene never starts
dayfine Nov 13, 2026
b6dd087
PokemonLZA AutoStory: walk_to_prompt walks straight on until an A pro…
dayfine Nov 13, 2026
39592b5
Merge remote-tracking branch 'origin/plza/story-detectors' into HEAD
dayfine Nov 13, 2026
f67228a
Merge origin/plza/story-detectors into plza/story-base: #45 review fixes
dayfine Nov 13, 2026
9be7edd
Merge remote-tracking branch 'origin/autostory/story-breakpoints' int…
dayfine Nov 13, 2026
83edab2
PLZA AutoStory: breakpoints before each step and walk leg
dayfine Nov 13, 2026
375cd86
Merge origin/plza/story-detectors into plza/story-base: #45 review fixes
dayfine Nov 13, 2026
b18b8cf
Merge origin/plza/story-detectors into plza/story-base: shared checkp…
dayfine Nov 13, 2026
8ebd5b0
PLZA AutoStory: Reload at Checkpoint Boundaries option, off by default
dayfine Nov 13, 2026
368c619
PLZA AutoStory: run_plza_segment takes a StoryRunPolicy
dayfine Nov 13, 2026
343a966
PLZA AutoStory: send the story log lines to the video overlay
dayfine Nov 13, 2026
9bfb515
Merge origin/plza/story-detectors into plza/story-base
dayfine Nov 13, 2026
d521a36
Merge origin/plza/story-detectors into plza/story-base
dayfine Nov 13, 2026
fe39da8
Merge origin/plza/story-detectors into plza/story-base
dayfine Nov 13, 2026
8548aa7
Merge origin/plza/story-detectors into plza/story-base: shared Screen…
dayfine Nov 14, 2026
0706b4b
Use the shared ScreenEvent names after merging autostory/engine
dayfine Nov 14, 2026
473e0a4
Merge plza/story-detectors into plza/story-base
dayfine Nov 14, 2026
f4fcb71
PokemonLZA: AutoStory: drop the new game intro picks and 00.00
dayfine Nov 14, 2026
9af276b
PokemonLZA: AutoStory: screen readers live in Detectors/
dayfine Nov 14, 2026
fa94e56
PokemonLZA: AutoStory: required Game Language option, as SV AutoStory's
dayfine Nov 14, 2026
b03ad1d
PokemonLZA: AutoStory: describe the hand-picked new game start
dayfine Nov 14, 2026
7576b39
Merge plza/story-detectors (#416) into plza/story-base
dayfine Nov 14, 2026
afb8b3c
PokemonLZA: AutoStory: Confirm Choices reader tests as case tables
dayfine Nov 14, 2026
8ba4d87
PokemonLZA: AutoStory: test cases keep the name outside the input
dayfine Nov 14, 2026
8545388
PokemonLZA: AutoStory: one field per line in the multi-line test cases
dayfine Nov 14, 2026
212bca0
Merge plza/story-detectors into plza/story-base
dayfine Nov 14, 2026
fcb1074
Merge origin/plza/story-detectors into plza/story-base
dayfine Nov 14, 2026
014fd6e
Merge origin/plza/story-detectors into plza/story-base
dayfine Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ add_library(SerialProgramsLib STATIC ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES})
include(cmake/EmbedTextFiles.cmake)
pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps
Pokemon/Navigation/Pokemon_NavigationTestMaps.h PokemonAutomation::Pokemon navigation_test_map_json)
pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData
VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h PokemonAutomation::NintendoSwitch::PokemonLZA autostory_checkpoint_json)
pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonLZA/Programs/AutoStory/ReferenceData
VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h PokemonAutomation::NintendoSwitch::PokemonLZA autostory_reference_json)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "Programs/TestPrograms/PokemonLZA_MoveBoxArrow.h"
#include "Programs/TestPrograms/PokemonLZA_TestBoxCellInfo.h"
#include "InferenceTraining/PokemonLZA_GenerateLocationNameOCR.h"
#include "Programs/AutoStory/PokemonLZA_AutoStory.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -68,6 +69,7 @@ PanelListFactory::PanelListFactory()
)
{}

// code-health: allow function_lines -- the list reads top to bottom as the program menu does; splitting it by section hides that order
std::vector<PanelEntry> PanelListFactory::make_panels() const{
std::vector<PanelEntry> ret;

Expand Down Expand Up @@ -121,6 +123,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{

ret.emplace_back("---- Public Betas ----");
ret.emplace_back(make_SingleSwitchProgram<StatsReset>());
ret.emplace_back(make_SingleSwitchProgram<AutoStory>());

if (STATIC_GLOBALS.DEVELOPER_MODE){
ret.emplace_back("---- Developer Tools ----");
Expand Down
10 changes: 10 additions & 0 deletions SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
#include "Inference/Map/PokemonLZA_MapIconDetector.h"
#include "Inference/PokemonLZA_OverworldPartySelectionDetector.h"
#include "Inference/PokemonLZA_SelectionArrowDetector.h"
#include "Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h"
#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h"
#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h"
#include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h"
#include "Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h"
#include "Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -42,7 +47,12 @@ void add_tests(UnitTestDatabase& database){
add_tests_MapIconDetector(database);
add_tests_OverworldPartySelectionDetector(database);
add_tests_SelectionArrowDetector(database);
add_tests_AutoStory_StoryTable(database);
add_tests_AutoStoryScreenEvents(database);
add_tests_AutoStoryDetectors(database);
add_tests_AutoStoryConfirmChoicesReader(database);
add_tests_AutoStorySceneMachine(database);
add_tests_AutoStoryEngine(database);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/* PokemonLZA AutoStory - Actions
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <utility>
#include "Common/Cpp/Color.h"
#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
#include "CommonTools/Async/InferenceRoutines.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "VideoGames/PokemonLZA/Inference/Battles/PokemonLZA_RunFromBattleDetector.h"
#include "VideoGames/PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
#include "VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h"
#include "VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h"
#include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h"
#include "VideoGames/PokemonLZA/Programs/PokemonLZA_TrainerBattle.h"
#include "PokemonLZA_AutoStoryActions.h"
#include "PokemonLZA_AutoStoryDialogs.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{

using namespace std::chrono_literals;


StoryActionNotImplemented::StoryActionNotImplemented(std::string message)
: OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, std::move(message))
{}


void fight_battle(

Check warning on line 36 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::fight_battle( ProgramEnvironment & env , ConsoleHandle & console , ProControllerContext & context , BattleAIOption & battle_ai): function_lines=41 (advisory above 25, limit 50)
ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context,
BattleAIOption& battle_ai
){
RunFromBattleWatcher battle_menu(COLOR_GREEN, &console.overlay(), 10ms);
OverworldPartySelectionWatcher overworld(COLOR_WHITE, &console.overlay(), 100ms);
TrainerBattleState battle_state(battle_ai);
// The battle's text first: the overworld only ends it once it has
// begun, and it must begin within a minute.
const WallClock start_deadline = current_time() + 60s;
bool started = false;
while (true){
context.wait_for_all_requests();
const int ret = run_until<ProControllerContext>(
console, context,
[](ProControllerContext& context){
pbf_mash_button(context, BUTTON_B, 120s);
},
{battle_menu, overworld}
);
if (ret == 0){
started = true;
if (!battle_state.attempt_one_attack(env, console, context)){
pbf_press_button(context, BUTTON_UP, 500ms, 1000ms);
}
continue;
}
if (ret == 1 && started){
return;
}
if (ret < 0 || current_time() > start_deadline){
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT,
"fight_battle(): no battle began within a minute, or its menu was gone for two.",
console
);
}
// The overworld before the battle: its text has not started it yet.
context.wait_for(500ms);
}
}



void fight_battle_in_progress(
ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context,
BattleAIOption& battle_ai, std::chrono::seconds timeout
){
TrainerBattleState battle_state(battle_ai);
FlatWhiteDialogDetector white_dialog;
BlueDialogDetector blue_dialog;
TealDialogDetector teal_dialog;
const WallClock deadline = current_time() + timeout;
while (true){
context.wait_for_all_requests();
const VideoSnapshot screen = console.video().snapshot();
if (white_dialog.detect(screen) || blue_dialog.detect(screen) || teal_dialog.detect(screen)){
return;
}
if (current_time() > deadline){
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT,
"fight_battle_in_progress(): no dialog after the battle within the timeout.",
console
);
}
battle_state.attempt_one_attack(env, console, context);
}
}



namespace{

// Whether the report page's Save button (its cursor arrow, where
// save_game_to_menu() looks for it) shows within `timeout`.
bool save_button_shows(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){
SelectionArrowWatcher save_button(
COLOR_GREEN, &console.overlay(), SelectionArrowType::RIGHT, {0.287118, 0.638835, 0.064410, 0.108738}
);
return wait_until(console, context, timeout, {save_button}) == 0;
}

// From the overworld: X opens the menu, R its report page. The first menu
// of a playthrough opens under a save tutorial card that A closes, leaving
// the menu with the cursor on the Bag (console B, 2026-11-10); R does
// nothing over the card. So when R does not bring up the Save button, A
// once, then R again. A is never pressed on the plain menu, where it
// would open the Bag.
void open_save_report(ConsoleHandle& console, ProControllerContext& context){
pbf_press_button(context, BUTTON_X, 160ms, 2340ms);
pbf_press_button(context, BUTTON_R, 160ms, 240ms);
if (save_button_shows(console, context, 5s)){
return;
}
console.log("save_story_game(): no Save button after R: the menu's tutorial card; pressing A, then R.");
pbf_press_button(context, BUTTON_A, 160ms, 1340ms);
pbf_press_button(context, BUTTON_R, 160ms, 240ms);
if (!save_button_shows(console, context, 5s)){
console.log("save_story_game(): still no Save button; save_game_to_menu() takes over.", COLOR_RED);
}
}

// save_game_to_menu(), its failures as false.
bool try_save(ConsoleHandle& console, ProControllerContext& context){
try{
return save_game_to_menu(console, context);
}catch (OperationFailedException& e){
console.log(std::format("save_story_game(): {}", e.message()), COLOR_RED);
return false;
}
}

} // namespace

// Opens the report page (open_save_report(), for the first menu's
// tutorial), then save_game_to_menu() presses Save once its button shows
// and waits for the "Saved!" text, so the save is confirmed. If that
// fails, B back to the overworld (B is harmless while writing) and one
// more try.
void save_story_game(ConsoleHandle& console, ProControllerContext& context){
open_save_report(console, context);
if (!try_save(console, context)){
mash_to_overworld(console, context, BUTTON_B, 10s);
if (!save_game_to_menu(console, context)){
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT,
"save_story_game(): the game did not save.",
console
);
}
}
mash_to_overworld(console, context, BUTTON_B, 10s);
}



} // namespace PokemonLZA
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* PokemonLZA AutoStory - Actions
*
* From: https://github.com/PokemonAutomation/
*
* The battle and save actions of the story game (PokemonLZA_AutoStoryGame.h),
* with the dialogue ones in PokemonLZA_AutoStoryDialogs.h, the walks in
* PokemonLZA_AutoStoryMoves.h and the scenes in PokemonLZA_AutoStoryScenes.h.
* Each is a short function over the LZA battle and menu code that already
* exists (TrainerBattle, BasicNavigation, the dialog and selection-arrow
* detectors). An action the game has no code for yet throws
* StoryActionNotImplemented, naming what is missing, instead of pressing
* buttons blind.
*
*/

#ifndef PokemonAutomation_PokemonLZA_AutoStoryActions_H
#define PokemonAutomation_PokemonLZA_AutoStoryActions_H

#include <chrono>
#include <string>
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "CommonFramework/Tools/ProgramEnvironment.h"
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
#include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{


// A story action this game has no code for yet. The story executor lets
// it end the run instead of reloading and trying again, since every
// attempt would fail the same way.
class StoryActionNotImplemented : public OperationFailedException{
public:
explicit StoryActionNotImplemented(std::string message);

// code-health: allow char_pointer -- the exception base class's name() returns const char*
virtual const char* name() const override{
return "StoryActionNotImplemented";
}
};


// From a trainer's or a wild Pokemon's battle starting, fights it with
// TrainerBattleState (`battle_ai`'s moves), pressing B through the text
// around it, until the overworld is back. Throws OperationFailedException
// if neither shows for two minutes.
void fight_battle(
ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context,
BattleAIOption& battle_ai
);

// In a battle that is already on screen: attacks with TrainerBattleState
// until a dialog box shows (the speech after a win or a loss). For story
// battles, which show no Run prompt for fight_battle() to start on.
// Throws OperationFailedException after `timeout`.
void fight_battle_in_progress(
ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context,
BattleAIOption& battle_ai, std::chrono::seconds timeout
);

// From the overworld, saves the game (save_game_to_menu()) and returns to
// the overworld. The first menu of a playthrough shows a save tutorial
// card, which it closes with A. If the save fails, B back to the
// overworld and one more try; throws OperationFailedException if that
// fails too.
void save_story_game(ConsoleHandle& console, ProControllerContext& context);



} // namespace PokemonLZA
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Loading
Loading