Recover around invalid navigation paths
This commit is contained in:
1 parent
5f5dde1a62
commit
c2b595a70d
4 files changed
+162
No files matched your search
@@ -121,6 +121,67 @@ def missing_movement_chunks(g):
|
||||
if g.chunks.get_chunk(x, z) is None)
|
||||
|
||||
|
||||
PATH_VALIDATION_INTERVAL = 0.25
|
||||
PATH_RECOVERY_RETRY_INTERVAL = 1.0
|
||||
|
||||
|
||||
def _recover_invalid_path(g, now=None):
|
||||
"""Replan the remaining route if live block updates invalidated it."""
|
||||
now = time.monotonic() if now is None else now
|
||||
route = list(g.get('path') or ())
|
||||
|
||||
if route:
|
||||
# A job or command may have replaced a route while recovery was pending.
|
||||
if g.get('navigation_recovery_target') is not None:
|
||||
g.navigation_recovery_target = None
|
||||
g.navigation_retry_at = 0.0
|
||||
if now >= g.get('path_validation_at', 0.0):
|
||||
g.path_validation_at = now + PATH_VALIDATION_INTERVAL
|
||||
start = utils.pint(g.pos)
|
||||
skip_first_edge = (not g.get('on_ground', True) or
|
||||
bool(g.get('y_v')))
|
||||
try:
|
||||
valid, invalid_node = path.Pathfinder(g).path_prefix_is_valid(
|
||||
start, route, steps=2,
|
||||
skip_start_edge=skip_first_edge)
|
||||
except path.AStarTimeout:
|
||||
valid, invalid_node = True, None
|
||||
if not valid:
|
||||
target = tuple(route[-1])
|
||||
print('[movement] path blocked at {}; rerouting to {}'.format(
|
||||
invalid_node, target), flush=True)
|
||||
g.path = []
|
||||
g.navigation_recovery_target = target
|
||||
g.navigation_retry_at = 0.0
|
||||
|
||||
target = g.get('navigation_recovery_target')
|
||||
if target is None or now < g.get('navigation_retry_at', 0.0):
|
||||
return
|
||||
|
||||
position = utils.pint(g.pos)
|
||||
if position == tuple(target):
|
||||
g.navigation_recovery_target = None
|
||||
g.navigation_retry_at = 0.0
|
||||
return
|
||||
|
||||
try:
|
||||
navpath = g.world.path_to_place(position, tuple(target))
|
||||
except path.AStarTimeout:
|
||||
navpath = None
|
||||
if navpath:
|
||||
g.path = navpath
|
||||
g.navigation_recovery_target = None
|
||||
g.navigation_retry_at = 0.0
|
||||
print('[movement] rerouted to {}'.format(target), flush=True)
|
||||
else:
|
||||
g.path = []
|
||||
g.navigation_retry_at = now + PATH_RECOVERY_RETRY_INTERVAL
|
||||
if now >= g.get('navigation_retry_log_at', 0.0):
|
||||
print('[movement] no route to {}; will retry'.format(target),
|
||||
flush=True)
|
||||
g.navigation_retry_log_at = now + 5.0
|
||||
|
||||
|
||||
def tick(global_state):
|
||||
g = global_state
|
||||
p = g.pos
|
||||
@@ -169,6 +230,8 @@ def tick(global_state):
|
||||
print('[movement] status={}'.format(status), flush=True)
|
||||
g.movement_status = status
|
||||
|
||||
_recover_invalid_path(g)
|
||||
|
||||
door_pause = (g.game.handle_path_doors()
|
||||
if g.get('game') and
|
||||
hasattr(g.game, 'handle_path_doors') else False)
|
||||
@@ -442,6 +505,9 @@ def start_automation(global_state, initialize=True):
|
||||
g.time_update_received_at = None
|
||||
g.clock_rate = 1.0
|
||||
g.path = []
|
||||
g.navigation_recovery_target = None
|
||||
g.navigation_retry_at = 0.0
|
||||
g.path_validation_at = 0.0
|
||||
g.look_at = None
|
||||
g.y_v = 0.0
|
||||
g.y_a = 0.0
|
||||
|
||||
Reference in new issue
Block a user