Skip to content

Commit

Permalink
Merge remote-tracking branch 'tobymao/master' into 1847_ae
Browse files Browse the repository at this point in the history
  • Loading branch information
Galatolol committed Dec 14, 2023
2 parents 495d9c7 + 6fd24b4 commit a048eed
Show file tree
Hide file tree
Showing 72 changed files with 22,803 additions and 14,528 deletions.
1 change: 1 addition & 0 deletions api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def render_pin(**needs)
static(
desc: " (Pin #{pin})",
js_tags: "<script type='text/javascript' src='#{Assets::PIN_DIR}#{pin}.js'></script>",
**needs,
)
end

Expand Down
1 change: 1 addition & 0 deletions assets/app/view/game/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def render
fontSize: '80%',
textAlign: 'left',
fontWeight: 'normal',
whiteSpace: 'pre-line',
}

value_style = {
Expand Down
2 changes: 1 addition & 1 deletion assets/app/view/welcome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def render

def render_notification
message = <<~MESSAGE
<p><a href="https://github.com/tobymao/18xx/wiki/1868%20Wyoming">1868 Wyoming</a> is in beta.</p>
<p><a href="https://github.com/tobymao/18xx/wiki/1868%20Wyoming">1868 Wyoming</a> and <a href="https://github.com/tobymao/18xx/wiki/18NL">18NL</a> are in beta.</p>
<p>Learn how to get <a href='https://github.com/tobymao/18xx/wiki/Notifications'>notifications</a> by email, Slack, Discord, and Telegram.</p>
<p>Please submit problem reports and make suggestions for improvements on
<a href='https://github.com/tobymao/18xx/issues'>GitHub</a>. Join the
Expand Down
28 changes: 19 additions & 9 deletions lib/engine/game/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class Base
# first -- after first stock round
# after_ipo -- after stock round in which company is opened
# operate -- after operation
# full_or_turn -- after corp completes a full OR turn
# p_any_operate -- pres any time, share holders after operation
# any_time -- at any time
# round -- after the stock round the share was purchased in
Expand Down Expand Up @@ -1067,6 +1068,12 @@ def check_sale_timing(entity, bundle)
corporation.operated?
when :p_any_operate
corporation.operated? || corporation.president?(entity)
when :full_or_turn
if @round.operating? && corporation.president?(entity)
corporation.operating_history.size > 1
else
corporation.operated?
end
when :round
(@round.stock? &&
corporation.share_holders[entity] - @round.players_bought[entity][corporation] >= bundle.percent) ||
Expand Down Expand Up @@ -1115,17 +1122,20 @@ def bundles_for_corporation(share_holder, corporation, shares: nil)
def all_bundles_for_corporation(share_holder, corporation, shares: nil)
return [] unless corporation.ipoed

shares = (shares || share_holder.shares_of(corporation)).sort_by { |h| [h.president ? 1 : 0, h.percent] }
shares ||= share_holder.shares_of(corporation)
return [] if shares.empty?

bundles = shares.flat_map.with_index do |share, index|
bundle = shares.take(index + 1)
percent = bundle.sum(&:percent)
bundles = [Engine::ShareBundle.new(bundle, percent)]
bundles.concat(partial_bundles_for_presidents_share(corporation, bundle, percent)) if share.president
bundles
shares = shares.sort_by { |h| [h.president ? 1 : 0, h.percent] }
bundle = []
percent = 0
all_bundles = shares.each_with_object([]) do |share, bundles|
bundle << share
percent += share.percent
bundles << Engine::ShareBundle.new(bundle, percent)
end
all_bundles.concat(partial_bundles_for_presidents_share(corporation, bundle, percent)) if shares.last.president

bundles.sort_by(&:percent)
all_bundles.sort_by(&:percent)
end

def partial_bundles_for_presidents_share(corporation, bundle, percent)
Expand Down Expand Up @@ -1417,7 +1427,7 @@ def compute_stops(route, train = nil)
# in a city/town/offboard slot.
distance = distance.sort_by { |types, _| types.size }

max_num_stops = [distance.sum { |h| h['pay'] }, visits.size].min
max_num_stops = [distance.sum { |h| h['pay'].to_i }, visits.size].min

max_num_stops.downto(1) do |num_stops|
# to_i to work around Opal bug
Expand Down
3 changes: 2 additions & 1 deletion lib/engine/game/g_1817/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,8 @@ def corporation_size_name(entity)
end

def empty_auction_slot
@empty_auction_slot ||= Engine::Company.new(sym: '', name: '', value: nil, revenue: nil, desc: '', color: 'LightGrey')
@empty_auction_slot ||= Engine::Company.new(sym: '', name: '', value: nil, revenue: nil, desc: "\n" * 3,
color: 'LightGrey')
end

def company_header(company)
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/game/g_1822/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Game < Game::Base
MUST_BUY_TRAIN = :always
NEXT_SR_PLAYER_ORDER = :most_cash

SELL_AFTER = :operate
SELL_AFTER = :full_or_turn

SELL_BUY_ORDER = :sell_buy

Expand Down
6 changes: 5 additions & 1 deletion lib/engine/game/g_1822_ca/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ def qmoo
@qmoo ||= corporation_by_id('QMOO')
end

def icr
@icr ||= corporation_by_id('ICR')
end

def after_lay_tile(hex, old_tile, tile)
super

Expand Down Expand Up @@ -708,7 +712,7 @@ def pending_home_tokeners
end

def render_hex_reservation?(corporation)
if corporation.id == 'QMOO'
if corporation == qmoo
quebec_hex.tile.color != :white && quebec_hex.tile.cities.size > 1 && current_entity != corporation
else
super
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/game/g_1822_ca/step/destination_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def process_place_token(action)
@game.remove_extra_tokens!(hex.tile)

# interactions with ICR's destination and QMOO's home
@game.update_home(qmoo) if entity.id == 'ICR'
@game.update_home(@game.qmoo) if entity == @game.icr

pass!
end
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/game/g_1822_ca/step/pending_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PendingToken < G1822::Step::PendingToken
def setup_m14_track_rights(_m14); end

def process_place_token(action)
if action.entity == @game.corporation_by_id('QMOO') &&
if action.entity == @game.qmoo &&
action.city.hex == @game.quebec_hex &&
action.city.available_slots.zero?
raise GameError, "Cannot place QMOO's home token in occupied or reserved city"
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/game/g_1822_pnw/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ module Entities
text_color: 'black',
},
{
name: 'MINOR: 14. Camas Prarie Railroad',
name: 'MINOR: 14. Camas Prairie Railroad',
sym: 'M14',
value: 100,
revenue: 0,
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/game/g_1822_pnw/meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Meta
GAME_INFO_URL = 'https://github.com/tobymao/18xx/wiki/1822PNW'.freeze
GAME_LOCATION = 'Pacific Northwest'.freeze
GAME_PUBLISHER = :all_aboard_games
GAME_RULES_URL = 'https://boardgamegeek.com/thread/2890404/1822pnw-public-rules-review'.freeze
GAME_RULES_URL = 'https://boardgamegeek.com/filepage/269597/1822pnw-rules'.freeze
GAME_TITLE = '1822PNW'.freeze

PLAYER_RANGE = [3, 5].freeze
Expand Down
4 changes: 2 additions & 2 deletions lib/engine/game/g_1825/step/track_and_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ def place_token(entity, city, token, connected: true, extra_action: false,

spender ||= entity
if spender.cash >= token.price
pay_token_cost(spender, token.price) if token.price.positive?
pay_token_cost(spender, token.price, nil) if token.price.positive?
else
diff = token.price - spender.cash
pay_token_cost(spender, spender.cash) if spender.cash.positive?
pay_token_cost(spender, spender.cash, nil) if spender.cash.positive?
@round.receivership_loan += diff
end

Expand Down
39 changes: 27 additions & 12 deletions lib/engine/game/g_1826/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@ module Entities
desc: 'This company allows a Corporation to increase the value of a City by F10 for all its runs. Once chosen,'\
' the corp and city cannot be changed. This closes the private company. Bonus is removed when the first E'\
' train is purchased.',
abilities: [],
abilities: [
{
type: 'assign_hexes',
when: 'any',
hexes: %w[B12 C11 C13 C15 E5 E15 F12 G9 G19 I1 I7 I13 K17 L14 M3 M13],
count: 1,
owner_type: 'player',
},
{
type: 'assign_corporation',
when: 'any',
count: 1,
owner_type: 'player',
},
],
color: nil,
},
{
name: "Chemin de Fer d'Algérie",
Expand Down Expand Up @@ -86,7 +101,7 @@ module Entities

CORPORATIONS = [
{
float_percent: 60,
float_percent: 50,
sym: 'Paris',
name: 'Chemin de Fer de Paris',
logo: '1826/Paris',
Expand All @@ -98,7 +113,7 @@ module Entities
color: 'sand',
},
{
float_percent: 60,
float_percent: 50,
sym: 'PO',
name: 'Chemin de Fer de Paris-Orléans',
logo: '1826/PO',
Expand All @@ -111,7 +126,7 @@ module Entities
text_color: 'black',
},
{
float_percent: 60,
float_percent: 50,
sym: 'N',
name: 'Chemin de Fer du Nord',
logo: '1826/N',
Expand All @@ -123,7 +138,7 @@ module Entities
color: 'red',
},
{
float_percent: 60,
float_percent: 50,
sym: 'Est',
name: "Chemin de Fer de l'Est",
logo: '1826/Est',
Expand All @@ -135,7 +150,7 @@ module Entities
color: 'orange',
},
{
float_percent: 60,
float_percent: 50,
sym: 'O',
name: "Chemin de Fer de l'Ouest",
logo: '1846/O',
Expand All @@ -148,7 +163,7 @@ module Entities
text_color: 'black',
},
{
float_percent: 60,
float_percent: 50,
sym: 'Midi',
name: 'Chemin de Fer du Midi',
logo: '1826/Midi',
Expand All @@ -160,7 +175,7 @@ module Entities
color: 'brightGreen',
},
{
float_percent: 60,
float_percent: 50,
sym: 'GC',
name: 'Grand Central de France',
logo: '1826/GC',
Expand All @@ -172,7 +187,7 @@ module Entities
text_color: 'black',
},
{
float_percent: 60,
float_percent: 50,
sym: 'PLM',
name: 'Chemin de Fer Paris-Lyon-Méditerranée',
logo: '1826/PLM',
Expand All @@ -185,7 +200,7 @@ module Entities
text_color: 'black',
},
{
float_percent: 60,
float_percent: 50,
sym: 'Al',
name: "Chemin de Fer d'Alsace",
logo: '1826/Al',
Expand All @@ -196,7 +211,7 @@ module Entities
color: 'blue',
},
{
float_percent: 60,
float_percent: 50,
sym: 'B',
name: "Chemins de Fer de l'Etat Belge",
logo: '1826/B',
Expand All @@ -215,7 +230,7 @@ module Entities
],
},
{
float_percent: 60,
float_percent: 50,
sym: 'Etat',
name: "Chemins de Fer de l'Etat",
logo: '1826/Etat',
Expand Down
45 changes: 45 additions & 0 deletions lib/engine/game/g_1826/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Game < Game::Base
{ 'nodes' => ['town'], 'pay' => 0, 'visit' => 99 }],
price: 800,
num: 2,
events: [{ 'type' => 'remove_abilities' }],
},
{
name: 'TGV',
Expand All @@ -112,6 +113,14 @@ class Game < Game::Base
},
].freeze

