Skip to content

Commit

Permalink
Merge pull request #11209 from patrikolesen/18_uruguay_second_share
Browse files Browse the repository at this point in the history
[18Uruguay] Also add FCE shares to secondary corps
  • Loading branch information
bentziaxl authored Jan 16, 2025
2 parents 51a85cd + dabb383 commit a7bad91
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 52 deletions.
1 change: 1 addition & 0 deletions lib/engine/game/g_18_uruguay/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ def next_round!
when 1
start_merge(current_entity.owner)
when 2
acquire_shares
decrease_stock_value
retreive_home_tokens
close_companies
Expand Down
76 changes: 24 additions & 52 deletions lib/engine/game/g_18_uruguay/nationalization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,60 +23,30 @@ def affected_shares(entity, corps)
affected
end

def find_president(holders, corps)
president_candidate = nil
candidate_sum = 0
holders.each do |holder|
entity_shares = affected_shares(holder, corps)
sum = entity_shares.sum(&:percent)
if sum > candidate_sum
president_candidate = holder
candidate_sum = sum
end
end
president_candidate
end

def transfer_share(share, new_owner)
corp = share.corporation
corp.share_holders[share.owner] -= share.percent
corp.share_holders[new_owner] += share.percent
share.owner.shares_by_corporation[corp].delete(share)
new_owner.shares_by_corporation[corp] << share
share.owner = new_owner
end

def transfer_pres_share(corporation, owner)
pres_share = corporation.presidents_share
transfer_share(pres_share, owner)
corporation.owner = owner
end

def acquire_shares_in_fce(corp_fce, merge_data)
new_president = find_president(merge_data[:holders], merge_data[:corps])
transfer_pres_share(corp_fce, new_president)
def acquire_shares
@merge_data[:holders].each do |holder|
entity_shares = affected_shares(holder, @merge_data[:corps])

merge_data[:holders].each do |holder|
aquired = 0
aquired = 20 if holder == new_president
entity_shares = affected_shares(holder, merge_data[:corps])
total_percent = entity_shares.sum(&:percent)
aquire_percent = (total_percent / 20).to_i * 10
while aquired < aquire_percent
share = corp_fce.shares.first
aquired += share.percent
transfer_share(share, holder)
end
number = aquire_percent
@log << "#{holder.name} receives #{number}% in FCE in exchange to the nationalized shares"
odd_share = aquired * 2 != total_percent
next unless odd_share

price = corp_fce.share_price.price / 2
num_shares, odd_shares = (total_percent / 10).divmod(2)
from_secondary = @merge_data[:secondary_corps].count { |corp| corp.president?(holder) }
num_shares += from_secondary
bundle =
if num_shares == 10
Engine::ShareBundle.new(@fce.shares.take(9))
else
Engine::ShareBundle.new(@fce.shares.reject(&:president).take(num_shares))
end
@share_pool.transfer_shares(bundle, holder, allow_president_change: true)
@log << "#{holder.name} receives #{num_shares * 10}% in FCE in exchange to the nationalized shares"

next unless odd_shares

price = @fce.share_price.price / 2
@bank.spend(price, holder)
@log << "#{holder.name} receives #{price} from half share"
end
@log << "#{new_president.name} becomes new president of #{corp_fce.name}"
@log << "#{@fce.presidents_share.owner.name} becomes new president of #{@fce.name}"
end

def compute_merger_share_price(corps)
Expand Down Expand Up @@ -134,12 +104,13 @@ def start_merge(originatior)
candidates = corps_to_nationalize
corps = candidates.take(2)
@merge_data = {
holders: share_holder_list(originatior, corps),
holders: share_holder_list(originatior, candidates),
corps: corps,
secondary_corps: [],
home_tokens: [],
tokens: [],
candidates: candidates,
corp_share_sum: 0,
}

if corps.empty?
Expand All @@ -153,8 +124,9 @@ def start_merge(originatior)
@fce.floatable = true
@stock_market.set_par(@fce, fce_share_price)
after_par(@fce)

acquire_shares_in_fce(@fce, @merge_data)
@merge_data[:corp_share_sum] = @merge_data[:holders].sum do |holder|
(affected_shares(holder, @merge_data[:corps]).sum(&:percent) / 20).to_i * 10
end
end

def nationalization_final_export!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def actions(entity)
return [] if @game.merge_data[:corps].include?(entity)
return [] unless entity.loans.size.positive?
return [] if @game.maximum_loans(entity) < entity.loans.size
return [] if @game.merge_data[:corp_share_sum] + (10 * @game.merge_data[:secondary_corps].size) >= 100

actions = []
actions << 'choose'
Expand Down

0 comments on commit a7bad91

Please sign in to comment.