Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
eae83ef
PokemonFRLG: 11.03, the Safari Zone to HM03 Surf and Fly back to Fuchsia
dayfine Nov 12, 2026
7929a7a
PokemonFRLG: the START menu's rows and contexts in their own file
dayfine Nov 12, 2026
ca937c0
Merge frlg/stage11-cycling-road into frlg/stage11-safari
dayfine Nov 12, 2026
36a2911
Merge frlg/stage11-cycling-road into frlg/stage11-safari
dayfine Nov 12, 2026
b386bfc
Merge branch 'frlg/stage11-cycling-road' into frlg/stage11-safari
dayfine Nov 12, 2026
e462f76
PokemonFRLG AutoStory: 11.03's item and attendant approaches end on t…
dayfine Nov 12, 2026
fd918b4
PokemonFRLG overworld: RouteStep::sign_ahead, sim long holds, Safari …
dayfine Nov 12, 2026
9d6bd73
PokemonFRLG overworld: no open leg ends facing a sign; a sign's messa…
dayfine Nov 12, 2026
9a320bf
FRLG ItemListReader: tests that plans' items have names (red)
dayfine Nov 12, 2026
2dd261c
FRLG ItemListReader: names for Full Restore, Super Potion, Moon Stone…
dayfine Nov 12, 2026
d6cfe38
FRLG ItemListReader: code health (header symbols tag, std::format)
dayfine Nov 12, 2026
5832016
Merge frlg/stage11-cycling-road into frlg/stage11-safari: upstream #1…
dayfine Nov 13, 2026
c3040f6
Merge frlg/stage11-cycling-road into frlg/stage11-safari
dayfine Nov 14, 2026
3d15fe0
Merge frlg/stage11-cycling-road into frlg/stage11-safari
dayfine Nov 14, 2026
29c1020
Merge frlg/stage11-cycling-road into frlg/stage11-safari
dayfine Nov 14, 2026
d24f89c
Merge frlg/stage11-cycling-road into frlg/stage11-safari
dayfine Nov 14, 2026
5848d03
Merge origin/frlg/stage11-cycling-road into frlg/stage11-safari
dayfine Nov 14, 2026
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 @@ -6,8 +6,10 @@

#include <algorithm>
#include <format>
#include <iterator>
#include <string>
#include <string_view>
#include <utility>
#include "Common/Cpp/Filesystem/Filesystem.h"
#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
Expand Down Expand Up @@ -38,6 +40,39 @@ constexpr double ROW_TOP = 11;
constexpr double ROW_STEP = 16;
constexpr double ROW_HEIGHT = 12;

// Each item's slug and its English name.
constexpr std::pair<std::string_view, std::string_view> ENGLISH_ITEM_NAMES[] = {
{"potion", "Potion"},
{"super-potion", "Super Potion"},
{"antidote", "Antidote"},
{"parlyz-heal", "Parlyz Heal"},
{"awakening", "Awakening"},
{"poke-ball", "Poke Ball"},
{"repel", "Repel"},
{"super-repel", "Super Repel"},
{"max-repel", "Max Repel"},
{"escape-rope", "Escape Rope"},
{"x-special", "X Special"},
{"x-speed", "X Speed"},
{"x-accuracy", "X Accuracy"},
{"guard-spec", "Guard Spec."},
{"bicycle", "Bicycle"},
// Route 17's hidden items. Without them a RARE CANDY read
// "FARE CANCY" and matched CANCEL: the pocket's read ended
// above it, and 11.02 counted no RARE CANDY in a bag with 2
// (console B, 2026-11-12).
{"rare-candy", "Rare Candy"},
{"max-elixir", "Max Elixir"},
// The Safari Zone's FULL RESTORE, which 11.03 counts. Without it its
// row matched several names and read as nothing (console B,
// 2026-11-12).
{"full-restore", "Full Restore"},
// Mt. Moon's, which top the pocket above the story's items.
{"moon-stone", "Moon Stone"},
{"nugget", "Nugget"},
{"cancel", "Cancel"},
};

