(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance. noai
authorrubidium
Sun, 15 Jul 2007 16:39:11 +0000
branchnoai
changeset 9668 6fe3d2cb9655
parent 9667 053afa64f977
child 9669 366771e15a2c
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
bin/ai/wrightai/main.nut
src/ai/NoAI/NoAI.cpp
src/ai/api/ai_company.cpp
src/ai/api/ai_company.hpp
src/ai/api/ai_company.hpp.sq
--- a/bin/ai/regression/regression.nut	Sun Jul 15 13:24:06 2007 +0000
+++ b/bin/ai/regression/regression.nut	Sun Jul 15 16:39:11 2007 +0000
@@ -71,19 +71,19 @@
 		print("  AiportAvailable(" + i + "):   " + airport.AiportAvailable(i));
 	}
 
-	print("  GetBankBalance():     " + company.GetBankBalance());
+	print("  GetBankBalance():     " + company.GetBankBalance(AICompany.MY_COMPANY));
 	print("  BuildAirport():       " + airport.BuildAirport(32116, 0));
 	print("  IsHangarTile():       " + airport.IsHangarTile(32116));
 	print("  IsAirportTile():      " + airport.IsAirportTile(32116));
 	print("  GetHangarOfAirport(): " + airport.GetHangarOfAirport(32116));
 	print("  IsHangarTile():       " + airport.IsHangarTile(32119));
 	print("  IsAirportTile():      " + airport.IsAirportTile(32119));
-	print("  GetBankBalance():     " + company.GetBankBalance());
+	print("  GetBankBalance():     " + company.GetBankBalance(AICompany.MY_COMPANY));
 
 	print("  RemoveAirport():      " + airport.RemoveAirport(32118));
 	print("  IsHangarTile():       " + airport.IsHangarTile(32119));
 	print("  IsAirportTile():      " + airport.IsAirportTile(32119));
-	print("  GetBankBalance():     " + company.GetBankBalance());
+	print("  GetBankBalance():     " + company.GetBankBalance(AICompany.MY_COMPANY));
 	print("  BuildAirport():       " + airport.BuildAirport(32116, 0));
 }
 
@@ -124,23 +124,26 @@
 		}
 	}
 
-	print("  GetCompanyName():     " + company.GetCompanyName());
-	print("  GetPresidentName():   " + company.GetPresidentName());
-	print("  SetPresidentName():   " + company.SetPresidentName("Regression AI"));
-	print("  GetPresidentName():   " + company.GetPresidentName());
-	print("  GetCompanyValue():    " + company.GetCompanyValue());
-	print("  GetBankBalance():     " + company.GetBankBalance());
-	print("  GetLoanAmount():      " + company.GetLoanAmount());
-	print("  GetMaxLoanAmount():   " + company.GetMaxLoanAmount());
-	print("  GetLoanInterval():    " + company.GetLoanInterval());
-	print("  SetLoanAmount(1):     " + company.SetLoanAmount(1));
-	print("  SetLoanAmount(100):   " + company.SetLoanAmount(100));
-	print("  SetLoanAmount(10000): " + company.SetLoanAmount(10000));
-	print("  GetBankBalance():     " + company.GetBankBalance());
-	print("  GetLoanAmount():      " + company.GetLoanAmount());
-	print("  SetLoanAmount(10000): " + company.SetLoanAmount(company.GetMaxLoanAmount()));
-	print("  GetBankBalance():     " + company.GetBankBalance());
-	print("  GetLoanAmount():      " + company.GetLoanAmount());
+	print("  GetCompanyName():            " + company.GetCompanyName(AICompany.MY_COMPANY));
+	print("  GetPresidentName():          " + company.GetPresidentName(AICompany.MY_COMPANY));
+	print("  SetPresidentName():          " + company.SetPresidentName("Regression AI"));
+	print("  GetPresidentName():          " + company.GetPresidentName(AICompany.MY_COMPANY));
+	print("  GetCompanyValue():           " + company.GetCompanyValue(AICompany.MY_COMPANY));
+	print("  GetBankBalance():            " + company.GetBankBalance(AICompany.MY_COMPANY));
+	print("  GetLoanAmount():             " + company.GetLoanAmount());
+	print("  GetMaxLoanAmount():          " + company.GetMaxLoanAmount());
+	print("  GetLoanInterval():           " + company.GetLoanInterval());
+	print("  SetLoanAmount(1):            " + company.SetLoanAmount(1));
+	print("  SetLoanAmount(100):          " + company.SetLoanAmount(100));
+	print("  SetLoanAmount(10000):        " + company.SetLoanAmount(10000));
+	print("  GetBankBalance():            " + company.GetBankBalance(AICompany.MY_COMPANY));
+	print("  GetLoanAmount():             " + company.GetLoanAmount());
+	print("  SetMinimumLoanAmount(31337): " + company.SetMinimumLoanAmount(31337));
+	print("  GetBankBalance():            " + company.GetBankBalance(AICompany.MY_COMPANY));
+	print("  GetLoanAmount():             " + company.GetLoanAmount());
+	print("  SetLoanAmount(10000):        " + company.SetLoanAmount(company.GetMaxLoanAmount()));
+	print("  GetBankBalance():            " + company.GetBankBalance(AICompany.MY_COMPANY));
+	print("  GetLoanAmount():             " + company.GetLoanAmount());
 }
 
 function Regression::Industry()
