(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
--- a/bin/ai/regression/regression.nut Fri Feb 29 00:17:59 2008 +0000
+++ b/bin/ai/regression/regression.nut Fri Feb 29 08:51:47 2008 +0000
@@ -233,6 +233,11 @@
print(" SetLoanAmount(10000): " + AICompany.SetLoanAmount(AICompany.GetMaxLoanAmount()));
print(" GetBankBalance(): " + AICompany.GetBankBalance(AICompany.MY_COMPANY));
print(" GetLoanAmount(): " + AICompany.GetLoanAmount());
+ print(" GetCompanyHQ(): " + AICompany.GetCompanyHQ(AICompany.MY_COMPANY));
+ print(" BuildCompanyHQ(): " + AICompany.BuildCompanyHQ(AIMap.GetTileIndex(127, 129)));
+ print(" GetCompanyHQ(): " + AICompany.GetCompanyHQ(AICompany.MY_COMPANY));
+ print(" BuildCompanyHQ(): " + AICompany.BuildCompanyHQ(AIMap.GetTileIndex(129, 129)));
+ print(" GetCompanyHQ(): " + AICompany.GetCompanyHQ(AICompany.MY_COMPANY));
}
function Regression::Engine()
--- a/bin/ai/regression/regression.txt Fri Feb 29 00:17:59 2008 +0000
+++ b/bin/ai/regression/regression.txt Fri Feb 29 08:51:47 2008 +0000
@@ -726,6 +726,11 @@
SetLoanAmount(10000): true
GetBankBalance(): 282534
GetLoanAmount(): 300000
+ GetCompanyHQ(): -1
+ BuildCompanyHQ(): true
+ GetCompanyHQ(): 33151
+ BuildCompanyHQ(): true
+ GetCompanyHQ(): 33153
--Engine--
Engine -1
@@ -4827,7 +4832,7 @@
IsBuoyTile(): false
IsLockTile(): false
IsCanalTile(): false
- GetBankBalance(): 282206
+ GetBankBalance(): 282086
BuildWaterDepot(): true
BuildDock(): true
BuildBuoy(): true
@@ -4838,7 +4843,7 @@
IsBuoyTile(): true
IsLockTile(): true
IsCanalTile(): true
- GetBankBalance(): 252657
+ GetBankBalance(): 252537
RemoveWaterDepot(): true
RemoveDock(): true
RemoveBuoy(): true
@@ -4849,7 +4854,7 @@
IsBuoyTile(): false
IsLockTile(): false
IsCanalTile(): false
- GetBankBalance(): 230012
+ GetBankBalance(): 229892
BuildWaterDepot(): true
BuildDock(): true
@@ -5710,7 +5715,7 @@
IsStoppedInDepot(): false
--Accounting--
GetCosts(): -5945
- Should be: -5944
+ Should be: -5945
GetName(): Road Vehicle 1
SetName(): true
GetName(): MyVehicleName
@@ -5723,7 +5728,7 @@
GetMaxAge(): 5490
GetAgeLeft(): 5489
GetRunningCost(): 421
- GetProfitThisYear(): -1
+ GetProfitThisYear(): 0
GetProfitLastYear(): 0
GetVehicleType(): 1
IsInDepot(): false
@@ -5781,7 +5786,7 @@
15 => 0
13 => 0
12 => 0
- 11 => -1
+ 11 => 0
ProfitLastYear ListDump:
15 => 0
13 => 0
--- a/src/ai/api/ai_company.cpp Fri Feb 29 00:17:59 2008 +0000
+++ b/src/ai/api/ai_company.cpp Fri Feb 29 08:51:47 2008 +0000
@@ -8,6 +8,7 @@
#include "../../player_base.h"
#include "../../economy_func.h"
#include "../../strings_func.h"
+#include "../../tile_map.h"
#include "../../variables.h"
#include "../../core/alloc_func.hpp"
#include "table/strings.h"
@@ -124,3 +125,19 @@
return GetLoanAmount() == loan;
}
+
+/* static */ bool AICompany::BuildCompanyHQ(TileIndex tile)
+{
+ if (!::IsValidTile(tile)) return false;
+
+ return AIObject::DoCommand(tile, 0, 0, CMD_BUILD_COMPANY_HQ);
+}
+
+/* static */ TileIndex AICompany::GetCompanyHQ(CompanyIndex company)
+{
+ company = ResolveCompanyIndex(company);
+ if (company == INVALID_COMPANY) return INVALID_TILE;
+
+ TileIndex loc = ::GetPlayer((PlayerID)company)->location_of_house;
+ return (loc == 0) ? INVALID_TILE : loc;
+}
--- a/src/ai/api/ai_company.hpp Fri Feb 29 00:17:59 2008 +0000
+++ b/src/ai/api/ai_company.hpp Fri Feb 29 08:51:47 2008 +0000
@@ -128,6 +128,23 @@
* @return true if we could allocate a minimum of "loan" loan.
*/
static bool SetMinimumLoanAmount(int32 loan);
+
+ /**
+ * Build your company's HQ on the given tile.
+ * @param tile the tile to build your HQ on, this tile is the most nothern tile of your HQ.
+ * @pre AIMap::IsValidTile(tile).
+ * @note An HQ can not be removed, only by water or rebuilding; If an HQ is build again, the old one is removed.
+ * @return true if the HQ could be build.
+ */
+ static bool BuildCompanyHQ(TileIndex tile);
+
+ /**
+ * Return the location of a company's HQ.
+ * @param company the company the get the HQ of.
+ * @pre ResolveCompanyIndex(company) != INVALID_COMPANY.
+ * @return The tile of the company's HQ, this tile is the most nothern tile of that HQ, or INVALID_TILE if there is no HQ yet.
+ */
+ static TileIndex GetCompanyHQ(CompanyIndex company);
};
DECLARE_POSTFIX_INCREMENT(AICompany::CompanyIndex);
--- a/src/ai/api/ai_company.hpp.sq Fri Feb 29 00:17:59 2008 +0000
+++ b/src/ai/api/ai_company.hpp.sq Fri Feb 29 08:51:47 2008 +0000
@@ -36,6 +36,8 @@
SQAICompany.DefSQStaticMethod(engine, &AICompany::GetLoanInterval, "GetLoanInterval", 1, "x");
SQAICompany.DefSQStaticMethod(engine, &AICompany::SetLoanAmount, "SetLoanAmount", 2, "xi");
SQAICompany.DefSQStaticMethod(engine, &AICompany::SetMinimumLoanAmount, "SetMinimumLoanAmount", 2, "xi");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::BuildCompanyHQ, "BuildCompanyHQ", 2, "xi");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetCompanyHQ, "GetCompanyHQ", 2, "xi");
SQAICompany.PostRegister(engine);
}