Skip to content

Commit

Permalink
Fix handling of dynamic warps in map code
Browse files Browse the repository at this point in the history
This adds handling for some special cases related to map warps.

Dynamic warps are warps that have a dynamic destination based on some in-game state.

One example for that is the entrance area of Terra Cave on Emerald (where Groudon is found.)

Before, the Map debug tab would crash the emulator on this map. Now it works.
  • Loading branch information
hanzi committed Jan 7, 2024
1 parent cf05e31 commit 62765ac
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions modules/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from modules.context import context
from modules.game import decode_string
from modules.memory import unpack_uint16, unpack_uint32, read_symbol, get_symbol_name
from modules.memory import unpack_uint16, unpack_uint32, read_symbol, get_symbol_name, get_save_block
from modules.pokemon import get_item_by_index, Item


Expand Down Expand Up @@ -510,9 +510,24 @@ def destination_map_number(self) -> int:

@property
def destination_location(self) -> "MapLocation":
destination_map = get_map_data(self.destination_map_group, self.destination_map_number, (0, 0))
destination_warp = destination_map.warps[self.destination_warp_id]
destination_map.local_position = destination_warp.local_coordinates
map_group = self.destination_map_group
map_number = self.destination_map_number
warp_id = self.destination_warp_id

# There is a special case for 'dynamic warps' that have their destination set
# in the player's save data.
if map_group == 127 and map_number == 127:
map_group, map_number, warp_id = get_save_block(1, offset=0x14, size=3)

destination_map = get_map_data(map_group, map_number, (0, 0))

# Another special case is when there is no corresponding target warp on the
# destination map we use _this_ warp's coordinates as the destination.
if warp_id == 0xFF:
destination_map.local_position = self.local_coordinates
else:
destination_warp = destination_map.warps[warp_id]
destination_map.local_position = destination_warp.local_coordinates
return destination_map

def to_dict(self) -> dict:
Expand Down

0 comments on commit 62765ac

Please sign in to comment.