Skip to content

Commit

Permalink
18USA: PR cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ventusignis committed Feb 13, 2022
1 parent 518f003 commit 98f33f1
Show file tree
Hide file tree
Showing 17 changed files with 13 additions and 60 deletions.
4 changes: 2 additions & 2 deletions assets/app/view/game/scrap_trains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ScrapTrains < Snabberb::Component

def render
@corporation ||= @game.round.active_step.current_entity
step = @game.round.active_step
step = @game.round.step_for(@corporation, 'scrap_train')

scrappable_trains = step.scrappable_trains(@corporation)
return nil if scrappable_trains.empty?
Expand All @@ -33,7 +33,7 @@ def render
end

def scrap_trains(scrappable_trains)
step = @game.round.active_step
step = @game.round.step_for(@corporation, 'scrap_train')
scrappable_trains.flat_map do |train|
scrap = lambda do
process_action(Engine::Action::ScrapTrain.new(
Expand Down
6 changes: 2 additions & 4 deletions lib/engine/game/g_18_usa/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,7 @@ def use_1840_style_merger_round_scrap_trains?
end

def crowded_corps
@crowded_corps ||= corporations.select do |c|
trains = self.class::OBSOLETE_TRAINS_COUNT_FOR_LIMIT ? c.trains.size : c.trains.count { |t| !t.obsolete }
trains > train_limit(c) || c.trains.count { |t| pullman_train?(t) } > 1
end
@crowded_corps ||= super | corporations.select { |c| c.trains.count { |t| pullman_train?(t) } > 1 }
end

# owner is the alleged corporation scrapping a pullman
Expand Down Expand Up @@ -700,6 +697,7 @@ def scrap_train(train)
@bank.spend(pullman_scrap_value, train.owner)
@log << "#{train.owner.name} scraps a pullman for #{format_currency(pullman_scrap_value)}"
@depot.reclaim_train(train)
@crowded_corps = nil
end

def next_round!
Expand Down
31 changes: 5 additions & 26 deletions lib/engine/game/g_18_usa/step/acquire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,18 @@ def actions(entity)
end

def pass_description
if @offer
'Pass (Offer for Sale)'
elsif @auctioning
'Pass (Bid)'
elsif @buyer && can_take_loan?(@buyer)
'Pass (Take Loan)'
elsif @buyer && can_payoff?(@buyer)
'Pass (On payoff Loan)'
elsif @buyer
'Pass (Scrap Train)'
end
return 'Pass (Scrap Train)' if @buyer && !can_take_loan?(@buyer) && !can_payoff?(@buyer)

super
end

def process_pass(action)
if @offer
@game.log << "#{@offer.owner.name} declines to put #{@offer.name} up for sale"
@round.offering.delete(@offer)
@offer = nil
setup_auction
elsif @buyer && can_take_loan?(@buyer)
@passed_take_loans = true
@game.log << "#{@buyer.name} passes taking additional loans"
acquire_post_loan
elsif @buyer && can_payoff?(@buyer)
@passed_payoff_loans = true
@game.log << "#{@buyer.name} passes paying off additional loans"
acquire_post_loan
elsif @buyer
if @buyer && !can_take_loan?(@buyer) && !can_payoff?(@buyer)
@passed_scrap_trains = true
@game.log << "#{@buyer.name} passes scrapping trains"
acquire_post_loan
else
pass_auction(action.entity)
super
end
end

Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/assign.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# frozen_string_literal: true

require_relative '../../../step/assign'
require_relative 'scrap_train_module'
module Engine
module Game
module G18USA
module Step
class Assign < Engine::Step::Assign
include ScrapTrainModule
def process_assign(action)
company = action.entity
target = action.target
Expand Down
6 changes: 3 additions & 3 deletions lib/engine/game/g_18_usa/step/buy_pullman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

require_relative '../../../step/base'
require_relative '../../../step/train'
require_relative 'scrap_train_module'
module Engine
module Game
module G18USA
module Step
class BuyPullman < Engine::Step::Base
include Engine::Step::Train
include ScrapTrainModule # Why would you scrap a pullman so you can buy a pullman!?
def actions(entity)
return [] if entity != current_entity

if @game.depot.upcoming.any? { |t| t.name == 'P' } && can_buy_train?(entity) && @game.pullmans_available? && \
if @game.depot.upcoming.any? do |t|
@game.pullman_train?(t)
end && can_buy_train?(entity) && @game.pullmans_available? && \
entity.runnable_trains.none? { |t| @game.pullman_train?(t) }
return %w[buy_train pass]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/game/g_18_usa/step/buy_sell_par_shares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def can_scrap_train?(entity)
end

def scrappable_trains(entity)
entity.trains.select { |t| t.name == 'P' }
entity.trains.select { |t| @game.pullman_train?(t) }
end

def scrap_info(_)
Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/buy_train.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# frozen_string_literal: true

require_relative '../../g_1817/step/buy_train'
require_relative 'scrap_train_module'

module Engine
module Game
module G18USA
module Step
class BuyTrain < G1817::Step::BuyTrain
include ScrapTrainModule
def should_buy_train?(entity)
:liquidation if entity.trains.reject { |t| @game.pullman_train?(t) }.empty?
end
Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/denver_track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

require_relative '../../../step/base'
require_relative '../../../step/tracker'
require_relative 'scrap_train_module'

module Engine
module Game
module G18USA
module Step
class DenverTrack < Engine::Step::Base
include Engine::Step::Tracker
include ScrapTrainModule
ACTIONS = %w[lay_tile].freeze

def actions(entity)
Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/dividend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

require_relative '../../../step/half_pay'
require_relative '../../g_1817/step/dividend'
require_relative 'scrap_train_module'
module Engine
module Game
module G18USA
module Step
class Dividend < G1817::Step::Dividend
include ScrapTrainModule
DIVIDEND_TYPES = %i[payout half withhold].freeze
include Engine::Step::HalfPay

Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/obsolete_train.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# frozen_string_literal: true

require_relative '../../../step/base'
require_relative 'scrap_train_module'
module Engine
module Game
module G18USA
module Step
class ObsoleteTrain < Engine::Step::Base
include ScrapTrainModule
ACTIONS = %w[choose pass].freeze

def actions(entity)
Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/reduce_tokens.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# frozen_string_literal: true

require_relative '../../../step/reduce_tokens'
require_relative 'scrap_train_module'
module Engine
module Game
module G18USA
module Step
class ReduceTokens < Engine::Step::ReduceTokens
include ScrapTrainModule
def actions(entity)
actions = super.dup
actions << 'choose' if !actions.empty? && owns_p8?(entity)
Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/route.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# frozen_string_literal: true

require_relative '../../../step/route'
require_relative 'scrap_train_module'
module Engine
module Game
module G18USA
module Step
class Route < Engine::Step::Route
include ScrapTrainModule
def actions(entity)
return [] if !entity.operator? || @game.route_trains(entity).empty? || !@game.can_run_route?(entity)

Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/special_buy_train.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# frozen_string_literal: true

require_relative '../../../step/special_buy_train'
require_relative 'scrap_train_module'
module Engine
module Game
module G18USA
module Step
class SpecialBuyTrain < Engine::Step::SpecialBuyTrain
include ScrapTrainModule
def must_buy_train?(_entity)
false
end
Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/special_token.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# frozen_string_literal: true

require_relative '../../../step/special_token'
require_relative 'scrap_train_module'

module Engine
module Game
module G18USA
module Step
class SpecialToken < Engine::Step::SpecialToken
include ScrapTrainModule
def process_place_token(action)
super

Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/special_track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

require_relative '../../../step/special_track'
require_relative 'resource_track'
require_relative 'scrap_train_module'

module Engine
module Game
module G18USA
module Step
class SpecialTrack < Engine::Step::SpecialTrack
include ResourceTrack
include ScrapTrainModule

def actions(entity)
return [] if entity&.id == 'P16' && !@game.phase.tiles.include?(:brown)
Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/token.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# frozen_string_literal: true

require_relative '../../../step/token'
require_relative 'scrap_train_module'

module Engine
module Game
module G18USA
module Step
class Token < Engine::Step::Token
include ScrapTrainModule
def place_token(entity, city, token, connected: true, extra_action: false,
special_ability: nil, check_tokenable: true, spender: nil)
super
Expand Down
2 changes: 0 additions & 2 deletions lib/engine/game/g_18_usa/step/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require_relative '../../../step/track'
require_relative '../../../step/upgrade_track_max_exits'
require_relative 'resource_track'
require_relative 'scrap_train_module'

module Engine
module Game
Expand All @@ -12,7 +11,6 @@ module Step
class Track < Engine::Step::Track
include Engine::Step::UpgradeTrackMaxExits
include ResourceTrack
include ScrapTrainModule

def can_lay_tile?(entity)
super || can_place_token_with_p20?(entity) || can_assign_p6?(entity)
Expand Down

0 comments on commit 98f33f1

Please sign in to comment.