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

[18Norway] Updated harbor #10990

Merged
merged 14 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions lib/engine/game/g_18_norway/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def nsb
@nsb ||= corporation_by_id('NSB')
end

def harbor_city_coordinates(hex_id)
CITY_HARBOR_MAP.key(hex_id)
end

def harbor_hex?(hex)
HARBOR_HEXES.include?(hex.id)
end

def price_movement_chart
[
['Action', 'Share Price Change'],
Expand Down
31 changes: 16 additions & 15 deletions lib/engine/game/g_18_norway/steps/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ module G18Norway
module Step
class Token < Engine::Step::Token
def available_hex(entity, hex)
return true if super(entity, hex)
return true if @game.ferry_graph.reachable_hexes(entity)[hex]
super(entity, hex) || harbor_available?(entity, hex)
end

def harbor_available?(entity, hex)
other_hex = @game.hex_by_id(@game.harbor_city_coordinates(hex.id))
return false unless other_hex

false
@game.ferry_graph.reachable_hexes(entity)[other_hex] ||
@game.token_graph_for_entity(entity).reachable_hexes(entity)[other_hex]
end

def can_place_token?(_entity)
Expand All @@ -21,25 +26,21 @@ def can_place_token?(_entity)
def process_place_token(action)
entity = action.entity
city = action.city
connected_city = @game.loading || @game.token_graph_for_entity(entity).connected_nodes(entity)[city]
place_token(entity, action.city, action.token) if connected_city

unless connected_city
connected_city = @game.token_graph_for_entity(entity).connected_nodes(entity)[city]
if connected_city
place_token(entity, action.city, action.token)
elsif harbor_available?(entity, city.hex)
@game.abilities(entity, :token) do |ability|
place_token(entity, action.city, action.token, connected: false, special_ability: ability)
entity.add_ability(Ability::Token.new(type: 'token', hexes: Engine::Game::G18Norway::Game::HARBOR_HEXES,
from_owner: true, discount: 0, connected: true))
ollybh marked this conversation as resolved.
Show resolved Hide resolved
end
else
raise GameError, "Cannot place token on #{city.hex.name} city is not connected"
end
@game.clear_graph
pass!
end

def check_connected(entity, city, hex)
return if @game.loading || @game.token_graph_for_entity(entity).connected_nodes(entity)[city]
return if @game.loading || @game.ferry_graph.connected_nodes(entity)[city]

city_string = hex.tile.cities.size > 1 ? " city #{city.index}" : ''
raise GameError, "Cannot place token on #{hex.name}#{city_string} because it is not connected"
end
end
end
end
Expand Down
Loading