@@ -678,7 +681,7 @@
 		print("    Reliability 100:    " + vehicle.FindBestAircraftVehicle(i, 100));
 	}
 
-	local bank = company.GetBankBalance();
+	local bank = company.GetBankBalance(AICompany.MY_COMPANY);
 
 	{
 		local transaction = AITransactionMode();
@@ -693,20 +696,20 @@
 	}
 	print("  CloneVehicle():       " + vehicle.CloneVehicle(33417, 1024, true));
 
-	local bank_after = company.GetBankBalance();
+	local bank_after = company.GetBankBalance(AICompany.MY_COMPANY);
 
 	print("  --Accounting--");
 	print("    GetCosts():         " + accounting.GetCosts());
 	print("    Should be:          " + (bank - bank_after));
 	print("    ResetCosts():       " + accounting.ResetCosts());
 
-	bank = company.GetBankBalance();
+	bank = company.GetBankBalance(AICompany.MY_COMPANY);
 
 	print("  SellVehicle(1025):    " + vehicle.SellVehicle(1025));
 	print("  StartStopVehicle():   " + vehicle.StartStopVehicle(1024));
 	print("  SendVehicleToDepot(): " + vehicle.SendVehicleToDepot(1024));
 
-	bank_after = company.GetBankBalance();
+	bank_after = company.GetBankBalance(AICompany.MY_COMPANY);
 
 	print("  --Accounting--");
 	print("    GetCosts():         " + accounting.GetCosts());
--- a/bin/ai/regression/regression.txt	Sun Jul 15 13:24:06 2007 +0000
+++ b/bin/ai/regression/regression.txt	Sun Jul 15 16:39:11 2007 +0000
@@ -192,23 +192,26 @@
   SetCompanyName():     true
   SetCompanyName():     true
   SetCompanyName():     false
-  GetCompanyName():     Regression
-  GetPresidentName():   L. Parker
-  SetPresidentName():   true
-  GetPresidentName():   Regression AI
-  GetCompanyValue():    0
-  GetBankBalance():     84436
-  GetLoanAmount():      100000
-  GetMaxLoanAmount():   300000
-  GetLoanInterval():    10000
-  SetLoanAmount(1):     false
-  SetLoanAmount(100):   false
-  SetLoanAmount(10000): false
-  GetBankBalance():     84436
-  GetLoanAmount():      100000
-  SetLoanAmount(10000): true
-  GetBankBalance():     284436
-  GetLoanAmount():      300000
+  GetCompanyName():            Regression
+  GetPresidentName():          L. Parker
+  SetPresidentName():          true
+  GetPresidentName():          Regression AI
+  GetCompanyValue():           0
+  GetBankBalance():            84436
+  GetLoanAmount():             100000
+  GetMaxLoanAmount():          300000
+  GetLoanInterval():           10000
+  SetLoanAmount(1):            false
+  SetLoanAmount(100):          false
+  SetLoanAmount(10000):        false
+  GetBankBalance():            84436
+  GetLoanAmount():             100000
+  SetMinimumLoanAmount(31337): true
+  GetBankBalance():            24436
+  GetLoanAmount():             40000
+  SetLoanAmount(10000):        true
+  GetBankBalance():            284436
+  GetLoanAmount():             300000
 
 --Industry--
   GetMaxIndustryID():  71
