diff --git a/lib/engine/game/g_18_norway/game.rb b/lib/engine/game/g_18_norway/game.rb index 3d71339e97..bb87b3c125 100644 --- a/lib/engine/game/g_18_norway/game.rb +++ b/lib/engine/game/g_18_norway/game.rb @@ -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'], diff --git a/lib/engine/game/g_18_norway/steps/token.rb b/lib/engine/game/g_18_norway/steps/token.rb index 58d4fdaa29..bceeafeeed 100644 --- a/lib/engine/game/g_18_norway/steps/token.rb +++ b/lib/engine/game/g_18_norway/steps/token.rb @@ -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) @@ -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)) 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