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
2 changes: 2 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Overworld/Ma
VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h PokemonAutomation::NintendoSwitch::PokemonFRLG overworld_map_json)
pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData
VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_battle_json)
pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData
VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_checkpoint_json)


# Create binary target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ class RouteLogLines{
for (const RouteStep& step : steps){
legs.push_back({.leg = route_log_leg(step), .after = route_tiles(step.end)});
}
m_calls.log(ROUTE_LOG_TAG + Pokemon::route_plan_line(m_label, route_tiles(from), legs));
m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_plan_line(m_label, route_tiles(from), legs));
}
void leg(size_t index, const std::vector<RouteStep>& steps) const{
const RouteStep& step = steps[index];
m_calls.log(ROUTE_LOG_TAG + Pokemon::route_leg_line(index + 1, steps.size(), {.leg = route_log_leg(step), .after = route_tiles(step.end)}));
m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_leg_line(index + 1, steps.size(), {.leg = route_log_leg(step), .after = route_tiles(step.end)}));
}
void end(const RouteStep& step, const std::optional<MapPosition>& at, EndBasis basis, const std::string& why) const{
m_calls.log(ROUTE_LOG_TAG + Pokemon::route_leg_end_line(m_label, route_log_leg(step), route_tiles(at), basis, why));
m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_leg_end_line(m_label, route_log_leg(step), route_tiles(at), basis, why));
}
void trainer_stopped(const RouteStep& step, const MapPosition& at) const{
m_calls.log(ROUTE_LOG_TAG + Pokemon::route_replan_line(m_label, route_log_leg(step), "stopped by a trainer who saw the player", route_tiles(at)));
m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_replan_line(m_label, route_log_leg(step), "stopped by a trainer who saw the player", route_tiles(at)));
}
void found(const MapPosition& at, size_t holds) const{
m_calls.log(ROUTE_LOG_TAG + Pokemon::route_found_line(m_label, route_tiles(at), holds));
m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_found_line(m_label, route_tiles(at), holds));
}
// Step `number` (from 1) of a plan whose first `holds` steps are holds
// to walls, walked to its end.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=772 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -13,7 +13,9 @@
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h"
#include "Pokemon/AutoStory/Pokemon_StoryLog.h"
#include "Pokemon/AutoStory/Pokemon_StorySegments.h"
#include "Pokemon/Options/Pokemon_GameLanguages.h"
#include "Pokemon/Pokemon_Strings.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h"
#include "VideoGames/PokemonFRLG/Programs/PokemonFRLG_NamingScreenKeyboard.h"
Expand Down Expand Up @@ -58,7 +60,14 @@
// The start and end dropdowns' entries: the table's checkpoints, 00.01 to
// 00.12b. The options hold a reference to it.
const StringSelectDatabase& checkpoint_database(){
static const StringSelectDatabase database = Pokemon::story_checkpoint_database(story_checkpoints());
static const std::vector<std::string> labels = []{
std::vector<std::string> result;
for (const StoryCheckpoint& checkpoint : story_checkpoints()){
result.push_back(Pokemon::story_checkpoint_label(checkpoint));
}
return result;
}();
static const StringSelectDatabase database = Pokemon::story_checkpoint_database(labels);
return database;
}

Expand Down Expand Up @@ -86,7 +95,7 @@
"English only. The Magikarp costs 500 and needs a free party slot; AutoStory's options leave the text fast.";

AutoStory::AutoStory()
: RUN(checkpoint_database())
: RUN(checkpoint_database(), Pokemon::FireRedLeafGreenLanguages_Database())
, NEW_GAME_FROM_TITLE(
"<b>New game from the title screen:</b><br>The game is on its title screen with no save data. "
"Needed to start at 00.01. Otherwise the program loads the save, which must be the one the start checkpoint begins from.",
Expand Down Expand Up @@ -171,7 +180,7 @@
// the screen as its frame if `keep_start_frame` (a save made by hand).
StoryEnv story_env(
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
const StoryCheckpoint& checkpoint, StoryChecks checks, bool keep_start_frame
const StoryCheckpoint& checkpoint, Pokemon::StoryCheckLevel checks, bool keep_start_frame
){
StoryEnv story{env.console, context, checkpoint.supplies, checkpoint.supplies, false, checks};
story.start_frames = program_start_frames();
Expand Down Expand Up @@ -248,11 +257,10 @@
){
const std::vector<StoryCheckpoint>& checkpoints = story_checkpoints();
const StoryCheckpoint& checkpoint = checkpoints[run.start_index()];
StoryEnv story = story_env(env, context, checkpoint, run.checks(), false);
StoryEnv story = story_env(env, context, checkpoint, run.check_level(), false);
load_verify_save(env, context, story, checkpoint);
story.language = run.language();
StoryExecutor executor(story);
executor.set_checks(run.checks());
executor.set_language(run.language());
Pokemon::Segment segment = make_story_segment(checkpoints, executor);
Pokemon::SegmentHooks hooks = story_hooks(env, story);

Expand Down Expand Up @@ -453,7 +461,7 @@
const Pokemon::SegmentReport report = run_segment(
state, segment, Pokemon::SegmentRange{rows.front().id, rows.back().id}, policy, hooks
);
Pokemon::record_story_stats(env.current_stats<Pokemon::AutoStoryStats>(), report);
Pokemon::record_story_counts(env.current_stats<Pokemon::AutoStoryStats>(), report.story_counts());
env.update_stats();
throw_if_failed(report);
}
Expand Down Expand Up @@ -635,7 +643,7 @@
};
}

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