@@ -867,144 +870,144 @@
     1098 => 1098
     1099 => 1099
   Randomize ListDump:
-    1 => -2039536299
-    2 => 796838333
-    1000 => 438558874
-    1001 => 179516226
-    1002 => -1007339217
-    1003 => 859527945
-    1004 => 124767077
-    1005 => 1693978408
-    1006 => -880974321
-    1007 => 559618342
-    1008 => 1569811314
-    1009 => 870205254
-    1010 => -1758318443
-    1011 => -444945639
-    1012 => -1608782669
-    1013 => 433700979
-    1014 => -855225247
-    1015 => 1879656391
-    1016 => 398529614
-    1017 => -2049334382
-    1018 => 840638691
-    1019 => -1384047520
-    1020 => 1955145790
-    1021 => 477697425
-    1022 => -1395473168
-    1023 => -1470736319
-    1024 => 1816531430
-    1025 => 469019242
-    1026 => 39077628
-    1027 => 664188731
-    1028 => 1750781759
-    1029 => -647481353
-    1030 => 696701854
-    1031 => -1413895498
-    1032 => 604542808
-    1033 => 1987508951
-    1034 => -1069250041
-    1035 => 173906611
-    1036 => 680670954
-    1037 => 2073579869
-    1038 => -1595475211
-    1039 => -1988008457
-    1040 => -869393758
-    1041 => -833288209
-    1042 => 97291907
-    1043 => -1979472169
-    1044 => -922114803
-    1045 => 321893130
-    1046 => -270105978
-    1047 => 1294387584
-    1048 => -1952039371
-    1049 => -1954676003
-    1051 => -1104910473
-    1052 => -422921716
-    1053 => 1224064537
-    1054 => 1710423508
-    1055 => -1618366898
-    1056 => -1972920327
-    1057 => -1228206217
-    1058 => 946938986
-    1059 => -1701157824
-    1060 => 1071969693
-    1061 => -809033431
-    1062 => -934111918
-    1063 => -1106636240
-    1064 => -1988056095
-    1065 => -1117013134
-    1066 => 621979826
-    1067 => -2004975443
-    1068 => 1540115053
-    1069 => 275963171
-    1070 => 889543466
-    1071 => 201714893
-    1072 => 1632614672
-    1073 => 769082751
-    1074 => 162800763
-    1075 => -373023425
-    1076 => -1966408356
-    1077 => 2064251247
-    1078 => 1139816730
-    1079 => 671778950
-    1080 => 23001506
-    1081 => -542275239
-    1082 => -688757755
-    1083 => -1599747459
-    1084 => 1599536138
-    1085 => 1610850417
-    1086 => 492239132
-    1087 => -1594652903
-    1088 => -1716035643
-    1089 => -211545671
-    1090 => 1644622460
-    1091 => 1941915278
-    1092 => -1801759945
-    1093 => -789334533
-    1094 => 588603837
-    1095 => 608572342
-    1096 => 886201348
-    1097 => -1491076971
-    1098 => 1172943384
-    1099 => 9895172
+    1 => 1163947042
+    2 => -1513471425
+    1000 => 1562384206
+    1001 => 1833834195
+    1002 => -643703837
+    1003 => 79805044
+    1004 => -1946902569
+    1005 => -1363518126
+    1006 => 954256773
+    1007 => 72347912
+    1008 => 47883823
+    1009 => -526367464
+    1010 => 346325205
+    1011 => -291428903
+    1012 => -1188902385
+    1013 => -1562251412
+    1014 => -552815341
+    1015 => 603515522
+    1016 => 522991803
+    1017 => 1584966634
+    1018 => 259781126
+    1019 => -1798372027
+    1020 => -1290381010
+    1021 => -2118641661
+    1022 => 1981833351
+    1023 => 356860827
+    1024 => -748795736
+    1025 => 1281369326
+    1026 => 38829942
+    1027 => -962063214
+    1028 => 686566813
+    1029 => -463383379
+    1030 => -51377460
+    1031 => -1314021363
+    1032 => -22458076
+    1033 => -1689110622
+    1034 => 1917673188
+    1035 => -374359940
+    1036 => 814208703
+    1037 => -779698758
+    1038 => 26176155
+    1039 => 318789462
+    1040 => 1275414053
+    1041 => -1236954331
+    1042 => -857923735
+    1043 => 595999707
+    1044 => -1992427987
+    1045 => 306864841
+    1046 => 653337905
+    1047 => 1953580222
+    1048 => 1207858715
+    1049 => 408422240
+    1051 => 829258216
+    1052 => -1724902148
+    1053 => -1627854008
+    1054 => 1608232025
+    1055 => -1379999864
+    1056 => 1465015175
+    1057 => -717078999
+    1058 => 1397987245
+    1059 => 1761965383
+    1060 => -40513737
+    1061 => -877356160
+    1062 => 1039172583
+    1063 => -1108941798
+    1064 => 603116880
+    1065 => -580990468
+    1066 => -1456784483
+    1067 => -1440803259
+    1068 => 583917089
+    1069 => 1367075057
+    1070 => 1762142035
+    1071 => 748223299
+    1072 => -1749562785
+    1073 => -423135862
+    1074 => 250140274
+    1075 => 208016187
+    1076 => 799885915
+    1077 => -2135630100
+    1078 => -1446755021
+    1079 => -290921131
+    1080 => -1042816678
+    1081 => -1399388025
+    1082 => -1777598091
+    1083 => 1413196365
+    1084 => 920434787
+    1085 => 1131297890
+    1086 => -361269603
+    1087 => -1848914632
+    1088 => -896934400
+    1089 => -1133847065
+    1090 => -597619383
+    1091 => -1030970132
+    1092 => -1337968061
+    1093 => 1966368896
+    1094 => -2074278501
+    1095 => 1144440235
+    1096 => 1566334976
+    1097 => 1383194789
+    1098 => -230311246
+    1099 => -1462383584
   KeepTop(10):
