Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18RoyalGorge] setup corporations and companies, implement phase-based parring #10193

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions lib/engine/game/g_18_royal_gorge/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,114 @@ class Game < Game::Base
TILE_LAYS = ([{ lay: true, upgrade: true, cost: 0 }] * 6).freeze
MUST_BUY_TRAIN = :always
CAPITALIZATION = :incremental
ESTABLISHED = {
'KP' => 1869,
'RG' => 1870,
'SPP' => 1872,
'PAV' => 1875,
'SF' => 1876,
'NO' => 1881,
'CM' => 1883,
'S' => 1887,
'FCC' => 1893,
'CSCC' => 1897,
'CS' => 1898,
}.freeze

EVENTS_TEXT = Base::EVENTS_TEXT.merge(
green_par: ['Green Par Available'],
brown_par: ['Brown Par Available'],
)

def ipo_name(_entity = nil)
'Treasury'
end

def game_companies
YELLOW_COMPANIES.sort_by { rand }.take(2).sort_by { |c| c[:sym] } +
GREEN_COMPANIES.sort_by { rand }.take(2).sort_by { |c| c[:sym] } +
BROWN_COMPANIES.sort_by { rand }.take(1)
end

def game_corporations
# SF, RG, and three random corporations
corporations = INCLUDED_CORPORATIONS + MAYBE_CORPORATIONS.sort_by { rand }.take(3)

# sort by established year, to create yellow/green/brown tranches
corporations = corporations.sort_by { |c| ESTABLISHED[c[:sym]] }

# put established year on charter
corporations.map do |corporation|
corp = corporation.dup
corp[:abilities] = [{ type: 'base', description: "Est. #{ESTABLISHED[corp[:sym]]}" }]
corp
end

@log << "Railroads in the game: #{corporations.map { |c| c[:sym] }.join(', ')}"

corporations
end

def setup
@corporation_phase_color = {}
@corporations[0..1].each { |c| @corporation_phase_color[c.name] = 'Yellow' }
@corporations[2..3].each { |c| @corporation_phase_color[c.name] = 'Green' }
@corporations[4..4].each { |c| @corporation_phase_color[c.name] = 'Brown' }

@available_par_groups = %i[par]
end

def status_array(corporation)
if can_start?(corporation) || corporation.type == :metal
nil
else
["Available in #{@corporation_phase_color[corporation.name]} Phase"]
end
end

def stock_round
Round::Stock.new(self, [
Engine::Step::DiscardTrain,
Engine::Step::Exchange,
Engine::Step::SpecialTrack,
G18RoyalGorge::Step::BuySellParShares,
])
end

def can_start?(corporation)
case @phase.name
when 'Yellow'
@corporation_phase_color[corporation.name] == @phase.name
when 'Green'
@corporation_phase_color[corporation.name] != 'Brown'
else
true
end
end

def can_par?(corporation, parrer)
can_start?(corporation) && super
end

def event_green_par!
@log << "-- Event: #{EVENTS_TEXT[:green_par]} --"
@available_par_groups << :par_1
update_cache(:share_prices)
end

def event_brown_par!
@log << "-- Event: #{EVENTS_TEXT[:brown_par]} --"
@available_par_groups << :par_2
update_cache(:share_prices)
end

def par_prices
@stock_market.share_prices_with_types(@available_par_groups)
end

def corporation_opts
@players.size == 2 ? { max_ownership_percent: 70 } : {}
end
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions lib/engine/game/g_18_royal_gorge/step/buy_sell_par_shares.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require_relative '../../../step/buy_sell_par_shares'

module Engine
module Game
module G18RoyalGorge
module Step
class BuySellParShares < Engine::Step::BuySellParShares
def get_par_prices(entity, _corp)
@game.par_prices.select { |p| p.price * 2 <= entity.cash }
end
end
end
end
end
end
Loading