Skip to content

Commit

Permalink
Merge pull request #11434 from tobymao/1837-minor-shares
Browse files Browse the repository at this point in the history
[1837] Change minors to corporation minors and floor fractional payouts
  • Loading branch information
crericha authored Jan 2, 2025
2 parents c8b8821 + a407ed5 commit b8d6bb5
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 69 deletions.
114 changes: 76 additions & 38 deletions lib/engine/game/g_1837/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ module Entities
desc: "Director's certificate of the minor company Kaiser Ferdinand North Railway (KK1). The company " \
'starts in Vienna (G17) with 90K starting capital.',
color: :brown,
meta: { start_packet: true, type: :minor },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [{ type: 'shares', shares: 'KK1_0' }],
},
{
name: 'Kaiserin Elisabeth-Railway (KK2)',
Expand All @@ -261,8 +261,8 @@ module Entities
desc: "Director's certificate of the minor company Kaiserin Elisabeth-Railway (KK2). The company " \
'starts in Vienna (G17) with 140K starting capital.',
color: :brown,
meta: { start_packet: true, type: :minor },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [{ type: 'shares', shares: 'KK2_0' }],
},
{
name: 'Kaiser Franz Joseph-Railway (KK3)',
Expand All @@ -271,8 +271,8 @@ module Entities
desc: "Director's certificate of the minor company Kaiser Franz Joseph-Railway (KK3). The company " \
'starts in Vienna (G17) with 90K starting capital.',
color: :brown,
meta: { start_packet: true, type: :minor },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [{ type: 'shares', shares: 'KK3_0' }],
},
{
name: 'Pest-Waitzen Railway (UG1)',
Expand All @@ -281,8 +281,8 @@ module Entities
desc: "Director's certificate of the minor company Pest-Waitzen Railway (UG1) " \
'starts in Budapest (H22) with 180K starting capital.',
color: :pink,
meta: { start_packet: true, type: :minor },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [{ type: 'shares', shares: 'UG1_0' }],
},
{
name: 'Mohacs-Fünfkirchener Railway (UG2)',
Expand All @@ -291,8 +291,8 @@ module Entities
desc: "Director's certificate of the minor company Mohacs-Fünfkirchener Railway (UG2). The company " \
'starts in Fün%irchen (K21) with 90K starting capital.',
color: :pink,
meta: { start_packet: true, type: :minor },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [{ type: 'shares', shares: 'UG2_0' }],
},
{
name: 'Pest-Czegled Railway (UG3)',
Expand All @@ -301,8 +301,8 @@ module Entities
desc: "Director's certificate of the minor company Pest-Czegled Railway (UG3). The company " \
'starts in Budapest (H22) with 180K starting capital.',
color: :pink,
meta: { start_packet: true, type: :minor },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [{ type: 'shares', shares: 'UG3_0' }],
},
{
name: 'Vienna-Gloggnitzer Railway (SD1)',
Expand All @@ -312,8 +312,11 @@ module Entities
"starts in Vienna (G17) with 90K starting capital.\n\nComes with the Mountain Railway " \
'Semmering Railway (H16) that has a value of 100K and a revenue of 5K.',
color: :orange,
meta: { start_packet: true, type: :minor, additional_companies: ['Semmering'] },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [
{ type: 'shares', shares: 'SD1_0' },
{ type: 'acquire_company', company: 'Semmering' },
],
},
{
name: 'Kärntner Railway (SD2)',
Expand All @@ -323,8 +326,11 @@ module Entities
"starts in Marburg (J16) with 90K starting capital.\n\n =Comes with the Mountain Railway " \
'Karawanken Railway (J12) that has a value of 120K and a revenue of 25K.',
color: :orange,
meta: { start_packet: true, type: :minor, additional_companies: ['Karawanken'] },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [
{ type: 'shares', shares: 'SD2_0' },
{ type: 'acquire_company', company: 'Karawanken' },
],
},
{
name: 'North Tyrol Railway (SD3)',
Expand All @@ -334,8 +340,11 @@ module Entities
"starts in Innsbruck (I7) with 90K starting capital.\n\nComes with the Mountain Railway " \
'Arlberg Railway (I5) that has a value of 135K and a revenue of 20K.',
color: :orange,
meta: { start_packet: true, type: :minor, additional_companies: ['Arlberg'] },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [
{ type: 'shares', shares: 'SD3_0' },
{ type: 'acquire_company', company: 'Arlberg' },
],
},
{
name: 'South Tyrol Railway (SD4)',
Expand All @@ -345,8 +354,11 @@ module Entities
"starts in Bozen (K5) with 90K starting capital.\n\nComes with the Mountain Railway " \
'Brenner Railway (J6) that has a value of 90K and a revenue of 15K.',
color: :orange,
meta: { start_packet: true, type: :minor, additional_companies: ['Brenner'] },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [
{ type: 'shares', shares: 'SD4_0' },
{ type: 'acquire_company', company: 'Brenner' },
],
},
{
name: 'Venice-Lombardy Railway (SD5)',
Expand All @@ -356,8 +368,11 @@ module Entities
"starts in Milan (L2) or Venice (L8), the director chooses, with 90K starting capital.\n\n" \
'Comes with the Mountain Railway Karst Railway (K13) that has a value of 70K and a revenue of 10K.',
color: :orange,
meta: { start_packet: true, type: :minor, additional_companies: ['Karst'] },
abilities: [{ type: 'no_buy' }],
meta: { start_packet: true },
abilities: [
{ type: 'shares', shares: 'SD5_0' },
{ type: 'acquire_company', company: 'Karst' },
],
},
{
name: 'Pest-Waitzen Railway (UG1) share',
Expand All @@ -366,7 +381,7 @@ module Entities
desc: 'A share of the minor company Pest-Waitzen Railway (UG1).',
color: :pink,
meta: { type: :share },
abilities: [{ type: 'no_buy' }],
abilities: [{ type: 'shares', shares: 'UG1_1' }],
},
{
name: 'Pest-Czegled Railway (UG3) share',
Expand All @@ -375,7 +390,7 @@ module Entities
desc: 'A share of the minor company Pest-Czegled Railway (UG3).',
color: :pink,
meta: { type: :share },
abilities: [{ type: 'no_buy' }],
abilities: [{ type: 'shares', shares: 'UG3_1' }],
},
{
name: 'Semmering Railway',
Expand Down Expand Up @@ -687,114 +702,137 @@ module Entities
coordinates: 'F26',
color: :black,
},
].freeze