-    1 => -2039536299
-    2 => 796838333
-    1000 => 438558874
-    1001 => 179516226
-    1002 => -1007339217
-    1003 => 859527945
-    1004 => 124767077
-    1005 => 1693978408
-    1006 => -880974321
-    1007 => 559618342
+    1 => 1163947042
+    2 => -1513471425
+    1000 => 1562384206
+    1001 => 1833834195
+    1002 => -643703837
+    1003 => 79805044
+    1004 => -1946902569
+    1005 => -1363518126
+    1006 => 954256773
+    1007 => 72347912
   KeepBottom(8):
-    1000 => 438558874
-    1001 => 179516226
-    1002 => -1007339217
-    1003 => 859527945
-    1004 => 124767077
-    1005 => 1693978408
-    1006 => -880974321
-    1007 => 559618342
+    1000 => 1562384206
+    1001 => 1833834195
+    1002 => -643703837
+    1003 => 79805044
+    1004 => -1946902569
+    1005 => -1363518126
+    1006 => 954256773
+    1007 => 72347912
   RemoveBottom(2):
-    1000 => 438558874
-    1001 => 179516226
-    1002 => -1007339217
-    1003 => 859527945
-    1004 => 124767077
-    1005 => 1693978408
+    1000 => 1562384206
+    1001 => 1833834195
+    1002 => -643703837
+    1003 => 79805044
+    1004 => -1946902569
+    1005 => -1363518126
   RemoveTop(2):
