Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18Uruguay] Interest should not be paid for penalty loans #11455

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/engine/game/g_18_uruguay/loans.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,30 @@ def adjust_stock_market_loan_penalty(entity)
end
end

def take_loan_if_needed_for_interest!(entity)
def pay_interest!(entity)
owed = interest_owed(entity)
return if owed.zero?
interest_paid[entity] = owed

remaining = owed - entity.cash
perform_ebuy_loans(entity, remaining + 10) if remaining.positive?
while owed > entity.cash &&
(loan = loans[0])
take_loan(entity, loan, ebuy: true)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you test this code? in the original implementation (interest_on_loans.rb),
owed = interest_owed(entity) is inside the loop, to update the owed value.
What's updating the owed value to prevent an infinite loop?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do need to add that line, it looks like this code is identical to the one in interest_on_loans.rb, except
entity.loans.size < maximum_loans(entity)

could you make the max high enough and then prevent this duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two changes here from the "original"

  1. That you in this case are allowed to take more than what is normally allowed
  2. It is by intension that owed is not updated. We do not want to pay interest on loans that we are forced to take due to interest payments. The entity.cash is increased for every loop so it will drop out when the entity has enough cash to pay the interest


if owed <= entity.cash
if owed.positive?
log_interest_payment(entity, owed)
entity.spend(owed, bank)
end
return
end
owed
end

def corps_pay_interest
corps = @round.entities.select { |entity| entity.loans.size.positive? && entity != @rptla }
corps.each do |corp|
next if corp.closed?

take_loan_if_needed_for_interest!(corp)
pay_interest!(corp)
end
end
Expand Down
Loading