CORPORATIONS = [
{
name: 'Vienna-Gloggnitzer Railway',
sym: 'SD1',
type: 'minor',
logo: '1837/sd1',
tokens: [0],
reserved_shares: [100],
float_percent: 50,
type: 'minor',
coordinates: 'G17',
city: 0,
color: :orange,
},
{
name: 'Kärntner Railway',
sym: 'SD2',
type: 'minor',
logo: '1837/sd2',
tokens: [0],
reserved_shares: [100],
float_percent: 50,
type: 'minor',
coordinates: 'J16',
color: :orange,
},
{
name: 'North Tyrol Railway',
sym: 'SD3',
type: 'minor',
logo: '1837/sd3',
tokens: [0],
reserved_shares: [100],
float_percent: 50,
type: 'minor',
coordinates: 'I7',
color: :orange,
},
{
name: 'South Tyrol Railway',
sym: 'SD4',
type: 'minor',
logo: '1837/sd4',
tokens: [0],
reserved_shares: [100],
float_percent: 50,
type: 'minor',
coordinates: 'K5',
color: :orange,
},
{
name: 'Venice-Lombardy Railway',
sym: 'SD5',
type: 'minor',
logo: '1837/sd5',
tokens: [0],
reserved_shares: [100],
float_percent: 50,
type: 'minor',
coordinates: %w[L2 L8],
color: :orange,
},
{
name: 'Kaiser Ferdinand North Railway',
sym: 'KK1',
type: 'minor',
logo: '1837/kk1',
tokens: [0],
reserved_shares: [100],
float_percent: 50,
type: 'minor',
coordinates: 'G17',
city: 3,
color: :brown,
},
{
name: 'Kaiserin Elisabeth-Railway',
sym: 'KK2',
type: 'minor',
logo: '1837/kk2',
tokens: [0],
reserved_shares: [100],
float_percent: 50,
type: 'minor',
coordinates: 'G17',
city: 1,
color: :brown,
},
{
name: 'Kaiser Franz Joseph-Railway',
sym: 'KK3',
type: 'minor',
logo: '1837/kk3',
tokens: [0],
reserved_shares: [100],
float_percent: 50,
type: 'minor',
coordinates: 'G17',
city: 2,
color: :brown,
},
{
name: 'Pest-Waitzen Railway',
sym: 'UG1',
type: 'minor',
logo: '1837/ug1',
tokens: [0],
reserved_shares: [50, 50],
treasury_as_holding: true,
float_percent: 50,
type: 'minor',
coordinates: 'H22',
city: 1,
color: :pink,
},
{
name: 'Mohacs-Fünfkirchener Railway',
sym: 'UG2',
type: 'minor',
logo: '1837/ug2',
tokens: [0],
reserved_shares: [100],
float_percent: 50,
type: 'minor',
coordinates: 'K21',
color: :pink,
},
{
name: 'Pest-Czegled Railway',
sym: 'UG3',
type: 'minor',
logo: '1837/ug3',
tokens: [0],
reserved_shares: [50, 50],
float_percent: 50,
type: 'minor',
coordinates: 'H22',
city: 0,
color: :pink,
},
].freeze

