(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
--- a/src/ai/NoAI/NoAI.cpp Wed Mar 14 09:30:22 2007 +0000
+++ b/src/ai/NoAI/NoAI.cpp Wed Mar 14 09:53:24 2007 +0000
@@ -15,7 +15,7 @@
}
if (this->GetTick() % 14 == 0) {
- uint level = (this->company.GetMaxLoanAmount() / 10000) + 1;
- this->company.SetLoanAmount(this->base.RandomRange(level) * 10000);
+ uint level = (this->company.GetMaxLoanAmount() / this->company.GetLoanInterval()) + 1;
+ this->company.SetLoanAmount(this->base.RandomRange(level) * this->company.GetLoanInterval());
}
}
--- a/src/ai/core/ai_company.hpp Wed Mar 14 09:30:22 2007 +0000
+++ b/src/ai/core/ai_company.hpp Wed Mar 14 09:53:24 2007 +0000
@@ -40,7 +40,7 @@
* Gets the amount the company have loaned
* @return the amount loaned
* @post return >= 0
- * @post return % LOAN_INTERVAL == 0
+ * @post return % this->GetLoanInterval() == 0
*/
int32 GetLoanAmount();
@@ -48,15 +48,22 @@
* Gets the maximum amount the company can loan
* @return the maximum amount the company can loan
* @post return >= 0
- * @post return % LOAN_INTERVAL == 0
+ * @post return % this->GetLoanInterval() == 0
*/
int32 GetMaxLoanAmount();
/**
+ * Gets the interval/loan steps
+ * @return the loan steps
+ * @post return >= 0
+ */
+ int32 GetLoanInterval();
+
+ /**
* Sets the amount to loan
- * @param loan the amount to load (multitude of LOAN_INTERVAL)
+ * @param loan the amount to load (multitude of GetLoanInterval())
* @pre loan >= 0
- * @pre loan % LOAN_INTERVAL == 0
+ * @pre loan % this->GetLoanInterval() == 0
* @pre loan < GetMaxLoan()
* @pre loan - GetLoan() + GetBankBalance() > 0
* @return true if the command was send without a problem
--- a/src/ai/core/company/money.cpp Wed Mar 14 09:30:22 2007 +0000
+++ b/src/ai/core/company/money.cpp Wed Mar 14 09:53:24 2007 +0000
@@ -26,22 +26,29 @@
return _economy.max_loan;
}
+int32 AICompany::GetLoanInterval()
+{
+ return LOAN_INTERVAL;
+}
+
bool AICompany::SetLoanAmount(int32 loan)
{
if (loan < 0 ||
- (loan % LOAN_INTERVAL) != 0 ||
+ (loan % this->GetLoanInterval()) != 0 ||
loan > this->GetMaxLoanAmount() ||
(loan - this->GetLoanAmount() + this->GetBankBalance()) < 0) {
return false;
}
+ /* When we get/repay everything at once (or the maximum we can repay),
+ * use the shortcut for that. Otherwise send several commands at once */
if (loan == 0) {
return !CmdFailed(this->DoCommand(0, 0, true, DC_EXEC, CMD_DECREASE_LOAN));
} else if (loan == this->GetMaxLoanAmount()) {
return !CmdFailed(this->DoCommand(0, 0, true, DC_EXEC, CMD_INCREASE_LOAN));
} else {
bool increase = loan > this->GetLoanAmount();
- for (uint diff_loan = abs(loan - this->GetLoanAmount()) / LOAN_INTERVAL; diff_loan > 0; diff_loan--) {
+ for (uint diff_loan = abs(loan - this->GetLoanAmount()) / this->GetLoanInterval(); diff_loan > 0; diff_loan--) {
if (CmdFailed(this->DoCommand(0, 0, false, DC_EXEC, increase? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN))) return false;
}
}