-    1002 => -1007339217
-    1003 => 859527945
-    1004 => 124767077
-    1005 => 1693978408
+    1002 => -643703837
+    1003 => 79805044
+    1004 => -1946902569
+    1005 => -1363518126
   RemoveList({1003, 1004}):
-    1002 => -1007339217
-    1005 => 1693978408
+    1002 => -643703837
+    1005 => -1363518126
   KeepList({1003, 1004, 1005}):
-    1005 => 1693978408
+    1005 => -1363518126
   IsEmpty():     true
 
 --PathFinderStupid--
--- a/bin/ai/wrightai/main.nut	Sun Jul 15 13:24:06 2007 +0000
+++ b/bin/ai/wrightai/main.nut	Sun Jul 15 16:39:11 2007 +0000
@@ -38,7 +38,7 @@
  */
 function WrightAI::HasMoney(money)
 {
-	if (this.company.GetBankBalance() + (this.company.GetMaxLoanAmount() - this.company.GetLoanAmount()) > money) return true;
+	if (this.company.GetBankBalance(AICompany.MY_COMPANY) + (this.company.GetMaxLoanAmount() - this.company.GetLoanAmount()) > money) return true;
 	return false;
 }
 
@@ -48,9 +48,9 @@
 function WrightAI::GetMoney(money)
 {
 	if (!this.HasMoney(money)) return;
-	if (this.company.GetBankBalance() > money) return;
+	if (this.company.GetBankBalance(AICompany.MY_COMPANY) > money) return;
 
-	local loan = money - this.company.GetBankBalance() + this.company.GetLoanInterval() + this.company.GetLoanAmount();
+	local loan = money - this.company.GetBankBalance(AICompany.MY_COMPANY) + this.company.GetLoanInterval() + this.company.GetLoanAmount();
 	loan = loan - loan % this.company.GetLoanInterval();
 	print(this.name + ": Need a loan to get " + money + ": " + loan);
 	this.company.SetLoanAmount(loan);
@@ -282,7 +282,7 @@
 			i++;
 		}
 	}
-	this.name = this.company.GetCompanyName();
+	this.name = this.company.GetCompanyName(AICompany.MY_COMPANY);
 	print(this.name + ": Welcome to WrightAI. I will be building airports all day long.");
 
 	/* We start with almost no loan, and we take a loan when we want to build something */
--- a/src/ai/NoAI/NoAI.cpp	Sun Jul 15 13:24:06 2007 +0000
+++ b/src/ai/NoAI/NoAI.cpp	Sun Jul 15 16:39:11 2007 +0000
@@ -39,7 +39,7 @@
 	}
 
 	if (this->GetTick() % 10 == 0) {
-		char *company_name = this->company.GetCompanyName();
+		char *company_name = this->company.GetCompanyName(AICompany::MY_COMPANY);
 		printf("%s has loaned %d\n", company_name, this->company.GetLoanAmount());
 		free(company_name);
 	}
--- a/src/ai/api/ai_company.cpp	Sun Jul 15 13:24:06 2007 +0000
+++ b/src/ai/api/ai_company.cpp	Sun Jul 15 16:39:11 2007 +0000
@@ -10,6 +10,13 @@
 #include "../../variables.h"
 #include "table/strings.h"
 
+AICompany::CompanyIndex AICompany::ResolveCompanyIndex(AICompany::CompanyIndex company)
+{
+	if (company == MY_COMPANY) return (CompanyIndex)_current_player;
+
+	return (IsValidPlayer((PlayerID)company) && GetPlayer((PlayerID)company)->is_active) ? company : INVALID_COMPANY;
+}
+
 bool AICompany::SetCompanyName(const char *name)
 {
 	if (name == NULL) return false;
@@ -18,12 +25,18 @@
 	return this->DoCommand(0, 0, 0, CMD_CHANGE_COMPANY_NAME);
 }
 
