--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/core/company/money.cpp Wed Mar 14 02:29:26 2007 +0000
@@ -0,0 +1,50 @@
+/* $Id$ */
+
+/** @file money.cpp handles the money-related functions of the AICompany class */
+
+#include "../ai_company.hpp"
+#include "../../../player.h"
+#include "../../../economy.h"
+
+int32 AICompany::GetCompanyValue()
+{
+ return GetPlayer(_current_player)->cur_economy.company_value;
+}
+
+int32 AICompany::GetBankBalance()
+{
+ return GetPlayer(_current_player)->player_money;
+}
+
+int32 AICompany::GetLoanAmount()
+{
+ return GetPlayer(_current_player)->current_loan;
+}
+
+int32 AICompany::GetMaxLoanAmount()
+{
+ return _economy.max_loan;
+}
+
+bool AICompany::SetLoanAmount(int32 loan)
+{
+ if (loan < 0 ||
+ (loan % LOAN_INTERVAL) != 0 ||
+ loan > this->GetMaxLoanAmount() ||
+ (loan - this->GetLoanAmount() + this->GetBankBalance()) < 0) {
+ return false;
+ }
+
+ 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--) {
+ if (CmdFailed(this->DoCommand(0, 0, false, DC_EXEC, increase? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN))) return false;
+ }
+ }
+
+ return true;
+}