Skip to content

Commit

Permalink
Merge pull request #11438 from tobymao/1837-stock-movement
Browse files Browse the repository at this point in the history
[1837] stock movement, express trains, game end conditions, and bug fixes
  • Loading branch information
crericha authored Jan 2, 2025
2 parents 84c50a8 + bcec436 commit b1d2aed
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lib/engine/game/g_1837/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ module Entities
tokens: [0],
reserved_shares: [100],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'G17',
city: 0,
Expand All @@ -724,6 +725,7 @@ module Entities
tokens: [0],
reserved_shares: [100],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'J16',
color: :orange,
Expand All @@ -735,6 +737,7 @@ module Entities
tokens: [0],
reserved_shares: [100],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'I7',
color: :orange,
Expand All @@ -746,6 +749,7 @@ module Entities
tokens: [0],
reserved_shares: [100],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'K5',
color: :orange,
Expand All @@ -757,6 +761,7 @@ module Entities
tokens: [0],
reserved_shares: [100],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: %w[L2 L8],
color: :orange,
Expand All @@ -768,6 +773,7 @@ module Entities
tokens: [0],
reserved_shares: [100],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'G17',
city: 3,
Expand All @@ -780,6 +786,7 @@ module Entities
tokens: [0],
reserved_shares: [100],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'G17',
city: 1,
Expand All @@ -792,6 +799,7 @@ module Entities
tokens: [0],
reserved_shares: [100],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'G17',
city: 2,
Expand All @@ -805,6 +813,7 @@ module Entities
reserved_shares: [50, 50],
treasury_as_holding: true,
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'H22',
city: 1,
Expand All @@ -817,6 +826,7 @@ module Entities
tokens: [0],
reserved_shares: [100],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'K21',
color: :pink,
Expand All @@ -828,6 +838,7 @@ module Entities
tokens: [0],
reserved_shares: [50, 50],
float_percent: 50,
max_ownership_percent: 100,
type: 'minor',
coordinates: 'H22',
city: 0,
Expand Down
43 changes: 36 additions & 7 deletions lib/engine/game/g_1837/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Game < Game::Base
EBUY_DEPOT_TRAIN_MUST_BE_CHEAPEST = false
MUST_BUY_TRAIN = :always

BANKRUPTCY_ENDS_GAME_AFTER = :all_but_one
GAME_END_CHECK = { bankrupt: :immediate, bank: :current_or }.freeze

MARKET = [
%w[95 99 104p 114 121 132 145 162 181 205 240 280 350 400 460],
%w[89 93 97p 102 111 118 128 140 154 173 195 225 260 300 360],
Expand Down Expand Up @@ -527,10 +530,19 @@ def unowned_purchasable_companies(_entity)
end

def after_buy_company(player, company, _price)
close_company = false

abilities(company, :shares) do |ability|
share = ability.shares.first
@share_pool.buy_shares(player, share, exchange: :free)
float_minor!(share.corporation) if share.president
close_company = true
end

if company.meta[:type] == :coal
minor = minor_by_id(company.id)
minor.owner = player
float_minor!(minor)
end

abilities(company, :acquire_company) do |ability|
Expand All @@ -540,14 +552,9 @@ def after_buy_company(player, company, _price)
@log << "#{player.name} receives #{acquired_company.name}"
after_buy_company(player, acquired_company, 0)
end
return unless close_company

if company.meta[:type] == :coal
minor = minor_by_id(company.id)
minor.owner = player
float_minor!(minor)
else
company.close!
end
company.close!
end

def float_str(entity)
Expand Down Expand Up @@ -595,6 +602,10 @@ def goods_train?(train_name)
train_name.end_with?('G')
end

def express_train?(train_name)
train_name.end_with?('E')
end

def can_buy_train_from_others?
@phase.name.to_i >= 3
end
Expand All @@ -604,6 +615,10 @@ def revenue_for(route, stops)
end

def check_other(route)
if express_train?(route.train.name) && (route.stops.count { |s| s.type == :city } < 2)
raise GameError, 'Must include at least two cities'
end

mine_stops = route.stops.count { |s| s.hex.assigned?(:coal) }
if goods_train?(route.train.name)
raise GameError, 'Must visit one mine' if mine_stops.zero?
Expand All @@ -613,6 +628,12 @@ def check_other(route)
end
end

def route_distance(route)
return route.stops.count { |s| s.type == :city } if express_train?(route.train.name)

super
end

def routes_subsidy(routes)
routes.sum { |route| mine_revenue(route, route.stops) }
end
Expand All @@ -635,6 +656,14 @@ def legal_tile_rotation?(entity, hex, tile)

super
end

def sold_out_stock_movement(corp)
if corp.owner.percent_of(corp) <= 40
@stock_market.move_up(corp)
else
@stock_market.move_diagonally_up_left(corp)
end
end
end
end
end
Expand Down

0 comments on commit b1d2aed

Please sign in to comment.