Skip to content

Commit

Permalink
Merge pull request #11423 from tobymao/1837-italy-event
Browse files Browse the repository at this point in the history
[1837] Implement Italy event
  • Loading branch information
crericha authored Dec 29, 2024
2 parents 113abec + 0fa02e9 commit cb38afd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/engine/game/g_1837/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Game < Game::Base
num: 4,
distance: 4,
price: 470,
events: [{ 'type' => 'sd_formation' }],
events: [{ 'type' => 'sd_formation' }, { 'type' => 'remove_italy' }],
},
{
name: '4E',
Expand Down Expand Up @@ -237,6 +237,7 @@ class Game < Game::Base
EVENTS_TEXT = Base::EVENTS_TEXT.merge(
'buy_across' => ['Buy Across', 'Trains can be bought between companies'],
'sd_formation' => ['SD Formation', 'SD forms immediately'],
'remove_italy' => ['Remove Italy', 'Remove tiles in Italy. Italy no longer in play.'],
'kk_formation' => ['KK Formation', 'KK forms immediately'],
'ug_formation' => ['UG Formation', 'UG forms immediately'],
).freeze
Expand Down Expand Up @@ -330,6 +331,19 @@ def event_sd_formation!
form_national_railway!(national, minors)
end

def event_remove_italy!
@log << "-- Event: #{EVENTS_TEXT['remove_italy'][1]} --"
ITALY_HEXES.each do |id|
hex = hex_by_id(id)
hex.law_downgrade(hex.original_tile) if hex.tile != hex.original_tile
hex.tile.modify_borders(type: :impassible)
end

# Lay Bo tile on Bozen
hex_by_id('K5').lay(tile_by_id('426-0').rotate!(2))
@graph.clear_graph_for_all
end

def event_kk_formation!
open_minors = %w[KK1 KK2 KK3].map { |id| minor_by_id(id) }.reject(&:closed?)
return if open_minors.empty?
Expand Down
2 changes: 2 additions & 0 deletions lib/engine/game/g_1837/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ module Map

MINE_HEXES = %w[A13 B32 C19 C21 E11 F26 K31 K33 L30 P20].freeze

ITALY_HEXES = %w[K1 K3 K7 K9 L2 L4 L6 L8 M3 M5 M7].freeze

HEXES = {
gray: {
['A11'] => 'town=revenue:10;path=a:0,b:_0;path=a:5,b:_0',
Expand Down
4 changes: 4 additions & 0 deletions lib/engine/part/border.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def initialize(edge, type = nil, cost = nil, color = nil)
@color = color&.to_sym
end

def ==(other)
other.edge == edge && other.type == type && other.cost == cost && other.color == color
end

def border?
true
end
Expand Down
21 changes: 21 additions & 0 deletions lib/engine/tile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,27 @@ def label
@labels.last
end

def modify_borders(edges = nil, type: nil, cost: nil, color: nil)
edges ||= ALL_EDGES

modified = edges.map do |edge|
border = @borders.find { |e| e.edge == edge }
next unless border

modified_border = Part::Border.new(edge, type || border.type, cost || border.cost, color || border.color)
next if border == modified_border

@borders.delete(border)
@borders << modified_border
edge
end

modified.each do |edge|
neighbor = @hex.neighbors[edge]&.tile
neighbor&.modify_borders([Hex.invert(edge)], type: type, cost: cost, color: color)
end
end

def restore_borders(edges = nil)
edges ||= ALL_EDGES

Expand Down

0 comments on commit cb38afd

Please sign in to comment.