Skip to content

Commit

Permalink
[18Uruguay] Secondary capitalization
Browse files Browse the repository at this point in the history
The corporation get the rest of the capitalization when the reach there destination tile
  • Loading branch information
patrikolesen committed Feb 4, 2024
1 parent 032b890 commit 870b571
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/engine/game/g_18_uruguay/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def operating_round(round_num)
Engine::Step::SpecialToken,
G18Uruguay::Step::TakeLoanBuyCompany,
Engine::Step::HomeToken,
Engine::Step::Track,
G18Uruguay::Step::Track,
G18Uruguay::Step::Token,
Engine::Step::Route,
Engine::Step::Dividend,
Expand Down Expand Up @@ -403,6 +403,13 @@ def or_round_finished
def final_operating_round?
@final_turn == @turn
end

# Second capatilization
def second_capitalization!(corporation)
amount = corporation.par_price.price * 5
@bank.spend(amount, corporation)
@log << "Connected to destination #{corporation.name} receives #{format_currency(amount)}"
end
end
end
end
Expand Down
63 changes: 63 additions & 0 deletions lib/engine/game/g_18_uruguay/step/track.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

require_relative '../../../step/tracker'
require_relative '../../../step/track'

module Engine
module Game
module G18Uruguay
module Step
class Track < Engine::Step::Track
def actions(entity)
return [] if entity == @game.rptla
return [] if @game.final_operating_round?

@round.loan_taken |= false
actions = super.map(&:clone)
actions << 'take_loan' if @game.can_take_loan?(entity) && !@round.loan_taken && !@game.nationalized?
actions
end

def destination_node_check?(entity)
return if entity.destination_coordinates.nil?

destination_hex = @game.hex_by_id(entity.destination_coordinates)
home_node = entity.tokens.first.city
destination_hex.tile.nodes.first&.walk(corporation: entity) do |path, _, _|
return true if path.nodes.include?(home_node)
end
false
end

def check_and_apply_destination_bonus
corporation = current_entity.corporation
apply_destination_bonus(corporation) if destination_node_check?(corporation)
end

def apply_destination_bonus(corporation)
ability = @game.abilities(corporation, :destination_bonus)
@game.second_capitalization!(corporation) unless ability.nil?
ability&.use!
end

def lay_tile(action, extra_cost: 0, entity: nil, spender: nil)
ret = super
check_and_apply_destination_bonus
ret
end

def pass!
check_and_apply_destination_bonus
super
end

def process_take_loan(action)
entity = action.entity
@game.take_loan(entity, action.loan) unless @round.loan_taken
@round.loan_taken = true
end
end
end
end
end
end

0 comments on commit 870b571

Please sign in to comment.