Skip to content

Commit

Permalink
[18Norway] Add the ships in the case that the company have a train bu…
Browse files Browse the repository at this point in the history
…t have less money then the next available train
  • Loading branch information
patrikolesen committed Mar 9, 2025
1 parent f3259d0 commit 759253e
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions lib/engine/game/g_18_norway/steps/buy_train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ def must_buy_train?(entity)
end

def buyable_trains(entity)
super.reject do |train|
next false unless @game.ship?(train)

must_buy_train?(entity) || entity.trains.any? { |ship| ship.name == train.name }
end
# We need to add the ships in the case that the company have a train but have less money then the next available train
ships = (must_buy_train?(entity) || entity.cash >= @depot.min_depot_price) ? [] :
@depot.depot_trains.reject do |train|
true unless @game.ship?(train)
true if train.price > entity.cash
end
super + ships
end

def process_sell_shares(action)
Expand Down Expand Up @@ -84,15 +86,6 @@ def spend_minmax(entity, _train)
[1, entity.cash]
end

def check_for_cheapest_train(train)
cheapest = @game.cheapest_train
cheapest_names = names_of_cheapest_variants(cheapest)
raise GameError, "Cannot purchase #{train.name} train: cheaper train available (#{cheapest_names.first})" if
!cheapest_names.include?(train.name) &&
@game.class::EBUY_DEPOT_TRAIN_MUST_BE_CHEAPEST &&
(@game.class::EBUY_FROM_OTHERS == :never || train.from_depot?)
end

def needed_cash(entity)
cheapest_train_price(entity)
end
Expand Down

0 comments on commit 759253e

Please sign in to comment.