ASSIGNMENT_TOKENS = {
'P2' => '/icons/1826/mail.svg',
}.freeze

EVENTS_TEXT = Base::EVENTS_TEXT.merge(
'remove_abilities' => ['Mail Token Removed'],
).freeze

def operating_round(round_num)
Round::Operating.new(self, [
Engine::Step::Bankrupt,
Expand All @@ -129,6 +138,42 @@ def operating_round(round_num)
[Engine::Step::BuyCompany, { blocks: true }],
], round_num: round_num)
end

def regie
@regie ||= company_by_id('P2')
end

def revenue_for(route, stops)
revenue = super

revenue += 10 if route.corporation.assigned?(regie.id) && stops.find { |s| s.hex.assigned?(regie.id) }

revenue
end

def event_remove_abilities!
@log << 'Company abilities are removed'
removals = Hash.new { |h, k| h[k] = {} }

@corporations.each do |corp|
corp.assignments.dup.each do |company, _|
removals[company][:corporation] = corp.name
corp.remove_assignment!(company)
end
end

@hexes.each do |hex|
hex.assignments.dup.each do |company, _|
removals[company][:hex] = hex.name
hex.remove_assignment!(company)
end
end

removals.each do |company, removal|
corp = removal[:corporation]
@log << "-- Event: #{corp}'s #{company_by_id(company).name} ability is removed --"
end
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/engine/game/g_1844/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,13 @@ def sellable_bundles(player, corporation)
bundles
end

def shares_for_presidency_swap(shares, num_shares)
return super unless shares.first.corporation == sbb

double_share = shares.find { |s| s.percent == sbb.presidents_share.percent }
double_share ? [double_share] : shares.take(num_shares)
end

def after_buy_company(player, company, _price)
super
return if !mountain_railways.include?(company) && !tunnel_companies.include?(company)
Expand Down
6 changes: 6 additions & 0 deletions lib/engine/game/g_1844/step/buy_train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def buyable_train_variants(train, entity)
variants
end

def other_trains(entity)
trains = super
trains.select! { |t| @game.hex_train_name?(t.name) } if entity.type == :regional
trains
end

def spend_minmax(entity, train)
return [train.price, train.price] if [train.owner, entity].include?(@game.sbb) ||
(train.owner&.corporation? && train.owner.owner != entity.owner)
Expand Down
Loading

0 comments on commit a048eed

Please sign in to comment.