-char *AICompany::GetCompanyName()
+char *AICompany::GetCompanyName(AICompany::CompanyIndex company)
 {
+	company = this->ResolveCompanyIndex(company);
+
 	static const int len = 64;
 	char *company_name = MallocT<char>(len);
-	SetDParam(0, GetPlayer(_current_player)->index);
-	GetString(company_name, STR_COMPANY_NAME, &company_name[len - 1]);
+	if (company != INVALID_COMPANY) {
+		SetDParam(0, GetPlayer((PlayerID)company)->index);
+		GetString(company_name, STR_COMPANY_NAME, &company_name[len - 1]);
+	} else {
+		*company_name = '\0';
+	}
 
 	return company_name;
 }
@@ -36,24 +49,36 @@
 	return this->DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME);
 }
 
-char *AICompany::GetPresidentName()
+char *AICompany::GetPresidentName(AICompany::CompanyIndex company)
 {
+	company = this->ResolveCompanyIndex(company);
+
 	static const int len = 64;
 	char *president_name = MallocT<char>(len);
-	SetDParam(0, GetPlayer(_current_player)->index);
-	GetString(president_name, STR_PLAYER_NAME, &president_name[len - 1]);
+	if (company != INVALID_COMPANY) {
+		SetDParam(0, GetPlayer((PlayerID)company)->index);
+		GetString(president_name, STR_PLAYER_NAME, &president_name[len - 1]);
+	} else {
+		*president_name = '\0';
+	}
 
 	return president_name;
 }
 
-int32 AICompany::GetCompanyValue()
+int32 AICompany::GetCompanyValue(AICompany::CompanyIndex company)
 {
-	return GetPlayer(_current_player)->cur_economy.company_value;
+	company = this->ResolveCompanyIndex(company);
+	if (company == INVALID_COMPANY) return 0;
+
+	return GetPlayer((PlayerID)company)->cur_economy.company_value;
 }
 
-int32 AICompany::GetBankBalance()
+int32 AICompany::GetBankBalance(AICompany::CompanyIndex company)
 {
-	return GetPlayer(_current_player)->player_money;
+	company = this->ResolveCompanyIndex(company);
+	if (company == INVALID_COMPANY) return 0;
+
+	return GetPlayer((PlayerID)company)->player_money;
 }
 
 int32 AICompany::GetLoanAmount()
@@ -76,7 +101,7 @@
 	if (loan < 0 ||
 			(loan % this->GetLoanInterval()) != 0 ||
 			loan > this->GetMaxLoanAmount() ||
-			(loan - this->GetLoanAmount() + this->GetBankBalance()) < 0) {
+			(loan - this->GetLoanAmount() + this->GetBankBalance(MY_COMPANY)) < 0) {
 		return false;
 	}
 
@@ -86,3 +111,17 @@
 			abs(loan - this->GetLoanAmount()), 2,
 			(loan > this->GetLoanAmount()) ? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN);
 }
+
+bool AICompany::SetMinimumLoanAmount(int32 loan)
+{
+	if (loan < 0) return false;
+
+	int32 over_interval = loan % this->GetLoanInterval();
+	if (over_interval != 0) loan += this->GetLoanInterval() - over_interval;
+
+	if (loan > this->GetMaxLoanAmount()) return false;
+
+	this->SetLoanAmount(loan);
+
+	return this->GetLoanAmount() == loan;
+}
--- a/src/ai/api/ai_company.hpp	Sun Jul 15 13:24:06 2007 +0000
+++ b/src/ai/api/ai_company.hpp	Sun Jul 15 16:39:11 2007 +0000
@@ -17,6 +17,25 @@
 	 */
 	static const char *GetClassName() { return "AICompany"; }
 
