diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp index 96f61bf5e2..e0af276247 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -75,6 +75,10 @@ class ItemNameMatcher : public OCR::SmallDictionaryMatcher{ {"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"}, {"cancel", "Cancel"}, }){ @@ -92,33 +96,43 @@ ImageViewRGB32 game_box(const ImageViewRGB32& screen){ return extract_box_reference(screen, GameSettings::instance().GAME_BOX); } +// Where row `row` of the bag shows its item count. +ImageFloatBox bag_item_count_box(int row){ + return ImageFloatBox(208.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 15.0 / 240, ROW_HEIGHT / 160); +} + } // namespace ImageFloatBox item_list_name_box(int row){ return ImageFloatBox(96.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 72.0 / 240, ROW_HEIGHT / 160); } -ImageFloatBox bag_item_count_box(int row){ - return ImageFloatBox(208.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 15.0 / 240, ROW_HEIGHT / 160); -} std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row){ return ItemNameMatcher::instance().read(logger, language, extract_box_reference(game_box(screen), item_list_name_box(row))); } +BagRow read_bag_row(Logger& logger, Language language, const ImageViewRGB32& screen, int shown){ + const std::string item = read_item_list_name(logger, language, screen, shown); + if (item == "cancel"){ + return BagRow{item, 0}; + } + const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(shown)); + // Not Tesseract on each waterfilled digit: the font joins some strokes + // only at a corner, so the 5 and the 3 fell apart into pieces and read + // as nothing (console B, 2026-11-02). The stat boxes' templates are + // the same digits on the same cream. + return BagRow{item, read_digits_waterfill_template(logger, count, DigitTemplateType::StatBox)}; +} + std::vector read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen){ std::vector rows; for (int row = 0; row < ITEM_LIST_ROWS; row++){ - const std::string item = read_item_list_name(logger, language, screen, row); - if (item == "cancel"){ + BagRow read = read_bag_row(logger, language, screen, row); + if (read.item == "cancel"){ break; } - const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(row)); - // Not Tesseract on each waterfilled digit: the font joins some strokes - // only at a corner, so the 5 and the 3 fell apart into pieces and read - // as nothing (console B, 2026-11-02). The stat boxes' templates are - // the same digits on the same cream. - rows.push_back(BagRow{item, read_digits_waterfill_template(logger, count, DigitTemplateType::StatBox)}); + rows.push_back(std::move(read)); } return pocket_rows(std::move(rows)); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h index 6565fcbfdd..1b9c63a277 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h @@ -29,11 +29,9 @@ namespace PokemonFRLG{ // Rows a list shows at once. constexpr int ITEM_LIST_ROWS = 6; -// Where row `row` (from 0) of a list shows its item's name, and in the bag -// its count, as fractions of the game screen. +// Where row `row` (from 0) of a list shows its item's name, as fractions +// of the game screen. ImageFloatBox item_list_name_box(int row); -// Where row `row` of the bag shows its item count. -ImageFloatBox bag_item_count_box(int row); // The item named in row `row`: a slug such as "potion", "antidote", // "parlyz-heal", "awakening", "poke-ball", "repel", @@ -51,6 +49,10 @@ struct BagRow{ int count = 0; }; +// The item and count shown in row `shown` (from 0) of the bag's open +// pocket; an empty item if its name can't be read. +BagRow read_bag_row(Logger& logger, Language language, const ImageViewRGB32& screen, int shown); + // The rows of the bag's open pocket from the top, as pocket_rows() keeps // them. The pocket must be scrolled to its top. std::vector read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp index 3933913e12..455eb7e731 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp @@ -80,6 +80,7 @@ class PlaceNameMatcher : public OCR::SmallDictionaryMatcher{ {"vermilion-city", "Vermilion City"}, {"celadon-city", "Celadon City"}, {"rocket-hideout", "Rocket Hideout"}, + {"pokemon-tower", "Pokemon Tower"}, }){ JsonArray names; names.push_back(std::string(name)); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp index 824acd9c5f..9fd3102219 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp @@ -48,7 +48,7 @@ constexpr double CURSOR_EDGE_LEFT = 120; constexpr double CURSOR_EDGE_TOP = 24; constexpr double CURSOR_EDGE_HEIGHT = 16; -// The level-up moves of Squirtle's, Magikarp's and Oddish's lines (pret +// The level-up moves of Squirtle's, Magikarp's, Oddish's and Pidgey's lines (pret // pokefirered src/data/pokemon/level_up_learnsets.h), then the TMs' // and HMs' moves not among them (src/data/items.h; Hyper Beam, Protect // and Rain Dance are above), as the game writes them @@ -83,6 +83,14 @@ constexpr std::pair MOVE_NAMES[] = { {"aromatherapy", "Aromatherapy"}, {"mega-drain", "Mega Drain"}, {"magical-leaf", "Magical Leaf"}, + {"sand-attack", "Sand-Attack"}, + {"gust", "Gust"}, + {"quick-attack", "Quick Attack"}, + {"whirlwind", "Whirlwind"}, + {"wing-attack", "Wing Attack"}, + {"feather-dance", "FeatherDance"}, + {"agility", "Agility"}, + {"mirror-move", "Mirror Move"}, {"hyper-beam", "Hyper Beam"}, {"focus-punch", "Focus Punch"}, {"dragon-claw", "Dragon Claw"}, @@ -354,6 +362,11 @@ void add_tests_SummaryMovesReader(UnitTestDatabase& database){ // FireRed on console B, 2026-11-03: the Oddish caught for Cut, Lv12, with // ABSORB, SWEET SCENT and two empty slots. database.add("PokemonFRLG/SummaryMovesReader/Oddish_KnownMoves_eng.png"); + // FireRed on console B, 2026-11-12 (10.01 teach_fly): the Route 7 + // Pidgey, Lv22, with SAND-ATTACK, GUST, QUICK ATTACK and WHIRLWIND, + // read as attract, ?, attract and steel-wing before its line's moves + // were in MOVE_NAMES. + database.add("PokemonFRLG/SummaryMovesReader/Pidgey_KnownMoves_eng.png"); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_CodedRooms.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_CodedRooms.cpp index 4a92687740..687f583705 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_CodedRooms.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_CodedRooms.cpp @@ -118,6 +118,18 @@ constexpr std::string_view LIFT_ROOM_JSON = R"({ "warps": [{"x": 2, "y": 5, "enter": "walk_south"}] })"; +// LAYOUT_CELADON_CITY_DEPARTMENT_STORE_ELEVATOR: the hideout lift's +// map.bin, the panel's bg events at (0, 2) and (4, 1), warp 0 at (2, 5) +// (the MB_SOUTH_ARROW_WARP tile, where the floors' doors land) and warp 1 +// at (2, 6), in the wall row, never reached. +constexpr std::string_view DEPT_STORE_LIFT_ROOM_JSON = R"({ + "name": "CeladonCity_DepartmentStore_Elevator", + "source": {"decomp_file": "data/layouts/CeladonCity_DepartmentStore_Elevator/map.bin", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", "date": "2026-11-11"}, + "tiles": ["#####", "####S", "S####", ".....", ".....", ".....", "#####"], + "points": {"warp_0": [2, 5], "warp_1": [2, 6]}, + "warps": [{"x": 2, "y": 5, "enter": "walk_south"}] +})"; + } // namespace @@ -206,6 +218,21 @@ const std::vector& rocket_hideout_lift_exits(){ return EXITS; } +MapData department_store_lift_room(){ + return parse_map(std::string(DEPT_STORE_LIFT_ROOM_JSON), std::string(DEPT_STORE_LIFT_MAP)); +} + +const std::vector& department_store_lift_exits(){ + static const std::vector EXITS{ + {"CeladonCity_DepartmentStore_5F", {6, 2}}, + {"CeladonCity_DepartmentStore_4F", {6, 2}}, + {"CeladonCity_DepartmentStore_3F", {6, 2}}, + {"CeladonCity_DepartmentStore_2F", {6, 2}}, + {"CeladonCity_DepartmentStore_1F", {6, 2}}, + }; + return EXITS; +} + } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.cpp new file mode 100644 index 0000000000..56a16709a7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.cpp @@ -0,0 +1,47 @@ +/* Fly Map + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonFRLG_FlyMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +const std::vector& kanto_fly_towns(){ + static const std::vector TOWNS{ + {"PalletTown", {4, 11}, {"PalletTown", {6, 8}}}, + {"ViridianCity", {4, 8}, {"ViridianCity", {26, 27}}}, + {"PewterCity", {4, 4}, {"PewterCity", {17, 26}}}, + {"Route4", {8, 3}, {"Route4", {12, 6}}}, + {"CeruleanCity", {14, 3}, {"CeruleanCity", {22, 20}}}, + {"VermilionCity", {14, 9}, {"VermilionCity", {15, 7}}}, + {"Route10", {18, 3}, {"Route10", {13, 21}}}, + {"LavenderTown", {18, 6}, {"LavenderTown", {6, 6}}}, + {"CeladonCity", {11, 6}, {"CeladonCity", {48, 12}}}, + {"SaffronCity", {14, 6}, {"SaffronCity", {24, 39}}}, + {"FuchsiaCity", {12, 12}, {"FuchsiaCity", {25, 32}}}, + {"CinnabarIsland", {4, 14}, {"CinnabarIsland", {14, 12}}}, + {"IndigoPlateau", {2, 3}, {"IndigoPlateau_Exterior", {11, 7}}}, + }; + return TOWNS; +} + +std::optional fly_town_index(std::string_view name){ + const std::vector& towns = kanto_fly_towns(); + for (size_t c = 0; c < towns.size(); c++){ + if (towns[c].name == name){ + return c; + } + } + return std::nullopt; +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.h new file mode 100644 index 0000000000..3748436f1e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.h @@ -0,0 +1,57 @@ +/* Fly Map + * + * From: https://github.com/PokemonAutomation/ + * + * The towns Fly takes the player to in Kanto: each one's cell on the fly + * map and the tile the player lands on. Cells are pokefirered's + * sRegionMapSections_Kanto (src/data/region_map/region_map_layout_kanto.h, + * 22 x 15, the cursor's x and y); landing tiles its heal locations + * (src/data/heal_locations.json), which Fly warps to (SetFlyWarpDestination() + * in src/region_map.c). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_FlyMap_H +#define PokemonAutomation_PokemonFRLG_FlyMap_H + +#include +#include +#include +#include +#include +#include "PokemonFRLG_OverworldRouteSteps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A place on the fly map Fly can take the player to. +struct FlyTown{ + // The map's name, as a step names the town ("CeladonCity", "Route4"). + std::string name; + // The town's cell on the fly map: the presses right and down from its + // top-left corner, where a hold up-left leaves the cursor + // (HandleRegionMapInput() stops it at 0). + TilePos cell; + // The tile Fly lands the player on: below the Pokemon Center's door, + // or Pallet Town's player's house. + MapPosition landing; +}; + +// Kanto's Fly destinations, Pallet Town first. +const std::vector& kanto_fly_towns(); +// The index of the town named `name` in kanto_fly_towns(), if it is one. +std::optional fly_town_index(std::string_view name); + +// The fly map's width in cells (MAP_WIDTH in region_map.c). +constexpr int FLY_MAP_COLUMNS = 22; +// The fly map's height in cells (MAP_HEIGHT in region_map.c). +constexpr int FLY_MAP_ROWS = 15; + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_HideoutLiftRoom.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_HideoutLiftRoom.h index 36f1d147b2..8daf33cc36 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_HideoutLiftRoom.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_HideoutLiftRoom.h @@ -38,6 +38,20 @@ MapData rocket_hideout_lift_room(); // and (20, 24) (console B, 2026-11-11, B4F). const std::vector& rocket_hideout_lift_exits(); +// The Celadon Department Store's lift: the same layout as the hideout's +// (LAYOUT_CELADON_CITY_DEPARTMENT_STORE_ELEVATOR's map.bin is byte for +// byte LAYOUT_ROCKET_HIDEOUT_ELEVATOR's), so the same LIFT_ARRIVAL and +// LIFT_PANEL_FRONT. Its floors' lift doors lead to its warp 0, (2, 5). +inline constexpr std::string_view DEPT_STORE_LIFT_MAP = "CeladonCity_DepartmentStore_Elevator"; +// The store lift's room, under DEPT_STORE_LIFT_MAP. Its door is a dynamic +// warp, as the hideout's (SimScript::lift_floors with +// department_store_lift_exits()). +MapData department_store_lift_room(); +// Where it lets out for each floor on its panel, top first: every floor's +// lift door is (6, 1) (setdynamicwarp ..., 255, 6, 1 in its scripts), and +// the player is walked a tile south off it, onto (6, 2). +const std::vector& department_store_lift_exits(); + } // namespace PokemonFRLG } // namespace NintendoSwitch diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp index e5d20f0607..583fe96027 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp @@ -24,6 +24,15 @@ std::optional facing_before(const BikeTapCalls& calls){ return calls.facing(); } +// On foot, a tap by a player read facing another way before it only +// turns them (MovementMechanics: 70 of 70 turned), whatever the screen +// showed: the screen check read the turn south before 10.04's "south 3" +// as a step, and the leg ended a tile short of the Pokemon Tower 3F +// stairs (console B, 2026-11-12 03:08). +bool only_turns(const std::optional& before, const RouteStep& step){ + return before && *before != step.direction; +} + } // namespace StepOutcome count_bike_taps(const RouteStep& step, const BikeTapCalls& calls){ @@ -31,18 +40,27 @@ StepOutcome count_bike_taps(const RouteStep& step, const BikeTapCalls& calls){ for (int tap = 1; tap <= step.tiles; tap++){ std::optional before = facing_before(calls); BikeTap result = calls.tap(tap); - for (int retry = 1; retry < calls.tries && !result.moved && !result.interrupt && !result.cleared_late; retry++){ - if (!before || *before == step.direction){ + for (int retry = 1; retry < calls.tries && !result.interrupt && !result.cleared_late; retry++){ + if (result.moved && !only_turns(before, step)){ + break; + } + if (!result.moved && !only_turns(before, step)){ calls.log(std::format( "Taps: tap {} of {} showed no step, facing {} before it: not tapping again, it may have stepped unseen.", tap, step.tiles, before ? Pokemon::direction_name(*before) : "an unknown way" )); break; } - calls.log(std::format("Taps: tap {} of {} didn't move: tapping again, it only turned the player.", tap, step.tiles)); + calls.log(std::format( + "Taps: tap {} of {} from facing {} only turned the player{}: tapping again.", + tap, step.tiles, Pokemon::direction_name(*before), result.moved ? ", though the screen changed" : "" + )); before = facing_before(calls); result = calls.tap(tap); } + if (result.moved && only_turns(before, step)){ + result.moved = false; + } if (result.interrupt || result.cleared_late){ calls.log(std::format("Bike: tap {} of {}: interrupted after {} tile(s).", tap, step.tiles, moved)); if (result.interrupt){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp index 3780ad147a..8a623e2745 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp @@ -133,6 +133,15 @@ std::optional exit_mat(const MapData& map, const TilePos& point){ bool walks_out_on_arrival(const MapData& map, const TilePos& point){ return is_door(map, point) || warp_entry(map, point) == WarpEntry::CAVE_ENTRANCE; } +std::optional arrival_facing(const MapData& map, const TilePos& point){ + if (walks_out_on_arrival(map, point)){ + return Direction::SOUTH; + } + if (const std::optional taken = exit_mat(map, point)){ + return opposite(*taken); + } + return std::nullopt; +} void hide_objects(MapData& map, const std::set& flags){ std::vector shown; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp index f6d168d32a..cc3802327d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp @@ -99,6 +99,29 @@ constexpr std::string_view MAP_NAMES[] = { "RocketHideout_B2F", "RocketHideout_B3F", "RocketHideout_B4F", + // The Pokemon Tower to Mr. Fuji, and his house in Lavender Town. + "PokemonTower_1F", + "PokemonTower_2F", + "PokemonTower_3F", + "PokemonTower_4F", + "PokemonTower_5F", + "PokemonTower_6F", + "PokemonTower_7F", + "LavenderTown_VolunteerPokemonHouse", + // Celadon Mansion's floors to the roof room's Eevee. + "CeladonCity_Condominiums_1F", + "CeladonCity_Condominiums_2F", + "CeladonCity_Condominiums_3F", + "CeladonCity_Condominiums_Roof", + "CeladonCity_Condominiums_RoofRoom", + // The Department Store's 1F and its 5F's X items, by the lift (coded: + // department_store_lift_room()). + "CeladonCity_DepartmentStore_1F", + "CeladonCity_DepartmentStore_5F", + // Route 16's house with HM02 Fly, past the Cut tree and the north gate. + "Route16", + "Route16_NorthEntrance_1F", + "Route16_House", "CeruleanCave_1F", "CeruleanCave_2F", "CeruleanCave_B1F", @@ -179,6 +202,13 @@ TilePos map_point(const std::vector& maps, const std::string& map, cons throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No point \"" + point + "\" on map " + map + "."); } +bool warp_keeps_bike(const std::string& map){ + static const std::set> MAPS{ + "Route16_NorthEntrance_1F", "Route18_EastEntrance_1F", "Route16", "Route18", + }; + return MAPS.contains(map); +} + std::set map_flag_set(const std::vector& maps, const std::string& name){ std::set flags; for (const MapData& map : maps){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h index 5f0b05d189..47d4bd43cf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h @@ -65,6 +65,13 @@ std::set map_flag_set(const std::vector& 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 +// 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); + void add_tests_OverworldMaps(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp index 86c1d11d41..b66999a143 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp @@ -24,6 +24,7 @@ #include "PokemonFRLG_OverworldRecoveryWalk.h" #include "PokemonFRLG_BikeSpinPresses.h" #include "PokemonFRLG_OverworldBike.h" +#include "PokemonFRLG_OverworldMaps.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -453,7 +454,7 @@ void walk_overworld_route_with_recovery( from_facing = std::nullopt; } const StepOutcome outcome = walk_and_watch(console, context, step, from_facing, interrupts, riding ? speed : on_foot(speed), player); - if (riding && step.warps){ + if (riding && step.warps && !warp_keeps_bike(step.end.map)){ console.log("Bike: through the warp to " + step.end.map + ", off the Bicycle."); riding = false; } @@ -461,7 +462,7 @@ void walk_overworld_route_with_recovery( }; calls.hold_to_warp = [&](const RouteStep& step){ hold_to_warp(console, context, step, step.wild ? interrupts.wild : interrupts.other, riding ? speed : on_foot(speed)); - riding = false; + riding = riding && warp_keeps_bike(step.end.map); }; calls.log = [&](const std::string& message){ console.log(message, COLOR_ORANGE); }; calls.fail = [&](const std::string& message){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp index 67361691c5..7c8911964b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp @@ -83,7 +83,9 @@ struct Transition{ Located next; RouteAction action = RouteAction::WALK; bool warped = false; - bool walked_out = false; // the warp ended with the game walking the player out + // The way the warp left the player facing (arrival_facing()), if not + // the way they moved. + std::optional facing; bool dismounted = false; // stepped off the water onto land // The step landed on a spinner, which slid the player on: how far, // and the way they last moved. @@ -106,9 +108,9 @@ std::optional take_warp(const std::vector& maps, const MapW } TilePos position = arrival->second; Transition transition; + transition.facing = arrival_facing(map, position); if (walks_out_on_arrival(map, position)){ position = position.next(Direction::SOUTH); - transition.walked_out = true; } transition.next.map = destination; transition.next.state = PlayerState{position, elevation_at(map, position), false}; @@ -285,7 +287,7 @@ class StepModel{ // A slide ends the leg: the hold must let go on the spinner. step.ends_leg = transition->warped || transition->dismounted || transition->spin; step.warped = transition->warped; - step.facing = transition->walked_out ? Direction::SOUTH : direction; + step.facing = transition->facing.value_or(direction); if (transition->spin){ step.facing = transition->spin->facing; step.extra_cost += transition->spin->tiles * route_cost(m_costs, RouteCost::TILE); @@ -360,6 +362,40 @@ std::optional last_spin_tiles(const std::vector& maps, const Pokem return transition->spin->tiles; } +// Whether WALK `step` ends on stairs at the side of a room, or an exit +// mat, going another way than its warp is taken, and not at a wall. The +// press the warp's way finds the warp only if the leg ended on its tile: +// a tile off, it meets the wall beside the stairs. So the leg is tapped, a +// tap a tile checked to have moved (10.05 tower_6f_stairs: "south 3 +// (open)" onto Pokemon Tower 5F's stairs (18, 10) ended a tile short; +// console B, 2026-11-12 03:41). +bool onto_warp_sideways(const MapData& map, const RouteStep& step){ + const std::optional taken = exit_mat(map, step.end.point); + return taken && *taken != step.direction && !step.warps && !step.to_wall && !step.spin_tiles; +} + +// Taps the open legs before each tapped leg in `route`, back to the start +// or a leg that ends where the walk knows the player is (a wall, a warp), +// so a leg onto stairs from the side starts from a known tile (Pokemon +// Tower 2F's "west 12" before "south 4" onto the stairs (4, 10)). +void tap_from_known_tile(std::vector& route){ + for (size_t c = route.size(); c-- > 1;){ + if (!route[c].tapped){ + continue; + } + for (size_t before = c; before-- > 0;){ + RouteStep& step = route[before]; + if (step.action == RouteAction::FACE){ + continue; + } + if (step.action != RouteAction::WALK || step.surfing || step.warps || step.to_wall || step.spin_tiles || step.tapped){ + break; + } + step.tapped = true; + } + } +} + RouteStep to_route_step(const std::vector& maps, const Pokemon::Leg& leg){ RouteStep step; switch (leg.kind){ @@ -390,6 +426,7 @@ RouteStep to_route_step(const std::vector& maps, const Pokemon::Leg 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; })){ @@ -419,7 +456,7 @@ std::optional predict_overworld_press( .position = {maps[next->next.map].name, next->next.state.position}, .elevation = next->next.state.elevation, .surfing = next->next.state.surfing, - .facing = next->spin ? next->spin->facing : next->walked_out ? Direction::SOUTH : direction, + .facing = next->spin ? next->spin->facing : next->facing.value_or(direction), }, .warped = next->warped, }; @@ -459,6 +496,7 @@ std::optional> plan_overworld_route( for (const Pokemon::Leg& leg : *legs){ route.push_back(to_route_step(maps, leg)); } + tap_from_known_tile(route); return route; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp index 880e331e4b..96e927ee10 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp @@ -14,6 +14,7 @@ #include "PokemonFRLG_OverworldReanchor.h" #include "PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_OverworldBike.h" +#include "PokemonFRLG_OverworldMaps.h" #include "PokemonFRLG_OverworldSim.h" namespace PokemonAutomation{ @@ -22,7 +23,6 @@ namespace PokemonFRLG{ using namespace std::chrono_literals; - std::string_view sim_screen_name(SimScreen screen){ switch (screen){ case SimScreen::OVERWORLD: @@ -168,6 +168,7 @@ void OverworldSim::update_view(){ m_state.black_below = map().connections.empty() && map().tiles.height <= SMALL_ROOM_ROWS && m_player.position.y >= map().tiles.height - BLACK_BELOW_ROWS; m_state.dark = m_script.dark_maps.contains(map().name); + m_state.surfing = m_player.surfing; } void OverworldSim::schedule(Milliseconds at, SimScreen screen, bool unfreeze){ @@ -263,11 +264,11 @@ std::optional OverworldSim::take_warp(int map_index, const T return std::nullopt; } TilePos position = arrival->second; - const bool walked_out = walks_out_on_arrival(to, position); - if (walked_out){ + const std::optional facing = arrival_facing(to, position); + if (walks_out_on_arrival(to, position)){ position = position.next(Direction::SOUTH); } - return Step{destination, PlayerState{position, elevation_at(to, position), false}, true, walked_out, false}; + return Step{destination, PlayerState{position, elevation_at(to, position), false}, true, facing, false}; } std::optional OverworldSim::cross_edge(Direction direction) const{ @@ -286,10 +287,10 @@ std::optional OverworldSim::cross_edge(Direction direction) case Direction::EAST: point.x = 0; break; } const StepKind kind = classify_step_onto(map(), m_player, direction, to, point); - if (kind != StepKind::WALK){ + if (kind != StepKind::WALK && kind != StepKind::STOP_SURFING){ return std::nullopt; } - return Step{destination, after_step_onto(map(), m_player, to, point, kind), false, false, false}; + return Step{destination, after_step_onto(map(), m_player, to, point, kind), false, std::nullopt, false}; } return std::nullopt; } @@ -310,13 +311,13 @@ std::optional OverworldSim::press(Direction direction) const } if (ledge_direction(tile_at(map(), ahead)) == direction){ const TilePos landed = ahead.next(direction); - return Step{m_map, PlayerState{landed, elevation_at(map(), landed), false}, false, false, true}; + return Step{m_map, PlayerState{landed, elevation_at(map(), landed), false}, false, std::nullopt, true}; } const StepKind kind = classify_step(map(), m_player, direction); - if (kind != StepKind::WALK){ + if (kind != StepKind::WALK && kind != StepKind::STOP_SURFING){ return std::nullopt; } - Step step{m_map, after_step_onto(map(), m_player, map(), ahead, kind), false, false, false}; + Step step{m_map, after_step_onto(map(), m_player, map(), ahead, kind), false, std::nullopt, false}; if (warps_on_step(map(), ahead)){ return take_warp(m_map, ahead); } @@ -369,11 +370,8 @@ bool OverworldSim::after_step(const Step& step, Milliseconds pressed){ update_view(); if (step.warped){ m_state.warps++; - for (auto& [index, tree] : m_cut_trees){ - m_maps[index].objects.push_back(tree); - } - m_cut_trees.clear(); - if (m_state.on_bike){ + regrow_cut_trees(); + if (m_state.on_bike && !warp_keeps_bike(map().name)){ // A door takes the player off (the user's; not measured). m_state.on_bike = false; note("the warp takes the player off the Bicycle."); @@ -511,8 +509,8 @@ void OverworldSim::take_steps(Direction direction, Milliseconds pressed, Millise return; } } - if (step->walked_out){ - m_state.facing = Direction::SOUTH; + if (step->facing){ + m_state.facing = *step->facing; } pressed += after_slide(*step); if (after_step(*step, pressed)){ @@ -623,18 +621,20 @@ void OverworldSim::hold_on(Direction direction, Milliseconds end){ press.end = end; } -bool OverworldSim::hides_moved_step_tap(){ - m_state.moved_step_taps++; - if (!m_script.unseen_step_taps.contains(m_state.moved_step_taps)){ - return false; +bool OverworldSim::reads_step_tap_as_step(const MapPosition& before, int turn_taps_before){ + const bool moved = !(m_state.position == before); + m_state.moved_step_taps += moved ? 1 : 0; + const bool misread = moved ? m_script.unseen_step_taps.contains(m_state.moved_step_taps) + : m_state.turn_taps > turn_taps_before && m_script.seen_turn_taps.contains(m_state.turn_taps); + if (misread){ + note(moved ? std::format("step tap {} moves the player, read as not moved.", m_state.moved_step_taps) : std::format("turn tap {} only turns the player, read as a step.", m_state.turn_taps)); } - note(std::format("step tap {} moves the player, read as not moved.", m_state.moved_step_taps)); - return true; + return moved != misread; } bool OverworldSim::drops_turn_tap(){ - m_turn_taps++; - return m_script.dropped_turn_taps.contains(m_turn_taps); + m_state.turn_taps++; + return m_script.dropped_turn_taps.contains(m_state.turn_taps); } std::optional OverworldSim::watch(const std::vector& watchers, Milliseconds duration){ @@ -821,7 +821,7 @@ bool OverworldSimWalker::after_warp(const RouteStep& step, int warps_before, Mil m_sim.tap(step.direction, STEP_TAP, STEP_TAP_RELEASE); } } - if (!battle && (m_sim.state().warps == warps_before || (!fade_over_since(watched_from) && !m_sim.watch({SimWatcher::FADE}, WARP_TIMEOUT)))){ + if (!battle && (m_sim.state().warps == warps_before || (!fade_over_since(watched_from) && !m_rules.scene_confirms_missed_fade && !m_sim.watch({SimWatcher::FADE}, WARP_TIMEOUT)))){ fail("walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + "."); } m_sim.watch({}, AFTER_WARP); @@ -841,8 +841,8 @@ std::optional OverworldSimWalker::walk_step(const RouteStep& step, sim_turn_to(m_sim, step.direction, m_rules.confirm_turn); return std::nullopt; } - if (step.action != RouteAction::WALK){ - fail("Sim: Surf isn't modelled."); + if (step.action == RouteAction::SURF){ + return surf(step); } if (turns_first(step, m_speed, facing)){ sim_turn_to(m_sim, step.direction, m_rules.confirm_turn); @@ -957,7 +957,7 @@ size_t OverworldSimWalker::clear_unseen_battle(const RouteStep& step){ void OverworldSimWalker::hold_to_warp(const RouteStep& step){ // The warp it holds on to takes the player off the Bicycle. - m_riding = false; + m_riding = m_riding && warp_keeps_bike(step.end.map); const std::vector& ints = interrupts(step); std::vector fade_first{SimWatcher::FADE}; for (const SimWatcher watcher : watchers(ints)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index da4d5b84f2..69ca8c3884 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -20,7 +20,8 @@ * A step onto a connected map waits a tile first, as the console does * while the game loads the map. * - * Not modelled: Surf, running, HP and status. Wandering people stand on + * Not modelled: running, HP and status, and wild battles on the water. + * Surf and Fly are (SimField::SURF, SimField::FLY). Wandering people stand on * their tile. The Bicycle is: its pace, its taps (each a tile, some * dropped when they come too fast), SELECT and doors taking the player * off it. @@ -66,9 +67,11 @@ class OverworldSim{ const SimState& state() const{ return m_state; } - // Counts a walker step tap that moved the player; whether the - // walker's screen check misses it (SimScript::unseen_step_taps). - bool hides_moved_step_tap(); + // Whether the walker's screen check reads its last step tap as a + // step: one that moved the player from `before`, but for + // SimScript::unseen_step_taps, or a turn tap since `turn_taps_before` + // (SimState::turn_taps) that SimScript::seen_turn_taps names. + bool reads_step_tap_as_step(const MapPosition& before, int turn_taps_before); // Holds `direction` for `duration` then lets go for `release`, while // `watchers` watch until `watch` (at least the hold and release) from @@ -121,7 +124,9 @@ class OverworldSim{ int map = 0; PlayerState player; bool warped = false; - bool walked_out = false; // the warp ended with the game walking the player a tile south + // The way the warp left the player facing (arrival_facing()), if + // not the way they moved. + std::optional facing = std::nullopt; bool ledge = false; // The step landed on a spinner, which slid the player to `player`. std::optional spin = {}; @@ -164,6 +169,10 @@ class OverworldSim{ bool cut_tree(); bool choose_lift_floor(size_t floor); bool push_poster_switch(); + bool start_surf(); + bool fly_to_town(size_t town); + // The trees cut come back, as after a warp. + void regrow_cut_trees(); bool after_step(const Step& step, Milliseconds pressed); bool wild_battle(Milliseconds pressed); std::optional next_encounter(); @@ -173,8 +182,11 @@ class OverworldSim{ // Whether the Bicycle tap starting at `start` is dropped, too soon // after the last one. bool drops_bike_tap(Milliseconds start); - // How long a tile takes: on the Bicycle or on foot. + // How long a tile takes: on the water, on the Bicycle or on foot. Milliseconds tile_time() const{ + if (m_player.surfing){ + return m_script.timing.surf_tile; + } return m_state.on_bike ? m_script.timing.bike_tile : m_script.timing.tile; } bool trainer_sees(Milliseconds pressed); @@ -208,7 +220,6 @@ class OverworldSim{ int m_steps_since_encounter = 0; int m_encounter_rate_buff = 0; // The turn taps so far, for SimScript::dropped_turn_taps. - int m_turn_taps = 0; // Steps onto a warp so far, and the fault on one // (SimScript::black_without_warp): its black without the warp. int m_warp_steps = 0; @@ -296,6 +307,15 @@ struct SimWalkerRules{ // Without it a black that cleared with the player where they were was // taken as the warp (console B, 2026-11-10 01:44, 09.01 run 4). bool confirm_warp_destination = true; + // A warp whose fade was over before the watch for it began is taken by + // the screen after it: another scene than before the hold, held still + // (OverworldWalkSteps::arrived_without_fade()). Without it the walker + // tapped twice into the Department Store lift's back wall and failed + // on "no fade in and out after walking onto the warp" with the player + // inside the lift (console B, 2026-11-12 00:39, 10.01 lift_to_1f): the + // lift room is mostly black, so a watch started after the fade never + // sees black end. + bool scene_confirms_missed_fade = true; // A turn tap is checked by the facing on screen, and tapped again // while the player faces another way (OverworldWalkSteps::turn_to()). // Without it a dropped tap left a one-tile leg turning the player @@ -397,6 +417,10 @@ class OverworldSimWalker{ return stop_tiles(step, timed, m_leg_dark); } std::optional walk_step(const RouteStep& step, std::optional facing); + // start_surf(): turned to the water, A, YES, and the jump onto it. + // Nothing: a Surf is never stopped part-way. + // (PokemonFRLG_OverworldSimField.cpp) + std::optional surf(const RouteStep& step); bool after_warp(const RouteStep& step, int warps_before, Milliseconds watched_from); bool fade_over_since(Milliseconds from) const; // after_warp() on a fade seen with no warp: fails, or with @@ -438,6 +462,8 @@ class OverworldSimWalker{ void add_tests_OverworldSim(UnitTestDatabase& database); // Register the tests of a warp's fade over before the hold onto it ends. void add_tests_OverworldWarpFade(UnitTestDatabase& database); +// Register the tests of the way a warp leaves the player facing. +void add_tests_OverworldStairs(UnitTestDatabase& database); } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp index 05dfa2e40f..84384e54da 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp @@ -3,13 +3,15 @@ * From: https://github.com/PokemonAutomation/ * * What A does on the sim's overworld, facing something: a tree to cut, - * the Game Corner's poster, the lift's panel (OverworldSim::use_field()). + * the Game Corner's poster, the lift's panel, the water to Surf onto; and + * Fly (OverworldSim::use_field()). * */ #include #include #include "PokemonFRLG_CodedRooms.h" +#include "PokemonFRLG_FlyMap.h" #include "PokemonFRLG_OverworldSim.h" #include "PokemonFRLG_OverworldSimField.h" #include "PokemonFRLG_BikeSpinMechanics.h" @@ -38,6 +40,10 @@ bool OverworldSim::use_field(SimField field, size_t floor){ return choose_lift_floor(floor); case SimField::BIKE_SELECT: return press_select(); + case SimField::SURF: + return start_surf(); + case SimField::FLY: + return fly_to_town(floor); } return false; } @@ -81,7 +87,7 @@ std::optional OverworldSim::lift_warp(int map_index) const{ if (to == m_maps.end()){ return std::nullopt; } - return Step{(int)(to - m_maps.begin()), PlayerState{out.point, elevation_at(*to, out.point), false}, true, false, false}; + return Step{(int)(to - m_maps.begin()), PlayerState{out.point, elevation_at(*to, out.point), false}, true, std::nullopt, false}; } bool OverworldSim::cut_tree(){ @@ -117,6 +123,62 @@ bool OverworldSim::choose_lift_floor(size_t floor){ return true; } +bool OverworldSim::start_surf(){ + const bool water = classify_step(map(), m_player, m_state.facing) == StepKind::START_SURF; + if (!water || m_state.screen != SimScreen::OVERWORLD || m_frozen){ + violation("no water to Surf onto " + std::string(direction_name(m_state.facing)) + " of " + to_string(m_state.position) + "."); + return false; + } + advance_to(m_now + m_script.timing.surf_start); + m_player = PokemonFRLG::after_step(map(), m_player, m_state.facing, StepKind::START_SURF); + m_state.on_bike = false; + update_view(); + note("surfed onto " + to_string(m_state.position) + "."); + return true; +} + +bool OverworldSim::fly_to_town(size_t town){ + const std::vector& towns = kanto_fly_towns(); + const MapPosition* landing = town < towns.size() ? &towns[town].landing : nullptr; + const auto to = std::find_if(m_maps.begin(), m_maps.end(), [&](const MapData& map){ + return landing != nullptr && map.name == landing->map; + }); + if (to == m_maps.end() || m_state.screen != SimScreen::OVERWORLD || m_frozen){ + violation(std::format("no Fly to town {} from {}.", town, to_string(m_state.position))); + return false; + } + m_state.warped_from.push_back(map().name); + m_state.warps++; + regrow_cut_trees(); + m_map = (int)(to - m_maps.begin()); + m_player = PlayerState{landing->point, elevation_at(*to, landing->point), false}; + m_state.facing = Direction::SOUTH; + m_state.on_bike = false; + update_view(); + m_frozen = true; + schedule(m_now + m_script.timing.message, SimScreen::FADE, false); + schedule(m_now + m_script.timing.fly, SimScreen::OVERWORLD, true); + note("flew to " + to_string(m_state.position) + "."); + return true; +} + +std::optional OverworldSimWalker::surf(const RouteStep& step){ + if (m_sim.state().facing != step.direction){ + sim_turn_to(m_sim, step.direction, m_rules.confirm_turn); + } + if (!m_sim.use_field(SimField::SURF)){ + fail("walk_overworld_route(): no Surf prompt facing the water."); + } + return std::nullopt; +} + +void OverworldSim::regrow_cut_trees(){ + for (auto& [index, tree] : m_cut_trees){ + m_maps[index].objects.push_back(tree); + } + m_cut_trees.clear(); +} + bool OverworldSim::push_poster_switch(){ std::vector& objects = m_maps[m_map].objects; const TilePos ahead = m_player.position.next(m_state.facing); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.h index 4dd405a0f6..b4993fa1e8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.h @@ -36,6 +36,15 @@ enum class SimField{ // running is allowed, or off it, in about // MovementMechanics::BIKE_SELECT_TIME. (PokemonFRLG_OverworldSimTaps.cpp) BIKE_SELECT, + // Surf onto the water the player faces, from ground beside it: the + // question, " used SURF!" and the jump (SimTiming::surf_start). + // Each step on the water then takes SimTiming::surf_tile, and a step + // onto land gets the player off. + SURF, + // Not A: Fly from the party menu to the town numbered `floor` in + // kanto_fly_towns(), outdoors: the fade, then the player on its landing + // tile facing south, still for SimTiming::fly. + FLY, }; // Register the tests of the Bicycle's taps and SELECT on a made-up map. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimScreens.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimScreens.h index b2407335b8..5f0be8df11 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimScreens.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimScreens.h @@ -62,6 +62,15 @@ struct SimTiming{ Milliseconds tile = MovementMechanics::TILE_TIME; // A tile on the Bicycle. Milliseconds bike_tile = MovementMechanics::BIKE_TILE_TIME; + // A tile on the water. + Milliseconds surf_tile = MovementMechanics::SURF_TILE_TIME; + // From the A facing the water to the player on it, able to move + // (OverworldWalkSteps::start_surf()'s presses and wait). Not measured + // on the console. + Milliseconds surf_start{4000}; + // From Fly's town picked to the player standing in it, able to move: + // the fade, the flight and the landing. Not measured on the console. + Milliseconds fly{5000}; Milliseconds flash{300}; Milliseconds battle_screen{3700}; // A wild battle's text box, before the HP boxes (battle_screen). Not diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h index 36d32a60ad..8222a0976a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h @@ -61,6 +61,11 @@ struct SimScript{ // the tap again took a second tile (console B, 2026-11-11 15:03 and // 15:36, 09.02). std::set unseen_step_taps; + // Fault injection: turn taps, by number from 1 as for + // dropped_turn_taps, that the walker's screen check reads as a step. + // The turn south before 10.04's "south 3" read so (console B, + // 2026-11-12 03:08), and the leg ended a tile short of the stairs. + std::set seen_turn_taps; // Fault injection: steps onto a warp, by number from 1, that show the // fade's black and clear with the player where they were, not warped // (console B, 2026-11-10 01:44, 09.01 run 4, "east 1 (warp)" on B4F). @@ -131,8 +136,12 @@ struct SimState{ Milliseconds in_wild_battles{0}; int signs_read = 0; int turn_taps_dropped = 0; + // Taps that only turned the player, or were dropped turning them. + int turn_taps = 0; // On the Bicycle (SimScript::on_bike). bool on_bike = false; + // On the water (SimField::SURF). + bool surfing = false; // Bicycle taps the game dropped, too soon after the last one. int bike_taps_dropped = 0; // Step taps the game ignored, inside the lockout after the last one diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp index f3f38d44fe..97f9fb3800 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp @@ -14,6 +14,7 @@ #include "PokemonFRLG_BikeSpinMechanics.h" #include "PokemonFRLG_BikeSpinPresses.h" #include "PokemonFRLG_OverworldBike.h" +#include "PokemonFRLG_OverworldMaps.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -80,9 +81,10 @@ StepOutcome OverworldSimWalker::walk_bike_taps(const RouteStep& step){ BikeTap OverworldSimWalker::step_tap(const RouteStep& step, int tap){ const MapPosition before = m_sim.state().position; + const int turn_taps = m_sim.state().turn_taps; m_sim.tap(step.direction, STEP_TAP, STEP_TAP_RELEASE); m_sim.watch({}, step_tap_settle(step, tap)); - if (!(m_sim.state().position == before) && !m_sim.hides_moved_step_tap()){ + if (m_sim.reads_step_tap_as_step(before, turn_taps)){ return BikeTap{.moved = true}; } return BikeTap{.moved = false, .interrupt = std::nullopt, .cleared_late = clear_late(interrupts(step), AFTER_LEG_WATCH, MAX_INTERRUPTIONS_PER_LEG) > 0}; @@ -121,7 +123,7 @@ StepOutcome OverworldSimWalker::walk(const RouteStep& step, std::optional +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_OverworldSim.h" +#include "PokemonFRLG_OverworldTileRules.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +struct StairsInput{ + std::string name; + std::function body; +}; + +struct StairsExpectation{ +}; + +struct StairsCase{ + StairsInput input; + StairsExpectation expectation; +}; + +class Test_OverworldStairs : public UnitTest{ +public: + explicit Test_OverworldStairs(StairsCase test_case) + : UnitTest("PokemonFRLG::OverworldStairs - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_case.input.body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + StairsCase m_case; +}; + +const std::vector& maps(){ + static const std::vector MAPS = overworld_maps(); + return MAPS; +} + +const MapData& map_named(const std::string& name){ + for (const MapData& map : maps()){ + if (map.name == name){ + return map; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No map " + name + "."); +} + +std::string facing_name(std::optional facing){ + return facing ? direction_name(*facing) : "unchanged"; +} + +// Celadon Mansion's side stairs, its front door's exit mat and Celadon +// City's door to it: the way the game turns a player arriving on each. +UnitTestResult test_arrival_facing(){ + const struct{ + MapPosition tile; + std::optional facing; + } CASES[] = { + // 1F's stairs up, taken walking east (MB_UP_RIGHT_STAIR_WARP). + {MapPosition{"CeladonCity_Condominiums_1F", {4, 2}}, Direction::WEST}, + // 2F's stairs up, taken walking west. + {MapPosition{"CeladonCity_Condominiums_2F", {2, 2}}, Direction::EAST}, + // 1F's exit mat, taken walking south. + {MapPosition{"CeladonCity_Condominiums_1F", {12, 18}}, Direction::NORTH}, + {MapPosition{"CeladonCity", map_point(maps(), "CeladonCity", "warp_3")}, Direction::SOUTH}, + {MapPosition{"CeladonCity_Condominiums_1F", {2, 2}}, std::nullopt}, + }; + for (const auto& c : CASES){ + const std::optional facing = arrival_facing(map_named(c.tile.map), c.tile.point); + if (facing != c.facing){ + return std::format("Arriving on {}: facing {}, expected {}.", to_string(c.tile), facing_name(facing), facing_name(c.facing)); + } + } + return true; +} + +std::string describe(const std::vector& route, const std::vector& log){ + std::string text = "\n route:"; + for (const RouteStep& step : route){ + text += "\n " + to_string(step) + ", facing " + direction_name(step.facing_after) + " after"; + } + text += "\n log:"; + for (const std::string& line : log){ + text += "\n " + line; + } + return text; +} + +// 10.01 below_store_lift (console B, 2026-11-11 23:40): down Celadon +// Mansion's stairs to 1F (4, 2), "west 2 (open)", then "north 1 (warp)" +// onto the back door (2, 1). The game turns a player off the 2F stairs to +// face west (pokefirered GetAdjustedInitialDirection()), so the turn tap +// the walker made, for a player it took as facing east, was a step: west 2 +// ended on (1, 2) and north 1 met the wall, "no fade in and out". +UnitTestResult test_mansion_stairs_to_back_door(){ + const MapPosition start{"CeladonCity_Condominiums_RoofRoom", {7, 4}}; + const MapPosition goal{"CeladonCity_DepartmentStore_1F", {6, 2}}; + const std::optional> route = plan_overworld_route( + maps(), start, RouteGoal{goal, std::nullopt}, default_route_costs(), Direction::NORTH + ); + if (!route){ + return std::string("No route from the roof room to the Department Store."); + } + OverworldSim sim(maps(), start, Direction::NORTH, SimScript{}); + OverworldSimWalker walker(sim, SimWalkerRules{}); + const RoutePlanning planning{.maps = &maps(), .costs = default_route_costs(), .start = start, .label = "Sim"}; + const std::string failure = walker.run(*route, planning); + std::vector log = walker.log(); + log.insert(log.end(), sim.state().log.begin(), sim.state().log.end()); + if (!failure.empty() || !(sim.state().position == goal) || !sim.state().violations.empty()){ + return std::format("Expected the Department Store reached by the Mansion's back door, ended at {}: \"{}\"", to_string(sim.state().position), failure) + + describe(*route, log); + } + for (const RouteStep& step : *route){ + if (step.warps && step.end == MapPosition{"CeladonCity_Condominiums_1F", {4, 2}} && step.facing_after != Direction::WEST){ + return "Expected the leg down the stairs to 1F to end facing west:" + describe(*route, {}); + } + } + return true; +} + +// A leg on foot of `tiles` taps `direction`, to `end`. +RouteStep tapped_leg(Direction direction, int tiles, const MapPosition& end){ + RouteStep step; + step.direction = direction; + step.tiles = tiles; + step.tapped = true; + step.facing_after = direction; + step.end = end; + return step; +} + +// 10.04 tower_3f_to_stairs (console B, 2026-11-12 03:08): taps east 11 +// along Pokemon Tower 3F's row 7 and south 3 down column 18 onto the +// stairs (18, 10). The first south tap only turned the player, but the +// screen check read it as a step: the leg ended on (18, 9), and the press +// east into the stairs' warp met the wall. A tap from facing another way +// is a turn, whatever the screen shows. +UnitTestResult test_tower_turn_read_as_step(){ + const MapPosition start{"PokemonTower_3F", {7, 7}}; + const MapPosition stairs{"PokemonTower_3F", {18, 10}}; + const MapPosition goal{"PokemonTower_4F", {18, 10}}; + std::vector route{ + tapped_leg(Direction::EAST, 11, MapPosition{"PokemonTower_3F", {18, 7}}), + tapped_leg(Direction::SOUTH, 3, stairs), + }; + const std::optional> warp = plan_overworld_route( + maps(), stairs, RouteGoal{goal, std::nullopt}, default_route_costs(), Direction::SOUTH + ); + if (!warp){ + return std::string("No route from 3F's stairs to 4F."); + } + route.insert(route.end(), warp->begin(), warp->end()); + SimScript script; + script.seen_turn_taps = {1}; + OverworldSim sim(maps(), start, Direction::EAST, script); + OverworldSimWalker walker(sim, SimWalkerRules{}); + const RoutePlanning planning{.maps = &maps(), .costs = default_route_costs(), .start = start, .label = "Sim"}; + const std::string failure = walker.run(route, planning); + std::vector log = walker.log(); + log.insert(log.end(), sim.state().log.begin(), sim.state().log.end()); + if (!failure.empty() || !(sim.state().position == goal)){ + return std::format("Expected 4F's stairs reached, ended at {}: \"{}\"", to_string(sim.state().position), failure) + + describe(route, log); + } + return true; +} + +// 10.05 tower_6f_stairs (console B, 2026-11-12 03:41): the planned route +// from Pokemon Tower 5F (18, 7), facing east, went "south 3 (open)" down +// column 18 onto the stairs (18, 10), then "east 1 (warp)". The hold +// ended a tile short, on (18, 9), and the presses east met the wall. The +// stairs have walls east and west, so the route can only step onto them +// going south: the leg onto them is tapped, a tap a tile checked to have +// moved, and a tap that only turned is not counted. +UnitTestResult test_tower_planned_onto_side_stairs(){ + const MapPosition start{"PokemonTower_5F", {18, 7}}; + const MapPosition goal{"PokemonTower_6F", {18, 10}}; + const std::optional> route = plan_overworld_route( + maps(), start, RouteGoal{goal, Direction::NORTH}, default_route_costs(), Direction::EAST + ); + if (!route){ + return std::string("No route from 5F (18, 7) to 6F's stairs."); + } + SimScript script; + script.short_holds = {{1, 1}}; + script.seen_turn_taps = {1}; + OverworldSim sim(maps(), start, Direction::EAST, script); + OverworldSimWalker walker(sim, SimWalkerRules{}); + const RoutePlanning planning{.maps = &maps(), .costs = default_route_costs(), .start = start, .label = "Sim"}; + const std::string failure = walker.run(*route, planning); + std::vector log = walker.log(); + log.insert(log.end(), sim.state().log.begin(), sim.state().log.end()); + if (!failure.empty() || !(sim.state().position == goal)){ + return std::format("Expected 6F's stairs reached, ended at {}: \"{}\"", to_string(sim.state().position), failure) + + describe(*route, log); + } + return true; +} + +} // namespace + + +const StairsCase STAIRS_CASES[] = { + { + .input = {.name = "arriving on stairs, an exit mat or a door turns the player", .body = test_arrival_facing}, + .expectation = {}, + }, + { + .input = {.name = "Celadon Mansion: down the stairs and out of the back door", .body = test_mansion_stairs_to_back_door}, + .expectation = {}, + }, + { + .input = {.name = "Pokemon Tower 3F: a turn tap read as a step is not counted", .body = test_tower_turn_read_as_step}, + .expectation = {}, + }, + { + .input = {.name = "Pokemon Tower 5F: planned onto side stairs from the side, a tap a tile", .body = test_tower_planned_onto_side_stairs}, + .expectation = {}, + }, +}; + +void add_tests_OverworldStairs(UnitTestDatabase& database){ + for (const StairsCase& item : STAIRS_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h index e8d6264d44..a8211bc671 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h @@ -42,6 +42,14 @@ std::optional exit_mat(const MapData& map, const TilePos& point); // Arriving on a door or cave entrance, the game walks the player one // tile south, out of it. bool walks_out_on_arrival(const MapData& map, const TilePos& point); +// The way the game turns a player who arrives by a warp on this tile, the +// warp's destination (pokefirered GetAdjustedInitialDirection()): south +// out of a door or cave entrance, and away from the way an exit mat or the +// stairs at the side of a room are taken (the map files write both as +// walk_). Nothing elsewhere: the player keeps facing the way +// they moved. Arriving on side stairs, the game only slides the sprite in +// (ExitStairsMovement(), a walk in place): the player stays on the stairs. +std::optional arrival_facing(const MapData& map, const TilePos& point); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp index 1ba2f46e40..b3f5bed738 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp @@ -354,9 +354,55 @@ bool warp_left_scene( return true; } +} // namespace + +bool arrived_without_fade( + const ImageViewRGB32& before, const ImageViewRGB32& now, const ImageViewRGB32& later, + const ImageFloatBox& game, const RouteStep& step +){ + if (BlackScreenDetector(COLOR_RED).detect(later)){ + return false; + } + const ImageViewRGB32 now_box = extract_box_reference(now, game); + const ImageViewRGB32 later_box = extract_box_reference(later, game); + if (now_box.width() != later_box.width() || now_box.height() != later_box.height()){ + return false; + } + if (scrolled_rmsd(now_box, later_box, 0, 0) >= SAME_SCENE_RMSD){ + return false; + } + return warp_left_scene(before, later, game, step.direction, step.tiles + step.warp_slack + 2); +} + +namespace{ + +// arrived_without_fade() on the screen now and DIM_WARP_POLL later. +bool arrived_unseen(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, const VideoSnapshot& before){ + if (!before){ + return false; + } + context.wait_for_all_requests(); + const VideoSnapshot now = console.video().snapshot(); + context.wait_for(DIM_WARP_POLL); + const VideoSnapshot later = console.video().snapshot(); + if (!now || !later){ + return false; + } + if (!arrived_without_fade(*before.frame, *now.frame, *later.frame, GameSettings::instance().GAME_BOX, step)){ + return false; + } + console.log(std::format("Route: no fade seen, but another scene is up and still: the warp to {} was taken.", step.end.map), COLOR_ORANGE); + return true; +} + // One watcher for the whole fade: a ladder's black is short enough to be -// over before a second watcher, started once the fade is seen, looks. -void wait_out_fade(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, Pokemon::WatchAlong& fade){ +// over before a second watcher, started once the fade is seen, looks. A +// fade missed altogether is taken by the scene after it (arrived_unseen()), +// before any step more. +void wait_out_fade( + ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, + Pokemon::WatchAlong& fade, const VideoSnapshot& before +){ if (fade.fired()){ console.log("Route: the fade to " + step.end.map + " was over before the hold ended."); return; @@ -365,6 +411,9 @@ void wait_out_fade(ConsoleHandle& console, ProControllerContext& context, const if (wait_until(console, context, WARP_TIMEOUT, {fade.watcher()}) >= 0){ return; } + if (arrived_unseen(console, context, step, before)){ + return; + } // A hold that ended short of a stairs or door warp, or on an arrow // warp: a step more at a time, twice, takes it. A hold ends up to two // tiles short, and an arrow warp fires on the press made standing on it. @@ -431,7 +480,7 @@ void wait_out_warp( ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, Pokemon::WatchAlong& fade, const VideoSnapshot& before ){ - wait_out_fade(console, context, step, fade); + wait_out_fade(console, context, step, fade, before); if (!before){ return; } @@ -634,6 +683,17 @@ constexpr size_t TURN_FACING_READS = 3; constexpr Milliseconds TURN_FACING_REREAD(100); void turn_to(ConsoleHandle& console, ProControllerContext& context, Direction direction, PlayerGender player){ + // A tap while the player faces `direction` already takes a step, so the + // screen is read first. A trainer's battle leaves the player facing the + // way they stepped into the line, not the trainer (pokefirered + // trainer_see.c, TrainerSeeFunc_PrepareToEngage): 10.05's turn tap west + // after Emilia stepped, and "west 4 (open)" ended on Pokemon Tower 6F + // (4, 8), a tile long (console B, 2026-11-12 04:39). + context.wait_for_all_requests(); + if (const VideoSnapshot screen = console.video().snapshot(); screen && read_player_facing(screen, player) == direction){ + console.log(std::format("Route: the player faces {} already: no turn tap.", Pokemon::direction_name(direction))); + return; + } for (size_t tap = 1; tap <= MAX_TURN_TAPS; tap++){ pbf_press_dpad(context, dpad(direction), TURN_TAP, TURN_SETTLE); std::optional facing; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h index cec21e6053..3dc7e7aab6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h @@ -82,6 +82,19 @@ void wait_out_warp( // scene from `before` gone and the screen settled instead. void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, const VideoSnapshot& before); +// Whether a warp onto `step` whose fade went unseen was taken anyway: the +// game box of `later` shows another scene than `before` (taken before the +// steps onto the warp; warp_left_scene()), is not black, and matches +// `now`, taken a little before it, so no fade is still on. The Department +// Store's lift room is mostly black around its lit floor: a watch for the +// fade started once it was over never sees black end (console B, +// 2026-11-12 00:39, 10.01 lift_to_1f: two steps more into the lift's back +// wall, then "no fade in and out"). +bool arrived_without_fade( + const ImageViewRGB32& before, const ImageViewRGB32& now, const ImageViewRGB32& later, + const ImageFloatBox& game, const RouteStep& step +); + // Before `step`: fails unless the overworld is up. void check_overworld(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp index 30f666859b..a97a0a81bb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp @@ -8,11 +8,14 @@ */ #include +#include #include #include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" #include "PokemonFRLG_OverworldMaps.h" #include "PokemonFRLG_OverworldSim.h" #include "PokemonFRLG_OverworldWalk.h" @@ -35,6 +38,8 @@ struct WarpFadeInput{ // SimScript::black_without_warp and SimWalkerRules::confirm_warp_destination. std::set black_without_warp = {}; bool confirm_destination = true; + // SimWalkerRules::scene_confirms_missed_fade. + bool scene_confirms = true; }; struct WarpFadeExpectation{ @@ -82,6 +87,7 @@ class Test_OverworldWarpFade : public UnitTest{ SimWalkerRules rules; rules.watch_fade_along_hold = m_case.input.watch_along_hold; rules.confirm_warp_destination = m_case.input.confirm_destination; + rules.scene_confirms_missed_fade = m_case.input.scene_confirms; OverworldSim sim(maps(), MART, Direction::SOUTH, script); OverworldSimWalker walker(sim, rules); const RoutePlanning planning{.maps = &maps(), .costs = default_route_costs(), .start = MART, .label = "Sim"}; @@ -105,6 +111,108 @@ class Test_OverworldWarpFade : public UnitTest{ WarpFadeCase m_case; }; +// A store floor: a pattern that repeats every 16-pixel tile. +ImageRGB32 store_floor(){ + ImageRGB32 image(240, 160); + for (size_t y = 0; y < 160; y++){ + for (size_t x = 0; x < 240; x++){ + image.pixel(x, y) = (x % 16 < 8) ^ (y % 16 < 8) ? 0xffc0b090 : 0xff906850; + } + } + return image; +} + +// The Department Store's lift room as the console shows it (console B, +// 2026-11-12 00:39): black but for its lit floor, 4 by 3 tiles, in the +// middle. +ImageRGB32 lift_room(){ + ImageRGB32 image(240, 160); + for (size_t y = 0; y < 160; y++){ + for (size_t x = 0; x < 240; x++){ + const bool lit = x >= 88 && x < 152 && y >= 56 && y < 104; + image.pixel(x, y) = lit ? ((x % 16 < 8) ? 0xffd8d0b8 : 0xff807060) : 0xff000000; + } + } + return image; +} + +ImageRGB32 black_screen(){ + ImageRGB32 image(240, 160); + for (size_t y = 0; y < 160; y++){ + for (size_t x = 0; x < 240; x++){ + image.pixel(x, y) = 0xff000000; + } + } + return image; +} + +// 10.01 lift_to_1f: the step north into the lift, its fade missed. A +// watch for the fade started on the lift room never sees black end; the +// scene after it is taken as the warp, and a black screen or the floor +// from before the step is not. +UnitTestResult test_lift_room_arrival(){ + const ImageFloatBox game(0, 0, 1, 1); + RouteStep step; + step.direction = Direction::NORTH; + step.tiles = 1; + step.warps = true; + step.end.map = "CeladonCity_DepartmentStore_Elevator"; + const ImageRGB32 before = store_floor(); + const ImageRGB32 lift = lift_room(); + const ImageRGB32 black = black_screen(); + BlackScreenOverWatcher late_watch(COLOR_RED); + for (int frame = 0; frame < 10; frame++){ + late_watch.process_frame(lift, WallClock{} + Milliseconds(100 * frame)); + } + if (late_watch.black_is_over(lift)){ + return "Expected a fade watch started on the lift room not to see black end."; + } + if (!OverworldWalkSteps::arrived_without_fade(before, lift, lift, game, step)){ + return "Expected the lift room after the step to be taken as the warp."; + } + if (OverworldWalkSteps::arrived_without_fade(before, black, black, game, step)){ + return "Expected a black screen (the fade still on) not to be taken as the warp."; + } + if (OverworldWalkSteps::arrived_without_fade(before, before, before, game, step)){ + return "Expected the floor from before the step not to be taken as the warp."; + } + if (OverworldWalkSteps::arrived_without_fade(before, black, lift, game, step)){ + return "Expected the lift room still fading in (black a poll before) not to be taken yet."; + } + return true; +} + +struct ArrivalScreenInput{ + std::string name; + std::function body; +}; + +struct ArrivalScreenExpectation{ +}; + +struct ArrivalScreenCase{ + ArrivalScreenInput input; + ArrivalScreenExpectation expectation; +}; + +class Test_ArrivalScreen : public UnitTest{ +public: + explicit Test_ArrivalScreen(ArrivalScreenCase test_case) + : UnitTest("PokemonFRLG::OverworldWarpFade - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return m_case.input.body(); + } + +private: + ArrivalScreenCase m_case; +}; + +const ArrivalScreenCase ARRIVAL_SCREEN_CASES[] = { + {.input = {"the lift room after a missed fade, by its screen", test_lift_room_arrival}, .expectation = {}}, +}; + } // namespace @@ -114,9 +222,16 @@ const WarpFadeCase WARP_FADE_CASES[] = { .expectation = {.failure = ""}, }, { - .input = {.name = "a fade over before the hold ends, watched from its end", .fade = 200ms, .watch_along_hold = false}, + .input = {.name = "a fade over before the hold ends, watched from its end", .fade = 200ms, .watch_along_hold = false, .scene_confirms = false}, .expectation = {.failure = "no fade in and out after walking onto the warp to ViridianCity"}, }, + { + // 10.01 lift_to_1f (console B, 2026-11-12 00:39): the step into + // the Department Store's lift, its fade missed; the lift room after + // it is another scene, so the warp is taken without the fade. + .input = {.name = "a fade missed, the scene after it confirms the warp", .fade = 200ms, .watch_along_hold = false}, + .expectation = {.failure = ""}, + }, { .input = {.name = "a fade still on when the hold ends, watched from its end", .fade = 1000ms, .watch_along_hold = false}, .expectation = {.failure = ""}, @@ -136,6 +251,9 @@ void add_tests_OverworldWarpFade(UnitTestDatabase& database){ for (const WarpFadeCase& item : WARP_FADE_CASES){ database.add(item); } + for (const ArrivalScreenCase& item : ARRIVAL_SCREEN_CASES){ + database.add(item); + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 6764ac1382..dc0d21bdcc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -92,10 +92,11 @@ const std::string RUN_GIFT_RNG_TEXT = "Run Gift RNG in AutoStory:
Off by default. After 04.02 saves beside the Magikarp salesman in Route 4's " "Pokemon Center, run Gift RNG's attempts for the Magikarp from that save, as the RNG plan lists them for its TID and " "SID (set by Run Starter RNG in AutoStory, or typed in). A shiny Magikarp is saved there (04.03) and the run goes " - "on; otherwise the run stops with the save beside the salesman.
" - "To try again from that save, start at 04.03 with this on: it loads the save and runs the attempts first. " - "After Gift RNG run by hand, start at 04.03 with this off.
" - "English only. The Magikarp costs 500 and needs a free party slot; AutoStory's options leave the text fast."; + "on; otherwise the run stops with the save beside the salesman. Likewise for the Eevee: 09.03 saves facing its ball " + "in Celadon Mansion's roof room, and 09.04 saves the shiny.
" + "To try again from that save, start at 04.03 (09.04) with this on: it loads the save and runs the attempts first. " + "After Gift RNG run by hand, start at 04.03 (09.04) with this off.
" + "English only. The Magikarp costs 500; each gift needs a free party slot; AutoStory's options leave the text fast."; AutoStory::AutoStory() : RUN(checkpoint_database(), Pokemon::FireRedLeafGreenLanguages_Database()) @@ -606,23 +607,22 @@ static bool run_starter_rng_in_program( return shiny_or_stop(env, finished, result, starter_rng_loop_message(result)); } -// Gift RNG's attempts in the program, from the save beside the Magikarp -// salesman. Returns true for a shiny Magikarp, the game on its summary; -// otherwise the run has stopped with what to do next. -static bool run_gift_rng_in_program( +// Gift RNG's attempts in the program for the language and gift of +// `settings`, from the save where the gift is taken; the sound and +// calibration come from `options`. A shiny leaves the game on its summary. +static StarterRngLoopResult run_gift_rng_in_program( SingleSwitchProgramEnvironment& env, ProControllerContext& context, - const StarterRngPlanned& planned, StarterRngPlanOptions& options, Language language, - const GiftRngNotifications& notifications, EventNotificationOption& finished + const StarterRngPlanned& planned, StarterRngPlanOptions& options, GiftRngConsoleSettings settings, + const GiftRngNotifications& notifications ){ // The console's seed and CSF offsets, from Starter RNG too, and Gift // RNG's own in-game offset, saved as Starter RNG's are. RngStopCalibrationOptions& calibration = options.CALIBRATION; - ConsoleGiftRngSteps console_steps(env, context, GiftRngConsoleSettings{ - .language = language, .sound = options.SOUND, .calibration = calibration.calibration(calibration.GIFT_INGAME), - }, notifications); + settings.sound = options.SOUND; + settings.calibration = calibration.calibration(calibration.GIFT_INGAME); + ConsoleGiftRngSteps console_steps(env, context, settings, notifications); CalibrationSavingSteps steps(console_steps, calibration, calibration.GIFT_INGAME); - const StarterRngLoopResult result = run_rng_plan_in_program(env, steps, planned, options); - return shiny_or_stop(env, finished, result, gift_rng_loop_message(result)); + return run_rng_plan_in_program(env, steps, planned, options); } // After a shiny Squirtle: off its summary, and the rows to run next: the @@ -643,14 +643,15 @@ static StoryRunPlan after_shiny_starter( return plan; } -// After a shiny Magikarp: the rows to run next, from 04.03, which leaves -// its summary and saves, to `last`. Until that save, a failure stops the -// run, as after a shiny Squirtle. -static StoryRunPlan after_shiny_magikarp( - SingleSwitchProgramEnvironment& env, StoryEnv& story, size_t salesman_row, size_t last, const StoryHandoffs& handoffs +// After a shiny gift: the rows to run next, from the row after +// `gift_row` (04.03, 09.04), which leaves its summary and saves, to +// `last`. Until that save, a failure stops the run, as after a shiny +// Squirtle. +static StoryRunPlan after_shiny_gift( + SingleSwitchProgramEnvironment& env, StoryEnv& story, size_t gift_row, size_t last, const StoryHandoffs& handoffs ){ - StoryRunPlan plan = rows_after_gift_rng(story_checkpoints(), salesman_row, last, handoffs); - env.console.log("The shiny Magikarp isn't saved until " + plan.rows.front().id + " saves. " + StoryRunPlan plan = rows_after_gift_rng(story_checkpoints(), gift_row, last, handoffs); + env.console.log("The shiny gift isn't saved until " + plan.rows.front().id + " saves. " "If it fails before then, the run stops without reloading: save by hand.", COLOR_BLUE); story.has_save = false; return plan; @@ -749,7 +750,7 @@ std::optional AutoStory::run_story_plan( next = after_starter_ball(env, context, story, planned, row); break; case StoryHandoff::GIFT_RNG: - next = after_magikarp_salesman(env, context, story, planned, row); + next = after_gift_row(env, context, story, planned, row); break; } if (!next){ @@ -766,7 +767,7 @@ std::optional AutoStory::run_from_gift_rng_save( const StarterRngPlanned planned = plan_handoff_attempts( env, context, RNG_PLAN, RUN.language(), StoryHandoff::GIFT_RNG, story_checkpoints()[first].id ); - std::optional next = after_magikarp_salesman(env, context, story, planned, first - 1); + std::optional next = after_gift_row(env, context, story, planned, first - 1); if (!next){ return std::nullopt; } @@ -790,17 +791,23 @@ std::optional AutoStory::after_starter_ball( return after_shiny_starter(env, context, story, ball_row, RUN.end_index(), story_handoffs()); } -std::optional AutoStory::after_magikarp_salesman( +std::optional AutoStory::after_gift_row( SingleSwitchProgramEnvironment& env, ProControllerContext& context, - StoryEnv& story, const StarterRngPlanned& planned, size_t salesman_row + StoryEnv& story, const StarterRngPlanned& planned, size_t gift_row ){ + const GiftRngConsoleSettings settings{ + .language = RUN.language(), .sound = {}, .calibration = {}, .target = story_checkpoints()[gift_row].gift, + }; const GiftRngNotifications notifications{ .shiny = NOTIFICATION_SHINY, .status_update = NOTIFICATION_STATUS_UPDATE, .error_recoverable = NOTIFICATION_ERROR_RECOVERABLE, }; - if (!run_gift_rng_in_program(env, context, planned, RNG_PLAN, RUN.language(), notifications, NOTIFICATION_PROGRAM_FINISH)){ + const StarterRngLoopResult result = run_gift_rng_in_program(env, context, planned, RNG_PLAN, settings, notifications); + // The live-start row after the gift's, which saves it (04.03, 09.04). + const std::string& saving_row = story_checkpoints().at(gift_row + 1).id; + if (!shiny_or_stop(env, NOTIFICATION_PROGRAM_FINISH, result, gift_rng_loop_message(result, settings.target, saving_row))){ return std::nullopt; } - return after_shiny_magikarp(env, story, salesman_row, RUN.end_index(), story_handoffs()); + return after_shiny_gift(env, story, gift_row, RUN.end_index(), story_handoffs()); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h index bd17538606..da0bf2d6e5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -65,19 +65,21 @@ class AutoStory : public SingleSwitchProgramInstance{ SingleSwitchProgramEnvironment& env, ProControllerContext& context, StoryEnv& story, const StarterRngPlanned& planned, size_t ball_row ); - // Started at 04.03 (row `first`) with Run Gift RNG in AutoStory on, - // the save beside the salesman loaded: Gift RNG's attempts, then for a - // shiny the rows after them. As run_story_plan() returns. + // Started at a gift's live-start row (04.03, 09.04; row `first`) with + // Run Gift RNG in AutoStory on, the save where the gift is taken + // loaded: Gift RNG's attempts, then for a shiny the rows after them. + // As run_story_plan() returns. std::optional run_from_gift_rng_save( SingleSwitchProgramEnvironment& env, ProControllerContext& context, StoryEnv& story, StoryExecutor& executor, size_t first ); - // After 04.02 saved beside the Magikarp salesman (row `salesman_row`): - // Gift RNG's attempts run here. Returns the rows to run after a shiny, - // or nothing once the run has stopped. - std::optional after_magikarp_salesman( + // After a GIFT_RNG row (04.02 beside the Magikarp salesman, 09.03 + // facing the Eevee's ball; row `gift_row`) saved: Gift RNG's attempts + // for its gift run here. Returns the rows to run after a shiny, or + // nothing once the run has stopped. + std::optional after_gift_row( SingleSwitchProgramEnvironment& env, ProControllerContext& context, - StoryEnv& story, const StarterRngPlanned& planned, size_t salesman_row + StoryEnv& story, const StarterRngPlanned& planned, size_t gift_row ); // The start and end checkpoints, attempts, checks and language, as in @@ -92,7 +94,8 @@ class AutoStory : public SingleSwitchProgramInstance{ // Runs SID Helper's steps and Starter RNG's attempts in the program // instead of stopping for them. BooleanCheckBoxOption RUN_STARTER_RNG; - // Runs Gift RNG's attempts for the Magikarp in the program after 04.02. + // Runs Gift RNG's attempts in the program after 04.02 (the Magikarp) + // and 09.03 (the Eevee). BooleanCheckBoxOption RUN_GIFT_RNG; StarterRngPlanOptions RNG_PLAN; EventNotificationOption NOTIFICATION_SHINY; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp index 17ff0d486c..c8c61be7bb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp @@ -36,8 +36,9 @@ class StubMart : public MartActions{ virtual bool open_buy_list() override{ return true; } virtual std::optional read_money() override{ return money; } - virtual void move_cursor(size_t, size_t) override{} + virtual void press_cursor(bool) override{} virtual std::string read_row(size_t) override{ return ""; } + virtual void dump_screen(std::string_view) override{} virtual PurchaseEnd buy(const MartBuy&) override{ return PurchaseEnd::FAILED; } virtual bool leave() override{ return true; } }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 796aceae0f..01cdc9797a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -144,14 +144,14 @@ void tap(ProControllerContext& context, DpadPosition position){ // 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, Pokemon::StoryCheckLevel checks, Language language + int row, int shown, const std::string& item, Pokemon::StoryCheckLevel checks, Language language ){ if (!checks_screen(checks)){ return true; } context.wait_for_all_requests(); VideoSnapshot screen = console.video().snapshot(); - const std::string read = screen ? read_item_list_name(console, language, screen, row) : ""; + const std::string read = screen ? read_item_list_name(console, language, screen, shown) : ""; if (read == item){ return true; } @@ -164,13 +164,22 @@ bool bag_row_is( return false; } +// What an item in battle is used on. +enum class ItemTarget{ + // A Potion or a cure: the party list opens, its cursor on the starter. + PARTY_MEMBER, + // An X item: the Pokemon out, with no party list. + POKEMON_OUT, +}; + // From the battle menu: `item`, in `row` (from 0) of the Items pocket, on -// the starter. The bag opens on the pocket used last; Items is the first. +// `target`. The bag opens on the pocket used last; Items is the first. // Returns whether it was used; else (THOROUGH) backs out to the menu. bool use_item( ConsoleHandle& console, ProControllerContext& context, - int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language + const Supplies& supplies, const std::string& item, ItemTarget target, Pokemon::StoryCheckLevel checks, Language language ){ + const int row = item_row(supplies, item); console.log(std::format("Battle: using the {} in row {} of the Items pocket.", item, row + 1)); tap(context, DPAD_LEFT); tap(context, DPAD_UP); @@ -185,14 +194,17 @@ bool use_item( for (int c = 0; c < row; c++){ tap(context, DPAD_DOWN); } - if (!bag_row_is(console, context, row, item, checks, language)){ + if (!bag_row_is(console, context, row, item_shown_row(supplies, row), item, checks, language)){ pbf_press_button(context, BUTTON_B, 160ms, 1500ms); return false; } - // The item, USE, then the starter in the party list. + // The item, USE, then the starter in the party list. An X item's USE + // goes straight to the battle's text, which the loop reads. pbf_press_button(context, BUTTON_A, 160ms, 800ms); pbf_press_button(context, BUTTON_A, 160ms, 1500ms); - pbf_press_button(context, BUTTON_A, 160ms, 1000ms); + if (target == ItemTarget::PARTY_MEMBER){ + pbf_press_button(context, BUTTON_A, 160ms, 1000ms); + } return true; } @@ -604,13 +616,16 @@ class BattleLoop{ run_away(m_context); return; case TurnChoice::POTION: - m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, item_row(m_supplies, "potion"), "potion", m_checks, m_language))); + m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, m_supplies, "potion", ItemTarget::PARTY_MEMBER, m_checks, m_language))); return; case TurnChoice::ANTIDOTE: - m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks, m_language))); + m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, m_supplies, "antidote", ItemTarget::PARTY_MEMBER, m_checks, m_language))); return; case TurnChoice::AWAKENING: - m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, item_row(m_supplies, "awakening"), "awakening", m_checks, m_language))); + m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, m_supplies, "awakening", ItemTarget::PARTY_MEMBER, m_checks, m_language))); + return; + case TurnChoice::BATTLE_ITEM: + m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, m_supplies, action.item, ItemTarget::POKEMON_OUT, m_checks, m_language))); return; case TurnChoice::MOVE: m_console.log(std::format("Battle: move {}.", action.slot + 1)); @@ -675,14 +690,15 @@ void open_items_pocket(ConsoleHandle& console, ProControllerContext& context){ // Not run on the console yet. bool use_item_on_overworld( ConsoleHandle& console, ProControllerContext& context, - int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language + const Supplies& supplies, const std::string& item, Pokemon::StoryCheckLevel checks, Language language ){ + const int row = item_row(supplies, item); console.log(std::format("Story: using a {} from the bag (Items pocket, row {}).", item, row + 1)); open_items_pocket(console, context); for (int c = 0; c < row; c++){ pbf_press_dpad(context, DPAD_DOWN, 100ms, 300ms); } - if (!bag_row_is(console, context, row, item, checks, language)){ + if (!bag_row_is(console, context, row, item_shown_row(supplies, row), item, checks, language)){ mash_until_overworld(console, context, AFTER_BATTLE_TEXT); return false; } @@ -832,102 +848,44 @@ bool battle_shows(const ImageViewRGB32& screen){ return text.hp_box || text.yes_no; } -// The count the story keeps for `item`, or null for an item it doesn't count. -static int Supplies::* count_member(const std::string& item){ - if (item == "potion"){ - return &Supplies::potions; - } - if (item == "antidote"){ - return &Supplies::antidotes; - } - if (item == "parlyz-heal"){ - return &Supplies::parlyz_heals; - } - if (item == "awakening"){ - return &Supplies::awakenings; - } - if (item == "full-heal"){ - return &Supplies::full_heals; - } - return nullptr; -} - -static int* count_slot(Supplies& supplies, const std::string& item){ - int Supplies::* const member = count_member(item); - return member == nullptr ? nullptr : &(supplies.*member); -} - -int item_count(const Supplies& supplies, const std::string& item){ - int Supplies::* const member = count_member(item); - return member == nullptr ? 0 : supplies.*member; -} - -// Whether the story keeps a count for `item`. -static bool counted(const std::string& item){ - return count_member(item) != nullptr; -} - -int item_row(const Supplies& supplies, const std::string& item){ - int row = 0; - for (const std::string& slot : supplies.pocket){ - if (counted(slot) && item_count(supplies, slot) <= 0){ - continue; - } - if (slot == item){ - return row; - } - row++; - } - return -1; -} - -std::vector set_from_bag(Supplies& supplies, const std::vector& rows){ - const Supplies before = supplies; - supplies.potions = 0; - supplies.antidotes = 0; - supplies.parlyz_heals = 0; - supplies.awakenings = 0; - supplies.full_heals = 0; - supplies.pocket.clear(); - std::vector unread; - for (const BagRow& row : rows){ - supplies.pocket.push_back(row.item); - int* slot = count_slot(supplies, row.item); - if (slot == nullptr){ - continue; - } - if (row.count > 0){ - *slot = row.count; - continue; - } - // Taking an unread count for none left the starter unhealed at - // 9 HP until it fainted (console B, 2026-11-02). - *slot = std::max(item_count(before, row.item), 1); - unread.push_back(row.item); - } - return unread; -} - -std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved, const std::vector& rows){ - if (rows.empty()){ - return {}; - } - std::vector unread = set_from_bag(supplies, rows); - saved.potions = supplies.potions; - saved.antidotes = supplies.antidotes; - saved.parlyz_heals = supplies.parlyz_heals; - saved.awakenings = supplies.awakenings; - saved.full_heals = supplies.full_heals; - saved.pocket = supplies.pocket; - return unread; -} +// The Items pocket's capacity (pokefirered BAG_ITEMS_COUNT). +constexpr size_t MAX_ITEMS_POCKET_ROWS = 42; std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language){ open_items_pocket(console, context); context.wait_for_all_requests(); VideoSnapshot screen = console.video().snapshot(); dump_debug_image(console, "AutoStory/bag", "items-pocket", screen); - std::vector rows = screen ? read_bag_pocket(console, language, screen) : std::vector{}; + std::vector reads; + bool cancel = !screen; + for (int shown = 0; !cancel && shown < ITEM_LIST_ROWS; shown++){ + BagRow read = read_bag_row(console, language, screen, shown); + cancel = read.item == "cancel"; + if (!cancel){ + reads.push_back(std::move(read)); + } + } + // The rows below the first six: DOWN to the fourth row shown, then each + // DOWN scrolls the next row into the last (item_shown_row()). Reading + // one page only missed the X Specials under a MOON STONE, a NUGGET and + // four more, and the Tower rival was fought with none (console B, + // 2026-11-12). + if (!cancel){ + for (int c = 0; c < ITEM_LIST_ROWS / 2; c++){ + pbf_press_dpad(context, DPAD_DOWN, 100ms, 300ms); + } + } + while (!cancel && reads.size() < MAX_ITEMS_POCKET_ROWS){ + pbf_press_dpad(context, DPAD_DOWN, 100ms, 400ms); + context.wait_for_all_requests(); + screen = console.video().snapshot(); + BagRow read = screen ? read_bag_row(console, language, screen, ITEM_LIST_ROWS - 1) : BagRow{}; + cancel = !screen || read.item == "cancel"; + if (!cancel){ + reads.push_back(std::move(read)); + } + } + std::vector rows = pocket_rows(std::move(reads)); std::string text; for (const BagRow& row : rows){ text += std::format(" {} x{};", row.item, row.count); @@ -944,11 +902,10 @@ void recover_after_battle( for (const std::string& item : recovery_items(supplies)){ // The row before the count drops: a counted item with none left // takes no row. - const int row = item_row(supplies, item); - if (!use_item_on_overworld(console, context, row, item, checks, language)){ + if (!use_item_on_overworld(console, context, supplies, item, checks, language)){ continue; } - (*count_slot(supplies, item))--; + spend_item(supplies, item); if (item == "potion"){ // One Potion (20 HP) takes a starter of these levels from red // to green; the bar can't be read again on the overworld. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp index 1f689f35d0..e244fa4f62 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp @@ -169,6 +169,31 @@ UnitTestResult test_risks(){ return true; } +// The Tower rival (console B, 2026-11-12, blacked out): Blastoise with +// Bite, Water Pulse, Bubble and Dig used Bite on everything. Water Pulse +// where it ties: with Bite against Pidgeotto, with Bubble and Dig against +// Growlithe; Bite against Kadabra, Gyarados and Ivysaur. +UnitTestResult test_water_pulse_ties(){ + PartyMember blastoise = grown_to(new_member("squirtle", 5), 36); + blastoise.moves = {{"bite", 25}, {"water-pulse", 20}, {"bubble", 30}, {"dig", 10}}; + constexpr size_t BITE_SLOT = 0; + constexpr size_t WATER_PULSE_SLOT = 1; + const std::vector> cases = { + {"pidgeotto", WATER_PULSE_SLOT}, + {"growlithe", WATER_PULSE_SLOT}, + {"kadabra", BITE_SLOT}, + {"gyarados", BITE_SLOT}, + {"ivysaur", BITE_SLOT}, + }; + for (const auto& [foe, expected] : cases){ + const std::optional slot = attack_slot_against(blastoise, {foe}); + if (slot != expected){ + return std::format("{}: expected slot {}, got slot {}.", foe, expected, slot ? std::to_string(*slot) : "none"); + } + } + return true; +} + // A wild Pokemon that wasn't read, or a name the data doesn't have, gets // the plan's order: Water Gun first. UnitTestResult test_wild_fallback(){ @@ -194,6 +219,10 @@ const AutoStoryBattleDataTestCase AUTO_STORY_BATTLE_DATA_CASES[] = { .input = {.name = "Miguel's Grimer: Water Gun", .body = test_miguel_grimer}, .expectation = {.description = "verifies move matchup choice against Miguel Grimer"}, }, + { + .input = {.name = "Water Pulse on ties at the Tower rival", .body = test_water_pulse_ties}, + .expectation = {.description = "prefers the strongest STAB move when matchups tie"}, + }, { .input = {.name = "Bite on Psychic, Ghost and Water-resistant foes", .body = test_bite_wins}, .expectation = {.description = "verifies move matchup prioritization for Bite"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 85d72dc2a2..246f7c3d72 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -208,6 +208,10 @@ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ m_antidote_used = true; return TurnAction{.choice = TurnChoice::ANTIDOTE, .heal_reason = items.reason}; } + if (std::optional item = planned_item(status)){ + m_planned_item = *item; + return TurnAction{.choice = TurnChoice::BATTLE_ITEM, .heal_reason = items.reason, .item = std::move(*item)}; + } TurnAction action = move_turn(); action.heal_reason = items.reason; return action; @@ -252,6 +256,36 @@ TurnAction BattleDecisions::move_turn(){ return TurnAction{.choice = TurnChoice::MOVE, .slot = *slot}; } +std::optional BattleDecisions::planned_item(const PartyStatus& status) const{ + if (m_kind != BattleKind::TRAINER || m_items_off || status.hp_red){ + return std::nullopt; + } + for (const Pokemon::StoryItem& use : m_supplies.battle_items){ + if (use.quantity > 0 && item_row(m_supplies, use.item) >= 0){ + return use.item; + } + } + return std::nullopt; +} + +void BattleDecisions::planned_item_used(){ + for (Pokemon::StoryItem& use : m_supplies.battle_items){ + if (use.item == m_planned_item && use.quantity > 0){ + use.quantity--; + break; + } + } + const auto count = m_supplies.other_counts.find(m_planned_item); + if (count == m_supplies.other_counts.end() || --count->second > 0){ + return; + } + m_supplies.other_counts.erase(count); + const auto row = std::find(m_supplies.pocket.begin(), m_supplies.pocket.end(), m_planned_item); + if (row != m_supplies.pocket.end()){ + m_supplies.pocket.erase(row); + } +} + void BattleDecisions::count_down_refused(){ for (auto it = m_refused.begin(); it != m_refused.end();){ it = --it->second <= 0 ? m_refused.erase(it) : std::next(it); @@ -303,6 +337,9 @@ void BattleDecisions::turn_done(TurnChoice choice, TurnResult result){ m_supplies.awakenings--; m_supplies.status = StatusCondition::NONE; return; + case TurnChoice::BATTLE_ITEM: + planned_item_used(); + return; case TurnChoice::RUN: case TurnChoice::MOVE: return; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h index 914d5cb826..167dd3c9ab 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -73,6 +73,12 @@ class BattleDecisions{ private: TurnAction lead_turn(const PartyStatus& status); TurnAction move_turn(); + // The next of the plan's battle items whose pocket row is known, for + // a trainer's battle with the lead's HP not red; none otherwise. + std::optional planned_item(const PartyStatus& status) const; + // The plan's battle item chosen last was used: its quantity and count + // go down, and its pocket row goes with the last one the bag had. + void planned_item_used(); // The HP the lead lost since the last turn, from the bar. void see_hit(const PartyStatus& status); void count_down_refused(); @@ -86,6 +92,8 @@ class BattleDecisions{ bool m_antidote_used = false; // An item read as another in the bag: none is used again this battle. bool m_items_off = false; + // The plan's battle item chosen last. + std::string m_planned_item; bool m_lost = false; // NO was answered to "Delete a move?": "Stop learning?" comes next. bool m_declined_delete = false; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h index cf632eccc6..52b442abe6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h @@ -31,6 +31,8 @@ enum class TurnChoice{ POTION, ANTIDOTE, AWAKENING, + // One of the plan's battle items (an X Special), on the lead. + BATTLE_ITEM, MOVE, }; @@ -42,6 +44,8 @@ struct TurnAction{ // Why a Potion was or wasn't used, for the log; empty when none was // weighed (green HP, awake). std::string heal_reason = {}; + // For BATTLE_ITEM, the item's slug. + std::string item = {}; }; // What came of a TurnAction. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCeladon_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCeladon_Tests.cpp index af222f36e8..82e4274803 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCeladon_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCeladon_Tests.cpp @@ -449,6 +449,7 @@ void add_tests_AutoStoryCeladon(UnitTestDatabase& database){ database.add(item); } add_tests_AutoStoryLavender(database); + add_tests_AutoStoryTower(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h index 5defa199a4..82981365ea 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCheckpoints.h @@ -18,6 +18,7 @@ #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/AutoStory/Pokemon_StoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_BlindNavigation.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" #include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" @@ -46,8 +47,8 @@ enum class StoryHandoff{ // which is where Starter RNG starts. With the handoff off, it runs on // into the next checkpoint as one, as the story did before the split. STARTER_RNG, - // The checkpoint saves beside the Magikarp salesman, facing him, which - // is where Gift RNG starts. + // The checkpoint saves where Gift RNG starts for its gift: beside the + // Magikarp salesman, facing him, or facing the Eevee's ball. GIFT_RNG, }; @@ -63,8 +64,17 @@ struct StoryCheckpoint : public Pokemon::StoryCheckpoint{ bool live_start = false; // The RNG program the user may run at this checkpoint. StoryHandoff handoff = StoryHandoff::NONE; + // With GIFT_RNG: the gift Gift RNG takes there. + PokemonFRLG_RngTarget gift = PokemonFRLG_RngTarget::magikarp; }; +// The pose the start check of `data` compares the loaded save with: +// nothing for a new game, or for a live-start row, which loads no save +// but starts where an RNG program left the game (console B, 2026-11-11: +// 09.04 stopped on the shiny Eevee's summary, which its start frame +// could never match). +std::optional checked_start_pose(const StoryCheckpoint& data); + // The handoffs a run stops for (AutoStory's options). struct StoryHandoffs{ bool sid_helper = false; @@ -79,9 +89,9 @@ struct StoryRunPlan{ // NONE: the run ends after `rows`. SID_HELPER: `rows` is empty; the run // plays the new game to the player's keyboard and stops there. // STARTER_RNG: the run stops after `rows`, the last of which saves at - // the starter's ball. GIFT_RNG: likewise, beside the Magikarp salesman; - // with `rows` empty, the run started at 04.03 and takes Gift RNG from - // the save beside the salesman, where the row before `first` ends. + // the starter's ball. GIFT_RNG: likewise, where a gift is taken; with + // `rows` empty, the run started at the live-start row after it (04.03) + // and takes Gift RNG from the save where the row before `first` ends. StoryHandoff stop = StoryHandoff::NONE; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 788385d2b4..ac6443b5eb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -253,6 +253,7 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ return Pokemon::outcome_failed("no_battle"); } env.supplies.foes = arg>(step, "foes"); + env.supplies.battle_items = arg>(step, "use_items"); if (!env.supplies.foes.empty()){ env.console.log(std::format( "Story: {} is {}, risk {}; attacks are chosen against the foe out.", @@ -263,6 +264,7 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ env.supplies.foes.clear(); env.supplies.trainer.clear(); env.supplies.foe_out.clear(); + env.supplies.battle_items.clear(); if (end == BattleEnd::LOST && !arg(step, "may_lose")){ return Pokemon::outcome_failed("blackout"); } @@ -357,6 +359,7 @@ std::string save_card_place(const std::string& map){ {"LavenderTown", "lavender-town"}, {"CeladonCity", "celadon-city"}, {"RocketHideout", "rocket-hideout"}, + {"PokemonTower", "pokemon-tower"}, }; for (const auto& [prefix, place] : PLACES){ if (map == prefix || map.rfind(prefix + "_", 0) == 0){ @@ -466,6 +469,23 @@ bool talk_opens_message(ConsoleHandle& console, ProControllerContext& context){ return shown >= 0; } +// A talk to someone who wanders (MOVEMENT_TYPE_WANDER_AROUND, as the +// Route 16 house's woman with HM02): A at the tile the player faces, each +// watched 2 s, until they step onto it and a message opens. They take a +// step every 0.5 to 2 s (pokefirered event_object_movement.c, +// MovementType_WanderAround), so a few tiles' zone has them in front of +// the player many times in WANDERER_TALK_TRIES. +constexpr int WANDERER_TALK_TRIES = 45; +bool talk_until_message(ConsoleHandle& console, ProControllerContext& context, const StoryStep& step){ + const int tries = step.action == TALK_WANDERER_VARIANT ? WANDERER_TALK_TRIES : 1; + for (int c = 0; c < tries; c++){ + if (talk_opens_message(console, context)){ + return true; + } + } + return false; +} + bool walked(StoryEnv& env, RunState& state, const StoryStep& step){ const Outcome outcome = walk_route(env, state, step); @@ -694,8 +714,8 @@ ConsoleAction console_action_of(StoryActionId id){ case StoryActionId::STEP: return take_step; case StoryActionId::TALK: - return [](StoryEnv& env, RunState&, const StoryStep&){ - if (!talk_opens_message(env.console, env.context)){ + return [](StoryEnv& env, RunState&, const StoryStep& step){ + if (!talk_until_message(env.console, env.context, step)){ return Pokemon::outcome_failed("no_message", "talk: A opened no message; nothing to talk to or pick up here."); } return Pokemon::outcome_ok(); @@ -890,7 +910,7 @@ StartRead read_console_start(StoryEnv& env, const std::string& checkpoint){ void keep_next_start_frame(StoryEnv& env, const std::string& ended){ const std::vector& table = story_checkpoints(); for (size_t c = 0; c + 1 < table.size(); c++){ - if (table[c].id == ended && table[c + 1].start){ + if (table[c].id == ended && checked_start_pose(table[c + 1])){ keep_console_frame(env.console, env.context, env.start_frames, table[c + 1].id, "saved at the end of " + ended); return; } @@ -899,6 +919,10 @@ void keep_next_start_frame(StoryEnv& env, const std::string& ended){ } // namespace +std::optional checked_start_pose(const StoryCheckpoint& data){ + return data.live_start ? std::nullopt : start_pose(data); +} + Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor){ executor.set_menu(data.menu); StoryEnv& env = executor.env(); @@ -908,7 +932,7 @@ Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& // program last saved there. With none kept, it passes. Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor, &env.prepared); add_start_check( - checkpoint, start_pose(data), + checkpoint, checked_start_pose(data), [&env, id = data.id]{ return read_console_start(env, id); }, [&env](const std::string& line){ env.console.log(line, COLOR_ORANGE); } ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 04d925ed05..d97cd8e685 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -48,6 +48,11 @@ namespace PokemonFRLG{ +// The variant of a TALK to someone who wanders (MOVEMENT_TYPE_WANDER_AROUND): +// the player faces a tile of their zone, and A is pressed until they step +// onto it and a message opens. +inline const std::string TALK_WANDERER_VARIANT = "wanderer"; + // What the story's events act on. `supplies` are what the bag holds now, // `saved_supplies` what the last save holds. struct StoryEnv{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp index 18489bd9ae..4a5095fd38 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -59,10 +59,13 @@ #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_HideoutLiftRoom.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" #include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryFieldMoves.h" +#include "PokemonFRLG_AutoStoryHideoutLift.h" #include "PokemonFRLG_AutoStoryRowSim.h" #include "PokemonFRLG_AutoStoryTable.h" #include "PokemonFRLG_AutoStoryFaultSweep_Tests.h" @@ -112,6 +115,8 @@ std::string_view fault_class_name(FaultClass fault){ const std::map KNOWN_FAILING{ {"PokemonFRLG::AutoStory - Fault sweep: 02.02, wild battles at the game's odds", "below_oak on Route 1 gives up after 9 stops part-way (seeds 16, 30): count stops that make no progress, not every battle"}, + {"PokemonFRLG::AutoStory - Fault sweep: 10.06, scene end pose", + "below_fuji_house plans from (4, 7), where Mr. Fuji's script warps the player (warp 4, 7, exact); from a tile off, no wall in his house funnels the walk onto (3, 4): legs that re-anchor, if the console shows the warp can land elsewhere"}, }; // The land encounter rates of the maps the story walks (pokefirered @@ -140,17 +145,28 @@ constexpr Milliseconds LATE_FADE = 1500ms; constexpr Milliseconds SLOW_FADE_IN = 1000ms; // The maps as the story after the Hall of Fame and a new game flag them: -// the same set for every row, as each stage's tests use. +// the same set for every row, as each stage's tests use, with the two +// lifts' coded rooms (09.02, 10.01). const std::vector& sweep_maps(){ static const std::vector maps = []{ const std::vector all = overworld_maps(); std::set flags = map_flag_set(all, "after_hall_of_fame"); flags.merge(map_flag_set(all, "new_game")); - return overworld_maps(flags); + std::vector flagged = overworld_maps(flags); + flagged.push_back(rocket_hideout_lift_room()); + flagged.push_back(department_store_lift_room()); + return flagged; }(); return maps; } +// `script` with the lifts' floors, for sweep_maps()' lift rooms. +SimScript with_lifts(SimScript script){ + script.lift_floors[std::string(LIFT_MAP)] = rocket_hideout_lift_exits(); + script.lift_floors[std::string(DEPT_STORE_LIFT_MAP)] = department_store_lift_exits(); + return script; +} + // Whether the overworld sim plays `step` (OverworldStepSim): the rest is stubbed. bool sim_plays(const StoryStep& step){ switch (step.kind){ @@ -160,7 +176,10 @@ bool sim_plays(const StoryStep& step){ case StoryStepKind::BATTLE: return true; case StoryStepKind::GAME: - return step.action == CUT_TREE_VARIANT; + // A Fly lands on its town's landing tile, as the sim plays it; a + // lift's warp lets out on its floor's tile (sweep_maps()' lift + // rooms, with_lifts()). + return step.action == CUT_TREE_VARIANT || is_field_move_step(step) || parse_lift_floor_step(step).has_value(); default: return false; } @@ -260,9 +279,10 @@ bool run_row_step( // play: in a clean run (`scripted` unset) at any step, else only at the // steps in `scripted`, where the clean run let it pass. RowRun run_row( - const StoryCheckpoint& row, const SimScript& script, const Landings& landings = {}, + const StoryCheckpoint& row, const SimScript& row_script, const Landings& landings = {}, const std::optional>& scripted = std::nullopt ){ + const SimScript script = with_lifts(row_script); RowRun out; std::optional off_maps; StoryPose at = *story_pose(Pokemon::pose_of(*row.start)); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.cpp new file mode 100644 index 0000000000..4f62918727 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.cpp @@ -0,0 +1,50 @@ +/* AutoStory Field Move Steps + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.h" +#include "PokemonFRLG_AutoStoryFieldMoves.h" +#include "PokemonFRLG_AutoStoryFieldMoveSteps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +using Pokemon::Direction; +using Pokemon::StoryStep; + + +StoryStep fly_step(std::string name, size_t slot, std::string_view town){ + StoryStep step; + step.kind = Pokemon::StoryStepKind::GAME; + step.name = std::move(name); + step.action = FLY_VARIANT; + step.args = {{"town", std::string(town)}, {"slot", (int64_t)slot}}; + if (const std::optional index = fly_town_index(town)){ + const MapPosition& landing = kanto_fly_towns()[*index].landing; + step.pose_after = Pokemon::TileDeclared{landing.map, {landing.point}, Direction::SOUTH}; + } + return step; +} + +StoryStep surf_step(std::string name, Pokemon::GridPose water){ + StoryStep step; + step.kind = Pokemon::StoryStepKind::GAME; + step.name = std::move(name); + step.action = SURF_VARIANT; + if (water.facing){ + step.args = {{"direction", *water.facing}}; + } + step.pose_after = Pokemon::TileDeclared{std::move(water.map), std::move(water.tiles), water.facing}; + return step; +} + + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.h new file mode 100644 index 0000000000..31440a57a0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.h @@ -0,0 +1,39 @@ +/* AutoStory Field Move Steps + * + * From: https://github.com/PokemonAutomation/ + * + * The field move GAME steps (PokemonFRLG_AutoStoryFieldMoves.h) as a + * checkpoint's JSON gives them, for tests. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryFieldMoveSteps_H +#define PokemonAutomation_PokemonFRLG_AutoStoryFieldMoveSteps_H + +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Types/Pokemon_GridPose.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryStep.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A fly step to `town` with the Fly user in `slot` (from 1), ending on its +// landing tile facing south. +Pokemon::StoryStep fly_step(std::string name, size_t slot, std::string_view town); +// A surf step onto `water`'s tile, `water.facing` the way to it. +Pokemon::StoryStep surf_step(std::string name, Pokemon::GridPose water); + + +// Registers the field moves' tests. +void add_tests_AutoStoryFieldMoves(UnitTestDatabase& database); + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp new file mode 100644 index 0000000000..e8e8272d84 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp @@ -0,0 +1,212 @@ +/* AutoStory Field Moves + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/AutoStory/Pokemon_StoryInterrupts.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_PartyDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/Map/PokemonFRLG_MapDetector.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_MovementMechanics.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryFieldMoves.h" +#include "PokemonFRLG_AutoStoryGameArgs.h" +#include "PokemonFRLG_AutoStoryQuietOverworld.h" +#include "PokemonFRLG_AutoStoryStepInterrupts.h" +#include "PokemonFRLG_AutoStoryTeach.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +using namespace std::chrono_literals; +using Pokemon::Direction; +using Pokemon::StoryStep; + + +namespace{ + +// A Pokemon's menu has at most SUMMARY, four field moves, SWITCH, ITEM +// and CANCEL (the party's six slots are PARTY_SLOTS). +constexpr size_t MON_MENU_ROWS = 8; + +} // namespace + +std::optional parse_fly_step(const StoryStep& step){ + if (step.action != FLY_VARIANT){ + return std::nullopt; + } + const std::string* town = game_arg(step.args, "town"); + const std::optional index = town == nullptr ? std::nullopt : fly_town_index(*town); + const std::string* species = game_arg(step.args, "species"); + // A slot or a species, not both. + const std::optional slot = species != nullptr + ? (step.args.contains("slot") || species->empty() ? std::nullopt : std::optional(0)) + : counted_arg(step.args, "slot", PARTY_SLOTS); + const std::optional menu_row = step.args.contains("menu_row") + ? counted_arg(step.args, "menu_row", MON_MENU_ROWS) + : std::optional(FlyPlan{}.menu_row); + if (!index || !slot || !menu_row){ + return std::nullopt; + } + return FlyPlan{.slot = *slot, .species = species == nullptr ? "" : *species, .menu_row = *menu_row, .town = *index}; +} + +std::optional FlyPlan::party_slot(const MemberReader& reader) const{ + if (species.empty()){ + return slot; + } + return find_party_species(reader, species); +} + +std::optional parse_surf_step(const StoryStep& step){ + const Direction* direction = step.action == SURF_VARIANT ? game_arg(step.args, "direction") : nullptr; + if (direction == nullptr || step.args.size() != 1){ + return std::nullopt; + } + return *direction; +} + +bool is_field_move_step(const StoryStep& step){ + return parse_fly_step(step).has_value() || parse_surf_step(step).has_value(); +} + +std::vector field_move_specs(){ + using Pokemon::StoryArgType; + using Pokemon::StoryStepKind; + return { + {.kind = StoryStepKind::GAME, .name = FLY_VARIANT, .args = { + required_arg("town", StoryArgType::WORD, "the town's map, as kanto_fly_towns() names it (CeladonCity, Route4)"), + absent_arg("slot", StoryArgType::INTEGER, "the Fly user's party slot, from 1, when no species is named"), + absent_arg("species", StoryArgType::WORD, "the Fly user by its species, e.g. \"pidgey\": the first slot whose summary reads it"), + optional_arg("menu_row", StoryArgType::INTEGER, int64_t(2), "FLY's row on its menu, from 1: SUMMARY, then field moves in move order"), + }}, + {.kind = StoryStepKind::GAME, .name = SURF_VARIANT, .args = { + required_arg("direction", StoryArgType::DIRECTION, "the way to the water, from ground beside it"), + }}, + }; +} + + +namespace{ + +// Not measured on the console: the party menu's and the fly map's cursor +// taps, as the lift panel's (PokemonFRLG_AutoStoryHideout.cpp). A fly map +// cursor step takes 4 frames (HandleRegionMapInput(): 2 pixels a frame, +// 8 a cell); the release leaves it time to stop. +constexpr Milliseconds MENU_TAP = 80ms; +constexpr Milliseconds MENU_TAP_RELEASE = 240ms; +constexpr Milliseconds CURSOR_TAP = 80ms; +constexpr Milliseconds CURSOR_TAP_RELEASE = 170ms; +// Up-left to the map's corner: 21 cells at 4 frames each is 1.4 s. +constexpr Milliseconds CURSOR_TO_CORNER = 3000ms; +// The Pokemon's menu, after its A. +constexpr Milliseconds MON_MENU_TIMEOUT = 5000ms; +// The fly map, after FLY's A, and before its cursor takes the D-pad +// (open_fly_map_from_overworld()'s wait). +constexpr Milliseconds FLY_MAP_TIMEOUT = 20000ms; +constexpr Milliseconds FLY_MAP_SETTLE = 1000ms; +// The fade out after the town's A: none, the town wasn't one Fly goes to. +constexpr Milliseconds TAKEOFF_TIMEOUT = 10000ms; +// The flight and the landing, to the overworld at rest. +constexpr Milliseconds LANDING_TIMEOUT = 30000ms; + +void tap_dpad(ProControllerContext& context, DpadPosition dpad, size_t count, Milliseconds tap, Milliseconds release){ + for (size_t c = 0; c < count; c++){ + pbf_press_dpad(context, dpad, tap, release); + } +} + +// From the overworld to the fly map: the party, the Fly user, FLY. +// Returns the failure, or empty. +std::string open_fly_map(ConsoleHandle& console, ProControllerContext& context, const FlyPlan& plan){ + open_party_menu_from_overworld(console, context); + tap_dpad(context, DPAD_DOWN, plan.slot, MENU_TAP, MENU_TAP_RELEASE); + PartySelectionWatcher mon_menu(COLOR_RED); + context.wait_for_all_requests(); + pbf_press_button(context, BUTTON_A, 160ms, 0ms); + if (wait_until(console, context, MON_MENU_TIMEOUT, {mon_menu}) < 0){ + return "fly_no_menu"; + } + tap_dpad(context, DPAD_DOWN, plan.menu_row, MENU_TAP, MENU_TAP_RELEASE); + KantoMapWatcher fly_map(COLOR_RED); + context.wait_for_all_requests(); + pbf_press_button(context, BUTTON_A, 160ms, 0ms); + if (wait_until(console, context, FLY_MAP_TIMEOUT, {fly_map}) < 0){ + return "fly_no_map"; + } + pbf_wait(context, FLY_MAP_SETTLE); + return ""; +} + +// On the fly map: the cursor to the corner, then to the town, and A. +// Returns the failure, or empty once the overworld is at rest after the +// landing. +std::string fly_to_town(ConsoleHandle& console, ProControllerContext& context, const FlyTown& town){ + pbf_press_dpad(context, DPAD_UP_LEFT, CURSOR_TO_CORNER, CURSOR_TAP_RELEASE); + tap_dpad(context, DPAD_RIGHT, (size_t)town.cell.x, CURSOR_TAP, CURSOR_TAP_RELEASE); + tap_dpad(context, DPAD_DOWN, (size_t)town.cell.y, CURSOR_TAP, CURSOR_TAP_RELEASE); + BlackScreenWatcher takeoff(COLOR_RED); + context.wait_for_all_requests(); + pbf_press_button(context, BUTTON_A, 160ms, 0ms); + if (wait_until(console, context, TAKEOFF_TIMEOUT, {takeoff}) < 0){ + return "fly_no_takeoff"; + } + context.wait_for_all_requests(); + ConsoleScreenLook eyes(console, context); + const Pokemon::ScreenSettle settle = wait_for_quiet_overworld( + [&eyes](bool fresh){ return eyes.look(fresh); }, + MovementMechanics::AFTER_BATTLE_QUIET, LANDING_TIMEOUT + ); + console.log(std::format("Story: landed in {}, {}", town.name, Pokemon::describe(settle))); + return quiet_overworld(settle, MovementMechanics::AFTER_BATTLE_QUIET) ? "" : "fly_no_landing"; +} + +} // namespace + +std::optional run_field_move_step( + ConsoleHandle& console, ProControllerContext& context, Language language, const StoryStep& step +){ + const auto done = [&step]{ + return step.pose_after ? Pokemon::outcome_ok(Pokemon::pose_of(*step.pose_after)) : Pokemon::outcome_ok(); + }; + if (const std::optional water = parse_surf_step(step)){ + console.log(std::format("Story: Surf {}.", Pokemon::direction_name(*water))); + OverworldWalkSteps::start_surf(console, context, *water, false); + return done(); + } + std::optional plan = parse_fly_step(step); + if (!plan){ + return std::nullopt; + } + const FlyTown& town = kanto_fly_towns()[plan->town]; + const std::optional slot = plan->party_slot(console_member_reader(console, context, language)); + if (!slot){ + console.log(std::format("Story: no {} read in the party to Fly with.", plan->species), COLOR_RED); + return Pokemon::outcome_failed("fly_no_member", plan->species); + } + plan->slot = *slot; + console.log(std::format( + "Story: Fly with slot {}, menu row {}, to {} (cell {}, {}).", + plan->slot + 1, plan->menu_row + 1, town.name, town.cell.x, town.cell.y + )); + std::string failure = open_fly_map(console, context, *plan); + if (failure.empty()){ + failure = fly_to_town(console, context, town); + } + return failure.empty() ? done() : Pokemon::outcome_failed(failure, town.name); +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h new file mode 100644 index 0000000000..3b61fa7ed5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h @@ -0,0 +1,80 @@ +/* AutoStory Field Moves + * + * From: https://github.com/PokemonAutomation/ + * + * The HMs the story uses away from what the player faces: Fly to a town, + * and Surf onto the water. Both are GAME steps named by their variant. + * The legs and routes after a Surf start on the water and are walked + * surfing (fixed_route(), plan_overworld_route()), until a step onto + * land gets the player off. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryFieldMoves_H +#define PokemonAutomation_PokemonFRLG_AutoStoryFieldMoves_H + +#include +#include +#include +#include +#include +#include "CommonFramework/Language.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryStep.h" +#include "PokemonFRLG_AutoStoryMemberInfo.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The GAME step that flies to a town, outdoors: START, POKEMON, the Fly +// user (`slot`, from 1, or the first member read as `species`), FLY on its menu (`menu_row`, from 1: SUMMARY, +// then its field moves in move order, so 2 when Fly is its only one; +// pokefirered SetPartyMonFieldSelectionActions()), and `town` on the fly +// map (kanto_fly_towns()). It ends on the town's landing tile. +inline const std::string FLY_VARIANT = "fly"; +// The GAME step that surfs onto the water `direction` of the player, on +// ground beside it: A facing it, YES to "Would you like to SURF?", and +// the jump onto it. It ends on that water tile. +inline const std::string SURF_VARIANT = "surf"; + +// A fly step's choices, counted from 0. +struct FlyPlan{ + size_t slot = 0; + // The Fly user's species ("pidgey"), when the step names it instead + // of a slot: party_slot() finds its slot in the party. + std::string species = {}; + size_t menu_row = 1; + // In kanto_fly_towns(). + size_t town = 0; + + // The party slot to fly with: `slot`, or the first member `reader` + // reads as `species`; nothing if none does. + std::optional party_slot(const MemberReader& reader) const; +}; + +// The fly step's choices, or nothing if `step` isn't one or names no town +// Fly goes to. +std::optional parse_fly_step(const Pokemon::StoryStep& step); +// The way a surf step faces the water, or nothing if it isn't one. +std::optional parse_surf_step(const Pokemon::StoryStep& step); +// Whether `step` is one of this file's steps. +bool is_field_move_step(const Pokemon::StoryStep& step); +// This file's GAME actions and their args (field_action_specs()). +std::vector field_move_specs(); + +// On the console, a step of this file's; nothing for another step. The +// step ends on its pose_after, if it has one. +std::optional run_field_move_step( + ConsoleHandle& console, ProControllerContext& context, Language language, const Pokemon::StoryStep& step +); + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves_Tests.cpp new file mode 100644 index 0000000000..cae15e22a7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves_Tests.cpp @@ -0,0 +1,290 @@ +/* AutoStory Field Moves Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryFieldMoves.h" +#include "PokemonFRLG_AutoStoryFieldMoveSteps.h" +#include "PokemonFRLG_AutoStoryHideout.h" +#include "PokemonFRLG_AutoStoryLegs.h" +#include "PokemonFRLG_AutoStoryPacedRoute.h" +#include "PokemonFRLG_AutoStoryPoses.h" +#include "PokemonFRLG_AutoStoryRowSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +using Pokemon::StoryLeg; +using Pokemon::StoryStep; + +struct FieldMovesInput{ + std::string name; + UnitTestResult (*body)(); +}; +struct FieldMovesExpectation{ + std::string_view description; +}; +struct FieldMovesCase{ + FieldMovesInput input; + FieldMovesExpectation expectation; +}; + +class Test_AutoStoryFieldMoves : public UnitTest{ +public: + explicit Test_AutoStoryFieldMoves(FieldMovesCase test_case) + : UnitTest("PokemonFRLG::AutoStoryFieldMoves - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_case.input.body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + FieldMovesCase m_case; +}; + +bool built_in(const std::string& map){ + const std::vector>& maps = overworld_map_json(); + return std::any_of(maps.begin(), maps.end(), [&](const auto& entry){ return entry.first == map; }); +} + +// Each town on its own cell of the fly map; on the maps built in, its +// landing tile below a door (a Center's, or the player's house). +UnitTestResult test_fly_map(){ + std::set> cells; + std::set names; + for (const FlyTown& town : kanto_fly_towns()){ + if (town.cell.x < 0 || town.cell.x >= FLY_MAP_COLUMNS || town.cell.y < 0 || town.cell.y >= FLY_MAP_ROWS + || !cells.emplace(town.cell.x, town.cell.y).second || !names.insert(town.name).second + ){ + return town.name + ": its cell is off the fly map or another town's, or its name is taken."; + } + if (!built_in(town.landing.map)){ + continue; + } + const MapData map = load_map(town.landing.map); + const TilePos door = town.landing.point.next(Direction::NORTH); + if (is_wall(map, town.landing.point) || !is_door(map, door)){ + return std::format("{}: no door north of the landing tile {}.", town.name, to_string(town.landing)); + } + } + if (kanto_fly_towns().size() != 13 || fly_town_index("CeladonCity") != 8 || fly_town_index("Celadon")){ + return "Expected Kanto's 13 Fly destinations, Celadon City 9th."; + } + return true; +} + +// The steps' args: a fly step needs a town Fly goes to and a party slot; +// its menu row is SUMMARY's next unless it says. A surf step needs only +// its way to the water. +UnitTestResult test_args(){ + StoryStep fly = fly_step("fly_celadon", 2, "CeladonCity"); + std::optional plan = parse_fly_step(fly); + if (!plan || plan->slot != 1 || plan->menu_row != 1 || plan->town != 8){ + return "Expected slot 2, menu row 2, Celadon City."; + } + const Pokemon::DeclaredPose landed = Pokemon::TileDeclared{"CeladonCity", {{48, 12}}, Direction::SOUTH}; + if (!(fly.pose_after == landed)){ + return "Expected the fly step to end below Celadon's Center door, (48, 12)."; + } + fly.args["menu_row"] = int64_t(3); + plan = parse_fly_step(fly); + if (!plan || plan->menu_row != 2){ + return "Expected menu row 3."; + } + fly.args["slot"] = int64_t(7); + if (parse_fly_step(fly) || parse_fly_step(fly_step("fly", 1, "SeafoamIslands"))){ + return "Expected no plan for slot 7 or a town Fly doesn't go to."; + } + StoryStep surf = surf_step("surf", Pokemon::GridPose{"PalletTown", {{7, 17}}, Direction::SOUTH}); + if (parse_surf_step(surf) != Direction::SOUTH || !is_field_move_step(surf)){ + return "Expected a surf step south."; + } + surf.args["town"] = std::string("PalletTown"); + if (parse_surf_step(surf) || is_field_move_step(surf)){ + return "Expected no surf step with an arg it doesn't take."; + } + const std::vector specs = field_action_specs(); + const auto has = [&](const std::string& name){ + return std::any_of(specs.begin(), specs.end(), [&](const Pokemon::StoryActionSpec& spec){ return spec.name == name; }); + }; + if (!has(FLY_VARIANT) || !has(SURF_VARIANT)){ + return "Expected fly and surf among the field actions."; + } + return true; +} + +// Fly from Lavender Town to Celadon City on the sim, as a row runs it: +// the player stands on Celadon's landing tile, off the Bicycle. +UnitTestResult test_fly_on_sim(){ + const MapPosition lavender{"LavenderTown", {6, 6}}; + SimScript script; + script.on_bike = true; + OverworldSim sim(story_maps(), lavender, Direction::SOUTH, script); + StoryPose at{lavender.map, lavender.point, Direction::SOUTH}; + const std::string failure = row_step_on_sim(sim, at, fly_step("fly_celadon", 1, "CeladonCity"), "11.01"); + if (!failure.empty()){ + return failure; + } + const MapPosition celadon{"CeladonCity", {48, 12}}; + if (!(sim.state().position == celadon) || !(at.map == celadon.map && at.tile == celadon.point) || sim.state().on_bike){ + return "After Fly, on " + to_string(sim.state().position) + ", not on foot on Celadon's (48, 12)."; + } + if (!sim.state().violations.empty()){ + return "Fly broke the game's rules: " + sim.state().violations.front(); + } + return true; +} + +StoryStep legs_step(std::string name, std::vector legs){ + StoryStep step; + step.kind = Pokemon::StoryStepKind::LEGS; + step.name = std::move(name); + step.args = {{"legs", std::move(legs)}}; + return step; +} + +// Viridian City's pond, x 11 to 16 and y 26 to 30, ground west and east +// of it. (Pallet Town's is in its Fat Man's wander box, so no leg crosses +// it.) +const MapPosition POND_WEST_SHORE{"ViridianCity", {10, 27}}; +const MapPosition POND_EAST_SHORE{"ViridianCity", {17, 27}}; + +// Legs from the water: surfing, until a one-tile leg onto land. Legs +// onto the water from land, or off it with more tiles after, aren't +// legs. +UnitTestResult test_legs_from_water(){ + const std::vector& maps = story_maps(); + const MapPosition pond{"ViridianCity", {11, 27}}; + const std::optional> route = fixed_route(maps, pond, {{Direction::EAST, 5}, {Direction::EAST, 1}}); + if (!route || route->size() != 2 || !(*route)[0].surfing || !(*route)[0].wild || !(*route)[1].surfing + || !((*route)[1].end == POND_EAST_SHORE) + ){ + return "Expected east 5 surfing, then east 1 onto Viridian City's (17, 27)."; + } + if (fixed_route(maps, MapPosition{"ViridianCity", {16, 27}}, {{Direction::EAST, 2}}) + || fixed_route(maps, POND_WEST_SHORE, {{Direction::EAST, 1}}) + ){ + return "Expected no legs off the water with a tile after, or onto it without Surf."; + } + return true; +} + +// Viridian City's pond on the sim, as a row runs it: Surf east from its +// west shore, the legs across it surfing, and off it onto the east shore. +UnitTestResult test_surf_legs_on_sim(){ + const MapPosition shore = POND_WEST_SHORE; + OverworldSim sim(story_maps(), shore, Direction::NORTH); + StoryPose at{shore.map, shore.point, Direction::NORTH}; + std::string failure = row_step_on_sim(sim, at, surf_step("surf", Pokemon::GridPose{"ViridianCity", {{11, 27}}, Direction::EAST}), "13.01"); + if (!failure.empty() || !sim.state().surfing){ + return "Surf: " + (failure.empty() ? std::string("not on the water.") : failure); + } + failure = row_step_on_sim(sim, at, legs_step("across", {{Direction::EAST, 5}, {Direction::EAST, 1}}), "13.01"); + if (!failure.empty()){ + return failure; + } + if (!(sim.state().position == POND_EAST_SHORE) || sim.state().surfing){ + return "After the legs, on " + to_string(sim.state().position) + ", not on land at (17, 27)."; + } + if (!sim.state().violations.empty()){ + return "Surf broke the game's rules: " + sim.state().violations.front(); + } + return true; +} + +// Routes planned on and onto the water, walked by the sim's walker: from +// the water the story's routes surf to land (Surf itself is off for +// them: RouteCost::SURF); with Surf on, a route surfs onto the pond. +UnitTestResult test_routes_on_water(){ + const std::vector& maps = story_maps(); + OverworldSim sim(maps, POND_WEST_SHORE, Direction::EAST); + if (!sim.use_field(SimField::SURF)){ + return "No Surf east of Viridian City's (10, 27)."; + } + const MapPosition water = sim.state().position; + const MapPosition land{"ViridianCity", {20, 28}}; + const std::optional> off = plan_overworld_route(maps, water, RouteGoal{land, std::nullopt}, story_route_costs()); + if (!off){ + return "No story route off the pond to (20, 28)."; + } + std::string failure = OverworldSimWalker(sim).run(*off, RoutePlanning{.maps = &maps, .costs = story_route_costs(), .start = water, .label = "Sim"}); + if (!failure.empty() || !(sim.state().position == land) || sim.state().surfing){ + return "Off the pond, on " + to_string(sim.state().position) + ": " + failure; + } + const MapPosition pond{"ViridianCity", {13, 28}}; + const std::optional> onto = plan_overworld_route(maps, land, RouteGoal{pond, std::nullopt}); + const bool surfs = onto && std::any_of(onto->begin(), onto->end(), [](const RouteStep& step){ return step.action == RouteAction::SURF; }); + if (!surfs){ + return "Expected a route that surfs onto the pond."; + } + failure = OverworldSimWalker(sim).run(*onto, RoutePlanning{.maps = &maps, .start = land, .label = "Sim"}); + if (!failure.empty() || !(sim.state().position == pond) || !sim.state().surfing){ + return "Onto the pond, on " + to_string(sim.state().position) + ": " + failure; + } + return true; +} + +const FieldMovesCase CASES[] = { + { + .input = {.name = "fly map", .body = test_fly_map}, + .expectation = {.description = "each town on its own cell, landing below a door"}, + }, + { + .input = {.name = "step args", .body = test_args}, + .expectation = {.description = "fly and surf steps read their args, the specs list them"}, + }, + { + .input = {.name = "fly on the sim", .body = test_fly_on_sim}, + .expectation = {.description = "Lavender Town to Celadon City's landing tile"}, + }, + { + .input = {.name = "legs from the water", .body = test_legs_from_water}, + .expectation = {.description = "surfing legs, and a one-tile leg off the water"}, + }, + { + .input = {.name = "surf and legs on the sim", .body = test_surf_legs_on_sim}, + .expectation = {.description = "Viridian City's pond: Surf, across, and off"}, + }, + { + .input = {.name = "routes on the water on the sim", .body = test_routes_on_water}, + .expectation = {.description = "planned routes off and onto the pond, walked"}, + }, +}; + +} // namespace + + +void add_tests_AutoStoryFieldMoves(UnitTestDatabase& database){ + for (const FieldMovesCase& test_case : CASES){ + database.add(test_case); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.cpp index 246b13055d..b9ce0e169a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.cpp @@ -41,7 +41,7 @@ StoryStep lift_floor_step(std::string name, std::string_view from, std::string_v StoryStep step = game_step(std::move(name), LIFT_FLOOR_VARIANT); step.args = {{"from", std::string(from)}, {"to", std::string(to)}}; if (const std::optional ride = parse_lift_floor_step(step)){ - const MapPosition& exit = rocket_hideout_lift_exits()[ride->to]; + const MapPosition& exit = lift_exits(ride->lift)[ride->to]; step.pose_after = Pokemon::TileDeclared{exit.map, {exit.point}, Direction::SOUTH}; } return step; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.h index 0cae409927..27b7cc5d1b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.h @@ -27,10 +27,10 @@ namespace PokemonFRLG{ // (POSTER_SWITCH_VARIANT). Pokemon::StoryStep poster_switch_step(std::string name); -// Rides the Rocket Hideout's lift from the floor it stands at to `to` -// (LIFT_FLOOR_VARIANT): "B1F", "B2F", "B4F". The player starts below -// `from`'s lift door, facing north, and ends a tile below `to`'s, -// facing south (rocket_hideout_lift_exits()). +// Rides a lift from the floor it stands at to `to` (LIFT_FLOOR_VARIANT): +// "B1F", "B2F", "B4F" (the Rocket Hideout's) or "1F" to "5F" (the +// Department Store's). The player starts below `from`'s lift door, +// facing north, and ends a tile below `to`'s, facing south (lift_exits()). Pokemon::StoryStep lift_floor_step(std::string name, std::string_view from, std::string_view to); // Into the Pokemon Center `center` (a map name) from below its door, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.cpp index 9046387f0f..122d63561b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.cpp @@ -11,6 +11,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryFieldMoves.h" #include "PokemonFRLG_AutoStoryHideout.h" #include "PokemonFRLG_AutoStoryHideoutLift.h" #include "PokemonFRLG_AutoStoryItemUse.h" @@ -30,16 +31,34 @@ namespace PokemonFRLG{ using namespace std::chrono_literals; -const std::vector& rocket_hideout_lift_menu(){ - static const std::vector MENU{"B1F", "B2F", "B4F", "EXIT"}; - return MENU; +const std::vector& lift_menu(std::string_view lift){ + static const std::vector NONE; + static const std::vector HIDEOUT{"B1F", "B2F", "B4F", "EXIT"}; + static const std::vector STORE{"5F", "4F", "3F", "2F", "1F", "EXIT"}; + if (lift == LIFT_MAP){ + return HIDEOUT; + } + if (lift == DEPT_STORE_LIFT_MAP){ + return STORE; + } + return NONE; +} + +const std::vector& lift_exits(std::string_view lift){ + static const std::vector NONE; + if (lift == LIFT_MAP){ + return rocket_hideout_lift_exits(); + } + if (lift == DEPT_STORE_LIFT_MAP){ + return department_store_lift_exits(); + } + return NONE; } namespace{ -// The row of `floor` on the panel's menu, if it is a floor (not EXIT). -std::optional floor_row(std::string_view floor){ - const std::vector& menu = rocket_hideout_lift_menu(); +// The row of `floor` on `menu`, if it is a floor (not EXIT). +std::optional floor_row(const std::vector& menu, std::string_view floor){ for (size_t row = 0; row + 1 < menu.size(); row++){ if (menu[row] == floor){ return row; @@ -59,12 +78,14 @@ std::optional parse_lift_floor_step(const Pokemon::StoryStep& step){ if (from_name == nullptr || to_name == nullptr){ return std::nullopt; } - const std::optional from = floor_row(*from_name); - const std::optional to = floor_row(*to_name); - if (!from || !to){ - return std::nullopt; + for (std::string_view lift : {LIFT_MAP, DEPT_STORE_LIFT_MAP}){ + const std::optional from = floor_row(lift_menu(lift), *from_name); + const std::optional to = floor_row(lift_menu(lift), *to_name); + if (from && to){ + return LiftRide{*from, *to, lift}; + } } - return LiftRide{*from, *to}; + return std::nullopt; } MenuPresses lift_menu_presses(const LiftRide& ride, size_t entries){ @@ -89,7 +110,7 @@ std::vector field_action_specs(){ std::vector specs{ {.kind = StoryStepKind::GAME, .name = POSTER_SWITCH_VARIANT, .args = {}}, {.kind = StoryStepKind::GAME, .name = LIFT_FLOOR_VARIANT, .args = { - required_arg("from", StoryArgType::WORD, "the floor the lift stands at, as the panel names it (B1F, B2F, B4F)"), + required_arg("from", StoryArgType::WORD, "the floor the lift stands at, as the panel names it (B1F, B2F, B4F; 1F to 5F)"), required_arg("to", StoryArgType::WORD, "the floor it rides to"), }}, {.kind = StoryStepKind::GAME, .name = USE_ITEM_VARIANT, .args = { @@ -101,6 +122,9 @@ std::vector field_action_specs(){ for (const std::string& center : {CENTER_ENTER_VARIANT, CENTER_EXIT_VARIANT}){ specs.push_back({.kind = StoryStepKind::GAME, .name = center, .args = {}}); } + for (Pokemon::StoryActionSpec& move : field_move_specs()){ + specs.push_back(std::move(move)); + } return specs; } @@ -118,11 +142,12 @@ constexpr Milliseconds HIDEOUT_SCENE_TIMEOUT = 30000ms; } // namespace void pick_lift_floor(ConsoleHandle& console, ProControllerContext& context, const LiftRide& ride){ - const MenuPresses presses = lift_menu_presses(ride, rocket_hideout_lift_menu().size()); - console.log( - "Story: lift from " + rocket_hideout_lift_menu()[ride.from] + " to " + rocket_hideout_lift_menu()[ride.to] - + ": " + std::to_string(presses.presses) + " press(es) " + Pokemon::direction_name(presses.direction) + "." - ); + const std::vector& menu = lift_menu(ride.lift); + const MenuPresses presses = lift_menu_presses(ride, menu.size()); + console.log(std::format( + "Story: lift from {} to {}: {} press(es) {}.", + menu[ride.from], menu[ride.to], presses.presses, Pokemon::direction_name(presses.direction) + )); pbf_press_button(context, BUTTON_A, 160ms, LIFT_MENU_WAIT); const DpadPosition dpad = presses.direction == Pokemon::Direction::SOUTH ? DPAD_DOWN : DPAD_UP; for (size_t c = 0; c < presses.presses; c++){ @@ -165,6 +190,9 @@ std::optional run_field_game_step( ride_lift(console, context, *ride, player); return done(); } + if (std::optional moved = run_field_move_step(console, context, language, step)){ + return moved; + } if (is_center_variant(step.action)){ // Both start facing north: at the door, or at the nurse. walk_room_legs(console, context, center_legs(step.action), Pokemon::Direction::NORTH, player); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.h index e6a2cde118..780f652d4d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.h @@ -39,12 +39,13 @@ namespace PokemonFRLG{ // beaten first. inline const std::string POSTER_SWITCH_VARIANT = "poster_switch"; -// The GAME step that rides the Rocket Hideout's lift with the LIFT KEY, -// its args `from` and `to`, floors as the panel names them (B1F, B2F, -// B4F). `from` is the floor the lift stands at, where the panel's cursor -// starts. The player starts below `from`'s lift door, facing north, and -// ends a tile below `to`'s (rocket_hideout_lift_exits()): the lift is -// walked by a script (lift_in_legs(), lift_out_legs()), not a map. +// The GAME step that rides a lift, the Rocket Hideout's with the LIFT KEY +// or the Celadon Department Store's, its args `from` and `to`, floors as +// the panel names them (B1F, B2F, B4F; 5F to 1F). `from` is the floor the +// lift stands at, where the panel's cursor starts. The player starts +// below `from`'s lift door, facing north, and ends a tile below `to`'s +// (lift_exits()): the lift is walked by a script (lift_in_legs(), +// lift_out_legs()), not a map. inline const std::string LIFT_FLOOR_VARIANT = "lift_floor"; @@ -59,7 +60,8 @@ std::vector field_action_specs(); void push_poster_switch(ConsoleHandle& console, ProControllerContext& context); // On the console, a GAME step of this file's, a Pokemon Center's -// (is_center_variant()) or an item from the bag (is_item_use_step()); +// (is_center_variant()), a field move (is_field_move_step()) or an item +// from the bag (is_item_use_step()); // nothing for another GAME step. The step ends on its pose_after, if it // has one (an Escape Rope's, a lift ride's, a Center's). std::optional run_field_game_step( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideoutLift.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideoutLift.h index c86267c68c..c27dd362cb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideoutLift.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideoutLift.h @@ -2,8 +2,9 @@ * * From: https://github.com/PokemonAutomation/ * - * Riding the Rocket Hideout's lift: its panel's menu, the presses that - * pick a floor, and the ride on the console. + * Riding a lift, the Rocket Hideout's or the Celadon Department Store's + * (one layout): its panel's menu, the presses that pick a floor, and the + * ride on the console. * */ @@ -18,24 +19,34 @@ #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryStep.h" #include "Pokemon/Navigation/Pokemon_Grid.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_HideoutLiftRoom.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// The lift panel's menu, top first (pokefirered -// sMultichoiceList_RocketHideoutElevator): B1F, B2F, B4F, EXIT. -const std::vector& rocket_hideout_lift_menu(); +// The panel's menu of the lift whose room is `lift`, top first; empty for +// another map. LIFT_MAP: B1F, B2F, B4F, EXIT (pokefirered +// sMultichoiceList_RocketHideoutElevator); DEPT_STORE_LIFT_MAP: 5F, 4F, +// 3F, 2F, 1F, EXIT (sMultichoiceList_DeptStoreElevator). +const std::vector& lift_menu(std::string_view lift); +// Where the lift `lift` lets out for each floor on its panel, top first; +// empty for another map. +const std::vector& lift_exits(std::string_view lift); -// A ride: the menu rows the cursor starts on and is moved to. +// A ride: the lift's room, and the menu rows the cursor starts on (the +// floor the player came from: pokefirered GetElevatorFloor()) and is +// moved to. struct LiftRide{ size_t from = 0; size_t to = 0; + std::string_view lift = LIFT_MAP; }; // The ride a lift_floor step names, or nothing if it is not one, or names -// a floor the panel hasn't. +// floors no one panel has. The floors' names pick the lift: B1F..B4F the +// hideout's, 1F..5F the store's. std::optional parse_lift_floor_step(const Pokemon::StoryStep& step); // Presses of the D-pad on a menu: which way, how many. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout_Tests.cpp index cbfc653e16..f17b50290c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout_Tests.cpp @@ -61,7 +61,7 @@ class Test_AutoStoryHideout : public UnitTest{ } return true; } - const MenuPresses got = lift_menu_presses(*ride, rocket_hideout_lift_menu().size()); + const MenuPresses got = lift_menu_presses(*ride, lift_menu(ride->lift).size()); if (got.direction != expected->direction || got.presses != expected->presses){ return std::format( "\"{}\": {} press(es) {}, expected {} {}.", m_case.input.variant, @@ -759,6 +759,24 @@ const LiftCase LIFT_CASES[] = { .input = {.name = "one floor only", .variant = "lift_floor B2F"}, .expectation = {.presses = std::nullopt}, }, + { + // The Department Store's: 5F, 4F, 3F, 2F, 1F, EXIT. From 1F, down + // past EXIT wraps to 5F (10.01's lift_to_5f). + .input = {.name = "store 1F to 5F: two down past EXIT", .variant = "lift_floor 1F 5F"}, + .expectation = {.presses = MenuPresses{Pokemon::Direction::SOUTH, 2}}, + }, + { + .input = {.name = "store 5F to 1F: two up past EXIT", .variant = "lift_floor 5F 1F"}, + .expectation = {.presses = MenuPresses{Pokemon::Direction::NORTH, 2}}, + }, + { + .input = {.name = "store 1F to 3F: two up", .variant = "lift_floor 1F 3F"}, + .expectation = {.presses = MenuPresses{Pokemon::Direction::NORTH, 2}}, + }, + { + .input = {.name = "no lift has both B2F and 5F", .variant = "lift_floor B2F 5F"}, + .expectation = {.presses = std::nullopt}, + }, }; } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.cpp new file mode 100644 index 0000000000..21045a47b2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.cpp @@ -0,0 +1,135 @@ +/* AutoStory Items Pocket + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "PokemonFRLG_AutoStoryItemsPocket.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The count the story keeps for `item`, or null for an item it doesn't count. +static int Supplies::* count_member(const std::string& item){ + if (item == "potion"){ + return &Supplies::potions; + } + if (item == "antidote"){ + return &Supplies::antidotes; + } + if (item == "parlyz-heal"){ + return &Supplies::parlyz_heals; + } + if (item == "awakening"){ + return &Supplies::awakenings; + } + if (item == "full-heal"){ + return &Supplies::full_heals; + } + return nullptr; +} + +static int* count_slot(Supplies& supplies, const std::string& item){ + int Supplies::* const member = count_member(item); + return member == nullptr ? nullptr : &(supplies.*member); +} + +int item_count(const Supplies& supplies, const std::string& item){ + int Supplies::* const member = count_member(item); + return member == nullptr ? 0 : supplies.*member; +} + +void spend_item(Supplies& supplies, const std::string& item){ + if (int* count = count_slot(supplies, item)){ + (*count)--; + } +} + +// Whether the story keeps a count for `item`. +static bool counted(const std::string& item){ + return count_member(item) != nullptr; +} + +int item_row(const Supplies& supplies, const std::string& item){ + int row = 0; + for (const std::string& slot : supplies.pocket){ + if (counted(slot) && item_count(supplies, slot) <= 0){ + continue; + } + if (slot == item){ + return row; + } + row++; + } + return -1; +} + +int item_shown_row(const Supplies& supplies, int row){ + // The CANCEL, and each row item_row() counts. + int rows = 1; + for (const std::string& slot : supplies.pocket){ + if (!counted(slot) || item_count(supplies, slot) > 0){ + rows++; + } + } + // The row the cursor stops at before the list scrolls. + constexpr int CURSOR_STOP = ITEM_LIST_ROWS / 2; + const int scroll = std::clamp(row - CURSOR_STOP, 0, std::max(rows - ITEM_LIST_ROWS, 0)); + return row - scroll; +} + +std::vector set_from_bag(Supplies& supplies, const std::vector& rows){ + const Supplies before = supplies; + supplies.potions = 0; + supplies.antidotes = 0; + supplies.parlyz_heals = 0; + supplies.awakenings = 0; + supplies.full_heals = 0; + supplies.pocket.clear(); + supplies.other_counts.clear(); + std::vector unread; + for (const BagRow& row : rows){ + supplies.pocket.push_back(row.item); + int* slot = count_slot(supplies, row.item); + if (slot == nullptr){ + if (!row.item.empty() && row.count > 0){ + supplies.other_counts[row.item] = row.count; + } + continue; + } + if (row.count > 0){ + *slot = row.count; + continue; + } + // Taking an unread count for none left the starter unhealed at + // 9 HP until it fainted (console B, 2026-11-02). + *slot = std::max(item_count(before, row.item), 1); + unread.push_back(row.item); + } + return unread; +} + +std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved, const std::vector& rows){ + if (rows.empty()){ + return {}; + } + std::vector unread = set_from_bag(supplies, rows); + saved.potions = supplies.potions; + saved.antidotes = supplies.antidotes; + saved.parlyz_heals = supplies.parlyz_heals; + saved.awakenings = supplies.awakenings; + saved.full_heals = supplies.full_heals; + saved.pocket = supplies.pocket; + saved.other_counts = supplies.other_counts; + return unread; +} + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h index 1ee4aa3e3f..2768e5786c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h @@ -32,10 +32,17 @@ namespace PokemonFRLG{ // How many of `item` (a slug) the bag holds, as far as known. int item_count(const Supplies& supplies, const std::string& item); +// One of `item` used: the count the story keeps for it goes down. +void spend_item(Supplies& supplies, const std::string& item); // The row (from 0) of `item` in the Items pocket, or -1 if none is left. // Items the story doesn't count, such as a MOON STONE, take rows too. int item_row(const Supplies& supplies, const std::string& item); +// Where row `row` (from 0) of the Items pocket shows once DOWN has moved +// the cursor there from the top: the cursor goes down to the fourth row +// shown, then the list scrolls under it until its CANCEL shows (pokefirered +// ListMenuUpdateSelectedRowIndexAndScrollOffset(), 6 rows shown). +int item_shown_row(const Supplies& supplies, int row); // Sets the counts and the pocket's order from the Items pocket as read. // A row whose count couldn't be read still holds at least one: it keeps diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index 401e949a96..d587034b75 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -34,6 +34,7 @@ #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryNewMembers.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -263,6 +264,29 @@ UnitTestResult test_pocket_rows_unread(Logger&){ return true; } +// Rows past the first six show where the list has scrolled to: the +// cursor stops at the fourth row shown, until the CANCEL shows. The +// Tower's bag (console B, 2026-11-12): its X Specials 7th of 8 rows and +// the CANCEL; then the Potions run out and take no row. +UnitTestResult test_item_shown_row(Logger&){ + Supplies supplies; + set_from_bag(supplies, { + {"moon-stone", 2}, {"potion", 1}, {"nugget", 1}, {"repel", 5}, + {"escape-rope", 5}, {"super-repel", 7}, {"x-special", 2}, {"x-speed", 1}, + }); + const std::vector> full = {{2, 2}, {3, 3}, {4, 3}, {6, 3}, {7, 4}, {8, 5}}; + for (const auto& [row, shown] : full){ + if (item_shown_row(supplies, row) != shown){ + return std::format("Row {} of 9: expected shown in row {}, got {}.", row, shown, item_shown_row(supplies, row)); + } + } + spend_item(supplies, "potion"); + if (item_row(supplies, "x-special") != 5 || item_shown_row(supplies, 5) != 3 || item_shown_row(supplies, 7) != 5){ + return "Expected the X Specials in row 6 of 8 shown 4th, the CANCEL last, with no Potions left."; + } + return true; +} + // In a language the reader has no names for, nothing is read, so the // checks fall back to positions instead of failing. UnitTestResult test_unread_language(Logger& logger){ @@ -507,6 +531,59 @@ UnitTestResult test_poison_cured_after_battle(Logger&){ return true; } +// The Tower rival as PokeGuy fought him (10.03): two X Specials on the +// first turns, then attacks. A Potion comes first for HP not green, red +// HP or a wild battle uses none, and the last X Special takes its row. +UnitTestResult test_planned_battle_items(Logger&){ + const PartyStatus GREEN{.hp_seen = true, .hp_yellow = false, .hp_red = false, .status = StatusCondition::NONE}; + const PartyStatus RED{.hp_seen = true, .hp_yellow = false, .hp_red = true, .status = StatusCondition::NONE}; + const PartyStatus YELLOW{.hp_seen = true, .hp_yellow = true, .hp_red = false, .status = StatusCondition::NONE}; + Supplies supplies; + supplies.lead = story_lead_after_brock(); + set_from_bag(supplies, {{"potion", 2}, {"x-special", 2}, {"x-speed", 6}}); + supplies.battle_items = {{.item = "x-special", .quantity = 3}}; + + Supplies wild_supplies = supplies; + BattleDecisions wild(wild_supplies, BattleKind::WILD_FIGHT); + if (wild.turn(GREEN).choice == TurnChoice::BATTLE_ITEM){ + return "Expected no X Special in a wild battle."; + } + + BattleDecisions decisions(supplies, BattleKind::TRAINER); + if (decisions.turn(YELLOW).choice != TurnChoice::POTION){ + return "Expected a Potion before an X Special for yellow HP."; + } + decisions.turn_done(TurnChoice::POTION, TurnResult::DONE); + for (int c = 0; c < 2; c++){ + const TurnAction action = decisions.turn(GREEN); + if (action.choice != TurnChoice::BATTLE_ITEM || action.item != "x-special"){ + return std::format("Expected an X Special at turn {}.", c + 2); + } + decisions.turn_done(action.choice, TurnResult::DONE); + } + if (item_row(supplies, "x-special") != -1 || item_row(supplies, "x-speed") != 1){ + return "Expected the X Special's row gone with the last of the 2, X Speed a row up."; + } + if (decisions.turn(GREEN).choice != TurnChoice::MOVE){ + return "Expected an attack once the bag has no X Special, though the plan asked for 3."; + } + + Supplies red_supplies; + set_from_bag(red_supplies, {{"x-special", 5}}); + red_supplies.battle_items = {{.item = "x-special", .quantity = 1}}; + BattleDecisions red(red_supplies, BattleKind::TRAINER); + if (red.turn(RED).choice != TurnChoice::MOVE){ + return "Expected an attack, not an X Special, at red HP with no Potion."; + } + const TurnAction other = red.turn(GREEN); + red.turn_done(other.choice, TurnResult::NOT_DONE); + if (other.choice != TurnChoice::BATTLE_ITEM || red.turn(GREEN).choice != TurnChoice::MOVE || red_supplies.other_counts.at("x-special") != 5){ + return "Expected no item after the bag's row read as another item."; + } + return true; +} + + const AutoStoryItemsTestCase AUTO_STORY_ITEMS_CASES[] = { { .input = {.name = "Mart cursor stays on the row bought", .body = test_mart_cursor}, @@ -524,6 +601,10 @@ const AutoStoryItemsTestCase AUTO_STORY_ITEMS_CASES[] = { .input = {.name = "an item the story doesn't count keeps its row", .body = test_loaded_bag_other_items}, .expectation = {.description = "preserves row indexing for uncounted items"}, }, + { + .input = {.name = "Items pocket rows past the first page", .body = test_item_shown_row}, + .expectation = {.description = "places rows below the first six where the scrolled list shows them"}, + }, { .input = {.name = "an unread item name keeps its row", .body = test_pocket_rows_unread}, .expectation = {.description = "preserves placeholder row when item name is unread"}, @@ -552,6 +633,10 @@ const AutoStoryItemsTestCase AUTO_STORY_ITEMS_CASES[] = { .input = {.name = "poison after a battle: Antidote, else Full Heal, then a Potion", .body = test_poison_cured_after_battle}, .expectation = {.description = "cures a status left by a battle before the story walks on"}, }, + { + .input = {.name = "battle items: the rival's X Specials first, Potions before them", .body = test_planned_battle_items}, + .expectation = {.description = "uses the plan's X items before attacking"}, + }, }; } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp index ee0e282b4c..b47d3d0624 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp @@ -7,6 +7,7 @@ #include #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h" #include "PokemonFRLG_AutoStoryLegs.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -46,20 +47,25 @@ std::optional> fixed_route( return std::nullopt; } std::vector route; - PlayerState player{start.point, elevation_at(*map, start.point), false}; + // On the water, after a Surf: surfing until a step onto land. + PlayerState player{start.point, elevation_at(*map, start.point), is_water(*map, start.point)}; for (const StoryLeg& leg : legs){ RouteStep step; step.direction = leg.direction; step.tiles = leg.tiles; step.facing_after = leg.direction; step.walk_only = !map->allow_running; + step.surfing = player.surfing; for (int c = 0; c < leg.tiles; c++){ const StepKind kind = classify_step(*map, player, leg.direction); const TilePos next = player.position.next(leg.direction); - if (kind != StepKind::WALK || !in_bounds(*map, next) || warps_on_step(*map, next)){ + // The step off the water is a leg of its own, as the planner + // makes it: the player walks at half the speed from there. + const bool lands = kind == StepKind::STOP_SURFING && leg.tiles == 1; + if ((kind != StepKind::WALK && !lands) || !in_bounds(*map, next) || warps_on_step(*map, next)){ return std::nullopt; } - step.wild |= is_tall_grass(*map, next); + step.wild |= is_tall_grass(*map, next) || player.surfing; player = after_step(*map, player, leg.direction, kind); if (spin_direction(*map, player.position) && !land_on_spinner(*map, player, c + 1 == leg.tiles, step)){ return std::nullopt; @@ -94,6 +100,19 @@ std::optional warp_press(const std::vector& maps, const MapP step.warps = true; step.facing_after = direction; step.end = MapPosition{warp->to ? warp->to->map : map->name, warp_tile}; + // Where the game leaves the player and the way it turns them, as the + // planner takes a warp (arrival_facing()). + const auto destination = std::find_if(maps.begin(), maps.end(), [&](const MapData& data){ + return warp->to && data.name == warp->to->map; + }); + if (destination != maps.end() && destination->points.contains(warp->to->point)){ + TilePos arrival = destination->points.at(warp->to->point); + step.facing_after = arrival_facing(*destination, arrival).value_or(direction); + if (walks_out_on_arrival(*destination, arrival)){ + arrival = arrival.next(Direction::SOUTH); + } + step.end.point = arrival; + } return step; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h index 75f33bd28f..d9e8b4f1dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h @@ -33,7 +33,9 @@ std::optional> fixed_route( // The one-tile walk a press of `direction` from `from` makes, if it takes // a warp: an exit mat stood on, a door ahead going north, or a warp tile -// stepped onto. Its fade and the scene after it must then be confirmed +// stepped onto. It ends where the warp leaves the player, facing the way +// the game turns them (arrival_facing(), as the planner takes a warp). Its +// fade and the scene after it must then be confirmed // (OverworldWalkSteps::wait_out_warp()), not taken as walked. std::optional warp_press(const std::vector& maps, const MapPosition& from, Direction direction); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp index 594ed80b7d..e88eb36921 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp @@ -8,6 +8,7 @@ #include #include #include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" @@ -28,6 +29,8 @@ namespace{ constexpr size_t MAX_QUANTITY = 99; // pokefirered: MAX_MONEY. constexpr size_t MAX_MONEY = 999999; +// The rows the BUY list shows at once (shop.c BuyMenuInitListMenu). +constexpr size_t LIST_ROWS_SHOWN = 6; // Prices from pokefirered src/data/items.json. constexpr MartStockItem POKE_BALL{"poke-ball", 200}; @@ -49,6 +52,13 @@ constexpr MartStockItem ESCAPE_ROPE{"escape-rope", 550}; constexpr MartStockItem REPEL{"repel", 350}; constexpr MartStockItem SUPER_REPEL{"super-repel", 500}; constexpr MartStockItem MAX_REPEL{"max-repel", 700}; +constexpr MartStockItem X_ATTACK{"x-attack", 500}; +constexpr MartStockItem X_DEFEND{"x-defend", 550}; +constexpr MartStockItem X_SPEED{"x-speed", 350}; +constexpr MartStockItem X_SPECIAL{"x-special", 350}; +constexpr MartStockItem X_ACCURACY{"x-accuracy", 950}; +constexpr MartStockItem GUARD_SPEC{"guard-spec", 700}; +constexpr MartStockItem DIRE_HIT{"dire-hit", 650}; // Each Mart's `_Items` list in pokefirered data/maps//scripts.inc. const std::map, std::less<>>& mart_stocks(){ @@ -65,6 +75,8 @@ const std::map, std::less<>>& mart_stock {"FuchsiaCity_Mart", {ULTRA_BALL, GREAT_BALL, SUPER_POTION, REVIVE, FULL_HEAL, MAX_REPEL}}, {"SaffronCity_Mart", {GREAT_BALL, HYPER_POTION, REVIVE, FULL_HEAL, ESCAPE_ROPE, MAX_REPEL}}, {"CinnabarIsland_Mart", {ULTRA_BALL, GREAT_BALL, HYPER_POTION, REVIVE, FULL_HEAL, ESCAPE_ROPE, MAX_REPEL}}, + // The X items clerk (CeladonCity_DepartmentStore_5F_XItems). + {"CeladonCity_DepartmentStore_5F", {X_ATTACK, X_DEFEND, X_SPEED, X_SPECIAL, X_ACCURACY, GUARD_SPEC, DIRE_HIT}}, {"IndigoPlateau_PokemonCenter_1F", { ULTRA_BALL, GREAT_BALL, FULL_RESTORE, MAX_POTION, REVIVE, FULL_HEAL, MAX_REPEL, }}, @@ -81,6 +93,67 @@ std::optional stock_row(const std::vector& stock, std::st return std::nullopt; } +// The item on row `index` of a Mart's list: its stock, then CANCEL. +std::string_view list_item(const std::vector& stock, size_t index){ + return index < stock.size() ? stock[index].item : "cancel"; +} + +// The BUY list's window over its rows, moved one UP or DOWN at a time as +// pokefirered's list_menu.c ListMenuUpdateSelectedRowIndexAndScrollOffset +// moves it (see PokemonFRLG_AutoStoryMart.h). +class ListWindow{ +public: + explicit ListWindow(size_t rows) + : m_rows(rows) + , m_shown(std::min(rows, LIST_ROWS_SHOWN)) + {} + + // The cursor's row in the list. + size_t index() const{ + return m_top + m_row; + } + // The cursor's row in the window. + size_t row() const{ + return m_row; + } + + void move(bool down){ + if (down){ + move_down(); + }else{ + move_up(); + } + } + +private: + void move_down(){ + if (index() + 1 >= m_rows){ + return; + } + if (m_row < m_shown / 2 + m_shown % 2 || m_top == m_rows - m_shown){ + m_row++; + }else{ + m_top++; + } + } + void move_up(){ + if (index() == 0){ + return; + } + if (m_top == 0 || m_row + 1 > m_shown - (m_shown / 2 + m_shown % 2)){ + m_row--; + }else{ + m_top--; + } + } + + size_t m_rows; + size_t m_shown; + // The list's row on the window's top. + size_t m_top = 0; + size_t m_row = 0; +}; + } // namespace @@ -191,6 +264,8 @@ class MartRun{ : m_logger(logger) , m_actions(actions) , m_plan(plan) + , m_stock(mart_stock(plan.map)) + , m_window(m_stock.size() + 1) {} MartResult run(){ @@ -203,7 +278,7 @@ class MartRun{ return leave(MartEnd::NO_MONEY_READ, ""); } m_logger.log(std::format("Mart: ${} ({}), budget ${}.", *money, read ? "read" : "the table's floor", m_plan.budget)); - const std::optional> buys = plan_mart_buys(mart_stock(m_plan.map), m_plan, *money); + const std::optional> buys = plan_mart_buys(m_stock, m_plan, *money); if (!buys){ return leave(MartEnd::FAILED, "an item the Mart doesn't sell"); } @@ -235,17 +310,37 @@ class MartRun{ return this->end(end, std::move(detail)); } + // Moves the cursor to `buy`'s row one press at a time, reading the + // cursor's row after each: a name that isn't the row's stops it, the + // screen saved. A row that can't be read is passed, or bought, by its + // position. + bool reach(const MartBuy& buy){ + for (size_t presses = 0; presses <= m_stock.size(); presses++){ + const size_t index = m_window.index(); + const std::string item = m_actions.read_row(m_window.row()); + if (!item.empty() && item != list_item(m_stock, index)){ + m_result.detail = std::format("row {} is {}, not {}", index + 1, item, list_item(m_stock, index)); + m_actions.dump_screen(std::format("row{}-{}-not-{}", index + 1, item, list_item(m_stock, index))); + return false; + } + if (index == buy.row){ + if (item.empty()){ + m_logger.log(std::format("Mart: couldn't read row {}; buying it by position.", index + 1), COLOR_ORANGE); + } + return true; + } + const bool down = index < buy.row; + m_actions.press_cursor(down); + m_window.move(down); + } + m_result.detail = std::format("the cursor didn't reach row {}", buy.row + 1); + return false; + } + bool buy_one(const MartBuy& buy){ - m_actions.move_cursor(m_cursor, buy.row); - m_cursor = buy.row; - const std::string item = m_actions.read_row(buy.row); - if (!item.empty() && item != buy.item){ - m_result.detail = std::format("row {} is {}, not {}", buy.row + 1, item, buy.item); + if (!reach(buy)){ return false; } - if (item.empty()){ - m_logger.log(std::format("Mart: couldn't read row {}; buying it by position.", buy.row + 1), COLOR_ORANGE); - } switch (m_actions.buy(buy)){ case PurchaseEnd::BOUGHT: m_logger.log(std::format("Mart: bought {} {} for ${}.", buy.quantity, buy.item, buy.cost)); @@ -282,7 +377,10 @@ class MartRun{ Logger& m_logger; MartActions& m_actions; const MartPlan& m_plan; - size_t m_cursor = 0; + const std::vector& m_stock; + // Where the cursor is, from the list's top row as open_buy_list() + // leaves it; a purchase leaves it on the row bought. + ListWindow m_window; MartResult m_result; }; @@ -331,8 +429,6 @@ bool ConsoleMartActions::open_buy_list(){ pbf_press_button(m_context, BUTTON_A, 160ms, 2000ms); pbf_press_button(m_context, BUTTON_A, 160ms, 2000ms); m_context.wait_for_all_requests(); - m_row = 0; - m_lowest_row = 0; return true; } @@ -341,21 +437,13 @@ std::optional ConsoleMartActions::read_money(){ return std::nullopt; } -void ConsoleMartActions::move_cursor(size_t from, size_t to){ - for (size_t c = from; c < to; c++){ - pbf_press_dpad(m_context, DPAD_DOWN, 160ms, 300ms); - } - for (size_t c = to; c < from; c++){ - pbf_press_dpad(m_context, DPAD_UP, 160ms, 300ms); - } +void ConsoleMartActions::press_cursor(bool down){ + pbf_press_dpad(m_context, down ? DPAD_DOWN : DPAD_UP, 160ms, 300ms); m_context.wait_for_all_requests(); - m_row = to; - m_lowest_row = std::max(m_lowest_row, to); } std::string ConsoleMartActions::read_row(size_t row){ - // Rows past the window's last but one may have scrolled the list. - if (m_lowest_row + 1 >= (size_t)ITEM_LIST_ROWS){ + if (row >= (size_t)ITEM_LIST_ROWS){ return ""; } VideoSnapshot screen = m_console.video().snapshot(); @@ -365,6 +453,13 @@ std::string ConsoleMartActions::read_row(size_t row){ return read_item_list_name(m_console.logger(), m_language, screen, (int)row); } +void ConsoleMartActions::dump_screen(std::string_view name){ + VideoSnapshot screen = m_console.video().snapshot(); + if (screen){ + dump_debug_image(m_console, "AutoStory/mart", std::string(name), screen); + } +} + PurchaseEnd ConsoleMartActions::buy(const MartBuy& buy){ // "How many?" drops presses while its text prints. pbf_press_button(m_context, BUTTON_A, 160ms, 2500ms); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h index c49592fbe7..8197bc3b93 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h @@ -17,6 +17,12 @@ * - A on the quantity: "... And you wanted N? That will be $X." YES/NO on * YES; YES: "Here you are! Thank you!", the money taken, back to the * list with the cursor on the row bought. + * - The list shows six rows (shop.c BuyMenuInitListMenu) and scrolls + * under the cursor as list_menu.c ListMenuUpdateSelectedRowIndexAndScrollOffset + * moves it: going down, the cursor stops on the window's fourth row and + * the list scrolls until its end shows; going up, it stops on the third + * until its top shows. A row on the screen is not the list's row once + * it has scrolled. * * The step never opens SELL. Each line buys as many as its quantity, * the budget left and the money left allow, in the order listed; a line @@ -102,8 +108,9 @@ class ConsoleMartActions : public MartActions{ virtual bool open_buy_list() override; virtual std::optional read_money() override; - virtual void move_cursor(size_t from, size_t to) override; + virtual void press_cursor(bool down) override; virtual std::string read_row(size_t row) override; + virtual void dump_screen(std::string_view name) override; virtual PurchaseEnd buy(const MartBuy& buy) override; virtual bool leave() override; @@ -112,10 +119,6 @@ class ConsoleMartActions : public MartActions{ ProControllerContext& m_context; Language m_language; Supplies& m_supplies; - size_t m_row = 0; - // The lowest row the cursor has reached: past the window's rows the - // list scrolls, and a screen row is no longer the list's. - size_t m_lowest_row = 0; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartBuys.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartBuys.h index ee6e9003ff..969e40a6e5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartBuys.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartBuys.h @@ -32,7 +32,7 @@ namespace PokemonFRLG{ // One purchase the step makes. struct MartBuy{ - // The list's row, from 0. + // The list's row, from 0 at the list's top. size_t row = 0; std::string item = {}; size_t quantity = 0; @@ -78,10 +78,14 @@ class MartActions{ virtual bool open_buy_list() = 0; // On the list: the money box; nothing if it can't be read. virtual std::optional read_money() = 0; - // On the list: the cursor from row `from` to row `to`. - virtual void move_cursor(size_t from, size_t to) = 0; - // On the list: row `row`'s item slug; empty if it can't be read. + // On the list: one DOWN (`down`) or UP. + virtual void press_cursor(bool down) = 0; + // On the list: the item slug on row `row` of its window, from the + // window's top (not the list's: the list scrolls); empty if it can't + // be read. virtual std::string read_row(size_t row) = 0; + // On the list: saves the screen to look at, as `name`. + virtual void dump_screen(std::string_view name) = 0; // On the list, the cursor on `buy`'s row: A, its quantity typed as // quantity_presses() says, A, YES. The quantity box is read before // the A, if it can be: another number backs out. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp index 29a1d701ba..e88dae4d58 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp @@ -51,12 +51,15 @@ class FakeMart : public MartActions{ size_t overcharge = 0; std::map bag = {}; size_t list_opened = 0; + size_t dumps = 0; bool in_list = false; std::string error = {}; virtual bool open_buy_list() override{ in_list = true; m_cursor = 0; + m_scroll = 0; + m_row = 0; list_opened++; return true; } @@ -66,22 +69,23 @@ class FakeMart : public MartActions{ } return money_readable ? std::optional(money) : std::nullopt; } - virtual void move_cursor(size_t from, size_t to) override{ - if (from != m_cursor){ - error = std::format("moved from row {}, but the cursor was on row {}", from, m_cursor); - } - // The list is the stock, then CANCEL. - m_cursor = std::min(to, stock.size()); + virtual void press_cursor(bool down) override{ + press(down); } + // `row` is a row of the window, as the console reads the screen. virtual std::string read_row(size_t row) override{ - if (row != m_cursor){ - error = std::format("read row {}, the cursor on row {}", row, m_cursor); + if (row != m_row){ + error = std::format("read window row {}, the cursor on window row {}", row, m_row); } - const auto found = misread.find(row); + const size_t index = m_scroll + row; + const auto found = misread.find(index); if (found != misread.end()){ return found->second; } - return rows_readable && row < stock.size() ? std::string(stock[row].item) : ""; + return rows_readable && index < stock.size() ? std::string(stock[index].item) : ""; + } + virtual void dump_screen(std::string_view) override{ + dumps++; } virtual PurchaseEnd buy(const MartBuy& buy) override{ if (m_cursor >= stock.size()){ @@ -107,6 +111,36 @@ class FakeMart : public MartActions{ } private: + // One UP or DOWN on the list (the stock, then CANCEL), as pokefirered's + // list_menu.c ListMenuUpdateSelectedRowIndexAndScrollOffset moves it, + // six rows shown (shop.c BuyMenuInitListMenu): going down the cursor + // stops on the window's fourth row and the list scrolls under it until + // its end shows; going up it stops on the third until its top shows. + void press(bool down){ + const size_t total = stock.size() + 1; + const size_t shown = std::min(total, 6); + if (down){ + if (m_scroll + m_row + 1 >= total){ + return; + } + if (m_row < shown / 2 + shown % 2 || m_scroll == total - shown){ + m_row++; + }else{ + m_scroll++; + } + }else{ + if (m_scroll + m_row == 0){ + return; + } + if (m_row > shown - (shown / 2 + shown % 2) - 1 || m_scroll == 0){ + m_row--; + }else{ + m_scroll--; + } + } + m_cursor = m_scroll + m_row; + } + // The box after quantity_presses(wanted), from 1, with this most. static size_t typed_quantity(size_t wanted, size_t most){ const QuantityPresses presses = quantity_presses(wanted); @@ -121,6 +155,9 @@ class FakeMart : public MartActions{ } size_t m_cursor = 0; + // The window: the list's row on its top, and the cursor's row in it. + size_t m_scroll = 0; + size_t m_row = 0; }; @@ -176,6 +213,8 @@ struct MartCase{ MartEnd end = MartEnd::DONE; std::map bag = {}; size_t money_after = 0; + // Screens saved for a row read as another item. + size_t dumps = 0; }; std::vector mart_cases_1(){ @@ -257,6 +296,7 @@ std::vector mart_cases_3(){ .end = MartEnd::FAILED, .bag = {{"potion", 1}}, .money_after = 2700, + .dumps = 1, }, { .name = "rows that can't be read are bought by position", @@ -278,9 +318,26 @@ std::vector mart_cases_3(){ }; } +// The X items clerk's list (seven, then CANCEL) scrolls under the cursor: +// after X SPECIAL and X SPEED, X ACCURACY sits on the window's fourth row, +// not its fifth, and the fifth was read as GUARD SPEC. (console B, +// 2026-11-12, 10.01). +std::vector mart_cases_4(){ + const std::vector lines{{"x-special", 21}, {"x-speed", 6}, {"x-accuracy", 5}, {"guard-spec", 2}}; + return { + { + .name = "a list scrolled under the cursor", + .plan = {.map = "CeladonCity_DepartmentStore_5F", .lines = lines, .budget = 15600}, + .money = 19862, + .bag = {{"x-special", 21}, {"x-speed", 6}, {"x-accuracy", 5}, {"guard-spec", 2}}, + .money_after = 4262, + }, + }; +} + std::vector mart_cases(){ std::vector cases; - for (std::vector part : {mart_cases_1(), mart_cases_2(), mart_cases_3()}){ + for (std::vector part : {mart_cases_1(), mart_cases_2(), mart_cases_3(), mart_cases_4()}){ cases.insert(cases.end(), part.begin(), part.end()); } return cases; @@ -300,9 +357,9 @@ UnitTestResult check_mart_case(const MartCase& item){ return std::format("{}: ended {}, expected {} ({}).", item.name, mart_end_name(result.end), mart_end_name(item.end), result.detail); } - if (mart.bag != item.bag || mart.money != item.money_after){ - return std::format("{}: bag {}, ${}; expected {}, ${}.", item.name, - bag_string(mart.bag), mart.money, bag_string(item.bag), item.money_after); + if (mart.bag != item.bag || mart.money != item.money_after || mart.dumps != item.dumps){ + return std::format("{}: bag {}, ${}, {} screens saved; expected {}, ${}, {}.", item.name, + bag_string(mart.bag), mart.money, mart.dumps, bag_string(item.bag), item.money_after, item.dumps); } if (mart.in_list){ return item.name + ": left in the Mart's list."; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp index c769fe016c..40ec1ce9fe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -116,6 +116,10 @@ struct Attack{ std::string_view move; }; constexpr Attack ATTACKS[] = { + // Blastoise's strongest STAB move: a tie with Bite against Pidgeotto + // went to Bite, and one with Bubble against Growlithe to Bubble, and + // the Tower rival won (console B, 2026-11-12). + {.line = "squirtle", .move = "water-pulse"}, {.line = "squirtle", .move = "water-gun"}, {.line = "squirtle", .move = "bite"}, {.line = "squirtle", .move = "bubble"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden.h index 4cd5d9abe1..d708eb4d51 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden.h @@ -43,7 +43,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "01.06 face south -> PalletTown_ProfessorOaksLab (7, 7) [walk only]", "02.01 below_mart_door from PalletTown_ProfessorOaksLab (7, 8) facing south to ViridianCity (36, 20) facing north", "02.01 walk south 4 (to wall) -> PalletTown_ProfessorOaksLab (7, 12) [walk only]", - "02.01 walk west 1 -> PalletTown_ProfessorOaksLab (6, 12) [walk only]", + "02.01 walk west 1 -> PalletTown_ProfessorOaksLab (6, 12) [walk only] [tapped]", "02.01 walk south 1 (warp) -> PalletTown (16, 14) [walk only]", "02.01 walk west 4 -> PalletTown (12, 14)", "02.01 walk north 22 -> Route1 (12, 32) [wild] [connection 15]", @@ -320,7 +320,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "05.02 face west -> CeruleanCity_Gym (9, 6) [walk only]", "05.02 cerulean_nurse from CeruleanCity_Gym (9, 13) facing east to CeruleanCity_PokemonCenter_1F (7, 4) facing north", "05.02 walk south 5 (to wall) -> CeruleanCity_Gym (9, 18) [walk only]", - "05.02 walk west 1 -> CeruleanCity_Gym (8, 18) [walk only]", + "05.02 walk west 1 -> CeruleanCity_Gym (8, 18) [walk only] [tapped]", "05.02 walk south 1 (warp) -> CeruleanCity (31, 22) [walk only]", "05.02 walk west 9 -> CeruleanCity (22, 22)", "05.02 walk north 3 (warp) -> CeruleanCity_PokemonCenter_1F (7, 8)", @@ -500,7 +500,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "05.10 walk south 57 -> UndergroundPath_NorthSouthTunnel (4, 60)", "05.10 walk west 2 (warp) -> UndergroundPath_SouthEntrance (7, 4)", "05.10 walk south 4 (to wall) -> UndergroundPath_SouthEntrance (7, 8)", - "05.10 walk west 1 -> UndergroundPath_SouthEntrance (6, 8)", + "05.10 walk west 1 -> UndergroundPath_SouthEntrance (6, 8) [tapped]", "05.10 walk south 1 (warp) -> Route6 (19, 14)", "05.10 walk west 4 -> Route6 (15, 14)", "05.10 vermilion_nurse from Route6 (10, 33) facing east to VermilionCity_PokemonCenter_1F (7, 4) facing north", @@ -572,10 +572,10 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "06.02 walk south 4 (to wall) -> VermilionCity (19, 28)", "06.02 walk west 5 -> VermilionCity (14, 28)", "06.02 walk north 3 (warp) -> VermilionCity_Gym (5, 19)", - "06.02 below_gym_tree from VermilionCity_Gym (5, 8) facing east to VermilionCity (19, 25) facing north", + "06.02 below_gym_tree from VermilionCity_Gym (5, 8) facing north to VermilionCity (19, 25) facing north", "06.02 walk east 1 -> VermilionCity_Gym (6, 8) [walk only]", "06.02 walk south 11 (to wall) -> VermilionCity_Gym (6, 19) [walk only]", - "06.02 walk west 1 -> VermilionCity_Gym (5, 19) [walk only]", + "06.02 walk west 1 -> VermilionCity_Gym (5, 19) [walk only] [tapped]", "06.02 walk south 1 (warp) -> VermilionCity (14, 26) [walk only]", "06.02 walk east 5 (to wall) -> VermilionCity (19, 26)", "06.02 walk north 1 -> VermilionCity (19, 25)", @@ -621,7 +621,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "06.04 below_gym_tree from VermilionCity_Gym (5, 3) facing north to VermilionCity (19, 25) facing north", "06.04 walk east 1 -> VermilionCity_Gym (6, 3) [walk only]", "06.04 walk south 16 (to wall) -> VermilionCity_Gym (6, 19) [walk only]", - "06.04 walk west 1 -> VermilionCity_Gym (5, 19) [walk only]", + "06.04 walk west 1 -> VermilionCity_Gym (5, 19) [walk only] [tapped]", "06.04 walk south 1 (warp) -> VermilionCity (14, 26) [walk only]", "06.04 walk east 5 (to wall) -> VermilionCity (19, 26)", "06.04 walk north 1 -> VermilionCity (19, 25)", @@ -654,7 +654,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "07.01 west_of_oaks_aide from VermilionCity_PokemonFanClub (4, 4) facing east to VermilionCity (22, 10)", "07.01 walk west 3 (to wall) -> VermilionCity_PokemonFanClub (1, 4) [walk only]", "07.01 walk south 6 (to wall) -> VermilionCity_PokemonFanClub (1, 10) [walk only]", - "07.01 walk east 4 -> VermilionCity_PokemonFanClub (5, 10) [walk only]", + "07.01 walk east 4 -> VermilionCity_PokemonFanClub (5, 10) [walk only] [tapped]", "07.01 walk south 1 (warp) -> VermilionCity (12, 18) [walk only]", "07.01 walk east 14 -> VermilionCity (26, 18)", "07.01 walk north 6 -> VermilionCity (26, 12)", @@ -675,7 +675,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "07.01 walk north 57 -> UndergroundPath_NorthSouthTunnel (3, 3)", "07.01 walk east 2 (warp) -> UndergroundPath_NorthEntrance (7, 4)", "07.01 walk south 4 (to wall) -> UndergroundPath_NorthEntrance (7, 8)", - "07.01 walk west 1 -> UndergroundPath_NorthEntrance (6, 8)", + "07.01 walk west 1 -> UndergroundPath_NorthEntrance (6, 8) [tapped]", "07.01 walk south 1 (warp) -> Route5 (31, 32)", "07.01 walk west 2 -> Route5 (29, 32)", "07.01 walk north 39 (to wall) -> CeruleanCity (29, 33) [connection 33]", @@ -690,7 +690,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "07.01 face east -> CeruleanCity_BikeShop (7, 3) [walk only]", "07.01 mart_clerk from CeruleanCity_BikeShop (7, 3) facing east to CeruleanCity_Mart (4, 3) facing west", "07.01 walk south 5 (to wall) -> CeruleanCity_BikeShop (7, 8) [walk only]", - "07.01 walk west 2 -> CeruleanCity_BikeShop (5, 8) [walk only]", + "07.01 walk west 2 -> CeruleanCity_BikeShop (5, 8) [walk only] [tapped]", "07.01 walk south 1 (warp) -> CeruleanCity (13, 29) [walk only]", "07.01 walk east 16 -> CeruleanCity (29, 29)", "07.01 walk north 1 (warp) -> CeruleanCity_Mart (4, 7)", @@ -722,7 +722,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "07.02 west_of_jeremy_sight from Route9 (11, 12) facing south to Route9 (19, 13) facing east", "07.02 walk south 1 -> Route9 (11, 13)", "07.02 walk east 8 -> Route9 (19, 13)", - "07.02 below_conner_line from Route9 (20, 13) facing south to Route9 (52, 8) facing north", + "07.02 below_conner_line from Route9 (20, 13) facing east to Route9 (52, 8) facing north", "07.02 walk east 32 (to wall) -> Route9 (52, 13)", "07.02 walk north 5 -> Route9 (52, 8)", "07.02 route10_ledge_end from Route9 (70, 8) facing east to Route10 (17, 11) facing east", @@ -738,7 +738,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "08.01 face north -> Route10 (10, 21)", "08.01 rock_tunnel_1f from Route10 (8, 20) facing west to RockTunnel_1F (17, 2) facing north", "08.01 walk north 1 (warp) -> RockTunnel_1F (17, 2)", - "08.01 b1f_south_ladder from RockTunnel_1F (24, 10) facing east to RockTunnel_B1F (38, 28) facing north", + "08.01 b1f_south_ladder from RockTunnel_1F (24, 10) facing south to RockTunnel_B1F (38, 28) facing north", "08.01 walk south 3 (to wall) -> RockTunnel_1F (24, 13) [wild]", "08.01 walk east 21 (to wall) -> RockTunnel_1F (45, 13) [wild]", "08.01 walk north 11 (warp) -> RockTunnel_B1F (38, 28) [wild]", @@ -787,10 +787,10 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "08.03 walk north 2 -> UndergroundPath_EastEntrance (8, 4)", "08.03 walk west 2 (warp) -> UndergroundPath_EastWestTunnel (76, 3)", "08.03 walk west 73 (to wall) -> UndergroundPath_EastWestTunnel (3, 3)", - "08.03 walk south 1 -> UndergroundPath_EastWestTunnel (3, 4)", + "08.03 walk south 1 -> UndergroundPath_EastWestTunnel (3, 4) [tapped]", "08.03 walk west 1 (warp) -> UndergroundPath_WestEntrance (7, 4)", "08.03 walk south 4 (to wall) -> UndergroundPath_WestEntrance (7, 8)", - "08.03 walk west 1 -> UndergroundPath_WestEntrance (6, 8)", + "08.03 walk west 1 -> UndergroundPath_WestEntrance (6, 8) [tapped]", "08.03 walk south 1 (warp) -> Route7 (7, 15)", "08.03 pidgey_grass from Route7 (7, 15) facing south to Route7 (14, 6) facing east", "08.03 walk east 3 -> Route7 (10, 15)", @@ -822,7 +822,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "09.01 walk west 5 -> RocketHideout_B2F (23, 9)", "09.01 walk north 5 (to wall) -> RocketHideout_B2F (23, 4)", "09.01 face west -> RocketHideout_B2F (23, 4)", - "09.01 b3f_off_stairs from RocketHideout_B2F (21, 2) facing north to RocketHideout_B3F (18, 2) facing east", + "09.01 b3f_off_stairs from RocketHideout_B2F (21, 2) facing north to RocketHideout_B3F (18, 2) facing west", "09.01 walk east 1 (warp) -> RocketHideout_B3F (18, 2)", "09.01 hideout_b4f_west from RocketHideout_B3F (15, 19) facing north to RocketHideout_B4F (5, 3) facing west", "09.01 walk north 1 (to wall) -> RocketHideout_B3F (15, 18)", @@ -839,7 +839,7 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "09.01 beside_b3f_rare_candy from RocketHideout_B3F (10, 13) facing north to RocketHideout_B3F (12, 13) facing north", "09.01 walk east 2 (to wall) -> RocketHideout_B3F (12, 13)", "09.01 face north -> RocketHideout_B3F (12, 13)", - "09.02 b2f_from_b3f from RocketHideout_B3F (12, 2) facing north to RocketHideout_B2F (21, 2) facing east", + "09.02 b2f_from_b3f from RocketHideout_B3F (12, 2) facing north to RocketHideout_B2F (21, 2) facing west", "09.02 walk east 7 (warp) -> RocketHideout_B2F (21, 2)", "09.02 above_moon_stone from RocketHideout_B2F (2, 4) facing east to RocketHideout_B2F (2, 4) facing south", "09.02 face south -> RocketHideout_B2F (2, 4)", @@ -849,6 +849,38 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN[] = { "09.02 face north -> RocketHideout_B4F (19, 5)", "09.02 face_silph_scope from RocketHideout_B4F (19, 5) facing south to RocketHideout_B4F (19, 5) facing east", "09.02 face east -> RocketHideout_B4F (19, 5)", + "09.03 above_tea_woman from CeladonCity (34, 22) facing south to CeladonCity_Condominiums_1F (2, 8) facing south", + "09.03 walk east 7 -> CeladonCity (41, 22)", + "09.03 walk north 10 (to wall) -> CeladonCity (41, 12)", + "09.03 walk west 11 -> CeladonCity (30, 12)", + "09.03 walk north 1 (warp) -> CeladonCity_Condominiums_1F (12, 18)", + "09.03 walk north 4 -> CeladonCity_Condominiums_1F (12, 14) [walk only]", + "09.03 walk west 12 (to wall) -> CeladonCity_Condominiums_1F (0, 14) [walk only]", + "09.03 walk north 6 (to wall) -> CeladonCity_Condominiums_1F (0, 8) [walk only]", + "09.03 walk east 2 -> CeladonCity_Condominiums_1F (2, 8) [walk only]", + "09.03 face south -> CeladonCity_Condominiums_1F (2, 8) [walk only]", + "09.03 facing_eevee_ball from CeladonCity_Condominiums_1F (2, 8) facing south to CeladonCity_Condominiums_RoofRoom (7, 4) facing north", + "09.03 walk west 2 (to wall) -> CeladonCity_Condominiums_1F (0, 8) [walk only]", + "09.03 walk south 6 (to wall) -> CeladonCity_Condominiums_1F (0, 14) [walk only]", + "09.03 walk east 12 -> CeladonCity_Condominiums_1F (12, 14) [walk only]", + "09.03 walk south 5 (warp) -> CeladonCity (30, 12) [walk only]", + "09.03 walk east 21 -> CeladonCity (51, 12)", + "09.03 walk north 6 (to wall) -> CeladonCity (51, 6)", + "09.03 walk west 13 -> CeladonCity (38, 6)", + "09.03 walk north 4 (to wall) -> CeladonCity (38, 2)", + "09.03 walk west 8 -> CeladonCity (30, 2)", + "09.03 walk south 3 (warp) -> CeladonCity_Condominiums_1F (2, 2)", + "09.03 walk east 3 (warp) -> CeladonCity_Condominiums_2F (4, 2) [walk only]", + "09.03 walk west 3 (warp) -> CeladonCity_Condominiums_3F (2, 2) [walk only]", + "09.03 walk east 3 (warp) -> CeladonCity_Condominiums_Roof (4, 2) [walk only]", + "09.03 walk south 3 (to wall) -> CeladonCity_Condominiums_Roof (4, 5) [walk only]", + "09.03 walk east 2 (to wall) -> CeladonCity_Condominiums_Roof (6, 5) [walk only]", + "09.03 walk south 9 (to wall) -> CeladonCity_Condominiums_Roof (6, 14) [walk only]", + "09.03 walk west 4 -> CeladonCity_Condominiums_Roof (2, 14) [walk only]", + "09.03 walk north 2 (warp) -> CeladonCity_Condominiums_RoofRoom (4, 7) [walk only]", + "09.03 walk north 2 (to wall) -> CeladonCity_Condominiums_RoofRoom (4, 5) [walk only]", + "09.03 walk east 3 -> CeladonCity_Condominiums_RoofRoom (7, 5) [walk only]", + "09.03 walk north 1 -> CeladonCity_Condominiums_RoofRoom (7, 4) [walk only]", }; } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden10.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden10.h new file mode 100644 index 0000000000..f1a4689f48 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden10.h @@ -0,0 +1,146 @@ +/* FRLG AutoStory Plan Golden, Segment 10 + * + * From: https://github.com/PokemonAutomation/ + * + * The golden's lines from segment 10 on (PokemonFRLG_AutoStoryPlanGolden.h + * holds the ones before; one file would pass 1000 lines). The test reads + * FRLG_PLAN_GOLDEN, then these. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryPlanGolden10_H +#define PokemonAutomation_PokemonFRLG_AutoStoryPlanGolden10_H + +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +// The stored plan lines from segment 10 on, after FRLG_PLAN_GOLDEN's. +inline constexpr std::string_view FRLG_PLAN_GOLDEN_10[] = { + "10.01 below_store_lift from CeladonCity_Condominiums_RoofRoom (7, 4) facing north to CeladonCity_DepartmentStore_1F (6, 2) facing north", + "10.01 walk south 3 (to wall) -> CeladonCity_Condominiums_RoofRoom (7, 7) [walk only]", + "10.01 walk west 3 -> CeladonCity_Condominiums_RoofRoom (4, 7) [walk only] [tapped]", + "10.01 walk south 1 (warp) -> CeladonCity_Condominiums_Roof (2, 13) [walk only]", + "10.01 walk east 4 (to wall) -> CeladonCity_Condominiums_Roof (6, 13) [walk only]", + "10.01 walk north 9 (to wall) -> CeladonCity_Condominiums_Roof (6, 4) [walk only]", + "10.01 walk west 5 (to wall) -> CeladonCity_Condominiums_Roof (1, 4) [walk only]", + "10.01 walk north 2 (to wall) -> CeladonCity_Condominiums_Roof (1, 2) [walk only]", + "10.01 walk east 4 (warp) -> CeladonCity_Condominiums_3F (4, 2) [walk only]", + "10.01 walk west 3 (warp) -> CeladonCity_Condominiums_2F (2, 2) [walk only]", + "10.01 walk east 3 (warp) -> CeladonCity_Condominiums_1F (4, 2) [walk only]", + "10.01 walk west 2 -> CeladonCity_Condominiums_1F (2, 2) [walk only]", + "10.01 walk north 1 (warp) -> CeladonCity (30, 4) [walk only]", + "10.01 walk north 2 (to wall) -> CeladonCity (30, 2)", + "10.01 walk east 9 -> CeladonCity (39, 2)", + "10.01 walk south 5 (to wall) -> CeladonCity (39, 7)", + "10.01 walk east 12 (to wall) -> CeladonCity (51, 7)", + "10.01 walk south 6 -> CeladonCity (51, 13)", + "10.01 walk west 28 -> CeladonCity (23, 13)", + "10.01 walk south 3 (to wall) -> CeladonCity (23, 16)", + "10.01 walk west 8 -> CeladonCity (15, 16)", + "10.01 walk north 2 (warp) -> CeladonCity_DepartmentStore_1F (10, 14)", + "10.01 walk north 9 (to wall) -> CeladonCity_DepartmentStore_1F (10, 5) [walk only]", + "10.01 walk west 4 -> CeladonCity_DepartmentStore_1F (6, 5) [walk only]", + "10.01 walk north 3 -> CeladonCity_DepartmentStore_1F (6, 2) [walk only]", + "10.01 x_items_clerk from CeladonCity_DepartmentStore_5F (6, 2) facing south to CeladonCity_DepartmentStore_5F (3, 7) facing west", + "10.01 walk south 4 -> CeladonCity_DepartmentStore_5F (6, 6) [walk only]", + "10.01 walk west 3 (to wall) -> CeladonCity_DepartmentStore_5F (3, 6) [walk only]", + "10.01 walk south 1 -> CeladonCity_DepartmentStore_5F (3, 7) [walk only]", + "10.01 face west -> CeladonCity_DepartmentStore_5F (3, 7) [walk only]", + "10.01 below_5f_lift from CeladonCity_DepartmentStore_5F (3, 7) facing west to CeladonCity_DepartmentStore_5F (6, 2) facing north", + "10.01 walk north 5 (to wall) -> CeladonCity_DepartmentStore_5F (3, 2) [walk only]", + "10.01 walk east 3 -> CeladonCity_DepartmentStore_5F (6, 2) [walk only]", + "10.01 face north -> CeladonCity_DepartmentStore_5F (6, 2) [walk only]", + "10.01 out_of_store from CeladonCity_DepartmentStore_1F (6, 2) facing south to CeladonCity (11, 15) facing south", + "10.01 walk south 5 (to wall) -> CeladonCity_DepartmentStore_1F (6, 7) [walk only]", + "10.01 walk west 4 -> CeladonCity_DepartmentStore_1F (2, 7) [walk only]", + "10.01 walk south 8 (warp) -> CeladonCity (11, 15) [walk only]", + "10.01 route16_below_cut_tree from CeladonCity (11, 15) facing south to Route16 (41, 12) facing north", + "10.01 walk west 7 (to wall) -> CeladonCity (4, 15)", + "10.01 walk south 7 -> CeladonCity (4, 22)", + "10.01 walk west 11 -> Route16 (41, 12) [connection 5]", + "10.01 face north -> Route16 (41, 12)", + "10.01 east_of_north_gate from Route16 (41, 11) facing north to Route16 (28, 6) facing west", + "10.01 walk north 3 -> Route16 (41, 8)", + "10.01 walk west 13 -> Route16 (28, 8)", + "10.01 walk north 2 -> Route16 (28, 6)", + "10.01 face west -> Route16 (28, 6)", + "10.01 below_fly_woman from Route16 (28, 6) facing west to Route16_House (4, 4) facing north", + "10.01 walk west 2 (warp) -> Route16_NorthEntrance_1F (11, 3)", + "10.01 walk west 11 (warp) -> Route16 (20, 6)", + "10.01 walk west 10 -> Route16 (10, 6)", + "10.01 walk north 1 (warp) -> Route16_House (4, 7)", + "10.01 walk north 3 -> Route16_House (4, 4) [walk only]", + "10.01 outside_fly_house from Route16_House (4, 4) facing north to Route16 (10, 6) facing south", + "10.01 walk south 4 (warp) -> Route16 (10, 6) [walk only]", + "10.01 lavender_nurse from LavenderTown (6, 6) facing south to LavenderTown_PokemonCenter_1F (7, 4) facing north", + "10.01 walk north 1 (warp) -> LavenderTown_PokemonCenter_1F (7, 8)", + "10.01 walk north 4 (to wall) -> LavenderTown_PokemonCenter_1F (7, 4) [walk only]", + "10.02 tower_2f_east_of_rival from LavenderTown_PokemonCenter_1F (7, 4) facing north to PokemonTower_2F (17, 6) facing west", + "10.02 walk south 5 (warp) -> LavenderTown (6, 6) [walk only]", + "10.02 walk east 6 (to wall) -> LavenderTown (12, 6)", + "10.02 walk south 2 (to wall) -> LavenderTown (12, 8)", + "10.02 walk east 6 -> LavenderTown (18, 8)", + "10.02 walk north 2 (warp) -> PokemonTower_1F (11, 18)", + "10.02 walk north 9 -> PokemonTower_1F (11, 9) [walk only]", + "10.02 walk east 8 (warp) -> PokemonTower_2F (18, 10) [walk only]", + "10.02 walk north 4 -> PokemonTower_2F (18, 6) [walk only]", + "10.02 walk west 1 -> PokemonTower_2F (17, 6) [walk only]", + "10.04 tower_3f_column_7 from PokemonTower_2F (16, 6) facing north to PokemonTower_3F (7, 7) facing east", + "10.04 walk west 12 -> PokemonTower_2F (4, 6) [walk only] [tapped]", + "10.04 walk south 4 -> PokemonTower_2F (4, 10) [walk only] [tapped]", + "10.04 walk west 1 (warp) -> PokemonTower_3F (4, 10) [walk only]", + "10.04 walk east 1 (to wall) -> PokemonTower_3F (5, 10) [walk only] [wild]", + "10.04 walk south 4 (to wall) -> PokemonTower_3F (5, 14) [walk only] [wild]", + "10.04 walk east 2 -> PokemonTower_3F (7, 14) [walk only] [wild]", + "10.04 walk north 7 (to wall) -> PokemonTower_3F (7, 7) [walk only] [wild]", + "10.04 face east -> PokemonTower_3F (7, 7) [walk only]", + "10.04 tower_4f_stairs from PokemonTower_3F (17, 10) facing south to PokemonTower_4F (18, 10) facing south", + "10.04 walk east 2 (warp) -> PokemonTower_4F (18, 10) [walk only]", + "10.04 face south -> PokemonTower_4F (18, 10) [walk only]", + "10.04 tower_4f_top from PokemonTower_4F (16, 7) facing north to PokemonTower_4F (11, 3) facing west", + "10.04 walk west 1 (to wall) -> PokemonTower_4F (15, 7) [walk only] [wild]", + "10.04 walk north 2 (to wall) -> PokemonTower_4F (15, 5) [walk only] [wild]", + "10.04 walk west 1 (to wall) -> PokemonTower_4F (14, 5) [walk only] [wild]", + "10.04 walk south 1 (to wall) -> PokemonTower_4F (14, 6) [walk only] [wild]", + "10.04 walk west 3 (to wall) -> PokemonTower_4F (11, 6) [walk only] [wild]", + "10.04 walk north 3 -> PokemonTower_4F (11, 3) [walk only] [wild]", + "10.04 face west -> PokemonTower_4F (11, 3) [walk only]", + "10.04 tower_5f_west_of_ruth from PokemonTower_4F (11, 3) facing west to PokemonTower_5F (10, 6) facing east", + "10.04 walk north 1 (to wall) -> PokemonTower_4F (11, 2) [walk only] [wild]", + "10.04 walk west 2 (to wall) -> PokemonTower_4F (9, 2) [walk only] [wild]", + "10.04 walk south 7 (to wall) -> PokemonTower_4F (9, 9) [walk only] [wild]", + "10.04 walk west 5 (to wall) -> PokemonTower_4F (4, 9) [walk only] [wild]", + "10.04 walk south 1 -> PokemonTower_4F (4, 10) [walk only] [tapped]", + "10.04 walk west 1 (warp) -> PokemonTower_5F (4, 10) [walk only]", + "10.04 walk north 5 (to wall) -> PokemonTower_5F (4, 5) [walk only] [wild]", + "10.04 walk east 1 (to wall) -> PokemonTower_5F (5, 5) [walk only] [wild]", + "10.04 walk south 2 (to wall) -> PokemonTower_5F (5, 7) [walk only] [wild]", + "10.04 walk east 2 (to wall) -> PokemonTower_5F (7, 7) [walk only] [wild]", + "10.04 walk north 1 (to wall) -> PokemonTower_5F (7, 6) [walk only] [wild]", + "10.04 walk east 3 -> PokemonTower_5F (10, 6) [walk only] [wild]", + "10.05 tower_6f_stairs from PokemonTower_5F (18, 7) facing south to PokemonTower_6F (18, 10) facing north", + "10.05 walk south 3 -> PokemonTower_5F (18, 10) [walk only] [tapped] [wild]", + "10.05 walk east 1 (warp) -> PokemonTower_6F (18, 10) [walk only]", + "10.05 face north -> PokemonTower_6F (18, 10) [walk only]", + "10.05 tower_6f_east_of_emilia_line from PokemonTower_6F (16, 6) facing north to PokemonTower_6F (10, 8) facing west", + "10.05 walk north 2 (to wall) -> PokemonTower_6F (16, 4) [walk only] [wild]", + "10.05 walk west 6 -> PokemonTower_6F (10, 4) [walk only] [wild]", + "10.05 walk south 4 -> PokemonTower_6F (10, 8) [walk only] [wild]", + "10.05 face west -> PokemonTower_6F (10, 8) [walk only]", + "10.06 tower_7f_below_grunt1_line from PokemonTower_6F (11, 15) facing south to PokemonTower_7F (11, 11) facing north", + "10.06 walk south 1 -> PokemonTower_6F (11, 16) [walk only] [tapped]", + "10.06 walk west 1 (warp) -> PokemonTower_7F (11, 16) [walk only]", + "10.06 walk north 5 -> PokemonTower_7F (11, 11) [walk only] [wild]", + "10.06 below_fuji from PokemonTower_7F (11, 6) facing north to PokemonTower_7F (11, 5) facing north", + "10.06 walk north 1 -> PokemonTower_7F (11, 5) [walk only] [wild]", + "10.06 facing_fuji from LavenderTown_VolunteerPokemonHouse (3, 4) facing west to LavenderTown_VolunteerPokemonHouse (3, 4) facing north", + "10.06 face north -> LavenderTown_VolunteerPokemonHouse (3, 4) [walk only]", +}; + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp index 17de77c1e1..c426201c9b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp @@ -25,6 +25,18 @@ std::string join_sids(const std::vector& sids){ return text.empty() ? "-" : text; } +// The gifts AutoStory takes Gift RNG for, as the log names them. +std::string_view gift_name(PokemonFRLG_RngTarget gift){ + switch (gift){ + case PokemonFRLG_RngTarget::magikarp: + return "Magikarp"; + case PokemonFRLG_RngTarget::eevee: + return "Eevee"; + default: + return "gift"; + } +} + } // namespace std::string starter_rng_loop_message(const StarterRngLoopResult& result){ @@ -64,18 +76,23 @@ std::string starter_rng_loop_message(const StarterRngLoopResult& result){ } -std::string gift_rng_loop_message(const StarterRngLoopResult& result){ - const std::string save = "The save is still beside the salesman, facing him: start AutoStory at 04.03 with Run Gift " - "RNG in AutoStory on to try again, or run Gift RNG (Magikarp) from it by hand with an attempt from the log, then " - "start AutoStory at 04.03 with that option off."; +std::string gift_rng_loop_message(const StarterRngLoopResult& result, PokemonFRLG_RngTarget gift, std::string_view row){ + const std::string_view name = gift_name(gift); + const std::string save = std::format( + "The save is still where Gift RNG starts for the {0}: start AutoStory at {1} with Run Gift RNG in AutoStory on " + "to try again, or run Gift RNG ({0}) from it by hand with an attempt from the log, then start AutoStory at {1} " + "with that option off.", name, row + ); switch (result.end){ case StarterRngLoopEnd::SHINY: - return "Gift RNG: shiny Magikarp, on the planned target. 04.03 saves it."; + return std::format("Gift RNG: shiny {}, on the planned target. {} saves it.", name, row); case StarterRngLoopEnd::SHINY_OFF_TARGET: - return "Gift RNG: shiny Magikarp, but not the planned target. 04.03 saves it."; + return std::format("Gift RNG: shiny {}, but not the planned target. {} saves it.", name, row); case StarterRngLoopEnd::TARGET: - return "Gift RNG hit the target (shiny not required). Nothing was saved after it: start AutoStory at 04.03 " - "to save the Magikarp where it stands."; + return std::format( + "Gift RNG hit the target (shiny not required). Nothing was saved after it: start AutoStory at {} " + "to save the {} where it stands.", row, name + ); case StarterRngLoopEnd::OUT_OF_ATTEMPTS: return std::format( "Gift RNG: every planned attempt hit its target and none was shiny, so the RNG plan's SID doesn't fit. " @@ -147,6 +164,8 @@ StoryRunPlan rows_after_starter_rng( } row.steps.erase(row.steps.begin(), taken + 1); row.title = "after Starter RNG in AutoStory: the rival's battle"; + // It starts where Starter RNG left the game, not from a save. + row.live_start = true; StoryRunPlan plan; plan.rows.emplace_back(std::move(row)); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h index 46a8cb06e2..2a59ca7449 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h @@ -15,8 +15,10 @@ #include #include +#include #include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_BlindNavigation.h" #include "VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngPlan.h" #include "VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngLoop.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -35,8 +37,9 @@ struct StarterRngPlanned{ // What the run says when the loop ends with `result`. std::string starter_rng_loop_message(const StarterRngLoopResult& result); -// As starter_rng_loop_message(), for Gift RNG's Magikarp. -std::string gift_rng_loop_message(const StarterRngLoopResult& result); +// As starter_rng_loop_message(), for Gift RNG's `gift`, which the +// live-start row `row` (04.03, 09.04) saves after a shiny. +std::string gift_rng_loop_message(const StarterRngLoopResult& result, PokemonFRLG_RngTarget gift, std::string_view row); // `steps`, with the calibration of each reset also kept in the RNG plan's @@ -58,7 +61,8 @@ class CalibrationSavingSteps : public StarterRngLoopSteps{ // The rows a run takes after a shiny from the loop, which leaves the player // under Squirtle's ball with the rival's ball taken: the row after -// `ball_row` (01.06) from its step after "rival_takes_bulbasaur", then +// `ball_row` (01.06) from its step after "rival_takes_bulbasaur", as a +// live-start row (no start check: no save was loaded), then // the rows after it to `last` as plan_story_run() takes them with // `handoffs`, with the handoff they stop at. Throws InternalProgramError // for a table without that row or step. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp index 03f6121ffc..59d80c9975 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp @@ -154,17 +154,33 @@ UnitTestResult test_rows_after_shiny(){ } -// What the run says when Gift RNG's loop ends: a shiny goes on to 04.03; -// otherwise the save beside the salesman is where to go on from. +// What the run says when Gift RNG's loop ends: a shiny goes on to the row +// that saves it, named with the gift (console B, 2026-11-11: a shiny +// Eevee was logged as a Magikarp that 04.03 saves); otherwise the save +// where Gift RNG starts is where to go on from. UnitTestResult test_gift_messages(){ struct Case{ StarterRngLoopResult result; std::string expected; + PokemonFRLG_RngTarget gift = PokemonFRLG_RngTarget::magikarp; + std::string row = "04.03"; }; - const std::string save = "The save is still beside the salesman, facing him: start AutoStory at 04.03 with Run Gift " - "RNG in AutoStory on to try again, or run Gift RNG (Magikarp) from it by hand with an attempt from the log, then " - "start AutoStory at 04.03 with that option off."; + const std::string save = "The save is still where Gift RNG starts for the Magikarp: start AutoStory at 04.03 with Run " + "Gift RNG in AutoStory on to try again, or run Gift RNG (Magikarp) from it by hand with an attempt from the log, " + "then start AutoStory at 04.03 with that option off."; const std::vector cases = { + { + .result = {.end = StarterRngLoopEnd::SHINY, .attempts_run = 7, .remaining_sids = {300}, .sid = uint16_t(300)}, + .expected = "Gift RNG: shiny Eevee, on the planned target. 09.04 saves it.", + .gift = PokemonFRLG_RngTarget::eevee, .row = "09.04", + }, + { + .result = {.end = StarterRngLoopEnd::OUT_OF_TIME, .attempts_run = 4, .remaining_sids = {300}, .sid = std::nullopt}, + .expected = "Gift RNG: out of time after 4 attempts. The save is still where Gift RNG starts for the Eevee: start " + "AutoStory at 09.04 with Run Gift RNG in AutoStory on to try again, or run Gift RNG (Eevee) from it by hand " + "with an attempt from the log, then start AutoStory at 09.04 with that option off.", + .gift = PokemonFRLG_RngTarget::eevee, .row = "09.04", + }, { .result = {.end = StarterRngLoopEnd::SHINY, .attempts_run = 1, .remaining_sids = {300}, .sid = uint16_t(300)}, .expected = "Gift RNG: shiny Magikarp, on the planned target. 04.03 saves it.", @@ -184,7 +200,7 @@ UnitTestResult test_gift_messages(){ }, }; for (const Case& item : cases){ - const std::string got = gift_rng_loop_message(item.result); + const std::string got = gift_rng_loop_message(item.result, item.gift, item.row); if (got != item.expected){ return "Expected \"" + item.expected + "\", got \"" + got + "\"."; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngOptions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngOptions.h index 060763bfdd..7a1d57c1d0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngOptions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngOptions.h @@ -71,7 +71,9 @@ class StarterRngPlanOptions : public GroupOption{ // in "language", logged as "RngPlan:" lines. Throws UserSetupError // when no target passes. std::vector plan(Logger& logger, Language language, uint16_t tid) const; - // As plan(), for Gift RNG's Magikarp from Route 4's salesman. Throws + // As plan(), for Gift RNG's gifts: Route 4's Magikarp, timed as + // Starter RNG's Squirtle, and Celadon's Eevee, whose shorter in-game + // sequence (4,000 ms, no gap) fits any of those timings. Throws // UserSetupError in a language other than English. std::vector gift_plan(Logger& logger, Language language, uint16_t tid) const; // SID Helper's candidates for "tid", from the two SID Helper options. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRoomLegs.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRoomLegs.h index 6c4f7b0e73..3f76328a3d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRoomLegs.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRoomLegs.h @@ -25,7 +25,7 @@ const std::vector& center_enter_legs(); // Out of a Center: south 4 to the mat, south through the door. const std::vector& center_exit_legs(); -// Into the hideout's lift, from below a floor's lift door facing north: +// Into a lift (the hideout's or the store's), from below a floor's lift door facing north: // north through the door onto LIFT_ARRIVAL, north 2, west 2 to below the // panel (LIFT_PANEL_FRONT), facing it. const std::vector& lift_in_legs(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRooms.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRooms.cpp index 89c418d01c..f7fbc68e8a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRooms.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRooms.cpp @@ -35,7 +35,7 @@ const std::vector& center_exit_legs(){ } const std::vector& lift_in_legs(){ static const std::vector LEGS{ - {Pokemon::Direction::NORTH, 1, true, false, LIFT_MAP}, + {Pokemon::Direction::NORTH, 1, true, false, "the lift"}, {Pokemon::Direction::NORTH, 2, false}, {Pokemon::Direction::WEST, 2, false}, {Pokemon::Direction::NORTH, 0, false}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index ef58e7f860..eef3bd93cd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -19,6 +19,7 @@ #include "PokemonFRLG_AutoStoryBattleDecisions.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryFieldMoves.h" #include "PokemonFRLG_AutoStoryHideout.h" #include "PokemonFRLG_AutoStoryHideoutLift.h" #include "PokemonFRLG_AutoStoryRooms.h" @@ -26,6 +27,7 @@ #include "PokemonFRLG_AutoStoryRowSim.h" #include "PokemonFRLG_AutoStoryViridianMart.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -477,6 +479,13 @@ std::string OverworldStepSim::walk(const StoryStep& step){ const RoutePlanning planning{.maps = &story_maps(), .costs = story_route_costs(), .start = MapPosition{m_at.map, m_at.tile}, .label = step.name}; SimWalkerRules rules; rules.trainer_battle_end = battle_end_on_sim; + // A BIKE_VARIANT rides, as on the console, when the sim has the + // player on the Bicycle (the rows' sims stub ride_bike): its open + // legs are tapped out a tile at a time (counts_bike_taps()). Other + // steps keep the sim's walking pace. + if (move_speed(step) == MoveSpeed::BIKE && m_sim.state().on_bike){ + rules.speed = MoveSpeed::BIKE; + } const std::string failure = route ? OverworldSimWalker(m_sim, rules).run(*route, planning) : "no legs."; m_at = route ? StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after} : m_at; return failure; @@ -602,11 +611,42 @@ bool center_walkable(const StoryStep& step){ return after && std::any_of(maps.begin(), maps.end(), [&](const auto& map){ return map.first == after->map; }); } +// Whether the sim can play a field move: Surf, or Fly to a town whose +// map is built into the program. +bool field_move_simulated(const StoryStep& step){ + if (parse_surf_step(step)){ + return true; + } + const std::optional fly = parse_fly_step(step); + const std::vector>& maps = overworld_map_json(); + return fly && std::any_of(maps.begin(), maps.end(), [&](const auto& map){ + return map.first == kanto_fly_towns()[fly->town].landing.map; + }); +} + +// A field move on the sim: turned to the water and Surf, or Fly and its +// landing waited out, as on the console. The failure, or empty. +std::string sim_field_move(const StoryStep& step, OverworldSim& sim){ + if (const std::optional water = parse_surf_step(step)){ + if (sim.state().facing != *water){ + sim_turn_to(sim, *water); + } + return sim.use_field(SimField::SURF) ? "" : "no water to Surf onto."; + } + const std::optional fly = parse_fly_step(step); + if (!fly || !sim.use_field(SimField::FLY, fly->town)){ + return "no Fly from " + to_string(sim.state().position) + "."; + } + sim_wait_out_battle_exit(sim); + return ""; +} + } // namespace // A scripted GAME step on the sim: the poster's switch, the lift's ride -// (its room coded, SimScript::lift_floors, rows as on the panel), or a -// Pokemon Center's way in or out (center_walkable()); any other GAME step +// (its room coded, SimScript::lift_floors, rows as on the panel), a +// Pokemon Center's way in or out (center_walkable()), or a field move +// (field_move_simulated()); any other GAME step // is stubbed. Pokemon::StoryAction OverworldStepSim::hideout_or_stub(){ Pokemon::StoryAction stub = m_stubs.stub(); @@ -615,7 +655,7 @@ Pokemon::StoryAction OverworldStepSim::hideout_or_stub(){ return failure.empty() ? Pokemon::outcome_ok() : Pokemon::outcome_failed("sim_failure", failure); }); sim.act = [stub, played_act = sim.act](const StoryStep& step, RunState& state){ - return is_hideout_step(step) || center_walkable(step) + return is_hideout_step(step) || center_walkable(step) || field_move_simulated(step) ? played_act(step, state) : stub.act(step, state); }; @@ -631,6 +671,10 @@ std::string OverworldStepSim::hideout(const StoryStep& step){ const std::string failure = sim_walk_room_legs(m_sim, center_legs(step.action)); return failure.empty() ? ended_on(step) : failure; } + if (is_field_move_step(step)){ + const std::string failure = sim_field_move(step, m_sim); + return failure.empty() ? ended_on(step) : failure; + } const std::optional ride = parse_lift_floor_step(step); if (!ride){ return "no lift ride \"" + step.action + "\"."; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows_Tests.h index 6b15acaab2..dcf1f4092a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows_Tests.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows_Tests.h @@ -22,10 +22,12 @@ void add_tests_AutoStoryVermilion(UnitTestDatabase& database); // Rows 06.02 to 06.04 on the overworld sim (PokemonFRLG_AutoStoryVermilionGym_Tests.cpp). void add_tests_AutoStoryVermilionGym(UnitTestDatabase& database); // Rows from 07.01 on on the overworld sim (PokemonFRLG_AutoStoryCeladon_Tests.cpp), -// with add_tests_AutoStoryLavender(). +// with add_tests_AutoStoryLavender() and add_tests_AutoStoryTower(). void add_tests_AutoStoryCeladon(UnitTestDatabase& database); // Rows from 08.01 on on the overworld sim (PokemonFRLG_AutoStoryLavender_Tests.cpp). void add_tests_AutoStoryLavender(UnitTestDatabase& database); +// Rows 10.01 to 10.06 on the overworld sim (PokemonFRLG_AutoStoryTower_Tests.cpp). +void add_tests_AutoStoryTower(UnitTestDatabase& database); } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp index 1bfb846f94..7ef168f77d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp @@ -139,7 +139,7 @@ class Test_RunPlan : public UnitTest{ const RunPlanScenario m_scenario; }; -const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02"; +const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06"; const RunPlanScenario RUN_PLAN_CASES[] = { { @@ -230,11 +230,11 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Gift RNG off: 04.03 is passed over", .first = "04.01"}, - .expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02"}, + .expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06"}, }, { .input = {.name = "Gift RNG off: 04.03 runs when started at", .first = "04.03"}, - .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02"}, + .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06"}, }, { .input = { .name = "Gift RNG: started at 04.03, from the save beside the salesman", @@ -257,9 +257,23 @@ const RunPlanScenario RUN_PLAN_CASES[] = { .expected_stop = StoryHandoff::GIFT_RNG, }, }, + { + .input = {.name = "Gift RNG: the Eevee's stop at 09.03", .first = "09.01", .handoffs = {.gift_rng = true}}, + .expectation = { + .expected_ids = "09.01 09.02 09.03", + .expected_stop = StoryHandoff::GIFT_RNG, + }, + }, + { + .input = {.name = "Gift RNG: started at 09.04, from the save facing the Eevee's ball", .first = "09.04", .handoffs = {.gift_rng = true}}, + .expectation = { + .expected_ids = "", + .expected_stop = StoryHandoff::GIFT_RNG, + }, + }, { .input = {.name = "Starter RNG alone: 04.03 runs when started at", .first = "04.03", .handoffs = {.starter_rng = true}}, - .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02"}, + .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06"}, }, { .input = { .name = "Starter RNG first, with both on", @@ -319,7 +333,7 @@ UnitTestResult test_starter_rows_joined(){ } // The ways back in after SID Helper and Gift RNG load no save and start -// where 01.01 and 04.02 leave the player, so the rows after them follow +// where 01.01, 04.02 and 09.03 leave the player, so the rows after them follow // unchanged. UnitTestResult test_after_sid_helper_row(){ const StoryCheckpoint& sid = story_checkpoints()[row_index("01.02")]; @@ -327,8 +341,9 @@ UnitTestResult test_after_sid_helper_row(){ return "Expected 01.01 to be SID Helper's handoff and 01.02 to start from the live game."; } for (const StoryCheckpoint& checkpoint : story_checkpoints()){ - if (checkpoint.live_start != (checkpoint.id == "01.02" || checkpoint.id == "04.03")){ - return checkpoint.id + ": only 01.02 and 04.03 start from the live game."; + const bool live = checkpoint.id == "01.02" || checkpoint.id == "04.03" || checkpoint.id == "09.04"; + if (checkpoint.live_start != live){ + return checkpoint.id + ": only 01.02, 04.03 and 09.04 start from the live game."; } } return true; @@ -608,7 +623,7 @@ UnitTestResult test_misty_grind_order(){ const AutoStoryCase AUTO_STORY_CASES[] = { { - .input = {"01.02 and 04.03: back in after SID Helper and Gift RNG", test_after_sid_helper_row}, + .input = {"01.02, 04.03 and 09.04: back in after SID Helper and Gift RNG", test_after_sid_helper_row}, .expectation = {}, }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 6a3d5e0278..990dfd737c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -35,6 +35,7 @@ #include "PokemonFRLG_AutoStoryCapture.h" #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStoryPaceSim.h" +#include "PokemonFRLG_AutoStoryRngLoop.h" #include "PokemonFRLG_AutoStoryRowSim.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -134,7 +135,7 @@ struct Simulation{ .id = data.id, .title = data.title, .saves = true, .build = [this, &data]{ Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, game); - add_start_pose_check(checkpoint, start_pose(data), [this]{ return game.save_stands; }, [this](const std::string& line){ lines.push_back(line); }); + add_start_pose_check(checkpoint, checked_start_pose(data), [this]{ return game.save_stands; }, [this](const std::string& line){ lines.push_back(line); }); return checkpoint; }, }); @@ -327,6 +328,39 @@ UnitTestResult test_save_off_start_pose(){ return true; } +// console B, FRLG 09.04, 2026-11-11: after a shiny Eevee from Gift RNG in +// AutoStory, 09.04 stopped at its start check on the Eevee's summary, +// which no save's start frame matches. The row after each RNG handoff +// starts where the RNG program left the game, so it runs whatever the +// screen shows. +UnitTestResult test_rows_after_rng_skip_start_check(){ + const std::vector& checkpoints = story_checkpoints(); + const auto index = [&checkpoints](std::string_view id){ + return (size_t)(&checkpoint_row(id) - checkpoints.data()); + }; + const StoryHandoffs handoffs{.starter_rng = true, .gift_rng = true}; + const std::vector CASES[] = { + rows_after_starter_rng(checkpoints, index("01.05"), index("01.06"), handoffs).rows, + rows_after_gift_rng(checkpoints, index("04.02"), index("04.03"), handoffs).rows, + rows_after_gift_rng(checkpoints, index("09.03"), index("09.04"), handoffs).rows, + }; + for (const std::vector& rows : CASES){ + Simulation sim; + sim.rows = rows; + sim.game.save_stands = StoryPose{"PewterCity", TilePos{17, 26}, Direction::SOUTH}; + const std::string& id = rows.front().id; + const Pokemon::SegmentReport report = sim.run({.from = id, .to = id}); + const auto told = [](const std::string& line){ return line.starts_with("start pose mismatch: "); }; + if (!report.completed || std::ranges::any_of(sim.lines, told)){ + return std::format( + "{} after its RNG handoff: expected it run with no start check; got {}{}{}", + id, Pokemon::to_string(report.failure), joined(sim.game.trace), joined(sim.lines) + ); + } + } + return true; +} + // Brock's battle lost every time: three attempts, then the stop. UnitTestResult test_gives_up_after_attempts(){ Simulation sim; @@ -830,6 +864,7 @@ const AutoStorySimulationTestCase AUTO_STORY_SIMULATION_CASES[] = { {.input = {.name = "05.09 onto the grass out of Shane's sight, the leg west a tile short", .body = test_oddish_patch_west_short}, .expectation = {.description = "recovers when approaching grass patch with short western leg"}}, {.input = {.name = "the routes after pacing, from either of its tiles", .body = test_routes_after_pacing}, .expectation = {.description = "plans valid routes regardless of which pacing tile character ends on"}}, {.input = {.name = "a save off the start pose stops before any step", .body = test_save_off_start_pose}, .expectation = {.description = "fails the start check without walking or saving"}}, + {.input = {.name = "the row after an RNG handoff runs off any start pose", .body = test_rows_after_rng_skip_start_check}, .expectation = {.description = "01.06, 04.03 and 09.04 start where the RNG program left the game"}}, {.input = {.name = "a dialog pops up before every step", .body = test_dialog_before_every_step}, .expectation = {.description = "cleared between steps, the story passes; left up, a walk fails on it"}}, {.input = {.name = "dialogs pop up before one step in five, over 5 seeds", .body = nullptr, .logged = test_dialogs_at_random}, .expectation = {.description = "every run passes with them cleared"}}, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h index c20800708b..9bcf72a2fd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrameStore.h @@ -10,6 +10,7 @@ #define PokemonAutomation_PokemonFRLG_AutoStoryStartFrameStore_H #include +#include #include #include #include @@ -51,6 +52,14 @@ using StartFrameSource = std::function; // is NOT_READ. StartRead read_start_frames(const std::optional& reference, const StartFrameSource& next_frame, size_t tries); +// The console's start check: how many frames it tries, so a fade or a +// passer-by in front of the camera on one frame doesn't fail it. Waiting +// doesn't help with Pokemon Tower's fog, which a reload shows elsewhere +// (see compare_start_frames()). +constexpr size_t CONSOLE_START_FRAME_TRIES = 3; +// The wait between two frames of the console's start check. +constexpr std::chrono::milliseconds CONSOLE_START_FRAME_WAIT{1000}; + // Where the start frames are kept: for each checkpoint, .png, the // frame, and .json, the checkpoint, when it was kept and why. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp index 22658b98fb..2552355711 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.cpp @@ -4,8 +4,11 @@ * */ +#include #include #include +#include +#include #include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/Json/JsonObject.h" @@ -30,33 +33,42 @@ constexpr size_t TILE = 16; // animated tile, whose pattern shifts a few pixels, keeps its averages. constexpr size_t BLOCK = 8; -// The thresholds, from console B's captures (Route 10 outside the -// Center and on its grass, S.S. Anne's 1F corridor) and edits of them, -// with 8x8 quarters and 24 below: -// - the same frame with the player's 16x32 sprite copied onto one or two -// other tiles, as a person who walked there: 1 to 4 tiles changed of -// 150; the river's pattern shifted 2 or 4 pixels, as its animation -// does: 0 to 10; -// - another place on the same route, or Route 10 against the S.S. Anne: -// 131 and 148; -// - the view one step off: 20 to 78, depending on how plain the floor is; -// six steps along the S.S. Anne's plain corridor: 36. -// A quarter of the tiles (37) leaves room for a river and 6 people who -// moved (at most 4 tiles each: where they stood and stand), and catches -// another place and 5 of the 6 single steps off; a step along a plain -// corridor can pass. - -// A tile has changed when its quarters differ by more than this, on -// average per colour channel (0 to 255). +// The tile's colour. A tile has changed when its quarters differ by more +// than this, on average per colour channel (0 to 255); from console B's +// captures (Route 10 outside the Center and on its grass, S.S. Anne's 1F +// corridor) and edits of them, as people who walked and water animating. constexpr unsigned TILE_CHANGE = 24; -// The same place when at most a quarter of the tiles changed. +// ...unless its detail is the same (below): Pokemon Tower's fog +// (WEATHER_FOG_HORIZONTAL) is a cloud texture blended over the whole +// screen, and on 5F (10.05, 2026-11-12) it changed the colour of up to 78 +// tiles between the frame kept after the save and the same pose reloaded, +// each by at most 38. The fog moves with the camera's offset since the map +// loaded (pret field_weather_effect.c, sprite->y2 = gSpriteCoordOffsetY) +// and scrolls with time, so a save loaded shows it elsewhere, here 16 +// pixels lower, whatever the wait. A colour change beyond the fog's +// changes the tile alone. +constexpr unsigned TILE_COLOUR_CHANGE = 48; + +// The tile's detail: each pixel less the average of the 5x5 pixels around +// it, which takes out the fog's smooth clouds and keeps the tiles' edges. +constexpr int DETAIL_RADIUS = 2; +// Detail moved by up to this many pixels is the same detail: water and +// flowers animate in shifts of a few pixels. +constexpr int DETAIL_SHIFT = 2; +// A tile has changed when its detail differs by more than this, on +// average per pixel and channel, or by more than DETAIL_SOME_CHANGE with +// its colour beyond TILE_CHANGE. On the Tower 5F pair: 19 of 150 tiles; +// one step off on Tower 3F to 5F, the Celadon Department Store and the +// Lavender house: 41 to 76; on Route 10's grass: 49 to 51; along the +// S.S. Anne's plain corridor: 36, and six steps: 43 (the colour alone: +// 20 and 36). +constexpr double DETAIL_CHANGE = 10; +constexpr double DETAIL_SOME_CHANGE = 8; + +// The same place when at most a quarter of the tiles changed: room for 6 +// people who moved (at most 4 tiles each: where they stood and stand). constexpr size_t MOST_CHANGED_PERCENT = 25; -// Frames the console's start check tries, a second apart: a fade or a -// passer-by in front of the camera on one frame doesn't fail it. -constexpr size_t START_FRAME_TRIES = 3; -constexpr Milliseconds START_FRAME_WAIT = std::chrono::milliseconds(1000); - // The block at (`bx`, `by`): its channels' totals in `a` less those in // `b`, summed as absolute values. uint64_t block_difference(const ImageViewRGB32& a, const ImageViewRGB32& b, size_t bx, size_t by){ @@ -84,6 +96,92 @@ unsigned tile_difference(const ImageViewRGB32& a, const ImageViewRGB32& b, size_ return (unsigned)(total / (TILE * TILE * 3)); } +// A start frame's detail: per pixel and channel, the value less the +// average around it (DETAIL_RADIUS, the edges repeated). +class FrameDetail{ +public: + explicit FrameDetail(const ImageViewRGB32& frame) + : m_values(FRAME_WIDTH * FRAME_HEIGHT * 3) + { + constexpr int SIDE = 2 * DETAIL_RADIUS + 1; + for (int y = 0; y < (int)FRAME_HEIGHT; y++){ + for (int x = 0; x < (int)FRAME_WIDTH; x++){ + int sums[3] = {0, 0, 0}; + for (int dy = -DETAIL_RADIUS; dy <= DETAIL_RADIUS; dy++){ + for (int dx = -DETAIL_RADIUS; dx <= DETAIL_RADIUS; dx++){ + add_channels(sums, frame.pixel(clamped(x + dx, FRAME_WIDTH), clamped(y + dy, FRAME_HEIGHT))); + } + } + const uint32_t pixel = frame.pixel(x, y); + for (int c = 0; c < 3; c++){ + m_values[index(x, y, c)] = (int)((pixel >> (8 * c)) & 0xff) * SIDE * SIDE - sums[c]; + } + } + } + } + + // The value at (`x`, `y`), channel `c`, times the averaged area. + int value(int x, int y, int c) const{ + return m_values[index(x, y, c)]; + } + +private: + static size_t clamped(int v, size_t size){ + return (size_t)std::clamp(v, 0, (int)size - 1); + } + static void add_channels(int sums[3], uint32_t pixel){ + for (int c = 0; c < 3; c++){ + sums[c] += (int)((pixel >> (8 * c)) & 0xff); + } + } + static size_t index(int x, int y, int c){ + return ((size_t)y * FRAME_WIDTH + (size_t)x) * 3 + (size_t)c; + } + + std::vector m_values; +}; + +// The tile at (`tx`, `ty`) of `a`'s detail against `b`'s moved by +// (`sx`, `sy`): the average difference per pixel and channel, over the +// pixels inside `b`. +double shifted_detail_difference(const FrameDetail& a, const FrameDetail& b, size_t tx, size_t ty, int sx, int sy){ + constexpr int AREA = (2 * DETAIL_RADIUS + 1) * (2 * DETAIL_RADIUS + 1); + int64_t total = 0; + int64_t count = 0; + for (int y = (int)(ty * TILE); y < (int)((ty + 1) * TILE); y++){ + for (int x = (int)(tx * TILE); x < (int)((tx + 1) * TILE); x++){ + const int bx = x + sx; + const int by = y + sy; + if (bx < 0 || by < 0 || bx >= (int)FRAME_WIDTH || by >= (int)FRAME_HEIGHT){ + continue; + } + for (int c = 0; c < 3; c++){ + total += std::abs(a.value(x, y, c) - b.value(bx, by, c)); + } + count += 3; + } + } + return (double)total / (double)(count * AREA); +} + +// The tile at (`tx`, `ty`)'s detail difference, the closest of the shifts +// up to DETAIL_SHIFT. +double detail_difference(const FrameDetail& a, const FrameDetail& b, size_t tx, size_t ty){ + double best = std::numeric_limits::max(); + for (int sy = -DETAIL_SHIFT; sy <= DETAIL_SHIFT; sy++){ + for (int sx = -DETAIL_SHIFT; sx <= DETAIL_SHIFT; sx++){ + best = std::min(best, shifted_detail_difference(a, b, tx, ty, sx, sy)); + } + } + return best; +} + +bool tile_changed(unsigned colour, double detail){ + return detail > DETAIL_CHANGE + || colour > TILE_COLOUR_CHANGE + || (colour > TILE_CHANGE && detail > DETAIL_SOME_CHANGE); +} + } // namespace @@ -94,11 +192,13 @@ ImageRGB32 start_frame(const ImageViewRGB32& game_screen){ StartFrameDifference compare_start_frames(const ImageViewRGB32& reference, const ImageViewRGB32& frame){ const ImageRGB32 a = start_frame(reference); const ImageRGB32 b = start_frame(frame); + const FrameDetail a_detail(a); + const FrameDetail b_detail(b); StartFrameDifference difference; for (size_t ty = 0; ty < FRAME_HEIGHT / TILE; ty++){ for (size_t tx = 0; tx < FRAME_WIDTH / TILE; tx++){ difference.tiles++; - if (tile_difference(a, b, tx, ty) > TILE_CHANGE){ + if (tile_changed(tile_difference(a, b, tx, ty), detail_difference(a_detail, b_detail, tx, ty))){ difference.changed++; } } @@ -187,10 +287,10 @@ StartRead check_console_start( size_t frames = 0; return read_start_frames(store.load(checkpoint), [&]{ if (frames++ > 0){ - context.wait_for(START_FRAME_WAIT); + context.wait_for(CONSOLE_START_FRAME_WAIT); } return console_start_frame(console, context); - }, START_FRAME_TRIES); + }, CONSOLE_START_FRAME_TRIES); } bool keep_console_frame( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h index 479a2beee6..37c898172a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames.h @@ -40,8 +40,8 @@ namespace PokemonFRLG{ ImageRGB32 console_start_frame(ConsoleHandle& console, ProControllerContext& context); // The console's start check for `checkpoint`: the screen against the -// frame `store` keeps for it, up to 3 frames a second apart -// (read_start_frames()). +// frame `store` keeps for it, up to CONSOLE_START_FRAME_TRIES frames +// CONSOLE_START_FRAME_WAIT apart (read_start_frames()). StartRead check_console_start( ConsoleHandle& console, ProControllerContext& context, const StartFrameStore& store, const std::string& checkpoint ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp index 27ab064b24..ed1b518c66 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStartFrames_Tests.cpp @@ -12,15 +12,19 @@ */ #include +#include #include +#include #include #include +#include #include #include #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "Tests/ImageUnitTest.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStoryStartFrames.h" @@ -87,9 +91,9 @@ struct Person{ size_t ty; }; -// What the camera at map tile (`cx`, `cy`) shows, with `people` on it, as -// the capture shows the game: scaled up, with noise. -ImageRGB32 screen(const Map& map, size_t cx, size_t cy, const std::vector& people, uint32_t noise_seed){ +// What the camera at map tile (`cx`, `cy`) shows, with `people` on it, in +// the GBA's own pixels. +ImageRGB32 view_of(const Map& map, size_t cx, size_t cy, const std::vector& people){ ImageRGB32 view(VIEW_TILES_X * TILE, VIEW_TILES_Y * TILE); for (size_t y = 0; y < view.height(); y++){ for (size_t x = 0; x < view.width(); x++){ @@ -105,6 +109,11 @@ ImageRGB32 screen(const Map& map, size_t cx, size_t cy, const std::vector& people, uint32_t noise_seed){ + return capture_of(view_of(map, cx, cy, people), noise_seed); +} + +// Pokemon Tower's upper floors (3F to 6F) have WEATHER_FOG_HORIZONTAL: +// a cloud texture scrolls one pixel every 4 frames (15 a second). It shows gray over the black void beside the +// floor and over the floor alike. `screen` with the void in its 5 right +// columns of tiles and the fog scrolled by `scroll` pixels; on console B's +// frame its 8x8 averages over the void ran from 126 to 186. +ImageRGB32 fogged(const Map& map, size_t cx, size_t cy, const std::vector& people, size_t scroll, uint32_t noise_seed){ + constexpr double TAU = 6.283185307179586; + ImageRGB32 view = view_of(map, cx, cy, people); + for (size_t y = 0; y < view.height(); y++){ + for (size_t x = 0; x < view.width(); x++){ + const double u = (double)(x + scroll); + const double v = (double)y; + const int cloud = (int)(32 * std::sin(TAU * u / 64 + 1.2 * std::sin(TAU * v / 64)) + + 12 * std::sin(TAU * u / 32 + TAU * v / 64)); + const uint32_t pixel = view.pixel(x, y); + const auto channel = [&](int shift){ + const int base = x >= 10 * TILE ? 155 : (int)((pixel >> shift) & 0xff); + return (uint32_t)std::clamp(base + cloud, 0, 255); + }; + view.pixel(x, y) = rgb(channel(16), channel(8), channel(0)); + } + } + return capture_of(view, noise_seed); +} + const Map CENTER = make_map(INDOOR, 27); const Map CITY = make_map(OUTDOOR, 10); const Map ROUTE = make_map(OUTDOOR, 4); @@ -207,7 +245,10 @@ struct ReadInput{ std::string name; bool has_reference; // The screens, one per frame read; an empty one is no video. - std::vector frames; + std::vector> frames; + // The screen kept as the start frame. + ImageRGB32 (*reference)() = counter_reference; + size_t tries = 3; }; struct ReadExpectation{ StartFound found; @@ -233,6 +274,25 @@ ImageRGB32 outside_door(){ return screen(CITY, 12, 6, {PLAYER}, 9); } +// Pokemon Tower 5F, the player beside a Channeler, as in a run: the frame +// kept right after the save, the check's frames the fog scrolled on. +const Map TOWER = make_map(INDOOR, 51); +constexpr size_t FOG_PIXELS_PER_SECOND = 15; +ImageRGB32 tower_kept(){ + return fogged(TOWER, 6, 9, {PLAYER, {8, 5}, {0, 2}}, 0, 21); +} +// The console's start check's frames from the camera at row `cy`, the +// first one with the fog scrolled 20 pixels on from the kept frame, the +// others CONSOLE_START_FRAME_WAIT apart. +std::vector> tower_frames(size_t cy, const std::vector& people){ + std::vector> frames; + for (size_t c = 0; c < CONSOLE_START_FRAME_TRIES; c++){ + const size_t scroll = 20 + c * FOG_PIXELS_PER_SECOND * (size_t)CONSOLE_START_FRAME_WAIT.count() / 1000; + frames.push_back([=]{ return fogged(TOWER, 6, cy, people, scroll, 22 + (uint32_t)c); }); + } + return frames; +} + std::string to_string(StartFound found){ switch (found){ case StartFound::NOT_READ: @@ -255,12 +315,12 @@ class Test_StartFrameRead : public UnitTest{ virtual UnitTestResult run(Logger&, CancellableScope&) const override{ std::optional reference; if (m_case.input.has_reference){ - reference = start_frame(counter_reference()); + reference = start_frame(m_case.input.reference()); } size_t read = 0; const StartRead got = read_start_frames(reference, [&]{ return m_case.input.frames[std::min(read++, m_case.input.frames.size() - 1)](); - }, 3); + }, m_case.input.tries); if (got.found != m_case.expectation.found || read != m_case.expectation.frames_read){ return std::format( "expected {} after {} frames, got {} after {}: {}", @@ -295,6 +355,16 @@ const ReadCase READ_CASES[] = { .input = {"outside the door three times: elsewhere", true, {outside_door}}, .expectation = {StartFound::ELSEWHERE, 3}, }, + { + .input = {"Tower fog scrolled since the save: at the start", true, + tower_frames(9, {PLAYER, {8, 5}, {0, 2}}), tower_kept, CONSOLE_START_FRAME_TRIES}, + .expectation = {StartFound::AT_START, 1}, + }, + { + .input = {"Tower fog, one step off: elsewhere", true, + tower_frames(10, {PLAYER, {8, 4}, {0, 1}}), tower_kept, CONSOLE_START_FRAME_TRIES}, + .expectation = {StartFound::ELSEWHERE, CONSOLE_START_FRAME_TRIES}, + }, }; @@ -455,6 +525,97 @@ const StoreCase STORE_CASES[] = { }, }; + +// console B, FRLG 10.05, 2026-11-12, Pokemon Tower 5F beside a Channeler: +// the start frame kept at the 10.04 save, and the same pose after that +// save was reloaded, the fog 16 pixels lower. The colour alone changed 71 +// of 150 tiles, on each of 12 frames over 4.8 seconds. The reloaded frame +// is also moved by a tile, the strip a step would bring into view taken +// from the kept frame, as the view one step off. +struct TowerFogInput{ + std::string name; + // The reloaded frame moved by this many tiles. + int tiles_x; + int tiles_y; +}; +struct TowerFogExpectation{ + bool same_place; +}; +struct TowerFogCase{ + TowerFogInput input; + TowerFogExpectation expectation; +}; + +constexpr std::string_view TOWER_KEPT = "PokemonFRLG/AutoStoryStartFrames/PokemonTower5F_KeptAtSave.png"; +constexpr std::string_view TOWER_RELOADED = "PokemonFRLG/AutoStoryStartFrames/PokemonTower5F_Reloaded.png"; + +// `frame` moved by (`tiles_x`, `tiles_y`) tiles, what it doesn't cover +// from `fill`. +ImageRGB32 moved(const ImageViewRGB32& frame, const ImageViewRGB32& fill, int tiles_x, int tiles_y){ + ImageRGB32 out = fill.copy(); + for (size_t y = 0; y < out.height(); y++){ + for (size_t x = 0; x < out.width(); x++){ + const int from_x = (int)x - tiles_x * (int)TILE; + const int from_y = (int)y - tiles_y * (int)TILE; + if (from_x >= 0 && from_y >= 0 && from_x < (int)frame.width() && from_y < (int)frame.height()){ + out.pixel(x, y) = frame.pixel(from_x, from_y); + } + } + } + return out; +} + +class Test_StartFrameTowerFog : public ImageUnitTest{ +public: + explicit Test_StartFrameTowerFog(TowerFogCase test_case) + : ImageUnitTest( + std::format("PokemonFRLG::AutoStoryStartFrames - {}", test_case.input.name), + {std::string(TOWER_KEPT), std::string(TOWER_RELOADED)} + ) + , m_case(std::move(test_case)) + {} + +protected: + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + const ImageRGB32 kept = start_frame(images[0]); + const ImageRGB32 reloaded = moved(start_frame(images[1]), kept, m_case.input.tiles_x, m_case.input.tiles_y); + const StartFrameDifference difference = compare_start_frames(kept, reloaded); + if (same_start_place(difference) != m_case.expectation.same_place){ + return std::format( + "expected {}, got {}", + m_case.expectation.same_place ? "the same place" : "another place", to_string(difference) + ); + } + return true; + } + +private: + TowerFogCase m_case; +}; + +const TowerFogCase TOWER_FOG_CASES[] = { + { + .input = {"Tower 5F reloaded, the fog elsewhere: the same place", 0, 0}, + .expectation = {true}, + }, + { + .input = {"Tower 5F reloaded, a step east: another place", 1, 0}, + .expectation = {false}, + }, + { + .input = {"Tower 5F reloaded, a step west: another place", -1, 0}, + .expectation = {false}, + }, + { + .input = {"Tower 5F reloaded, a step south: another place", 0, 1}, + .expectation = {false}, + }, + { + .input = {"Tower 5F reloaded, a step north: another place", 0, -1}, + .expectation = {false}, + }, +}; + } // namespace @@ -471,6 +632,9 @@ void add_tests_AutoStoryStartFrames(UnitTestDatabase& database){ for (const auto& item : STORE_CASES){ database.add(item); } + for (const auto& item : TOWER_FOG_CASES){ + database.add(item); + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp index c6def74d2c..9836fdb983 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -127,8 +127,10 @@ Pokemon::StoryActionSpec teach_action_spec(){ return {.kind = StoryStepKind::GAME, .name = TEACH_ACTION, .args = { required_arg("item", StoryArgType::WORD, "the TM or HM, e.g. \"hm03\""), required_arg("move", StoryArgType::WORD, "the move it holds, e.g. \"surf\""), - required_arg("slot", StoryArgType::INTEGER, "the party slot, from 1"), + absent_arg("slot", StoryArgType::INTEGER, "the party slot, from 1, when no species is named"), + absent_arg("species", StoryArgType::WORD, "the member by its species, e.g. \"pidgey\": the first slot whose summary reads it"), absent_arg("forget", StoryArgType::WORD, "the move to forget when it knows four"), + absent_arg("or_forget", StoryArgType::WORDS, "the moves to forget, in order, when it doesn't know `forget`"), absent_arg("forget_slot", StoryArgType::INTEGER, "the move slot to forget, from 1, when no move is named"), }}; } @@ -190,10 +192,15 @@ std::span story_action_specs(){ .key = "foes", .type = Pokemon::StoryArgType::WORDS, .required = false, .fallback = std::vector(), .why = "the trainer's party in order; attacks are chosen against the one out", }); + spec.args.push_back(Pokemon::StoryArgSpec{ + .key = "use_items", .type = Pokemon::StoryArgType::ITEMS, .required = false, .fallback = std::vector(), + .why = "items used on the lead from the first turn, in order, before any attack (X Specials)", + }); } for (Pokemon::StoryActionSpec spec : movement_variant_specs(builtin)){ specs.push_back(std::move(spec)); } + specs.push_back({.kind = StoryStepKind::TALK, .name = TALK_WANDERER_VARIANT, .args = {}}); specs.push_back({.kind = StoryStepKind::GAME, .name = CLOSE_TRAINER_CARD, .args = {}}); specs.push_back({.kind = StoryStepKind::GAME, .name = LEAVE_GIFT_SUMMARY, .args = {}}); specs.push_back({.kind = StoryStepKind::GAME, .name = CUT_TREE_VARIANT, .args = { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h index 1feb1136eb..c7d89a441a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h @@ -74,7 +74,8 @@ const std::vector& story_action_rows(); // ones (Pokemon_BuiltinStoryActions.h), then a ROUTE and a LEGS named // "run" (RUN_VARIANT), which take the same args and run with B held, // STEPs named "trainer_line" (TRAINER_LINE_VARIANT) and "trainer_wait" -// (TRAINER_WAIT_VARIANT), then FRLG's GAME actions: closing the Trainer +// (TRAINER_WAIT_VARIANT), a TALK named "wanderer" (TALK_WANDERER_VARIANT), +// then FRLG's GAME actions: closing the Trainer // Card or the Gift RNG summary, cutting a tree, the trash cans, a PC // transfer, a capture, the fossil, a LEVEL check, a Mart, a TEACH and a // GRIND, each with the args it declares. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp index f1ebde9f09..926b48d2c4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp @@ -19,6 +19,7 @@ #include "PokemonFRLG_AutoStoryStepInterrupts.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryFieldMoveSteps.h" #include "PokemonFRLG_AutoStoryHideout.h" #include "PokemonFRLG_AutoStoryRooms.h" #include "PokemonFRLG_AutoStoryItemUse.h" @@ -254,6 +255,7 @@ void add_tests_AutoStoryStepTable(UnitTestDatabase& database){ add_tests_AutoStoryStepInterrupts(database); // The GAME variants with logic of their own. add_tests_AutoStoryHideout(database); + add_tests_AutoStoryFieldMoves(database); add_tests_AutoStoryRooms(database); add_tests_AutoStoryItemUse(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp index e61a81ab2a..4748f8709c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp @@ -120,7 +120,12 @@ std::optional read_party_summary( console, context, menu == StartMenu::BEFORE_POKEDEX ? StartMenuContext::NO_DEX : StartMenuContext::STANDARD ); context.wait_for_all_requests(); - // The party menu opens on the lead; DOWN steps through the slots. + // LEFT puts the cursor on the lead from any other slot (pokefirered + // party_menu.c, MENU_DIR_LEFT); on the lead it does nothing. The menu + // doesn't always open on the lead: 10.01's teach_fly read slot 1 as the + // Pidgey, the party's third (console B, 2026-11-12 01:38). DOWN steps + // through the slots from there. + tap(context, DPAD_LEFT); for (size_t c = 0; c < slot; c++){ tap(context, DPAD_DOWN); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h index a35911cd19..58d122e50f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h @@ -11,6 +11,7 @@ #define PokemonAutomation_PokemonFRLG_AutoStorySupplies_H #include +#include #include #include #include @@ -18,6 +19,7 @@ #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionArg.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryActions.h" @@ -54,8 +56,11 @@ struct Supplies{ // The Items pocket's order, by slug (see read_item_list_name()): the // order bought, or as read from the bag, with "" for a row whose name // couldn't be read. A counted item with none left takes no row; the - // others always take theirs. + // others always take theirs, until other_counts says the last is used. std::vector pocket = {"potion", "antidote", "parlyz-heal"}; + // The counts the bag read for the items the story doesn't count (an + // X Special), by slug; an item missing here has an unknown count. + std::map other_counts = {}; // The starter's status at the last battle screen that showed it, and // not cured since. StatusCondition status = StatusCondition::NONE; @@ -80,6 +85,11 @@ struct Supplies{ std::vector foes = {}; // That trainer, as its plan names it (the step's "trainer"), "" otherwise. std::string trainer = {}; + // The items that battle uses on the lead from its first turn, in the + // plan's order and before any attack (the step's "use_items": PokeGuy's + // X Specials against the Tower rival), each once its pocket row is + // known; a quantity counts down as they are used. Empty otherwise. + std::vector battle_items = {}; // How carefully that battle is fought (default_battle_risk()). BattleRisk risk = BattleRisk::LOW; // The species of the trainer's Pokemon out, as read at the last battle diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 7a8faade06..51ddeca644 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -52,6 +52,17 @@ StoryHandoff read_handoff(std::string_view name, std::string_view source){ throw ParseException(std::format("{}: unknown handoff {}", source, name)); } +// The wire names of the gifts Gift RNG's handoff takes. +PokemonFRLG_RngTarget read_gift(std::string_view name, std::string_view source){ + if (name == "magikarp"){ + return PokemonFRLG_RngTarget::magikarp; + } + if (name == "eevee"){ + return PokemonFRLG_RngTarget::eevee; + } + throw ParseException(std::format("{}: unknown gift {}", source, name)); +} + // `object`'s fields, each of which must be one of `keys`. void only_fields(const JsonObject& object, std::initializer_list keys, std::string_view source){ for (const auto& [key, unused] : object){ @@ -173,12 +184,15 @@ StoryCheckpoint read_story_checkpoint_file(const JsonValue& value, std::string_v StoryCheckpoint checkpoint; std::set note_keys; const Pokemon::ExecutionReader read_execution = [&](const JsonObject& execution, std::string_view where){ - only_fields(execution, {"menu", "supplies", "lead", "handoff", "live_start", "notes"}, where); + only_fields(execution, {"menu", "supplies", "lead", "handoff", "gift", "live_start", "notes"}, where); checkpoint.menu = read_start_menu(execution.get_string_throw("menu", std::string(where)), where); checkpoint.supplies = read_supplies(execution, where); if (execution.get_value("handoff") != nullptr){ checkpoint.handoff = read_handoff(execution.get_string_throw("handoff", std::string(where)), where); } + if (execution.get_value("gift") != nullptr){ + checkpoint.gift = read_gift(execution.get_string_throw("gift", std::string(where)), where); + } if (execution.get_value("live_start") != nullptr){ checkpoint.live_start = execution.get_boolean_throw("live_start", std::string(where)); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp index c9697a6700..02cc1455f5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp @@ -44,14 +44,42 @@ bool is_tm_or_hm(std::string_view item){ && item[2] >= '0' && item[2] <= '9' && item[3] >= '0' && item[3] <= '9'; } +// The slot of `plan`'s move to forget, its first choice the member knows. +std::optional first_known(const std::vector& moves, const TeachPlan& plan){ + std::vector choices{plan.forget_move}; + choices.insert(choices.end(), plan.forget_else.begin(), plan.forget_else.end()); + for (const std::string& move : choices){ + const auto found = std::find(moves.begin(), moves.end(), move); + if (found != moves.end()){ + return size_t(found - moves.begin()); + } + } + return std::nullopt; +} + +// "whirlwind", or "whirlwind or sand-attack". +std::string forget_names(const TeachPlan& plan){ + std::string names = plan.forget_move; + for (const std::string& move : plan.forget_else){ + names += std::format(" or {}", move); + } + return names; +} + } // namespace Pokemon::StoryActionArgs teach_args(const TeachPlan& plan){ - Pokemon::StoryActionArgs args{ - {"item", plan.item}, {"move", plan.move}, {"slot", int64_t(plan.member + 1)}, - }; + Pokemon::StoryActionArgs args{{"item", plan.item}, {"move", plan.move}}; + if (plan.species.empty()){ + args.emplace("slot", int64_t(plan.member + 1)); + }else{ + args.emplace("species", plan.species); + } if (!plan.forget_move.empty()){ args.emplace("forget", plan.forget_move); + if (!plan.forget_else.empty()){ + args.emplace("or_forget", plan.forget_else); + } }else if (plan.forget_slot){ args.emplace("forget_slot", int64_t(*plan.forget_slot + 1)); } @@ -61,17 +89,28 @@ Pokemon::StoryActionArgs teach_args(const TeachPlan& plan){ std::optional teach_plan_of(const Pokemon::StoryActionArgs& args){ const std::string* item = game_arg(args, "item"); const std::string* move = game_arg(args, "move"); - const std::optional member = counted_arg(args, "slot", PARTY_SLOTS); - if (item == nullptr || !(is_tm_or_hm(*item) || *item == TEACH_TUTOR) || move == nullptr || move->empty() || !member){ + const std::string* species = game_arg(args, "species"); + const std::optional member = args.contains("slot") ? counted_arg(args, "slot", PARTY_SLOTS) : std::nullopt; + const bool one_member = species == nullptr ? member.has_value() : !species->empty() && !args.contains("slot"); + if (item == nullptr || !(is_tm_or_hm(*item) || *item == TEACH_TUTOR) || move == nullptr || move->empty() || !one_member){ return std::nullopt; } - TeachPlan plan{.item = *item, .move = *move, .member = *member}; + TeachPlan plan{.item = *item, .move = *move, .member = member.value_or(0)}; + if (species != nullptr){ + plan.species = *species; + } if (const std::string* forget = game_arg(args, "forget")){ if (forget->empty()){ return std::nullopt; } plan.forget_move = *forget; } + if (const std::vector* forget_else = game_arg>(args, "or_forget")){ + if (plan.forget_move.empty()){ + return std::nullopt; + } + plan.forget_else = *forget_else; + } if (args.contains("forget_slot")){ plan.forget_slot = counted_arg(args, "forget_slot", MOVE_SLOTS); if (!plan.forget_slot){ @@ -102,11 +141,11 @@ TeachDecision decide_teach(const TeachPlan& plan, const std::vector } std::optional slot = plan.forget_slot; if (!plan.forget_move.empty()){ - const auto found = std::find(moves.begin(), moves.end(), plan.forget_move); - if (found == moves.end()){ - return {.error = std::format("it doesn't know {}, the move to forget", plan.forget_move)}; + const std::optional known = first_known(moves, plan); + if (!known){ + return {.error = std::format("it doesn't know {}, the move to forget", forget_names(plan))}; } - slot = size_t(found - moves.begin()); + slot = known; } if (!slot){ return {.error = "it knows four moves and the table names none to forget"}; @@ -247,15 +286,41 @@ class TeachRun{ } // namespace +std::optional find_party_species(const MemberReader& reader, std::string_view species){ + for (size_t slot = 0; slot < PARTY_SLOTS; slot++){ + const std::optional member = reader(slot); + if (!member){ + return std::nullopt; + } + if (member->species == species){ + return slot; + } + } + return std::nullopt; +} + TeachResult run_teach(Logger& logger, TeachActions& actions, const MemberReader& reader, const TeachPlan& plan){ - TeachResult result = TeachRun(actions, reader, plan).run(); + TeachPlan found = plan; + if (!plan.species.empty()){ + const std::optional slot = find_party_species(reader, plan.species); + if (!slot){ + const TeachResult result{.end = TeachEnd::UNREAD, .detail = std::format("no {} read in the party", plan.species)}; + logger.log(std::format("Teach {} ({}) to the {}: {}.", plan.move, plan.item, plan.species, result.detail), COLOR_RED); + return result; + } + found.member = *slot; + } + TeachResult result = TeachRun(actions, reader, found).run(); const Color color = result.end == TeachEnd::LEARNED ? COLOR_BLACK : result.end == TeachEnd::NO_ITEM ? COLOR_ORANGE : COLOR_RED; - logger.log(teach_message(plan, result), color); + logger.log(teach_message(found, result), color); return result; } std::string teach_message(const TeachPlan& plan, const TeachResult& result){ - const std::string what = std::format("Teach {} ({}) to slot {}", plan.move, plan.item, plan.member + 1); + const std::string to = plan.species.empty() + ? std::format("slot {}", plan.member + 1) + : std::format("the {} (slot {})", plan.species, plan.member + 1); + const std::string what = std::format("Teach {} ({}) to {}", plan.move, plan.item, to); switch (result.end){ case TeachEnd::LEARNED: return result.forgot.empty() diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h index b89dbbdd8b..08d418d90e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h @@ -89,6 +89,11 @@ struct TeachResult{ std::string detail = {}; }; +// The first party slot whose member `reader` reads as `species`; nothing +// if none does. Stops at the first slot not read (an empty slot ends the +// party). +std::optional find_party_species(const MemberReader& reader, std::string_view species); + // From the overworld: reads the member, teaches as `plan` says, back to // the overworld, and reads the member again to confirm. TeachResult run_teach(Logger& logger, TeachActions& actions, const MemberReader& reader, const TeachPlan& plan); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachPlan.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachPlan.h index dbe7136025..84e98f69a3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachPlan.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachPlan.h @@ -35,9 +35,15 @@ struct TeachPlan{ std::string move = {}; // The party slot (0-5). size_t member = 0; + // The member by its species' slug (e.g. "pidgey"), as its summary + // reads: the first slot that holds one is taught, and `member` is + // not used. Empty: `member`. + std::string species = {}; // The move to forget when it knows four: by name, or else by its // slot (0-3). Neither: it must have a free slot. std::string forget_move = {}; + // The moves to forget, in order, when it doesn't know `forget_move`. + std::vector forget_else = {}; std::optional forget_slot = std::nullopt; }; @@ -45,9 +51,11 @@ struct TeachPlan{ bool is_hm_move(std::string_view move); // The GAME action of a TEACH step: item WORD (required), the TM or HM, -// e.g. "hm03"; move WORD (required), e.g. "surf"; slot INTEGER -// (required, from 1); forget WORD or forget_slot INTEGER (from 1) -// (optional): the move to forget when it knows four. +// e.g. "hm03"; move WORD (required), e.g. "surf"; slot INTEGER (from 1) +// or species WORD (one of them required); forget WORD or forget_slot +// INTEGER (from 1) (optional): the move to forget when it knows four. +// or_forget WORDS (optional): the moves to forget, in order, when it +// doesn't know `forget`'s. inline const std::string TEACH_ACTION = "teach"; // `plan` as its action's args. Pokemon::StoryActionArgs teach_args(const TeachPlan& plan); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach_Tests.cpp index 5445302ee2..293ceb2f2e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach_Tests.cpp @@ -375,6 +375,43 @@ UnitTestResult test_tm_used_up(){ } +// 10.01's Fly: the Pidgey found by its summary's species wherever it +// stands (here fourth, an Eevee after it), Whirlwind read among its moves +// and forgotten. A species no member reads as teaches no one. +UnitTestResult test_teach_by_species(){ + QuietLogger logger; + FakeTeachGame game = console_b_party(); + game.party.push_back({"pidgey", {"sand-attack", "gust", "quick-attack", "whirlwind"}, {"fly"}}); + game.party.push_back({"eevee", {"tackle", "tail-whip", "helping-hand", "sand-attack"}, {}}); + game.tm_case["hm02"] = {"fly", 1}; + const TeachPlan fly{.item = "hm02", .move = "fly", .species = "pidgey", .forget_move = "whirlwind"}; + const TeachResult taught = run_teach(logger, game, reader_of(game), fly); + const std::vector expected{"sand-attack", "gust", "quick-attack", "fly"}; + if (taught.end != TeachEnd::LEARNED || taught.forgot != "whirlwind" || game.party[3].moves != expected || !game.error.empty()){ + return std::format("Fly by species: ended {} ({}), forgot \"{}\".", teach_end_name(taught.end), taught.detail, taught.forgot); + } + const size_t opened = game.items_opened; + const TeachResult missing = run_teach(logger, game, reader_of(game), {.item = "hm02", .move = "fly", .species = "spearow"}); + if (missing.end != TeachEnd::UNREAD || game.items_opened != opened){ + return std::format("No Spearow in the party: ended {}, expected unread with the bag shut.", teach_end_name(missing.end)); + } + // No Whirlwind (a Pidgey that declined it at 19): Sand-Attack, the + // plan's next choice, goes, which leaves pokeguy's moveset. + game.party[3].moves = {"sand-attack", "gust", "quick-attack", "steel-wing"}; + TeachPlan or_else = fly; + or_else.forget_else = {"sand-attack"}; + const TeachResult fallback = run_teach(logger, game, reader_of(game), or_else); + const std::vector pokeguys{"fly", "gust", "quick-attack", "steel-wing"}; + if (fallback.end != TeachEnd::LEARNED || fallback.forgot != "sand-attack" || game.party[3].moves != pokeguys){ + return std::format("Fly, no Whirlwind: ended {} ({}), forgot \"{}\".", teach_end_name(fallback.end), fallback.detail, fallback.forgot); + } + const std::optional back = teach_plan_of(teach_args(or_else)); + if (!back || back->forget_else != or_else.forget_else){ + return "or_forget didn't read back from its args."; + } + return true; +} + UnitTestResult test_teach_args(){ const TeachPlan plan{.item = "hm03", .move = "surf", .member = 0, .forget_move = "tail-whip"}; const Pokemon::StoryActionArgs args = teach_args(plan); @@ -392,6 +429,16 @@ UnitTestResult test_teach_args(){ if (!tutor || tutor->item != TEACH_TUTOR || tutor->move != "mega-kick" || tutor->forget_move != "withdraw"){ return "The tutor's Mega Kick didn't read back from its args."; } + const std::optional by_species = teach_plan_of(teach_args({.item = "hm02", .move = "fly", .species = "pidgey", .forget_move = "whirlwind"})); + if (!by_species || by_species->species != "pidgey" || by_species->forget_move != "whirlwind"){ + return "Fly to the Pidgey by species didn't read back from its args."; + } + if (teach_plan_of({{"item", std::string("hm02")}, {"move", std::string("fly")}}) + || teach_plan_of({{"item", std::string("hm02")}, {"move", std::string("fly")}, {"slot", int64_t(3)}, {"species", std::string("pidgey")}}) + || teach_plan_of({{"item", std::string("hm02")}, {"move", std::string("fly")}, {"species", std::string("")}}) + ){ + return "Expected exactly one of slot and species."; + } const std::vector> bad_args{ {"item", std::string("potion")}, {"item", std::string("tutors")}, @@ -425,6 +472,10 @@ const AutoStoryTeachCase AUTO_STORY_TEACH_CASES[] = { .input = {"the step's args", test_teach_args}, .expectation = {}, }, + { + .input = {"Fly to the Pidgey found by species", test_teach_by_species}, + .expectation = {}, + }, }; void add_tests_AutoStoryTeach(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTower_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTower_Tests.cpp new file mode 100644 index 0000000000..36feefef88 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTower_Tests.cpp @@ -0,0 +1,419 @@ +/* AutoStory Tower Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Rows 10.01 to 10.06 on the overworld sim: from the Eevee's room in + * Celadon Mansion (09.04) by the Department Store's lift to its 5F's X + * items, to Route 16's house for HM02 and a Fly to Lavender Town, up + * the Pokemon Tower past the rival, its Channelers, the Marowak ghost and + * the three Grunts to Mr. Fuji, and the POKE FLUTE in his house. Each row + * fights only the trainers it plans to (the chain from row to row is + * PokemonFRLG_AutoStory_Tests.cpp's). + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_HideoutLiftRoom.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldObjects.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryFieldMoves.h" +#include "PokemonFRLG_AutoStoryLegs.h" +#include "PokemonFRLG_AutoStoryMember.h" +#include "PokemonFRLG_AutoStoryMemberInfo.h" +#include "PokemonFRLG_AutoStoryPacedRoute.h" +#include "PokemonFRLG_AutoStoryRowSim.h" +#include "PokemonFRLG_AutoStoryRows_Tests.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +struct AutoStoryTowerInput{ + std::string name; + std::function body; +}; + +struct AutoStoryTowerExpectation{ +}; + +struct AutoStoryTowerCase{ + AutoStoryTowerInput input; + AutoStoryTowerExpectation expectation; +}; + +class Test_AutoStoryTower : public UnitTest{ +public: + explicit Test_AutoStoryTower(AutoStoryTowerCase test_case) + : UnitTest(std::format("PokemonFRLG::AutoStory - Simulation: {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::format("{}: {}", e.name(), e.message()); + } + } + +private: + AutoStoryTowerCase m_case; +}; + +const StoryCheckpoint& checkpoint(std::string_view id){ + const std::vector& rows = story_checkpoints(); + const auto row = std::find_if(rows.begin(), rows.end(), [&](const StoryCheckpoint& data){ return data.id == id; }); + if (row == rows.end()){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No checkpoint {}.", id)); + } + return *row; +} + +// A trainer the story has beaten before the row: still standing where +// the map puts it, but no longer looking for the player. +struct Beaten{ + std::string map; + int x = 0; + int y = 0; +}; + +// The maps as the story leaves them by 10.01: the story's flags, as for +// the rows before (maps_after_route10()), and `beaten` sees no one. +std::vector maps_with_beaten(const std::vector& beaten){ + const std::vector all = overworld_maps(); + std::set flags = map_flag_set(all, "after_hall_of_fame"); + flags.merge(map_flag_set(all, "new_game")); + flags.erase("FLAG_HIDE_VERMILION_CITY_OAKS_AIDE"); + std::vector maps = overworld_maps(flags); + maps.push_back(department_store_lift_room()); + for (MapData& map : maps){ + for (MapObject& object : map.objects){ + const bool hit = std::any_of(beaten.begin(), beaten.end(), [&](const Beaten& trainer){ + return trainer.map == map.name && trainer.x == object.x && trainer.y == object.y; + }); + if (hit){ + object.trainer.reset(); + } + } + } + return maps; +} + +// A step the sim can't play but the table says the end of: the rival's +// and the Marowak's scripted battles, which no trainer of the sim's +// starts, and a talk whose script warps the player (Mr. Fuji's). +bool scripted(const StoryStep& step){ + if (step.kind == StoryStepKind::TALK){ + return step.pose_after.has_value(); + } + if (step.kind != StoryStepKind::BATTLE){ + return false; + } + const std::string& trainer = Pokemon::story_arg(step.args, "trainer"); + return trainer.empty() || trainer.starts_with("TRAINER_RIVAL_"); +} + +struct RowRun{ + std::string failure; + std::vector fought; + MapPosition end; +}; + +// Row `id` on the sim from its start on `maps`: each step played, or for +// a scripted one, the sim started again where the table says it ends. +RowRun run_row(std::string_view id, std::vector maps){ + const StoryCheckpoint& row = checkpoint(id); + StoryPose at = *story_pose(Pokemon::pose_of(*row.start)); + // The Department Store's lift (10.01): its room and its floors. + SimScript script; + script.lift_floors[std::string(DEPT_STORE_LIFT_MAP)] = department_store_lift_exits(); + auto sim = std::make_unique(maps, MapPosition{at.map, at.tile}, *at.facing, script); + RowRun run; + for (const StoryStep& step : row.steps){ + if (scripted(step)){ + at = *story_pose(Pokemon::pose_of(*step.pose_after)); + run.fought.insert(run.fought.end(), sim->state().trainers_beaten.begin(), sim->state().trainers_beaten.end()); + if (!sim->state().violations.empty()){ + run.failure = std::format("{}: a violation before {}: {}", id, step.name, sim->state().violations.back()); + return run; + } + sim = std::make_unique(maps, MapPosition{at.map, at.tile}, *at.facing, script); + continue; + } + if (const std::string failure = row_step_on_sim(*sim, at, step, row.id); !failure.empty()){ + run.failure = std::format("{}: ended on {}; {}", id, to_string(sim->state().position), failure); + return run; + } + } + run.fought.insert(run.fought.end(), sim->state().trainers_beaten.begin(), sim->state().trainers_beaten.end()); + if (!sim->state().violations.empty()){ + run.failure = std::format("{}: a violation on the way: {}", id, sim->state().violations.back()); + } + run.end = sim->state().position; + return run; +} + +// Row `id` ends on `end`, having fought `fought` (the sim's object names) +// in order and no one else. +UnitTestResult row_checked( + std::string_view id, const std::vector& beaten, const std::vector& fought, const MapPosition& end +){ + const RowRun run = run_row(id, maps_with_beaten(beaten)); + if (!run.failure.empty()){ + return run.failure; + } + if (run.fought != fought){ + std::string names; + for (const std::string& name : run.fought){ + names += std::format(" {}", name); + } + return std::format("{}: fought{} on the sim, not the {} planned.", id, names.empty() ? " no one" : names, fought.size()); + } + if (!(run.end == end)){ + return std::format("{}: ended on {}, not {}.", id, to_string(run.end), to_string(end)); + } + return true; +} + +// 10.01: the Department Store's lift up to the X items clerk on 5F and +// back down, Celadon City past Route 16's Cut tree to the house with +// HM02, out of Lea's and Jed's lines, then a Fly to Lavender's Center. +UnitTestResult test_back_to_lavender(Logger&){ + return row_checked("10.01", {}, {}, MapPosition{"LavenderTown_PokemonCenter_1F", {7, 4}}); +} + +// 10.02: the Tower's door, 1F, and 2F to east of the rival's trigger. +UnitTestResult test_tower_to_rival(Logger&){ + return row_checked("10.02", {}, {}, MapPosition{"PokemonTower_2F", {17, 6}}); +} + +// 10.03: the step onto the trigger below the rival; his battle is the +// script's. +UnitTestResult test_tower_rival(Logger&){ + return row_checked("10.03", {}, {}, MapPosition{"PokemonTower_2F", {16, 6}}); +} + +// 10.04: 3F and 4F out of every Channeler's line, Ruth and Tammy fought +// on 5F. +UnitTestResult test_tower_3f_to_5f(Logger&){ + return row_checked("10.04", {}, {"channeler", "channeler"}, MapPosition{"PokemonTower_5F", {18, 7}}); +} + +// 10.05: from beside Tammy, beaten, down to 6F: Jennifer and Emilia +// fought, Angelica walked round, the Rare Candy, the Marowak's trigger. +UnitTestResult test_tower_6f(Logger&){ + return row_checked( + "10.05", {{"PokemonTower_5F", 19, 7}}, {"channeler", "channeler"}, MapPosition{"PokemonTower_6F", {11, 15}} + ); +} + +// 10.05 above_tower_rare_candy (console B, 2026-11-12 04:39): from +// Pokemon Tower 6F (9, 8), after Emilia, "west 4 (open)" and "south 6 +// (open)" to (5, 14), above the Rare Candy (5, 15), walked as holds. The +// west one ended on (4, 8), the south one met the gravestone (4, 9), and +// the A faced nothing. An approach to an A press is walked a tap a tile +// from the tile Emilia's battle leaves the player on, so a hold that ends +// a tile short or long (here: short, both legs) can't leave it off. +UnitTestResult test_rare_candy_approach_exact(Logger&){ + const StoryCheckpoint& row = checkpoint("10.05"); + const auto step = std::find_if(row.steps.begin(), row.steps.end(), [](const StoryStep& data){ return data.name == "above_tower_rare_candy"; }); + if (step == row.steps.end()){ + return std::string("10.05 has no above_tower_rare_candy."); + } + const MapPosition start{"PokemonTower_6F", {9, 8}}; + const MapPosition above{"PokemonTower_6F", {5, 14}}; + SimScript script; + script.short_holds = {{1, 1}, {2, 1}}; + OverworldSim sim(maps_with_beaten({{"PokemonTower_6F", 9, 6}}), start, Direction::WEST, script); + StoryPose at{start.map, start.point, Direction::WEST}; + if (const std::string failure = row_step_on_sim(sim, at, *step, row.id); !failure.empty()){ + return std::format("10.05 above_tower_rare_candy: {}", failure); + } + if (!(sim.state().position == above)){ + return std::format("10.05 above_tower_rare_candy: ended on {}, not {}.", to_string(sim.state().position), to_string(above)); + } + return true; +} + +// 10.06: the three Grunts up column 11, Mr. Fuji, and his house. +UnitTestResult test_tower_7f_and_fuji(Logger&){ + return row_checked( + "10.06", {}, {"rocket_m", "rocket_m", "rocket_m"}, MapPosition{"LavenderTown_VolunteerPokemonHouse", {3, 4}} + ); +} + +// Battle checkpoint `id`'s precondition: a LEVEL step on the lead before +// its battle `battle`, at least `pokeguy`, pokeguy's level there (whose +// sims stand for the fight at that level or above). A lead at that level +// passes it; one a level below stops the checkpoint before the fight. +UnitTestResult check_lead_level_precondition(Logger& logger, std::string_view id, std::string_view battle, unsigned pokeguy){ + std::optional check; + for (const StoryStep& step : checkpoint(id).steps){ + if (step.kind == StoryStepKind::BATTLE && step.name == battle){ + break; + } + if (step.action == LEVEL_ACTION){ + check = level_check_of(step.args); + } + } + if (!check || check->slot != 0 || check->level != pokeguy){ + return std::format("{}: expected a LEVEL step on the lead, at least Lv{}, before {}.", id, pokeguy, battle); + } + for (const unsigned level : {pokeguy, pokeguy - 1}){ + const MemberReader lead = [level](size_t slot) -> std::optional{ + if (slot != 0){ + return std::nullopt; + } + return MemberInfo{.species = "blastoise", .level = level}; + }; + const LevelResult result = run_level_check(logger, lead, *check); + const LevelEnd expected = level >= pokeguy ? LevelEnd::REACHED : LevelEnd::BELOW; + if (result.end != expected || result.level != level){ + return std::format("{}: a Lv{} lead {} the Lv{} check.", id, level, level >= pokeguy ? "fails" : "passes", pokeguy); + } + } + return true; +} + +// 10.01's Fly names the Pidgey, not a slot, and flies with the slot the +// party reads it in: the third with the Oddish and the Eevee, the second +// without the Oddish, none without a Pidgey. +UnitTestResult test_fly_finds_pidgey(Logger&){ + const StoryCheckpoint& row = checkpoint("10.01"); + const auto fly = std::find_if(row.steps.begin(), row.steps.end(), [](const StoryStep& step){ + return parse_fly_step(step).has_value(); + }); + if (fly == row.steps.end() || parse_fly_step(*fly)->species != "pidgey" || fly->args.contains("slot")){ + return std::string("10.01: expected a Fly by the Pidgey's species, with no slot."); + } + const FlyPlan plan = *parse_fly_step(*fly); + const auto party = [](std::vector species){ + return MemberReader([species](size_t slot) -> std::optional{ + if (slot >= species.size()){ + return std::nullopt; + } + return MemberInfo{.species = species[slot], .level = 30}; + }); + }; + if (plan.party_slot(party({"blastoise", "oddish", "pidgey", "eevee"})) != size_t(2) + || plan.party_slot(party({"blastoise", "pidgey"})) != size_t(1) + || plan.party_slot(party({"blastoise", "oddish"})).has_value() + ){ + return std::string("10.01: the Fly doesn't find the Pidgey's slot as the party reads it."); + } + return true; +} + +// 10.01 below_fly_woman from east of Route 16's north gate on the +// Bicycle, which the gate's warps leave the rider on (allow_cycling): the +// open leg west to the Fly house's door must be walked at the Bicycle's +// pace, or it overshoots the door (console B, 2026-11-12 01:05: a +// run-paced west 10 ended four tiles past the door, and north bumped the +// fence). +UnitTestResult test_fly_house_door_on_bike(Logger& logger){ + const StoryCheckpoint& row = checkpoint("10.01"); + const auto step = std::find_if(row.steps.begin(), row.steps.end(), [](const StoryStep& data){ + return data.name == "below_fly_woman"; + }); + if (step == row.steps.end()){ + return std::string("10.01: no below_fly_woman."); + } + SimScript script; + script.on_bike = true; + script.bike_registered = true; + OverworldSim sim(maps_with_beaten({}), MapPosition{"Route16", {28, 6}}, Direction::WEST, script); + StoryPose at{"Route16", {28, 6}, Direction::WEST}; + const std::string failure = row_step_on_sim(sim, at, *step, "10.01"); + for (const std::string& line : sim.state().log){ + logger.log(line); + } + if (!failure.empty()){ + return failure; + } + const MapPosition end{"Route16_House", {4, 4}}; + if (!(sim.state().position == end)){ + return std::format("10.01 below_fly_woman: ended on {}, not {}.", to_string(sim.state().position), to_string(end)); + } + return true; +} + +// The step a press makes off a warp, ending where the game leaves the +// player and facing the way it turns them (arrival_facing()), not the way +// the press went. 10.01 below_store_lift comes down from the roof room on +// Celadon Mansion's 2F stairs (4, 2), taken east, to 1F's (4, 2), where +// the player faces west (console B, 2026-11-11 23:40). Out of Mt. Moon +// B1F's north exit, the game walks the player south out of Route 4's cave +// entrance (32, 5). +UnitTestResult test_warp_press_arrivals(Logger&){ + const struct{ + MapPosition from; + Direction press; + MapPosition end; + Direction facing; + } CASES[] = { + {{"CeladonCity_Condominiums_2F", {4, 2}}, Direction::EAST, {"CeladonCity_Condominiums_1F", {4, 2}}, Direction::WEST}, + {{"MtMoon_B1F", {45, 5}}, Direction::NORTH, {"Route4", {32, 6}}, Direction::SOUTH}, + }; + for (const auto& c : CASES){ + const std::optional step = warp_press(story_maps(), c.from, c.press); + if (!step){ + return std::format("A press {} from {}: no warp taken.", direction_name(c.press), to_string(c.from)); + } + if (!(step->end == c.end) || step->facing_after != c.facing){ + return std::format( + "A press {} from {}: ends on {} facing {}, expected {} facing {}.", + direction_name(c.press), to_string(c.from), to_string(step->end), direction_name(step->facing_after), + to_string(c.end), direction_name(c.facing) + ); + } + } + return true; +} + +const AutoStoryTowerCase AUTO_STORY_TOWER_CASES[] = { + { + .input = {.name = "10.05: the Rare Candy's approach ends above it after short holds", .body = test_rare_candy_approach_exact}, + .expectation = {}, + }, + {.input = {"10.01 Route 16's house for HM02, out of every line, and Fly to Lavender's Pokemon Center", test_back_to_lavender}, .expectation = {}}, + {.input = {"10.01 flies with the Pidgey found by species", test_fly_finds_pidgey}, .expectation = {}}, + {.input = {"10.01 on the Bicycle through Route 16's north gate to the Fly house's door", test_fly_house_door_on_bike}, .expectation = {}}, + {.input = {"10.01 a press off Celadon Mansion's 2F stairs arrives on 1F facing west", test_warp_press_arrivals}, .expectation = {}}, + {.input = {"10.02 the Pokemon Tower's 1F and 2F to east of the rival's trigger", test_tower_to_rival}, .expectation = {}}, + {.input = {"10.03 onto the rival's trigger", test_tower_rival}, .expectation = {}}, + {.input = {"10.04 the Tower's 3F to 5F, Ruth and Tammy alone fought", test_tower_3f_to_5f}, .expectation = {}}, + {.input = {"10.05 the Tower's 6F, Jennifer and Emilia alone fought, to the Marowak's trigger", test_tower_6f}, .expectation = {}}, + {.input = {"10.06 the Tower's 7F Grunts, Mr. Fuji and his house", test_tower_7f_and_fuji}, .expectation = {}}, + {.input = {"10.03 stops before the Tower rival unless the lead is at least pokeguy's Lv36", [](Logger& logger){ return check_lead_level_precondition(logger, "10.03", "rival_tower", 36); }}, .expectation = {}}, +}; + +} // namespace + + +void add_tests_AutoStoryTower(UnitTestDatabase& database){ + for (const auto& item : AUTO_STORY_TOWER_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 0a5f768539..2b85a7172e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -25,13 +25,17 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldTileRules.h" #include "PokemonFRLG_AutoStoryLegs.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryCapture.h" #include "PokemonFRLG_AutoStoryGenderMenu.h" +#include "PokemonFRLG_AutoStoryBag.h" #include "PokemonFRLG_AutoStoryGrind.h" +#include "PokemonFRLG_AutoStoryItemUse.h" #include "PokemonFRLG_AutoStoryPcStorage.h" #include "PokemonFRLG_AutoStoryPlanGolden.h" +#include "PokemonFRLG_AutoStoryPlanGolden10.h" #include "PokemonFRLG_AutoStoryMoveData.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -278,8 +282,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po // before leaves the player, and adds the plans to `golden`. UnitTestResult chain_story_routes(std::vector& golden){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 39 || checkpoints[0].start){ - return "Expected 39 checkpoints, the first from a new game."; + if (checkpoints.size() != 47 || checkpoints[0].start){ + return "Expected 47 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ @@ -308,17 +312,20 @@ UnitTestResult test_routes_and_chain(){ // Every story route's plan against the stored copy in // PokemonFRLG_AutoStoryPlanGolden.h. A change that should not alter any // plan must leave this byte-identical. To regenerate after an intended plan -// change: run this suite, and replace the lines of FRLG_PLAN_GOLDEN with -// the lines the failure lists after "GOLDEN|". +// change: run this suite, and replace the lines of FRLG_PLAN_GOLDEN and +// FRLG_PLAN_GOLDEN_10 (segment 10 on) with the lines the failure lists +// after "GOLDEN|". UnitTestResult test_golden_plans(){ std::vector actual; UnitTestResult result = chain_story_routes(actual); if (result.result != UnitTestResult::PASSED){ return result; } - const size_t stored = sizeof(FRLG_PLAN_GOLDEN) / sizeof(FRLG_PLAN_GOLDEN[0]); + std::vector golden(std::begin(FRLG_PLAN_GOLDEN), std::end(FRLG_PLAN_GOLDEN)); + golden.insert(golden.end(), std::begin(FRLG_PLAN_GOLDEN_10), std::end(FRLG_PLAN_GOLDEN_10)); + const size_t stored = golden.size(); size_t first_diff = 0; - while (first_diff < actual.size() && first_diff < stored && actual[first_diff] == FRLG_PLAN_GOLDEN[first_diff]){ + while (first_diff < actual.size() && first_diff < stored && actual[first_diff] == golden[first_diff]){ first_diff++; } if (first_diff == actual.size() && first_diff == stored){ @@ -327,7 +334,7 @@ UnitTestResult test_golden_plans(){ std::string message = std::format("plans differ from the golden at line {} ({} lines now, {} stored): now \"{}\", stored \"{}\". Now:", first_diff + 1, actual.size(), stored, first_diff < actual.size() ? std::string_view(actual[first_diff]) : std::string_view(), - first_diff < stored ? FRLG_PLAN_GOLDEN[first_diff] : std::string_view()); + first_diff < stored ? golden[first_diff] : std::string_view()); for (const std::string& line : actual){ message += std::format("\nGOLDEN|{}", line); } @@ -646,11 +653,16 @@ UnitTestResult advance(StoryPose& pose, const StoryStep& step){ // `checkpoint`'s routes and legs keep to tiles with no tile_problem(); a // step into a trainer's line is followed by the battle, which beats them. -UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set& beaten){ +// `repelled`: a Repel the table used is on (it lasts past the +// checkpoint's save): grass is walked as any floor. +UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set& beaten, bool& repelled){ StoryPose pose = one_tile(Pokemon::grid_pose_of(*checkpoint.start)); for (size_t c = 0; c < checkpoint.steps.size(); c++){ const StoryStep& step = checkpoint.steps[c]; const std::string where = checkpoint.id + "/" + step.name + ": "; + if (step.action == USE_ITEM_VARIANT && is_repel(Pokemon::story_arg(step.args, "item"))){ + repelled = true; + } const bool walks = step.kind == StoryStepKind::ROUTE || step.kind == StoryStepKind::LEGS; // A GRIND's or a capture's patch is grass: the route there may end on it. const bool to_patch = step.args.contains("target") && c + 1 < checkpoint.steps.size() @@ -658,7 +670,7 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set{}){ const StoryPose end = to_patch ? one_tile(Pokemon::story_arg(step.args, "target")) : StoryPose{}; const bool patch = to_patch && tile.map == end.map && tile.point == end.tile; - if (const std::string problem = tile_problem(tile, beaten); !problem.empty() && !((patch || grass_held(pose, step)) && problem.starts_with("in the grass"))){ + if (const std::string problem = tile_problem(tile, beaten); !problem.empty() && !((patch || repelled || grass_held(pose, step)) && problem.starts_with("in the grass"))){ return where + problem; } } @@ -685,27 +697,213 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set& legs){ + bool known = true; + for (const RouteStep& leg : legs){ + if (leg.action == RouteAction::FACE){ + continue; + } + const MapData* map = find_map_named(leg.end.map); + const std::optional taken = map ? exit_mat(*map, leg.end.point) : std::nullopt; + if (taken && leg.direction != *taken && !leg.warps && !leg.to_wall && !(leg.tapped && known)){ + return std::format( + "ends on {}, whose warp is taken going {}, going {}, not to a wall and not tapped from a known tile.", + to_string(leg.end), direction_name(*taken), direction_name(leg.direction) + ); + } + known = leg.to_wall || leg.warps || leg.tapped; + } + return ""; +} +UnitTestResult test_legs_onto_stairs_their_way(){ + const std::set PASSED_ON_CONSOLE{"09.01/b4f_to_stairs"}; + bool has_shoes = false; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + const bool walked = has_shoes; + has_shoes = has_shoes || checkpoint.id == "03.03"; + if (!walked){ + continue; + } + StoryPose pose = one_tile(Pokemon::grid_pose_of(*checkpoint.start)); + for (const StoryStep& step : checkpoint.steps){ + if (step.kind == StoryStepKind::ROUTE){ + if (const std::string problem = planned_onto_stairs_sideways(legs_walked(pose, step)); !problem.empty()){ + return std::format("{}/{}: {}", checkpoint.id, step.name, problem); + } + } + const std::vector legs = step.kind == StoryStepKind::LEGS ? legs_walked(pose, step) : std::vector{}; + if (!legs.empty() && !legs.back().warps){ + const MapData* map = find_map_named(legs.back().end.map); + const std::optional taken = map ? exit_mat(*map, legs.back().end.point) : std::nullopt; + if (taken && legs.back().direction != *taken && !legs.back().to_wall && !PASSED_ON_CONSOLE.contains(checkpoint.id + "/" + step.name)){ + return std::format( + "{}/{}: ends on {}, whose warp is taken going {}, going {} and not to a wall.", + checkpoint.id, step.name, to_string(legs.back().end), direction_name(*taken), direction_name(legs.back().direction) + ); + } + } + if (UnitTestResult result = advance(pose, step); result.result != UnitTestResult::PASSED){ + return checkpoint.id + " " + result.message; + } + } + } + return true; +} + +// Whether `legs`, walked from a tile the walk knows, end on their planned +// tile, or why not. A leg to a wall or a spinner's stop finds the player +// along its way, a warp finds them on both, a tapped or one-tile leg +// keeps what was found, and a held open leg loses its way: it can end a +// tile short or long. +std::string approach_off_tile(const std::vector& legs){ + bool x_known = true; + bool y_known = true; + for (const RouteStep& leg : legs){ + if (leg.action == RouteAction::FACE){ + continue; + } + bool& along = leg.direction == Direction::EAST || leg.direction == Direction::WEST ? x_known : y_known; + if (leg.warps){ + x_known = true; + y_known = true; + }else if (leg.to_wall || leg.spin_tiles){ + along = true; + }else if (!leg.tapped && leg.tiles != 1){ + along = false; + } + } + if (x_known && y_known){ + return ""; + } + return std::format( + "ends on {} after {}, a held open leg not found again by a wall, a warp or a tap.", + legs.empty() ? std::string("?") : to_string(legs.back().end), legs.empty() ? std::string("?") : to_string(legs.back()) + ); +} + +// The walk before an A press (a TALK: a person, an item, a sign) ends on +// its tile: tapped from a tile the walk knows, or against a wall. 10.05's +// approach to the Rare Candy, "west 4" and "south 6" held open, ended a +// tile west and met a gravestone (console B, 2026-11-12 04:39). +// PASSED_ON_CONSOLE: approaches before 10.05 that passed their console +// runs as held legs (a follow-up to tap them). +UnitTestResult test_approaches_end_on_their_tile(){ + const std::set PASSED_ON_CONSOLE{ + "02.02/below_oak", "03.02/before_brock", "05.07/below_bill_clefairy", "05.07/pc_front", + "05.07/beside_bill", "06.01/behind_captain", "07.01/beside_chairman", "07.01/bike_clerk", + "09.01/below_poster_guard", "09.02/below_left_guard", "09.03/above_tea_woman", "10.01/below_fly_woman", + }; + std::string wrong; + size_t count = 0; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + const std::optional start = checkpoint.start ? story_pose(Pokemon::pose_of(Pokemon::grid_pose_of(*checkpoint.start))) : std::nullopt; + if (!start){ + continue; + } + StoryPose pose = *start; + // The legs of the ROUTE and LEGS steps since the last other step. + std::vector approach; + for (size_t c = 0; c < checkpoint.steps.size(); c++){ + const StoryStep& step = checkpoint.steps[c]; + const std::string where = c > 0 ? checkpoint.id + "/" + checkpoint.steps[c - 1].name : ""; + if (step.kind == StoryStepKind::ROUTE || step.kind == StoryStepKind::LEGS){ + for (RouteStep leg : legs_walked(pose, step)){ + leg.tapped |= step.action == TAPS_VARIANT; + approach.push_back(leg); + } + }else if (step.kind == StoryStepKind::TALK && !approach.empty() && !PASSED_ON_CONSOLE.contains(where)){ + if (const std::string problem = approach_off_tile(approach); !problem.empty()){ + count++; + wrong += "\n " + where + ": " + problem; + } + approach.clear(); + }else{ + approach.clear(); + } + if (UnitTestResult result = advance(pose, step); result.result != UnitTestResult::PASSED){ + return checkpoint.id + " " + result.message; + } + } + } + if (count > 0){ + return std::format("{} approaches to an A press may end off their tile:{}", count, wrong); + } + return true; +} + +// A trainer's battle leaves the player facing the way they stepped into +// its line or waited in it: the game doesn't turn the player to the +// trainer (pokefirered src/trainer_see.c, TrainerSeeFunc_PrepareToEngage, +// the turn commented out). 10.05's facing declared after Emilia was the +// way to her, and the walk's turn tap took a step (console B, 2026-11-12 +// 04:39). Lists every battle after a trainer_line or trainer_wait step +// whose declared facing is another. +UnitTestResult test_facing_after_trainer_battles(){ + std::string wrong; + size_t count = 0; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + const std::optional start = checkpoint.start ? story_pose(Pokemon::pose_of(Pokemon::grid_pose_of(*checkpoint.start))) : std::nullopt; + if (!start){ + continue; + } + StoryPose pose = *start; + for (size_t c = 0; c < checkpoint.steps.size(); c++){ + const StoryStep& step = checkpoint.steps[c]; + const bool after_line = c > 0 && (checkpoint.steps[c - 1].action == TRAINER_LINE_VARIANT || checkpoint.steps[c - 1].action == TRAINER_WAIT_VARIANT); + if (step.kind == StoryStepKind::BATTLE && after_line && step.pose_after){ + const std::optional declared = one_tile(Pokemon::grid_pose_of(*step.pose_after)).facing; + if (declared != pose.facing){ + count++; + wrong += std::format("\n {}/{}: declared {}, faces {}", checkpoint.id, step.name, describe(one_tile(Pokemon::grid_pose_of(*step.pose_after))), describe(pose)); + } + } + if (UnitTestResult result = advance(pose, step); result.result != UnitTestResult::PASSED){ + return checkpoint.id + " " + result.message; + } + } + } + if (count > 0){ + return std::format("{} battles declare a facing the trainer didn't leave:{}", count, wrong); + } + return true; +} + UnitTestResult test_trainer_lines(){ std::set beaten; bool has_shoes = false; + bool repelled = false; for (const StoryCheckpoint& checkpoint : story_checkpoints()){ if (has_shoes){ - if (UnitTestResult result = check_lines(checkpoint, beaten); result.result != UnitTestResult::PASSED){ + if (UnitTestResult result = check_lines(checkpoint, beaten, repelled); result.result != UnitTestResult::PASSED){ return result; } } has_shoes = has_shoes || checkpoint.id == "03.03"; } - if (beaten.size() != 30){ + if (beaten.size() != 37){ return "Expected to fight Colton, Greg and James on Route 3, the Grunt at (12, 20) in Mt. Moon, Nugget Bridge's five" ", Franklin, Kelsey, Nob and Haley on Route 25, Jeff on Route 6, Dwayne, Baily and Tucker in Vermilion Gym, Alicia, Jeremy and Conner on Route 9" - ", Ashton, Winston, Martha, Allen, Lenny, Sofia, Dudley and Dana in Rock Tunnel, Rich on Route 8 and the Lift Key Grunt on B4F; the table fights " + ", Ashton, Winston, Martha, Allen, Lenny, Sofia, Dudley and Dana in Rock Tunnel, Rich on Route 8, the Lift Key Grunt on B4F, Ruth, Tammy, Jennifer and Emilia and the three Grunts in the Pokemon Tower; the table fights " + std::to_string(beaten.size()) + " trainers."; } return true; @@ -948,7 +1146,8 @@ UnitTestResult test_lint(){ } // Every battle step in the table names its trainer and that trainer's -// party, each species one the battle data has. +// party, each species one the battle data has. A scripted wild battle +// (the Pokemon Tower's Marowak) names no trainer and its one foe. UnitTestResult test_story_trainers(){ size_t battles = 0; for (const StoryCheckpoint& checkpoint : story_checkpoints()){ @@ -959,7 +1158,7 @@ UnitTestResult test_story_trainers(){ battles++; const std::string& trainer = Pokemon::story_arg(step.args, "trainer"); const std::vector& foes = Pokemon::story_arg>(step.args, "foes"); - if (trainer.empty() || foes.empty()){ + if (foes.empty() || (trainer.empty() && foes.size() != 1)){ return std::format("{}, {}: no trainer or no foes.", checkpoint.id, step.name); } for (const std::string& foe : foes){ @@ -1165,6 +1364,18 @@ const AutoStoryTestCase AUTO_STORY_CASES[] = { .input = {.name = "options: RIGHT presses from the shown value", .body = test_option_presses}, .expectation = {.description = "calculates Dpad RIGHT inputs for setting game options"}, }, + { + .input = {.name = "legs and routes onto stairs step onto them the way their warp is taken, or tap", .body = test_legs_onto_stairs_their_way}, + .expectation = {.description = "legs that end on side stairs or an exit mat end going the warp's way"}, + }, + { + .input = {.name = "the walk before an A press ends on its tile", .body = test_approaches_end_on_their_tile}, + .expectation = {.description = "approaches to talks, items and signs end at a wall, a warp or taps from a known tile"}, + }, + { + .input = {.name = "a trainer's battle leaves the player facing the way they stepped into its line", .body = test_facing_after_trainer_battles}, + .expectation = {.description = "declared facings after trainer battles match pokefirered trainer_see.c"}, + }, { .input = {.name = "Route 3: only the planned trainers' lines", .body = test_trainer_lines}, .expectation = {.description = "verifies route 3 trainer interaction sightlines"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-06.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-06.02.plan.json index cefb1b1ba6..cb8b4e4cd3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-06.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-06.02.plan.json @@ -82,7 +82,7 @@ "trainer": "TRAINER_SAILOR_DWAYNE", "foes": ["pikachu", "pikachu"] }, - "declared_after": {"map": "VermilionCity_Gym", "tiles": [[8, 15]], "facing": "north"}, + "declared_after": {"map": "VermilionCity_Gym", "tiles": [[8, 15]], "facing": "east"}, "why": "two Pikachu, Lv21" }, { @@ -110,7 +110,7 @@ "trainer": "TRAINER_ENGINEER_BAILY", "foes": ["voltorb", "magnemite"] }, - "declared_after": {"map": "VermilionCity_Gym", "tiles": [[2, 13]], "facing": "north"}, + "declared_after": {"map": "VermilionCity_Gym", "tiles": [[2, 13]], "facing": "west"}, "why": "Voltorb and Magnemite, Lv21" }, { @@ -138,7 +138,7 @@ "trainer": "TRAINER_GENTLEMAN_TUCKER", "foes": ["pikachu"] }, - "declared_after": {"map": "VermilionCity_Gym", "tiles": [[5, 8]], "facing": "east"}, + "declared_after": {"map": "VermilionCity_Gym", "tiles": [[5, 8]], "facing": "north"}, "why": "Pikachu, Lv23" }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-07.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-07.02.plan.json index ee98e4edab..72326f4f3c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-07.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-07.02.plan.json @@ -69,7 +69,7 @@ "trainer": "TRAINER_PICNICKER_ALICIA", "foes": ["oddish", "bellsprout", "oddish", "bellsprout"] }, - "declared_after": {"map": "Route9", "tiles": [[11, 10]], "facing": "east"}, + "declared_after": {"map": "Route9", "tiles": [[11, 10]], "facing": "south"}, "why": "Oddish, Bellsprout, Oddish and Bellsprout, Lv18" }, { @@ -106,7 +106,7 @@ "trainer": "TRAINER_HIKER_JEREMY", "foes": ["machop", "onix"] }, - "declared_after": {"map": "Route9", "tiles": [[20, 13]], "facing": "south"}, + "declared_after": {"map": "Route9", "tiles": [[20, 13]], "facing": "east"}, "why": "Machop and Onix, Lv20" }, { @@ -134,7 +134,7 @@ "trainer": "TRAINER_BUG_CATCHER_CONNER", "foes": ["caterpie", "weedle", "venonat"] }, - "declared_after": {"map": "Route9", "tiles": [[52, 7]], "facing": "west"}, + "declared_after": {"map": "Route9", "tiles": [[52, 7]], "facing": "north"}, "why": "Caterpie, Weedle and Venonat, Lv20" }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-08.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-08.01.plan.json index a132e16b38..b7153a03ce 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-08.01.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-08.01.plan.json @@ -77,7 +77,7 @@ "trainer": "TRAINER_POKEMANIAC_ASHTON", "foes": ["cubone", "slowpoke"] }, - "declared_after": {"map": "RockTunnel_1F", "tiles": [[24, 10]], "facing": "east"}, + "declared_after": {"map": "RockTunnel_1F", "tiles": [[24, 10]], "facing": "south"}, "why": "Slowpoke, Slowpoke and Slowpoke" }, { @@ -114,7 +114,7 @@ "trainer": "TRAINER_POKEMANIAC_WINSTON", "foes": ["slowpoke"] }, - "declared_after": {"map": "RockTunnel_B1F", "tiles": [[29, 37]], "facing": "north"}, + "declared_after": {"map": "RockTunnel_B1F", "tiles": [[29, 37]], "facing": "west"}, "why": "Slowpoke and Slowpoke" }, { @@ -142,7 +142,7 @@ "trainer": "TRAINER_PICNICKER_MARTHA", "foes": ["oddish", "bulbasaur"] }, - "declared_after": {"map": "RockTunnel_B1F", "tiles": [[16, 33]], "facing": "west"}, + "declared_after": {"map": "RockTunnel_B1F", "tiles": [[16, 33]], "facing": "north"}, "why": "Oddish and Bulbasaur" }, { @@ -170,7 +170,7 @@ "trainer": "TRAINER_HIKER_ALLEN", "foes": ["geodude"] }, - "declared_after": {"map": "RockTunnel_B1F", "tiles": [[36, 12]], "facing": "north"}, + "declared_after": {"map": "RockTunnel_B1F", "tiles": [[36, 12]], "facing": "west"}, "why": "Geodude, Geodude and Graveler" }, { @@ -216,7 +216,7 @@ "trainer": "TRAINER_HIKER_LENNY", "foes": ["geodude", "machop", "geodude", "geodude"] }, - "declared_after": {"map": "RockTunnel_1F", "tiles": [[7, 9]], "facing": "north"}, + "declared_after": {"map": "RockTunnel_1F", "tiles": [[7, 9]], "facing": "east"}, "why": "Machop and Onix" }, { @@ -262,7 +262,7 @@ "trainer": "TRAINER_PICNICKER_SOFIA", "foes": ["jigglypuff", "pidgey", "meowth"] }, - "declared_after": {"map": "RockTunnel_B1F", "tiles": [[11, 16]], "facing": "north"}, + "declared_after": {"map": "RockTunnel_B1F", "tiles": [[11, 16]], "facing": "west"}, "why": "Pidgey, Pidgey and Pidgeotto" }, { @@ -290,7 +290,7 @@ "trainer": "TRAINER_HIKER_DUDLEY", "foes": ["geodude", "geodude", "graveler"] }, - "declared_after": {"map": "RockTunnel_B1F", "tiles": [[5, 15]], "facing": "north"}, + "declared_after": {"map": "RockTunnel_B1F", "tiles": [[5, 15]], "facing": "west"}, "why": "Geodude, Geodude and Graveler" }, { @@ -336,7 +336,7 @@ "trainer": "TRAINER_PICNICKER_DANA", "foes": ["meowth", "oddish", "pidgey"] }, - "declared_after": {"map": "RockTunnel_1F", "tiles": [[26, 31]], "facing": "north"}, + "declared_after": {"map": "RockTunnel_1F", "tiles": [[26, 31]], "facing": "west"}, "why": "Meowth, Oddish and Pidgey" }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-08.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-08.03.plan.json index a85c5e67c7..14b7476935 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-08.03.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-08.03.plan.json @@ -109,7 +109,7 @@ "trainer": "TRAINER_GAMER_RICH", "foes": ["growlithe", "vulpix"] }, - "declared_after": {"map": "Route8", "tiles": [[55, 18]], "facing": "north"}, + "declared_after": {"map": "Route8", "tiles": [[55, 18]], "facing": "west"}, "why": "Gamer Rich (TRAINER_GAMER_RICH): Growlithe, Vulpix Lv24" }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.01.plan.json index a2b2434fd7..d55ff51ed7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.01.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.01.plan.json @@ -77,9 +77,9 @@ "kind": "route", "action": "run", "args": { - "target": {"map": "RocketHideout_B3F", "tiles": [[18, 2]], "facing": "east"} + "target": {"map": "RocketHideout_B3F", "tiles": [[18, 2]], "facing": "west"} }, - "why": "east off the stairs (21, 2) to B3F, onto its stairs (18, 2)" + "why": "east off the stairs (21, 2) to B3F, onto its stairs (18, 2), which leave the player facing west" }, { "id": "b3f_arrow_maze", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.02.plan.json index 9bdef21aa2..80faed81ae 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.02.plan.json @@ -29,9 +29,9 @@ "kind": "route", "action": "run", "args": { - "target": {"map": "RocketHideout_B2F", "tiles": [[21, 2]], "facing": "east"} + "target": {"map": "RocketHideout_B2F", "tiles": [[21, 2]], "facing": "west"} }, - "why": "east along row 2 onto the stairs (18, 2), up to B2F's (21, 2); no arrow on the way" + "why": "east along row 2 onto the stairs (18, 2), up to B2F's (21, 2), facing west off them; no arrow on the way" }, { "id": "b2f_arrows_to_moon_stone", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.03.plan.json new file mode 100644 index 0000000000..0a3b029260 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.03.plan.json @@ -0,0 +1,55 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "09.03", + "title": "Celadon Mansion: the TEA on 1F, then the roof room, saved facing the Eevee's ball", + "start": {"map": "CeladonCity", "tiles": [[34, 22]], "facing": "south"}, + "events": [ + { + "id": "above_tea_woman", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeladonCity_Condominiums_1F", "tiles": [[2, 8]], "facing": "south"} + }, + "why": "from outside the Game Corner in by Celadon Mansion's front door (30, 11) to above the old woman (2, 9), west of the Nidoran's zone (3..7, 7..9)" + }, + { + "id": "tea", + "kind": "talk", + "why": "the old woman gives the TEA (CeladonCity_Condominiums_1F_EventScript_TeaWoman, FLAG_GOT_TEA), for the Saffron gate guards (15.01)" + }, + { + "id": "facing_eevee_ball", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeladonCity_Condominiums_RoofRoom", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "out of the front door again and round to the back door (30, 4), whose part of 1F has the stairs: up 2F and 3F to the roof, down into the roof room at (2, 12), and below the Eevee's ball (7, 3)" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "handoff": "gift_rng", + "gift": "eevee", + "notes": { + "checkpoint": [ + "PokeGuy takes the TEA and the Eevee after the Rocket Hideout and before Route 16's house. Celadon Mansion (CeladonCity_Condominiums_* map.json): 1F's stairs (4, 2) or (12, 2) to 2F, 3F, and 3F's (4, 2) or (12, 2) up to the roof; the roof's door (2, 12) leads down into the roof room, whose Eevee's ball (7, 3) is CeladonCity_Condominiums_RoofRoom_EventScript_EeveeBall. 1F's Clefairy (4..6, 13) and Nidoran (3..7, 7..9) wander." + ], + "facing_eevee_ball": [ + "Gift RNG starts from a save facing the ball." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": {"map": "CeladonCity_Condominiums_RoofRoom", "tiles": [[7, 4]], "facing": "north"}, + "items": {"TEA": 1} + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.04.plan.json new file mode 100644 index 0000000000..c9daf8768c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-09.04.plan.json @@ -0,0 +1,29 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "09.04", + "title": "after Gift RNG: save with the Eevee", + "start": {"map": "CeladonCity_Condominiums_RoofRoom", "tiles": [[7, 4]], "facing": "north"}, + "events": [ + { + "id": "leave_gift_summary", + "kind": "game_action", + "action": "leave_gift_summary", + "declared_after": {"map": "CeladonCity_Condominiums_RoofRoom", "tiles": [[7, 4]], "facing": "north"}, + "why": "the Eevee's summary Gift RNG left open, or HOME" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "live_start": true, + "notes": { + "checkpoint": [ + "Gift RNG takes the Eevee from its ball without moving the player and leaves its summary open, or HOME. This saves the shiny where 09.03 ended. A run started here with Gift RNG's handoff on loads the save facing the ball and runs Gift RNG first." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.01.plan.json new file mode 100644 index 0000000000..d4dde3e346 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.01.plan.json @@ -0,0 +1,192 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "10.01", + "title": "X items on the Department Store's 5F, HM02 Fly from Route 16's house, taught to the Pidgey, and Fly to Lavender Town's Pokemon Center", + "start": {"map": "CeladonCity_Condominiums_RoofRoom", "tiles": [[7, 4]], "facing": "north"}, + "events": [ + { + "id": "below_store_lift", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeladonCity_DepartmentStore_1F", "tiles": [[6, 2]], "facing": "north"} + }, + "why": "from the Eevee's ball (09.04) out of the roof room, down Celadon Mansion's stairs and out of its door, west to the Department Store's door (11, 14) and up 1F to below its lift door (6, 1)" + }, + { + "id": "lift_to_5f", + "kind": "game_action", + "action": "lift_floor", + "args": { + "from": "1F", + "to": "5F" + }, + "declared_after": {"map": "CeladonCity_DepartmentStore_5F", "tiles": [[6, 2]], "facing": "south"}, + "why": "the lift as the Rocket Hideout's (09.02, one layout): in through the door, to the panel (cursor on 1F, the floor came from), 5F, out a tile south of 5F's lift door (6, 1); PokeGuy rides it at 1:02:41" + }, + { + "id": "x_items_clerk", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeladonCity_DepartmentStore_5F", "tiles": [[3, 7]], "facing": "west"} + }, + "why": "down and west to face the X items clerk (1, 7) over the counter (2, 7), out of the Sailor's zone (5..7, 7..9)" + }, + { + "id": "buy_x_items", + "kind": "game_action", + "action": "mart", + "args": { + "map": "CeladonCity_DepartmentStore_5F", + "budget": 15600, + "floor": 19862, + "items": [ + {"item": "x-special", "quantity": 21}, {"item": "x-speed", "quantity": 6}, {"item": "x-accuracy", "quantity": 5}, + {"item": "guard-spec", "quantity": 2} + ] + }, + "why": "pokeguy 1:02:42: 6 X Speeds, 21 X Specials, 5 X Accuracies and 2 Guard Specs (15,600 of his 15,694), X Special first; the floor is the money measured at the Celadon save on console B (19,862 on the trainer card, 2026-11-11), which buys the whole list" + }, + { + "id": "below_5f_lift", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeladonCity_DepartmentStore_5F", "tiles": [[6, 2]], "facing": "north"} + }, + "why": "back up to below the lift door (6, 1)" + }, + { + "id": "lift_to_1f", + "kind": "game_action", + "action": "lift_floor", + "args": { + "from": "5F", + "to": "1F" + }, + "declared_after": {"map": "CeladonCity_DepartmentStore_1F", "tiles": [[6, 2]], "facing": "south"}, + "why": "the lift down, the cursor on 5F, to 1F, out a tile south of 1F's lift door" + }, + { + "id": "out_of_store", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeladonCity", "tiles": [[11, 15]], "facing": "south"} + }, + "why": "down 1F and out of the door (2, 14) onto Celadon below the store's door (11, 14)" + }, + { + "id": "ride_bike", + "kind": "game_action", + "action": "ride_bike", + "why": "on the BICYCLE with SELECT (registered in 08.03) outside the store" + }, + { + "id": "route16_below_cut_tree", + "kind": "route", + "action": "bike", + "args": { + "target": {"map": "Route16", "tiles": [[41, 12]], "facing": "north"} + }, + "why": "west along Celadon and out onto Route 16's east end, below the Cut tree (41, 11); the Snorlax (31, 13) closes row 13 west of it" + }, + { + "id": "cut_route16_tree", + "kind": "game_action", + "action": "cut_tree", + "args": { + "direction": "north" + }, + "declared_after": {"map": "Route16", "tiles": [[41, 11]], "facing": "north"}, + "why": "the Oddish (HM01, 06.02) cuts the tree; a step onto its tile" + }, + { + "id": "east_of_north_gate", + "kind": "route", + "action": "bike", + "args": { + "target": {"map": "Route16", "tiles": [[28, 6]], "facing": "west"} + }, + "why": "up to row 10 and west to a tile east of the north gate's door (27, 6), off the grass (33..41, 5..7) and out of Lea's and Jed's lines (30, 6), (31, 6)" + }, + { + "id": "below_fly_woman", + "kind": "route", + "action": "bike", + "args": { + "target": {"map": "Route16_House", "tiles": [[4, 4]], "facing": "north"} + }, + "why": "on the Bicycle through the gate, which allows cycling and keeps the rider on (warp_keeps_bike()), out at (20, 6), west to the house's door (10, 5) at the Bicycle's pace, and on foot up to below the woman's zone (3..5, 2..3); pokeguy cycles here (1:03:20). A run-paced leg on the Bicycle overshot the door (console B, 2026-11-12 01:05)" + }, + { + "id": "hm02_fly", + "kind": "talk", + "action": "wanderer", + "why": "the woman wanders (3..5, 2..3); once she steps onto (4, 3) she gives HM02 FLY (Route16_House_EventScript_Woman, FLAG_GOT_HM02)" + }, + { + "id": "teach_fly", + "kind": "game_action", + "action": "teach", + "args": { + "item": "hm02", + "move": "fly", + "species": "pidgey", + "forget": "whirlwind", + "or_forget": ["sand-attack"] + }, + "why": "HM02 Fly to the Pidgey (08.03), found by its summary's species (the Eevee, 09.04, stays in the party), in place of Whirlwind, which the step reads among its moves first: a Route 7 Pidgey (Lv19..22) knows Sand-Attack, Gust, Quick Attack and Whirlwind; without Whirlwind, Sand-Attack goes, leaving pokeguy's Fly, Gust, Quick Attack and Steel Wing" + }, + { + "id": "outside_fly_house", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route16", "tiles": [[10, 6]], "facing": "south"} + }, + "why": "out of the house's door onto Route 16, where Fly works" + }, + { + "id": "fly_lavender", + "kind": "game_action", + "action": "fly", + "args": { + "town": "LavenderTown", + "species": "pidgey" + }, + "declared_after": {"map": "LavenderTown", "tiles": [[6, 6]], "facing": "south"}, + "why": "the Pidgey, found in the party by its summary's species, flies to Lavender Town, landing below the Pokemon Center's door (6, 5)" + }, + { + "id": "lavender_nurse", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "LavenderTown_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "in at the Center's door and up to the nurse" + }, + { + "id": "heal_lavender", + "kind": "heal", + "why": "full HP before the Tower" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "From the Eevee's ball in Celadon Mansion's roof room (09.04), PokeGuy's way (1:02:18 to 1:04:11) to Lavender Town's Pokemon Center: X items on the Department Store's 5F, by its lift both ways (scripted as the Rocket Hideout's: the lift has no map, its doors' warps are dynamic), HM02 FLY from the woman in Route 16's house, taught to the Pidgey (08.03's catch), and Fly to Lavender.", + "Route 16 (Route16 map.json): from Celadon the east end (33..47, 12..14) is closed west by the Snorlax (31, 13), so the way north is the Cut tree (41, 11), then the north gate (Route16_NorthEntrance_1F) to the house (10, 5). Lea (30, 5) and Jed (31, 5) face south with sight 1; the grass (33..41, 5..7) is walked round. The bikers (6..16, 12..14) are south of the house's part of the route, behind the gate.", + "The woman wanders (MOVEMENT_TYPE_WANDER_AROUND, 3..5 by 2..3): the wanderer TALK presses A at (4, 3) until she is on it." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.02.plan.json new file mode 100644 index 0000000000..d32e65ef38 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.02.plan.json @@ -0,0 +1,31 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "10.02", + "title": "Pokemon Tower 1F and 2F, saved below the rival's trigger", + "start": {"map": "LavenderTown_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"}, + "events": [ + { + "id": "tower_2f_east_of_rival", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PokemonTower_2F", "tiles": [[17, 6]], "facing": "west"} + }, + "why": "out of the Center's door (6, 5), east to the Tower's door (18, 6), up 1F to its stairs (18, 9), and on 2F from its stairs (18, 10) up column 18 to (17, 6), a tile east of the trigger (16, 6) below the rival (16, 5); the other trigger (17, 5) is north of it" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "From Lavender's Pokemon Center into the Pokemon Tower (PokemonTower_1F, _2F map.json) to a tile east of the rival's lower trigger. The rival's battle is its own checkpoint, 10.03, verified and retried from this save. 1F and 2F have no wild Pokemon; 1F's wanderers (6..8, 7..9) and (6..10, 10..14) keep west of column 11.", + "The save card's place in the Tower isn't in save_card_place(): a run started at 10.03 doesn't check it." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.03.plan.json new file mode 100644 index 0000000000..567906e701 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.03.plan.json @@ -0,0 +1,48 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "10.03", + "title": "Pokemon Tower 2F: the rival", + "start": {"map": "PokemonTower_2F", "tiles": [[17, 6]], "facing": "west"}, + "events": [ + { + "id": "lead_lv36_for_rival_tower", + "kind": "game_action", + "action": "level", + "args": {"slot": 1, "min": 36}, + "why": "the precondition for the Tower rival: the lead at least Lv36, pokeguy's Blastoise here (PokemonSimulation docs/battles/pokeguy-conditions.md, tower-rival: C2 setup to Sp. Atk +2 and outspeed, Guard Spec first, from 38/114 HP: 630/700 wins, 90.0%, 83.8% to 94.5%); at his level or above, those sims stand for this fight and no new one is needed; below it, the run stops here, before the fight" + }, + { + "id": "rival_trigger", + "kind": "step", + "args": { + "direction": "west" + }, + "declared_after": {"map": "PokemonTower_2F", "tiles": [[16, 6]], "facing": "west"}, + "why": "onto (16, 6), below the rival (16, 5): PokemonTower_2F_EventScript_RivalTriggerDown turns the player north to him" + }, + { + "id": "rival_tower", + "kind": "battle", + "args": { + "trainer": "TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR", + "foes": ["pidgeotto", "gyarados", "growlithe", "kadabra", "ivysaur"], + "use_items": [{"item": "x-special", "quantity": 2}] + }, + "declared_after": {"map": "PokemonTower_2F", "tiles": [[16, 6]], "facing": "north"}, + "why": "the rival (TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR, sParty_RivalPokemonTowerBulbasaur): Pidgeotto Lv25, Gyarados Lv23, Growlithe Lv22, Kadabra Lv20, Ivysaur Lv25; then he walks off and the player stays facing north. Two X Specials (10.01's Department Store) on the first turns, against Pidgeotto, as PokeGuy did" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "The rival on the Tower's 2F (PokemonTower_2F scripts.inc): a step onto (16, 6) or (17, 5) with VAR_MAP_SCENE_POKEMON_TOWER_2F 0 starts him, with no walk; for a player who took Squirtle he has sParty_RivalPokemonTowerBulbasaur. PokeGuy (1:04:12 to 1:06:01) used two X Specials against Pidgeotto at 38/114 HP; his notes give the order Pidgeotto, Ivysaur, Gyarados, Growlithe, Kadabra, pret's party lists Ivysaur last. The battle saves after it." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.04.plan.json new file mode 100644 index 0000000000..febe390b00 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.04.plan.json @@ -0,0 +1,133 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "10.04", + "title": "Pokemon Tower 3F to 5F: a Super Repel, Ruth and Tammy", + "start": {"map": "PokemonTower_2F", "tiles": [[16, 6]], "facing": "north"}, + "events": [ + { + "id": "super_repel", + "kind": "game_action", + "action": "use_item", + "args": { + "item": "super-repel" + }, + "why": "the floors from 3F up have wild Pokemon on every floor tile; one of 08.03's Super Repels (pokeguy 1:03:50, before his Fly)" + }, + { + "id": "tower_3f_column_7", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PokemonTower_3F", "tiles": [[7, 7]], "facing": "east"} + }, + "why": "west along 2F's row 6 and down column 4 onto its stairs (4, 10), to 3F's (4, 10); down to the wall (4, 14), east and up column 7 to the wall (7, 6): the only way to row 7 from the west, south of Hope's line (12, 5) and north of Carly's (9, 10..12) and Patricia's (10, 15..16)" + }, + { + "id": "tower_3f_to_stairs", + "kind": "legs", + "action": "taps", + "args": { + "legs": [{"direction": "east", "tiles": 11}, {"direction": "south", "tiles": 2}, {"direction": "west", "tiles": 1}, {"direction": "south", "tiles": 1}] + }, + "why": "a tap a tile east along row 7 to (18, 7), down to (18, 9), west to the wall (17, 9) and down to (17, 10): the stairs (18, 10) warp on a press east, so they are stepped onto going east, and a walk a tile short still ends with the press east onto them. Down column 18 instead, a turn read as a step left the player on (18, 9), facing a wall (console B, 2026-11-12). The planner, kept off open stops on wild floor, would go down to (18, 12) and round" + }, + { + "id": "tower_4f_stairs", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PokemonTower_4F", "tiles": [[18, 10]], "facing": "south"} + }, + "why": "east onto 3F's stairs (18, 10) and on, to 4F's (18, 10), turned south: the way on keeps out of Laurel's line (17, 8..10)" + }, + { + "id": "tower_4f_column_16", + "kind": "legs", + "action": "taps", + "args": { + "legs": [{"direction": "south", "tiles": 1}, {"direction": "west", "tiles": 2}, {"direction": "north", "tiles": 4}] + }, + "why": "a tap a tile: down to (18, 11), west to (16, 11) and up column 16 to the wall (16, 6), on (16, 7), west of Laurel's line" + }, + { + "id": "tower_4f_top", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PokemonTower_4F", "tiles": [[11, 3]], "facing": "west"} + }, + "why": "west and up to (11, 3), north of Jody's line (10..14, 13)" + }, + { + "id": "tower_5f_west_of_ruth", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PokemonTower_5F", "tiles": [[10, 6]], "facing": "east"} + }, + "why": "down column 9 to row 9, west to 4F's stairs (4, 10) above Paula's line (5..6, 12), to 5F's (4, 10); up column 4 to row 6 and east to (10, 6), west of Ruth's south line (11, 5..6)" + }, + { + "id": "ruth_line", + "kind": "step", + "action": "trainer_wait", + "args": { + "direction": "east" + }, + "why": "onto (11, 6), two below Ruth (11, 4), who looks around (MOVEMENT_TYPE_LOOK_AROUND): when she looks south she walks down to (11, 5). Row 6 is the only way east past the middle" + }, + { + "id": "channeler_ruth", + "kind": "battle", + "args": { + "trainer": "TRAINER_CHANNELER_RUTH", + "foes": ["gastly"] + }, + "declared_after": {"map": "PokemonTower_5F", "tiles": [[11, 6]], "facing": "east"}, + "why": "Channeler Ruth: Gastly Lv22" + }, + { + "id": "tower_5f_row6_east", + "kind": "legs", + "action": "taps", + "args": { + "legs": [{"direction": "east", "tiles": 7}] + }, + "why": "a tap a tile along row 6 to (18, 6), above Tammy's line (16..18, 7)" + }, + { + "id": "tammy_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "south" + }, + "why": "onto (18, 7), the first tile of Tammy's line: she faces west from (19, 7), beside it" + }, + { + "id": "channeler_tammy", + "kind": "battle", + "args": { + "trainer": "TRAINER_CHANNELER_TAMMY", + "foes": ["haunter"] + }, + "declared_after": {"map": "PokemonTower_5F", "tiles": [[18, 7]], "facing": "south"}, + "why": "Channeler Tammy: Haunter Lv23 (pokeguy 1:06:36)" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "From the rival's battle up the Tower to 5F (PokemonTower_3F.._5F map.json, scripts.inc): every floor tile from 3F up has wild Pokemon, so first a Super Repel. The Channelers' lines (pret sight): 3F Patricia (10, 14) and Carly (9, 9) south 3, Hope (12, 4) north and south 2; 4F Laurel (17, 7) south 3, Jody (15, 13) west 5, Paula (4, 12) east 2; 5F Ruth (11, 4) looks around 2, Tammy (19, 7) west 3, Karina (7, 12) east 2, Janae (11, 16) looks around 2.", + "3F and 4F are walked round every line. On 5F every way from the west stairs to the east stairs crosses Ruth's or Tammy's lines and row 6 crosses both: PokeGuy fought only Tammy, Ruth looking away. Here Ruth is waited for (trainer_wait) and fought, then Tammy. 5F's purified zone (10..12, 8..10) heals the party (PokemonTower_5F_EventScript_PurifiedZone); PokeGuy walks round it, and so does this.", + "The runtime maps (PokemonSimulation bdca47c) have no item balls on 5F and 6F, where pret has a NUGGET (6, 16) and the CLEANSE TAG (11, 9) on 5F, and the Rare Candy (5, 15) and an X ACCURACY (15, 15) on 6F: no way here steps on them." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.05.plan.json new file mode 100644 index 0000000000..168f7ad506 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.05.plan.json @@ -0,0 +1,128 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "10.05", + "title": "Pokemon Tower 6F: Jennifer, Emilia, the Rare Candy and the Marowak ghost", + "start": {"map": "PokemonTower_5F", "tiles": [[18, 7]], "facing": "south"}, + "events": [ + { + "id": "tower_6f_stairs", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PokemonTower_6F", "tiles": [[18, 10]], "facing": "north"} + }, + "why": "down 5F's column 18 onto its stairs (18, 10) to 6F's (18, 10), turned north: the way on keeps out of Angelica's line (14..16, 10)" + }, + { + "id": "tower_6f_below_jennifer_line", + "kind": "legs", + "action": "taps", + "args": { + "legs": [{"direction": "north", "tiles": 2}, {"direction": "west", "tiles": 2}, {"direction": "north", "tiles": 1}] + }, + "why": "a tap a tile: up to the wall (18, 7), on (18, 8), west to (16, 8) and up to (16, 7), below Jennifer's line (15..17, 6)" + }, + { + "id": "jennifer_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "north" + }, + "why": "onto (16, 6) in Jennifer's line: she faces west from (18, 6) and walks to (17, 6)" + }, + { + "id": "channeler_jennifer", + "kind": "battle", + "args": { + "trainer": "TRAINER_CHANNELER_JENNIFER", + "foes": ["gastly"] + }, + "declared_after": {"map": "PokemonTower_6F", "tiles": [[16, 6]], "facing": "north"}, + "why": "Channeler Jennifer: Gastly Lv24 (pokeguy 1:07:00)" + }, + { + "id": "tower_6f_east_of_emilia_line", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PokemonTower_6F", "tiles": [[10, 8]], "facing": "west"} + }, + "why": "up column 16 to row 4, west along it and down column 12 to row 8, west to (10, 8), east of Emilia's line (9, 7..9)" + }, + { + "id": "emilia_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "west" + }, + "why": "onto (9, 8) in Emilia's line: she faces south from (9, 6) and walks to (9, 7)" + }, + { + "id": "channeler_emilia", + "kind": "battle", + "args": { + "trainer": "TRAINER_CHANNELER_EMILIA", + "foes": ["gastly"] + }, + "declared_after": {"map": "PokemonTower_6F", "tiles": [[9, 8]], "facing": "west"}, + "why": "Channeler Emilia: Gastly Lv24 (pokeguy 1:07:28)" + }, + { + "id": "above_tower_rare_candy", + "kind": "legs", + "action": "taps", + "args": { + "legs": [{"direction": "west", "tiles": 4}, {"direction": "south", "tiles": 6}] + }, + "why": "a tap a tile from (9, 8), where Emilia's battle leaves the player, west along row 8 to (5, 8) and down column 5 to (5, 14), above the Rare Candy (5, 15) (pokeguy 1:07:53): an approach to an A press ends on its tile. As holds, west ended on (4, 8) and south met the gravestone (4, 9) (console B, 2026-11-12 04:39)" + }, + { + "id": "tower_rare_candy", + "kind": "talk", + "why": "pick up the Rare Candy" + }, + { + "id": "above_marowak_trigger", + "kind": "legs", + "action": "taps", + "args": { + "legs": [{"direction": "north", "tiles": 2}, {"direction": "east", "tiles": 6}, {"direction": "south", "tiles": 2}] + }, + "why": "a tap a tile back up column 5 to row 12, east along it to (11, 12) and down column 11 to (11, 14), above the trigger (11, 15) before the stairs (11, 16): the planner, kept off open stops on wild floor, would go west to the wall (2, 11) and back" + }, + { + "id": "marowak_trigger", + "kind": "step", + "args": { + "direction": "south" + }, + "declared_after": {"map": "PokemonTower_6F", "tiles": [[11, 15]], "facing": "south"}, + "why": "onto (11, 15): PokemonTower_6F_EventScript_MarowakGhost, \"Be gone... Intruders...\"; with the SILPH SCOPE the ghost is a Marowak" + }, + { + "id": "marowak_ghost", + "kind": "battle", + "args": { + "foes": ["marowak"] + }, + "declared_after": {"map": "PokemonTower_6F", "tiles": [[11, 15]], "facing": "south"}, + "why": "Marowak Lv30, a wild battle that can't be run from (StartMarowakBattle); pokeguy KOs it with one Water Pulse (1:08:04). Then the spirit's text" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "6F (PokemonTower_6F map.json, scripts.inc), from 10.04's save beside Tammy: Angelica (13, 10) looks east 3, Jennifer (18, 6) west 3, Emilia (9, 6) south 3. Every way from the east stairs to the west part crosses Jennifer's and Emilia's lines (pokeguy fights both); Angelica's is walked round. The Rare Candy in the south-west pocket, then the Marowak ghost: a step onto (11, 15) or (12, 16), both beside the stairs up (11, 16), with VAR_MAP_SCENE_POKEMON_TOWER_6F 0. The save after it is the retry point before 7F's three Grunts.", + "The runtime map has no ball at the Rare Candy (5, 15) or the X ACCURACY (15, 15) (see 10.04's notes); the pickup faces (5, 15) from above." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.06.plan.json new file mode 100644 index 0000000000..058d207f70 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-10.06.plan.json @@ -0,0 +1,144 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "10.06", + "title": "Pokemon Tower 7F: three Rocket Grunts, Mr. Fuji and the POKE FLUTE", + "start": {"map": "PokemonTower_6F", "tiles": [[11, 15]], "facing": "south"}, + "events": [ + { + "id": "tower_7f_below_grunt1_line", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PokemonTower_7F", "tiles": [[11, 11]], "facing": "north"} + }, + "why": "onto 6F's stairs (11, 16) to 7F's (11, 16), up column 11 to (11, 11), below Grunt 1's line (10..13, 10)" + }, + { + "id": "grunt1_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "north" + }, + "why": "onto (11, 10) in the first Grunt's line: he faces east from (9, 10) and walks to (10, 10)" + }, + { + "id": "tower_grunt1", + "kind": "battle", + "args": { + "trainer": "TRAINER_TEAM_ROCKET_GRUNT_19", + "foes": ["zubat", "zubat", "golbat"] + }, + "declared_after": {"map": "PokemonTower_7F", "tiles": [[11, 10]], "facing": "north"}, + "why": "Rocket Grunt (TRAINER_TEAM_ROCKET_GRUNT_19): Zubat, Zubat, Golbat Lv25; he walks off (PokemonTower_7F_EventScript_Grunt1ExitRight) and is removed" + }, + { + "id": "below_grunt2_line", + "kind": "step", + "args": { + "direction": "north" + }, + "declared_after": {"map": "PokemonTower_7F", "tiles": [[11, 9]], "facing": "north"}, + "why": "a step up to (11, 9), below Grunt 2's line (9..12, 8)" + }, + { + "id": "grunt2_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "north" + }, + "why": "onto (11, 8) in the second Grunt's line: he faces west from (13, 8) and walks to (12, 8)" + }, + { + "id": "tower_grunt2", + "kind": "battle", + "args": { + "trainer": "TRAINER_TEAM_ROCKET_GRUNT_20", + "foes": ["koffing", "drowzee"] + }, + "declared_after": {"map": "PokemonTower_7F", "tiles": [[11, 8]], "facing": "north"}, + "why": "Rocket Grunt (TRAINER_TEAM_ROCKET_GRUNT_20): Koffing, Drowzee Lv26; he walks off and is removed" + }, + { + "id": "below_grunt3_line", + "kind": "step", + "args": { + "direction": "north" + }, + "declared_after": {"map": "PokemonTower_7F", "tiles": [[11, 7]], "facing": "north"}, + "why": "a step up to (11, 7), below Grunt 3's line (10..13, 6)" + }, + { + "id": "grunt3_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "north" + }, + "why": "onto (11, 6) in the third Grunt's line: he faces east from (9, 6) and walks to (10, 6)" + }, + { + "id": "tower_grunt3", + "kind": "battle", + "args": { + "trainer": "TRAINER_TEAM_ROCKET_GRUNT_21", + "foes": ["zubat", "rattata", "raticate", "zubat"] + }, + "declared_after": {"map": "PokemonTower_7F", "tiles": [[11, 6]], "facing": "north"}, + "why": "Rocket Grunt (TRAINER_TEAM_ROCKET_GRUNT_21): Zubat, Rattata, Raticate, Zubat Lv23 (Rattata's Quick Attack, pokeguy 1:10:12); he walks off and is removed" + }, + { + "id": "below_fuji", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PokemonTower_7F", "tiles": [[11, 5]], "facing": "north"} + }, + "why": "a tile up, below Mr. Fuji (11, 4)" + }, + { + "id": "mr_fuji_tower", + "kind": "talk", + "declared_after": {"map": "LavenderTown_VolunteerPokemonHouse", "tiles": [[4, 7]], "facing": "north"}, + "why": "Mr. Fuji: \"follow me\", and the script warps the player to his house's (4, 7)" + }, + { + "id": "below_fuji_house", + "kind": "legs", + "action": "taps", + "args": { + "legs": [{"direction": "north", "tiles": 3}, {"direction": "west", "tiles": 1}] + }, + "why": "a tap a tile from the door (4, 7) up to (4, 4) and west to below Mr. Fuji (3, 3), now shown (FLAG_HIDE_POKEHOUSE_FUJI cleared): (3, 4), between the table (5..6, 4..5) and the youngster (3, 5). An approach to an A press ends on its tile: held, \"north 3\" is open at (4, 3)" + }, + { + "id": "facing_fuji", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "LavenderTown_VolunteerPokemonHouse", "tiles": [[3, 4]], "facing": "north"} + }, + "why": "turned north to Mr. Fuji (3, 3)" + }, + { + "id": "poke_flute", + "kind": "talk", + "why": "Mr. Fuji gives the POKE FLUTE (FLAG_GOT_POKE_FLUTE), no YES/NO" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "7F (PokemonTower_7F map.json, scripts.inc): column 11 is the only way up to Mr. Fuji (11, 4), and three Grunts look across it, 4 tiles each: (9, 10) east, (13, 8) west, (9, 6) east. Each is fought on the first tile of column 11 in his line; each walks off after his battle and is removed (FLAG_HIDE_TOWER_ROCKET_1..3). Mr. Fuji's talk warps the player to his house (warp MAP_LAVENDER_TOWN_VOLUNTEER_POKEMON_HOUSE, 4, 7); talked to again there, he gives the POKE FLUTE (pokeguy 1:11:04 to 1:11:24). The save is in his house: LAVENDER TOWN on the save card.", + "The facing after the script's warp is not measured; north is assumed (the player faced north to talk)." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRngConsoleSteps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRngConsoleSteps.cpp index 0f537eed5f..408749bb4d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRngConsoleSteps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRngConsoleSteps.cpp @@ -4,7 +4,9 @@ * */ +#include #include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/ScopeExit.h" #include "CommonFramework/Exceptions/OperationFailedException.h" #include "PokemonFRLG_StarterRngConsoleSteps.h" #include "PokemonFRLG_GiftRngConsoleSteps.h" @@ -88,10 +90,9 @@ StarterRngResult ConsoleGiftRngSteps::run_attempt(const RngAttempt& attempt, con throw InternalProgramError(&m_env.logger(), PA_CURRENT_FUNCTION, "The plan's seed isn't in the seed list it came from."); } - GiftRngStats stats; GiftRngAttempts attempts( GiftRngTarget{ - .target = PokemonFRLG_RngTarget::magikarp, + .target = m_settings.target, .seed = attempt.target.seed.seed, .advances = attempt.target.advances, .seed_match = seed_match, @@ -105,8 +106,10 @@ StarterRngResult ConsoleGiftRngSteps::run_attempt(const RngAttempt& attempt, con .calibration = m_calibration_display, }, m_notifications, - stats + m_stats ); + // The run's counts after each try, however it ends. + const ScopeExit log_stats_after([this]{ log_stats(); }); try{ const GiftRngResult result = attempts.run(m_env, m_context); return StarterRngResult{.outcome = loop_outcome(result.outcome), .pokemon = result.pokemon}; @@ -120,6 +123,10 @@ StarterRngResult ConsoleGiftRngSteps::run_attempt(const RngAttempt& attempt, con } } +void ConsoleGiftRngSteps::log_stats(){ + m_env.log(std::format("Gift RNG stats: {}", m_stats.to_str(StatsTracker::DISPLAY_ON_SCREEN))); +} + } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRngConsoleSteps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRngConsoleSteps.h index 692f74a8d3..14e56ff1fc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRngConsoleSteps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRngConsoleSteps.h @@ -3,8 +3,9 @@ * From: https://github.com/PokemonAutomation/ * * The RNG plan loop's steps (PokemonFRLG_StarterRngLoop.h) on the console - * for Gift RNG's Magikarp: each try runs Gift RNG's attempts - * (PokemonFRLG_GiftRngAttempts.h) from the save beside Route 4's salesman. + * for a Gift RNG target (Route 4's Magikarp, Celadon's Eevee): each try + * runs Gift RNG's attempts (PokemonFRLG_GiftRngAttempts.h) from the save + * where the gift is taken. * The loop counts tries in Starter RNG's outcomes; Gift RNG's map onto * them one to one. * @@ -39,12 +40,16 @@ struct GiftRngConsoleSettings{ SoundSetting sound = SoundSetting::Mono; // The calibration the first try starts from. RngCalibrations calibration = {}; + // The gift: Gift RNG's target, its save beside the salesman or + // facing the ball. + PokemonFRLG_RngTarget target = PokemonFRLG_RngTarget::magikarp; }; // The loop's steps on the console, with Gift RNG's displays, stats and // calibration kept here (AutoStory doesn't show them). Each try after the -// first starts from the calibration the last one ended with. Magikarp, FireRed, -// the Switch's default profile, no Teachy TV and no Rare Candies. +// first starts from the calibration the last one ended with. The settings' +// target, FireRed, the Switch's default profile, no Teachy TV and no Rare +// Candies. class ConsoleGiftRngSteps : public StarterRngLoopSteps{ public: ConsoleGiftRngSteps( @@ -56,6 +61,9 @@ class ConsoleGiftRngSteps : public StarterRngLoopSteps{ virtual StarterRngResult run_attempt(const RngAttempt& attempt, const StarterRngAttemptCall& call) override; private: + // Logs Gift RNG's counts so far in this run. + void log_stats(); + SingleSwitchProgramEnvironment& m_env; ProControllerContext& m_context; GiftRngConsoleSettings m_settings; @@ -64,6 +72,8 @@ class ConsoleGiftRngSteps : public StarterRngLoopSteps{ RngTargetDisplay m_target_display; RngFilterDisplay m_filter_display; RngCalibrationDisplay m_calibration_display; + // Gift RNG's counts over all tries of this run. + GiftRngStats m_stats; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngConsoleSteps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngConsoleSteps.cpp index 3a914823e7..e21778f5c3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngConsoleSteps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngConsoleSteps.cpp @@ -4,6 +4,8 @@ * */ +#include +#include "Common/Cpp/ScopeExit.h" #include "CommonFramework/Exceptions/OperationFailedException.h" #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "PokemonFRLG_StarterRngConsoleSteps.h" @@ -70,7 +72,6 @@ StarterRngResult ConsoleStarterRngSteps::run_attempt(const RngAttempt& attempt, throw InternalProgramError(&m_env.logger(), PA_CURRENT_FUNCTION, "The plan's seed isn't in the seed list it came from."); } - StarterRngStats stats; StarterRngAttempts attempts( StarterRngTarget{ .starter = StarterSpecies::squirtle, @@ -96,8 +97,10 @@ StarterRngResult ConsoleStarterRngSteps::run_attempt(const RngAttempt& attempt, .calibration = m_calibration_display, }, m_notifications, - stats + m_stats ); + // The run's counts after each try, however it ends. + const ScopeExit log_stats_after([this]{ log_stats(); }); try{ return attempts.run(m_env, m_context); }catch (OperationFailedException& e){ @@ -110,6 +113,10 @@ StarterRngResult ConsoleStarterRngSteps::run_attempt(const RngAttempt& attempt, } } +void ConsoleStarterRngSteps::log_stats(){ + m_env.log(std::format("Starter RNG stats: {}", m_stats.to_str(StatsTracker::DISPLAY_ON_SCREEN))); +} + } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngConsoleSteps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngConsoleSteps.h index 5baafa8774..e94d662553 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngConsoleSteps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngConsoleSteps.h @@ -76,6 +76,9 @@ class ConsoleStarterRngSteps : public StarterRngLoopSteps{ virtual StarterRngResult run_attempt(const RngAttempt& attempt, const StarterRngAttemptCall& call) override; private: + // Logs Starter RNG's counts so far in this run. + void log_stats(); + SingleSwitchProgramEnvironment& m_env; ProControllerContext& m_context; StarterRngConsoleSettings m_settings; @@ -84,6 +87,8 @@ class ConsoleStarterRngSteps : public StarterRngLoopSteps{ RngTargetDisplay m_target_display; RngFilterDisplay m_filter_display; RngCalibrationDisplay m_calibration_display; + // Starter RNG's counts over all tries of this run. + StarterRngStats m_stats; }; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 426cb0ad26..690f3f754a 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2007,6 +2007,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_BikeSpinPresses.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_CodedRooms.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_CodedRooms.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_FlyMap.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_HideoutLiftRoom.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_MovementMechanics.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_MovementStepPresses.h @@ -2046,6 +2048,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldStairs_Tests.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimScreens.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteCosts.h @@ -2112,6 +2115,11 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldSteps.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFossil.h @@ -2135,6 +2143,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTower_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartBuys.h @@ -2149,6 +2158,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacing.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacing.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItemsPocket.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLevelUps.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMemberInfo.h @@ -2163,6 +2173,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden10.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryResources.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryResources.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryResources_Tests.cpp diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json index a446a338aa..24f10bf535 100644 --- a/devtools/maps/map-resources.lock.json +++ b/devtools/maps/map-resources.lock.json @@ -3,9 +3,9 @@ "repository": "dayfine/PokemonSimulation", "games": { "frlg": { - "revision": "bdca47c5045797be1d2a1f0931ad6a8f15ab3225", + "revision": "0c46df1e5e9abe79016f2c8610aeb784835768fe", "manifest_path": "data/maps/runtime-manifest.json", - "manifest_sha256": "1ccdf3c4e5b8abc90f13e80b6dc8fa429c20f641a018e0e11368930f16165d10" + "manifest_sha256": "70f1947e4b2474319e87959480abad04f130834d235ef7b8a2f24a0256314c14" } } }