Check warning on line 646 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::AutoStory::program( SingleSwitchProgramEnvironment & env , ProControllerContext & context): function_lines=40 (advisory above 25, limit 50)
if (const std::optional<Pokemon::VerifyPolicy> verify = RUN.VERIFY.policy()){
verify_story_checkpoint(env, context, RUN, *verify, NOTIFICATION_PROGRAM_FINISH);
return;
Expand All @@ -661,13 +669,12 @@
first = checkpoint_index(checkpoints, "00.01b");
plan = plan_story_run(checkpoints, first, last, handoffs);
}
StoryEnv story = story_env(env, context, checkpoints[first], RUN.checks(), KEEP_START_FRAME);
StoryEnv story = story_env(env, context, checkpoints[first], RUN.check_level(), KEEP_START_FRAME);
story.player_name = player_name;
const bool at_gift_rng = plan.stop == StoryHandoff::GIFT_RNG && plan.rows.empty();
prepare_start(env, context, checkpoints, first, story, at_gift_rng);
story.language = RUN.language();
StoryExecutor executor(story);
executor.set_checks(RUN.checks());
executor.set_language(RUN.language());

const std::optional<std::string> done_through = at_gift_rng
? run_from_gift_rng_save(env, context, story, executor, first)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,31 @@
} // namespace


std::optional<Outcome> run_ability_game_step(

Check warning on line 77 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::run_ability_game_step( Logger & logger , VideoStream * stream , const Pokemon :: StoryStep & step , StoryAbilities & abilities): function_lines=28 (advisory above 25, limit 50)
Logger& logger, VideoStream* stream, const Pokemon::StoryStep& step, StoryAbilities& abilities
){
const std::string_view variant = step.variant;
if (variant.starts_with(MART_VARIANT_PREFIX)){
const std::optional<MartPlan> plan = parse_mart_variant(variant);
return plan ? mart(logger, *plan, abilities) : Pokemon::outcome_failed("bad_variant", step.variant);
if (step.action == MART_ACTION){
const std::optional<MartPlan> plan = mart_plan_of(step.args);
return plan ? mart(logger, *plan, abilities) : Pokemon::outcome_failed("bad_args", step.action);
}
if (variant.starts_with(TEACH_VARIANT_PREFIX)){
const std::optional<TeachPlan> plan = parse_teach_variant(variant);
return plan ? teach(logger, *plan, abilities) : Pokemon::outcome_failed("bad_variant", step.variant);
if (step.action == TEACH_ACTION){
const std::optional<TeachPlan> plan = teach_plan_of(step.args);
return plan ? teach(logger, *plan, abilities) : Pokemon::outcome_failed("bad_args", step.action);
}
if (variant.starts_with(LEVEL_VARIANT_PREFIX)){
const std::optional<LevelCheck> check = parse_level_variant(variant);
return check ? level(logger, *check, abilities) : Pokemon::outcome_failed("bad_variant", step.variant);
if (step.action == LEVEL_ACTION){
const std::optional<LevelCheck> check = level_check_of(step.args);
return check ? level(logger, *check, abilities) : Pokemon::outcome_failed("bad_args", step.action);
}
if (variant.starts_with(GRIND_VARIANT_PREFIX)){
const std::optional<GrindPlan> plan = parse_grind_variant(variant);
if (!plan || !step.target){
return Pokemon::outcome_failed("bad_variant", step.variant + (step.target ? "" : " (no nurse)"));
if (step.action == GRIND_ACTION){
const std::optional<GrindPlan> plan = grind_plan_of(step.args);
if (!plan || !step.args.contains("nurse")){
return Pokemon::outcome_failed("bad_args", step.action + (step.args.contains("nurse") ? "" : " (no nurse)"));
}
return grind(logger, stream, *plan, abilities);
}
if (variant.starts_with(FOSSIL_VARIANT_PREFIX)){
const std::optional<Fossil> choice = parse_fossil_variant(variant);
return choice ? fossil(logger, *choice, abilities) : Pokemon::outcome_failed("bad_variant", step.variant);
if (step.action == FOSSIL_ACTION){
const std::optional<Fossil> choice = fossil_of(step.args);
return choice ? fossil(logger, *choice, abilities) : Pokemon::outcome_failed("bad_args", step.action);
}
return std::nullopt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The GAME steps beyond walking and talking that later checkpoints name
* in the table: MART (a budgeted buy list), TEACH (a TM or HM), LEVEL (a
* member's level checked), GRIND (wild battles to a level) and
* CHOICE(fossil). Each is a variant of a GAME step; this runs the one a
* CHOICE(fossil). Each is an action of a GAME step; this runs the one a
* step names with the game steps it is given.
*
*/
Expand All @@ -17,7 +17,7 @@
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "CommonFramework/Tools/VideoStream.h"
#include "Pokemon/AutoStory/Pokemon_StoryEvents.h"
#include "Pokemon/AutoStory/Pokemon_StorySteps.h"
#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h"
#include "PokemonFRLG_AutoStoryChoice.h"
#include "PokemonFRLG_AutoStoryGrind.h"
#include "PokemonFRLG_AutoStoryMart.h"
Expand All @@ -39,7 +39,7 @@ struct StoryAbilities{
};

// A MART, TEACH, LEVEL, GRIND or fossil step with `abilities`: nothing for
// another variant. A GRIND that meets a shiny throws
// another action. A GRIND that meets a shiny throws
// ProgramFinishedException, with a screenshot from `stream` if given, so
// the segment stops without reloading. Any other end but success is a
// failed Outcome; a MART that buys nothing because the money doesn't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ class Test_AutoStoryAbilities : public UnitTest{
};


Pokemon::StoryStep game_step(std::string variant){
Pokemon::StoryStep game_step(std::string action, Pokemon::StoryActionArgs args){
Pokemon::StoryStep step;
step.kind = Pokemon::StoryStepKind::GAME;
step.name = "test";
step.variant = std::move(variant);
step.action = std::move(action);
step.args = std::move(args);
return step;
}

Expand Down Expand Up @@ -147,20 +148,21 @@ struct StepCase{

std::vector<StepCase> step_cases(){
const auto none = [](StubGame&){};
const Pokemon::StoryStep mart = mart_step("mart", "", {.map = "PewterCity_Mart", .lines = {{"potion", 5}}, .budget = 2000});
const Pokemon::StoryStep grind = grind_step("grind", "", {.member = 0, .level = 20, .max_encounters = 5, .pace = Pokemon::Direction::EAST, .heal_every = 0}, {});
return {
{"level reached", none, level_step("check", "", {.slot = 0, .level = 16}), ""},
{"level below", none, level_step("check", "", {.slot = 0, .level = 17}), "level_below"},
{"level unread", [](StubGame& game){ game.level.reset(); }, level_step("check", "", {.slot = 0, .level = 16}), "level_unread"},
{"a Mart with too little money succeeds", [](StubGame& game){ game.mart.money = 100; }, game_step("mart PewterCity_Mart budget=2000 potion=5"), ""},
{"a Mart purchase that fails", none, game_step("mart PewterCity_Mart budget=2000 potion=5"), "mart_failed"},
{"a move it knows already succeeds", none, game_step("teach hm03 surf slot=1"), ""},
{"a TM not in the TM Case is skipped", none, game_step("teach tm03 water-pulse slot=1 forget=water-gun"), ""},
{"a Mart with too little money succeeds", [](StubGame& game){ game.mart.money = 100; }, mart, ""},
{"a Mart purchase that fails", none, mart, "mart_failed"},
{"a move it knows already succeeds", none, teach_step("teach", "", {.item = "hm03", .move = "surf", .member = 0}), ""},
{"a TM not in the TM Case is skipped", none, teach_step("teach", "", {.item = "tm03", .move = "water-pulse", .member = 0, .forget_move = "water-gun"}), ""},
{"a level that can't be read stops a GRIND", [](StubGame& game){ game.level.reset(); }, grind, "grind_unread"},
{"a GRIND without a nurse", none, game_step("grind slot=1 level=20"), "bad_variant"},
{"a GRIND without a nurse", none, game_step(GRIND_ACTION, {{"slot", int64_t(1)}, {"level", int64_t(20)}}), "bad_args"},
{"no YES/NO at the fossil", none, fossil_step("fossil", "", Fossil::HELIX), "fossil_failed"},
{"a bad variant", none, game_step("mart PewterCity_Mart"), "bad_variant"},
{"another game step", none, game_step("capture rattata"), "none"},
{"bad args", none, game_step(MART_ACTION, {{"map", std::string("PewterCity_Mart")}}), "bad_args"},
{"another game step", none, capture_step("capture", "", {.species = "rattata"}), "none"},
};
}

Expand Down Expand Up @@ -192,15 +194,21 @@ UnitTestResult test_grind_shiny_stops(){
}


UnitTestResult test_level_variant(){
const std::string variant = level_variant({.slot = 1, .level = 23});
const std::optional<LevelCheck> back = parse_level_variant(variant);
if (variant != "level slot=2 min=23" || !back || back->slot != 1 || back->level != 23){
return "Unexpected level variant \"" + variant + "\".";
UnitTestResult test_level_args(){
const std::optional<LevelCheck> back = level_check_of(level_args({.slot = 1, .level = 23}));
if (!back || back->slot != 1 || back->level != 23){
return "Expected slot 2, level 23 to read back.";
}
for (std::string_view bad : {"level", "level slot=1", "level min=5", "level slot=0 min=5", "level slot=1 min=101"}){
if (parse_level_variant(bad)){
return "Expected \"" + std::string(bad) + "\" refused.";
const std::vector<Pokemon::StoryActionArgs> bad_args{
{},
{{"slot", int64_t(1)}},
{{"min", int64_t(5)}},
{{"slot", int64_t(0)}, {"min", int64_t(5)}},
{{"slot", int64_t(1)}, {"min", int64_t(101)}},
};
for (const Pokemon::StoryActionArgs& bad : bad_args){
if (level_check_of(bad)){
return "Expected args with a missing or out-of-range value refused.";
}
}
return true;
Expand All @@ -219,7 +227,7 @@ const AutoStoryAbilitiesCase AUTO_STORY_ABILITIES_CASES[] = {
.expectation = {},
},
{
.input = {"the LEVEL step's variant", test_level_variant},
.input = {"the LEVEL step's args", test_level_args},
.expectation = {},
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Actions

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=924 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -843,7 +843,7 @@

void buy_items(
ConsoleHandle& console, ProControllerContext& context,
const std::vector<MartOrder>& orders, StoryChecks checks, Language language
const std::vector<MartOrder>& orders, Pokemon::StoryCheckLevel checks, Language language
){
// "May I help you?" with BUY on top, then the list, cursor on its top.
press(context, BUTTON_A, 2000ms);
Expand All @@ -860,7 +860,7 @@
}
cursor = order.row;
mart_shot(console, context, std::format("row{}-list", order.row + 1));
if (checks == StoryChecks::THOROUGH){
if (checks_screen(checks)){
check_mart_row(console, context, order, language);
}
// "How many?" drops presses while its text prints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
#include "Pokemon/AutoStory/Pokemon_StorySteps.h"
#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h"
#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h"
#include "Pokemon/Navigation/Pokemon_Grid.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


// How much the story checks the screen before and after it acts: the
// shared level (Pokemon_StorySteps.h, set by StoryRunOptions). For FRLG,
// THOROUGH reads a Mart row's item before buying it, the bag's Items
// pocket after shopping (the counts the story then keeps), and an item's
// name in the bag before using it. FAST trusts the counts it keeps and the
// timings.
using StoryChecks = Pokemon::StoryChecks;
// Whether the shared check level (Types/Pokemon_StoryCheckLevel.h, set by
// StoryRunOptions) has the story check the screen before and after it
// acts: DEFAULT and above (TESTING, THOROUGH). Then FRLG reads a Mart
// row's item before buying it, the bag's Items pocket after shopping (the
// counts the story then keeps), and an item's name in the bag before
// using it. FAST and SPEEDRUN trust the counts it keeps and the timings.
inline bool checks_screen(Pokemon::StoryCheckLevel level){
return level <= Pokemon::StoryCheckLevel::DEFAULT;
}

// The START menu as the story grows it. Before the starter: BAG, the
// player, SAVE, OPTION, EXIT; the starter adds POKEMON on top, the Pokedex
Expand Down Expand Up @@ -214,7 +217,7 @@ int mart_cursor_moves(int cursor, int row);
// bought by position only.
void buy_items(
ConsoleHandle& console, ProControllerContext& context,
const std::vector<MartOrder>& orders, StoryChecks checks, Language language
const std::vector<MartOrder>& orders, Pokemon::StoryCheckLevel checks, Language language
);

// From the title screen of a game with no save, to the bedroom: the
Expand Down
Loading
Loading