+	/** Different constants related to companies */
+	enum CompanyIndex {
+		FIRST_COMPANY   = 0, ///< The first available company.
+		LAST_COMPANY    = 7, ///< The last available company.
+		MY_COMPANY      = 8, ///< Constant that gets resolved to the correct company index for your company.
+		INVALID_COMPANY = 9, ///< An invalid company
+	};
+
+	/**
+	 * Resolved the given company index to the correct index
+	 * for the company. If the company index was MY_COMPANY
+	 * it will be resolved to the index of your company.
+	 * If the company with the given index does not exist
+	 * it will return INVALID_COMPANY.
+	 * @param company the company index to resolve.
+	 * @return the resolved company index.
+	 */
+	CompanyIndex ResolveCompanyIndex(CompanyIndex company);
+
 	/**
 	 * Set the name of your company.
 	 * @param name the new name of the company.
@@ -26,11 +45,13 @@
 	bool SetCompanyName(const char *name);
 
 	/**
-	 * Get the name of your company.
-	 * @return the name of your company.
+	 * Get the name of the given company.
+	 * @param company the company to get the name for.
+	 * @pre ResolveCompanyIndex(company) != INVALID_COMPANY
+	 * @return the name of the given company.
 	 * @note the returned company name must be free'd (C++ only).
 	 */
-	char *GetCompanyName();
+	char *GetCompanyName(CompanyIndex company);
 
 	/**
 	 * Set the name of your president.
@@ -41,23 +62,29 @@
 	bool SetPresidentName(const char *name);
 
 	/**
-	 * Get the name of your president.
-	 * @return the name of your president.
+	 * Get the name of the president of the given company.
+	 * @param company the company to get the president's name for.
+	 * @pre ResolveCompanyIndex(company) != INVALID_COMPANY
+	 * @return the name of the president of the given company.
 	 * @note the returned president name must be free'd (C++ only).
 	 */
-	char *GetPresidentName();
+	char *GetPresidentName(CompanyIndex company);
 
 	/**
-	 * Gets the current value of your company.
-	 * @return the current value of your company.
+	 * Gets the current value of the given company.
+	 * @param company the company to get the company value of.
+	 * @pre ResolveCompanyIndex(company) != INVALID_COMPANY
+	 * @return the current value of the given company.
 	 */
-	int32 GetCompanyValue();
+	int32 GetCompanyValue(CompanyIndex company);
 
 	/**
-	 * Gets the bank balance. In other words, the amount of money you can spent.
-	 * @return the bank balance of your company.
+	 * Gets the bank balance. In other words, the amount of money the given company can spent.
+	 * @param company the company to get the bank balance of.
+	 * @pre ResolveCompanyIndex(company) != INVALID_COMPANY
+	 * @return the actual bank balance.
 	 */
-	int32 GetBankBalance();
+	int32 GetBankBalance(CompanyIndex company);
 
 	/**
 	 * Gets the amount your company have loaned.
@@ -92,6 +119,17 @@
 	 * @return true if the loan could be set to your requested amount.
 	 */
 	bool SetLoanAmount(int32 loan);
+
+	/**
+	 * Sets the minimum amount to loan, i.e. the given amount of loan rounded up.
+	 * @param loan the amount to loan (any positive number).
+	 * @pre loan must be non-negative.
+	 * @pre loan must be below GetMaxLoan().
+	 * @return true if we could allocate a minimum of "loan" loan.
+	 */
+	bool SetMinimumLoanAmount(int32 loan);
 };
 
+DECLARE_POSTFIX_INCREMENT(AICompany::CompanyIndex);
+
 #endif /* AI_COMPANY_HPP */
--- a/src/ai/api/ai_company.hpp.sq	Sun Jul 15 13:24:06 2007 +0000
+++ b/src/ai/api/ai_company.hpp.sq	Sun Jul 15 16:39:11 2007 +0000
@@ -1,6 +1,10 @@
 #include "ai_company.hpp"
 
 namespace SQConvert {
+	/* Allow enums to be used as Squirrel parameters */
+	template <> AICompany::CompanyIndex GetParam(ForceType<AICompany::CompanyIndex>, HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AICompany::CompanyIndex)tmp; }
+	template <> int Return<AICompany::CompanyIndex>(HSQUIRRELVM vm, AICompany::CompanyIndex res) { sq_pushinteger(vm, (int32)res); return 1; }
+
 	/* Allow AICompany to be used as Squirrel parameter */
 	template <> AICompany *GetParam(ForceType<AICompany *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AICompany *)instance; }
 	template <> AICompany &GetParam(ForceType<AICompany &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AICompany *)instance; }
