diff --git a/data/games/frlg/maps/README.md b/data/games/frlg/maps/README.md index daefe81..dd4878a 100644 --- a/data/games/frlg/maps/README.md +++ b/data/games/frlg/maps/README.md @@ -220,6 +220,22 @@ A collision-free `MB_COUNTER` (PewterCity_Museum_1F (11, 5)) is floor: the counter only lets the player talk across it. NPCs and pickups keep source event, script and optional local-ID provenance. +A person who wanders or walks back and forth has a `wander` box: their start +tile +- the pret movement range, kept inside the map +(`IsCoordOutsideObjectEventMovementRange()`). Back-and-forth walkers and +`*_UP_AND_DOWN`/`*_LEFT_AND_RIGHT` wanderers keep to their axis. +A person who walks a sequence of directions (`MOVEMENT_TYPE_WALK_SEQUENCE_*`) +has a `path` instead: legs `[direction, tiles]` (north/east/south/west) walked +in order from their `coord`, back to it and over again, e.g. Route 11's Dave +`[["south", 4], ["east", 8], ["west", 8], ["north", 4]]`. The generator walks +pret's rule on the map's collision, behavior and elevation grids +(`MoveNextDirectionInSequence()` and `MovementType_WalkSequence*_Step1()` in +`src/event_object_movement.c`): at the edge of their range they turn to the +next direction; any other collision (a wall, ground at another elevation, a +person who stands still) makes them walk in place for good, which the last +leg marks with a third element, `["east", 3, "stuck"]`. A walk that does +neither fails the generator. Every FRLG sequence walker returns to its start; +`npc_path.path_tiles()` expands legs to tiles. `source_event` is a zero-based source array index, not an in-game object ID. An item ball's `item` and `quantity` come from the pinned catalog (`data/maps/item-identities.json`) or, for a map it doesn't list, from the diff --git a/data/games/frlg/maps/base/CeladonCity.json b/data/games/frlg/maps/base/CeladonCity.json index 4ed53fc..2ecf040 100644 --- a/data/games/frlg/maps/base/CeladonCity.json +++ b/data/games/frlg/maps/base/CeladonCity.json @@ -167,7 +167,13 @@ "source_script": "CeladonCity_EventScript_Poliwrath", "source_local_id": "LOCALID_CELADON_POLIWRATH" }, - {"name": "little_girl", "coord": [11, 18], "source_event": 3, "source_script": "CeladonCity_EventScript_LittleGirl"}, + { + "name": "little_girl", + "coord": [11, 18], + "path": [["east", 4], ["south", 4], ["west", 4], ["north", 4]], + "source_event": 3, + "source_script": "CeladonCity_EventScript_LittleGirl" + }, { "name": "woman_2", "coord": [18, 22], diff --git a/data/games/frlg/maps/base/MtMoon_1F.json b/data/games/frlg/maps/base/MtMoon_1F.json index 26204e9..1def8ed 100644 --- a/data/games/frlg/maps/base/MtMoon_1F.json +++ b/data/games/frlg/maps/base/MtMoon_1F.json @@ -97,6 +97,7 @@ { "name": "lass", "coord": [33, 4], + "path": [["west", 5], ["south", 3], ["east", 5], ["north", 3]], "trainer": {"sight": 2, "looks": ["north", "east", "south", "west"]}, "source_event": 3, "source_script": "MtMoon_1F_EventScript_Miriam" diff --git a/data/games/frlg/maps/base/Route11.json b/data/games/frlg/maps/base/Route11.json index 2a96466..afbb88a 100644 --- a/data/games/frlg/maps/base/Route11.json +++ b/data/games/frlg/maps/base/Route11.json @@ -107,6 +107,7 @@ { "name": "youngster", "coord": [28, 10], + "path": [["south", 4], ["east", 8], ["west", 8], ["north", 4]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 3, "source_script": "Route11_EventScript_Dave" @@ -135,6 +136,7 @@ { "name": "youngster", "coord": [50, 14], + "wander": {"min": [50, 10], "max": [50, 18]}, "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 7, "source_script": "Route11_EventScript_Yasu" diff --git a/data/games/frlg/maps/base/Route12.json b/data/games/frlg/maps/base/Route12.json index 839f89b..7294bf5 100644 --- a/data/games/frlg/maps/base/Route12.json +++ b/data/games/frlg/maps/base/Route12.json @@ -338,6 +338,7 @@ { "name": "rocker", "coord": [13, 92], + "path": [["west", 4], ["north", 4], ["south", 4], ["east", 4]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 5, "source_script": "Route12_EventScript_Luca" diff --git a/data/games/frlg/maps/base/Route14.json b/data/games/frlg/maps/base/Route14.json index 185fb44..3b10d29 100644 --- a/data/games/frlg/maps/base/Route14.json +++ b/data/games/frlg/maps/base/Route14.json @@ -215,6 +215,7 @@ { "name": "biker", "coord": [10, 37], + "wander": {"min": [10, 31], "max": [10, 43]}, "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 8, "source_script": "Route14_EventScript_Lukas" diff --git a/data/games/frlg/maps/base/Route19.json b/data/games/frlg/maps/base/Route19.json index 3285510..27fbd90 100644 --- a/data/games/frlg/maps/base/Route19.json +++ b/data/games/frlg/maps/base/Route19.json @@ -164,6 +164,7 @@ { "name": "swimmer_m_water", "coord": [18, 33], + "path": [["west", 5], ["north", 3], ["east", 5], ["south", 3]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 3, "source_script": "Route19_EventScript_Matthew" diff --git a/data/games/frlg/maps/base/Route20.json b/data/games/frlg/maps/base/Route20.json index e73c851..8a8da59 100644 --- a/data/games/frlg/maps/base/Route20.json +++ b/data/games/frlg/maps/base/Route20.json @@ -104,6 +104,7 @@ { "name": "swimmer_m_water", "coord": [23, 10], + "path": [["east", 5], ["south", 4], ["west", 5], ["north", 4]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 4, "source_script": "Route20_EventScript_Dean" @@ -119,6 +120,7 @@ { "name": "swimmer_m_water", "coord": [111, 9], + "path": [["north", 3], ["west", 5], ["south", 3], ["east", 5]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 6, "source_script": "Route20_EventScript_Barry" @@ -126,6 +128,7 @@ { "name": "swimmer_m_water", "coord": [106, 11], + "path": [["south", 3], ["west", 5], ["north", 3], ["east", 5]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 7, "source_script": "Route20_EventScript_Darrin" diff --git a/data/games/frlg/maps/base/Route21_North.json b/data/games/frlg/maps/base/Route21_North.json index 99260bd..23ac9b7 100644 --- a/data/games/frlg/maps/base/Route21_North.json +++ b/data/games/frlg/maps/base/Route21_North.json @@ -132,6 +132,7 @@ { "name": "swimmer_m_water", "coord": [12, 44], + "path": [["west", 4], ["north", 2], ["east", 4], ["south", 2]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 2, "source_script": "Route21_North_EventScript_Spencer" diff --git a/data/games/frlg/maps/base/Route25.json b/data/games/frlg/maps/base/Route25.json index b2a31f0..65d7b04 100644 --- a/data/games/frlg/maps/base/Route25.json +++ b/data/games/frlg/maps/base/Route25.json @@ -143,6 +143,7 @@ { "name": "youngster", "coord": [36, 4], + "wander": {"min": [36, 1], "max": [36, 7]}, "trainer": {"sight": 2, "looks": ["north", "east", "south", "west"]}, "source_event": 7, "source_script": "Route25_EventScript_Chad" diff --git a/data/games/frlg/maps/base/Route8.json b/data/games/frlg/maps/base/Route8.json index ee3eeb4..4ce2f81 100644 --- a/data/games/frlg/maps/base/Route8.json +++ b/data/games/frlg/maps/base/Route8.json @@ -166,6 +166,7 @@ { "name": "biker", "coord": [14, 16], + "path": [["east", 5], ["south", 2], ["west", 5], ["north", 2]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 13, "source_script": "Route8_EventScript_Ricardo" @@ -173,6 +174,7 @@ { "name": "biker", "coord": [24, 17], + "path": [["east", 5], ["north", 5], ["south", 5], ["west", 5]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 14, "source_script": "Route8_EventScript_Jaren" diff --git a/data/games/frlg/maps/base/SilphCo_5F.json b/data/games/frlg/maps/base/SilphCo_5F.json index 467b8c3..fe9e5fe 100644 --- a/data/games/frlg/maps/base/SilphCo_5F.json +++ b/data/games/frlg/maps/base/SilphCo_5F.json @@ -137,7 +137,13 @@ "source_event": 4, "source_script": "SilphCo_5F_EventScript_Grunt1" }, - {"name": "scientist", "coord": [2, 7], "source_event": 8, "source_script": "SilphCo_5F_EventScript_Scientist"} + { + "name": "scientist", + "coord": [2, 7], + "wander": {"min": [0, 7], "max": [4, 7]}, + "source_event": 8, + "source_script": "SilphCo_5F_EventScript_Scientist" + } ], "items": [ { diff --git a/data/games/frlg/maps/base/SilphCo_7F.json b/data/games/frlg/maps/base/SilphCo_7F.json index de8c022..ff1cb12 100644 --- a/data/games/frlg/maps/base/SilphCo_7F.json +++ b/data/games/frlg/maps/base/SilphCo_7F.json @@ -125,6 +125,7 @@ { "name": "worker_m", "coord": [9, 14], + "wander": {"min": [8, 14], "max": [10, 14]}, "source_event": 7, "source_script": "SilphCo_7F_EventScript_WorkerM2", "source_local_id": "LOCALID_SILPH_CO_7F_WORKER_M2" diff --git a/data/games/frlg/maps/base/VictoryRoad_2F.json b/data/games/frlg/maps/base/VictoryRoad_2F.json index ffc53c1..6abbfeb 100644 --- a/data/games/frlg/maps/base/VictoryRoad_2F.json +++ b/data/games/frlg/maps/base/VictoryRoad_2F.json @@ -196,6 +196,7 @@ { "name": "man", "coord": [26, 6], + "path": [["south", 4], ["east", 4], ["west", 4], ["north", 4]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 3, "source_script": "VictoryRoad_2F_EventScript_Vincent" diff --git a/data/games/frlg/maps/runtime/CeladonCity.json b/data/games/frlg/maps/runtime/CeladonCity.json index 4ed53fc..2ecf040 100644 --- a/data/games/frlg/maps/runtime/CeladonCity.json +++ b/data/games/frlg/maps/runtime/CeladonCity.json @@ -167,7 +167,13 @@ "source_script": "CeladonCity_EventScript_Poliwrath", "source_local_id": "LOCALID_CELADON_POLIWRATH" }, - {"name": "little_girl", "coord": [11, 18], "source_event": 3, "source_script": "CeladonCity_EventScript_LittleGirl"}, + { + "name": "little_girl", + "coord": [11, 18], + "path": [["east", 4], ["south", 4], ["west", 4], ["north", 4]], + "source_event": 3, + "source_script": "CeladonCity_EventScript_LittleGirl" + }, { "name": "woman_2", "coord": [18, 22], diff --git a/data/games/frlg/maps/runtime/MtMoon_1F.json b/data/games/frlg/maps/runtime/MtMoon_1F.json index 26204e9..1def8ed 100644 --- a/data/games/frlg/maps/runtime/MtMoon_1F.json +++ b/data/games/frlg/maps/runtime/MtMoon_1F.json @@ -97,6 +97,7 @@ { "name": "lass", "coord": [33, 4], + "path": [["west", 5], ["south", 3], ["east", 5], ["north", 3]], "trainer": {"sight": 2, "looks": ["north", "east", "south", "west"]}, "source_event": 3, "source_script": "MtMoon_1F_EventScript_Miriam" diff --git a/data/games/frlg/maps/runtime/Route11.json b/data/games/frlg/maps/runtime/Route11.json index 2a96466..afbb88a 100644 --- a/data/games/frlg/maps/runtime/Route11.json +++ b/data/games/frlg/maps/runtime/Route11.json @@ -107,6 +107,7 @@ { "name": "youngster", "coord": [28, 10], + "path": [["south", 4], ["east", 8], ["west", 8], ["north", 4]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 3, "source_script": "Route11_EventScript_Dave" @@ -135,6 +136,7 @@ { "name": "youngster", "coord": [50, 14], + "wander": {"min": [50, 10], "max": [50, 18]}, "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 7, "source_script": "Route11_EventScript_Yasu" diff --git a/data/games/frlg/maps/runtime/Route12.json b/data/games/frlg/maps/runtime/Route12.json index 839f89b..7294bf5 100644 --- a/data/games/frlg/maps/runtime/Route12.json +++ b/data/games/frlg/maps/runtime/Route12.json @@ -338,6 +338,7 @@ { "name": "rocker", "coord": [13, 92], + "path": [["west", 4], ["north", 4], ["south", 4], ["east", 4]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 5, "source_script": "Route12_EventScript_Luca" diff --git a/data/games/frlg/maps/runtime/Route14.json b/data/games/frlg/maps/runtime/Route14.json index 185fb44..3b10d29 100644 --- a/data/games/frlg/maps/runtime/Route14.json +++ b/data/games/frlg/maps/runtime/Route14.json @@ -215,6 +215,7 @@ { "name": "biker", "coord": [10, 37], + "wander": {"min": [10, 31], "max": [10, 43]}, "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 8, "source_script": "Route14_EventScript_Lukas" diff --git a/data/games/frlg/maps/runtime/Route19.json b/data/games/frlg/maps/runtime/Route19.json index 3285510..27fbd90 100644 --- a/data/games/frlg/maps/runtime/Route19.json +++ b/data/games/frlg/maps/runtime/Route19.json @@ -164,6 +164,7 @@ { "name": "swimmer_m_water", "coord": [18, 33], + "path": [["west", 5], ["north", 3], ["east", 5], ["south", 3]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 3, "source_script": "Route19_EventScript_Matthew" diff --git a/data/games/frlg/maps/runtime/Route20.json b/data/games/frlg/maps/runtime/Route20.json index e73c851..8a8da59 100644 --- a/data/games/frlg/maps/runtime/Route20.json +++ b/data/games/frlg/maps/runtime/Route20.json @@ -104,6 +104,7 @@ { "name": "swimmer_m_water", "coord": [23, 10], + "path": [["east", 5], ["south", 4], ["west", 5], ["north", 4]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 4, "source_script": "Route20_EventScript_Dean" @@ -119,6 +120,7 @@ { "name": "swimmer_m_water", "coord": [111, 9], + "path": [["north", 3], ["west", 5], ["south", 3], ["east", 5]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 6, "source_script": "Route20_EventScript_Barry" @@ -126,6 +128,7 @@ { "name": "swimmer_m_water", "coord": [106, 11], + "path": [["south", 3], ["west", 5], ["north", 3], ["east", 5]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 7, "source_script": "Route20_EventScript_Darrin" diff --git a/data/games/frlg/maps/runtime/Route21_North.json b/data/games/frlg/maps/runtime/Route21_North.json index 99260bd..23ac9b7 100644 --- a/data/games/frlg/maps/runtime/Route21_North.json +++ b/data/games/frlg/maps/runtime/Route21_North.json @@ -132,6 +132,7 @@ { "name": "swimmer_m_water", "coord": [12, 44], + "path": [["west", 4], ["north", 2], ["east", 4], ["south", 2]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 2, "source_script": "Route21_North_EventScript_Spencer" diff --git a/data/games/frlg/maps/runtime/Route25.json b/data/games/frlg/maps/runtime/Route25.json index b2a31f0..65d7b04 100644 --- a/data/games/frlg/maps/runtime/Route25.json +++ b/data/games/frlg/maps/runtime/Route25.json @@ -143,6 +143,7 @@ { "name": "youngster", "coord": [36, 4], + "wander": {"min": [36, 1], "max": [36, 7]}, "trainer": {"sight": 2, "looks": ["north", "east", "south", "west"]}, "source_event": 7, "source_script": "Route25_EventScript_Chad" diff --git a/data/games/frlg/maps/runtime/Route8.json b/data/games/frlg/maps/runtime/Route8.json index ee3eeb4..4ce2f81 100644 --- a/data/games/frlg/maps/runtime/Route8.json +++ b/data/games/frlg/maps/runtime/Route8.json @@ -166,6 +166,7 @@ { "name": "biker", "coord": [14, 16], + "path": [["east", 5], ["south", 2], ["west", 5], ["north", 2]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 13, "source_script": "Route8_EventScript_Ricardo" @@ -173,6 +174,7 @@ { "name": "biker", "coord": [24, 17], + "path": [["east", 5], ["north", 5], ["south", 5], ["west", 5]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 14, "source_script": "Route8_EventScript_Jaren" diff --git a/data/games/frlg/maps/runtime/SilphCo_5F.json b/data/games/frlg/maps/runtime/SilphCo_5F.json index 28fb2d6..d6c872d 100644 --- a/data/games/frlg/maps/runtime/SilphCo_5F.json +++ b/data/games/frlg/maps/runtime/SilphCo_5F.json @@ -138,7 +138,13 @@ "source_script": "SilphCo_5F_EventScript_Grunt1", "coord": [9, 21] }, - {"name": "scientist", "source_event": 8, "source_script": "SilphCo_5F_EventScript_Scientist", "coord": [2, 7]} + { + "name": "scientist", + "wander": {"min": [0, 7], "max": [4, 7]}, + "source_event": 8, + "source_script": "SilphCo_5F_EventScript_Scientist", + "coord": [2, 7] + } ], "items": [ { diff --git a/data/games/frlg/maps/runtime/SilphCo_7F.json b/data/games/frlg/maps/runtime/SilphCo_7F.json index f8fbe3b..bc727a7 100644 --- a/data/games/frlg/maps/runtime/SilphCo_7F.json +++ b/data/games/frlg/maps/runtime/SilphCo_7F.json @@ -125,6 +125,7 @@ {"name": "worker_m", "source_event": 6, "source_script": "SilphCo_7F_EventScript_WorkerM1", "coord": [13, 14]}, { "name": "worker_m", + "wander": {"min": [8, 14], "max": [10, 14]}, "source_event": 7, "source_script": "SilphCo_7F_EventScript_WorkerM2", "source_local_id": "LOCALID_SILPH_CO_7F_WORKER_M2", diff --git a/data/games/frlg/maps/runtime/VictoryRoad_2F.json b/data/games/frlg/maps/runtime/VictoryRoad_2F.json index 984aa95..18b77d9 100644 --- a/data/games/frlg/maps/runtime/VictoryRoad_2F.json +++ b/data/games/frlg/maps/runtime/VictoryRoad_2F.json @@ -196,6 +196,7 @@ }, { "name": "man", + "path": [["south", 4], ["east", 4], ["west", 4], ["north", 4]], "trainer": {"sight": 1, "looks": ["north", "east", "south", "west"]}, "source_event": 3, "source_script": "VictoryRoad_2F_EventScript_Vincent", diff --git a/data/maps/runtime-manifest.json b/data/maps/runtime-manifest.json index 99396d3..bac7cd4 100644 --- a/data/maps/runtime-manifest.json +++ b/data/maps/runtime-manifest.json @@ -9,7 +9,7 @@ { "name": "CeladonCity", "file": "data/games/frlg/maps/runtime/CeladonCity.json", - "sha256": "6633a14ec03259b9585e7dc5c1f0b6498edf7b7cc9187e755e8c357b0edcab34", + "sha256": "a32481268755b54eba82ccddd403ab93ef37538072562aad706f1771bddec435", "source": { "decomp_file": "data/maps/CeladonCity/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -49,7 +49,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/CeladonCity.json", - "sha256": "6633a14ec03259b9585e7dc5c1f0b6498edf7b7cc9187e755e8c357b0edcab34" + "sha256": "a32481268755b54eba82ccddd403ab93ef37538072562aad706f1771bddec435" } }, { @@ -1327,7 +1327,7 @@ { "name": "MtMoon_1F", "file": "data/games/frlg/maps/runtime/MtMoon_1F.json", - "sha256": "809cd258e150853f8f0affbd792d586c8576a66629f5511552ebb5c5b00d3a4d", + "sha256": "5f1d04efa1b65bee64724d02c0476ee345b3dfbc7d07bdb394740ca317bb2f3a", "upstream_path": "SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/MtMoon_1F.json", "source": { "decomp_file": "data/maps/MtMoon_1F/map.json", @@ -1374,7 +1374,7 @@ }, "base": { "file": "data/games/frlg/maps/base/MtMoon_1F.json", - "sha256": "809cd258e150853f8f0affbd792d586c8576a66629f5511552ebb5c5b00d3a4d" + "sha256": "5f1d04efa1b65bee64724d02c0476ee345b3dfbc7d07bdb394740ca317bb2f3a" } }, { @@ -3030,7 +3030,7 @@ { "name": "Route11", "file": "data/games/frlg/maps/runtime/Route11.json", - "sha256": "8985056f969c0686850ad7c18e8f8bb2320b1785fc85aa1d2f273f134b69410e", + "sha256": "4cf4d50378d864d70b3a409284c071f21bcac82912aff2a512a99e8152d7de07", "source": { "decomp_file": "data/maps/Route11/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -3070,7 +3070,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/Route11.json", - "sha256": "8985056f969c0686850ad7c18e8f8bb2320b1785fc85aa1d2f273f134b69410e" + "sha256": "4cf4d50378d864d70b3a409284c071f21bcac82912aff2a512a99e8152d7de07" } }, { @@ -3111,7 +3111,7 @@ { "name": "Route12", "file": "data/games/frlg/maps/runtime/Route12.json", - "sha256": "14d442d97d709d0a40be1622476c6828b33c97d33a00ece9ee3fcd9eb2895804", + "sha256": "152d55c8a18240b026e6cf67b30508d51a6aac06bea68719093e41d080dc7b1b", "source": { "decomp_file": "data/maps/Route12/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -3151,7 +3151,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/Route12.json", - "sha256": "14d442d97d709d0a40be1622476c6828b33c97d33a00ece9ee3fcd9eb2895804" + "sha256": "152d55c8a18240b026e6cf67b30508d51a6aac06bea68719093e41d080dc7b1b" } }, { @@ -3226,7 +3226,7 @@ { "name": "Route14", "file": "data/games/frlg/maps/runtime/Route14.json", - "sha256": "2c7a2ca34580235a380e02fa981ea4fe4f281393df916b2871b60634cff52b07", + "sha256": "eda215f6fbf9f5da026dc3e62d016dcd79f87f97a5104a5d3020582501e79eab", "source": { "decomp_file": "data/maps/Route14/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -3254,7 +3254,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/Route14.json", - "sha256": "2c7a2ca34580235a380e02fa981ea4fe4f281393df916b2871b60634cff52b07" + "sha256": "eda215f6fbf9f5da026dc3e62d016dcd79f87f97a5104a5d3020582501e79eab" } }, { @@ -3515,7 +3515,7 @@ { "name": "Route19", "file": "data/games/frlg/maps/runtime/Route19.json", - "sha256": "32334780c5e81e03842354b7b6fbf0fb9fcfee8225bae4216c006d3617096a09", + "sha256": "6ae4bdd6e98be87a7c22e8b13357f0ec47b82db32fc8177a5f1d0cf7e40ea91d", "source": { "decomp_file": "data/maps/Route19/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -3543,7 +3543,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/Route19.json", - "sha256": "32334780c5e81e03842354b7b6fbf0fb9fcfee8225bae4216c006d3617096a09" + "sha256": "6ae4bdd6e98be87a7c22e8b13357f0ec47b82db32fc8177a5f1d0cf7e40ea91d" } }, { @@ -3602,7 +3602,7 @@ { "name": "Route20", "file": "data/games/frlg/maps/runtime/Route20.json", - "sha256": "813ef18147a184416137408aedb46cae313d5dbe9b5d190115a2aaa07274c645", + "sha256": "58389e90e75f41c5f78720fcb4570ffa367cb48fe631a601b2bb75734d67add5", "source": { "decomp_file": "data/maps/Route20/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -3630,13 +3630,13 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/Route20.json", - "sha256": "813ef18147a184416137408aedb46cae313d5dbe9b5d190115a2aaa07274c645" + "sha256": "58389e90e75f41c5f78720fcb4570ffa367cb48fe631a601b2bb75734d67add5" } }, { "name": "Route21_North", "file": "data/games/frlg/maps/runtime/Route21_North.json", - "sha256": "083f789200e275429cffa470c9322878d61b7d9fcdbf42980abd47d2d813c2f4", + "sha256": "ff46809674ee535430330af9cdaa0a784ae5217a310de0705de6aea1c71c2d95", "source": { "decomp_file": "data/maps/Route21_North/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -3664,7 +3664,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/Route21_North.json", - "sha256": "083f789200e275429cffa470c9322878d61b7d9fcdbf42980abd47d2d813c2f4" + "sha256": "ff46809674ee535430330af9cdaa0a784ae5217a310de0705de6aea1c71c2d95" } }, { @@ -3865,7 +3865,7 @@ { "name": "Route25", "file": "data/games/frlg/maps/runtime/Route25.json", - "sha256": "41a94d698a61e9dfb65f4dec050117fcb0bb9c07a497e8fdc14921672a48091c", + "sha256": "a5c4db46c5f057734da815e35d5449a0a6de58d1956ccbf3e4d38cd2ec62eeae", "upstream_path": "SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/Maps/Route25.json", "source": { "decomp_file": "data/maps/Route25/map.json", @@ -3911,7 +3911,7 @@ }, "base": { "file": "data/games/frlg/maps/base/Route25.json", - "sha256": "41a94d698a61e9dfb65f4dec050117fcb0bb9c07a497e8fdc14921672a48091c" + "sha256": "a5c4db46c5f057734da815e35d5449a0a6de58d1956ccbf3e4d38cd2ec62eeae" } }, { @@ -4429,7 +4429,7 @@ { "name": "Route8", "file": "data/games/frlg/maps/runtime/Route8.json", - "sha256": "bf715f82fb2edb389e4fbc1cf5ccb542629ef05d9762fd08bb1dc877af90dd98", + "sha256": "6765f3632f56b06e7eb1840133b915eb47a1e64f386820bcec9e0e65cf5b884f", "source": { "decomp_file": "data/maps/Route8/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -4458,7 +4458,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/Route8.json", - "sha256": "bf715f82fb2edb389e4fbc1cf5ccb542629ef05d9762fd08bb1dc877af90dd98" + "sha256": "6765f3632f56b06e7eb1840133b915eb47a1e64f386820bcec9e0e65cf5b884f" } }, { @@ -5407,7 +5407,7 @@ { "name": "SilphCo_5F", "file": "data/games/frlg/maps/runtime/SilphCo_5F.json", - "sha256": "d44c6fafc5779cea7425be540958eac7432152ec3bba44ccc5ec17d52600f6b4", + "sha256": "ab9445a98979d49dda4fb7afe6a88a588a87c9bd1c13bc680b9698825e75f6c5", "source": { "decomp_file": "data/maps/SilphCo_5F/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -5452,7 +5452,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/SilphCo_5F.json", - "sha256": "ce43b0df2f2260a0348cdb3ce89d26ab01d0f88dd0d4eddb2e4c3f9373eedca3" + "sha256": "a042ac4b2c268d941e0458f2e58d51802790413fb5012acbaa6bc133e1c04302" }, "overlay": { "file": "data/games/frlg/maps/overlays/SilphCo_5F.json", @@ -5517,7 +5517,7 @@ { "name": "SilphCo_7F", "file": "data/games/frlg/maps/runtime/SilphCo_7F.json", - "sha256": "add2ebf8c19c13e7d1e216b635df68374bef32cf3434b2d47d15c9b0bcb58d36", + "sha256": "7336f91715c2f7f1bc4c34ac22adc19369a91fb7888c7a64253b17cbba5b53dc", "source": { "decomp_file": "data/maps/SilphCo_7F/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -5562,7 +5562,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/SilphCo_7F.json", - "sha256": "9a22e5dac1b0c36338c9ef60bce85951459ca732675e65bd120586d18d70c6a7" + "sha256": "837b5dfb73d6837ad7489e5f208e947b5d9c098a0fd93e2324532aa837269a6d" }, "overlay": { "file": "data/games/frlg/maps/overlays/SilphCo_7F.json", @@ -6156,7 +6156,7 @@ { "name": "VictoryRoad_2F", "file": "data/games/frlg/maps/runtime/VictoryRoad_2F.json", - "sha256": "a8fea35e8a9c15a34aeee10604e42e711bcfb9f769636c18238f287d8b5cd565", + "sha256": "1018fed7b1f8e1504dcbec02f38ef609b3b0b0576f18d2c1ad7f2b686c9d10b5", "source": { "decomp_file": "data/maps/VictoryRoad_2F/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", @@ -6200,7 +6200,7 @@ "status": "candidate", "base": { "file": "data/games/frlg/maps/base/VictoryRoad_2F.json", - "sha256": "0ef4254d9ed8e2f6dab103ad5c00cc9eb4c8c9598f877b1534fc92bae8315195" + "sha256": "5b46bfcd40278939f990065bab5e584078f419984a3ed7e92bca582c34ca96cf" }, "overlay": { "file": "data/games/frlg/maps/overlays/VictoryRoad_2F.json", diff --git a/schemas/runtime-map-v2.schema.json b/schemas/runtime-map-v2.schema.json index ff26590..c659552 100644 --- a/schemas/runtime-map-v2.schema.json +++ b/schemas/runtime-map-v2.schema.json @@ -253,6 +253,21 @@ "required": ["min", "max"], "additionalProperties": true }, + "path": { + "type": "array", + "description": "legs a walk-sequence person walks from their coord, back to it and over again; a last leg marked stuck ends where they stop for good", + "minItems": 1, + "items": { + "type": "array", + "prefixItems": [ + {"$ref": "#/$defs/direction"}, + {"type": "integer", "minimum": 1}, + {"const": "stuck"} + ], + "items": false, + "minItems": 2 + } + }, "npc": { "type": "object", "properties": { @@ -261,7 +276,8 @@ "facing": {"$ref": "#/$defs/direction"}, "hide_flag": {"type": "string"}, "source_event": {"type": "integer", "minimum": 0, "maximum": 2147483647}, - "wander": {"$ref": "#/$defs/wander"} + "wander": {"$ref": "#/$defs/wander"}, + "path": {"$ref": "#/$defs/path"} }, "required": ["coord", "name"], "additionalProperties": true, diff --git a/src/pokesim/cli/route.py b/src/pokesim/cli/route.py index 5da1d4f..20590ce 100644 --- a/src/pokesim/cli/route.py +++ b/src/pokesim/cli/route.py @@ -137,7 +137,7 @@ def main(argv=None): moves=[dict(direction=move.direction.name.lower(), kind=move.kind.value, tile=list(move.to.place.tile), elevation=move.to.elevation) for move in path.moves], limitations=['single-map static route; transitions excluded', - 'NPC wander boxes conservatively occupied; trainer sight and omitted NPCs not simulated', + 'NPC wander boxes and walk paths conservatively occupied; trainer sight and omitted NPCs not simulated', 'scene effects, encounters and recovery not simulated']) args.json.write_text(json.dumps(report, indent=2) + '\n') sys.stdout.write(ascii_route(view, path)) diff --git a/src/pokesim/maps/frlg_decomp_map_builder.py b/src/pokesim/maps/frlg_decomp_map_builder.py index 87e785d..25d9773 100644 --- a/src/pokesim/maps/frlg_decomp_map_builder.py +++ b/src/pokesim/maps/frlg_decomp_map_builder.py @@ -56,6 +56,7 @@ import sys from pokesim.formats.contract_format import json_text as contract_json_text +from . import npc_path from .runtime_symbols import CLOSED_SIDES, LEDGE_GLYPHS from .item_identity import INPUTS as ITEM_SOURCE_INPUTS, digest, enrich_objects from .item_pickup_sources import frlg_pickups, unresolved as unresolved_pickup @@ -537,14 +538,25 @@ def grid(decomp, layout, names, unhandled, signs=frozenset(), land_encounters=Fa return tiles, elevation, entries, wild_edges +# Movement types that wander or walk back and forth: they stay within +# initial +- range (IsCoordOutsideObjectEventMovementRange() in +# src/event_object_movement.c). The pairs move along one axis only. Walk +# sequences (WALK_SEQUENCE) walk a fixed path instead; see walk_sequence(). +MOVING = ('MOVEMENT_TYPE_WANDER_', 'MOVEMENT_TYPE_WALK_UP_AND_DOWN', + 'MOVEMENT_TYPE_WALK_DOWN_AND_UP', 'MOVEMENT_TYPE_WALK_LEFT_AND_RIGHT', 'MOVEMENT_TYPE_WALK_RIGHT_AND_LEFT') +WALK_SEQUENCE = 'MOVEMENT_TYPE_WALK_SEQUENCE_' +VERTICAL = ('UP_AND_DOWN', 'DOWN_AND_UP') +HORIZONTAL = ('LEFT_AND_RIGHT', 'RIGHT_AND_LEFT') + + def wander_box(obj, tiles): - """The tiles a wandering person may stand on, kept inside the map, or None - if they stand still.""" + """The tiles a person who walks on their own may stand on, kept inside the + map, or None if they stand still.""" movement = obj.get('movement_type', '') - if 'WANDER' not in movement: + if not movement.startswith(MOVING): 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) + x = 0 if movement.endswith(VERTICAL) else int(obj.get('movement_range_x') or 0) + y = 0 if movement.endswith(HORIZONTAL) else int(obj.get('movement_range_y') or 0) if x == 0 and y == 0: return None return { @@ -553,6 +565,174 @@ def wander_box(obj, tiles): } + +class Ground: + """What a person's step checks on each tile of a map: the blockdata + collision bits, metatile behavior and elevation (GetCollisionAtCoords() in + src/event_object_movement.c), as rows.""" + def __init__(self, collision, behavior, elevation): + self.collision, self.behavior, self.elevation = collision, behavior, elevation + + def inside(self, x, y): + return 0 <= y < len(self.collision) and 0 <= x < len(self.collision[0]) + + +def read_ground(decomp, layout, names): + """The Ground of `layout`, from its blockdata and tilesets.""" + width, height = layout['width'], layout['height'] + blocks = decomp.read(layout['blockdata_filepath']) + primary = tileset_attributes(decomp, layout['primary_tileset']) + secondary = tileset_attributes(decomp, layout['secondary_tileset']) + collision, behavior, elevation = [], [], [] + for y in range(height): + values = [struct.unpack_from('> 10) & 3 for value in values]) + elevation.append([value >> 12 for value in values]) + behavior.append([names.get((primary[value & 0x3ff] if value & 0x3ff < 640 else secondary[(value & 0x3ff) - 640]) & 0x1ff, '') + for value in values]) + return Ground(collision, behavior, elevation) + + +STEPS = {'UP': (0, -1), 'DOWN': (0, 1), 'LEFT': (-1, 0), 'RIGHT': (1, 0)} +# The behaviors that close a tile's side (MetatileBehavior_Is*Blocked() in +# src/metatile_behavior.c), by side. +CLOSED_BY = { + 'UP': ('MB_IMPASSABLE_NORTH', 'MB_IMPASSABLE_NORTHEAST', 'MB_IMPASSABLE_NORTHWEST'), + 'DOWN': ('MB_IMPASSABLE_SOUTH', 'MB_IMPASSABLE_SOUTHEAST', 'MB_IMPASSABLE_SOUTHWEST'), + 'LEFT': ('MB_IMPASSABLE_WEST', 'MB_IMPASSABLE_NORTHWEST', 'MB_IMPASSABLE_SOUTHWEST'), + 'RIGHT': ('MB_IMPASSABLE_EAST', 'MB_IMPASSABLE_NORTHEAST', 'MB_IMPASSABLE_SOUTHEAST'), +} +OPPOSITE = {'UP': 'DOWN', 'DOWN': 'UP', 'LEFT': 'RIGHT', 'RIGHT': 'LEFT'} + + +def walk_sequence_rules(source): + """Each walk sequence's shortcut, from its MovementType_WalkSequence*_Step1() + in src/event_object_movement.c, by movement type: (index, axis), where at + sequence index `index`, back on its start column (axis x) or row (axis y), + the person skips to the next direction.""" + rules = {} + for name, index, axis, to in re.findall( + r'MovementType_WalkSequence(\w+)_Step1\(.*?\)\s*\{.*?directionSequenceIndex == (\d) && ' + r'objectEvent->initialCoords\.([xy]) == objectEvent->currentCoords\.\3\)\s*\{\s*' + r'objectEvent->directionSequenceIndex = (\d);', source, re.S): + if int(to) != int(index) + 1: + raise ValueError('unexpected walk sequence shortcut in ' + name) + movement = WALK_SEQUENCE + re.sub(r'(? 3: + raise ValueError(f'walk sequence from {start} runs past its last direction') + hit = collision(x, y, level, directions[index]) + if not hit: + dx, dy = STEPS[directions[index]] + x, y = x + dx, y + dy + if ground.elevation[y][x] != 15: + level = ground.elevation[y][x] + tiles.append([x, y]) + index = next_index(x, y, index) + loop = tile_of_state[seen[(x, y, index, level)]] + if tiles[-1] == tiles[loop] and loop != len(tiles) - 1: + tiles.pop() # back where the loop starts + return {'tiles': tiles, 'loop': loop} + + +LEG_DIRECTIONS = {step: direction for direction, step in npc_path.STEPS.items()} + + +def path_legs(walk): + """A walk_sequence() walk as path legs (npc_path), or None if the person + never leaves their start tile. Raises unless the walk loops back to its + start or stops for good.""" + tiles, loop = walk['tiles'], walk['loop'] + if len(tiles) == 1: + return None + if loop == 0: + steps, stops = tiles + [tiles[0]], False + elif loop == len(tiles) - 1: + steps, stops = tiles, True + else: + raise ValueError(f'walk from {tiles[0]} neither returns to its start nor stops') + legs = [] + for (ax, ay), (bx, by) in zip(steps, steps[1:]): + direction = LEG_DIRECTIONS[(bx - ax, by - ay)] + if legs and legs[-1][0] == direction: + legs[-1][1] += 1 + else: + legs.append([direction, 1]) + if stops: + legs[-1].append(npc_path.STUCK) + return legs + + +def sequence_path(obj, ground, rules, objects=frozenset()): + """A walk sequence's path legs (path_legs()), or None for any other movement.""" + movement = obj.get('movement_type', '') + if not movement.startswith(WALK_SEQUENCE): + return None + directions = movement[len(WALK_SEQUENCE):].split('_') + ranges = (int(obj.get('movement_range_x') or 0), int(obj.get('movement_range_y') or 0)) + return path_legs(walk_sequence((obj['x'], obj['y']), int(obj.get('elevation') or 0), ranges, directions, + rules[movement], ground, objects)) + + # Which way a person stands, by how they move. FACINGS = { 'MOVEMENT_TYPE_FACE_UP': 'north', 'MOVEMENT_TYPE_FACE_DOWN': 'south', @@ -585,7 +765,7 @@ def trainer(obj): return {'sight': sight, 'looks': TURNING_LOOKS.get(movement, ALL_LOOKS)} -def map_object(obj, tiles, event_index=None): +def map_object(obj, tiles, event_index=None, path=None): 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']} if kind == 'item_ball' and event_index is not None: @@ -597,6 +777,8 @@ def map_object(obj, tiles, event_index=None): box = wander_box(obj, tiles) if box: data['wander'] = box + if path: + data['path'] = path sight = trainer(obj) if sight: # A trainer who faces one way looks that way. @@ -764,6 +946,21 @@ def land_encounter_maps(decomp): return {e['map'] for group in groups for e in group.get('encounters', []) if 'land_mons' in e} +def walk_sequence_paths(decomp, source, layouts, names): + """The path of each person on the map who walks a sequence, by object + event index. People who don't move on their own block them.""" + objects = source.get('object_events', []) + walkers = [index for index, obj in enumerate(objects) if obj.get('movement_type', '').startswith(WALK_SEQUENCE)] + if not walkers: + return {} + rules = walk_sequence_rules(decomp.read('src/event_object_movement.c').decode()) + land = read_ground(decomp, layouts[source['layout']], names) + standing = frozenset((obj['x'], obj['y']) for obj in objects + if not obj.get('movement_type', '').startswith((WALK_SEQUENCE,) + MOVING)) + paths = {index: sequence_path(objects[index], land, rules, standing) for index in walkers} + return {index: path for index, path in paths.items() if path} + + def map_json(decomp, name, sources, layouts, names, loaded, unhandled, land_maps=frozenset(), include_item_identities=False, candidate=False): source = sources[name] signs = frozenset((e['x'], e['y']) for e in source.get('bg_events', []) if e.get('type') == 'sign') @@ -786,6 +983,7 @@ def map_json(decomp, name, sources, layouts, names, loaded, unhandled, land_maps 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']] + paths = walk_sequence_paths(decomp, source, layouts, names) data = { 'name': name, 'source': {'decomp_file': f'data/maps/{name}/map.json', 'revision': getattr(decomp, 'commit', COMMIT), 'date': COMMIT_DATE}, @@ -796,7 +994,8 @@ def map_json(decomp, name, sources, layouts, names, loaded, unhandled, land_maps '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, index if include_item_identities else None) for index, obj in enumerate(source.get('object_events', [])) + map_object(obj, tiles, index if include_item_identities else None, paths.get(index)) + for index, obj in enumerate(source.get('object_events', [])) if 0 <= obj['x'] < len(tiles[0]) and 0 <= obj['y'] < len(tiles) ], 'flag_sets': FLAG_SETS.get(name, {}), diff --git a/src/pokesim/maps/local_routing.py b/src/pokesim/maps/local_routing.py index b7ea5bc..0ea786d 100644 --- a/src/pokesim/maps/local_routing.py +++ b/src/pokesim/maps/local_routing.py @@ -16,6 +16,7 @@ from pokesim.grid.movement import (FLAT, Blocked, BlockReason, Edge, Hop, Moved, PlayerState, Warp, WorldState, step) from pokesim.grid.routing.shortest import Costs, shortest_path +from .npc_path import path_tiles from .consumer_source import GitSource, lock_entry, published_pack, read_json from .runtime_map_pack import effective_map from .runtime_symbols import CLOSED_SIDES, cell_for @@ -95,6 +96,8 @@ def _objects(self): if box: occupied.update(Tile(x, y) for y in range(box['y0'], box['y1'] + 1) for x in range(box['x0'], box['x1'] + 1)) + elif 'path' in obj: + occupied.update(Tile(x, y) for x, y in path_tiles((obj['x'], obj['y']), obj['path'])) else: occupied.add(Tile(obj['x'], obj['y'])) return occupied diff --git a/src/pokesim/maps/npc_path.py b/src/pokesim/maps/npc_path.py new file mode 100644 index 0000000..95a1113 --- /dev/null +++ b/src/pokesim/maps/npc_path.py @@ -0,0 +1,49 @@ +"""A person's walk path: legs from their start tile. + +A path is a list of legs `[direction, tiles]`, direction north, east, south or +west, walked in order from the person's own coord. It returns to that coord +and starts over, unless its last leg has a third element, "stuck": the person +stops on the tile it ends on and stays there. +""" + +STEPS = {'north': (0, -1), 'east': (1, 0), 'south': (0, 1), 'west': (-1, 0)} +STUCK = 'stuck' + + +def path_tiles(start, legs): + """Every tile on the path, in walking order: `start`, then one tile per + step of each leg.""" + x, y = start + tiles = [(x, y)] + for leg in legs: + dx, dy = STEPS[leg[0]] + for _ in range(leg[1]): + x, y = x + dx, y + dy + tiles.append((x, y)) + return tiles + + +def stuck(legs): + """Whether the person stops for good at the end of the path.""" + return bool(legs) and len(legs[-1]) == 3 + + +def path_error(start, legs, width, height): + """Why `legs` is no valid path from `start` on a `width` x `height` map, or None.""" + if not isinstance(legs, list) or not legs: + return 'a path is a nonempty list of legs' + for index, leg in enumerate(legs): + if not isinstance(leg, list) or len(leg) not in (2, 3) or leg[0] not in STEPS: + return 'a leg is [direction, tiles] or [direction, tiles, "stuck"]' + if type(leg[1]) is not int or leg[1] < 1: + return 'a leg walks at least one tile' + if len(leg) == 3 and (leg[2] != STUCK or index != len(legs) - 1): + return 'only the last leg may be "stuck"' + if index and leg[0] == legs[index - 1][0]: + return 'consecutive legs go different ways' + tiles = path_tiles(start, legs) + if not all(0 <= x < width and 0 <= y < height for x, y in tiles): + return 'a path leaves the map' + if not stuck(legs) and tiles[-1] != tuple(start): + return 'a path returns to its start unless stuck' + return None diff --git a/src/pokesim/maps/route_drawing.py b/src/pokesim/maps/route_drawing.py index cc4efbb..a9b9581 100644 --- a/src/pokesim/maps/route_drawing.py +++ b/src/pokesim/maps/route_drawing.py @@ -6,6 +6,7 @@ from pokesim.grid.maps import render from pokesim.grid.maps.render import Overlay from pokesim.grid.maps.schema import MapImage +from .npc_path import path_tiles from .runtime_symbols import CLOSED_SIDES @@ -58,6 +59,8 @@ def route_image(view, path, tile_px=16, goal_tiles=()): if box: _outline(image, box['x0'] * tile_px, box['y0'] * tile_px, (box['x1'] + 1) * tile_px, (box['y1'] + 1) * tile_px, (145, 95, 20, 160)) + for x, y in path_tiles((obj['x'], obj['y']), obj['path']) if 'path' in obj else (): + _outline(image, x * tile_px, y * tile_px, (x + 1) * tile_px, (y + 1) * tile_px, (145, 95, 20, 160)) cx, cy = (obj['x'] + .5) * tile_px, (obj['y'] + .5) * tile_px image.fill_rect(int(cx) - 3, int(cy) - 3, int(cx) + 3, int(cy) + 3, OBJECT_COLOR) for x in range(view.map_file.grid.width + 1): @@ -118,6 +121,9 @@ def text(x, y, value, size=12, extra=''): parts.append(f'') + for x, y in path_tiles((obj['x'], obj['y']), obj['path']) if 'path' in obj else (): + parts.append(f'') parts.append(f'') if obj.get('kind') == 'item' and obj.get('item'): label = obj['item'].replace('_', ' ').title() + ' ×' + str(obj['quantity']) diff --git a/src/pokesim/maps/route_picture.py b/src/pokesim/maps/route_picture.py index 33044e4..cbde837 100644 --- a/src/pokesim/maps/route_picture.py +++ b/src/pokesim/maps/route_picture.py @@ -20,6 +20,7 @@ from pokesim.grid.geometry import Tile from pokesim.grid.maps.model import LEDGE_DIRECTION, Behavior from pokesim.png import Image +from .npc_path import path_tiles from .runtime_symbols import CLOSED_SIDES @@ -96,6 +97,18 @@ def _clip(zone, box): return clipped if clipped['x0'] <= clipped['x1'] and clipped['y0'] <= clipped['y1'] else None +def _zones(obj, box): + """Where a person may stand, cut to the drawn rectangle: their wander box, + or each tile of the path they walk.""" + if 'wander' in obj: + zones = [obj['wander']] + elif 'path' in obj: + zones = [dict(x0=x, y0=y, x1=x, y1=y) for x, y in path_tiles((obj['x'], obj['y']), obj['path'])] + else: + zones = [] + return [zone for zone in (_clip(zone, box) for zone in zones) if zone] + + def visible_objects(view): return [obj for obj in view.data.get('objects', []) if not obj.get('hide_flag') or obj['hide_flag'] not in view.context.flags] @@ -194,8 +207,7 @@ def text(x, y, value, cls='', extra=''): parts.append(f'') for obj in visible_objects(view): - zone = obj.get('wander') and _clip(obj['wander'], (x0, y0, x1, y1)) - if zone: + for zone in _zones(obj, (x0, y0, x1, y1)): parts.append(f'') @@ -300,8 +312,7 @@ def outline(ax, ay, bx, by, color, width=1, dash=0): if x0 <= x <= x1 and y0 <= y <= y1: outline((x - x0) * t, (y - y0) * t, (x - x0 + 1) * t, (y - y0 + 1) * t, _RGB(REGION_COLOR)) for obj in visible_objects(view): - zone = obj.get('wander') and _clip(obj['wander'], (x0, y0, x1, y1)) - if zone: + for zone in _zones(obj, (x0, y0, x1, y1)): outline((zone['x0'] - x0) * t, (zone['y0'] - y0) * t, (zone['x1'] - x0 + 1) * t, (zone['y1'] - y0 + 1) * t, _RGB(ZONE_EDGE), 2, 3) if x0 <= obj['x'] <= x1 and y0 <= obj['y'] <= y1: diff --git a/src/pokesim/maps/runtime_map_schema.py b/src/pokesim/maps/runtime_map_schema.py index 615a219..a20fc4a 100644 --- a/src/pokesim/maps/runtime_map_schema.py +++ b/src/pokesim/maps/runtime_map_schema.py @@ -4,6 +4,7 @@ game-specific flag/trigger semantics belong to the replay adapter. """ +from .npc_path import path_error from .runtime_symbols import GLYPHS from .runtime_map_coordinates import COMPACT, LEGACY, legacy_map @@ -80,6 +81,9 @@ def tile(x, y): tile(box['x0'], box['y0']) tile(box['x1'], box['y1']) require(box['x0'] <= box['x1'] and box['y0'] <= box['y1'], 'inverted wander box') + if 'path' in obj: + error = path_error((obj['x'], obj['y']), obj['path'], width, height) + require(error is None, f"{obj['name']} ({obj['x']}, {obj['y']}): {error}") for event in data.get('coord_events', []): tile(event['x'], event['y']) require(type(event['width']) is int and type(event['length']) is int diff --git a/src/pokesim/maps/test_frlg_decomp_map_builder.py b/src/pokesim/maps/test_frlg_decomp_map_builder.py index 3223648..b91e44b 100644 --- a/src/pokesim/maps/test_frlg_decomp_map_builder.py +++ b/src/pokesim/maps/test_frlg_decomp_map_builder.py @@ -1,9 +1,12 @@ # Imported from dayfine/Arduino-Source@51c0ce6128e5981da56b370a770874b96a1e129f # Original path: devtools/maps/tests/test_frlg_maps.py +import json +import os +from pathlib import Path import unittest from pokesim.grid.geometry import Tile -from pokesim.maps import frlg_decomp_map_builder as frlg_maps +from pokesim.maps import frlg_decomp_map_builder as frlg_maps, npc_path from pokesim.maps.local_routing import LocalMap from pokesim.maps.runtime_map_pack import ROOT, load @@ -41,6 +44,181 @@ def test_others_are_no_trainers(self): self.assertNotIn('facing', data) +class WalkerBoxTest(unittest.TestCase): + def test_box_by_movement(self): + # Each case: name, input (movement type, range), expectation (wander box or None). + # Walkers stay within initial +- range (IsCoordOutsideObjectEventMovementRange()). + cases = ( + ('a walk sequence walks a path, not a box', ('MOVEMENT_TYPE_WALK_SEQUENCE_LEFT_UP_RIGHT_DOWN', 1, 2), None), + ('walking up and down keeps to its column', ('MOVEMENT_TYPE_WALK_UP_AND_DOWN', 1, 1), + {'x0': 2, 'y0': 1, 'x1': 2, 'y1': 3}), + ('walking down and up keeps to its column', ('MOVEMENT_TYPE_WALK_DOWN_AND_UP', 1, 1), + {'x0': 2, 'y0': 1, 'x1': 2, 'y1': 3}), + ('walking left and right keeps to its row', ('MOVEMENT_TYPE_WALK_LEFT_AND_RIGHT', 1, 1), + {'x0': 1, 'y0': 2, 'x1': 3, 'y1': 2}), + ('walking right and left keeps to its row', ('MOVEMENT_TYPE_WALK_RIGHT_AND_LEFT', 1, 1), + {'x0': 1, 'y0': 2, 'x1': 3, 'y1': 2}), + ('wandering down and up keeps to its column', ('MOVEMENT_TYPE_WANDER_DOWN_AND_UP', 1, 1), + {'x0': 2, 'y0': 1, 'x1': 2, 'y1': 3}), + ('facing one way stands', ('MOVEMENT_TYPE_FACE_DOWN', 1, 1), None), + ('looking around stands', ('MOVEMENT_TYPE_LOOK_AROUND', 1, 1), None), + ('walking in place stands', ('MOVEMENT_TYPE_WALK_IN_PLACE_DOWN', 1, 1), None), + ) + for name, (movement, range_x, range_y), box in cases: + with self.subTest(name): + data = frlg_maps.map_object(event(movement_type=movement, movement_range_x=range_x, + movement_range_y=range_y), TILES) + self.assertEqual(data.get('wander'), box) + + +def ground(rows, behaviors=None): + """A Ground from glyph rows: # blocked, w water (elevation 1), . land (elevation 3).""" + behaviors = behaviors or {} + return frlg_maps.Ground( + [[1 if glyph == '#' else 0 for glyph in row] for row in rows], + [[behaviors.get((x, y), '') for x in range(len(row))] for y, row in enumerate(rows)], + [[1 if glyph == 'w' else 3 for glyph in row] for row in rows]) + + +OPEN = ['.....'] * 5 +RIGHT_DOWN_LEFT_UP = (['RIGHT', 'DOWN', 'LEFT', 'UP'], (2, 'x')) +DOWN_RIGHT_LEFT_UP = (['DOWN', 'RIGHT', 'LEFT', 'UP'], (2, 'x')) + + +class WalkSequenceTest(unittest.TestCase): + def test_legs_by_ground(self): + # Each case: name, input (ground, start elevation, ranges, sequence, + # people standing), expectation (path legs, None for standing still). Start (1, 1). + loop = [['east', 2], ['south', 2], ['west', 2], ['north', 2]] + stopped = [['east', 2], ['south', 1, 'stuck']] + cases = ( + ('walks its range edges back to the start', (ground(OPEN), 3, (2, 2), RIGHT_DOWN_LEFT_UP, ()), loop), + ('back on its start column it skips the rest of the way left', + (ground(OPEN), 3, (2, 2), DOWN_RIGHT_LEFT_UP, ()), + [['south', 2], ['east', 2], ['west', 2], ['north', 2]]), + ('a wall stops it for good', (ground(['.....'] * 3 + ['...#.', '.....']), 3, (2, 2), RIGHT_DOWN_LEFT_UP, ()), + stopped), + ('a wall next to the start keeps it there', + (ground(['.....', '..#..'] + ['.....'] * 3), 3, (2, 2), RIGHT_DOWN_LEFT_UP, ()), None), + ('a closed side stops it', (ground(OPEN, {(3, 2): 'MB_IMPASSABLE_SOUTH'}), 3, (2, 2), RIGHT_DOWN_LEFT_UP, ()), + stopped), + ('a swimmer stops at land', (ground(['wwwww'] * 3 + ['www.w', 'wwwww']), 1, (2, 2), RIGHT_DOWN_LEFT_UP, ()), + stopped), + ('from elevation 0 it takes the elevation of the ground it steps on', + (ground(['wwwww'] * 3 + ['www.w', 'wwwww']), 0, (2, 2), RIGHT_DOWN_LEFT_UP, ()), stopped), + ('a person standing in the way stops it', (ground(OPEN), 3, (2, 2), RIGHT_DOWN_LEFT_UP, ((3, 3),)), stopped), + ('range 0 is no limit: it walks to the map edge', (ground(OPEN), 3, (2, 0), RIGHT_DOWN_LEFT_UP, ()), + [['east', 2], ['south', 3, 'stuck']]), + ) + for name, (land, elevation, ranges, (directions, shortcut), standing), legs in cases: + with self.subTest(name): + walk = frlg_maps.walk_sequence((1, 1), elevation, ranges, directions, shortcut, land, frozenset(standing)) + self.assertEqual(frlg_maps.path_legs(walk), legs) + + def test_a_walk_that_neither_returns_nor_stops_fails(self): + with self.assertRaises(ValueError): + frlg_maps.path_legs({'tiles': [[1, 1], [2, 1], [3, 1]], 'loop': 1}) + + +class PathTest(unittest.TestCase): + def test_path_errors(self): + # Each case: name, input (legs from (1, 1) on a 5 x 5 map), expectation (error or None). + cases = ( + ('a loop back to the start', [['east', 2], ['south', 1], ['west', 2], ['north', 1]], None), + ('stuck after a leg', [['east', 2], ['south', 1, 'stuck']], None), + ('not back at the start', [['east', 2], ['south', 1]], 'a path returns to its start unless stuck'), + ('off the map', [['north', 2], ['south', 2]], 'a path leaves the map'), + ('stuck before the last leg', [['east', 1, 'stuck'], ['west', 1]], 'only the last leg may be "stuck"'), + ('unmerged legs', [['east', 1], ['east', 1], ['west', 2]], 'consecutive legs go different ways'), + ('an empty leg', [['east', 0]], 'a leg walks at least one tile'), + ('a pret direction', [['RIGHT', 1], ['LEFT', 1]], 'a leg is [direction, tiles] or [direction, tiles, "stuck"]'), + ) + for name, legs, error in cases: + with self.subTest(name): + self.assertEqual(npc_path.path_error((1, 1), legs, 5, 5), error) + + +DECOMP_CACHE = Path(os.path.expanduser('~/.cache/pokefirered')) / frlg_maps.COMMIT + + +class WalkSequencesInThePackTest(unittest.TestCase): + """People who walk a sequence in the published maps, from pret map.json.""" + def test_published_legs(self): + # Each case: name, input (map, start tile), expectation (path legs). + cases = ( + ('Dave walks down 4 and right 8, and back', ('Route11', 28, 10), + [['south', 4], ['east', 8], ['west', 8], ['north', 4]]), + ('swimmer Spencer swims around his 4 x 2 range', ('Route21_North', 12, 44), + [['west', 4], ['north', 2], ['east', 4], ['south', 2]]), + ('Jaren walks right 5 and up 5, and back', ('Route8', 24, 17), + [['east', 5], ['north', 5], ['south', 5], ['west', 5]]), + ) + for name, (map_name, x, y), legs in cases: + with self.subTest(name): + objects = load(ROOT / 'data/games/frlg/maps/runtime' / (map_name + '.json'))['objects'] + [person] = [o for o in objects if (o['x'], o['y']) == (x, y)] + self.assertEqual(person.get('path'), legs) + self.assertNotIn('wander', person) + + @unittest.skipUnless((DECOMP_CACHE / 'src/event_object_movement.c').exists(), + 'needs the pinned pokefirered files in ~/.cache/pokefirered (the generator fetches them)') + def test_legs_expand_to_the_simulated_walk(self): + decomp = frlg_maps.Decomp(frlg_maps.COMMIT, str(DECOMP_CACHE.parent)) + names = frlg_maps.behaviors(decomp) + layouts = {l['id']: l for l in json.loads(decomp.read('data/layouts/layouts.json'))['layouts'] if 'id' in l} + rules = frlg_maps.walk_sequence_rules(decomp.read('src/event_object_movement.c').decode()) + checked = 0 + for path in sorted((ROOT / 'data/games/frlg/maps/runtime').glob('*.json')): + people = [o for o in load(path).get('objects', []) if 'path' in o] + if not people: + continue + source = json.loads(decomp.read(f'data/maps/{path.stem}/map.json')) + land = frlg_maps.read_ground(decomp, layouts[source['layout']], names) + standing = frozenset((e['x'], e['y']) for e in source['object_events'] if not e.get('movement_type', '') + .startswith((frlg_maps.WALK_SEQUENCE,) + frlg_maps.MOVING)) + for person in people: + with self.subTest(path.stem, tile=(person['x'], person['y'])): + [event] = [e for e in source['object_events'] if (e['x'], e['y']) == (person['x'], person['y'])] + movement = event['movement_type'] + walk = frlg_maps.walk_sequence( + (event['x'], event['y']), int(event.get('elevation') or 0), + (int(event['movement_range_x']), int(event['movement_range_y'])), + movement[len(frlg_maps.WALK_SEQUENCE):].split('_'), rules[movement], land, standing) + self.assertEqual(walk['loop'], 0) + expected = [tuple(t) for t in walk['tiles']] + [tuple(walk['tiles'][0])] + self.assertEqual(npc_path.path_tiles((person['x'], person['y']), person['path']), expected) + checked += 1 + self.assertEqual(checked, 12) + + def test_routing_blocks_the_path_not_the_range(self): + # Each case: name, input (tile on Route 11), expectation (occupied by Dave's path). + cases = ( + ('on his way right', (32, 14), True), + ('inside his range, off his path', (32, 10), False), + ) + world = LocalMap(load(ROOT / 'data/games/frlg/maps/runtime/Route11.json'), 'frlg') + for name, tile, occupied in cases: + with self.subTest(name): + self.assertEqual(Tile(*tile) in world.occupied, occupied) + + +class WalkersInThePackTest(unittest.TestCase): + """People who walk on their own in the published maps, from pret map.json.""" + def test_published_boxes(self): + # Each case: name, input (map, start tile), expectation (wander box or None). + cases = ( + ('swimmer Spencer walks a path, not a box', ('Route21_North', 12, 44), None), + ('the Cinnabar woman wanders left and right', ('CinnabarIsland', 14, 6), + {'x0': 13, 'y0': 6, 'x1': 15, 'y1': 6}), + ('swimmer Lil faces down and stands', ('Route21_North', 14, 35), None), + ) + for name, (map_name, x, y), box in cases: + with self.subTest(name): + objects = load(ROOT / 'data/games/frlg/maps/runtime' / (map_name + '.json'))['objects'] + [person] = [o for o in objects if (o['x'], o['y']) == (x, y)] + self.assertEqual(person.get('wander'), box) + + class DoorScriptTest(unittest.TestCase): SCRIPTS = ( 'EventScript_Close5FDoor1:: @ comment\n' diff --git a/src/pokesim/maps/test_runtime_map_publication.py b/src/pokesim/maps/test_runtime_map_publication.py index 575c18b..aef328b 100644 --- a/src/pokesim/maps/test_runtime_map_publication.py +++ b/src/pokesim/maps/test_runtime_map_publication.py @@ -45,6 +45,23 @@ def undo_story_flags_and_wander(game, data): del obj['wander'], obj['hide_flag'] +# Where people who walk on their own without wandering may stand, published +# after the v1 baseline, as {(game, map): {(name, start tile): field}}: Mt. +# Moon's Miriam walks a sequence (`path`), Route 25's Chad back and forth +# (`wander`). Names repeat on a map, so the start tile picks the person. +# Undone before digesting. +ADDED_WALKER_FIELDS = {('frlg', 'MtMoon_1F'): {('lass', (33, 4)): 'path'}, + ('frlg', 'Route25'): {('youngster', (36, 4)): 'wander'}} + + +def undo_walker_fields(game, data): + added = ADDED_WALKER_FIELDS.get((game, data['name']), {}) + for obj in data.get('objects', []): + field = added.get((obj['name'], (obj['x'], obj['y']))) + if field: + del obj[field] + + # Links to maps published after the v1 baseline, as {(game, map): (points, # warp destinations by tile, connections)}. The v1 pack left these out because # their destinations weren't in it; the generator writes them once they are. @@ -154,6 +171,7 @@ def test_all_published_values_match_reviewed_v1_baseline_and_stable_formatter(se undo_base_delta(game, baseline_data, deltas) undo_corrections(game, baseline_data) undo_story_flags_and_wander(game, baseline_data) + undo_walker_fields(game, baseline_data) undo_added_links(game, baseline_data) undo_added_people(game, baseline_data) digest = hashlib.sha256(json.dumps(compact_map(baseline_data), sort_keys=True).encode()).hexdigest()