From e908b26ef74f08c2a3f2b620a3c726a95b5a2fd7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 00:17:57 -0800 Subject: [PATCH 1/2] FRLG maps: Mt. Moon 1F, B1F and B2F, with cave floors as wild tiles The generator writes Mt. Moon's three floors from pokefirered and joins them to Route 4's two cave mouths. Floor tiles whose metatile encounter type is LAND, on a map with land encounters, are written as '~' (open, with wild encounters): every floor of a cave can start a wild battle, so the planner now ends cave legs on walls as it does in grass. This also changes Cerulean Cave's three floors, the only other caves loaded. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Overworld/Maps/CeruleanCave_1F.json | 42 ++-- .../Overworld/Maps/CeruleanCave_2F.json | 36 +-- .../Overworld/Maps/CeruleanCave_B1F.json | 42 ++-- .../PokemonFRLG/Overworld/Maps/MtMoon_1F.json | 229 ++++++++++++++++++ .../Overworld/Maps/MtMoon_B1F.json | 121 +++++++++ .../Overworld/Maps/MtMoon_B2F.json | 187 ++++++++++++++ .../PokemonFRLG/Overworld/Maps/Route4.json | 10 +- .../Overworld/PokemonFRLG_OverworldMaps.cpp | 4 + .../PokemonFRLG_OverworldMaps_Tests.cpp | 40 +++ devtools/maps/frlg_maps.py | 35 ++- devtools/maps/tests/test_frlg_maps.py | 14 ++ 11 files changed, 693 insertions(+), 67 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_1F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B1F.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B2F.json diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json index a6cb236993..e1539f229f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_1F.json @@ -7,27 +7,27 @@ }, "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#....##......###...#.....###", - "##......#...#....####...####...#...#####", - "##......#...#..................#...#####", - "#####.###...##.#...............#...#####", - "#####..........#...............#...#####", - "#####..........#...............#...#####", - "#####..........#################...#####", + "#######~~~##~#########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": [ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json index 185103d4c8..fa72ccc628 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_2F.json @@ -9,24 +9,24 @@ "########################################", "########################################", "########################################", - "####....####..##.....#............######", - "#######.......#..###.#.#########..######", - "####..####.####.##.#.#.........#########", - "####.....#.........###########....######", - "#######.############.........####.######", - "####.#...............#######....#.######", - "####.#################..#..###.##.######", - "####.#....#.............#...#...#.######", - "####.#.##.#.#####.#######.#####.#.######", - "####.#..#.#.....#.......#.....#.#.######", - "####.#..#.#####.#######.#####.#.########", - "####.#..#.#.....#.....#.....#.#.#.######", - "####.####.#.#####.###.#.#.#.#.#.#.######", - "####.#....#.........#.#.#.#.#.#.#.######", - "####.#.####.#########.#.#.#.###.#.######", - "####.#....#.....#.....#.#.#.....#.######", - "####.############.#####.#.#######.######", - "####..............#.....#.........######", + "####~~~~####~~##~~~~~#~~~~~~~~~~~~######", + "#######~~~~~~.#~~###~#~#########~.######", + "####~~####~####~##~#~#~~~~~~~~~#########", + "####~.~~~#~~~~~~~~~###########~~~~######", + "#######~############~~~~~~~~~####~######", + "####~#~~~~~~~~~~~~~~~#######~~~~#~######", + "####~#################~~#~.###~##~######", + "####~#~~~~#~~~~~~~~~~~~.#~~~#~~~#~######", + "####~#~##~#~#####~#######~#####~#~######", + "####~#~~#~#~~~~~#~~~~~~~#~~~~~#~#~######", + "####~#~~#~#####~#######~#####~#~########", + "####~#~.#~#~~~~~#~~~~~#~~~~~#~#~#~######", + "####~####~#~#####~###~#~#~#~#~#~#~######", + "####~#~~~~#~~~~~~~~~#~#~#~#~#~#~#~######", + "####~#~####~#########~#~#~#~###~#~######", + "####~#~~~~#~~~~~#~~~~~#~#~#~~~~~#~######", + "####~############~#####~#~#######~######", + "####~~~~~~~~~~~~~~#~~~~~#~~~~~~~~~######", "########################################", "########################################" ], diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json index 683929ff37..b06ee61a5f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/CeruleanCave_B1F.json @@ -7,27 +7,27 @@ }, "tiles": [ "########################################", - "##..............##.....############....#", - "##..............#........#######.......#", - "##..............#..####.....#######....#", - "##......#####.###..####.....#######....#", - "##......#..........########.#######.#..#", - "##..##..##........#########............#", - "##..#...###......##########............#", - "##......#wwwww##................#...####", - "#########wwwww##................#...####", - "#www############................#...####", - "#www##############.########.###.#...####", - "#www#.#.#.########........#.###.#...####", - "#www#.....########........#.....#...####", - "#www#.....########........#.....#...####", - "#www###.###wwww#......#...#.###.#...####", - "#wwwwwwwwwwwwww#......#...#.###.#...####", - "#wwwwwwwwwwwwww#......#...#.....#...####", - "#wwwwwwwwwwwwww#......#...#.....#...####", - "######wwwwwwwww##.##.##...###.###...####", - "######wwwwwwwwwwww#.......###.......####", - "######wwwwwwwwwwww##.....####.......####", + "##~~~~~~~~~~~~~~##~~~~~############~~~~#", + "##~~~~~~~~~~~~~~#~~~~~~~~#######~~~~~~~#", + "##~~~~~~~~~~~~~~#~~####~~~~~#######~~~~#", + "##~~~~~~#####.###~~####~~~~~#######~~~~#", + "##~~~~~~#~~~~~~~~~~########~#######~#~~#", + "##~~##~~##~~~~~~~~#########~~~~~~~~~~~~#", + "##~~#.~~###~~~~~~##########~~~~~~~~~~~~#", + "##~~~~~~#wwwww##~~~~~~~~~~~~~~~~#~~~####", + "#########wwwww##~~~~~~~~~~~~~~~~#~~~####", + "#www############~~~~~~~~~~~~~~~~#~~~####", + "#www##############.########~###~#~~~####", + "#www#~#~#~########~~~~~~~~#~###~#~~~####", + "#www#~~~~~########~~~~~~~~#~~~~~#~~~####", + "#www#~~~~~########~~~~~~~~#~~~~~#~~~####", + "#www###.###wwww#~~~~~~#~~~#~###~#~~~####", + "#wwwwwwwwwwwwww#~~~~~~#~~~#~###~#~~~####", + "#wwwwwwwwwwwwww#~~~~~~#~~~#~~~~~#~~~####", + "#wwwwwwwwwwwwww#~~~~~~#~~~#~~~~~#~~~####", + "######wwwwwwwww##.##.##~~~###.###~~~####", + "######wwwwwwwwwwww#~~~~~~~###~~~~~~~####", + "######wwwwwwwwwwww##~~~~~####~~~~~~~####", "########################################" ], "elevation": [ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_1F.json new file mode 100644 index 0000000000..cf3836faa8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_1F.json @@ -0,0 +1,229 @@ +{ + "name": "MtMoon_1F", + "source": { + "decomp_file": "data/maps/MtMoon_1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "################################################", + "################################################", + "##~~~~~~~~~#########~~~~~~~~~~~~~~~~~~~~~~~~~~##", + "##~~~~~~~~~~#######~~~~~~~~~~~~~~~~~~~~~~~~~~~##", + "##~~~~~~~~~~~#####~~~~~~~~~~~~~~~~~~~~~~~~~~~~##", + "##~~~~~~~~~~~#####~~~~~~~~~~~~~~~~~~~~~~~~~~~~##", + "##~~~.~~~~~~~####~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##", + "##~~~~~~~~~~~####~~~~~~~~~~~~~~~~~~~~~~~~#~~~~##", + "##~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~####~~##", + "##~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~##~~~##", + "##~~~~~~~~~~~###~~~~###############~~~~~~~~~~~##", + "##~~~~~~~~~~~###~~~~###############~~~~~~~~~~~##", + "##~~~~~~~~~~~###~~~~###############~~~~~~~~~~~##", + "##~~~~~~~~~~~###~~~~#####~~~~~####~~~~~~~~~~~~##", + "##~~~~~~~~~~~###~~~.####~~~~~~~~~~~~~~~###~~~~##", + "##~~~~~~~~~~~###~~~~####~~~~~~~~~~~~~~~###~~~~##", + "##~~~~~~~~~~~###~~~~###~~~~~~~~.~~~~~~~###~~~~##", + "##~~~~~~~~~~~~~~~~~~###~~~~###~~~~~~~~~###~~~~##", + "##~~~~~~~~~~~~~~~~~~###~~~~###~~~~~~~~~###~~~~##", + "###########~~~~~~~~~###~~~~###~~~~~~~~~###~~~~##", + "###########~~~~~~~~~###~~~~###~~~~~~~~~###~~~~##", + "###########~~~~~~~~~###~~~~###~~~~~~~~~###~~~~##", + "##~~~~#################~~~~###~~~~~~~~~###~~~~##", + "##~~~~~################~~~~###~~~~~~~~~###~~~~##", + "##~~~~~~###############~~~~###~~~~~~~~~###~~~~##", + "##~~~~~~###~~~~~~~~~~~~~~~~###~~~~~~~~~###~~~~##", + "##~~~~~~###~~~~~~~~S~~~~~~~###~~~~~~~~~###~~~~##", + "##~~~~~~###~~~~~~~~~~~~~~~~###~~~~~~~~~###~~~~##", + "##~~~~~~~~~~~~~~~~~~~~~~~~~###~~~~~~~~~###~~~~##", + "##~~~~~~~~~~~~~~~~~~##########~~~###~~~###~~~~##", + "##~~~~~~~~~~~~~~~~~~##########~~~###~~~###~~~~##", + "##~~~~~~~~~~~~##~~~~##########~~~###~~~###~~~~##", + "##~~~~~~~~~~~####~~~#####~~~~~~~~###~~~~~~~~~~##", + "##~~~~~~~~~~~####~~~######~~~~~~~###~~~~~~~~~~##", + "##~~~~~~~~~~~####~~~######~~~~~~~###~~~~~~~~~~##", + "##~~~~~~~~~~~####~~~#####~~~~~~~~~~~~~~~~~~~~~##", + "##~~~~~~~~~~~####~~~####~~~~~~~~~~~~~~~~~~~~~~##", + "##~~~~~~~~~~~####~.~####~~~~~~~~~~~~~~~~~~~~~~##", + "################################################", + "################################################" + ], + "points": { + "warp_0": [5, 6], + "warp_1": [19, 14], + "warp_2": [31, 16], + "warp_3": [18, 37] + }, + "warps": [ + { + "x": 5, + "y": 6, + "enter": "step_on", + "to_map": "MtMoon_B1F", + "to_point": "warp_0" + }, + { + "x": 19, + "y": 14, + "enter": "step_on", + "to_map": "MtMoon_B1F", + "to_point": "warp_1" + }, + { + "x": 31, + "y": 16, + "enter": "step_on", + "to_map": "MtMoon_B1F", + "to_point": "warp_2" + }, + { + "x": 18, + "y": 37, + "enter": "walk_south", + "to_map": "Route4", + "to_point": "warp_0" + } + ], + "objects": [ + { + "name": "lass", + "kind": "npc", + "x": 20, + "y": 26, + "facing": "south", + "trainer": { + "sight": 2 + } + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 36, + "y": 30, + "facing": "east", + "trainer": { + "sight": 2 + } + }, + { + "name": "scientist", + "kind": "npc", + "x": 30, + "y": 35, + "trainer": { + "sight": 4, + "looks": [ + "north", + "east", + "south", + "west" + ] + } + }, + { + "name": "lass", + "kind": "npc", + "x": 33, + "y": 4, + "trainer": { + "sight": 2, + "looks": [ + "north", + "east", + "south", + "west" + ] + } + }, + { + "name": "bug_catcher", + "kind": "npc", + "x": 7, + "y": 26, + "facing": "south", + "trainer": { + "sight": 4 + } + }, + { + "name": "youngster", + "kind": "npc", + "x": 13, + "y": 17, + "facing": "east", + "trainer": { + "sight": 4 + } + }, + { + "name": "hiker", + "kind": "npc", + "x": 7, + "y": 10, + "wander": { + "x0": 5, + "y0": 8, + "x1": 9, + "y1": 12 + }, + "trainer": { + "sight": 1, + "looks": [ + "north", + "east", + "south", + "west" + ] + } + }, + { + "name": "item_ball", + "kind": "item", + "x": 2, + "y": 22, + "hide_flag": "FLAG_HIDE_MT_MOON_1F_PARALYZE_HEAL" + }, + { + "name": "item_ball", + "kind": "item", + "x": 11, + "y": 35, + "hide_flag": "FLAG_HIDE_MT_MOON_1F_TM09" + }, + { + "name": "item_ball", + "kind": "item", + "x": 26, + "y": 32, + "hide_flag": "FLAG_HIDE_MT_MOON_1F_POTION" + }, + { + "name": "item_ball", + "kind": "item", + "x": 42, + "y": 35, + "hide_flag": "FLAG_HIDE_MT_MOON_1F_RARE_CANDY" + }, + { + "name": "item_ball", + "kind": "item", + "x": 44, + "y": 21, + "hide_flag": "FLAG_HIDE_MT_MOON_1F_ESCAPE_ROPE" + }, + { + "name": "item_ball", + "kind": "item", + "x": 3, + "y": 2, + "hide_flag": "FLAG_HIDE_MT_MOON_1F_MOON_STONE" + }, + { + "name": "balding_man", + "kind": "npc", + "x": 42, + "y": 7 + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B1F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B1F.json new file mode 100644 index 0000000000..448aa61f4d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B1F.json @@ -0,0 +1,121 @@ +{ + "name": "MtMoon_B1F", + "source": { + "decomp_file": "data/maps/MtMoon_B1F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "#################################################", + "#################################################", + "##################~~~~~~~~###############~~~~~###", + "##~.~~~##########~~~~~~~~#############~~~~~~~####", + "##~~~~~#########~~~~~~~~~.~##########~~.~~~~~.~##", + "##~~~~~#########~.~~~~~~~~~#########~~~~~~~~~~~##", + "##~~~~~##########################################", + "##~~~~~##########################################", + "##~~~~~##########################################", + "##~~~~###########################################", + "##~~~~~##########################################", + "##~~~#~##########################################", + "##~~~~###########################################", + "##~~~~~##########################################", + "##~~~~~##########################################", + "##~~~~~##########################################", + "##~~~~~~~~~~~~~~~~~~~~~~#########################", + "##~~~~~~~~~~~~~~~~~~~~~~#########################", + "##~~~~~~~~~~~~~~~~~~~~.~#########################", + "#################################################", + "#################################################", + "#########################################~~.~####", + "#########################################~~~~####", + "#########################################~~~~####", + "#########################################~~~~####", + "#########################################~~~~####", + "#########################################~~~~####", + "#########################################~~~~####", + "#########################################~~~~####", + "#########################################~~~~####", + "#########################################~~~~####", + "##########################################~~~####", + "##########################################~~~####", + "##########################################~~~####", + "##########################~~~~~~~~~~~####~~~~####", + "#########################~~~~~~~~~~~~~~~~~~~~####", + "########################~~.~~~~~~~~~~~~~~~~~~####", + "#################################################", + "#################################################", + "#################################################" + ], + "points": { + "warp_0": [3, 3], + "warp_1": [25, 4], + "warp_2": [43, 21], + "warp_3": [22, 18], + "warp_4": [17, 5], + "warp_5": [26, 36], + "warp_6": [39, 4], + "warp_7": [45, 4] + }, + "warps": [ + { + "x": 3, + "y": 3, + "enter": "step_on", + "to_map": "MtMoon_1F", + "to_point": "warp_0" + }, + { + "x": 25, + "y": 4, + "enter": "step_on", + "to_map": "MtMoon_1F", + "to_point": "warp_1" + }, + { + "x": 43, + "y": 21, + "enter": "step_on", + "to_map": "MtMoon_1F", + "to_point": "warp_2" + }, + { + "x": 22, + "y": 18, + "enter": "step_on", + "to_map": "MtMoon_B2F", + "to_point": "warp_0" + }, + { + "x": 17, + "y": 5, + "enter": "step_on", + "to_map": "MtMoon_B2F", + "to_point": "warp_1" + }, + { + "x": 26, + "y": 36, + "enter": "step_on", + "to_map": "MtMoon_B2F", + "to_point": "warp_2" + }, + { + "x": 39, + "y": 4, + "enter": "step_on", + "to_map": "MtMoon_B2F", + "to_point": "warp_3" + }, + { + "x": 45, + "y": 4, + "enter": "step_on", + "to_map": "Route4", + "to_point": "warp_1" + } + ], + "objects": [], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B2F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B2F.json new file mode 100644 index 0000000000..3ea4072658 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B2F.json @@ -0,0 +1,187 @@ +{ + "name": "MtMoon_B2F", + "source": { + "decomp_file": "data/maps/MtMoon_B2F/map.json", + "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", + "date": "2026-10-31" + }, + "tiles": [ + "################################################", + "################################################", + "################################################", + "###~~~~~~~~~~~~~~~~~############################", + "###~~~~~~~~~~~~~~~~~############################", + "###~~~~~~~~~~~~~~~~~###~~~~######~~~~###########", + "###~~~~~~~~~~~~~~~~~###~~~~#~~~~#~~~~#~~~~######", + "###~~########~~########~~~~#~~~~##~~##~~~~######", + "##~~~~~~#8888~~88888###~~~~#~~~~~~~~~~~~~~######", + "##~~~#~~#~~~~~~~~~~~###~~~~#~~~~~~~~~~~~~~######", + "##~~~.#~#~~~~~~~~~~~###~~~~#~~##~~~~~~~~~~######", + "##~~~~~~#~~~~~~~~~~~###~~~~#~~#.~~~~~~~#~~######", + "##~~~~~######~~###~~###~~~~#~~~~~~~~~~~~~~######", + "#########~~~~~~~~#~~###~~~~#~~~~~~~~~~~~~~######", + "#vvvvvv#~~~~~~~~~#~~###~~~~88888888##8888888888#", + "########~~~~~~~~~######~~~~~~~~~~~~##~~~~~~~~~~#", + "########~~~~~~~~~~~~###~~~~~~~~~~~~##~~~~~~~~~~#", + "############~~~########~~~~~~~~~~~~##~~~~~~~~~~#", + "#######vvvv#~~~#vvvvvv#~~~~~~##~~#####~~##~~~~~#", + "############~~~########~~~~~~#~~~~~~~~~~~#~~~~~#", + "############~~~########~~#~~~#~~~~~~~~~~~#~~~~~#", + "########~~~~~~~~~~~~~##~~.~#~#~~~~~~~~~~~#~~~~~#", + "########~~~~~~~~~~~~~##~~~#~~#~~~~~~~~~~~#~~~~~#", + "########~~~~~##############################~~~~#", + "########~~~~~#vvvvvvvvvvvvvvvvvvvvvvvvvvvv#~~~~#", + "########~~~~~##############################~~~~#", + "########~~~~~###############~~~~###########~~~~#", + "########~~~~~##~~~~~~~~~~~~#~~~~#~~##~~~~~~~~~~#", + "########~~~~~###~~~~~~~~~~~##~~##~~##~~~~~~~~~~#", + "########~~~~~##~~~~~~~~~~~~~~~~~~~~##~~~~~######", + "########~~~~~##~~#~~~~~~~~~~~~~~~~~##~~~~~######", + "########~~~~~##~#.~~~~~~~~~~~~~~~~~##~~~~~######", + "########~~~~~####~~~~~~~~~~~~~~~~~~##~~~~~######", + "########~~~~~########################~~~~~######", + "########~~~~~#vvvvvvvvvvvvvvvvvvvvvv#~~~~~######", + "########~~~~~########################~~~~~######", + "########~~~~~########################~~~~~######", + "########~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~######", + "########~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~######", + "################################################" + ], + "points": { + "warp_0": [25, 21], + "warp_1": [31, 11], + "warp_2": [17, 31], + "warp_3": [5, 10] + }, + "warps": [ + { + "x": 25, + "y": 21, + "enter": "step_on", + "to_map": "MtMoon_B1F", + "to_point": "warp_3" + }, + { + "x": 31, + "y": 11, + "enter": "step_on", + "to_map": "MtMoon_B1F", + "to_point": "warp_4" + }, + { + "x": 17, + "y": 31, + "enter": "step_on", + "to_map": "MtMoon_B1F", + "to_point": "warp_5" + }, + { + "x": 5, + "y": 10, + "enter": "step_on", + "to_map": "MtMoon_B1F", + "to_point": "warp_6" + } + ], + "objects": [ + { + "name": "fossil", + "kind": "npc", + "x": 13, + "y": 7, + "hide_flag": "FLAG_HIDE_DOME_FOSSIL" + }, + { + "name": "fossil", + "kind": "npc", + "x": 14, + "y": 7, + "hide_flag": "FLAG_HIDE_HELIX_FOSSIL" + }, + { + "name": "scientist", + "kind": "npc", + "x": 13, + "y": 11 + }, + { + "name": "rocket_m", + "kind": "npc", + "x": 37, + "y": 21, + "trainer": { + "sight": 3, + "looks": [ + "north", + "east", + "south", + "west" + ] + }, + "hide_flag": "FLAG_HIDE_MISC_KANTO_ROCKETS" + }, + { + "name": "rocket_m", + "kind": "npc", + "x": 12, + "y": 20, + "facing": "south", + "trainer": { + "sight": 2 + }, + "hide_flag": "FLAG_HIDE_MISC_KANTO_ROCKETS" + }, + { + "name": "rocket_m", + "kind": "npc", + "x": 35, + "y": 12, + "facing": "north", + "trainer": { + "sight": 4 + }, + "hide_flag": "FLAG_HIDE_MISC_KANTO_ROCKETS" + }, + { + "name": "rocket_m", + "kind": "npc", + "x": 18, + "y": 27, + "facing": "south", + "trainer": { + "sight": 4 + }, + "hide_flag": "FLAG_HIDE_MISC_KANTO_ROCKETS" + }, + { + "name": "item_ball", + "kind": "item", + "x": 30, + "y": 26, + "hide_flag": "FLAG_HIDE_MT_MOON_B2F_STAR_PIECE" + }, + { + "name": "item_ball", + "kind": "item", + "x": 35, + "y": 5, + "hide_flag": "FLAG_HIDE_MT_MOON_B2F_TM46" + }, + { + "name": "item_ball", + "kind": "item", + "x": 24, + "y": 6, + "hide_flag": "FLAG_HIDE_MT_MOON_B2F_REVIVE" + }, + { + "name": "item_ball", + "kind": "item", + "x": 3, + "y": 11, + "hide_flag": "FLAG_HIDE_MT_MOON_B2F_ANTIDOTE" + } + ], + "flag_sets": {}, + "connections": [] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route4.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route4.json index 3dd6fc1123..5c8b219633 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route4.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route4.json @@ -50,18 +50,24 @@ "000000003333333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ], "points": { + "warp_0": [19, 5], + "warp_1": [32, 5], "warp_2": [12, 5] }, "warps": [ { "x": 19, "y": 5, - "enter": "cave_entrance" + "enter": "cave_entrance", + "to_map": "MtMoon_1F", + "to_point": "warp_3" }, { "x": 32, "y": 5, - "enter": "cave_entrance" + "enter": "cave_entrance", + "to_map": "MtMoon_B1F", + "to_point": "warp_7" }, { "x": 12, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp index a1aaeda292..96954b03cc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp @@ -41,6 +41,10 @@ const char* const MAP_NAMES[] = { "Route3", "Route4", "Route4_PokemonCenter_1F", + // Mt. Moon, from Route 4 west of it to Route 4 east of it. + "MtMoon_1F", + "MtMoon_B1F", + "MtMoon_B2F", // Cerulean Cave, for Mewtwo. "CeruleanCity_PokemonCenter_1F", "CeruleanCity", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp index 1c621ce1e8..8a89186186 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp @@ -246,6 +246,45 @@ UnitTestResult test_route3_route4_maps(){ return true; } +// Mt. Moon's three floors load, every floor tile of them with wild +// encounters, and join Route 4's two cave mouths: the way from the west +// mouth (19, 5) to the east one (32, 5) goes down to B2F and back up, +// through the gap the fossils leave once taken, and comes out walked a +// tile south, facing south. +UnitTestResult test_mt_moon_maps(){ + const std::vector maps = overworld_maps({"FLAG_HIDE_DOME_FOSSIL", "FLAG_HIDE_HELIX_FOSSIL"}); + for (const char* name : {"MtMoon_1F", "MtMoon_B1F", "MtMoon_B2F"}){ + const MapData* map = built_in(maps, name); + if (map == nullptr){ + return std::string("Missing map ") + name + "."; + } + for (int y = 0; y < map->tiles.height; y++){ + for (int x = 0; x < map->tiles.width; x++){ + const TilePos tile{x, y}; + if (map->tiles.at(tile) == TileKind::OPEN && warp_at(*map, tile) == nullptr){ + return std::format("{}: open floor without wild encounters at {}.", name, Pokemon::to_string(tile)); + } + } + } + } + const std::optional> route = plan_overworld_route( + maps, MapPosition{"Route4", {19, 6}}, RouteGoal{MapPosition{"Route4", {32, 6}}, Direction::SOUTH} + ); + if (!route || route->empty()){ + return "No route through Mt. Moon from Route 4's west mouth to its east one."; + } + std::set floors; + for (const RouteStep& step : *route){ + if (step.warps){ + floors.insert(step.end.map); + } + } + if (floors != std::set{"MtMoon_1F", "MtMoon_B1F", "MtMoon_B2F", "Route4"} || route->back().facing_after != Direction::SOUTH){ + return "Expected the way through to warp onto every floor and out to Route 4 facing south."; + } + return true; +} + // A planned step walks where its map doesn't let the player run, and only // there: out of Pewter's Pokemon Center to the Gym. UnitTestResult test_walk_only_indoors(){ @@ -445,6 +484,7 @@ void add_tests_OverworldMaps(UnitTestDatabase& database){ database.add("unknown tile", test_unknown_tile); database.add("not JSON", test_not_json); database.add("Route 3, Route 4 and its Pokemon Center", test_route3_route4_maps); + database.add("Mt. Moon joins Route 4's cave mouths", test_mt_moon_maps); database.add("walks where running isn't allowed", test_walk_only_indoors); database.add("Route 4's Pokemon Center escalator", test_route4_center_escalator); database.add("trainer sight", test_trainer_sight); diff --git a/devtools/maps/frlg_maps.py b/devtools/maps/frlg_maps.py index f0fd8b921a..a5fa31f145 100644 --- a/devtools/maps/frlg_maps.py +++ b/devtools/maps/frlg_maps.py @@ -57,6 +57,11 @@ # 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') +# A metatile's encounter type (METATILE_ATTRIBUTE_ENCOUNTER_TYPE in +# include/fieldmap.h): on a map with land encounters, a step onto a LAND +# tile may start a wild battle, as on every floor tile of a cave. +ENCOUNTER_TYPE_SHIFT, ENCOUNTER_TYPE_MASK = 24, 0x7 +TILE_ENCOUNTER_LAND = 1 DIRECTIONS = {'up': 'north', 'down': 'south', 'left': 'west', 'right': 'east'} # Places and flag sets the decompilation doesn't name, written into the map @@ -153,9 +158,18 @@ def tile_glyph(behavior, collision, unhandled, sign_event=False): return '.', None -def grid(decomp, layout, names, unhandled, signs=frozenset()): +def encounter_glyph(glyph, attributes): + """On a map with land encounters: `glyph` for a tile with these metatile + attributes, open floor where wild Pokemon appear written as tall grass.""" + encounter = (attributes >> ENCOUNTER_TYPE_SHIFT) & ENCOUNTER_TYPE_MASK + return '~' if glyph == '.' and encounter == TILE_ENCOUNTER_LAND else glyph + + +def grid(decomp, layout, names, unhandled, signs=frozenset(), land_encounters=False): """The map's tile rows, elevation rows, and how the warp on each tile is - entered, by (x, y), where it isn't by walking into it.""" + entered, by (x, y), where it isn't by walking into it. With + `land_encounters`, open floor where wild Pokemon appear (a cave's) is + written as tall grass, the glyph for "open, with wild encounters".""" width, height = layout['width'], layout['height'] blocks = decomp.read(layout['blockdata_filepath']) primary = tileset_attributes(decomp, layout['primary_tileset'], 'primary') @@ -169,6 +183,8 @@ def grid(decomp, layout, names, unhandled, signs=frozenset()): 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) + if land_encounters and entry is None: + glyph = encounter_glyph(glyph, attributes) row += glyph if entry: entries[(x, y)] = entry @@ -283,10 +299,18 @@ def arrivals(sources, loaded): return arriving -def map_json(decomp, name, sources, layouts, names, loaded, unhandled): +def land_encounter_maps(decomp): + """The ids of the maps that have land encounters (src/data/wild_encounters.json).""" + groups = json.loads(decomp.read('src/data/wild_encounters.json'))['wild_encounter_groups'] + return {e['map'] for group in groups for e in group.get('encounters', []) if 'land_mons' in e} + + +def map_json(decomp, name, sources, layouts, names, loaded, unhandled, land_maps=frozenset()): 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) + tiles, elevation, entries = grid( + decomp, layouts[source['layout']], names, unhandled, signs, source['id'] in land_maps + ) 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]): @@ -341,7 +365,8 @@ def main(): 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] + land_maps = land_encounter_maps(decomp) + maps = [(name, json_text(map_json(decomp, name, sources, layouts, names, loaded, unhandled, land_maps))) for name in args.maps] if unhandled: print(f'Non-collision behaviors written as floor: {unhandled}') if args.check: diff --git a/devtools/maps/tests/test_frlg_maps.py b/devtools/maps/tests/test_frlg_maps.py index 70256f8216..c65570a9e8 100644 --- a/devtools/maps/tests/test_frlg_maps.py +++ b/devtools/maps/tests/test_frlg_maps.py @@ -36,5 +36,19 @@ def test_others_are_no_trainers(self): self.assertNotIn('facing', data) +class EncounterTest(unittest.TestCase): + # MtMoon_1F's cave floor: behavior MB_CAVE (0x08), encounter type LAND. + CAVE_FLOOR = 0x08 | (frlg_maps.TILE_ENCOUNTER_LAND << frlg_maps.ENCOUNTER_TYPE_SHIFT) + + def test_cave_floor_has_wild_encounters(self): + self.assertEqual(frlg_maps.encounter_glyph('.', self.CAVE_FLOOR), '~') + + def test_floor_without_encounters_stays_open(self): + self.assertEqual(frlg_maps.encounter_glyph('.', 0x08), '.') + + def test_walls_stay_walls(self): + self.assertEqual(frlg_maps.encounter_glyph('#', self.CAVE_FLOOR), '#') + + if __name__ == '__main__': unittest.main() From a69943c083e0be4077f1a467ff4e65ec0ce4e322 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 03:40:27 -0800 Subject: [PATCH 2/2] FRLG maps: a cave's floor closed on one side is wild too Mt. Moon B2F's rows 8 and 14 are floor closed on the north ('8'). Their metatiles have encounter type LAND like the cave floor around them, but the glyph can't also say "wild", so the planner gave legs over them wild = false and the walker skipped its battle checks. The generator now lists such tiles in the map region "wild", and is_tall_grass() reads it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Overworld/Maps/MtMoon_B2F.json | 31 ++++++++++++++ .../Overworld/PokemonFRLG_OverworldMap.cpp | 9 ++++- .../Overworld/PokemonFRLG_OverworldMap.h | 9 ++++- .../PokemonFRLG_OverworldMaps_Tests.cpp | 27 +++++++++++++ devtools/maps/frlg_maps.py | 40 ++++++++++++++----- devtools/maps/tests/test_frlg_maps.py | 15 +++++++ 6 files changed, 120 insertions(+), 11 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B2F.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B2F.json index 3ea4072658..33c98997eb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B2F.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_B2F.json @@ -53,6 +53,37 @@ "warp_2": [17, 31], "warp_3": [5, 10] }, + "regions": { + "wild": [ + [9, 8], + [10, 8], + [11, 8], + [12, 8], + [15, 8], + [16, 8], + [17, 8], + [18, 8], + [19, 8], + [27, 14], + [28, 14], + [29, 14], + [30, 14], + [31, 14], + [32, 14], + [33, 14], + [34, 14], + [37, 14], + [38, 14], + [39, 14], + [40, 14], + [41, 14], + [42, 14], + [43, 14], + [44, 14], + [45, 14], + [46, 14] + ] + }, "warps": [ { "x": 25, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp index e0fc1a339e..632480ca81 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.cpp @@ -4,6 +4,7 @@ * */ +#include #include "Common/Cpp/Exceptions.h" #include "PokemonFRLG_OverworldMap.h" @@ -43,8 +44,14 @@ bool is_ledge(const MapData& map, const TilePos& point){ bool is_water(const MapData& map, const TilePos& point){ return tile_at(map, point) == TileKind::WATER; } +const char WILD_REGION[] = "wild"; + bool is_tall_grass(const MapData& map, const TilePos& point){ - return tile_at(map, point) == TileKind::TALL_GRASS; + if (tile_at(map, point) == TileKind::TALL_GRASS){ + return true; + } + const auto wild = map.regions.find(WILD_REGION); + return wild != map.regions.end() && std::find(wild->second.begin(), wild->second.end(), point) != wild->second.end(); } namespace{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h index 399d5f0537..42bcc590fe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h @@ -58,7 +58,9 @@ constexpr uint8_t ELEVATION_GROUND = 3; // 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. +// - CLOSED_ can't be entered or left through that side. One with wild +// encounters (a cave's) is listed in the map's region WILD_REGION, as its +// glyph can't say so too. // - 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 @@ -72,6 +74,11 @@ 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); +// The map region of the tiles with wild encounters whose glyph isn't tall +// grass. +extern const char WILD_REGION[]; +// Whether a step onto the tile may start a wild battle: tall grass, or a +// tile in WILD_REGION. 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 diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp index 8a89186186..d8083fe067 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp @@ -12,6 +12,7 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_OverworldMap.h" #include "PokemonFRLG_OverworldMaps.h" #include "PokemonFRLG_OverworldReanchor.h" #include "PokemonFRLG_OverworldRoute.h" @@ -285,6 +286,31 @@ UnitTestResult test_mt_moon_maps(){ return true; } +// Mt. Moon B2F's floor closed on its north side, along row 14, has wild +// encounters like the cave floor south of it: a leg along it is wild, so the +// walker watches for a battle there. +UnitTestResult test_mt_moon_closed_floor_wild(){ + const std::vector maps = overworld_maps({"FLAG_HIDE_DOME_FOSSIL", "FLAG_HIDE_HELIX_FOSSIL"}); + const MapData* map = built_in(maps, "MtMoon_B2F"); + if (map == nullptr){ + return "Missing map MtMoon_B2F."; + } + if (map->tiles.at({40, 14}) != TileKind::CLOSED_NORTH || !is_tall_grass(*map, {40, 14})){ + return "Expected MtMoon_B2F (40, 14) to be floor closed on the north, with wild encounters."; + } + const std::optional> route = plan_overworld_route( + maps, MapPosition{"MtMoon_B2F", {37, 14}}, RouteGoal{MapPosition{"MtMoon_B2F", {46, 14}}, Direction::EAST} + ); + if (!route || route->size() != 1){ + return "Expected one leg along MtMoon_B2F's row 14."; + } + const RouteStep& step = route->front(); + if (step.direction != Direction::EAST || step.tiles != 9 || !step.wild){ + return "Expected a wild leg 9 tiles east along row 14, got " + to_string(step) + "."; + } + return true; +} + // A planned step walks where its map doesn't let the player run, and only // there: out of Pewter's Pokemon Center to the Gym. UnitTestResult test_walk_only_indoors(){ @@ -485,6 +511,7 @@ void add_tests_OverworldMaps(UnitTestDatabase& database){ database.add("not JSON", test_not_json); database.add("Route 3, Route 4 and its Pokemon Center", test_route3_route4_maps); database.add("Mt. Moon joins Route 4's cave mouths", test_mt_moon_maps); + database.add("Mt. Moon's floor closed on one side is wild", test_mt_moon_closed_floor_wild); database.add("walks where running isn't allowed", test_walk_only_indoors); database.add("Route 4's Pokemon Center escalator", test_route4_center_escalator); database.add("trainer sight", test_trainer_sight); diff --git a/devtools/maps/frlg_maps.py b/devtools/maps/frlg_maps.py index a5fa31f145..f72a9ecca0 100644 --- a/devtools/maps/frlg_maps.py +++ b/devtools/maps/frlg_maps.py @@ -62,6 +62,10 @@ # tile may start a wild battle, as on every floor tile of a cave. ENCOUNTER_TYPE_SHIFT, ENCOUNTER_TYPE_MASK = 24, 0x7 TILE_ENCOUNTER_LAND = 1 +# Open tiles closed on one side, and the region that lists those of them +# with wild encounters, which their glyph can't say. +CLOSED_GLYPHS = '8264' +WILD_REGION = 'wild' DIRECTIONS = {'up': 'north', 'down': 'south', 'left': 'west', 'right': 'east'} # Places and flag sets the decompilation doesn't name, written into the map @@ -158,23 +162,36 @@ def tile_glyph(behavior, collision, unhandled, sign_event=False): return '.', None +def land_encounter(attributes): + """Whether, on a map with land encounters, a step onto a tile with these + metatile attributes may start a wild battle.""" + return (attributes >> ENCOUNTER_TYPE_SHIFT) & ENCOUNTER_TYPE_MASK == TILE_ENCOUNTER_LAND + + def encounter_glyph(glyph, attributes): """On a map with land encounters: `glyph` for a tile with these metatile attributes, open floor where wild Pokemon appear written as tall grass.""" - encounter = (attributes >> ENCOUNTER_TYPE_SHIFT) & ENCOUNTER_TYPE_MASK - return '~' if glyph == '.' and encounter == TILE_ENCOUNTER_LAND else glyph + return '~' if glyph == '.' and land_encounter(attributes) else glyph + + +def wild_edge(glyph, attributes): + """On a map with land encounters: whether a tile closed on one side, with + these metatile attributes, has wild encounters. Its glyph can't say so; + the map lists it in region WILD_REGION.""" + return glyph in CLOSED_GLYPHS and land_encounter(attributes) def grid(decomp, layout, names, unhandled, signs=frozenset(), land_encounters=False): - """The map's tile rows, elevation rows, and how the warp on each tile is - entered, by (x, y), where it isn't by walking into it. With - `land_encounters`, open floor where wild Pokemon appear (a cave's) is - written as tall grass, the glyph for "open, with wild encounters".""" + """The map's tile rows, elevation rows, how the warp on each tile is + entered, by (x, y), where it isn't by walking into it, and the tiles closed + on one side that have wild encounters. With `land_encounters`, open floor + where wild Pokemon appear (a cave's) is written as tall grass, the glyph + for "open, with wild encounters".""" width, height = layout['width'], layout['height'] blocks = decomp.read(layout['blockdata_filepath']) primary = tileset_attributes(decomp, layout['primary_tileset'], 'primary') secondary = tileset_attributes(decomp, layout['secondary_tileset'], 'secondary') - tiles, elevation, entries = [], [], {} + tiles, elevation, entries, wild_edges = [], [], {}, [] for y in range(height): row, levels = '', '' for x in range(width): @@ -185,13 +202,15 @@ def grid(decomp, layout, names, unhandled, signs=frozenset(), land_encounters=Fa glyph, entry = tile_glyph(behavior, collision, unhandled, (x, y) in signs) if land_encounters and entry is None: glyph = encounter_glyph(glyph, attributes) + if wild_edge(glyph, attributes): + wild_edges.append([x, y]) row += glyph if entry: entries[(x, y)] = entry levels += '%x' % level tiles.append(row) elevation.append(levels) - return tiles, elevation, entries + return tiles, elevation, entries, wild_edges def wander_box(obj, tiles): @@ -308,7 +327,7 @@ def land_encounter_maps(decomp): def map_json(decomp, name, sources, layouts, names, loaded, unhandled, land_maps=frozenset()): 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( + tiles, elevation, entries, wild_edges = grid( decomp, layouts[source['layout']], names, unhandled, signs, source['id'] in land_maps ) warp_events = source.get('warp_events', []) @@ -321,6 +340,7 @@ def map_json(decomp, name, sources, layouts, names, loaded, unhandled, land_maps 'allow_running': source.get('allow_running', True), 'tiles': tiles, 'elevation': elevation, 'points': points, + 'regions': {WILD_REGION: wild_edges} if wild_edges else {}, 'warps': [warp(event, entries, loaded, sources) for event in warp_events], # A few objects stand off the map, where no route meets them. 'objects': [ @@ -333,6 +353,8 @@ def map_json(decomp, name, sources, layouts, names, loaded, unhandled, land_maps for c in (source.get('connections') or []) if c['map'] in loaded ], } + if not data['regions']: + del data['regions'] if ground_only(tiles, elevation): del data['elevation'] if data['allow_running']: diff --git a/devtools/maps/tests/test_frlg_maps.py b/devtools/maps/tests/test_frlg_maps.py index c65570a9e8..96fc4b5eda 100644 --- a/devtools/maps/tests/test_frlg_maps.py +++ b/devtools/maps/tests/test_frlg_maps.py @@ -49,6 +49,21 @@ def test_floor_without_encounters_stays_open(self): def test_walls_stay_walls(self): self.assertEqual(frlg_maps.encounter_glyph('#', self.CAVE_FLOOR), '#') + # MtMoon_B2F's floor closed on the north: MB_IMPASSABLE_NORTH (0x32), + # encounter type LAND, as wild as the cave floor around it. + CLOSED_NORTH = 0x32 | (frlg_maps.TILE_ENCOUNTER_LAND << frlg_maps.ENCOUNTER_TYPE_SHIFT) + + def test_closed_side_floor_has_wild_encounters(self): + for glyph in '8264': + self.assertTrue(frlg_maps.wild_edge(glyph, self.CLOSED_NORTH)) + + def test_closed_side_floor_without_encounters_is_not_wild(self): + self.assertFalse(frlg_maps.wild_edge('8', 0x32)) + + def test_other_tiles_are_no_wild_edges(self): + for glyph in '.~#': + self.assertFalse(frlg_maps.wild_edge(glyph, self.CAVE_FLOOR)) + if __name__ == '__main__': unittest.main()