Skip to content

Commit

Permalink
Merge pull request #11436 from tobymao/1837-vienna-budapest
Browse files Browse the repository at this point in the history
[1837] Treat Vienna as one city, return KK/UG tokens when Vienna/Budapest upgraded to brown
  • Loading branch information
crericha authored Jan 2, 2025
2 parents b8d6bb5 + 3bf1094 commit b89d72f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
21 changes: 14 additions & 7 deletions lib/engine/game/g_1837/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def event_buy_across!
def event_sd_formation!
@log << "-- Event: #{EVENTS_TEXT['sd_formation'][1]} --"
national = corporation_by_id('SD')
minors = %w[SD1 SD2 SD3 SD4 SD5].map { |id| minor_by_id(id) }
minors = %w[SD1 SD2 SD3 SD4 SD5].map { |id| corporation_by_id(id) }
form_national_railway!(national, minors)
end

Expand All @@ -348,7 +348,7 @@ def event_remove_italy!
end

def event_kk_formation!
open_minors = %w[KK1 KK2 KK3].map { |id| minor_by_id(id) }.reject(&:closed?)
open_minors = %w[KK1 KK2 KK3].map { |id| corporation_by_id(id) }.reject(&:closed?)
return if open_minors.empty?

@log << "-- Event: #{EVENTS_TEXT['kk_formation'][1]} --"
Expand All @@ -363,7 +363,7 @@ def event_kk_formation!
end

def event_ug_formation!
open_minors = %w[UG1 UG2 UG3].map { |id| minor_by_id(id) }.reject(&:closed?)
open_minors = %w[UG1 UG2 UG3].map { |id| corporation_by_id(id) }.reject(&:closed?)
return if open_minors.empty?

national = corporation_by_id('UG')
Expand Down Expand Up @@ -456,10 +456,11 @@ def merge_minor!(minor, corporation)
minor.tokens.first.swap!(blocking_token, check_tokenable: false)
else
token = minor.tokens.first
num_unused = corporation.tokens.count { |t| !t.used }
new_token = Token.new(corporation, price: num_unused.zero? ? 20 : 40)
new_token = Token.new(corporation)
corporation.tokens << new_token
if !%w[L2 L8].include?(token.hex.id) && token.city.tokenable?(corporation, free: true, cheater: true)
if %w[L2 L8].include?(token.hex.id)
token.price = 20
else
token.swap!(new_token, check_tokenable: false)
end
@log << "#{corporation.name} receives token (#{new_token.used ? new_token.city.hex.id : 'charter'})"
Expand Down Expand Up @@ -508,7 +509,7 @@ def operating_round(round_num)
G1837::Step::HomeToken,
G1837::Step::DiscardTrain,
G1837::Step::SpecialTrack,
Engine::Step::Track,
G1837::Step::Track,
G1837::Step::Token,
Engine::Step::Route,
G1837::Step::Dividend,
Expand Down Expand Up @@ -627,6 +628,12 @@ def blocking_token
@blocker ||= Corporation.new(sym: 'B', name: '', logo: '1837/blocking', tokens: [])
Token.new(@blocker)
end

def legal_tile_rotation?(entity, hex, tile)
return tile.rotation == 5 if tile.name == '436'

super
end
end
end
end
Expand Down
14 changes: 8 additions & 6 deletions lib/engine/game/g_1837/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ module Map
'427' => {
'count' => 1,
'color' => 'green',
'code' => 'city=revenue:60;path=a:0,b:_0;city=revenue:60;path=a:1,b:_1;city=revenue:60;path=a:2,b:_2;' \
'city=revenue:60;path=a:3,b:_3;city=revenue:60;path=a:4,b:_4;city=revenue:60;path=a:5,b:_5;' \
'code' => 'city=revenue:60,groups:Vienna;path=a:0,b:_0;city=revenue:60,groups:Vienna;path=a:1,b:_1;' \
'city=revenue:60,groups:Vienna;path=a:2,b:_2;city=revenue:60,groups:Vienna;path=a:3,b:_3;' \
'city=revenue:60,groups:Vienna;path=a:4,b:_4;city=revenue:60,groups:Vienna;path=a:5,b:_5;' \
'label=W',
},
'429' => {
Expand Down Expand Up @@ -220,8 +221,9 @@ module Map
'436' => {
'count' => 1,
'color' => 'brown',
'code' => 'city=revenue:80;path=a:0,b:_0;city=revenue:80;path=a:1,b:_1;city=revenue:80;path=a:2,b:_2;' \
'path=a:3,b:_2;path=a:4,b:_2;city=revenue:80;path=a:5,b:_3;label=W',
'code' => 'city=revenue:80,groups:Vienna;path=a:0,b:_0;city=revenue:80,groups:Vienna;path=a:1,b:_1;' \
'city=revenue:80,groups:Vienna;path=a:2,b:_2;path=a:3,b:_2;path=a:4,b:_2;' \
'city=revenue:80,groups:Vienna;path=a:5,b:_3;label=W',
},
}.freeze

Expand Down Expand Up @@ -330,8 +332,8 @@ module Map
yellow: {
['C11'] => 'city=revenue:20;path=a:2,b:_0;path=a:4,b:_0;label=X',
['F18'] => 'town=revenue:10;path=a:0,b:_0;path=a:2,b:_0;town=revenue:10;path=a:1,b:_1;path=a:5,b:_1',
['G17'] => 'city=revenue:40;city=revenue:40;city=revenue:40;city=revenue:40;' \
'path=a:0,b:_0;path=a:1,b:_1;path=a:2,b:_2;path=a:3,b:_3;label=W',
['G17'] => 'city=revenue:40,groups:Vienna;city=revenue:40,groups:Vienna;city=revenue:40,groups:Vienna;' \
'city=revenue:40,groups:Vienna;path=a:0,b:_0;path=a:1,b:_1;path=a:2,b:_2;path=a:3,b:_3;label=W',
['G27'] => 'town=revenue:10;path=a:2,b:_0;path=a:3,b:_0',
['H22'] => 'city=revenue:40;city=revenue:40;path=a:0,b:_0;path=a:5,b:_0;' \
'path=a:1,b:_1;path=a:3,b:_1;label=Bu',
Expand Down
31 changes: 31 additions & 0 deletions lib/engine/game/g_1837/step/track.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

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

module Engine
module Game
module G1837
module Step
class Track < Engine::Step::Track
def lay_tile(action, extra_cost: 0, entity: nil, spender: nil)
tile = action.tile
case tile.name
when '435'
corp = @game.corporation_by_id('UG')
when '436'
corp = @game.corporation_by_id('KK')
end
if corp
# Keep home token - index 0
corp.tokens[1..-1].select { |token| token.city.hex == action.hex }.each_with_index do |token, i|
token.remove!
token.price = i.zero? ? 20 : 40
end
end
super
end
end
end
end
end
end

0 comments on commit b89d72f

Please sign in to comment.