Skip to content

PokemonLZA AutoStory: the console backend, dialogs, scenes and battles - #559

Draft
dayfine wants to merge 7 commits into
plza/upstream/p2-01from
plza/upstream/p2-02
Draft

dayfine wants to merge 7 commits into
plza/upstream/p2-01from
plza/upstream/p2-02

Conversation

@dayfine

@dayfine dayfine commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Depends on #558

Adds PlzaConsoleBackend, PLZA's implementation of the shared story backend: it looks at the screen through the detectors, presses buttons, fights and saves. It comes with the console routines it calls, which call it back: dialogs, scenes, battles (run_battle_until() in PokemonLZA_TrainerBattle) and the save through the menu; this cycle is why the PR is over the size the rest of the chain keeps to. The story game in #568 wires the backend into the engine. Tested by PokemonLZA::AutoStoryDialogs; the backend itself runs only on a console, and the engine tests in #568 drive the same steps through a fake backend.

@dayfine

dayfine commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

API review (claude-sonnet-5-5) at 22d8882: changes_requested

Two behavior problems and several style points. PlzaConsoleBackend::observe() writes a PNG on every change of screen state and every 2 s, with no option gating it, so a long run can fill the disk. fight_battle_in_progress() passes a possibly empty snapshot to the detector. Smaller items: the talk_through_map_screen() contract does not match its code, run_battle_until() adds a new int sentinel return, a duplicated magic box has a process-talk TODO, and a few readability and consistency nits.

  • [bug] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp:162 capture() runs on every observe() and saves a full PNG under SCREENSHOTS_PATH() whenever the events/readings text changes, and at least every 2 s otherwise. It is not gated by any option or debug flag, and the header describes it as a debugging aid ('to find the screens they miss'). A multi-hour story run will write thousands of images and can fill the disk. Every user run also creates a new PLZA-capture/<timestamp>/ folder. Fix: Gate it behind an explicit option (default off), or cap it: a maximum capture count, or capture only on specific events. Also log how many were written.
  • [bug] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp:83 console.video().snapshot() can return an empty snapshot, and fight_battle_in_progress() passes it straight to any_dialog.detect(screen). Its sibling press_a_until_quiet() and PlzaConsoleBackend::observe() both check screen/frame first. An empty frame here can misread as 'no dialog' or trip the detector. Fix: If !screen, context.wait_for(...) a short poll and continue, as the other call sites do. Do not run the detector or the attack on it.
  • [style] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h:65 The talk_through_map_screen() contract does not match the code. The header says it presses A until the map shows, closes it with B, and throws if the map does not show within 60 s. The .cpp never waits for the map: it alternates A and B until the party bar holds, with a 120 s timeout. The .cpp comment also says the map is not waited for, which contradicts the header. Fix: Rewrite the header comment to the real behavior (A and B in turn until the overworld has held, throws after 120 s). Fix the misindented comment at lines 113-117 of the .cpp while there.
  • [style] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_TrainerBattle.h:67 run_battle_until() adds a new sentinel API: it returns 0 when end_watcher fires and -1 on timeout, and callers test < 0. That is an int with an invented meaning. Its default Milliseconds(120000) is also a bare literal. Fix: Return bool (fired / timed out), or an enum or std::optional. Use std::chrono::seconds(120) or a named constant for the default.
  • [style] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp:112 The Save-button search box {0.287118, 0.638835, 0.064410, 0.108738} is copied from save_game_to_menu() as bare literals. The TODO justifies the duplication by a code-health symbol limit, which is tooling talk rather than a reason about the code. Two copies of the box can drift apart. Fix: Name the box once, in PokemonLZA_BasicNavigation or a small shared constant, and use it in both places. If it cannot move in this PR, name it here and reword the TODO to say only that it duplicates save_game_to_menu().
  • [style] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp:113 The reading list is encoded twice by hand, as a run of if (detector) readings[X] = 1; blocks in observe() and a matching run of if (contains(X)) text += "+x" blocks in look_text(). Adding a reading means editing both in lockstep. Fix: Keep one table of {reading name, capture label} and loop over it in look_text(), so the label cannot drift from the reading.
  • [nit] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp:230 (int)std::lround(heading) % 360 is a C-style cast. It also yields a negative value if the minimap ever reports a negative heading, while the header promises [0, 360). Fix: Use static_cast<int>(std::lround(heading)) and normalize with ((v % 360) + 360) % 360, or document that the heading is already in range.
  • [nit] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp:142 Inconsistent spellings of the same check: choice_arrow_shows tests wait_until(...) >= 0 while save_button_shows in the Actions file tests == 0 and the other call sites test < 0. Fix: Use one form, e.g. == 0 for 'the watcher fired', as save_button_shows does.
  • [nit] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp:109 Milliseconds(120000) is a bare literal, while other new code writes the same kind of duration as 120s/60s. Likewise fight_battle_in_progress takes std::chrono::seconds while the rest of the new API takes Milliseconds. Fix: Use 120s or a named STORY_SCENE_TIMEOUT constant. Pick one duration type for the action signatures.
  • [nit] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h:11 The header comment says an action with no game code yet throws Pokemon::StoryActionNotImplemented, but none of the four actions declared here does. It also points to Moves.h and Game.h, which this PR does not add. Fix: Drop the sentence and the forward references, or move them to the PR that introduces them.
  • [nit] SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs_Tests.h:17 The comment says the tests cover only the D-pad presses between choice rows, but add_tests_AutoStoryDialogs also registers the QuietPresses clock cases. Fix: Mention the QuietPresses clock in the comment.

…_looks; review fixes

observe() saved a PNG on every change of the look's events and every 2 s
with no way to turn it off; it now saves only with StoryEnv::capture_looks
(off by default). fight_battle_in_progress() waits for the next frame
instead of reading an empty snapshot. The heading reading is normalized to
[0, 360) with a static_cast, and talk_through_map_screen()'s header says
what the code does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant