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 @@ -71,20 +71,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=652 (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 @@ -57,7 +59,14 @@
// The start and end dropdowns' entries: the table's checkpoints, 00.01 to
// 00.10. 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 All @@ -76,7 +85,7 @@
"SID Helper's timing needs the text speed and button settings already saved, as with Stop for SID Helper.";

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 @@ -159,7 +168,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 @@ -236,11 +245,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 @@ -436,7 +444,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 @@ -569,7 +577,7 @@
};
}

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

Check warning on line 580 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=49 (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 @@ -595,12 +603,11 @@
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;
prepare_start(env, context, checkpoints, first, story);
story.language = RUN.language();
StoryExecutor executor(story);
executor.set_checks(RUN.checks());
executor.set_language(RUN.language());
StarterRngPlanned planned;
std::function<void()> before;
if (plan.stop == StoryHandoff::STARTER_RNG){
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=909 (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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Battle

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=981 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -164,9 +164,9 @@
// no names for) is taken by its position; only another item's name stops it.
bool bag_row_is(
ConsoleHandle& console, ProControllerContext& context,
int row, const std::string& item, StoryChecks checks, Language language
int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language
){
if (checks == StoryChecks::FAST){
if (!checks_screen(checks)){
return true;
}
context.wait_for_all_requests();
Expand All @@ -190,7 +190,7 @@
// backs out to the battle menu. Not run on the console yet.
bool use_item(
ConsoleHandle& console, ProControllerContext& context,
int row, const std::string& item, StoryChecks checks, Language language
int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language
){
console.log(std::format("Battle: using the {} in row {} of the Items pocket.", item, row + 1));
tap(context, DPAD_LEFT);
Expand Down Expand Up @@ -321,7 +321,7 @@
public:
BattleLoop(
ConsoleHandle& console, ProControllerContext& context,
Supplies& supplies, BattleKind kind, StoryChecks checks, Language language
Supplies& supplies, BattleKind kind, Pokemon::StoryCheckLevel checks, Language language
)
: m_console(console)
, m_context(context)
Expand Down Expand Up @@ -659,7 +659,7 @@
BattleEndWatch m_end;
MoveRefusalWatch m_refusal;
const BattleKind m_kind;
const StoryChecks m_checks;
const Pokemon::StoryCheckLevel m_checks;
const Language m_language;
const WallClock m_start;
WallClock m_last_battle;
Expand Down Expand Up @@ -694,7 +694,7 @@
// Not run on the console yet.
bool use_item_on_overworld(
ConsoleHandle& console, ProControllerContext& context,
int row, const std::string& item, StoryChecks checks, Language language
int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language
){
console.log(std::format("Story: using a {} from the bag (Items pocket, row {}).", item, row + 1));
open_items_pocket(console, context);
Expand Down Expand Up @@ -727,7 +727,7 @@
// <Pokemon> appeared!".
class StoryWildBattle : public OverworldInterrupt{
public:
StoryWildBattle(Supplies& supplies, bool fight, bool late, StoryChecks checks, Language language)
StoryWildBattle(Supplies& supplies, bool fight, bool late, Pokemon::StoryCheckLevel checks, Language language)
: m_supplies(supplies)
, m_checks(checks)
, m_language(language)
Expand Down Expand Up @@ -758,7 +758,7 @@

private:
Supplies& m_supplies;
const StoryChecks m_checks;
const Pokemon::StoryCheckLevel m_checks;
const Language m_language;
const bool m_fight;
const bool m_late;
Expand All @@ -767,7 +767,7 @@
// A message: read to its end, then a trainer's battle if one starts.
class StoryMessage : public OverworldInterrupt{
public:
StoryMessage(Supplies& supplies, StoryChecks checks, Language language)
StoryMessage(Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language)
: m_supplies(supplies)
, m_checks(checks)
, m_language(language)
Expand All @@ -793,7 +793,7 @@

private:
Supplies& m_supplies;
const StoryChecks m_checks;
const Pokemon::StoryCheckLevel m_checks;
const Language m_language;
};

Expand Down Expand Up @@ -932,7 +932,7 @@

void recover_after_battle(
ConsoleHandle& console, ProControllerContext& context,
Supplies& supplies, StoryChecks checks, Language language
Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language
){
if (supplies.status == StatusCondition::POISON && supplies.antidotes > 0){
if (use_item_on_overworld(console, context, item_row(supplies, "antidote"), "antidote", checks, language)){
Expand All @@ -959,12 +959,12 @@

BattleEnd fight_battle(
ConsoleHandle& console, ProControllerContext& context,
Supplies& supplies, BattleKind kind, StoryChecks checks, Language language
Supplies& supplies, BattleKind kind, Pokemon::StoryCheckLevel checks, Language language
){
return BattleLoop(console, context, supplies, kind, checks, language).run();
}

OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language){
OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, Pokemon::StoryCheckLevel checks, Language language){
// Battles first: their screens are checked before the message box's.
OverworldInterruptSet ret;
ret.wild.emplace_back(std::make_unique<StoryWildBattle>(supplies, fight_wild, false, checks, language));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ bool battle_shows(const ImageViewRGB32& screen);
// different one isn't used.
BattleEnd fight_battle(
ConsoleHandle& console, ProControllerContext& context,
Supplies& supplies, BattleKind kind, StoryChecks checks, Language language
Supplies& supplies, BattleKind kind, Pokemon::StoryCheckLevel checks, Language language
);


Expand All @@ -188,15 +188,15 @@ BattleEnd fight_battle(
// The bag's inputs are not checked on the console yet.
void recover_after_battle(
ConsoleHandle& console, ProControllerContext& context,
Supplies& supplies, StoryChecks checks, Language language
Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language
);


// The interrupts for walking story routes. Wild battles are run from, or
// fought if `fight_wild`. A message is advanced until the overworld is
// back; a battle that starts after it (a trainer who saw the player) is
// fought. A battle lost (a blackout) throws OperationFailedException.
OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language);
OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, Pokemon::StoryCheckLevel checks, Language language);


// Registers AutoStory item usage unit tests.
Expand Down
Loading
Loading