Skip to content

Commit

Permalink
Merge branch '18bf'
Browse files Browse the repository at this point in the history
  • Loading branch information
ollybh committed Mar 5, 2024
2 parents a8ac388 + 1f51095 commit ec4c9a0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/engine/game/g_1867/step/single_item_auction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SingleItemAuction < Engine::Step::Base

def actions(entity)
return [] if @companies.empty?
return %w[bid pass] if @auctioning

entity == current_entity ? ACTIONS : []
end
Expand Down
21 changes: 18 additions & 3 deletions lib/engine/game/g_18_bf/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def operating_round(round_num)
Engine::Step::BuyCompany,
G1867::Step::RedeemShares,
G18BF::Step::SpecialTrack,
G1867::Step::Track,
G18BF::Step::Track,
G1867::Step::Token,
Engine::Step::Route,
G1867::Step::Dividend,
Expand All @@ -105,12 +105,14 @@ def event_minors_batch3!
end

def event_u1_available!
u1 = @future_companies.delete { |company| company.sym == 'U1' }
u1 = @future_companies.find { |company| company.sym == 'U1' }
@future_companies.delete(u1)
@companies << u1
end

def event_u2_available!
u2 = @future_companies.delete { |company| company.sym == 'U2' }
u2 = @future_companies.find { |company| company.sym == 'U2' }
@future_companies.delete(u2)
@companies << u2
end

Expand Down Expand Up @@ -146,6 +148,19 @@ def revenue_for(route, stops)
end
super + bonuses
end

def check_other(route)
check_london(route)
end

def check_london(route)
# Can only run to London if running to your own token.
london_stops = route.visited_stops & @london_cities
return if london_stops.all? { |city| city.tokened_by?(current_entity) }

raise GameError, 'Route may not include London unless running to a ' \
"#{current_entity.id} token."
end
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions lib/engine/game/g_18_bf/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,41 @@ module Map
{ coord1: 'M29', edge1: 5, coord2: 'V24', edge2: 2 },
].freeze
LONDON_HEX_CENTRE = 'L28'
LONDON_HEX_ON_MAP = 'U23'

def setup_london_hexes
# Keep references to London hexes for tracking upgrades.
@london_small = @hexes.find { |hex| hex.coordinates == LONDON_HEX_ON_MAP }
@london_zoomed = []

# Join the hexes adjacent to London to the expanded hexes.
LONDON_HEX_NEIGHBOURS.each do |item|
hex1 = @hexes.find { |hex| hex.coordinates == item[:coord1] }
hex2 = @hexes.find { |hex| hex.coordinates == item[:coord2] }
hex1.neighbors[item[:edge1]] = hex2
hex2.neighbors[item[:edge2]] = hex1
@london_zoomed << hex1
end

# Sever all connections from the London hex on the main map.
london = @hexes.find { |hex| hex.coordinates == LONDON_HEX_CENTRE }
london.neighbors.clear
@london_zoomed << london

# Keep references to the London cities for managing routes.
@london_cities = @london_zoomed.flat_map { |hex| hex.tile.cities }
end

# Keeps the zoomed London hex colour and city revenue in sync with the
# London tile on the map.
def london_upgraded(new_tile)
color = new_tile.color
revenue = new_tile.offboards.first.revenue[color]

@london_zoomed.each do |hex|
hex.color = color
hex.cities.each { |city| city.revenue = revenue }
end
end

# Bonus revenues are shown on the map as detached offboard areas.
Expand Down
29 changes: 29 additions & 0 deletions lib/engine/game/g_18_bf/step/track.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require_relative '../../g_1867/step/track'

module Engine
module Game
module G18BF
module Step
class Track < G1867::Step::Track
def available_hex(entity, hex)
return super unless hex == @london_small

london_available?(entity)
end

def london_available?(entity)
@london_zoomed.any? { |hex| available_hex(entity, hex) }
end

def lay_tile(action, extra_cost: 0, entity: nil, spender: nil)
super

@game.london_upgraded(action.hex.tile) if action.hex == @london_small
end
end
end
end
end
end

0 comments on commit ec4c9a0

Please sign in to comment.