diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index d0966df32f..6a94155e3d 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -197,6 +197,8 @@ add_library(SerialProgramsLib STATIC ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES}) include(cmake/EmbedTextFiles.cmake) pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps Pokemon/Navigation/Pokemon_Navigation_Tests.h PokemonAutomation::Pokemon navigation_test_map_json) +pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Overworld/Maps + VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h PokemonAutomation::NintendoSwitch::PokemonFRLG overworld_map_json) # Create binary target diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.cpp index fbb88051fb..84ed2fa37e 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.cpp @@ -63,9 +63,16 @@ LegResult walk_leg_with(const LegSpec& leg, const LegCalls& calls, size_t max_in calls.clear(outcome->interrupt); const std::string seen = std::format("{} after {}ms", calls.name(outcome->interrupt), outcome->elapsed.count()); if (stops_here(leg, result, *outcome)){ - calls.log(seen + ", stopping the leg."); result.exact = false; result.stopped = true; + if (leg.to_wall){ + calls.log(seen + ", stopping the leg."); + return result; + } + // The caller finds the player again, near where the timing says. + result.tiles = leg.tiles - remaining + + tiles_before_interrupt(leg, outcome->elapsed, calls.detection_delay(outcome->interrupt), remaining); + calls.log(std::format("{}, about {} of {} tiles walked, stopping the leg.", seen, result.tiles, leg.tiles)); return result; } if (leg.to_wall){ diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.h index ca694db900..3993176f26 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker.h @@ -94,7 +94,9 @@ struct LegResult{ bool exact = true; size_t interruptions = 0; // The leg stopped at an interrupt (stop_on_interrupt, stop_if_blocked): - // the player is somewhere along it, and `tiles` is not known. + // the player is somewhere along it. For an open leg `tiles` is then how + // many the interrupt's timing says were walked (tiles_before_interrupt()), + // for the caller to look around; for a leg to a wall it is 0. bool stopped = false; }; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp index 667fb55d64..9f9564e275 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp @@ -130,7 +130,8 @@ UnitTestResult test_open_leg_interrupted_at_end(){ return true; } -// An open leg set to stop at an interrupt doesn't walk on from a guess. +// An open leg set to stop at an interrupt doesn't walk on from a guess; it +// says how far the timing puts the player, for the caller to look around. UnitTestResult test_open_leg_stops(){ ScriptedLeg script; script.outcomes = {after_step(2)}; @@ -140,6 +141,9 @@ UnitTestResult test_open_leg_stops(){ if (script.holds.size() != 1 || !result.stopped || result.exact || script.cleared.size() != 1){ return "Expected one hold, the interrupt cleared, and the leg stopped."; } + if (result.tiles != 2){ + return std::format("Expected the timing to put the player 2 tiles in, got {}.", result.tiles); + } return true; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json new file mode 100644 index 0000000000..a6cb236993 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json @@ -0,0 +1,194 @@ +{ + "name": "CeruleanCave_1F", + "source": { + "decomp_file": "data/maps/CeruleanCave_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########################################", + "#######...##.#########wwwwwwwww#..##..##", + "#######......#########wwwwwwwww#......##", + "#######..##..#wwwwwwwwwwwwwwwww#......##", + "##.####..##..#wwwwwwwwww#...#ww##.######", + "##.#.........#wwwwwwwwww#...#wwwwwwwwww#", + "#..#....##...#www#..........#wwwwwwwwww#", + "#..#....##...#www#..........#wwwwwwwwww#", + "#..#....##...#www#.................#www#", + "####....##.###www#...######...#....#www#", + "##.#....#www##www#...##.####.......#www#", + "##......#www##www##.###...##.......#www#", + "##......#wwwwwwww#....#...##...#####www#", + "##......#wwwwwwww#..#.##.###...###.....#", + "##..##..#wwwwwwww#.........#...#.......#", + "##..#...#www#....##......###...#.....###", + "##......#...#....####...####...#...#####", + "##......#...#..................#...#####", + "#####.###...##.#...............#...#####", + "#####..........#...............#...#####", + "#####..........#...............#...#####", + "#####..........#################...#####", + "########################################" + ], + "elevation": [ + "0000000000000000000000000000000000000000", + "0000000333003000000000111111111033003300", + "0000000333333000000000111111111033333300", + "0000000330033011111111111111111033333300", + "0030000330033011111111110444011003000000", + "0030333333333011111111110444011111111110", + "0330333300333011104444444444011111111110", + "0330333300333011104444444444011111111110", + "0330333300333011104444444444444444401110", + "0000333300300011104440000004440444401110", + "0030333301110011104440030000444444401110", + "0033333301110011100000033300444444401110", + "0033333301111111103333033300444000001110", + "0033333301111111103303003000444000333330", + "0033003301111111103333333330444033333330", + "0033033301110444400333333000444033333000", + "0033333303330444400003330000444033300000", + "0033333303330444444444444444444033300000", + "0000030003330000444444444444444033300000", + "0000033333333330444444444444444033300000", + "0000033333333330444444444444444033300000", + "0000033333333330000000000000000033300000", + "0000000000000000000000000000000000000000" + ], + "points": { + "entrance": [33, 21], + "warp_0": [33, 21], + "warp_1": [34, 2], + "warp_2": [1, 7], + "warp_3": [10, 2], + "warp_4": [5, 15], + "warp_5": [30, 10], + "warp_6": [24, 11], + "warp_7": [2, 4] + }, + "warps": [ + { + "x": 33, + "y": 21, + "enter": "walk_south", + "to_map": "CeruleanCity", + "to_point": "warp_7" + }, + { + "x": 34, + "y": 2, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_0" + }, + { + "x": 1, + "y": 7, + "enter": "step_on", + "to_map": "CeruleanCave_B1F", + "to_point": "warp_0" + }, + { + "x": 10, + "y": 2, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_1" + }, + { + "x": 5, + "y": 15, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_2" + }, + { + "x": 30, + "y": 10, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_3" + }, + { + "x": 24, + "y": 11, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_4" + }, + { + "x": 2, + "y": 4, + "enter": "step_on", + "to_map": "CeruleanCave_2F", + "to_point": "warp_5" + } + ], + "objects": [ + { + "name": "item_ball", + "kind": "item", + "x": 7, + "y": 3, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_1F_NUGGET" + }, + { + "name": "item_ball", + "kind": "item", + "x": 11, + "y": 16, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_1F_FULL_RESTORE" + }, + { + "name": "item_ball", + "kind": "item", + "x": 25, + "y": 5, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_1F_MAX_ELIXIR" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 7, + "y": 21, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 13, + "y": 21, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 5, + "y": 20, + "hide_flag": "FLAG_TEMP_14" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 14, + "y": 20, + "hide_flag": "FLAG_TEMP_15" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 11, + "y": 21, + "hide_flag": "FLAG_TEMP_16" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 9, + "y": 18, + "hide_flag": "FLAG_TEMP_17" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json new file mode 100644 index 0000000000..185103d4c8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json @@ -0,0 +1,180 @@ +{ + "name": "CeruleanCave_2F", + "source": { + "decomp_file": "data/maps/CeruleanCave_2F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########################################", + "########################################", + "########################################", + "####....####..##.....#............######", + "#######.......#..###.#.#########..######", + "####..####.####.##.#.#.........#########", + "####.....#.........###########....######", + "#######.############.........####.######", + "####.#...............#######....#.######", + "####.#################..#..###.##.######", + "####.#....#.............#...#...#.######", + "####.#.##.#.#####.#######.#####.#.######", + "####.#..#.#.....#.......#.....#.#.######", + "####.#..#.#####.#######.#####.#.########", + "####.#..#.#.....#.....#.....#.#.#.######", + "####.####.#.#####.###.#.#.#.#.#.#.######", + "####.#....#.........#.#.#.#.#.#.#.######", + "####.#.####.#########.#.#.#.###.#.######", + "####.#....#.....#.....#.#.#.....#.######", + "####.############.#####.#.#######.######", + "####..............#.....#.........######", + "########################################", + "########################################" + ], + "points": { + "warp_0": [33, 4], + "warp_1": [13, 4], + "warp_2": [7, 14], + "warp_3": [26, 9], + "warp_4": [23, 10], + "warp_5": [5, 6] + }, + "warps": [ + { + "x": 33, + "y": 4, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_1" + }, + { + "x": 13, + "y": 4, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_3" + }, + { + "x": 7, + "y": 14, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_4" + }, + { + "x": 26, + "y": 9, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_5" + }, + { + "x": 23, + "y": 10, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_6" + }, + { + "x": 5, + "y": 6, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_7" + } + ], + "objects": [ + { + "name": "item_ball", + "kind": "item", + "x": 9, + "y": 18, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_2F_PP_UP" + }, + { + "name": "item_ball", + "kind": "item", + "x": 29, + "y": 16, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_2F_ULTRA_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 33, + "y": 12, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_2F_FULL_RESTORE" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 33, + "y": 10, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 33, + "y": 9, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 25, + "y": 11, + "hide_flag": "FLAG_TEMP_14" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 28, + "y": 20, + "hide_flag": "FLAG_TEMP_15" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 30, + "y": 20, + "hide_flag": "FLAG_TEMP_16" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 9, + "y": 13, + "hide_flag": "FLAG_TEMP_17" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 23, + "y": 16, + "hide_flag": "FLAG_TEMP_18" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 13, + "y": 6, + "hide_flag": "FLAG_TEMP_19" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 4, + "y": 12, + "hide_flag": "FLAG_TEMP_1A" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 10, + "y": 20, + "hide_flag": "FLAG_TEMP_1B" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json new file mode 100644 index 0000000000..683929ff37 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json @@ -0,0 +1,159 @@ +{ + "name": "CeruleanCave_B1F", + "source": { + "decomp_file": "data/maps/CeruleanCave_B1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########################################", + "##..............##.....############....#", + "##..............#........#######.......#", + "##..............#..####.....#######....#", + "##......#####.###..####.....#######....#", + "##......#..........########.#######.#..#", + "##..##..##........#########............#", + "##..#...###......##########............#", + "##......#wwwww##................#...####", + "#########wwwww##................#...####", + "#www############................#...####", + "#www##############.########.###.#...####", + "#www#.#.#.########........#.###.#...####", + "#www#.....########........#.....#...####", + "#www#.....########........#.....#...####", + "#www###.###wwww#......#...#.###.#...####", + "#wwwwwwwwwwwwww#......#...#.###.#...####", + "#wwwwwwwwwwwwww#......#...#.....#...####", + "#wwwwwwwwwwwwww#......#...#.....#...####", + "######wwwwwwwww##.##.##...###.###...####", + "######wwwwwwwwwwww#.......###.......####", + "######wwwwwwwwwwww##.....####.......####", + "########################################" + ], + "elevation": [ + "0000000000000000000000000000000000000000", + "0033333333333333003333300000000000033330", + "0033333333333333033333333000000033333330", + "0033333333333333033000033333000000033330", + "0033333300000300033000033333000000033330", + "0033333303333333333000000003000000030330", + "0033003300333333330000000003333333333330", + "0033033300033333300000000003333333333330", + "0033333301111100444444444444444403330000", + "0000000001111100444444444444444403330000", + "0111000000000000444444444444444403330000", + "0111000000000000000000000004000403330000", + "0111030303000000003333333304000403330000", + "0111033333000000003333333304444403330000", + "0111033333000000003333333304444403330000", + "0111000300011110444444033304000403330000", + "0111111111111110444444033304000403330000", + "0111111111111110444444033304444403330000", + "0111111111111110404444033304444403330000", + "0000001111111110030000033300000003330000", + "0000001111111111110333333300033333330000", + "0000001111111111110033333000033333330000", + "0000000000000000000000000000000000000000" + ], + "points": { + "mewtwo": [7, 12], + "warp_0": [5, 7] + }, + "warps": [ + { + "x": 5, + "y": 7, + "enter": "step_on", + "to_map": "CeruleanCave_1F", + "to_point": "warp_2" + } + ], + "objects": [ + { + "name": "item_ball", + "kind": "item", + "x": 31, + "y": 9, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_B1F_ULTRA_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 32, + "y": 2, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_B1F_MAX_REVIVE" + }, + { + "name": "mewtwo", + "kind": "npc", + "x": 7, + "y": 12, + "hide_flag": "FLAG_HIDE_MEWTWO" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 37, + "y": 1, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 38, + "y": 2, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 35, + "y": 1, + "hide_flag": "FLAG_TEMP_14" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 37, + "y": 4, + "hide_flag": "FLAG_TEMP_15" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 35, + "y": 5, + "hide_flag": "FLAG_TEMP_16" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 2, + "y": 2, + "hide_flag": "FLAG_TEMP_17" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 4, + "y": 1, + "hide_flag": "FLAG_TEMP_18" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 6, + "y": 1, + "hide_flag": "FLAG_TEMP_19" + }, + { + "name": "rock_smash_rock", + "kind": "npc", + "x": 3, + "y": 4, + "hide_flag": "FLAG_TEMP_1A" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json new file mode 100644 index 0000000000..0c54fa2d7d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity.json @@ -0,0 +1,270 @@ +{ + "name": "CeruleanCity", + "source": { + "decomp_file": "data/maps/CeruleanCity/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "################wwwww#...#...#wwwwwwwwwwwwwwwwww", + "################wwwww#...#vvv#wwwwwwwwwwwwwwwwww", + "####wwwwwwwwwwwwwwwww#...#...#wwwwwwwwwwwwwwwwww", + "####wwwwwwwwwwwwwwwww#...#...#wwwwwwwwwwwwwwwwww", + "####wwwwwwwwwwwwwwwww#...#...###################", + "####www###############...#...#.........#########", + "####www#.............#...#...#.........#########", + "####www#.............#...#...#.........#########", + "####www##...##########.......#...##...##########", + "####www###############......#######...##########", + "####www###############......#######...##########", + "####www###D######D####......##D####......#######", + "#.##www#..........................#......#######", + "....www#..........................#......#######", + "....www#..........................#......#######", + "....www#.....#######..............#......#######", + "wwwwwww#...vv############.........#......#......", + "wwwwwww#.....##D#########.........#......#######", + "wwwwwww#............#####vvv#######.............", + "########............SSD##...#######.............", + "............................#######vvv#..#######", + "...........................S..#D#.....#..#......", + "......................................#..#######", + "#######...............................#..#######", + "#######.....####......................#..#######", + "#######....#####....S.................#..#######", + "#######....#####.....###############..#..#######", + "#######....#####.....###############..#..#######", + "#######....S#..#.....##D###SSD######..#..#######", + "#######...............................#..#######", + "#######...............................#..#######", + "#######...............................#..#######", + "###################S######.############..#######", + "#######..................................#######", + "#######..................................#######", + "###############....#........#....###############", + "###############....#vvvvvvvv#....###############", + "###############....#........#....###############", + "###############....#........#....###############", + "###############....#........#....###############" + ], + "elevation": [ + "000000000000000011111033303330100000000000000000", + "000000000000000011111033300000100000000000000000", + "000011111111111111111033303330100000000000000000", + "000011111111111111111033303330111111111111111111", + "000011111111111111111033303330000000000000000000", + "000011100000000000000033303330333333333000000000", + "000011103333333333333033303330333333333000000000", + "000011103333333333333033303330333333333000000000", + "000011100333000000000033333330333003330000000000", + "000011100000000000000033333300000003330000000000", + "000011100000000000000033333300000003330000000000", + "000011100000000000000033333300000003333330000000", + "030011103333333333333333333333333303333330000000", + "333311103333333333333333333333333303333330000000", + "333311103333333333333333333333333303333330000000", + "333311103333300000003333333333333303333330000000", + "111111103330000000000000033333333303333330333333", + "111111103333300000000000033333333303333330000000", + "111111103333333333330000000000000003333333333333", + "000000003333333333330000033300000003333333333333", + "333333333333333333333333333300000000000330000000", + "333333333333333333333333333033000333330330333333", + "333333333333333333333333333333333333330330000000", + "000000033333333333333333333333333333330330000000", + "000000033333000033333333333333333333330330000000", + "000000033330000033330333333333333333330330000000", + "000000033330000033333000000000000000330330000000", + "000000033330000033333000000000000000330330000000", + "000000033330033033333000000000000000330330000000", + "000000033333333333333333333333333333330330000000", + "000000033333333333333333333333333333330330000000", + "000000033333333333333333333333333333330330000000", + "000000000000000000000000003000000000000330000000", + "000000033333333333333333333333333333333330000000", + "000000033333333333333333333333333333333330000000", + "000000000000000333303333333303333000000000000000", + "000000000000000333300000000003333000000000000000", + "000000000000000333303333333303333000000000000000", + "000000000000000333303333333303333000000000000000", + "000000000000000333303333333303333000000000000000" + ], + "points": { + "warp_3": [22, 19], + "warp_7": [1, 12] + }, + "warps": [ + { + "x": 10, + "y": 11, + "enter": "walk_into" + }, + { + "x": 30, + "y": 11, + "enter": "walk_into" + }, + { + "x": 15, + "y": 17, + "enter": "walk_into" + }, + { + "x": 22, + "y": 19, + "enter": "walk_into", + "to_map": "CeruleanCity_PokemonCenter_1F", + "to_point": "warp_1" + }, + { + "x": 31, + "y": 21, + "enter": "walk_into" + }, + { + "x": 13, + "y": 28, + "enter": "cave_entrance" + }, + { + "x": 29, + "y": 28, + "enter": "walk_into" + }, + { + "x": 1, + "y": 12, + "enter": "cave_entrance", + "to_map": "CeruleanCave_1F", + "to_point": "warp_0" + }, + { + "x": 10, + "y": 8, + "enter": "walk_south" + }, + { + "x": 31, + "y": 8, + "enter": "walk_south" + }, + { + "x": 31, + "y": 9, + "enter": "walk_into" + }, + { + "x": 14, + "y": 28, + "enter": "cave_entrance" + }, + { + "x": 23, + "y": 28, + "enter": "walk_into" + }, + { + "x": 17, + "y": 11, + "enter": "walk_into" + } + ], + "objects": [ + { + "name": "policeman", + "kind": "npc", + "x": 31, + "y": 12 + }, + { + "name": "rocket_m", + "kind": "npc", + "x": 33, + "y": 6, + "hide_flag": "FLAG_HIDE_CERULEAN_ROCKET" + }, + { + "name": "little_boy", + "kind": "npc", + "x": 16, + "y": 21, + "wander": { + "x0": 16, + "y0": 18, + "x1": 16, + "y1": 24 + } + }, + { + "name": "balding_man", + "kind": "npc", + "x": 9, + "y": 23, + "wander": { + "x0": 8, + "y0": 22, + "x1": 10, + "y1": 24 + } + }, + { + "name": "slowbro", + "kind": "npc", + "x": 32, + "y": 29 + }, + { + "name": "lass", + "kind": "npc", + "x": 33, + "y": 29 + }, + { + "name": "youngster", + "kind": "npc", + "x": 34, + "y": 22 + }, + { + "name": "blue", + "kind": "npc", + "x": 22, + "y": 0, + "hide_flag": "FLAG_HIDE_CERULEAN_RIVAL" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 26, + "y": 32, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "woman_1", + "kind": "npc", + "x": 12, + "y": 30 + }, + { + "name": "cooltrainer_m", + "kind": "npc", + "x": 1, + "y": 13, + "hide_flag": "FLAG_HIDE_CERULEAN_CAVE_GUARD" + } + ], + "flag_sets": { + "after_hall_of_fame": [ + "FLAG_HIDE_CERULEAN_CAVE_GUARD", + "FLAG_HIDE_CERULEAN_RIVAL", + "FLAG_HIDE_CERULEAN_ROCKET" + ] + }, + "connections": [ + { + "side": "north", + "to_map": "Route24", + "offset": 12 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json new file mode 100644 index 0000000000..c538b6e3b1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCity_PokemonCenter_1F.json @@ -0,0 +1,125 @@ +{ + "name": "CeruleanCity_PokemonCenter_1F", + "source": { + "decomp_file": "data/maps/CeruleanCity_PokemonCenter_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#.#############", + "###############", + "....###..##....", + "....#######....", + "...............", + "...............", + "#..........##..", + "...........##..", + "...............", + "###############" + ], + "elevation": [ + "030000000000000", + "000000000000000", + "333300033003333", + "333300000003333", + "333333333333333", + "330333333333333", + "044033333330033", + "330333333330033", + "333333333333333", + "000000000000000" + ], + "points": { + "pc": [11, 2], + "nurse_front": [7, 4], + "warp_1": [7, 8] + }, + "warps": [ + { + "x": 6, + "y": 8, + "enter": "walk_into", + "to_map": "CeruleanCity", + "to_point": "warp_3" + }, + { + "x": 7, + "y": 8, + "enter": "walk_south", + "to_map": "CeruleanCity", + "to_point": "warp_3" + }, + { + "x": 8, + "y": 8, + "enter": "walk_into", + "to_map": "CeruleanCity", + "to_point": "warp_3" + }, + { + "x": 1, + "y": 6, + "enter": "step_on" + } + ], + "objects": [ + { + "name": "nurse", + "kind": "npc", + "x": 7, + "y": 2 + }, + { + "name": "gentleman", + "kind": "npc", + "x": 12, + "y": 5 + }, + { + "name": "rocker", + "kind": "npc", + "x": 5, + "y": 4, + "wander": { + "x0": 4, + "y0": 4, + "x1": 6, + "y1": 4 + } + }, + { + "name": "youngster", + "kind": "npc", + "x": 4, + "y": 8, + "wander": { + "x0": 3, + "y0": 8, + "x1": 5, + "y1": 8 + } + }, + { + "name": "lass", + "kind": "npc", + "x": 3, + "y": 3 + }, + { + "name": "0", + "kind": "npc", + "x": 2, + "y": 1, + "hide_flag": "FLAG_HIDE_POSTGAME_GOSSIPERS" + }, + { + "name": "0", + "kind": "npc", + "x": 3, + "y": 1, + "hide_flag": "FLAG_HIDE_POSTGAME_GOSSIPERS" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json new file mode 100644 index 0000000000..63540ac440 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown.json @@ -0,0 +1,122 @@ +{ + "name": "PalletTown", + "source": { + "decomp_file": "data/maps/PalletTown/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "############..##########", + "############..##########", + "##....................##", + "##....................##", + "##...#####....#####...##", + "##...#####....#####...##", + "##...#####....#####...##", + "##..S#D###...S#D###...##", + "##....................##", + "##....................##", + "##...........#######..##", + "##...####S...#######..##", + "##...........#######..##", + "##...........###D###..##", + "##...S................##", + "##....................##", + "##...........###S##...##", + "##.....wwww...........##", + "##.....wwww...........##", + "##.....wwww...........##" + ], + "elevation": [ + "000000000000330000000000", + "000000000000330000000000", + "003333333333333333333300", + "003333333333333333333300", + "003330000033330000033300", + "003330000033330000033300", + "003330000033330000033300", + "003300000033300000033300", + "003333333333333333333300", + "003333333333333333333300", + "003333333333300000003300", + "003330000033300000003300", + "003333333333300000003300", + "003333333333300000003300", + "003330333333333333333300", + "003333333333333333333300", + "003333333333300000033300", + "003333311113333333333300", + "003333311113333333333300", + "003333311113333333333300" + ], + "points": { + "oaks_lab_front": [16, 14], + "warp_0": [6, 7], + "warp_1": [15, 7], + "warp_2": [16, 13] + }, + "warps": [ + { + "x": 6, + "y": 7, + "enter": "walk_into", + "to_map": "PalletTown_PlayersHouse_1F", + "to_point": "warp_1" + }, + { + "x": 15, + "y": 7, + "enter": "walk_into", + "to_map": "PalletTown_RivalsHouse", + "to_point": "warp_0" + }, + { + "x": 16, + "y": 13, + "enter": "walk_into", + "to_map": "PalletTown_ProfessorOaksLab", + "to_point": "warp_0" + } + ], + "objects": [ + { + "name": "woman_1", + "kind": "npc", + "x": 3, + "y": 10, + "wander": { + "x0": 2, + "y0": 6, + "x1": 4, + "y1": 14 + } + }, + { + "name": "fat_man", + "kind": "npc", + "x": 13, + "y": 17, + "wander": { + "x0": 7, + "y0": 15, + "x1": 19, + "y1": 19 + } + }, + { + "name": "prof_oak", + "kind": "npc", + "x": 10, + "y": 8, + "hide_flag": "FLAG_HIDE_OAK_IN_PALLET_TOWN" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "north", + "to_map": "Route1", + "offset": 0 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json new file mode 100644 index 0000000000..ee57a2a78a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_1F.json @@ -0,0 +1,64 @@ +{ + "name": "PalletTown_PlayersHouse_1F", + "source": { + "decomp_file": "data/maps/PalletTown_PlayersHouse_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############", + "#############", + "#..........##", + "#............", + "#.....##.....", + "#.....##.....", + "#............", + "##..........#", + "#............", + "#############" + ], + "points": { + "warp_1": [4, 8], + "warp_2": [10, 2] + }, + "warps": [ + { + "x": 5, + "y": 8, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_0" + }, + { + "x": 4, + "y": 8, + "enter": "walk_south", + "to_map": "PalletTown", + "to_point": "warp_0" + }, + { + "x": 10, + "y": 2, + "enter": "walk_east", + "to_map": "PalletTown_PlayersHouse_2F", + "to_point": "warp_0" + }, + { + "x": 3, + "y": 9, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_0" + } + ], + "objects": [ + { + "name": "mom", + "kind": "npc", + "x": 8, + "y": 4 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json new file mode 100644 index 0000000000..eb5cbf8d32 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_PlayersHouse_2F.json @@ -0,0 +1,46 @@ +{ + "name": "PalletTown_PlayersHouse_2F", + "source": { + "decomp_file": "data/maps/PalletTown_PlayersHouse_2F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "############", + "###########S", + "#.......##..", + "#.......##..", + "#.2...#.....", + "#.8...#.....", + "#.#.........", + "#...........", + "#..........." + ], + "elevation": [ + "000000000000", + "000000000000", + "033333330033", + "033333330033", + "033333033333", + "003033033333", + "040403333333", + "003033333333", + "033333333333" + ], + "points": { + "start": [6, 6], + "warp_0": [10, 2] + }, + "warps": [ + { + "x": 10, + "y": 2, + "enter": "walk_west", + "to_map": "PalletTown_PlayersHouse_1F", + "to_point": "warp_2" + } + ], + "objects": [], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json new file mode 100644 index 0000000000..158ea7c73d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_ProfessorOaksLab.json @@ -0,0 +1,127 @@ +{ + "name": "PalletTown_ProfessorOaksLab", + "source": { + "decomp_file": "data/maps/PalletTown_ProfessorOaksLab/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############", + "######SS#####", + ".............", + "#............", + "###.....###..", + ".##..........", + ".............", + ".............", + "#####...#####", + ".............", + ".............", + ".............", + "#...........#", + "#############" + ], + "points": { + "warp_0": [6, 12] + }, + "warps": [ + { + "x": 6, + "y": 12, + "enter": "walk_south", + "to_map": "PalletTown", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 12, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_2" + }, + { + "x": 5, + "y": 12, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_2" + } + ], + "objects": [ + { + "name": "scientist", + "kind": "npc", + "x": 3, + "y": 11 + }, + { + "name": "worker_f", + "kind": "npc", + "x": 2, + "y": 10, + "wander": { + "x0": 2, + "y0": 6, + "x1": 2, + "y1": 13 + } + }, + { + "name": "scientist", + "kind": "npc", + "x": 11, + "y": 10 + }, + { + "name": "prof_oak", + "kind": "npc", + "x": 6, + "y": 3, + "hide_flag": "FLAG_HIDE_OAK_IN_HIS_LAB" + }, + { + "name": "item_ball", + "kind": "item", + "x": 8, + "y": 4, + "hide_flag": "FLAG_HIDE_BULBASAUR_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 9, + "y": 4, + "hide_flag": "FLAG_HIDE_SQUIRTLE_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 10, + "y": 4, + "hide_flag": "FLAG_HIDE_CHARMANDER_BALL" + }, + { + "name": "blue", + "kind": "npc", + "x": 5, + "y": 4, + "hide_flag": "FLAG_HIDE_RIVAL_IN_LAB" + }, + { + "name": "pokedex", + "kind": "npc", + "x": 4, + "y": 1, + "hide_flag": "FLAG_HIDE_POKEDEX" + }, + { + "name": "pokedex", + "kind": "npc", + "x": 5, + "y": 1, + "hide_flag": "FLAG_HIDE_POKEDEX" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json new file mode 100644 index 0000000000..bfd7bdf2e0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PalletTown_RivalsHouse.json @@ -0,0 +1,69 @@ +{ + "name": "PalletTown_RivalsHouse", + "source": { + "decomp_file": "data/maps/PalletTown_RivalsHouse/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############", + "#############", + ".............", + ".............", + "......##.....", + "......##.....", + ".............", + ".............", + "#...........#", + "#############" + ], + "points": { + "warp_0": [4, 8] + }, + "warps": [ + { + "x": 4, + "y": 8, + "enter": "walk_south", + "to_map": "PalletTown", + "to_point": "warp_1" + }, + { + "x": 5, + "y": 8, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_1" + }, + { + "x": 3, + "y": 8, + "enter": "walk_into", + "to_map": "PalletTown", + "to_point": "warp_1" + } + ], + "objects": [ + { + "name": "daisy", + "kind": "npc", + "x": 10, + "y": 6, + "wander": { + "x0": 9, + "y0": 3, + "x1": 11, + "y1": 9 + } + }, + { + "name": "town_map", + "kind": "npc", + "x": 6, + "y": 4, + "hide_flag": "FLAG_HIDE_TOWN_MAP" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json new file mode 100644 index 0000000000..da09eb8aa1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity.json @@ -0,0 +1,167 @@ +{ + "name": "PewterCity", + "source": { + "decomp_file": "data/maps/PewterCity/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "################################################", + "#######################....#####################", + "####........#################.........##########", + "####........#################.........##########", + "####........#############D######......##########", + "####........###########...............##########", + "#######.....#####.#####..#######........########", + "####vvv..vvvvvvv...Svvvvvvvvvvvvvvvvv...########", + "####....................................########", + "####............................#####...########", + "######..........................#####...########", + "######..........................#D###...########", + "######..................................########", + "######...##.#######.##..................########", + "######...#############..................########", + "######...##.#######.##..................########", + "######...##S..#D#...##....####..........########", + "######...............#....######........########", + "######...............#....SSD###........########", + "######...............#.................S########", + "######################..........................", + "######..........................................", + "######.......#########..........................", + "######.......#########....##########............", + "######.......#########....##########....########", + "######.......##SSD####....#####S#####...########", + "######....................#.........#...########", + "######....................#.........#...########", + "######..#####.............#.........#...########", + "######..#####.............#.........#...########", + "######..#D###.......S.....#vvvv.vvvv#...########", + "######..................................########", + "######..................................########", + "######..................................########", + "######..................................########", + "######..................................########", + "####################....########################", + "####################....########################", + "####################....########################", + "####################....########################" + ], + "points": { + "gym_front": [15, 17], + "warp_0": [17, 6], + "warp_1": [25, 4], + "warp_2": [15, 16], + "warp_3": [28, 18], + "warp_5": [17, 25] + }, + "warps": [ + { + "x": 17, + "y": 6, + "enter": "cave_entrance", + "to_map": "PewterCity_Museum_1F", + "to_point": "warp_1" + }, + { + "x": 25, + "y": 4, + "enter": "walk_into", + "to_map": "PewterCity_Museum_1F", + "to_point": "warp_3" + }, + { + "x": 15, + "y": 16, + "enter": "walk_into", + "to_map": "PewterCity_Gym", + "to_point": "warp_1" + }, + { + "x": 28, + "y": 18, + "enter": "walk_into", + "to_map": "PewterCity_Mart", + "to_point": "warp_1" + }, + { + "x": 33, + "y": 11, + "enter": "walk_into" + }, + { + "x": 17, + "y": 25, + "enter": "walk_into", + "to_map": "PewterCity_PokemonCenter_1F", + "to_point": "warp_1" + }, + { + "x": 9, + "y": 30, + "enter": "walk_into" + } + ], + "objects": [ + { + "name": "lass", + "kind": "npc", + "x": 6, + "y": 15 + }, + { + "name": "man", + "kind": "npc", + "x": 33, + "y": 17, + "hide_flag": "FLAG_HIDE_PEWTER_MUSEUM_GUIDE" + }, + { + "name": "fat_man", + "kind": "npc", + "x": 21, + "y": 28 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 33, + "y": 27, + "wander": { + "x0": 31, + "y0": 27, + "x1": 35, + "y1": 27 + } + }, + { + "name": "boy", + "kind": "npc", + "x": 42, + "y": 20, + "hide_flag": "FLAG_HIDE_PEWTER_CITY_GYM_GUIDE" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 30, + "y": 5, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "scientist", + "kind": "npc", + "x": 46, + "y": 20, + "hide_flag": "FLAG_HIDE_PEWTER_CITY_RUNNING_SHOES_GUY" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "south", + "to_map": "Route2", + "offset": 12 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json new file mode 100644 index 0000000000..75afb1541c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Gym.json @@ -0,0 +1,75 @@ +{ + "name": "PewterCity_Gym", + "source": { + "decomp_file": "data/maps/PewterCity_Gym/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############", + "####.....####", + "#############", + "#....#.#....#", + "#...........#", + "#...#...#...#", + "#...........#", + "#..#.#.#.#..#", + "##.........##", + "#...#...#...#", + "##.........##", + "#...........#", + "#...S...S...#", + "#...........#", + "#...........#", + "#############" + ], + "points": { + "brock_front": [6, 6], + "warp_1": [6, 14] + }, + "warps": [ + { + "x": 5, + "y": 14, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_2" + }, + { + "x": 6, + "y": 14, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 14, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_2" + } + ], + "objects": [ + { + "name": "brock", + "kind": "npc", + "x": 6, + "y": 5 + }, + { + "name": "camper", + "kind": "npc", + "x": 3, + "y": 8 + }, + { + "name": "gym_guy", + "kind": "npc", + "x": 7, + "y": 12 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json new file mode 100644 index 0000000000..7b4e49dea9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Mart.json @@ -0,0 +1,78 @@ +{ + "name": "PewterCity_Mart", + "source": { + "decomp_file": "data/maps/PewterCity_Mart/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###########", + "###########", + "##.#......#", + "...#.......", + "####...##.#", + ".......##.#", + ".##....##.#", + "...........", + "###########" + ], + "elevation": [ + "00000000000", + "00000000000", + "00303333330", + "33003333333", + "00003330030", + "33333330030", + "30033330030", + "33333333333", + "00000000000" + ], + "points": { + "warp_1": [4, 7] + }, + "warps": [ + { + "x": 3, + "y": 7, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_3" + }, + { + "x": 4, + "y": 7, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_3" + }, + { + "x": 5, + "y": 7, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_3" + } + ], + "objects": [ + { + "name": "youngster", + "kind": "npc", + "x": 8, + "y": 2 + }, + { + "name": "boy", + "kind": "npc", + "x": 6, + "y": 4 + }, + { + "name": "clerk", + "kind": "npc", + "x": 2, + "y": 3 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json new file mode 100644 index 0000000000..1ea83f0faf --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_Museum_1F.json @@ -0,0 +1,108 @@ +{ + "name": "PewterCity_Museum_1F", + "source": { + "decomp_file": "data/maps/PewterCity_Museum_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "############################", + "############################", + "...............#............", + "...............#......#....#", + "...####........#...........#", + "...............#............", + "...........#...#...........#", + "...####..###...###.........#", + ".........###.....#..........", + "#........###....##......##..", + "############################" + ], + "points": { + "warp_1": [14, 9], + "warp_3": [21, 9] + }, + "warps": [ + { + "x": 13, + "y": 9, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_0" + }, + { + "x": 14, + "y": 9, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_0" + }, + { + "x": 15, + "y": 9, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_0" + }, + { + "x": 21, + "y": 9, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_1" + }, + { + "x": 22, + "y": 9, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_1" + }, + { + "x": 8, + "y": 8, + "enter": "walk_east" + } + ], + "objects": [ + { + "name": "worker_m", + "kind": "npc", + "x": 16, + "y": 5 + }, + { + "name": "old_man_1", + "kind": "npc", + "x": 2, + "y": 4 + }, + { + "name": "scientist", + "kind": "npc", + "x": 21, + "y": 3 + }, + { + "name": "old_amber", + "kind": "npc", + "x": 22, + "y": 3, + "hide_flag": "FLAG_HIDE_OLD_AMBER" + }, + { + "name": "scientist", + "kind": "npc", + "x": 26, + "y": 4 + }, + { + "name": "scientist", + "kind": "npc", + "x": 26, + "y": 7 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json new file mode 100644 index 0000000000..90267e027f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/PewterCity_PokemonCenter_1F.json @@ -0,0 +1,110 @@ +{ + "name": "PewterCity_PokemonCenter_1F", + "source": { + "decomp_file": "data/maps/PewterCity_PokemonCenter_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#.#############", + "###############", + "....###..##....", + "....#######....", + "...............", + "...............", + "#..........##..", + "...........##..", + "...............", + "###############" + ], + "elevation": [ + "030000000000000", + "000000000000000", + "333300033003333", + "333300000003333", + "333333333333333", + "330333333333333", + "044033333330033", + "330333333330033", + "333333333333333", + "000000000000000" + ], + "points": { + "nurse_front": [7, 4], + "warp_1": [7, 8] + }, + "warps": [ + { + "x": 6, + "y": 8, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_5" + }, + { + "x": 7, + "y": 8, + "enter": "walk_south", + "to_map": "PewterCity", + "to_point": "warp_5" + }, + { + "x": 8, + "y": 8, + "enter": "walk_into", + "to_map": "PewterCity", + "to_point": "warp_5" + }, + { + "x": 1, + "y": 6, + "enter": "step_on" + } + ], + "objects": [ + { + "name": "jigglypuff", + "kind": "npc", + "x": 2, + "y": 2 + }, + { + "name": "gentleman", + "kind": "npc", + "x": 4, + "y": 8 + }, + { + "name": "nurse", + "kind": "npc", + "x": 7, + "y": 2 + }, + { + "name": "youngster", + "kind": "npc", + "x": 1, + "y": 2 + }, + { + "name": "woman_1", + "kind": "npc", + "x": 13, + "y": 2 + }, + { + "name": "gba_kid", + "kind": "npc", + "x": 10, + "y": 7 + }, + { + "name": "gba_kid", + "kind": "npc", + "x": 14, + "y": 6 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json new file mode 100644 index 0000000000..c48c746b72 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route1.json @@ -0,0 +1,91 @@ +{ + "name": "Route1", + "source": { + "decomp_file": "data/maps/Route1/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "##########....##########", + "##########....##########", + "##....................##", + "##....................##", + "##......##............##", + "##vvvvvv##vvvvvv......##", + "##......##~~~~~~~~~~~~##", + "##......##~~~~~~~~~~~~##", + "##......##~~~~~~~~~~~~##", + "##......##~~~~~~~~~~~~##", + "##vvvvvv##~~~~~~~~~~~~##", + "##......##............##", + "##....................##", + "##..............~~~~~~##", + "##..............~~~~~~##", + "####vvvvvv######~~~~~~##", + "####......######~~~~~~##", + "##..............~~~~~~##", + "##....................##", + "##....................##", + "##vv.vvvv..vvvvvvvvvvv##", + "##....................##", + "##....................##", + "##....................##", + "##..........~~~~~~....##", + "############~~~~~~....##", + "############~~~~~~vvvv##", + "##..........~~~~~~....##", + "##..........~~~~~~....##", + "##....................##", + "##....................##", + "##vvvv...Svvvvvvvvvvvv##", + "##..~~~~~~~......~~~~~##", + "##..~~~~~~~......~~~~~##", + "##~~~~~~~......~~~~~..##", + "##~~~~~~~...~~.~~~~~..##", + "############~~##########", + "##.........#~~#.......##", + "############~~##########", + "############~~##########" + ], + "points": {}, + "warps": [], + "objects": [ + { + "name": "clerk", + "kind": "npc", + "x": 6, + "y": 28, + "wander": { + "x0": 6, + "y0": 27, + "x1": 6, + "y1": 29 + } + }, + { + "name": "boy", + "kind": "npc", + "x": 19, + "y": 16, + "wander": { + "x0": 18, + "y0": 16, + "x1": 20, + "y1": 16 + } + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "north", + "to_map": "ViridianCity", + "offset": -12 + }, + { + "side": "south", + "to_map": "PalletTown", + "offset": 0 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json new file mode 100644 index 0000000000..706949faeb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2.json @@ -0,0 +1,211 @@ +{ + "name": "Route2", + "source": { + "decomp_file": "data/maps/Route2/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########....############", + "########....############", + "##~~~~~~~...############", + "##~~~~~~~...#.........##", + "##~~~~~~~...#.........##", + "##~~~~~~~...#.........##", + "##~~~~~~~...#########.##", + "##~~~~~~~...#########.##", + "##~~~~~~~...#########.##", + "##..........#########.##", + "##..........#########.##", + "##..........#####.###.##", + "##..........#.S.......##", + "####....###.#.........##", + "###########...........##", + "##########............##", + "##############........##", + "##############........##", + "##############........##", + "##############........##", + "##############........##", + "###################...##", + "#################D#...##", + "##############........##", + "################......##", + "################......##", + "##################.#####", + "################......##", + "################......##", + "################......##", + "################......##", + "################......##", + "################vvv.vv##", + "################......##", + "################......##", + "################......##", + "################......##", + "################vvv.vv##", + "################......##", + "################......##", + "################......##", + "#################....###", + "########################", + "########################", + "########################", + "##........##############", + "##################..####", + "#################....###", + "################......##", + "################......##", + "###.####.#######......##", + "#####..#########vvv.vv##", + "####....########......##", + "##............##......##", + "##............##......##", + "##vvvvvvvvv...##......##", + "##....~~~~~~~.##......##", + "##....~~~~~~~.##vv.vvv##", + "##....~~~~~~~.##......##", + "##....~~~~~~~.##......##", + "##....~~~~~~~.##......##", + "##............##......##", + "##....................##", + "##....##########......##", + "##....##########......##", + "##....##########......##", + "##....##########......##", + "##............##......##", + "##............##......##", + "##....................##", + "##vvvvvvv..vvv..vv.vvv##", + "##............##......##", + "####..........##......##", + "####...S......##......##", + "####..........##......##", + "####..........##......##", + "####..........##......##", + "####..........##......##", + "#######.......##########", + "#######.....############" + ], + "points": { + "warp_0": [5, 13], + "warp_2": [5, 51] + }, + "warps": [ + { + "x": 5, + "y": 13, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_3" + }, + { + "x": 6, + "y": 13, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_3" + }, + { + "x": 5, + "y": 51, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_1" + }, + { + "x": 17, + "y": 11, + "enter": "cave_entrance" + }, + { + "x": 17, + "y": 22, + "enter": "walk_into" + }, + { + "x": 18, + "y": 46, + "enter": "cave_entrance" + }, + { + "x": 18, + "y": 41, + "enter": "walk_south" + }, + { + "x": 19, + "y": 41, + "enter": "walk_south" + }, + { + "x": 19, + "y": 46, + "enter": "cave_entrance" + }, + { + "x": 6, + "y": 51, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_1" + } + ], + "objects": [ + { + "name": "cut_tree", + "kind": "npc", + "x": 16, + "y": 62, + "hide_flag": "FLAG_TEMP_14" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 15, + "y": 69, + "hide_flag": "FLAG_TEMP_13" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 11, + "y": 13, + "hide_flag": "FLAG_TEMP_15" + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 18, + "y": 26, + "hide_flag": "FLAG_TEMP_16" + }, + { + "name": "item_ball", + "kind": "item", + "x": 17, + "y": 54, + "hide_flag": "FLAG_HIDE_ROUTE2_ETHER" + }, + { + "name": "item_ball", + "kind": "item", + "x": 17, + "y": 64, + "hide_flag": "FLAG_HIDE_ROUTE2_PARALYZE_HEAL" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "north", + "to_map": "PewterCity", + "offset": -12 + }, + { + "side": "south", + "to_map": "ViridianCity", + "offset": -12 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json new file mode 100644 index 0000000000..be2d5629b2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route22.json @@ -0,0 +1,90 @@ +{ + "name": "Route22", + "source": { + "decomp_file": "data/maps/Route22/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#############################################...", + "###########################################.#...", + "##################################........#.###.", + "##################################vvvv.vvv#...##", + "######################....................#.....", + "########D######...........................######", + "#####.......###.........................##......", + "###...........#.............######......##......", + "###...........#vvvvvvvwwwwww######vv..vv##......", + "###vvvvvvv..vv#~~~~~~~wwwwww######~~~~~~##......", + "###...........#~~~~~~~wwwwww######~~~~~~##....##", + "###...........#~~~~~~~wwwwww######~~~~~~##....##", + "####...S#######~~~~~~~......######~~~~~~##....##", + "####...........~~~~~~~......######~~~~~~##....##", + "####........................######............##", + "####vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv..vvvvv##", + "####..........................................##", + "####..........................................##", + "####..........................................##", + "################################################", + "################################################", + "################################################", + "################################################", + "################################################" + ], + "elevation": [ + "000000000000000000000000000000000000000000000333", + "000000000000000000000000000000000000000000030333", + "000000000000000000000000000000000033333333030003", + "000000000000000000000000000000000000003000033300", + "000000000000000000000033333333333333333333033333", + "000000000000000333333333333333333333333333000000", + "000003333333000333333333333333333333333300333333", + "000333333333330333333333333300000033333300333333", + "000333333333330000000011111100000000330000333333", + "000000000033000333333311111100000033333300333333", + "000333333333330333333311111100000033333300333300", + "000333333333330333333311111100000033333300333300", + "000033300000000333333333333300000033333300333300", + "000033333333333333333333333300000033333300333300", + "000033333333333333333333333300000033333333333300", + "000000000000000000000000000000000000000330000000", + "000033333333333333333333333333333333333333333300", + "000033333333333333333333333333333333333333333300", + "000033333333333333333333333333333333333333333300", + "000000000000000000000000000000000000000000000000", + "000000000000000000000000000000000000000000000000", + "000000000000000000000000000000000000000000000000", + "000000000000000000000000000000000000000000000000", + "000000000000000000000000000000000000000000000000" + ], + "points": {}, + "warps": [ + { + "x": 8, + "y": 5, + "enter": "walk_into" + }, + { + "x": 9, + "y": 5, + "enter": "walk_into" + } + ], + "objects": [ + { + "name": "blue", + "kind": "npc", + "x": 25, + "y": 4, + "hide_flag": "FLAG_HIDE_ROUTE_22_RIVAL" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "east", + "to_map": "ViridianCity", + "offset": -10 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json new file mode 100644 index 0000000000..59d1789c3c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route24.json @@ -0,0 +1,154 @@ +{ + "name": "Route24", + "source": { + "decomp_file": "data/maps/Route24/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "########################", + "########################", + "########################", + "####.........>...<......", + "####.........>...<......", + "####.........>...<......", + "###vvvv..vvvv#...#vvvvvv", + "###.....................", + "###.....................", + "###.....................", + "###..........###########", + "###..........#..........", + "###..........#...#######", + "###..........#...#######", + "###..........#...#######", + "###..........#...#######", + "###...www#...#...#######", + "###...www#...#...#######", + "###...www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#######", + "###~~~www#...#...#wwwwww", + "###~~~www#...#...#wwwwww", + "###~~~www#...#...#wwwwww", + "###~~~www#...#...#wwwwww", + "###~~~www#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww", + "####wwwww#...#...#wwwwww" + ], + "elevation": [ + "000000000000000000000000", + "000000000000000000000000", + "000000000000000000000000", + "000033333333303330333333", + "000033333333303330333333", + "000033333333303330333333", + "000000033000003330000000", + "000333333333333333333333", + "000333333333333333333333", + "000333333333333333333333", + "000333333333300000000000", + "000333333333303333333333", + "000333333333303330000000", + "000333333333303330000000", + "000333333333303330000000", + "000333333333303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330000000", + "000333111033303330111111", + "000333111033303330100000", + "000333111033303330100000", + "000333111033303330100000", + "000333111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000", + "000011111033303330100000" + ], + "points": {}, + "warps": [], + "objects": [ + { + "name": "man", + "kind": "npc", + "x": 12, + "y": 15, + "hide_flag": "FLAG_HIDE_NUGGET_BRIDGE_ROCKET" + }, + { + "name": "camper", + "kind": "npc", + "x": 12, + "y": 19 + }, + { + "name": "lass", + "kind": "npc", + "x": 10, + "y": 22 + }, + { + "name": "youngster", + "kind": "npc", + "x": 12, + "y": 25 + }, + { + "name": "lass", + "kind": "npc", + "x": 10, + "y": 28 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 12, + "y": 31 + }, + { + "name": "camper", + "kind": "npc", + "x": 5, + "y": 21 + }, + { + "name": "item_ball", + "kind": "item", + "x": 11, + "y": 4, + "hide_flag": "FLAG_HIDE_ROUTE24_TM45" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "south", + "to_map": "CeruleanCity", + "offset": -12 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json new file mode 100644 index 0000000000..021edbb11d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_NorthEntrance.json @@ -0,0 +1,78 @@ +{ + "name": "Route2_ViridianForest_NorthEntrance", + "source": { + "decomp_file": "data/maps/Route2_ViridianForest_NorthEntrance/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###############", + "#######.#######", + "##...#...#...##", + "#.............#", + "#..........##.#", + "###........##.#", + "#.............#", + "#..........##.#", + "###........##.#", + "#.............#", + "#.............#", + "###############" + ], + "points": { + "warp_1": [7, 10], + "warp_3": [7, 1] + }, + "warps": [ + { + "x": 6, + "y": 10, + "enter": "walk_into", + "to_map": "ViridianForest", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 10, + "enter": "walk_south", + "to_map": "ViridianForest", + "to_point": "warp_2" + }, + { + "x": 8, + "y": 10, + "enter": "walk_into", + "to_map": "ViridianForest", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 1, + "enter": "cave_entrance", + "to_map": "Route2", + "to_point": "warp_0" + } + ], + "objects": [ + { + "name": "youngster", + "kind": "npc", + "x": 5, + "y": 4 + }, + { + "name": "old_man_1", + "kind": "npc", + "x": 4, + "y": 7 + }, + { + "name": "cooltrainer_f", + "kind": "npc", + "x": 10, + "y": 5 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json new file mode 100644 index 0000000000..3b00abc4eb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route2_ViridianForest_SouthEntrance.json @@ -0,0 +1,78 @@ +{ + "name": "Route2_ViridianForest_SouthEntrance", + "source": { + "decomp_file": "data/maps/Route2_ViridianForest_SouthEntrance/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###############", + "#######.#######", + "##...#...#...##", + "#.............#", + "#..........##.#", + "###........##.#", + "#.............#", + "#..........##.#", + "###........##.#", + "#.............#", + "#.............#", + "###############" + ], + "points": { + "warp_1": [7, 10], + "warp_3": [7, 1] + }, + "warps": [ + { + "x": 6, + "y": 10, + "enter": "walk_into", + "to_map": "Route2", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 10, + "enter": "walk_south", + "to_map": "Route2", + "to_point": "warp_2" + }, + { + "x": 8, + "y": 10, + "enter": "walk_into", + "to_map": "Route2", + "to_point": "warp_2" + }, + { + "x": 7, + "y": 1, + "enter": "cave_entrance", + "to_map": "ViridianForest", + "to_point": "warp_0" + } + ], + "objects": [ + { + "name": "woman_2", + "kind": "npc", + "x": 10, + "y": 6 + }, + { + "name": "woman_1", + "kind": "npc", + "x": 4, + "y": 7, + "wander": { + "x0": 3, + "y0": 6, + "x1": 5, + "y1": 8 + } + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json new file mode 100644 index 0000000000..5bf976082a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity.json @@ -0,0 +1,216 @@ +{ + "name": "ViridianCity", + "source": { + "decomp_file": "data/maps/ViridianCity/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###################.....########################", + "###################....S########################", + "###################.....########################", + "###################.....########################", + "###################.....####..............######", + "########..................................######", + "########.##########.......................######", + "########.###########.............######...######", + "########.##########..............######...######", + "########.###########...######....######...######", + "########.##########.....#####...S..#D#....######", + "########.###########...##D###.............######", + "########.##########........##vvvvvvvvvvvvv######", + "########.###########......................######", + "########.##########.......................######", + "######...###########.........###################", + ".........##########.S..######.............######", + "........................#####.....####....######", + ".......................##D###.....####....######", + "..................................SSD#....######", + "#######...................................######", + "#######...................................######", + "#######...................................######", + "###########.............#####.............######", + "###########.##..........#####.............######", + "#######.....##..........#####.............######", + "#######....wwwwww.......SSD##.............######", + "#######....wwwwww.........................######", + "#######....wwwwww.........................######", + "#######....wwwwww.........................######", + "#######vvvvwwwwwwvvv...vvvvvvvvvvvvvvvvvvv######", + "#######.............S.....................######", + "#######...................................######", + "#######...................................######", + "##############............................######", + "##############............................######", + "######################....######################", + "######################....######################", + "######################....######################", + "######################....######################" + ], + "elevation": [ + "000000000000000000033333000000000000000000000000", + "000000000000000000033330000000000000000000000000", + "000000000000000000033333000000000000000000000000", + "000000000000000000033333000000000000000000000000", + "000000000000000000033333000033333333333333000000", + "000000003333333333333333333333333333333333000000", + "000000003000000000033333333333333333333333000000", + "000000003000000000003333333333333000000333000000", + "000000003000000000033333333333333000000333000000", + "000000003000000000003330000003333000000333000000", + "000000003000000000033333000003330330003333000000", + "000000003000000000003330000003333333333333000000", + "000000003000000000033333333000000000000000000000", + "000000003000000000003333333333333333333333000000", + "000000003000000000033333333333333333333333000000", + "000000333000000000003333333330000000000000000000", + "333333333000000000030330000003333333333333000000", + "333333333333333333333333000003333300003333000000", + "333333333333333333333330000003333300003333000000", + "333333333333333333333333333333333300003333000000", + "000000033333333333333333333333333333333333000000", + "000000033333333333333333333333333333333333000000", + "000000033333333333333333333333333333333333000000", + "000000000003333333333333000003333333333333000000", + "000000000003003333333333000003333333333333000000", + "000000033333003333333333000003333333333333000000", + "000000033331111113333333000003333333333333000000", + "000000033331111113333333333333333333333333000000", + "000000033331111113333333333333333333333333000000", + "000000033331111113333333333333333333333333000000", + "000000000001111110003330000000000000000000000000", + "000000033333333333330333333333333333333333000000", + "000000033333333333333333333333333333333333000000", + "000000033333333333333333333333333333333333000000", + "000000000000003333333333333333333333333333000000", + "000000000000003333333333333333333333333333000000", + "000000000000000000000033330000000000000000000000", + "000000000000000000000033330000000000000000000000", + "000000000000000000000033330000000000000000000000", + "000000000000000000000033330000000000000000000000" + ], + "points": { + "warp_0": [26, 26], + "warp_4": [36, 19] + }, + "warps": [ + { + "x": 26, + "y": 26, + "enter": "walk_into", + "to_map": "ViridianCity_PokemonCenter_1F", + "to_point": "warp_1" + }, + { + "x": 25, + "y": 11, + "enter": "walk_into" + }, + { + "x": 36, + "y": 10, + "enter": "walk_into" + }, + { + "x": 25, + "y": 18, + "enter": "walk_into" + }, + { + "x": 36, + "y": 19, + "enter": "walk_into", + "to_map": "ViridianCity_Mart", + "to_point": "warp_1" + } + ], + "objects": [ + { + "name": "fat_man", + "kind": "npc", + "x": 8, + "y": 26 + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 11, + "y": 24, + "hide_flag": "FLAG_TEMP_11" + }, + { + "name": "old_man_1", + "kind": "npc", + "x": 34, + "y": 11 + }, + { + "name": "var_0", + "kind": "npc", + "x": 21, + "y": 6 + }, + { + "name": "woman_3", + "kind": "npc", + "x": 20, + "y": 12 + }, + { + "name": "youngster", + "kind": "npc", + "x": 33, + "y": 26, + "wander": { + "x0": 33, + "y0": 24, + "x1": 33, + "y1": 28 + } + }, + { + "name": "boy", + "kind": "npc", + "x": 16, + "y": 22, + "wander": { + "x0": 15, + "y0": 20, + "x1": 17, + "y1": 24 + } + }, + { + "name": "cut_tree", + "kind": "npc", + "x": 18, + "y": 5, + "hide_flag": "FLAG_TEMP_12" + }, + { + "name": "item_ball", + "kind": "item", + "x": 17, + "y": 5, + "hide_flag": "FLAG_HIDE_VIRIDIAN_CITY_POTION" + } + ], + "flag_sets": {}, + "connections": [ + { + "side": "north", + "to_map": "Route2", + "offset": 12 + }, + { + "side": "south", + "to_map": "Route1", + "offset": 12 + }, + { + "side": "west", + "to_map": "Route22", + "offset": 10 + } + ] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json new file mode 100644 index 0000000000..1078ec3405 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_Mart.json @@ -0,0 +1,91 @@ +{ + "name": "ViridianCity_Mart", + "source": { + "decomp_file": "data/maps/ViridianCity_Mart/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "###########", + "###########", + "##.#......#", + "...#.......", + "####...##.#", + ".......##.#", + ".##....##.#", + "...........", + "###########" + ], + "elevation": [ + "00000000000", + "00000000000", + "00303333330", + "33003333333", + "00003330030", + "33333330030", + "30033330030", + "33333333333", + "00000000000" + ], + "points": { + "clerk_front": [4, 3], + "warp_1": [4, 7] + }, + "warps": [ + { + "x": 3, + "y": 7, + "enter": "walk_into", + "to_map": "ViridianCity", + "to_point": "warp_4" + }, + { + "x": 4, + "y": 7, + "enter": "walk_south", + "to_map": "ViridianCity", + "to_point": "warp_4" + }, + { + "x": 5, + "y": 7, + "enter": "walk_into", + "to_map": "ViridianCity", + "to_point": "warp_4" + } + ], + "objects": [ + { + "name": "clerk", + "kind": "npc", + "x": 2, + "y": 3 + }, + { + "name": "youngster", + "kind": "npc", + "x": 6, + "y": 2, + "wander": { + "x0": 5, + "y0": 1, + "x1": 7, + "y1": 3 + } + }, + { + "name": "woman_1", + "kind": "npc", + "x": 9, + "y": 5, + "wander": { + "x0": 9, + "y0": 4, + "x1": 9, + "y1": 6 + } + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json new file mode 100644 index 0000000000..63a2707d8f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianCity_PokemonCenter_1F.json @@ -0,0 +1,98 @@ +{ + "name": "ViridianCity_PokemonCenter_1F", + "source": { + "decomp_file": "data/maps/ViridianCity_PokemonCenter_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#.#############", + "###############", + "....###..##....", + "....#######....", + "...............", + "...............", + "#..........##..", + "...........##..", + "...............", + "###############" + ], + "elevation": [ + "030000000000000", + "000000000000000", + "333300033003333", + "333300000003333", + "333333333333333", + "330333333333333", + "044033333330033", + "330333333330033", + "333333333333333", + "000000000000000" + ], + "points": { + "nurse_front": [7, 4], + "warp_1": [7, 8] + }, + "warps": [ + { + "x": 6, + "y": 8, + "enter": "walk_into", + "to_map": "ViridianCity", + "to_point": "warp_0" + }, + { + "x": 7, + "y": 8, + "enter": "walk_south", + "to_map": "ViridianCity", + "to_point": "warp_0" + }, + { + "x": 8, + "y": 8, + "enter": "walk_into", + "to_map": "ViridianCity", + "to_point": "warp_0" + }, + { + "x": 1, + "y": 6, + "enter": "step_on" + } + ], + "objects": [ + { + "name": "nurse", + "kind": "npc", + "x": 7, + "y": 2 + }, + { + "name": "gentleman", + "kind": "npc", + "x": 12, + "y": 5 + }, + { + "name": "boy", + "kind": "npc", + "x": 4, + "y": 7 + }, + { + "name": "youngster", + "kind": "npc", + "x": 2, + "y": 3, + "wander": { + "x0": 1, + "y0": 2, + "x1": 3, + "y1": 4 + } + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json new file mode 100644 index 0000000000..93352339c5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/ViridianForest.json @@ -0,0 +1,201 @@ +{ + "name": "ViridianForest", + "source": { + "decomp_file": "data/maps/ViridianForest/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "######################################################", + "######################################################", + "######################################################", + "######################################################", + "######################################################", + "###########.............###........................###", + "###########.............###........................###", + "###########.............###........................###", + "#..#####..#.............###.....###############....###", + "####...####.............###.....###############....###", + "####...####.............###.....###############....###", + "####...####.....###.....###.....###############....###", + "####..S####~~~~~###~~~~~###~~~~~###############....###", + "###~~~~~###~~~~~###~~~~~###~~~~~###############....###", + "###~~~~~###~~~~~###~~~~~###~~~~~###############....###", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.............###", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.............###", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.............###", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~~.......#########", + "###~~~~~###~~~~~###~~~~~###~~~~~~~~~~........#########", + "###~~~~~###~~~~~###~~~~~###~~~~~~######......#########", + "###~~~~~###~~~~~###~~~~~###...~~~######......#########", + "###~~~~~###~~~~~###.....###......######......#########", + "###~~~~~###~~~~~###..............######......#########", + "###~~~~~###~~~~~#####............######......#########", + "###~~~~~###~~~~~#####............######............###", + "###~~~~~###~~~~~~~#####################....S.......###", + "###~~~~~...~~~~~~~#####################............###", + "###...............#####################............###", + "###......S........#####################~~~~........###", + "###...............#####################~~~~~###....###", + "###.....................###############~~~~~###....###", + "###.....................###############~~~~~###....###", + "###.....................###############~~~~~###....###", + "##################......###############~~~~~###....###", + "##################......###############~~~~~###....###", + "#######################################~~~~~###....###", + "#######################################~~~~~###....###", + "#######################################~~~~~###....###", + "###~~~~~~~~~~~~~~~#####################~~~~~###....###", + "###~~~~~~~~~~~~~~~#####################~~~~~###....###", + "###~~~~~~~~~~~~~~~#####################~~~~~###....###", + "###~~~~~~~~~~~~~~~#####################~~~~~###....###", + "###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~######~~~~........###", + "############~~~~~~~~~~~~~~~~S..~~######~~~.........###", + "############~~~~~~~~~~~~~~~~...~~######~~~.........###", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "############..~~~#########~~...~~######~~~...#########", + "###~~~~~~~~~..~~~~~~~~~~~~~~###~~~~~~~~~~~...~~~~~~###", + "###~~~~~~~~~..~~~~~~~~~~~~~~###~~~~~~~~~~~...~~~~~~###", + "###~~~~~~~~~...~~~~~~~~~~~~.###.~~~~~~~~~...~~~~~~~###", + "###~~~~~~~~~....~~~~~~~~~~.......~~~~~~~....~~~~~~~###", + "###~~~~~~~~............................S....~~~~~~~###", + "###~~~~~~~~....................S...........~~~~~~~~###", + "###~~~~~~~~................................~~~~~~~~###", + "###########################......#####################", + "######################################################", + "######################################################", + "######################################################", + "######################################################", + "######################################################", + "######################################################" + ], + "points": { + "warp_0": [29, 62], + "warp_2": [5, 9] + }, + "warps": [ + { + "x": 29, + "y": 62, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_3" + }, + { + "x": 28, + "y": 62, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_3" + }, + { + "x": 5, + "y": 9, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_1" + }, + { + "x": 6, + "y": 9, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_1" + }, + { + "x": 30, + "y": 62, + "enter": "walk_south", + "to_map": "Route2_ViridianForest_SouthEntrance", + "to_point": "warp_3" + }, + { + "x": 4, + "y": 9, + "enter": "cave_entrance", + "to_map": "Route2_ViridianForest_NorthEntrance", + "to_point": "warp_1" + } + ], + "objects": [ + { + "name": "youngster", + "kind": "npc", + "x": 29, + "y": 58 + }, + { + "name": "boy", + "kind": "npc", + "x": 45, + "y": 58 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 47, + "y": 45 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 47, + "y": 29 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 7, + "y": 22 + }, + { + "name": "item_ball", + "kind": "item", + "x": 5, + "y": 41, + "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_POKE_BALL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 40, + "y": 21, + "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_ANTIDOTE" + }, + { + "name": "item_ball", + "kind": "item", + "x": 21, + "y": 34, + "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_POTION" + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 43, + "y": 6 + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 16, + "y": 5 + }, + { + "name": "item_ball", + "kind": "item", + "x": 49, + "y": 60, + "hide_flag": "FLAG_HIDE_VIRIDIAN_FOREST_POTION_2" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp new file mode 100644 index 0000000000..e0fc1a339e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp @@ -0,0 +1,252 @@ +/* Overworld Map + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Exceptions.h" +#include "PokemonFRLG_OverworldMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +bool in_bounds(const MapData& map, const TilePos& point){ + return map.tiles.contains(point); +} +TileKind tile_at(const MapData& map, const TilePos& point){ + return in_bounds(map, point) ? map.tiles.at(point) : TileKind::WALL; +} +uint8_t elevation_at(const MapData& map, const TilePos& point){ + if (!in_bounds(map, point)){ + return ELEVATION_IGNORED; + } + return map.elevation ? map.elevation->at(point) : ELEVATION_GROUND; +} + +bool is_wall(const MapData& map, const TilePos& point){ + const TileKind tile = tile_at(map, point); + return tile == TileKind::WALL || tile == TileKind::DOOR || tile == TileKind::SIGN || is_ledge(map, point); +} +bool is_ledge(const MapData& map, const TilePos& point){ + switch (tile_at(map, point)){ + case TileKind::LEDGE_NORTH: + case TileKind::LEDGE_SOUTH: + case TileKind::LEDGE_WEST: + case TileKind::LEDGE_EAST: + return true; + default: + return false; + } +} +bool is_water(const MapData& map, const TilePos& point){ + return tile_at(map, point) == TileKind::WATER; +} +bool is_tall_grass(const MapData& map, const TilePos& point){ + return tile_at(map, point) == TileKind::TALL_GRASS; +} + +namespace{ + +// The tile closed on its `side` edge. +TileKind closed_side(Direction side){ + switch (side){ + case Direction::NORTH: + return TileKind::CLOSED_NORTH; + case Direction::SOUTH: + return TileKind::CLOSED_SOUTH; + case Direction::EAST: + return TileKind::CLOSED_EAST; + case Direction::WEST: + return TileKind::CLOSED_WEST; + } + return TileKind::WALL; +} +Direction opposite(Direction direction){ + switch (direction){ + case Direction::NORTH: + return Direction::SOUTH; + case Direction::SOUTH: + return Direction::NORTH; + case Direction::EAST: + return Direction::WEST; + case Direction::WEST: + return Direction::EAST; + } + return direction; +} + +// How the warp on this tile is entered, if there is one. +std::optional warp_entry(const MapData& map, const TilePos& point){ + const MapWarp* warp = warp_at(map, point); + if (warp == nullptr){ + return std::nullopt; + } + return warp->enter; +} + +} + +bool blocks_entering(const MapData& map, const TilePos& point, Direction direction){ + // Moving south enters by the north edge. + return tile_at(map, point) == closed_side(opposite(direction)); +} +bool blocks_leaving(const MapData& map, const TilePos& point, Direction direction){ + return tile_at(map, point) == closed_side(direction); +} + +bool warps_on_step(const MapData& map, const TilePos& point){ + const std::optional entry = warp_entry(map, point); + return entry == WarpEntry::STEP_ON || entry == WarpEntry::CAVE_ENTRANCE; +} +bool is_door(const MapData& map, const TilePos& point){ + return tile_at(map, point) == TileKind::DOOR; +} +std::optional exit_mat(const MapData& map, const TilePos& point){ + const std::optional entry = warp_entry(map, point); + if (!entry){ + return std::nullopt; + } + switch (*entry){ + case WarpEntry::WALK_NORTH: + return Direction::NORTH; + case WarpEntry::WALK_SOUTH: + return Direction::SOUTH; + case WarpEntry::WALK_WEST: + return Direction::WEST; + case WarpEntry::WALK_EAST: + return Direction::EAST; + default: + return std::nullopt; + } +} +bool walks_out_on_arrival(const MapData& map, const TilePos& point){ + return is_door(map, point) || warp_entry(map, point) == WarpEntry::CAVE_ENTRANCE; +} + +void hide_objects(MapData& map, const std::set& flags){ + std::vector shown; + for (const MapObject& object : map.objects){ + if (!object.hide_flag || flags.count(*object.hide_flag) == 0){ + shown.push_back(object); + } + } + map.objects = std::move(shown); +} + +namespace{ + +// The tiles `object` may stand on: its wander box, or its own tile. +Pokemon::TileBox standing_box(const MapObject& object){ + return object.wander.value_or( + Pokemon::TileBox{.x0 = object.x, .y0 = object.y, .x1 = object.x, .y1 = object.y} + ); +} + +// Whether `trainer`, standing on `from`, sees `tile` any way it looks. +bool sees_from(const MapData& map, const Pokemon::MapTrainer& trainer, const TilePos& from, const TilePos& tile){ + for (Direction look : trainer.looks){ + TilePos seen = from; + for (int c = 0; c < trainer.sight && !is_wall(map, seen.next(look)); c++){ + seen = seen.next(look); + if (seen == tile){ + return true; + } + } + } + return false; +} + +} + +const MapObject* object_at(const MapData& map, const TilePos& point){ + for (const MapObject& object : map.objects){ + const Pokemon::TileBox box = standing_box(object); + if (box.x0 <= point.x && point.x <= box.x1 && box.y0 <= point.y && point.y <= box.y1){ + return &object; + } + } + return nullptr; +} + +bool trainer_may_see(const MapData& map, const MapObject& object, const TilePos& tile){ + if (!object.trainer){ + return false; + } + const Pokemon::TileBox box = standing_box(object); + for (int y = box.y0; y <= box.y1; y++){ + for (int x = box.x0; x <= box.x1; x++){ + if (sees_from(map, *object.trainer, TilePos{x, y}, tile)){ + return true; + } + } + } + return false; +} + + + +StepKind classify_step(const MapData& map, const PlayerState& state, Direction direction){ + return classify_step_onto(map, state, direction, map, state.position.next(direction)); +} + +StepKind classify_step_onto( + const MapData& from, const PlayerState& state, Direction direction, + const MapData& to, const TilePos& destination +){ + if (is_wall(to, destination) + || blocks_leaving(from, state.position, direction) + || blocks_entering(to, destination, direction) + ){ + return StepKind::BLOCKED; + } + + const uint8_t level = elevation_at(to, destination); + const bool mismatch = state.elevation != ELEVATION_ANY + && level != ELEVATION_ANY && level != ELEVATION_IGNORED + && level != state.elevation; + if (mismatch){ + // CanStopSurfing() and IsPlayerFacingSurfableFishableWater(). + if (state.surfing && level == ELEVATION_GROUND && object_at(to, destination) == nullptr){ + return StepKind::STOP_SURFING; + } + if (!state.surfing && state.elevation == ELEVATION_GROUND && is_water(to, destination)){ + return StepKind::START_SURF; + } + return StepKind::BLOCKED; + } + + if (object_at(to, destination) != nullptr){ + return StepKind::BLOCKED; + } + return StepKind::WALK; +} + +PlayerState after_step(const MapData& map, const PlayerState& state, Direction direction, StepKind kind){ + return after_step_onto(map, state, map, state.position.next(direction), kind); +} + +PlayerState after_step_onto( + const MapData& from, const PlayerState& state, + const MapData& to, const TilePos& destination, StepKind kind +){ + PlayerState next = state; + next.position = destination; + const uint8_t level = elevation_at(to, destination); + if (level != ELEVATION_IGNORED && elevation_at(from, state.position) != ELEVATION_IGNORED){ + next.elevation = level; + } + if (kind == StepKind::START_SURF){ + next.surfing = true; + }else if (kind == StepKind::STOP_SURFING){ + next.surfing = false; + } + return next; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h new file mode 100644 index 0000000000..399d5f0537 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h @@ -0,0 +1,143 @@ +/* Overworld Map + * + * From: https://github.com/PokemonAutomation/ + * + * FRLG's walking rules on a map (a Pokemon::MapData): per tile collision, + * elevation and the behaviors that matter for walking (water, one-way + * edges), plus its warps and the objects standing on it. The map data is + * generated from the pret/pokefirered decompilation, and classify_step() + * follows the game's own collision checks (GetCollisionAtCoords() in + * src/event_object_movement.c), so a route planned on these maps is one the + * game allows. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldMap_H +#define PokemonAutomation_PokemonFRLG_OverworldMap_H + +#include +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "Pokemon/Navigation/Pokemon_MapData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +using Pokemon::Direction; +using Pokemon::TilePos; +using Pokemon::TileKind; +using Pokemon::MapData; +using Pokemon::MapWarp; +using Pokemon::MapObject; +using Pokemon::MapConnection; +using Pokemon::WarpEntry; +using Pokemon::warp_at; + + +// Elevations with a meaning of their own in the game's rules +// (IsElevationMismatchAt() and ObjectEventUpdateElevation() in +// pokefirered). +// Stairs and ladders: they join every elevation. +constexpr uint8_t ELEVATION_ANY = 0; +// Bridges and the like: they don't change the player's elevation. +constexpr uint8_t ELEVATION_IGNORED = 15; +// Ordinary ground: most walkable tiles in the decompilation's map layouts. +// Surf starts and ends here (CanStopSurfing(), and the Surf field move +// checks the player's elevation is 3). +constexpr uint8_t ELEVATION_GROUND = 3; + + +// How FRLG reads a map's tiles (Pokemon::TileKind) and warps: +// - WALL, DOOR, SIGN and the ledges are walls. A DOOR warps the player who +// walks north into it; a SIGN shows its message to the player who walks +// into it moving north or south (signposts, Center and Mart signs; +// pokefirered TrySetUpWalkIntoSignpostScript()). Ledges are hopped the +// way they face, which isn't modelled, so the planner avoids them. +// - WATER is entered only by starting to Surf. +// - CLOSED_ can't be entered or left through that side. +// - A warp entered by step_on (ladders, escalators) or cave_entrance warps +// the player who steps onto its tile; walk_ (exit mats, stairs +// at the side of a room) warps the player standing on it who walks that +// way. +// A map without an elevation grid is all ground. + +bool in_bounds(const MapData& map, const TilePos& point); +// Out-of-bounds tiles are walls. +TileKind tile_at(const MapData& map, const TilePos& point); +uint8_t elevation_at(const MapData& map, const TilePos& point); + +bool is_wall(const MapData& map, const TilePos& point); +bool is_water(const MapData& map, const TilePos& point); +bool is_tall_grass(const MapData& map, const TilePos& point); +bool is_ledge(const MapData& map, const TilePos& point); +// Whether the tile itself refuses a step in `direction`: entering it, or +// leaving it. +bool blocks_entering(const MapData& map, const TilePos& point, Direction direction); +bool blocks_leaving(const MapData& map, const TilePos& point, Direction direction); + +// Whether the game takes this tile's warp on stepping onto it (a ladder or +// cave entrance). +bool warps_on_step(const MapData& map, const TilePos& point); +// A door, entered by walking north into it. +bool is_door(const MapData& map, const TilePos& point); +// The direction that takes the exit mat on this tile, if it is one. +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 object standing, or maybe wandering, on this tile. +const MapObject* object_at(const MapData& map, const TilePos& point); + +// Whether `object`, a trainer, may see the player on `tile`: up to its +// sight ahead, any way it looks, short of a wall, from its tile or, for +// one who wanders, from any tile it may wander to. False for an object +// that isn't a trainer. +bool trainer_may_see(const MapData& map, const MapObject& object, const TilePos& tile); + +// Removes the objects the game hides once one of `flags` is set. +void hide_objects(MapData& map, const std::set& flags); + + +// What decides where the player's next step can go. +struct PlayerState{ + TilePos position; + uint8_t elevation = ELEVATION_GROUND; + bool surfing = false; +}; + +enum class StepKind{ + BLOCKED, + WALK, // moves one tile (on land, or on water while surfing) + STOP_SURFING, // moves from water onto land and stops surfing + START_SURF, // blocked, but facing water the player can Surf onto +}; + +// What pressing `direction` once does to the player in `state`. +StepKind classify_step(const MapData& map, const PlayerState& state, Direction direction); + +// The same for a step that crosses into another map: from `state` on `from` +// onto `destination` on `to`. +StepKind classify_step_onto( + const MapData& from, const PlayerState& state, Direction direction, + const MapData& to, const TilePos& destination +); + +// The player after a step of kind WALK, STOP_SURFING or START_SURF (the +// Surf action moves the player onto the water). +PlayerState after_step(const MapData& map, const PlayerState& state, Direction direction, StepKind kind); +PlayerState after_step_onto( + const MapData& from, const PlayerState& state, + const MapData& to, const TilePos& destination, StepKind kind +); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp new file mode 100644 index 0000000000..0f7514fe28 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp @@ -0,0 +1,118 @@ +/* Overworld Maps + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "PokemonFRLG_OverworldMaps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +const char* const MAP_NAMES[] = { + // From a new game to Brock. + "PalletTown", + "PalletTown_PlayersHouse_1F", + "PalletTown_PlayersHouse_2F", + "PalletTown_RivalsHouse", + "PalletTown_ProfessorOaksLab", + "Route1", + "ViridianCity", + "ViridianCity_Mart", + "ViridianCity_PokemonCenter_1F", + "Route22", + "Route2", + "Route2_ViridianForest_SouthEntrance", + "ViridianForest", + "Route2_ViridianForest_NorthEntrance", + "PewterCity", + "PewterCity_PokemonCenter_1F", + "PewterCity_Mart", + "PewterCity_Museum_1F", + "PewterCity_Gym", + // Cerulean Cave, for Mewtwo. + "CeruleanCity_PokemonCenter_1F", + "CeruleanCity", + "Route24", + "CeruleanCave_1F", + "CeruleanCave_2F", + "CeruleanCave_B1F", +}; + + +const std::vector& all_maps(){ + static const std::vector MAPS = []{ + std::vector maps; + for (const char* name : MAP_NAMES){ + maps.push_back(load_map(name)); + } + return maps; + }(); + return MAPS; +} + +} + + +MapData parse_map(const std::string& json, const std::string& source){ + return Pokemon::parse_map(parse_json(json), source); +} + +MapData load_map(const std::string& name){ + const std::string source = "Maps/" + name + ".json"; + const std::vector>& files = overworld_map_json(); + const auto file = std::find_if(files.begin(), files.end(), [&](const auto& item){ return item.first == name; }); + if (file == files.end()){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, source + " is not built into the program."); + } + MapData map = parse_map(file->second, source); + if (map.name != name){ + throw ParseException(source + ": name is \"" + map.name + "\", not \"" + name + "\"."); + } + return map; +} + +std::vector overworld_maps(const std::set& set_flags){ + std::vector maps = all_maps(); + for (MapData& map : maps){ + hide_objects(map, set_flags); + } + return maps; +} + +TilePos map_point(const std::vector& maps, const std::string& map, const std::string& point){ + for (const MapData& data : maps){ + if (data.name != map){ + continue; + } + const auto iter = data.points.find(point); + if (iter != data.points.end()){ + return iter->second; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No point \"" + point + "\" on map " + map + "."); +} + +std::set map_flag_set(const std::vector& maps, const std::string& name){ + std::set flags; + for (const MapData& map : maps){ + const auto iter = map.flag_sets.find(name); + if (iter != map.flag_sets.end()){ + flags.insert(iter->second.begin(), iter->second.end()); + } + } + return flags; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h new file mode 100644 index 0000000000..cff0668eb5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h @@ -0,0 +1,71 @@ +/* Overworld Maps + * + * From: https://github.com/PokemonAutomation/ + * + * The FRLG maps the overworld routes know about so far: every map from a + * new game in Pallet Town through Viridian City, Route 2 and Viridian + * Forest to Brock's gym in Pewter City; and Cerulean City, its Pokemon + * Center, Route 24 to its north, and the three floors of Cerulean Cave, + * where Mewtwo waits on B1F. + * + * Each map is a JSON file, Maps/.json next to this file, generated by + * devtools/maps/frlg_maps.py and built into the program by CMake + * (pa_embed_text_files() in cmake/EmbedTextFiles.cmake), so the program and + * its tests read the same copy. The schema is Pokemon::MapData's + * (Pokemon/Navigation/Pokemon_MapData.h). A warp leads to point + * "warp_" of its map, the tile of that map's warp n. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldMaps_H +#define PokemonAutomation_PokemonFRLG_OverworldMaps_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Reads a map from its JSON text (Pokemon::parse_map()). `source` names it +// in errors. Throws ParseException, naming the map and the field, if a field +// is missing or doesn't fit the schema. +MapData parse_map(const std::string& json, const std::string& source); + +// (name, JSON text) of each file in Maps/, sorted by name. Generated at +// build time. +// TODO: move the maps to PokemonAutomation/Packages (Resources/PokemonFRLG/Maps) when ready. +const std::vector>& overworld_map_json(); + +// Reads map `name` from overworld_map_json(). Throws InternalProgramError if +// it isn't built in, and ParseException as parse_map(). +MapData load_map(const std::string& name); + +// Every map, by its decompilation name ("CeruleanCity", "CeruleanCave_B1F", ...), +// with the objects the given event flags hide removed. The maps are parsed +// once, on the first call. +std::vector overworld_maps(const std::set& set_flags = {}); + +// Point `point` of map `map` among `maps`, e.g. ("CeruleanCave_B1F", +// "mewtwo"). Throws InternalProgramError if there is none. +TilePos map_point(const std::vector& maps, const std::string& map, const std::string& point); + +// The flags in flag set `name` of every map among `maps`, e.g. +// "after_hall_of_fame": the flags the Hall of Fame sets, which clear the way +// to Cerulean Cave. +std::set map_flag_set(const std::vector& maps, const std::string& name); + + +void add_tests_OverworldMaps(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp new file mode 100644 index 0000000000..b9c82f093f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp @@ -0,0 +1,258 @@ +/* Overworld Maps Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_OverworldMaps : public UnitTest{ +public: + Test_OverworldMaps(std::string name, std::function body) + : UnitTest("PokemonFRLG::OverworldMaps - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + + +const char* const VALID_MAP = R"({ + "name": "Test", + "source": {"decomp_file": "data/maps/Test/map.json", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#.w", "~D."], + "elevation": ["031", "3f3"], + "points": {"door": [1, 1]}, + "warps": [ + {"x": 1, "y": 1, "enter": "walk_into", "to_map": "Other", "to_point": "warp_2"}, + {"x": 2, "y": 1, "enter": "walk_south"} + ], + "objects": [{"name": "nurse", "kind": "npc", "x": 0, "y": 1, "wander": {"x0": 0, "y0": 1, "x1": 1, "y1": 1}, "hide_flag": "FLAG_X"}], + "flag_sets": {"later": ["FLAG_X", "FLAG_Y"]}, + "connections": [{"side": "south", "to_map": "Other", "offset": -4}] +})"; + +// The ParseException that parsing `json` throws, or empty if it doesn't. +std::string parse_error(const std::string& json){ + try{ + parse_map(json, "Test.json"); + }catch (ParseException& e){ + return e.message(); + } + return ""; +} + +// Whether `text` contains every one of `parts`. +bool mentions(const std::string& text, std::initializer_list parts){ + for (const char* part : parts){ + if (text.find(part) == std::string::npos){ + return false; + } + } + return true; +} + +UnitTestResult test_valid_map(){ + const MapData map = parse_map(VALID_MAP, "Test.json"); + if (map.name != "Test" || map.tiles.width != 3 || map.tiles.height != 2 + || map.tiles.at({0, 1}) != TileKind::TALL_GRASS || exit_mat(map, {2, 1}) != Direction::SOUTH + ){ + return "Wrong name, size or tiles."; + } + if (elevation_at(map, {2, 0}) != 1 || elevation_at(map, {1, 1}) != 15){ + return "Wrong elevation."; + } + const MapWarp* door = warp_at(map, {1, 1}); + if (map.warps.size() != 2 || door == nullptr || !door->to || door->to->map != "Other" || door->to->point != "warp_2"){ + return "Wrong warps."; + } + const MapObject* nurse = object_at(map, {1, 1}); + if (map.objects.size() != 1 || nurse == nullptr || nurse->name != "nurse" || nurse->hide_flag != "FLAG_X"){ + return "Wrong objects."; + } + const MapConnection& connection = map.connections.at(0); + if (connection.side != Direction::SOUTH || connection.offset != -4 || connection.to_map != "Other"){ + return "Wrong connections."; + } + if (map.points.at("door") != TilePos{1, 1} || map.flag_sets.at("later") != std::set{"FLAG_X", "FLAG_Y"}){ + return "Wrong points or flag sets."; + } + return true; +} + +UnitTestResult test_missing_field(){ + std::string json = VALID_MAP; + json.replace(json.find("\"tiles\""), 7, "\"cells\""); + const std::string error = parse_error(json); + if (!mentions(error, {"Test.json", "tiles", "missing"})){ + return "Expected an error naming the missing tiles, got: \"" + error + "\""; + } + return true; +} + +UnitTestResult test_elevation_left_out(){ + std::string json = VALID_MAP; + json.erase(json.find("\"elevation\""), std::string("\"elevation\": [\"031\", \"3f3\"],").size()); + const MapData map = parse_map(json, "Test.json"); + for (int y = 0; y < 2; y++){ + for (int x = 0; x < 3; x++){ + if (elevation_at(map, {x, y}) != ELEVATION_GROUND){ + return "Expected ground everywhere without an elevation grid."; + } + } + } + return true; +} + +UnitTestResult test_bad_field_type(){ + std::string json = VALID_MAP; + json.replace(json.find("\"x\": 1"), 6, "\"x\": \"1\""); + const std::string error = parse_error(json); + if (!mentions(error, {"Test.json", "warps[0]", "x", "integer"})){ + return "Expected an error naming warps[0].x, got: \"" + error + "\""; + } + return true; +} + +UnitTestResult test_bad_row_length(){ + std::string json = VALID_MAP; + json.replace(json.find("\"~D.\""), 5, "\"~D\""); + const std::string error = parse_error(json); + if (!mentions(error, {"Test.json", "tiles[1]", "string of 3 glyphs"})){ + return "Expected an error naming the short row, got: \"" + error + "\""; + } + return true; +} + +UnitTestResult test_unknown_tile(){ + std::string json = VALID_MAP; + json.replace(json.find("\"#.w\""), 5, "\"#.?\""); + const std::string error = parse_error(json); + if (!mentions(error, {"Test.json", "tiles[0]", "unknown glyph '?'", "(2, 0)"})){ + return "Expected an error naming the unknown tile, got: \"" + error + "\""; + } + return true; +} + +// Route 3's Lass Robin, shrunk: she wanders x 2, y 2..4 looking north and +// south, sight 3, below a corridor (row 1) walled off at x 2 above it; a +// bug catcher at (5, 4) looks west, sight 2. +const char* const TRAINERS_MAP = R"({ + "name": "Trainers", + "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, + "tiles": ["##.####", ".......", ".......", ".......", ".......", "~~~~~~~"], + "objects": [ + {"name": "lass", "kind": "npc", "x": 2, "y": 3, "wander": {"x0": 2, "y0": 2, "x1": 2, "y1": 4}, "trainer": {"sight": 3, "looks": ["north", "south"]}}, + {"name": "bug_catcher", "kind": "npc", "x": 5, "y": 4, "facing": "west", "trainer": {"sight": 2}}, + {"name": "youngster", "kind": "npc", "x": 6, "y": 1} + ] +})"; + +// A wanderer sees from every tile she may stand on, short of a wall; a +// trainer standing still only along his facing; a non-trainer nothing. +UnitTestResult test_trainer_sight(){ + const MapData map = parse_map(TRAINERS_MAP, "Trainers.json"); + const MapObject& lass = map.objects[0]; + const MapObject& bug_catcher = map.objects[1]; + const MapObject& youngster = map.objects[2]; + struct Case{ + const MapObject* object; + TilePos tile; + bool sees; + }; + const Case cases[] = { + {&lass, {2, 1}, true}, // from (2, 2..4), north + {&lass, {2, 0}, true}, // the gap in the wall, 2 tiles up from (2, 2) + {&lass, {2, 5}, true}, // south, from (2, 4) + {&lass, {1, 1}, false}, + {&bug_catcher, {3, 4}, true}, + {&bug_catcher, {2, 4}, false}, // past his sight + {&bug_catcher, {5, 3}, false}, // not his way + {&youngster, {5, 1}, false}, + }; + for (const Case& c : cases){ + if (trainer_may_see(map, *c.object, c.tile) != c.sees){ + return c.object->name + (c.sees ? " should see " : " shouldn't see ") + Pokemon::to_string(c.tile) + "."; + } + } + return true; +} + +UnitTestResult test_not_json(){ + const std::string error = parse_error("{\"name\": "); + if (!mentions(error, {"Test.json", "not a JSON object"})){ + return "Expected an error for broken JSON, got: \"" + error + "\""; + } + return true; +} + +// A hall with an escalator at (1, 2) to a floor that isn't loaded, like +// Route 4's Pokemon Center. +const char* const ESCALATOR_HALL = R"({ + "name": "Hall", "source": {"decomp_file": "", "revision": "test", "date": "2026-11-02"}, + "tiles": ["######", "#....#", "#....#", "######"], + "warps": [{"x": 1, "y": 2, "enter": "step_on"}] +})"; + +// Holding west along the escalator's row rides it: a leg there ends by +// counting tiles, never by holding to the wall behind it (console B, +// 2026-11-02, Route 4's Pokemon Center). +UnitTestResult test_no_hold_onto_escalator(){ + const std::vector maps{parse_map(ESCALATOR_HALL, "Hall")}; + if (hold_to_wall(maps, {"Hall", {4, 2}}, false, Direction::WEST)){ + return "Expected no hold west along the escalator's row."; + } + const std::optional> route = plan_overworld_route(maps, {"Hall", {4, 2}}, {{"Hall", {2, 1}}, std::nullopt}); + if (!route || !(follow_overworld_route(maps, {"Hall", {4, 2}}, *route) == MapPosition{"Hall", {2, 1}})){ + return "Expected a route from (4, 2) to (2, 1)."; + } + for (const RouteStep& step : *route){ + if (step.to_wall && step.direction == Direction::WEST && step.end.point == TilePos{2, 2}){ + return "Expected no hold west next to the escalator: " + to_string(step); + } + } + return true; +} + +} + + +void add_tests_OverworldMaps(UnitTestDatabase& database){ + database.add("valid map", test_valid_map); + database.add("missing field", test_missing_field); + database.add("elevation left out", test_elevation_left_out); + database.add("field of the wrong type", test_bad_field_type); + database.add("row of the wrong length", test_bad_row_length); + database.add("unknown tile", test_unknown_tile); + database.add("not JSON", test_not_json); + database.add("trainer sight", test_trainer_sight); + database.add("no hold onto an escalator", test_no_hold_onto_escalator); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp new file mode 100644 index 0000000000..6e63bc8ed4 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp @@ -0,0 +1,993 @@ +/* Overworld Route + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/Navigation/Pokemon_LegPlanner.h" +#include "PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +std::string to_string(const MapPosition& position){ + return position.map + " " + to_string(position.point); +} + +std::string to_string(const RouteStep& step){ + std::string text; + switch (step.action){ + case RouteAction::WALK: + text = std::format("walk {} {}", direction_name(step.direction), step.tiles); + if (step.warps){ + text += " (warp)"; + } + if (step.to_wall){ + text += " (to wall)"; + } + break; + case RouteAction::SURF: + text = "surf " + std::string(direction_name(step.direction)); + break; + case RouteAction::FACE: + text = "face " + std::string(direction_name(step.direction)); + break; + } + return text + " -> " + to_string(step.end); +} + + + +const RouteCosts& default_route_costs(){ + static const RouteCosts COSTS{ + {RouteCost::TILE, 1}, + {RouteCost::TURN, 2}, + {RouteCost::WARP, 30}, + {RouteCost::SURF, 40}, + {RouteCost::GRASS_TILE, 20}, + {RouteCost::OPEN_STOP, 8}, + {RouteCost::OPEN_WILD_STOP, 300}, + }; + return COSTS; +} + +int route_cost(const RouteCosts& costs, RouteCost kind){ + auto iter = costs.find(kind); + if (iter == costs.end()){ + iter = default_route_costs().find(kind); + } + return iter->second; +} + + + +namespace{ + + +int find_map(const std::vector& maps, const std::string& name){ + for (size_t c = 0; c < maps.size(); c++){ + if (maps[c].name == name){ + return (int)c; + } + } + return -1; +} + +// The player on one of the loaded maps. +struct Located{ + int map = 0; + PlayerState state; + + bool operator==(const Located& other) const{ + return map == other.map + && state.position == other.state.position + && state.elevation == other.state.elevation + && state.surfing == other.state.surfing; + } +}; +struct LocatedHash{ + size_t operator()(const Located& player) const{ + return (((std::hash()(player.state.position) * 31 + player.map) * 16 + + player.state.elevation) * 2) + (player.state.surfing ? 1 : 0); + } +}; + +// What pressing a direction once does to the player. +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 + bool dismounted = false; // stepped off the water onto land +}; + +// The player taking `warp`, or nothing if it leads off the loaded maps. +std::optional take_warp(const std::vector& maps, const MapWarp* warp){ + if (warp == nullptr || !warp->to){ + return std::nullopt; + } + const int destination = find_map(maps, warp->to->map); + if (destination < 0){ + return std::nullopt; + } + const MapData& map = maps[destination]; + const auto arrival = map.points.find(warp->to->point); + if (arrival == map.points.end()){ + return std::nullopt; + } + TilePos position = arrival->second; + Transition transition; + 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}; + transition.warped = true; + return transition; +} + +// Walking off the map's edge onto the map connected there, if it is loaded. +std::optional cross_edge(const std::vector& maps, const Located& player, Direction direction){ + const MapData& map = maps[player.map]; + for (const MapConnection& connection : map.connections){ + if (connection.side != direction){ + continue; + } + const int destination = find_map(maps, connection.to_map); + if (destination < 0){ + return std::nullopt; + } + const MapData& to = maps[destination]; + const TilePos here = player.state.position; + TilePos point; + switch (direction){ + case Direction::NORTH: + point = {here.x - connection.offset, to.tiles.height - 1}; + break; + case Direction::SOUTH: + point = {here.x - connection.offset, 0}; + break; + case Direction::WEST: + point = {to.tiles.width - 1, here.y - connection.offset}; + break; + case Direction::EAST: + point = {0, here.y - connection.offset}; + break; + } + const StepKind kind = classify_step_onto(map, player.state, direction, to, point); + if (kind == StepKind::BLOCKED){ + return std::nullopt; + } + Transition transition; + transition.next.map = destination; + transition.next.state = after_step_onto(map, player.state, to, point, kind); + transition.action = kind == StepKind::START_SURF ? RouteAction::SURF : RouteAction::WALK; + transition.dismounted = kind == StepKind::STOP_SURFING; + return transition; + } + return std::nullopt; +} + +// Pressing `direction` once (field_control_avatar.c): an exit mat or a door +// warps without the player moving, a step onto a ladder or cave entrance +// warps after it, and anything else is a step by the collision rules. +std::optional press(const std::vector& maps, const Located& player, Direction direction){ + const MapData& map = maps[player.map]; + const TilePos here = player.state.position; + if (exit_mat(map, here) == direction){ + return take_warp(maps, warp_at(map, here)); + } + const TilePos ahead = here.next(direction); + if (direction == Direction::NORTH && is_door(map, ahead) && !player.state.surfing){ + return take_warp(maps, warp_at(map, ahead)); + } + + if (!in_bounds(map, ahead)){ + return cross_edge(maps, player, direction); + } + + const StepKind kind = classify_step(map, player.state, direction); + if (kind == StepKind::BLOCKED){ + return std::nullopt; + } + Transition transition; + transition.next = player; + transition.next.state = after_step(map, player.state, direction, kind); + transition.action = kind == StepKind::START_SURF ? RouteAction::SURF : RouteAction::WALK; + transition.dismounted = kind == StepKind::STOP_SURFING; + const TilePos landed = transition.next.state.position; + if (transition.action == RouteAction::WALK && warps_on_step(map, landed) && warp_at(map, landed) != nullptr){ + return take_warp(maps, warp_at(map, landed)); + } + return transition; +} + +// Whether pressing `direction` takes a warp to a map that isn't loaded, +// which press() refuses as if it were a wall. +bool warps_off_loaded_maps(const std::vector& maps, const Located& player, Direction direction){ + const MapData& map = maps[player.map]; + const TilePos here = player.state.position; + const TilePos ahead = here.next(direction); + const MapWarp* warp = nullptr; + if (exit_mat(map, here) == direction){ + warp = warp_at(map, here); + }else if (direction == Direction::NORTH && is_door(map, ahead) && !player.state.surfing){ + warp = warp_at(map, ahead); + }else if (in_bounds(map, ahead) && warps_on_step(map, ahead) && classify_step(map, player.state, direction) != StepKind::BLOCKED){ + warp = warp_at(map, ahead); + } + return warp != nullptr && !take_warp(maps, warp); +} + +// Whether holding `direction` stops the player where they are: a wall, or +// water they'd need to Surf onto. A leg that ends there can be +// held for longer than it takes, and walked again after an interruption. A +// person in the way doesn't count, since they may have wandered off, and +// neither does an edge to a map that isn't loaded. +bool stops_at(const std::vector& maps, const Located& player, Direction direction){ + const std::optional transition = press(maps, player, direction); + if (transition){ + return transition->action == RouteAction::SURF; + } + // Nor does a warp to a map that isn't loaded: the player takes it (console + // B, 2026-11-02, "west 5 (to wall)" rode Route 4's Pokemon Center + // escalator up to 2F). + if (warps_off_loaded_maps(maps, player, direction)){ + return false; + } + const MapData& map = maps[player.map]; + const TilePos ahead = player.state.position.next(direction); + // Held into a sign moving north or south, the game shows the sign's + // message: the player stops, but the walk is interrupted (console B, + // 2026-11-01, the poster on the bedroom's wall). + if (tile_at(map, ahead) == TileKind::SIGN && (direction == Direction::NORTH || direction == Direction::SOUTH)){ + return false; + } + // Held into a ledge the way it faces, the player hops down it (console + // B, 2026-11-01, Viridian City: "south 2 (to wall)" from the Pokemon + // Center hopped the ledge two rows down). Routes don't hop ledges, so + // none is held into. + if (is_ledge(map, ahead)){ + return false; + } + if (in_bounds(map, ahead)){ + return object_at(map, ahead) == nullptr; + } + for (const MapConnection& connection : map.connections){ + if (connection.side == direction){ + return false; + } + } + return true; +} + +// The search state: a player, the way they face (4 stands for "not known +// yet", before the first step), and whether they are in the middle of a leg +// that could go on, as opposed to just stopped by a warp or Surf. +// The game's step rules for the shared leg planner. +class StepModel{ +public: + using State = Located; + using StateHash = LocatedHash; + + StepModel(const std::vector& maps, const RouteCosts& costs) + : m_maps(maps) + , m_costs(costs) + {} + + std::optional> press(const State& state, Direction direction) const{ + const std::optional transition = PokemonFRLG::press(m_maps, state, direction); + if (!transition){ + return std::nullopt; + } + Pokemon::Step step; + step.next = transition->next; + step.action = transition->action == RouteAction::SURF ? ACTION_SURF : 0; + // Leaving the water: the player walks at half the speed from here. + step.starts_leg = transition->dismounted; + step.ends_leg = transition->warped || transition->dismounted; + step.warped = transition->warped; + step.facing = transition->walked_out ? Direction::SOUTH : direction; + if (transition->action == RouteAction::SURF){ + step.extra_cost += route_cost(m_costs, RouteCost::SURF); + } + if (transition->warped){ + step.extra_cost += route_cost(m_costs, RouteCost::WARP); + } + if (is_tall_grass(m_maps[step.next.map], step.next.state.position)){ + step.extra_cost += route_cost(m_costs, RouteCost::GRASS_TILE); + step.wild = true; + } + if (step.next.state.surfing){ + step.wild = true; + } + return step; + } + bool held_at(const State& state, Direction direction) const{ + return stops_at(m_maps, state, direction); + } + + static constexpr int ACTION_SURF = 1; + +private: + const std::vector& m_maps; + const RouteCosts& m_costs; +}; + +Pokemon::LegCosts to_leg_costs(const RouteCosts& costs){ + Pokemon::LegCosts leg_costs; + leg_costs.per_tile = route_cost(costs, RouteCost::TILE); + leg_costs.per_turn = route_cost(costs, RouteCost::TURN); + leg_costs.per_open_stop = route_cost(costs, RouteCost::OPEN_STOP); + leg_costs.per_open_wild_stop = route_cost(costs, RouteCost::OPEN_WILD_STOP); + return leg_costs; +} + +RouteStep to_route_step(const std::vector& maps, const Pokemon::Leg& leg){ + RouteStep step; + switch (leg.kind){ + case Pokemon::LegKind::WALK: + step.action = RouteAction::WALK; + break; + case Pokemon::LegKind::ACTION: + step.action = RouteAction::SURF; + break; + case Pokemon::LegKind::FACE: + step.action = RouteAction::FACE; + break; + } + step.direction = leg.direction; + step.tiles = leg.kind == Pokemon::LegKind::FACE ? 0 : leg.tiles; + step.warps = leg.warps; + step.surfing = leg.start.state.surfing; + step.to_wall = leg.to_wall; + step.facing_after = leg.facing_after; + step.end = MapPosition{maps[leg.end.map].name, leg.end.state.position}; + if (leg.kind != Pokemon::LegKind::FACE){ + // Tall grass on any map the leg crosses, or the water. Counted on the + // start map only, "north 22" from Pallet Town through Route 1's grass + // wasn't watched for battles (console B, 2026-11-01). + step.wild = leg.wild || leg.start.state.surfing || leg.kind == Pokemon::LegKind::ACTION; + } + return step; +} + +} + + + +std::optional> plan_overworld_route( + const std::vector& maps, + const MapPosition& start, + const RouteGoal& goal, + const RouteCosts& costs, + std::optional start_facing +){ + const int start_map = find_map(maps, start.map); + const int goal_map = find_map(maps, goal.position.map); + if (start_map < 0 || goal_map < 0){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Route between maps that aren't loaded."); + } + Located first; + first.map = start_map; + first.state.position = start.point; + first.state.elevation = elevation_at(maps[start_map], start.point); + first.state.surfing = is_water(maps[start_map], start.point); + + const StepModel model(maps, costs); + const auto legs = Pokemon::plan_legs( + model, first, start_facing, + std::function([&](const Located& player){ + return player.map == goal_map && player.state.position == goal.position.point; + }), + goal.facing, to_leg_costs(costs) + ); + if (!legs){ + return std::nullopt; + } + + std::vector route; + for (const Pokemon::Leg& leg : *legs){ + route.push_back(to_route_step(maps, leg)); + } + return route; +} + + +namespace{ + +// Further than any straight line on a map. +constexpr int MAX_HOLD_TILES = 128; + +std::optional locate(const std::vector& maps, const MapPosition& position, bool surfing){ + const int map = find_map(maps, position.map); + if (map < 0){ + return std::nullopt; + } + Located player; + player.map = map; + player.state = PlayerState{position.point, elevation_at(maps[map], position.point), surfing}; + return player; +} + +// A plain step: no warp, no Surf, no getting off the water. +std::optional plain_step(const std::vector& maps, const Located& player, Direction direction){ + const std::optional transition = press(maps, player, direction); + if (!transition || transition->warped || transition->dismounted || transition->action != RouteAction::WALK){ + return std::nullopt; + } + return transition->next; +} + +} + + +namespace{ + +// Holding north into a ledge stops the player: the maps don't keep which way +// a ledge faces, but FRLG's face south, east or west (pokefirered has no +// MB_JUMP_NORTH on any map these load). Only finding the player again +// relies on this; routes never hold into a ledge (stops_at()). +bool ledge_stops_north(const std::vector& maps, const Located& player, Direction direction){ + return direction == Direction::NORTH && is_ledge(maps[player.map], player.state.position.next(direction)); +} + +} + +std::optional hold_to_wall( + const std::vector& maps, + const MapPosition& from, bool surfing, Direction direction +){ + std::optional player = locate(maps, from, surfing); + WallHold hold; + for (int c = 0; player && c <= MAX_HOLD_TILES; c++){ + if (stops_at(maps, *player, direction) || ledge_stops_north(maps, *player, direction)){ + hold.end = MapPosition{maps[player->map].name, player->state.position}; + hold.tiles = c; + return hold; + } + player = plain_step(maps, *player, direction); + if (player){ + const MapData& map = maps[player->map]; + hold.wild = hold.wild || is_tall_grass(map, player->state.position) || player->state.surfing; + } + } + return std::nullopt; +} + +std::vector leg_tiles( + const std::vector& maps, + const MapPosition& start, const RouteStep& step +){ + std::vector tiles{start}; + std::optional player = locate(maps, start, step.surfing); + const int along = step.tiles - (step.warps ? 1 : 0); + for (int c = 0; player && c < along; c++){ + player = plain_step(maps, *player, step.direction); + if (player){ + tiles.push_back(MapPosition{maps[player->map].name, player->state.position}); + } + } + return tiles; +} + +MapPosition follow_overworld_route( + const std::vector& maps, + const MapPosition& start, + const std::vector& route +){ + Located player; + player.map = find_map(maps, start.map); + if (player.map < 0){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Route from a map that isn't loaded: " + start.map); + } + player.state.position = start.point; + player.state.elevation = elevation_at(maps[player.map], start.point); + player.state.surfing = is_water(maps[player.map], start.point); + + for (const RouteStep& step : route){ + if (step.action == RouteAction::FACE){ + continue; + } + for (int c = 0; c < step.tiles; c++){ + const std::optional transition = press(maps, player, step.direction); + if (!transition || transition->action != step.action){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Step refused at " + to_string(MapPosition{maps[player.map].name, player.state.position}) + ": " + to_string(step) + ); + } + player = transition->next; + } + const MapPosition position{maps[player.map].name, player.state.position}; + if (!(position == step.end)){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Ended at " + to_string(position) + " instead of " + to_string(step.end) + ); + } + } + return MapPosition{maps[player.map].name, player.state.position}; +} + + + +namespace{ + +class Test_OverworldRoute : public UnitTest{ +public: + Test_OverworldRoute(std::string name, std::function body) + : UnitTest("PokemonFRLG::OverworldRoute - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +std::string describe(const std::vector& route){ + std::string text; + for (const RouteStep& step : route){ + text += "\n " + to_string(step); + } + return text; +} + +// A 5x4 map for the step rules: a pond, a raised ledge reached by a stair +// tile, and a tile that can't be entered moving south. +const MapData& small_map(){ + static const MapData MAP = parse_map(R"({ + "name": "Small", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#####", "#.8.#", "#.w.#", "#####"], + "elevation": ["33333", "33403", "33133", "33333"] + })", "Small"); + return MAP; +} + +UnitTestResult test_step_rules(){ + const MapData& map = small_map(); + PlayerState state{{1, 1}, 3, false}; + if (classify_step(map, state, Direction::EAST) != StepKind::BLOCKED){ + return "Walked from elevation 3 onto elevation 4."; + } + if (classify_step(map, PlayerState{{2, 0}, 3, false}, Direction::SOUTH) != StepKind::BLOCKED){ + return "Entered a north-blocked tile moving south."; + } + state = PlayerState{{1, 2}, 3, false}; + if (classify_step(map, state, Direction::EAST) != StepKind::START_SURF){ + return "Can't start surfing onto the pond."; + } + state = after_step(map, state, Direction::EAST, StepKind::START_SURF); + if (!state.surfing || state.elevation != 1){ + return "Surfing didn't put the player on the water."; + } + if (classify_step(map, state, Direction::EAST) != StepKind::STOP_SURFING){ + return "Can't land from the pond."; + } + if (classify_step(map, PlayerState{{3, 2}, 3, false}, Direction::NORTH) != StepKind::WALK){ + return "Can't step from elevation 3 onto the elevation-0 stair."; + } + return true; +} + +// The maps after the Hall of Fame, which clears the way to Cerulean Cave. +std::vector post_game_maps(){ + return overworld_maps(map_flag_set(overworld_maps(), "after_hall_of_fame")); +} + +MapPosition point_on(const std::vector& maps, const std::string& map, const std::string& point){ + return MapPosition{map, map_point(maps, map, point)}; +} + +const MapData* map_named(const std::vector& maps, const std::string& name){ + const int index = find_map(maps, name); + return index < 0 ? nullptr : &maps[index]; +} + +UnitTestResult test_maps(){ + const std::vector maps = post_game_maps(); + const MapData* b1f = map_named(maps, "CeruleanCave_B1F"); + const MapData* city = map_named(maps, "CeruleanCity"); + if (b1f == nullptr || city == nullptr || map_named(maps, "CeruleanCity_PokemonCenter_1F") == nullptr){ + return "Missing a map."; + } + if (b1f->tiles.width != 40 || b1f->tiles.height != 23 || city->tiles.width != 48 || city->tiles.height != 40){ + return "Unexpected map size."; + } + const TilePos mewtwo_tile = map_point(maps, "CeruleanCave_B1F", "mewtwo"); + const MapObject* mewtwo = object_at(*b1f, mewtwo_tile); + if (mewtwo == nullptr || mewtwo->name != "mewtwo"){ + return "Mewtwo is not on B1F at " + to_string(mewtwo_tile) + "."; + } + if (object_at(*city, {1, 13}) != nullptr){ + return "The cave guard is still there after the Hall of Fame."; + } + if (object_at(*map_named(overworld_maps(), "CeruleanCity"), {1, 13}) == nullptr){ + return "The cave guard is missing before the Hall of Fame."; + } + return true; +} + +// Plans `start` to `goal`, replays it with the step rules and checks where it ends. +UnitTestResult check_route( + const std::vector& maps, + const MapPosition& start, const RouteGoal& goal, + std::vector& route +){ + const std::optional> planned = plan_overworld_route(maps, start, goal); + if (!planned){ + return "No route from " + to_string(start) + " to " + to_string(goal.position) + "."; + } + route = *planned; + const MapPosition end = follow_overworld_route(maps, start, route); + if (!(end == goal.position)){ + return "Route ends at " + to_string(end) + ":" + describe(route); + } + if (goal.facing && route.back().direction != *goal.facing){ + return "Doesn't end facing " + std::string(direction_name(*goal.facing)) + ":" + describe(route); + } + return true; +} + +// Below Mewtwo, facing it, to talk to it. +RouteGoal facing_mewtwo(const std::vector& maps){ + const TilePos mewtwo = map_point(maps, "CeruleanCave_B1F", "mewtwo"); + return RouteGoal{{"CeruleanCave_B1F", mewtwo.next(Direction::SOUTH)}, Direction::NORTH}; +} + +UnitTestResult test_entrance_to_mewtwo(){ + const std::vector maps = post_game_maps(); + std::vector route; + UnitTestResult result = check_route(maps, point_on(maps, "CeruleanCave_1F", "entrance"), facing_mewtwo(maps), route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + bool surfs = false; + bool reaches_b1f = false; + for (const RouteStep& step : route){ + surfs |= step.action == RouteAction::SURF; + reaches_b1f |= step.warps && step.end.map == "CeruleanCave_B1F"; + } + if (!surfs || !reaches_b1f){ + return "Expected to take the ladder to B1F and to surf:" + describe(route); + } + return true; +} + +UnitTestResult test_pokemon_center_to_mewtwo(){ + const std::vector maps = post_game_maps(); + std::vector route; + UnitTestResult result = check_route( + maps, point_on(maps, "CeruleanCity_PokemonCenter_1F", "pc"), facing_mewtwo(maps), route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + // Out through the exit mat, onto the city's step below the door, and + // into the cave by its entrance. + std::vector maps_in_order; + for (const RouteStep& step : route){ + if (step.warps){ + maps_in_order.push_back(step.end.map); + } + } + if (maps_in_order.size() < 2 || maps_in_order[0] != "CeruleanCity" || maps_in_order[1] != "CeruleanCave_1F"){ + return "Expected to leave by the mat and enter the cave next:" + describe(route); + } + if (!(route[0].end.map == "CeruleanCity_PokemonCenter_1F" || route[0].warps)){ + return "Unexpected first step:" + describe(route); + } + return true; +} + +UnitTestResult test_cave_guard_blocks(){ + // Before the Hall of Fame the guard stands in the cave entrance. + const std::vector maps = overworld_maps(); + if (plan_overworld_route(maps, point_on(maps, "CeruleanCity_PokemonCenter_1F", "pc"), facing_mewtwo(maps))){ + return "Planned past the cave guard."; + } + return true; +} + +UnitTestResult test_mewtwo_tile_unreachable(){ + const std::vector maps = post_game_maps(); + const std::optional> route = plan_overworld_route( + maps, + point_on(maps, "CeruleanCave_1F", "entrance"), + {point_on(maps, "CeruleanCave_B1F", "mewtwo"), std::nullopt} + ); + if (route){ + return "Planned a route onto Mewtwo itself:" + describe(*route); + } + return true; +} + +UnitTestResult test_story_maps(){ + const std::vector maps = overworld_maps(); + for (const char* name : { + "PalletTown_PlayersHouse_2F", "PalletTown_ProfessorOaksLab", "Route1", "ViridianCity_Mart", + "Route22", "Route2", "ViridianForest", "PewterCity", "PewterCity_Museum_1F", "PewterCity_Gym", + }){ + if (map_named(maps, name) == nullptr){ + return std::string("Missing map ") + name + "."; + } + } + return true; +} + +// Which maps `route` warps into, in order. +std::vector maps_warped_into(const std::vector& route){ + std::vector maps; + for (const RouteStep& step : route){ + if (step.warps){ + maps.push_back(step.end.map); + } + } + return maps; +} + +UnitTestResult test_bedroom_to_oaks_lab(){ + const std::vector maps = overworld_maps(); + std::vector route; + UnitTestResult result = check_route( + maps, point_on(maps, "PalletTown_PlayersHouse_2F", "start"), + {point_on(maps, "PalletTown", "oaks_lab_front"), Direction::NORTH}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + const std::vector warped = maps_warped_into(route); + if (warped != std::vector{"PalletTown_PlayersHouse_1F", "PalletTown"}){ + return "Expected to take the stairs and leave by the front door:" + describe(route); + } + return true; +} + +UnitTestResult test_viridian_mart_to_pewter_gym(){ + const std::vector maps = overworld_maps(); + std::vector route; + UnitTestResult result = check_route( + maps, point_on(maps, "ViridianCity_Mart", "clerk_front"), + {point_on(maps, "PewterCity", "gym_front"), Direction::NORTH}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + const std::vector warped = maps_warped_into(route); + if (std::find(warped.begin(), warped.end(), "ViridianForest") == warped.end()){ + return "Expected to go through Viridian Forest:" + describe(route); + } + return true; +} + +// A room with a sign on its north wall, above the third column. +const char* const TEST_SIGN_ROOM_JSON = R"({ + "name": "SignRoom", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["##S##", "#...#", "#...#", "#...#", "#####"], + "elevation": ["33333", "33333", "33333", "33333", "33333"] +})"; + +// Walking north under a sign stops by counting tiles, never by holding into +// the sign; under the wall beside it, the wall stops the player. +UnitTestResult test_no_hold_into_sign(){ + const std::vector maps{parse_map(TEST_SIGN_ROOM_JSON, "SignRoom")}; + std::vector route; + UnitTestResult result = check_route(maps, {"SignRoom", {2, 3}}, {{"SignRoom", {2, 1}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.to_wall && step.end.point == TilePos{2, 1}){ + return "Expected no hold into the sign:" + describe(route); + } + } + route.clear(); + result = check_route(maps, {"SignRoom", {1, 3}}, {{"SignRoom", {1, 1}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + if (route.empty() || !route.back().to_wall){ + return "Expected the wall to stop the player beside the sign:" + describe(route); + } + return true; +} + +// A yard with a row of ledges across it. +const char* const TEST_LEDGE_YARD_JSON = R"({ + "name": "LedgeYard", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#####", "#...#", "#...#", "#vvv#", "#...#", "#####"], + "elevation": ["33333", "33333", "33333", "33333", "33333", "33333"] +})"; + +// A ledge isn't a wall to hold into: moving the way it faces the player +// would hop it, and routes don't hop ledges. Viridian City, +// from the Pokemon Center's door south to the row above the ledge. +UnitTestResult test_no_hold_into_ledge(){ + const std::vector maps{parse_map(TEST_LEDGE_YARD_JSON, "LedgeYard")}; + std::vector route; + UnitTestResult result = check_route(maps, {"LedgeYard", {2, 1}}, {{"LedgeYard", {2, 2}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.to_wall){ + return "Expected no hold into the ledge:" + describe(route); + } + } + route.clear(); + const std::vector world = overworld_maps(); + result = check_route(world, {"ViridianCity", {26, 27}}, {{"ViridianCity", {26, 29}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.to_wall && step.end.point == TilePos{26, 29}){ + return "Expected no hold into the ledge below the Pokemon Center:" + describe(route); + } + } + return true; +} + +// Two small maps that don't need the map files: a room left by the exit mat +// at its bottom, onto the door of a yard, out of which the game walks the +// player. +// No wild battle can start between the bedroom and Oak's Lab: Pallet Town's +// streets have no tall grass. Route 2 and Viridian Forest do. +UnitTestResult test_wild_steps(){ + const std::vector maps = overworld_maps(); + std::vector route; + UnitTestResult result = check_route( + maps, point_on(maps, "PalletTown_PlayersHouse_2F", "start"), + {point_on(maps, "PalletTown", "oaks_lab_front"), Direction::NORTH}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.wild){ + return "Expected no wild step from the bedroom to Oak's Lab, got " + to_string(step) + ":" + describe(route); + } + } + route.clear(); + result = check_route( + maps, point_on(maps, "ViridianCity_Mart", "clerk_front"), + {point_on(maps, "PewterCity", "gym_front"), Direction::NORTH}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + bool forest = false; + for (const RouteStep& step : route){ + forest = forest || (step.wild && step.end.map == "ViridianForest"); + } + if (!forest){ + return "Expected a wild step in Viridian Forest:" + describe(route); + } + // The leg from Pallet Town north onto Route 1 crosses Route 1's grass + // after the map's edge. + route.clear(); + result = check_route( + maps, point_on(maps, "PalletTown", "oaks_lab_front"), + {point_on(maps, "ViridianCity_Mart", "clerk_front"), std::nullopt}, route + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.end.map == "Route1" && step.direction == Direction::NORTH && step.tiles > 14 && !step.wild){ + return "Expected the leg from Pallet Town onto Route 1 to be wild, got " + to_string(step) + ":" + describe(route); + } + } + return true; +} + +const char* const TEST_ROOM_JSON = R"({ + "name": "Room", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#####", "#...#", "#...#", "##.##"], + "elevation": ["33333", "33333", "33333", "33333"], + "points": {"warp_0": [2, 3]}, + "warps": [{"x": 2, "y": 3, "enter": "walk_south", "to_map": "Yard", "to_point": "warp_0"}] +})"; +const char* const TEST_YARD_JSON = R"({ + "name": "Yard", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"}, + "tiles": ["#####", "##D##", "#...#", "#####"], + "elevation": ["33333", "33333", "33333", "33333"], + "points": {"warp_0": [2, 1]}, + "warps": [{"x": 2, "y": 1, "enter": "walk_into", "to_map": "Room", "to_point": "warp_0"}] +})"; + +UnitTestResult test_route_through_warp(){ + const std::vector maps{ + parse_map(TEST_ROOM_JSON, "Room"), + parse_map(TEST_YARD_JSON, "Yard"), + }; + std::vector route; + UnitTestResult result = check_route(maps, {"Room", {2, 1}}, {{"Yard", {1, 2}}, std::nullopt}, route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + for (const RouteStep& step : route){ + if (step.warps && step.end.map == "Yard"){ + return true; + } + } + return "Expected to warp into the yard:" + describe(route); +} + +// `json` with its elevation grid replaced by `rows`, or left out if empty. +std::string with_elevation(std::string json, const std::string& rows){ + const size_t begin = json.find("\"elevation\""); + const size_t end = json.find("\n", begin); + json.erase(begin, end - begin + 1); + if (!rows.empty()){ + json.insert(begin, "\"elevation\": " + rows + ",\n"); + } + return json; +} + +// Room and yard as the decompilation writes them, their walls and the +// door at elevation 0, plan the same as with no elevation grid, which +// frlg_maps.py leaves out when every tile the player can stand on is ground. +UnitTestResult test_ground_only_elevation_left_out(){ + const std::vector written{ + parse_map(with_elevation(TEST_ROOM_JSON, R"(["00000", "03330", "03330", "00300"])"), "Room"), + parse_map(with_elevation(TEST_YARD_JSON, R"(["00000", "00000", "03330", "00000"])"), "Yard"), + }; + const std::vector left_out{ + parse_map(with_elevation(TEST_ROOM_JSON, ""), "Room"), + parse_map(with_elevation(TEST_YARD_JSON, ""), "Yard"), + }; + for (const MapPosition& start : {MapPosition{"Room", {1, 1}}, MapPosition{"Room", {3, 2}}}){ + for (const MapPosition& goal : {MapPosition{"Yard", {1, 2}}, MapPosition{"Yard", {3, 2}}, MapPosition{"Room", {2, 2}}}){ + const std::optional> a = plan_overworld_route(written, start, {goal, std::nullopt}); + const std::optional> b = plan_overworld_route(left_out, start, {goal, std::nullopt}); + if (!a || !b || describe(*a) != describe(*b)){ + return "Plans differ from " + to_string(start) + " to " + to_string(goal) + ":" + + (a ? describe(*a) : " none") + "\nwithout elevation:" + (b ? describe(*b) : " none"); + } + } + } + return true; +} + +} + +void add_tests_OverworldRoute(UnitTestDatabase& database){ + database.add("route through a warp", test_route_through_warp); + database.add("ground-only elevation left out", test_ground_only_elevation_left_out); + database.add("maps to Brock", test_story_maps); + database.add("bedroom to Oak's Lab", test_bedroom_to_oaks_lab); + database.add("Viridian Mart to Pewter Gym", test_viridian_mart_to_pewter_gym); + database.add("wild steps", test_wild_steps); + database.add("no hold into a sign", test_no_hold_into_sign); + database.add("no hold into a ledge", test_no_hold_into_ledge); + database.add("step rules", test_step_rules); + database.add("maps", test_maps); + database.add("Cerulean Cave entrance to Mewtwo", test_entrance_to_mewtwo); + database.add("Cerulean Pokemon Center to Mewtwo", test_pokemon_center_to_mewtwo); + database.add("cave guard blocks the way", test_cave_guard_blocks); + database.add("Mewtwo's tile is blocked", test_mewtwo_tile_unreachable); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h new file mode 100644 index 0000000000..ce5d6f872b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h @@ -0,0 +1,151 @@ +/* Overworld Route + * + * From: https://github.com/PokemonAutomation/ + * + * Plans a route over one or more FRLG maps joined by warps: the D-pad legs + * to walk, where to start surfing, and which way to face at the end. FRLG + * moves exactly one tile per step, so a planned route can be walked blind. + * Legs end against walls where that costs little: such a leg can be held + * for longer than it takes, and walked again if something interrupts it. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldRoute_H +#define PokemonAutomation_PokemonFRLG_OverworldRoute_H + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_OverworldMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +struct MapPosition{ + std::string map; + TilePos point; + + bool operator==(const MapPosition& other) const = default; +}; +std::string to_string(const MapPosition& position); + + +enum class RouteAction{ + WALK, // hold `direction` for `tiles` tiles + SURF, // face `direction`, use Surf, and land on the water there + FACE, // turn to `direction` without moving +}; + +struct RouteStep{ + RouteAction action = RouteAction::WALK; + Direction direction = Direction::NORTH; + int tiles = 0; + // WALK: the last tile is a warp (ladder, stairs), so the screen fades + // and the player arrives on another map. + bool warps = false; + // WALK: on the water, where the player moves twice as fast. + bool surfing = false; + // WALK: a wall stops the player at the end, so the leg can be held for + // longer than it takes and still ends on its tile. + bool to_wall = false; + // WALK, SURF: a wild Pokemon can appear on the way: the step crosses + // tall grass or water. Elsewhere (indoors, streets) no wild battle can + // start, so the walker doesn't watch for one. + bool wild = false; + // Which way the player faces after the step. Arriving at a door or a + // cave mouth, the game walks the player a tile out, facing south. + Direction facing_after = Direction::NORTH; + // Where the player is after the step. + MapPosition end; +}; +std::string to_string(const RouteStep& step); + + +struct RouteGoal{ + MapPosition position; + // Which way to face on arrival, e.g. towards a Pokemon to talk to. + std::optional facing; +}; + +// What the planner weighs a route by. Each is a cost per occurrence. +enum class RouteCost{ + TILE, + TURN, // extra for a leg in a new direction + WARP, // the fade in and out + SURF, // the dialog and the animation + GRASS_TILE, // extra for tall grass, where wild Pokemon appear + // Extra for a leg that ends where the player could keep walking: it has + // to be timed, and if a message or a battle stops it part-way, where + // the player is can only be estimated. A leg that ends at a wall is + // walked again instead. + OPEN_STOP, + // Extra again when that leg crosses tall grass or water, where a wild + // battle is likely to stop it: the walker can't tell where it did + // (console B, 2026-11-01, Route 1, four runs). + OPEN_WILD_STOP, +}; +using RouteCosts = std::map; + +// TILE 1, TURN 2, WARP 30, SURF 40, GRASS_TILE 20, OPEN_STOP 8, +// OPEN_WILD_STOP 300. +const RouteCosts& default_route_costs(); + +// `costs`'s cost for `kind`, or the default if it has none. +int route_cost(const RouteCosts& costs, RouteCost kind); + +// The cheapest route from `start`, surfing if it is on water, to +// `goal`, or nothing if there is none. `maps` must hold every map the route +// may pass through; warps to other maps are not taken. Planned with +// Pokemon::plan_legs() on the game's step rules. +std::optional> plan_overworld_route( + const std::vector& maps, + const MapPosition& start, + const RouteGoal& goal, + const RouteCosts& costs = default_route_costs(), + std::optional start_facing = std::nullopt +); + +// Holding `direction` from `from`, on the water if `surfing`: where a wall +// stops the player, how many tiles on, and whether any tile on the way is +// tall grass or water. +struct WallHold{ + MapPosition end; + int tiles = 0; + bool wild = false; +}; +// Nothing unless every step on the way is a plain walk: a warp, Surf, a +// ledge, a person, a sign that would speak, or the edge of the loaded maps +// comes first. +std::optional hold_to_wall( + const std::vector& maps, + const MapPosition& from, bool surfing, Direction direction +); + +// The tiles a WALK `step` from `start` passes through, `start` first, short +// of a warp at its end. +std::vector leg_tiles( + const std::vector& maps, + const MapPosition& start, const RouteStep& step +); + +// Replays `route` from `start` with the game's step rules and returns where +// it ends. Throws InternalProgramError if a step can't be taken as planned. +MapPosition follow_overworld_route( + const std::vector& maps, + const MapPosition& start, + const std::vector& route +); + + +void add_tests_OverworldRoute(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp new file mode 100644 index 0000000000..f747f401b1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp @@ -0,0 +1,263 @@ +/* Player Facing Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Color.h" +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "Tests/TestUtils.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_PlayerFacingReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// The sprite sheet's frames are 16x32, and the standing ones are 0 (south), +// 1 (north) and 2 (west). Rows 12 to 30 are drawn; the rest is empty. +const char PLAYER_SPRITE_SHEET[] = "PokemonFRLG/PlayerSprites/red_normal.png"; +constexpr int SHEET_FRAME_WIDTH = 16; +constexpr int SHEET_FIRST_ROW = 12; + +constexpr int SPRITE_WIDTH = 16; +constexpr int SPRITE_ROWS = 19; +// Where the sprite's first drawn row sits on the GBA's 240x160 screen while +// the camera follows the player. Measured on the console. +constexpr int SPRITE_X = 112; +constexpr int SPRITE_Y = 56 + 12; +constexpr int GBA_WIDTH = 240; +constexpr int GBA_HEIGHT = 160; + +// Average difference per channel over the sprite's pixels. On the console a +// match scored about 12 and the next best sprite over 50. +constexpr double MATCH_MAX = 25; +constexpr double MATCH_MARGIN = 2.0; + + +ImageRGB32 sheet_frame(const ImageViewRGB32& sheet, int frame){ + return sheet.sub_image(frame * SHEET_FRAME_WIDTH, SHEET_FIRST_ROW, SPRITE_WIDTH, SPRITE_ROWS).copy(); +} + +// How far the screen differs from `sprite`, drawn `dy` GBA pixels lower. +double difference(const ImageViewRGB32& game, const ImageViewRGB32& sprite, bool mirror, int dy){ + const double scale_x = (double)game.width() / GBA_WIDTH; + const double scale_y = (double)game.height() / GBA_HEIGHT; + long total = 0; + int pixels = 0; + for (int row = 0; row < SPRITE_ROWS; row++){ + for (int col = 0; col < SPRITE_WIDTH; col++){ + const Color expected(sprite.pixel(mirror ? SPRITE_WIDTH - 1 - col : col, row)); + if (expected.alpha() == 0){ + continue; + } + const size_t x = (size_t)((SPRITE_X + col + 0.5) * scale_x); + const size_t y = (size_t)((SPRITE_Y + dy + row + 0.5) * scale_y); + if (x >= game.width() || y >= game.height()){ + return std::numeric_limits::max(); + } + const Color pixel(game.pixel(x, y)); + total += std::abs((int)pixel.red() - expected.red()); + total += std::abs((int)pixel.green() - expected.green()); + total += std::abs((int)pixel.blue() - expected.blue()); + pixels++; + } + } + return pixels == 0 ? std::numeric_limits::max() : (double)total / (3 * pixels); +} + +} + + +const PlayerSprites& player_sprites(){ + static const PlayerSprites SPRITES = []{ + const ImageRGB32 sheet(RESOURCE_PATH() + PLAYER_SPRITE_SHEET); + return PlayerSprites{sheet_frame(sheet, 0), sheet_frame(sheet, 1), sheet_frame(sheet, 2)}; + }(); + return SPRITES; +} + + +std::optional read_player_facing(const ImageViewRGB32& screen){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + return match_player_facing(game, player_sprites()); +} + +std::optional match_player_facing(const ImageViewRGB32& game, const PlayerSprites& sprites){ + struct Candidate{ + Direction direction; + const ImageViewRGB32& sprite; + bool mirror; + }; + const Candidate candidates[] = { + {Direction::SOUTH, sprites.south, false}, + {Direction::NORTH, sprites.north, false}, + {Direction::WEST, sprites.west, false}, + {Direction::EAST, sprites.west, true}, + }; + + double best = std::numeric_limits::max(); + double second = best; + Direction facing = Direction::SOUTH; + for (const Candidate& candidate : candidates){ + // A pixel either way, for a box that is slightly off. + double score = std::numeric_limits::max(); + for (int dy = -1; dy <= 1; dy++){ + score = std::min(score, difference(game, candidate.sprite, candidate.mirror, dy)); + } + if (score < best){ + second = best; + best = score; + facing = candidate.direction; + }else{ + second = std::min(second, score); + } + } + if (best > MATCH_MAX || second < best * MATCH_MARGIN){ + return std::nullopt; + } + return facing; +} + + + +namespace{ + +class Test_PlayerFacingReader : public UnitTest{ +public: + // The image's name ends with the way the player faces, or "None" where + // no standing player shows: _. + Test_PlayerFacingReader(const std::string& image) + : UnitTest("PokemonFRLG::PlayerFacingReader - " + image) + , m_image(UNIT_TEST_RESOURCE_PATH() + image) + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{ + const std::vector words = parse_words(Filesystem::Path(m_image).stem().string()); + if (words.size() < 2){ + return "Error: filename must be _."; + } + std::string expected = words.back(); + std::transform(expected.begin(), expected.end(), expected.begin(), [](unsigned char c){ return (char)std::tolower(c); }); + + std::optional facing; + try{ + facing = read_player_facing(ImageRGB32(m_image)); + }catch (FileException& e){ + // The screenshots and the sprite sheet aren't in CI's resources yet. + return UnitTestResult(UnitTestResult::SKIPPED, "File not found: " + e.message()); + } + const std::string read = facing ? direction_name(*facing) : "none"; + if (read == expected){ + return true; + } + return "Expected " + expected + ", read " + read; + } + +private: + std::string m_image; +}; + +// Made-up sprites, so the matching is tested without the sprite sheet: +// solid red facing south, solid blue facing north, and green on the left +// half facing west. +PlayerSprites fixture_sprites(){ + PlayerSprites sprites{ + ImageRGB32(SPRITE_WIDTH, SPRITE_ROWS), + ImageRGB32(SPRITE_WIDTH, SPRITE_ROWS), + ImageRGB32(SPRITE_WIDTH, SPRITE_ROWS), + }; + sprites.south.fill(0xffff0000); + sprites.north.fill(0xff0000ff); + sprites.west.fill(0x00000000); + for (int row = 0; row < SPRITE_ROWS; row++){ + for (int col = 0; col < SPRITE_WIDTH / 2; col++){ + sprites.west.pixel(col, row) = 0xff00ff00; + } + } + return sprites; +} + +// A grey GBA screen at twice its size, with `sprite` drawn where the +// player stands. +ImageRGB32 fixture_screen(const ImageViewRGB32* sprite, bool mirror){ + ImageRGB32 game(2 * GBA_WIDTH, 2 * GBA_HEIGHT); + game.fill(0xff808080); + for (int row = 0; sprite != nullptr && row < SPRITE_ROWS; row++){ + for (int col = 0; col < SPRITE_WIDTH; col++){ + const uint32_t pixel = sprite->pixel(mirror ? SPRITE_WIDTH - 1 - col : col, row); + if (Color(pixel).alpha() == 0){ + continue; + } + for (int dy = 0; dy < 2; dy++){ + for (int dx = 0; dx < 2; dx++){ + game.pixel(2 * (SPRITE_X + col) + dx, 2 * (SPRITE_Y + row) + dy) = pixel; + } + } + } + } + return game; +} + +class Test_PlayerFacingFixture : public UnitTest{ +public: + Test_PlayerFacingFixture() + : UnitTest("PokemonFRLG::PlayerFacingReader - made-up sprites") + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{ + const PlayerSprites sprites = fixture_sprites(); + struct Case{ + const ImageViewRGB32* sprite; + bool mirror; + std::optional expected; + }; + const Case cases[] = { + {&sprites.south, false, Direction::SOUTH}, + {&sprites.north, false, Direction::NORTH}, + {&sprites.west, false, Direction::WEST}, + {&sprites.west, true, Direction::EAST}, + {nullptr, false, std::nullopt}, + }; + for (const Case& test : cases){ + const std::optional facing = match_player_facing(fixture_screen(test.sprite, test.mirror), sprites); + if (facing != test.expected){ + return std::string("Read ") + (facing ? direction_name(*facing) : "nothing") + + " instead of " + (test.expected ? direction_name(*test.expected) : "nothing"); + } + } + return true; + } +}; + +} + +void add_tests_PlayerFacingReader(UnitTestDatabase& database){ + database.add(); + // LeafGreen on the Switch, captured with a 1080p card. + database.add("PokemonFRLG/PlayerFacingReader/Route24_South.png"); + database.add("PokemonFRLG/PlayerFacingReader/Route24_North.png"); + database.add("PokemonFRLG/PlayerFacingReader/CeruleanCave_South.png"); + database.add("PokemonFRLG/PlayerFacingReader/CeruleanCave_North.png"); + database.add("PokemonFRLG/PlayerFacingReader/Surfing_None.png"); + database.add("PokemonFRLG/PlayerFacingReader/Bag_None.png"); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h new file mode 100644 index 0000000000..fb682fde18 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h @@ -0,0 +1,58 @@ +/* Player Facing Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Which way the player faces, read from the overworld. The camera keeps the + * player on the same spot of the screen, so the reader compares that spot + * with the player's standing sprites from pret/pokefirered, on the sprite's + * own pixels only, so the ground behind doesn't matter. The sprites come + * from Packages: Resources/PokemonFRLG/PlayerSprites/red_normal.png is the + * decompilation's graphics/object_events/pics/people/red_normal.png. + * + * Only the walking player is known: surfing and biking use other sprites. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_PlayerFacingReader_H +#define PokemonAutomation_PokemonFRLG_PlayerFacingReader_H + +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "PokemonFRLG_OverworldMap.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The standing player's frames, as the game draws them, with transparent +// pixels at alpha 0. Facing east is facing west mirrored. +struct PlayerSprites{ + ImageRGB32 south; + ImageRGB32 north; + ImageRGB32 west; +}; + +// Loads the frames once. Throws FileException if the file is missing. +const PlayerSprites& player_sprites(); + + +// The way the standing player faces, or nothing if no standing sprite +// matches clearly (surfing, on the bike, in a menu, mid-step). +std::optional read_player_facing(const ImageViewRGB32& screen); + +// The same on `game`, the GBA's 240x160 screen at any scale, already cut +// out of the console's. +std::optional match_player_facing(const ImageViewRGB32& game, const PlayerSprites& sprites); + + +void add_tests_PlayerFacingReader(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index d734e275f7..7378cf7599 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -27,6 +27,9 @@ #include "Inference/PokemonFRLG_StatsReader.h" #include "Inference/PokemonFRLG_TrainerIdReader.h" #include "Inference/PokemonFRLG_WildEncounterReader.h" +#include "Overworld/PokemonFRLG_OverworldMaps.h" +#include "Overworld/PokemonFRLG_OverworldRoute.h" +#include "Overworld/PokemonFRLG_PlayerFacingReader.h" #include "PokemonFRLG_Navigation.h" #include "Tests/TestUtils.h" @@ -288,6 +291,9 @@ void add_tests(UnitTestDatabase& database){ add_tests_BattleMoveSelectionArrow(database); add_tests_BagDetector(database); add_tests_ExitWildBattle(database); + add_tests_OverworldMaps(database); + add_tests_OverworldRoute(database); + add_tests_PlayerFacingReader(database); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 46553724c9..c096e70382 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1791,6 +1791,15 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/Sounds/PokemonFRLG_CatchFanfareDetector.h Source/VideoGames/PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp diff --git a/devtools/maps/frlg_maps.py b/devtools/maps/frlg_maps.py new file mode 100644 index 0000000000..3a4ef4a25a --- /dev/null +++ b/devtools/maps/frlg_maps.py @@ -0,0 +1,318 @@ +"""Writes FRLG overworld maps as JSON, from the pret/pokefirered decompilation. + +TODO: move the maps to PokemonAutomation/Packages (Resources/PokemonFRLG/Maps) when ready. + +Usage: + python3 devtools/maps/frlg_maps.py --out SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps \ + CeruleanCity_PokemonCenter_1F CeruleanCity Route24 \ + CeruleanCave_1F CeruleanCave_2F CeruleanCave_B1F + python3 devtools/maps/frlg_maps.py --out + python3 devtools/maps/frlg_maps.py --out --check + +Downloads each map's data/maps//map.json, its layout's map.bin and its +tilesets' metatile_attributes.bin at --commit into --cache, then writes +/.json in the schema of Pokemon::MapData (Pokemon_MapData.h). +Warps and connections lead only to maps in the same run: a warp to another map +has no destination, and a connection to one is left out. A warp arrives at +point "warp_" of its map, the tile of that map's warp n. Other named points +and flag sets come from POINTS and FLAG_SETS below. + +Without map names, the maps are the ones already in --out. --check writes +nothing: it regenerates them and fails if any file differs. The program +builds in the files of SerialPrograms/Source/VideoGames/PokemonFRLG/ +Overworld/Maps, the folder to write and check. +""" +import argparse +import json +import os +import re +import struct +import subprocess +import sys + +COMMIT = 'ce6406d8c2eaf46d543c8a2606de0c3cb1951982' +# When COMMIT was pinned, for each map's "source". +COMMIT_DATE = '2026-10-31' + +# Behaviors with a glyph of their own (Pokemon_MapData.h has the legend). +TERRAIN = { + 'MB_TALL_GRASS': '~', 'MB_WARP_DOOR': 'D', + 'MB_IMPASSABLE_NORTH': '8', 'MB_IMPASSABLE_SOUTH': '2', + 'MB_IMPASSABLE_EAST': '6', 'MB_IMPASSABLE_WEST': '4', +} +# Open tiles whose warp is taken other than by walking into it: how. +WARP_ENTRIES = { + 'MB_CAVE_DOOR': 'cave_entrance', + 'MB_LADDER': 'step_on', 'MB_UP_ESCALATOR': 'step_on', 'MB_DOWN_ESCALATOR': 'step_on', + 'MB_SOUTH_ARROW_WARP': 'walk_south', 'MB_NORTH_ARROW_WARP': 'walk_north', + 'MB_EAST_ARROW_WARP': 'walk_east', 'MB_WEST_ARROW_WARP': 'walk_west', + # Stairs at the side of a room warp like an exit mat, the way the stairs + # go up or down (IsDirectionalStairWarpMetatileBehavior()). + 'MB_UP_RIGHT_STAIR_WARP': 'walk_east', 'MB_DOWN_RIGHT_STAIR_WARP': 'walk_east', + 'MB_UP_LEFT_STAIR_WARP': 'walk_west', 'MB_DOWN_LEFT_STAIR_WARP': 'walk_west', +} +# Ledges, by the way the player hops over them. +LEDGES = {'MB_JUMP_NORTH': '^', 'MB_JUMP_SOUTH': 'v', 'MB_JUMP_WEST': '<', 'MB_JUMP_EAST': '>'} +FLOOR = ('MB_NORMAL', 'MB_CAVE', 'MB_ROCK_STAIRS', 'MB_TALL_GRASS') +DIRECTIONS = {'up': 'north', 'down': 'south', 'left': 'west', 'right': 'east'} + +# Places and flag sets the decompilation doesn't name, written into the map +# they belong to. +# A `*_front` point is where the player stands to talk to someone across a +# counter, or to walk north through a door. +POINTS = { + # Where a new game starts (WarpToPlayersRoom() in src/new_game.c). + 'PalletTown_PlayersHouse_2F': {'start': (6, 6)}, + 'PalletTown': {'oaks_lab_front': (16, 14)}, + # The clerk is across the counter to the west. + 'ViridianCity_Mart': {'clerk_front': (4, 3)}, + 'ViridianCity_PokemonCenter_1F': {'nurse_front': (7, 4)}, + 'PewterCity': {'gym_front': (15, 17)}, + 'PewterCity_PokemonCenter_1F': {'nurse_front': (7, 4)}, + 'PewterCity_Gym': {'brock_front': (6, 6)}, + # The tile in front of the PC. + 'CeruleanCity_PokemonCenter_1F': {'pc': (11, 2), 'nurse_front': (7, 4)}, + # Where the player stands after entering from Cerulean City. + 'CeruleanCave_1F': {'entrance': (33, 21)}, + # Mewtwo's tile. Its battle starts by talking to it from the south. + 'CeruleanCave_B1F': {'mewtwo': (7, 12)}, +} +FLAG_SETS = { + # Set once the player has entered the Hall of Fame. They clear the way + # to Cerulean Cave: its guard, the rival and the Rocket. + 'CeruleanCity': {'after_hall_of_fame': [ + 'FLAG_HIDE_CERULEAN_CAVE_GUARD', + 'FLAG_HIDE_CERULEAN_RIVAL', + 'FLAG_HIDE_CERULEAN_ROCKET', + ]}, +} + + +class Decomp: + def __init__(self, commit, cache): + self.raw = 'https://raw.githubusercontent.com/pret/pokefirered/' + commit + self.cache = os.path.join(cache, commit) + + def path(self, rel): + local = os.path.join(self.cache, rel) + if not os.path.exists(local): + os.makedirs(os.path.dirname(local), exist_ok=True) + subprocess.run(['curl', '-sfL', f'{self.raw}/{rel}', '-o', local], check=True) + return local + + def read(self, rel): + with open(self.path(rel), 'rb') as file: + return file.read() + + +def behaviors(decomp): + names = {} + for line in decomp.read('include/constants/metatile_behaviors.h').decode().splitlines(): + match = re.match(r'#define (MB_\w+)\s+(0x[0-9A-Fa-f]+|\d+)', line) + if match: + names[int(match.group(2), 0)] = match.group(1) + return names + + +def tileset_attributes(decomp, symbol, kind): + name = re.sub(r'([a-z])([A-Z0-9])', r'\1_\2', symbol.replace('gTileset_', '')).lower() + data = decomp.read(f'data/tilesets/{kind}/{name}/metatile_attributes.bin') + return [struct.unpack_from('> 10) & 3, value >> 12 + attributes = primary[metatile] if metatile < 640 else secondary[metatile - 640] + behavior = names.get(attributes & 0x1ff, hex(attributes & 0x1ff)) + glyph, entry = tile_glyph(behavior, collision, unhandled, (x, y) in signs) + row += glyph + if entry: + entries[(x, y)] = entry + levels += '%x' % level + tiles.append(row) + elevation.append(levels) + return tiles, elevation, entries + + +def wander_box(obj, tiles): + """The tiles a wandering person may stand on, kept inside the map, or None + if they stand still.""" + movement = obj.get('movement_type', '') + if 'WANDER' not in movement: + return None + x = 0 if 'UP_AND_DOWN' in movement else int(obj.get('movement_range_x') or 0) + y = 0 if 'LEFT_AND_RIGHT' in movement else int(obj.get('movement_range_y') or 0) + if x == 0 and y == 0: + return None + return { + 'x0': max(obj['x'] - x, 0), 'y0': max(obj['y'] - y, 0), + 'x1': min(obj['x'] + x, len(tiles[0]) - 1), 'y1': min(obj['y'] + y, len(tiles) - 1), + } + + +def map_object(obj, tiles): + kind = obj['graphics_id'].replace('OBJ_EVENT_GFX_', '').lower() + data = {'name': kind, 'kind': 'item' if kind == 'item_ball' else 'npc', 'x': obj['x'], 'y': obj['y']} + box = wander_box(obj, tiles) + if box: + data['wander'] = box + flag = obj.get('flag') or '0' + if flag != '0': + data['hide_flag'] = flag + return data + + +# Tiles the player never walks onto: their elevation only matters for doors, +# which the player is put on by a warp and leaves at once. +UNWALKABLE = '#^v<>DS' +GROUND = '3' + + +def ground_only(tiles, elevation): + """Whether every walkable tile is at ground level, so that the map can + leave out its elevation grid (the loader reads ground everywhere).""" + return all(level == GROUND for row, levels in zip(tiles, elevation) + for tile, level in zip(row, levels) if tile not in UNWALKABLE) + + +def warp_point(index): + return f'warp_{index}' + + +def warp(event, entries, loaded, sources): + """A warp event as MapData's warp: how it is entered, and the point it + leads to, if its map is loaded and has that warp.""" + data = {'x': event['x'], 'y': event['y'], 'enter': entries.get((event['x'], event['y']), 'walk_into')} + to_map, index = loaded.get(event['dest_map']), int(event['dest_warp_id']) + if to_map is not None and index < len(sources[to_map].get('warp_events', [])): + data['to_map'] = to_map + data['to_point'] = warp_point(index) + return data + + +def arrivals(sources, loaded): + """For each map, the indices of its warps that a warp leads to.""" + arriving = {name: set() for name in sources} + for source in sources.values(): + for event in source.get('warp_events', []): + to_map = loaded.get(event['dest_map']) + if to_map is not None and int(event['dest_warp_id']) < len(sources[to_map].get('warp_events', [])): + arriving[to_map].add(int(event['dest_warp_id'])) + return arriving + + +def map_json(decomp, name, sources, layouts, names, loaded, unhandled): + source = sources[name] + signs = frozenset((e['x'], e['y']) for e in source.get('bg_events', []) if e.get('type') == 'sign') + tiles, elevation, entries = grid(decomp, layouts[source['layout']], names, unhandled, signs) + warp_events = source.get('warp_events', []) + points = {n: [x, y] for n, (x, y) in POINTS.get(name, {}).items()} + for index in sorted(arrivals(sources, loaded)[name]): + points[warp_point(index)] = [warp_events[index]['x'], warp_events[index]['y']] + data = { + 'name': name, + 'source': {'decomp_file': f'data/maps/{name}/map.json', 'revision': COMMIT, 'date': COMMIT_DATE}, + 'tiles': tiles, 'elevation': elevation, + 'points': points, + 'warps': [warp(event, entries, loaded, sources) for event in warp_events], + # A few objects stand off the map, where no route meets them. + 'objects': [ + map_object(obj, tiles) for obj in source.get('object_events', []) + if 0 <= obj['x'] < len(tiles[0]) and 0 <= obj['y'] < len(tiles) + ], + 'flag_sets': FLAG_SETS.get(name, {}), + 'connections': [ + {'side': DIRECTIONS[c['direction']], 'to_map': loaded[c['map']], 'offset': c['offset']} + for c in (source.get('connections') or []) if c['map'] in loaded + ], + } + if ground_only(tiles, elevation): + del data['elevation'] + return data + + +def json_text(data): + text = json.dumps(data, indent=4) + # A point's [x, y] on one line. + return re.sub(r'\[\s*(-?\d+),\s*(-?\d+)\s*\]', r'[\1, \2]', text) + '\n' + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('--commit', default=COMMIT) + parser.add_argument('--cache', default=os.path.expanduser('~/.cache/pokefirered')) + parser.add_argument('--out', required=True, help='folder of the .json files') + parser.add_argument('--check', action='store_true', help='check the files in --out instead of writing them') + parser.add_argument('maps', nargs='*', help='default: the maps already in --out') + args = parser.parse_args() + if not args.maps and os.path.isdir(args.out): + args.maps = sorted(f[:-5] for f in os.listdir(args.out) if f.endswith('.json')) + if not args.maps: + parser.error('no maps given, and none in --out') + + decomp = Decomp(args.commit, args.cache) + names = behaviors(decomp) + layouts = {l['id']: l for l in json.loads(decomp.read('data/layouts/layouts.json'))['layouts'] if 'id' in l} + sources = {m: json.loads(decomp.read(f'data/maps/{m}/map.json')) for m in args.maps} + loaded = {source['id']: m for m, source in sources.items()} + unhandled = {} + maps = [(name, json_text(map_json(decomp, name, sources, layouts, names, loaded, unhandled))) for name in args.maps] + if unhandled: + print(f'Non-collision behaviors written as floor: {unhandled}') + if args.check: + differ = [] + for name, text in maps: + path = os.path.join(args.out, name + '.json') + if not os.path.exists(path) or open(path, newline='').read() != text: + differ.append(name) + if differ: + sys.exit(f'Differ from the generator: {" ".join(differ)}. Regenerate them without --check.') + print(f'{len(maps)} maps in {args.out} match the generator.') + return + os.makedirs(args.out, exist_ok=True) + for name, text in maps: + with open(os.path.join(args.out, name + '.json'), 'w', newline='') as out: + out.write(text) + + +if __name__ == '__main__': + main()