diff --git a/lib/engine/game/g_18_royal_gorge/step/buy_train.rb b/lib/engine/game/g_18_royal_gorge/step/buy_train.rb index 69ca60ec7a..ed24530310 100644 --- a/lib/engine/game/g_18_royal_gorge/step/buy_train.rb +++ b/lib/engine/game/g_18_royal_gorge/step/buy_train.rb @@ -16,6 +16,21 @@ def room?(entity) # even when train tight, there's room for a self-rust return true if entity.trains.any? { |t| t.rusts_on == upcoming_train.name } end + + def check_connected!(buyer, train) + return if train.owner == @game.depot + + seller = train.corporation + seller_nodes = @game.graph.connected_nodes(seller) + return if @game.graph.connected_nodes(buyer).any? { |node, _| seller_nodes.include?(node) } + + raise GameError, "#{buyer.name} must be connected to #{seller.name} to buy their train." + end + + def process_buy_train(action) + check_connected!(action.entity, action.train) + super + end end end end