CORPORATIONS = [
{
name: 'Bohemian Commercial Railway',
sym: 'BK',
Expand Down
41 changes: 27 additions & 14 deletions lib/engine/game/g_1837/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ def event_exchange_coal_companies!
coal_company_exchange_order.each { |c| exchange_coal_company(c) }
end

def operating_order
minors, majors = @corporations.select(&:floated?).partition { |c| c.type == :minor }
@minors.select(&:floated?) + minors + majors.sort
end

def coal_company_exchange_order
exchangeable_companies = Hash.new { |h, k| h[k] = [] }
@companies.each do |c|
Expand Down Expand Up @@ -519,23 +524,27 @@ def unowned_purchasable_companies(_entity)
@companies.select { |c| c.owner == @bank }
end

def after_company_acquisition(company)
player = company.owner
def after_buy_company(player, company, _price)
abilities(company, :shares) do |ability|
share = ability.shares.first
@share_pool.buy_shares(player, share, exchange: :free)
float_minor!(share.corporation) if share.president
end

abilities(company, :acquire_company) do |ability|
acquired_company = company_by_id(ability.company)
acquired_company.owner = player
player.companies << acquired_company
@log << "#{player.name} receives #{acquired_company.name}"
after_buy_company(player, acquired_company, 0)
end

case company.meta[:type]
when :minor, :coal
if company.meta[:type] == :coal
minor = minor_by_id(company.id)
minor.owner = player
float_minor!(minor)
when :minor_share
# todo
puts 'todo'
end

Array(company.meta[:additional_companies]).each do |c_id|
additional_company = company_by_id(c_id)
additional_company.owner = player
player.companies << additional_company
else
company.close!
end
end

Expand All @@ -555,7 +564,11 @@ def float_minor!(minor)
remove_reservations!(minor, coordinates)
end
place_home_token(minor) unless minor.coordinates.is_a?(Array)
minor.float!
if minor.corporation?
minor.floated = true
else
minor.float!
end
end

def float_corporation(corporation)
Expand Down
9 changes: 4 additions & 5 deletions lib/engine/game/g_1837/step/buy_sell_par_shares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def actions(entity)
UNBOUGHT_COMPANIES_ACTIONS
end

def visible_corporations
@game.corporations.reject { |c| c.type == :minor }
end

def hide_corporations?
unbought_companies?
end
Expand All @@ -34,11 +38,6 @@ def can_buy_any_company?(entity)
entity.cash >= @game.buyable_bank_owned_companies.min_by(&:value).value
end

def process_buy_company(entity)
super
@game.after_company_acquisition(entity.company)
end

def process_par(action)
super
@game.set_par(action.corporation, action.share_price, action.slot)
Expand Down
Loading

0 comments on commit b8d6bb5

Please sign in to comment.