Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18RoyalGorge] Require graph connection for cross-buying trains #11386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/engine/game/g_18_royal_gorge/step/buy_train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a return if @game.loading guard cause here would remove the need for the game graph to be recalculated when a game is being loaded, at the cost of not rechecking the legality of the move.


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
Expand Down