diff --git a/lib/engine/auto_router.rb b/lib/engine/auto_router.rb index 244a83df95..403da81917 100644 --- a/lib/engine/auto_router.rb +++ b/lib/engine/auto_router.rb @@ -64,16 +64,12 @@ def compute_for_train_group(trains, corporation, **opts) @next_hexside_bit = 0 nodes.each do |node| - if Time.now - now > path_timeout - LOGGER.debug('Path timeout reached') - path_walk_timed_out = true - break - else - LOGGER.debug { "Path search: #{nodes.index(node)} / #{nodes.size} - paths starting from #{node.hex.name}" } - end + LOGGER.debug { "Path search: #{nodes.index(node)} / #{nodes.size} - paths starting from #{node.hex.name}" } walk_corporation = graph.no_blocking? ? nil : corporation node.walk(corporation: walk_corporation, skip_paths: skip_paths) do |_, vp| + raise PathTimeout if Time.now - now > path_timeout + paths = vp.keys chains = [] chain = [] @@ -163,6 +159,10 @@ def compute_for_train_group(trains, corporation, **opts) next :abort if path_abort.empty? end + rescue PathTimeout + LOGGER.debug('Path timeout reached') + path_walk_timed_out = true + break end # Check that there are no duplicate hexside bits (algorithm error) diff --git a/lib/engine/game_error.rb b/lib/engine/game_error.rb index c62fd1becb..833ec28c2c 100644 --- a/lib/engine/game_error.rb +++ b/lib/engine/game_error.rb @@ -17,4 +17,9 @@ class RouteTooLong < GameError class ReusesCity < GameError end + + # errors generated by the auto_router + + class PathTimeout < GameError + end end