@@ -13,18 +17,25 @@
 	SQAICompany.PreRegister(engine);
 	SQAICompany.AddConstructor<void (AICompany::*)(), 1>(engine, "x");
 
+	SQAICompany.DefSQConst(engine, AICompany::FIRST_COMPANY,   "FIRST_COMPANY");
+	SQAICompany.DefSQConst(engine, AICompany::LAST_COMPANY,    "LAST_COMPANY");
+	SQAICompany.DefSQConst(engine, AICompany::MY_COMPANY,      "MY_COMPANY");
+	SQAICompany.DefSQConst(engine, AICompany::INVALID_COMPANY, "INVALID_COMPANY");
+
 	SQAICompany.DefSQStaticMethod(engine, &AICompany::GetClassName, "GetClassName", 1, "x");
 
-	SQAICompany.DefSQMethod(engine, &AICompany::SetCompanyName,   "SetCompanyName",   2, "xs");
-	SQAICompany.DefSQMethod(engine, &AICompany::GetCompanyName,   "GetCompanyName",   1, "x");
-	SQAICompany.DefSQMethod(engine, &AICompany::SetPresidentName, "SetPresidentName", 2, "xs");
-	SQAICompany.DefSQMethod(engine, &AICompany::GetPresidentName, "GetPresidentName", 1, "x");
-	SQAICompany.DefSQMethod(engine, &AICompany::GetCompanyValue,  "GetCompanyValue",  1, "x");
-	SQAICompany.DefSQMethod(engine, &AICompany::GetBankBalance,   "GetBankBalance",   1, "x");
-	SQAICompany.DefSQMethod(engine, &AICompany::GetLoanAmount,    "GetLoanAmount",    1, "x");
-	SQAICompany.DefSQMethod(engine, &AICompany::GetMaxLoanAmount, "GetMaxLoanAmount", 1, "x");
-	SQAICompany.DefSQMethod(engine, &AICompany::GetLoanInterval,  "GetLoanInterval",  1, "x");
-	SQAICompany.DefSQMethod(engine, &AICompany::SetLoanAmount,    "SetLoanAmount",    2, "xi");
+	SQAICompany.DefSQMethod(engine, &AICompany::ResolveCompanyIndex,  "ResolveCompanyIndex",  2, "xi");
+	SQAICompany.DefSQMethod(engine, &AICompany::SetCompanyName,       "SetCompanyName",       2, "xs");
+	SQAICompany.DefSQMethod(engine, &AICompany::GetCompanyName,       "GetCompanyName",       2, "xi");
+	SQAICompany.DefSQMethod(engine, &AICompany::SetPresidentName,     "SetPresidentName",     2, "xs");
+	SQAICompany.DefSQMethod(engine, &AICompany::GetPresidentName,     "GetPresidentName",     2, "xi");
+	SQAICompany.DefSQMethod(engine, &AICompany::GetCompanyValue,      "GetCompanyValue",      2, "xi");
+	SQAICompany.DefSQMethod(engine, &AICompany::GetBankBalance,       "GetBankBalance",       2, "xi");
+	SQAICompany.DefSQMethod(engine, &AICompany::GetLoanAmount,        "GetLoanAmount",        1, "x");
+	SQAICompany.DefSQMethod(engine, &AICompany::GetMaxLoanAmount,     "GetMaxLoanAmount",     1, "x");
+	SQAICompany.DefSQMethod(engine, &AICompany::GetLoanInterval,      "GetLoanInterval",      1, "x");
+	SQAICompany.DefSQMethod(engine, &AICompany::SetLoanAmount,        "SetLoanAmount",        2, "xi");
+	SQAICompany.DefSQMethod(engine, &AICompany::SetMinimumLoanAmount, "SetMinimumLoanAmount", 2, "xi");
 
 	SQAICompany.PostRegister(engine);
 }