--- a/bin/ai/regression/regression.nut Sun Apr 08 14:46:55 2007 +0000
+++ b/bin/ai/regression/regression.nut Wed Apr 11 14:18:10 2007 +0000
@@ -93,6 +93,9 @@
}
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());
--- a/bin/ai/regression/regression.txt Sun Apr 08 14:46:55 2007 +0000
+++ b/bin/ai/regression/regression.txt Wed Apr 11 14:18:10 2007 +0000
@@ -163,7 +163,10 @@
SetCompanyName(): true
SetCompanyName(): true
SetCompanyName(): false
- GetCompanyName(): Regression Transport
+ GetCompanyName(): Regression
+ GetPresidentName(): A. Adams
+ SetPresidentName(): true
+ GetPresidentName(): Regression AI
GetCompanyValue(): 0
GetBankBalance(): 100000
GetLoanAmount(): 100000
--- a/src/ai/api/ai_company.cpp Sun Apr 08 14:46:55 2007 +0000
+++ b/src/ai/api/ai_company.cpp Wed Apr 11 14:18:10 2007 +0000
@@ -13,7 +13,7 @@
if (name == NULL) return false;
_cmd_text = name;
- return this->DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME);
+ return this->DoCommand(0, 0, 0, CMD_CHANGE_COMPANY_NAME);
}
char *AICompany::GetCompanyName()
@@ -25,6 +25,23 @@
return company_name;
}
+bool AICompany::SetPresidentName(const char *name)
+{
+ if (name == NULL) return false;
+
+ _cmd_text = name;
+ return this->DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME);
+}
+
+char *AICompany::GetPresidentName()
+{
+ static const int len = 64;
+ char *president_name = MallocT<char>(len);
+ GetString(president_name, GetPlayer(_current_player)->president_name_1, &president_name[len - 1]);
+
+ return president_name;
+}
+
int32 AICompany::GetCompanyValue()
{
return GetPlayer(_current_player)->cur_economy.company_value;
--- a/src/ai/api/ai_company.hpp Sun Apr 08 14:46:55 2007 +0000
+++ b/src/ai/api/ai_company.hpp Wed Apr 11 14:18:10 2007 +0000
@@ -21,7 +21,7 @@
* Set the name of your company.
* @param name the new name of the company.
* @pre name != NULL
- * @return true if the command was send without problem.
+ * @return true if the name was changed.
*/
bool SetCompanyName(const char *name);
@@ -33,6 +33,21 @@
char *GetCompanyName();
/**
+ * Set the name of your president.
+ * @param name the new name of the president.
+ * @pre name != NULL
+ * @return true if the name was changed.
+ */
+ bool SetPresidentName(const char *name);
+
+ /**
+ * Get the name of your president.
+ * @return the name of your president.
+ * @note the returned president name must be free'd (C++ only).
+ */
+ char *GetPresidentName();
+
+ /**
* Gets the current value of your company.
* @return the current value of your company.
*/
@@ -94,6 +109,8 @@
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");