diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp index 5ca0645fa2..d4966aa506 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp @@ -115,9 +115,9 @@ std::optional run_story_move_but_last_walk(PlzaBackend& b void hold_last_leg(PlzaBackend& backend, const StoryMove& move, Milliseconds slice){ if (move.style == StoryWalkStyle::HELD && !move.legs.empty()){ - backend.stick(move.legs.back().turn, slice, /*release=*/0ms, Pokemon::StoryPace::WALK); + backend.stick(move.legs.back().turn, slice, /*release=*/0ms, Pokemon::StoryPace::RUN); }else{ - backend.stick(/*degrees=*/0, slice, /*release=*/0ms, Pokemon::StoryPace::WALK); + backend.stick(/*degrees=*/0, slice, /*release=*/0ms, Pokemon::StoryPace::RUN); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index e1450ab50e..6c0ef130ec 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -89,6 +89,43 @@ void check_checkpoint_range(ConsoleHandle& console, size_t first, size_t last, s } } +const EnumDropdownDatabase& starter_database(){ + static const EnumDropdownDatabase database{ + {StarterChoice::CHIKORITA, "chikorita", "Chikorita"}, + {StarterChoice::TOTODILE, "totodile", "Totodile"}, + {StarterChoice::TEPIG, "tepig", "Tepig"}, + }; + return database; +} + +// The stick heading from 01.03's start to each starter: Chikorita's -70 is +// from console B; the others keep #1933's stick angles relative to its +// Chikorita (-66, -50, -34). +double starter_turn(StarterChoice starter){ + switch (starter){ + case StarterChoice::TOTODILE: + return -54; + case StarterChoice::TEPIG: + return -38; + case StarterChoice::CHIKORITA: + break; + } + return -70; +} + +// Before `run_from` (dash is not unlocked yet), each step's run legs walk. +void walk_before(std::vector& rows, const std::string& run_from, StoryEnv& story){ + for (StoryCheckpoint& row : rows){ + const bool walk_only = row.id < run_from; + for (StoryStep& step : row.steps){ + step.run = [&story, walk_only, run = std::move(step.run)](PlzaBackend& backend, Pokemon::RunState& state) mutable{ + story.walk_only = walk_only; + return run(backend, state); + }; + } + } +} + const EnumDropdownDatabase& new_game_language_database(){ static const EnumDropdownDatabase database{ {NewGameLanguage::English, "en", "English"}, @@ -287,6 +324,12 @@ AutoStory::AutoStory() true ) , RECORD_START_MINIMAPS(std::string(RECORD_START_MINIMAPS_LABEL), LockMode::LOCK_WHILE_RUNNING, /*default_value=*/false) + , STARTER("Starter:
The starter 01.03 picks.", starter_database(), LockMode::LOCK_WHILE_RUNNING, StarterChoice::CHIKORITA) + , RUN_FROM( + /*is_password=*/false, + "Run From:
The first checkpoint whose walks hold B to run; earlier ones walk (the game has no dash yet).", + LockMode::LOCK_WHILE_RUNNING, /*default_value=*/"02.01", /*placeholder_text=*/"02.01" + ) , GO_HOME_WHEN_DONE(false) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, @@ -302,6 +345,8 @@ AutoStory::AutoStory() PA_ADD_OPTION(REWINDS_TO_BACKUP); PA_ADD_OPTION(LOAD_SAVE_FIRST); PA_ADD_OPTION(RECORD_START_MINIMAPS); + PA_ADD_OPTION(STARTER); + PA_ADD_OPTION(RUN_FROM); PA_ADD_OPTION(BATTLE_AI); PA_ADD_OPTION(GO_HOME_WHEN_DONE); PA_ADD_OPTION(NOTIFICATIONS); @@ -311,9 +356,10 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex const NewGameChoices new_game{.language = GAME_LANGUAGE, .look = PLAYER_LOOK, .name = PLAYER_NAME}; StoryEnv story{.env = env, .context = context, .battle_ai = BATTLE_AI, .new_game = new_game}; AutosaveSightings sightings; - const PlzaStoryTools tools = plza_console_tools(story, sightings); + const PlzaStoryTools tools = plza_console_tools(story, sightings, starter_turn(STARTER)); StoryData story_data = load_plza_story(tools); note_autosaves(story_data.checkpoints, sightings); + walk_before(story_data.checkpoints, RUN_FROM, story); std::vector& rows = story_data.checkpoints; const size_t first = RANGE.start_index(); const size_t last = RANGE.end_index(); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index ace2eecdbc..d7ceb1b75a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -33,6 +33,12 @@ class AutoStory_Descriptor : public SingleSwitchProgramDescriptor{ // Runs the story's checkpoints from the start one to the end one. +enum class StarterChoice{ + CHIKORITA, + TOTODILE, + TEPIG, +}; + class AutoStory : public SingleSwitchProgramInstance{ public: using Descriptor = AutoStory_Descriptor; @@ -49,6 +55,8 @@ class AutoStory : public SingleSwitchProgramInstance{ SimpleIntegerOption REWINDS_TO_BACKUP; BooleanCheckBoxOption LOAD_SAVE_FIRST; BooleanCheckBoxOption RECORD_START_MINIMAPS; + EnumDropdownOption STARTER; + StringOption RUN_FROM; BattleAIOption BATTLE_AI; GoHomeWhenDoneOption GO_HOME_WHEN_DONE; EventNotificationsOption NOTIFICATIONS; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.cpp index 4b0feb506e..9be776d41a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.cpp @@ -37,6 +37,7 @@ PlzaConsoleBackend::PlzaConsoleBackend(StoryEnv& env) {} void PlzaConsoleBackend::press(Button button, Milliseconds hold, Milliseconds release){ + m_run_end.reset(); pbf_press_button(m_env.context, button, hold, release); } @@ -47,21 +48,37 @@ constexpr double RUN_SPEEDUP = 2.25; void PlzaConsoleBackend::stick(double degrees, Milliseconds duration, Milliseconds release, Pokemon::StoryPace pace){ const double radians = degrees * std::numbers::pi / 180.0; const JoystickPosition position{std::sin(radians), std::cos(radians)}; - if (pace != Pokemon::StoryPace::RUN){ + if (pace != Pokemon::StoryPace::RUN || m_env.walk_only){ + m_run_end.reset(); pbf_move_left_joystick(m_env.context, position, duration, release); return; } const Milliseconds run(static_cast(duration.count() / RUN_SPEEDUP)); + const WallClock now = current_time(); + const WallClock start = m_run_end && *m_run_end > now ? *m_run_end : now; pbf_controller_state(m_env.context, BUTTON_B, DPAD_NONE, position, {}, run); - pbf_wait(m_env.context, release); + if (release > 0ms){ + pbf_wait(m_env.context, release); + m_run_end.reset(); + }else{ + m_run_end = start + run; + } } void PlzaConsoleBackend::wait(Milliseconds duration){ + m_env.context.wait_for_all_requests(); + m_run_end.reset(); m_env.context.wait_for(duration); } ScreenObservation PlzaConsoleBackend::observe(){ - m_env.context.wait_for_all_requests(); + // Look before the queued run ends, with time left to queue the next slice. + if (m_run_end && *m_run_end - 80ms > current_time()){ + m_env.context.wait_until(*m_run_end - 80ms); + }else if (!m_run_end || *m_run_end <= current_time()){ + m_env.context.wait_for_all_requests(); + m_run_end.reset(); + } VideoSnapshot frame = m_env.env.console.video().snapshot(); ScreenObservation look; if (frame && m_home.detect(*frame.frame)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.h index c0801d61bc..3c009b498b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.h @@ -10,6 +10,7 @@ #ifndef PokemonAutomation_PokemonLZA_AutoStoryConsoleBackend_H #define PokemonAutomation_PokemonLZA_AutoStoryConsoleBackend_H +#include #include #include "Common/Cpp/Time.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" @@ -42,6 +43,9 @@ struct StoryEnv{ BattleAIOption& battle_ai; // The language, look and name 01.00a picks (01.00b checks them). NewGameChoices new_game = {}; + // Set while a checkpoint before the one where B first runs plays: run + // legs walk at their walk times. + bool walk_only = false; }; // The console's MinimapArrowReader. @@ -88,6 +92,10 @@ class PlzaConsoleBackend : public PlzaBackend{ MapDetector m_map; SelectionArrowDetector m_save_button; VideoSnapshot m_previous; + // When the queued run (B held) ends. A look during a run waits only until + // just before then, so the next slice queues behind it and B never lets go: + // a new press of B inside a leg switches dash off. + std::optional m_run_end; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.cpp index 7ae59a0de4..6ae5b8c75e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.cpp @@ -234,7 +234,7 @@ PlzaConsoleActions console_actions(StoryEnv& env){ } // namespace -PlzaStoryTools plza_console_tools(StoryEnv& env, AutosaveSightings& sightings){ +PlzaStoryTools plza_console_tools(StoryEnv& env, AutosaveSightings& sightings, double starter_turn){ return PlzaStoryTools{ .console = console_actions(env), .arrow = minimap_arrow(env), @@ -248,6 +248,7 @@ PlzaStoryTools plza_console_tools(StoryEnv& env, AutosaveSightings& sightings){ return std::nullopt; }, .sightings = &sightings, + .starter_turn = starter_turn, }; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.h index c8084bddc1..2fe1475bfb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.h @@ -21,7 +21,8 @@ namespace PokemonLZA{ // The console's tools: its actions, the minimap arrow, lock-on and // battle code. `env` and `sightings` must outlive them. -PlzaStoryTools plza_console_tools(StoryEnv& env, AutosaveSightings& sightings); +// `starter_turn`: the stick heading from 01.03's start to the starter picked. +PlzaStoryTools plza_console_tools(StoryEnv& env, AutosaveSightings& sightings, double starter_turn); // plza_story_game() with the console's reload of the latest save, which // says the game is at the failed checkpoint's start. `env` and diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 088f9c4137..16f24fdd84 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -161,6 +161,8 @@ struct WalkArgs{ std::optional> end = std::nullopt; Milliseconds end_after = 0ms; std::optional heading = std::nullopt; + // The first leg turns toward the chosen starter. + bool turn_to_starter = false; }; // [[turn degrees, walk ms], ...] @@ -177,9 +179,13 @@ std::vector read_legs(const JsonArray& rows){ } WalkArgs read_walk_args(const JsonObject& args){ - reject_unknown_keys(args, {"legs", "end", "held", "wait_ms", "end_after_ms", "heading"}); + reject_unknown_keys(args, {"legs", "end", "held", "wait_ms", "end_after_ms", "heading", "turn_to_starter"}); WalkArgs walk; walk.move.legs = read_legs(args.get_array_throw("legs")); + walk.turn_to_starter = flag(args, "turn_to_starter"); + if (walk.turn_to_starter && walk.move.legs.empty()){ + throw ParseException("\"turn_to_starter\" needs a leg to turn"); + } if (flag(args, "held")){ walk.move.style = StoryWalkStyle::HELD; } @@ -404,7 +410,12 @@ StoryActions plza_story_actions(const PlzaStoryTools& tools){ {"opening_to_platform", platform_action(PlatformWait::AFTER_AUTOSAVE, 240000ms)}, {"walk", [&tools](const JsonObject& args) -> StoryStepRun{ return [&tools, walk = read_walk_args(args)](PlzaBackend& backend, RunState&){ - return walk_step(tools, walk, backend, "walk"); + if (!walk.turn_to_starter){ + return walk_step(tools, walk, backend, "walk"); + } + WalkArgs aimed = walk; + aimed.move.legs.front().turn = tools.starter_turn; + return walk_step(tools, aimed, backend, "walk"); }; }}, {"mash_to_move_hints", move_hints_action()}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 5c5d16f94e..f73a56c89b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -56,6 +56,8 @@ struct PlzaStoryTools{ std::function(PlzaBackend& backend)> battle = {}; // Where a menu save counts as an autosave; none: nowhere. AutosaveSightings* sightings = nullptr; + // The stick heading of a walk with "turn_to_starter" (01.03's starter pick). + double starter_turn = -70; }; // Every action a PLZA checkpoint may name, bound to `tools`, which must diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json index aa64102512..24d67c93e4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json @@ -10,17 +10,18 @@ "events": [ { "id": "approach_starter", - "why": "to Chikorita's \"A Talk\" prompt. not planned: no tile grid in Lumiose", + "why": "to the chosen starter's \"A Talk\" prompt; the turn is the Starter option's heading. not planned: no tile grid in Lumiose", "action": "walk", "args": { - "legs": [[-70, 750]], - "end": "prompt" + "legs": [[-70, 1500]], + "end": "prompt", + "turn_to_starter": true } }, { "id": "talk_to_starter", "action": "talk", - "why": "A at \"A Talk Chikorita\"" + "why": "A at the starter's \"A Talk\"" }, { "id": "andi_battle_start",