Skip to content

Commit

Permalink
Merge pull request #11558 from tobymao/1837-emr-bugs
Browse files Browse the repository at this point in the history
[1837] Fix EMR and bankruptcy bugs
  • Loading branch information
crericha authored Feb 18, 2025
2 parents 70ba20c + 8bc1217 commit f1db37d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion assets/app/view/game/buy_trains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def render_president_contributions

children.concat(render_emergency_money_raising(owner)) if share_funds_allowed.positive?
end
elsif share_funds_allowed.positive? && @step.can_ebuy_sell_shares?(@corporation)
elsif @step.can_ebuy_sell_shares?(@corporation)
children.concat(render_emergency_money_raising(player))
end

Expand Down
10 changes: 0 additions & 10 deletions lib/engine/game/g_1837/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ module Entities
type: 'exchange',
description: 'Exchange for BK share',
corporations: ['BK'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand All @@ -560,7 +559,6 @@ module Entities
type: 'exchange',
description: 'Exchange for BK share',
corporations: ['BK'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand All @@ -582,7 +580,6 @@ module Entities
type: 'exchange',
description: 'Exchange for MS share',
corporations: ['MS'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand All @@ -604,7 +601,6 @@ module Entities
type: 'exchange',
description: 'Exchange for MS share',
corporations: ['MS'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand All @@ -626,7 +622,6 @@ module Entities
type: 'exchange',
description: 'Exchange for CL share',
corporations: ['CL'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand All @@ -648,7 +643,6 @@ module Entities
type: 'exchange',
description: 'Exchange for TR share',
corporations: ['TR'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand All @@ -670,7 +664,6 @@ module Entities
type: 'exchange',
description: 'Exchange for TR share',
corporations: ['TR'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand All @@ -692,7 +685,6 @@ module Entities
type: 'exchange',
description: 'Exchange for TI share',
corporations: ['TI'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand All @@ -714,7 +706,6 @@ module Entities
type: 'exchange',
description: 'Exchange for BH share',
corporations: ['BH'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand All @@ -736,7 +727,6 @@ module Entities
type: 'exchange',
description: 'Exchange for TI share',
corporations: ['TI'],
owner_type: 'player',
when: 'exchange',
from: 'reserved',
},
Expand Down
14 changes: 11 additions & 3 deletions lib/engine/game/g_1837/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ class Game < Game::Base
PHASES = [
{
name: '2',
train_limit: { coal: 2, minor: 2, major: 4 },
train_limit: { coal: 2, minor: 2, major: 4, national: 4 },
tiles: [:yellow],
operating_rounds: 1,
},
{
name: '3',
on: '3',
train_limit: { coal: 2, minor: 2, major: 3 },
train_limit: { coal: 2, minor: 2, major: 3, national: 4 },
tiles: %i[yellow green],
operating_rounds: 2,
},
{
name: '3+1',
on: '3+1',
train_limit: { coal: 1, minor: 1, major: 3 },
train_limit: { coal: 1, minor: 1, major: 3, national: 4 },
tiles: %i[yellow green],
operating_rounds: 2,
},
Expand Down Expand Up @@ -436,6 +436,8 @@ def exchange_target(entity)
if coal_minor?(entity)
target_id = abilities(entity, :exchange, time: 'any')&.corporations&.first
corporation_by_id(target_id)
elsif sd_minors.include?(entity)
corporation_by_id('SD')
elsif kk_minors.include?(entity)
corporation_by_id('KK')
elsif ug_minors.include?(entity)
Expand Down Expand Up @@ -808,6 +810,12 @@ def acting_for_entity(entity)

super
end

def sellable_bundles(player, corporation)
return [] unless corporation.share_price

super
end
end
end
end
Expand Down
15 changes: 4 additions & 11 deletions lib/engine/game/g_1837/step/bankrupt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Step
class Bankrupt < Engine::Step::Bankrupt
def process_bankrupt(action)
entity = action.entity
player = entity.corporation? ? entity.owner : entity
player = entity.owner

@log << "-- #{player.name} goes bankrupt and remaining shares placed in the bank pool --"

Expand All @@ -26,8 +26,8 @@ def process_bankrupt(action)
@game.sell_shares_and_change_price(bundle)
end

# Remaining shares are placed in the bank pool. Minors merge immediately, unless
# the presidency is transferred (UG1 and UG3).
# Remaining shares are placed in the bank pool. Coal companies and minors merge immediately,
# unless the presidency is transferred (UG1 and UG3).
player.shares_by_corporation(sorted: true).each do |corporation, shares|
next if shares.empty?

Expand All @@ -44,13 +44,6 @@ def process_bankrupt(action)
end
end

# Coal companies merge immediately
@game.minors.select { |m| m.owner == player }.each do |minor|
minor.owner = @game.share_pool
@log << "#{minor.name} is forced to merge immediately"
@game.merge_minor!(minor, @game.exchange_target(minor))
end

if entity.corporation? && player.cash.positive?
@log << "#{player.name}'s remaining cash (#{@game.format_currency(player.cash)}) is "\
"transferred to #{entity.name}"
Expand All @@ -60,7 +53,7 @@ def process_bankrupt(action)
@game.declare_bankrupt(player)
player.cash = 0

@round.bankrupting_corporations << entity if entity.corporation?
@round.bankrupting_corporations << entity
end

def round_state
Expand Down

0 comments on commit f1db37d

Please sign in to comment.