class ItemNameMatcher : public OCR::SmallDictionaryMatcher{
public:
static constexpr double MAX_LOG10P = -1.40;
Expand Down Expand Up @@ -76,29 +111,7 @@ class ItemNameMatcher : public OCR::SmallDictionaryMatcher{

static JsonObject dictionary(){
JsonObject english;
for (const auto& [slug, name] : {
std::pair<std::string_view, std::string_view>{"potion", "Potion"},
{"antidote", "Antidote"},
{"parlyz-heal", "Parlyz Heal"},
{"awakening", "Awakening"},
{"poke-ball", "Poke Ball"},
{"repel", "Repel"},
{"super-repel", "Super Repel"},
{"max-repel", "Max Repel"},
{"escape-rope", "Escape Rope"},
{"x-special", "X Special"},
{"x-speed", "X Speed"},
{"x-accuracy", "X Accuracy"},
{"guard-spec", "Guard Spec."},
{"bicycle", "Bicycle"},
// Route 17's hidden items. Without them a RARE CANDY read
// "FARE CANCY" and matched CANCEL: the pocket's read ended
// above it, and 11.02 counted no RARE CANDY in a bag with 2
// (console B, 2026-11-12).
{"rare-candy", "Rare Candy"},
{"max-elixir", "Max Elixir"},
{"cancel", "Cancel"},
}){
for (const auto& [slug, name] : ENGLISH_ITEM_NAMES){
JsonArray names;
names.push_back(std::string(name));
english[std::string(slug)] = std::move(names);
Expand Down Expand Up @@ -139,6 +152,12 @@ std::string read_item_list_name(Logger& logger, Language language, const ImageVi
return ItemNameMatcher::instance().read(logger, language, extract_box_reference(game_box(screen), item_list_name_box(row)));
}

bool item_list_reader_knows(std::string_view item){
return std::any_of(std::begin(ENGLISH_ITEM_NAMES), std::end(ENGLISH_ITEM_NAMES), [&](const auto& entry){
return entry.first == item;
});
}

BagRow read_bag_row(Logger& logger, Language language, const ImageViewRGB32& screen, int shown){
std::string item = read_item_list_name(logger, language, screen, shown);
const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(shown));
Expand Down Expand Up @@ -242,6 +261,39 @@ class Test_Route17ItemNames : public UnitTest{
}
};

// 11.03's count (console B, 2026-11-12): the FULL RESTORE's row matched
// several names with no Full Restore in the dictionary, read as nothing,
// and the count saw 0 after the Safari Zone's ball was picked up. The
// other names the story counts or buys, and those it keeps rows for,
// are each read as themselves, and the shorter names they contain stay
// apart.
class Test_StoryItemNames : public UnitTest{
public:
Test_StoryItemNames()
: UnitTest("PokemonFRLG::ItemListReader - 11.03 the FULL RESTORE's row is read")
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
const ItemNameMatcher& matcher = ItemNameMatcher::instance();
for (const auto& [text, expected] : {
std::pair<std::string_view, std::string_view>{"FULL RESTORE", "full-restore"},
{"SUPER POTION", "super-potion"},
{"MOON STONE", "moon-stone"},
{"NUGGET", "nugget"},
{"POTION", "potion"},
{"REPEL", "repel"},
{"SUPER REPEL", "super-repel"},
{"MAX REPEL", "max-repel"},
}){
const std::string item = matcher.match(Language::English, std::string(text));
if (item != expected){
return std::format("Expected \"{}\" read as {}, got \"{}\".", text, expected, item);
}
}
return true;
}
};

// A capture of a Mart's BUY list, read from the top to its CANCEL. Its
// golden file holds each row's item, one per line.
class Test_MartList : public ImageUnitTest{
Expand Down Expand Up @@ -279,12 +331,14 @@ void add_tests_ItemListReader(UnitTestDatabase& database){
// the 3 read as nothing before the digit templates.
database.add<Test_BagPocket>("PokemonFRLG/ItemListReader/ItemsPocket_eng.png");
// Console B, 2026-11-03, the save before Cerulean's rival: a MOON STONE,
// which the reader has no name for, above the PARLYZ HEAL and 15 POTIONs.
// Stopping at it read nothing, and the rival was fought with 0 Potions.
// which the reader had no name for then, above the PARLYZ HEAL and 15
// POTIONs. Stopping at it read nothing, and the rival was fought with 0
// Potions.
database.add<Test_BagPocket>("PokemonFRLG/ItemListReader/ItemsPocketMoonStone_eng.png");
// The Viridian Mart's BUY list, the same day, the cursor on POTION.
database.add<Test_MartList>("PokemonFRLG/ItemListReader/MartBuyList_eng.png");
database.add<Test_Route17ItemNames>();
database.add<Test_StoryItemNames>();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
* Reads the item lists of the bag's pockets and of a Mart's BUY menu,
* which the game draws alike: rows 16 pixels apart from y 13, names from
* x 97 (pokefirered: the list window at tile (11, 1), item_X 9). It knows
* the names of the items a new game meets before the Boulder Badge, in
* English only so far: in another language a name is never read.
* the names of the items the story buys, uses or counts, in English only
* so far: in another language a name is never read.
*
*/
// code-health: allow header_symbols -- the plans' item check needs which names the reader has; a header for one query splits the reader's single concern

#ifndef PokemonAutomation_PokemonFRLG_ItemListReader_H
#define PokemonAutomation_PokemonFRLG_ItemListReader_H

#include <string>
#include <string_view>
#include <vector>
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
Expand All @@ -40,6 +42,10 @@ ImageFloatBox item_list_name_box(int row);
// reader has no names for.
std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row);

// Whether read_item_list_name() has a name for `item`, a slug as it gives
// them, in English.
bool item_list_reader_knows(std::string_view item);

// A single item entry in the bag pocket.
struct BagRow{
// The item's slug, as read_item_list_name() gives it; empty if its name
Expand All @@ -61,7 +67,7 @@ std::vector<BagRow> read_bag_pocket(Logger& logger, Language language, const Ima
// the CANCEL (not included). A row whose name can't be read stays, with an
// empty item, so the rows below keep their places: stopping there read
// nothing below a MOON STONE, and the rival was fought with 0 of the bag's
// 15 Potions (console B, 2026-11-03). Unread rows after the last name read
// 15 Potions (console B, 2026-11-03), before it had a name. Unread rows after the last name read
// are dropped. Empty if no name is read, as in a language the reader has
// no names for.
std::vector<BagRow> pocket_rows(std::vector<BagRow> reads);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ LateStop place_late_stop(
){
LateStop out;
out.verdict = Pokemon::classify_interrupt(log, {hold_start, now}, {});
if (out.verdict.kind == Pokemon::InterruptKind::DIALOG && step.sign_ahead){
// The sign past the end: only a hold run on from there reads it.
out.walked = WalkedTiles{.min = step.tiles, .max = step.tiles};
return out;
}
if (out.verdict.kind != Pokemon::InterruptKind::WILD_ENCOUNTER){
return out;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ int tile_reached(Milliseconds since_hold, Milliseconds tile_time, int tiles);
struct LateStop{
Pokemon::InterruptVerdict verdict;
// The tiles of the leg the player may be on. Set for a wild battle
// whose step the log times.
// whose step the log times, and for a message after a leg that ends
// below a sign (RouteStep::sign_ahead): its end.
std::optional<WalkedTiles> walked;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ constexpr std::string_view MAP_NAMES[] = {
"Route18",
"Route18_EastEntrance_1F",
"FuchsiaCity",
// The Safari Zone, pokeguy's way through it: its entrance, the
// center, east, north and west areas, and the Secret House (HM03).
"FuchsiaCity_SafariZone_Entrance",
"SafariZone_Center",
"SafariZone_East",
"SafariZone_North",
"SafariZone_West",
"SafariZone_SecretHouse",
"CeruleanCave_1F",
"CeruleanCave_2F",
"CeruleanCave_B1F",
Expand Down Expand Up @@ -211,6 +219,9 @@ TilePos map_point(const std::vector<MapData>& maps, const std::string& map, cons
bool warp_keeps_bike(const std::string& map){
static const std::set<std::string, std::less<>> MAPS{
"Route16_NorthEntrance_1F", "Route18_EastEntrance_1F", "Route16", "Route18",
// The Safari Zone's areas allow cycling, and their edge warps lead
// from one to the next (pokefirered SafariZone_* map.json).
"SafariZone_Center", "SafariZone_East", "SafariZone_North", "SafariZone_West",
};
return MAPS.contains(map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ std::set<std::string> map_flag_set(const std::vector<MapData>& maps, const std::

// Registers overworld map unit tests.
// Whether a warp onto `map` leaves a rider on the Bicycle: the Cycling
// Road's gates (allow_cycling in pokefirered's map.json) and the routes
// their doors open onto. Every other door takes the player off (console
// Road's gates (allow_cycling in pokefirered's map.json), the routes
// their doors open onto, and the Safari Zone's areas, whose edge warps
// lead from one to the next (not measured). Every other door takes the player off (console
// B, 2026-11-12 01:05: through Route 16's north gate the player still
// rode, and a run-paced open leg after it overshot the Fly house's door).
bool warp_keeps_bike(const std::string& map);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Route

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=638 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -33,6 +33,7 @@
{RouteCost::OPEN_WILD_STOP, 300},
{RouteCost::SIGHT_TILE, 0},
{RouteCost::SIGHT_OVERSHOOT, 0},
{RouteCost::SIGN_OVERSHOOT, 3},
};
return COSTS;
}
Expand Down Expand Up @@ -218,6 +219,14 @@
return warp != nullptr && !take_warp(maps, warp);
}

// Whether holding `direction` from `here` reads a sign: one walked into
// moving north or south shows its message (pokefirered
// TrySetUpWalkIntoSignpostScript()).
bool reads_sign_ahead(const MapData& map, TilePos here, Direction direction){
return tile_at(map, here.next(direction)) == TileKind::SIGN
&& (direction == Direction::NORTH || direction == Direction::SOUTH);
}

// Whether holding `direction` stops the player where they are: a wall, or
// water they'd need to Surf onto. A leg that ends there can be
// held for longer than it takes, and walked again after an interruption. A
Expand All @@ -239,7 +248,7 @@
// Held into a sign moving north or south, the game shows the sign's
// message: the player stops, but the walk is interrupted (console B,
// 2026-11-01, the poster on the bedroom's wall).
if (tile_at(map, ahead) == TileKind::SIGN && (direction == Direction::NORTH || direction == Direction::SOUTH)){
if (reads_sign_ahead(map, player.state.position, direction)){
return false;
}
// Held into a ledge the way it faces, the player hops down it (console
Expand Down Expand Up @@ -314,6 +323,9 @@
return stops_at(m_maps, state, direction);
}
int open_stop_risk(const State& state, Direction direction) const{
if (reads_sign_ahead(m_maps[state.map], state.state.position, direction)){
return route_cost(m_costs, RouteCost::SIGN_OVERSHOOT);
}
const std::optional<Transition> past = PokemonFRLG::press(m_maps, state, direction);
if (!past || !seen_by_trainer(past->next)){
return 0;
Expand Down Expand Up @@ -396,7 +408,7 @@
}
}

RouteStep to_route_step(const std::vector<MapData>& maps, const Pokemon::Leg<Located>& leg){

Check warning on line 411 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::to_route_step( const std :: vector<MapData> & maps , const Pokemon :: Leg<Located> & leg): function_lines=39 (advisory above 25, limit 50)
RouteStep step;
switch (leg.kind){
case Pokemon::LegKind::WALK:
Expand Down Expand Up @@ -427,6 +439,7 @@
step.spin_tiles = last_spin_tiles(maps, leg);
step.to_wall = step.to_wall && !step.spin_tiles;
step.tapped = !step.surfing && onto_warp_sideways(maps[leg.end.map], step);
step.sign_ahead = !step.to_wall && !step.warps && reads_sign_ahead(maps[leg.end.map], leg.end.state.position, step.direction);
}
const std::vector<MapPosition> tiles = leg_tiles(maps, MapPosition{maps[leg.start.map].name, leg.start.state.position}, step);
for (int c : std::views::iota(1, (int)tiles.size()) | std::views::filter([&](int n){ return tiles[n].map != tiles[n - 1].map; })){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ enum class RouteCost{
// to (19, 6), in the Grunt's line). Below SIGHT_TILE: it takes a
// missed stop to cost the battle.
SIGHT_OVERSHOOT,
// Extra for an open leg north or south that ends below or above a
// sign: a hold that runs on reads it, and the walk is interrupted
// (console B, 2026-11-12, 11.03: "north 5" to Safari Zone West's
// (27, 10) on the Bicycle). A tie-break more than a detour.
SIGN_OVERSHOOT,
};
// Cost mapping table for path planning.
using RouteCosts = std::map<RouteCost, int>;

// TILE 1, TURN 2, WARP 30, SURF 40, GRASS_TILE 20, OPEN_STOP 8,
// OPEN_WILD_STOP 300, SIGHT_TILE 0, SIGHT_OVERSHOOT 0. The sight costs are
// OPEN_WILD_STOP 300, SIGHT_TILE 0, SIGHT_OVERSHOOT 0, SIGN_OVERSHOOT 3.
// The sight costs are
// off by default until beaten trainers and battles a story step wants are
// told apart: at 100 and 10 they moved Pewter City's and Pewter Gym's
// plans (the Gym's Camper is fought on the way to Brock).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ struct RouteStep{
// tall grass or water. Elsewhere (indoors, streets) no wild battle can
// start, so the walker doesn't watch for one.
bool wild = false;
// WALK, open, north or south: the tile past the end is a sign. A hold
// that runs on reads it, so a message after the hold, not a battle,
// leaves the player on the end (console B, 2026-11-12, 11.03: "north 5"
// to Safari Zone West's (27, 10), below the sign on (27, 9)).
bool sign_ahead = false;
// WALK: the steps (from 1) onto a connected map. The game holds the
// player up a tile before each while it loads the map: a hold timed
// by the tiles alone ended a tile short (console B, 2026-11-03, rows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Sim

Check failure on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

<file>: file_lines=1013, limit=1000, allowed 1009
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -552,7 +552,9 @@
m_last_tap.reset();
}else{
const auto short_hold = m_script.short_holds.find(m_holds);
walk_hold(direction, duration, short_hold == m_script.short_holds.end() ? 0 : short_hold->second);
const auto long_hold = m_script.long_holds.find(m_holds);
const Milliseconds over = long_hold == m_script.long_holds.end() ? Milliseconds(0) : tile_time() * long_hold->second;
walk_hold(direction, duration + over, short_hold == m_script.short_holds.end() ? 0 : short_hold->second);
}
return watch_until(watchers, start, start + std::max(duration + release, watch));
}
Expand Down Expand Up @@ -920,8 +922,10 @@
return std::nullopt;
}
const WallClock start = sim_wall_clock(m_leg_start);
RouteStep placed = step;
placed.sign_ahead = step.sign_ahead && m_rules.place_by_sign;
const LateStop stop = place_late_stop(
step, TILE_TIME, screen_event_log(m_sim.state(), m_leg_start), start, sim_wall_clock(m_sim.state().time)
placed, TILE_TIME, screen_event_log(m_sim.state(), m_leg_start), start, sim_wall_clock(m_sim.state().time)
);
m_log.push_back(late_stop_line(step, stop, start));
return m_leg_dark ? std::optional<WalkedTiles>(dark_stop(step, whole_leg(step))) : stop.walked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ struct SimWalkerRules{
// player may be anywhere on the leg: on Route 10, "east 11" was found
// again from all 12 of its tiles (console B, 2026-11-09, 07.02 run 2).
bool place_late_battle = true;
// A message after the hold of an open leg that ends below a sign
// (RouteStep::sign_ahead) places the player on its end. Without it
// the walker found the player at walls and held the same leg into the
// sign 9 times (console B, 2026-11-12, 11.03, Safari Zone West).
bool place_by_sign = true;
// The watch for a warp's fade starts with the hold onto the warp
// (Pokemon::WatchAlong), not when it ends. Without it a fade over
// before the hold ended was missed, and the walk stopped on "no fade in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct SimScript{
// The hold numbered by the key (from 1) stops this many tiles short,
// with nothing on screen (the forest drift, console B, 2026-11-01).
std::map<int, int> short_holds;
// The hold numbered by the key (from 1) runs on this many tiles past
// its time: on the Bicycle, "north 5" to Safari Zone West's (27, 10)
// read the sign above it (console B, 2026-11-12, 11.03).
std::map<int, int> long_holds;
// Maps where every step can start a wild battle, also on tiles the maps
// don't mark as grass: Mt. Moon B2F's tiles closed on one side ('8')
// are cave floor too (console B, 2026-11-03).
Expand Down
Loading
Loading