Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ std::optional<Pokemon::StoryFailure> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,43 @@
}
}

const EnumDropdownDatabase<StarterChoice>& starter_database(){
static const EnumDropdownDatabase<StarterChoice> 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<StoryCheckpoint>& rows, const std::string& run_from, StoryEnv& story){

Check warning on line 117 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: walk_before: output parameter 'std::vector<StoryCheckpoint>& rows' comes before an input; put inputs (by value, const&) first and non-const references last (Google "Function Parameter Ordering")
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<NewGameLanguage>& new_game_language_database(){
static const EnumDropdownDatabase<NewGameLanguage> database{
{NewGameLanguage::English, "en", "English"},
Expand Down Expand Up @@ -260,7 +297,7 @@
} // namespace


AutoStory::AutoStory()

Check failure on line 300 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonLZA::AutoStory::AutoStory(): function_lines=54, limit=50, allowed 50
: RANGE("Checkpoints", checkpoint_database())
, GAME_LANGUAGE(
"<b>Game Language:</b><br>01.00a picks it on the new game's language list; 01.00b checks it on Confirm Choices. "
Expand All @@ -287,6 +324,12 @@
true
)
, RECORD_START_MINIMAPS(std::string(RECORD_START_MINIMAPS_LABEL), LockMode::LOCK_WHILE_RUNNING, /*default_value=*/false)
, STARTER("<b>Starter:</b><br>The starter 01.03 picks.", starter_database(), LockMode::LOCK_WHILE_RUNNING, StarterChoice::CHIKORITA)
, RUN_FROM(
/*is_password=*/false,
"<b>Run From:</b><br>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,
Expand All @@ -302,18 +345,21 @@
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);
}

void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){

Check failure on line 355 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonLZA::AutoStory::program( SingleSwitchProgramEnvironment & env , ProControllerContext & context): function_lines=51, limit=50, allowed 50
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<StoryCheckpoint>& rows = story_data.checkpoints;
const size_t first = RANGE.start_index();
const size_t last = RANGE.end_index();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,6 +55,8 @@ class AutoStory : public SingleSwitchProgramInstance{
SimpleIntegerOption<uint8_t> REWINDS_TO_BACKUP;
BooleanCheckBoxOption LOAD_SAVE_FIRST;
BooleanCheckBoxOption RECORD_START_MINIMAPS;
EnumDropdownOption<StarterChoice> STARTER;
StringOption RUN_FROM;
BattleAIOption BATTLE_AI;
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
EventNotificationsOption NOTIFICATIONS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
{}

void PlzaConsoleBackend::press(Button button, Milliseconds hold, Milliseconds release){
m_run_end.reset();
pbf_press_button(m_env.context, button, hold, release);
}

Expand All @@ -47,21 +48,37 @@
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<int64_t>(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(){

Check failure on line 74 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonLZA::PlzaConsoleBackend::observe(): function_lines=51, limit=50, allowed 50
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)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef PokemonAutomation_PokemonLZA_AutoStoryConsoleBackend_H
#define PokemonAutomation_PokemonLZA_AutoStoryConsoleBackend_H

#include <optional>
#include <string_view>
#include "Common/Cpp/Time.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
Expand Down Expand Up @@ -42,6 +43,9 @@
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.
Expand All @@ -52,7 +56,7 @@


// PLZA on the console.
// code-health: allow public_methods -- the engine's backend calls; nothing PLZA adds

Check warning on line 59 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleBackend.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::PlzaConsoleBackend: public_methods=7 is within limit 7; remove its code-health allow tag
class PlzaConsoleBackend : public PlzaBackend{
public:
explicit PlzaConsoleBackend(StoryEnv& env);
Expand Down Expand Up @@ -88,6 +92,10 @@
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<WallClock> m_run_end;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
} // namespace


PlzaStoryTools plza_console_tools(StoryEnv& env, AutosaveSightings& sightings){
PlzaStoryTools plza_console_tools(StoryEnv& env, AutosaveSightings& sightings, double starter_turn){

Check warning on line 237 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: plza_console_tools: output parameter 'AutosaveSightings& sightings' comes before an input; put inputs (by value, const&) first and non-const references last (Google "Function Parameter Ordering")
return PlzaStoryTools{
.console = console_actions(env),
.arrow = minimap_arrow(env),
Expand All @@ -248,6 +248,7 @@
return std::nullopt;
},
.sightings = &sightings,
.starter_turn = starter_turn,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

// 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);

Check warning on line 25 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryConsoleGame.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: plza_console_tools: output parameter 'AutosaveSightings& sightings' comes before an input; put inputs (by value, const&) first and non-const references last (Google "Function Parameter Ordering")

// 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PokemonLZA AutoStory - Story game

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=694 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -161,6 +161,8 @@
std::optional<std::optional<ScreenEvent>> end = std::nullopt;
Milliseconds end_after = 0ms;
std::optional<double> heading = std::nullopt;
// The first leg turns toward the chosen starter.
bool turn_to_starter = false;
};

// [[turn degrees, walk ms], ...]
Expand All @@ -176,10 +178,14 @@
return legs;
}

WalkArgs read_walk_args(const JsonObject& args){

Check warning on line 181 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::read_walk_args( const JsonObject & args): function_lines=31 (advisory above 25, limit 50)
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;
}
Expand Down Expand Up @@ -398,13 +404,18 @@
} // namespace


StoryActions plza_story_actions(const PlzaStoryTools& tools){

Check warning on line 407 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::plza_story_actions( const PlzaStoryTools & tools): function_lines=45 (advisory above 25, limit 50)

Check failure on line 407 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonLZA::plza_story_actions( const PlzaStoryTools & tools): nesting=5, limit=4, allowed 4
StoryActions actions{
{"wait_for_platform", platform_action(PlatformWait::PLATFORM_ONLY, 180000ms)},
{"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()},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct PlzaStoryTools{
std::function<std::optional<Pokemon::StoryFailure>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading