Skip to content

Commit 23eb5c5

Browse files
authored
Merge pull request #772 from hanzi/navigate-to-end-facing
Support defining a final facing direction in `navigate_to()`
2 parents 07de5d1 + 09a2289 commit 23eb5c5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

modules/modes/util/higher_level_actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from ...game import get_symbol_name_before
4141
from ...items import Item, get_item_bag, ItemPocket, Pokeblock, get_pokeblocks
4242
from ...map import get_map_objects, get_map_data_for_current_position
43-
from ...map_path import calculate_path, PathFindingError
43+
from ...map_path import calculate_path, PathFindingError, Direction
4444
from ...mart import get_mart_buyable_items, get_mart_buy_menu_scroll_position, get_mart_main_menu_scroll_position
4545
from ...pokeblock_feeder import get_active_pokeblock_feeder_for_location
4646

@@ -547,7 +547,7 @@ def get_npc_location() -> tuple[int, int] | None:
547547
raise BotModeError(f"Could not find an empty tile around local object #{local_object_id}")
548548

549549
try:
550-
yield from navigate_to(*nearest_tile)
550+
yield from navigate_to(*nearest_tile, final_facing_direction=Direction.from_string(nearest_tile_facing))
551551
yield from ensure_facing_direction(nearest_tile_facing)
552552
except (PathFindingError, BotModeError):
553553
pass

modules/modes/util/walking.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ def navigate_to(
313313
avoid_encounters: bool = True,
314314
avoid_scripted_events: bool = True,
315315
expecting_script: bool = False,
316+
final_facing_direction: Direction | None = None,
316317
) -> Generator:
317318
"""
318319
Tries to walk the player to a given location while circumventing obstacles.
@@ -333,6 +334,9 @@ def navigate_to(
333334
still navigate via those tiles of there is no other option.
334335
:param expecting_script: This will accept if a script is triggered during navigation (presumably at the destination)
335336
and will not show an error about that.
337+
:param final_facing_direction: A direction that the player avatar should face after reaching its
338+
destination. This can be useful to make it bump into an obstacle with
339+
the Mach Bike.
336340
"""
337341

338342
def waypoint_generator():
@@ -367,7 +371,7 @@ def waypoint_generator():
367371

368372
while True:
369373
try:
370-
yield from follow_waypoints(waypoint_generator(), run)
374+
yield from follow_waypoints(waypoint_generator(), run, final_facing_direction=final_facing_direction)
371375
break
372376
except TimedOutTryingToReachWaypointError:
373377
# If we run into a timeout while trying to follow the waypoints, this is likely because of either of

0 commit comments

Comments
 (0)