summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/api/ai_changelog.hpp11
-rw-r--r--src/ai/api/ai_company.cpp55
-rw-r--r--src/ai/api/ai_company.hpp66
-rw-r--r--src/ai/api/ai_company.hpp.sq66
4 files changed, 158 insertions, 40 deletions
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index d9cc76e3a..76897a837 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -19,6 +19,17 @@
*
* 1.2.0 is not yet released. The following changes are not set in stone yet.
*
+ * API additions:
+ *
+ * \li AICompany::GetQuarterlyIncome
+ * \li AICompany::GetQuarterlyExpenses
+ * \li AICompany::GetQuarterlyCargoDelivered
+ * \li AICompany::GetQuarterlyPerformanceRating
+ * \li AICompany::GetQuarterlyCompanyValue
+ *
+ * API removals:
+ * \li AICompany::GetCompanyValue, use AICompany::GetQuarterlyCompanyValue instead.
+ *
* \b 1.1.0
*
* API additions:
diff --git a/src/ai/api/ai_company.cpp b/src/ai/api/ai_company.cpp
index c2a4f2935..90487951c 100644
--- a/src/ai/api/ai_company.cpp
+++ b/src/ai/api/ai_company.cpp
@@ -101,14 +101,65 @@
return HasBit(ge, ::GENDER_FEMALE) ? GENDER_FEMALE : GENDER_MALE;
}
-/* static */ Money AICompany::GetCompanyValue(AICompany::CompanyID company)
+/* static */ Money AICompany::GetQuarterlyIncome(AICompany::CompanyID company, uint32 quarter)
{
company = ResolveCompanyID(company);
if (company == COMPANY_INVALID) return -1;
+ if (quarter > EARLIEST_QUARTER) return -1;
- return ::CalculateCompanyValue(::Company::Get((CompanyID)company));
+ if (quarter == CURRENT_QUARTER) {
+ return ::Company::Get((::CompanyID)company)->cur_economy.income;
+ }
+ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].income;
+}
+
+/* static */ Money AICompany::GetQuarterlyExpenses(AICompany::CompanyID company, uint32 quarter)
+{
+ company = ResolveCompanyID(company);
+ if (company == COMPANY_INVALID) return -1;
+ if (quarter > EARLIEST_QUARTER) return -1;
+
+ if (quarter == CURRENT_QUARTER) {
+ return ::Company::Get((::CompanyID)company)->cur_economy.expenses;
+ }
+ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].expenses;
+}
+
+/* static */ int32 AICompany::GetQuarterlyCargoDelivered(AICompany::CompanyID company, uint32 quarter)
+{
+ company = ResolveCompanyID(company);
+ if (company == COMPANY_INVALID) return -1;
+ if (quarter > EARLIEST_QUARTER) return -1;
+
+ if (quarter == CURRENT_QUARTER) {
+ return ::Company::Get((::CompanyID)company)->cur_economy.delivered_cargo;
+ }
+ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].delivered_cargo;
}
+/* static */ int32 AICompany::GetQuarterlyPerformanceRating(AICompany::CompanyID company, uint32 quarter)
+{
+ company = ResolveCompanyID(company);
+ if (company == COMPANY_INVALID) return -1;
+ if (quarter > EARLIEST_QUARTER) return -1;
+ if (quarter == CURRENT_QUARTER) return -1;
+
+ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].performance_history;
+}
+
+/* static */ Money AICompany::GetQuarterlyCompanyValue(AICompany::CompanyID company, uint32 quarter)
+{
+ company = ResolveCompanyID(company);
+ if (company == COMPANY_INVALID) return -1;
+ if (quarter > EARLIEST_QUARTER) return -1;
+
+ if (quarter == CURRENT_QUARTER) {
+ return ::CalculateCompanyValue(::Company::Get((::CompanyID)company));
+ }
+ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].company_value;
+}
+
+
/* static */ Money AICompany::GetBankBalance(AICompany::CompanyID company)
{
company = ResolveCompanyID(company);
diff --git a/src/ai/api/ai_company.hpp b/src/ai/api/ai_company.hpp
index 263271fc1..f7e329531 100644
--- a/src/ai/api/ai_company.hpp
+++ b/src/ai/api/ai_company.hpp
@@ -22,6 +22,12 @@ public:
/** Get the name of this class to identify it towards squirrel. */
static const char *GetClassName() { return "AICompany"; }
+ /** The range of possible quarters to get company information of. */
+ enum Quarter {
+ CURRENT_QUARTER = 0, ///< The current quarter.
+ EARLIEST_QUARTER = MAX_HISTORY_QUARTERS, ///< The earliest quarter company information is available for.
+ };
+
/** Different constants related to CompanyID. */
enum CompanyID {
COMPANY_FIRST = 0, ///< The first available company.
@@ -149,14 +155,6 @@ public:
static Money GetLoanInterval();
/**
- * Gets the current value of the given company.
- * @param company The company to get the company value of.
- * @pre ResolveCompanyID(company) != COMPANY_INVALID.
- * @return The current value of the given company.
- */
- static Money GetCompanyValue(CompanyID 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 ResolveCompanyID(company) != COMPANY_INVALID.
@@ -165,6 +163,58 @@ public:
static Money GetBankBalance(CompanyID company);
/**
+ * Get the income of the company in the given quarter.
+ * @param company The company to get the quarterly income of.
+ * @param quarter The quarter to get the income of.
+ * @pre ResolveCompanyID(company) != COMPANY_INVALID.
+ * @pre quarter <= EARLIEST_QUARTER.
+ * @return The bruto income of the company in the given quarter.
+ */
+ static Money GetQuarterlyIncome(CompanyID company, uint32 quarter);
+
+ /**
+ * Get the expenses of the company in the given quarter.
+ * @param company The company to get the quarterly expenses of.
+ * @param quarter The quarter to get the expenses of.
+ * @pre ResolveCompanyID(company) != COMPANY_INVALID.
+ * @pre quarter <= EARLIEST_QUARTER.
+ * @return The expenses of the company in the given quarter.
+ */
+ static Money GetQuarterlyExpenses(CompanyID company, uint32 quarter);
+
+ /**
+ * Get the amount of cargo delivered by the given company in the given quarter.
+ * @param company The company to get the amount of delivered cargo of.
+ * @param quarter The quarter to get the amount of delivered cargo of.
+ * @pre ResolveCompanyID(company) != COMPANY_INVALID.
+ * @pre quarter <= EARLIEST_QUARTER.
+ * @return The amount of cargo delivered by the given company in the given quarter.
+ */
+ static int32 GetQuarterlyCargoDelivered(CompanyID company, uint32 quarter);
+
+ /**
+ * Get the performance rating of the given company in the given quarter.
+ * @param company The company to get the performance rating of.
+ * @param quarter The quarter to get the performance rating of.
+ * @pre ResolveCompanyID(company) != COMPANY_INVALID.
+ * @pre quarter <= EARLIEST_QUARTER.
+ * @pre quarter != CURRENT_QUARTER.
+ * @note The performance rating is calculated after every quarter, so the value for CURRENT_QUARTER is undefined.
+ * @return The performance rating of the given company in the given quarter.
+ */
+ static int32 GetQuarterlyPerformanceRating(CompanyID company, uint32 quarter);
+
+ /**
+ * Get the value of the company in the given quarter.
+ * @param company The company to get the value of.
+ * @param quarter The quarter to get the value of.
+ * @pre ResolveCompanyID(company) != COMPANY_INVALID.
+ * @pre quarter <= EARLIEST_QUARTER.
+ * @return The value of the company in the given quarter.
+ */
+ static Money GetQuarterlyCompanyValue(CompanyID company, uint32 quarter);
+
+ /**
* 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).
diff --git a/src/ai/api/ai_company.hpp.sq b/src/ai/api/ai_company.hpp.sq
index e91989834..8673cb842 100644
--- a/src/ai/api/ai_company.hpp.sq
+++ b/src/ai/api/ai_company.hpp.sq
@@ -32,37 +32,43 @@ void SQAICompany_Register(Squirrel *engine)
SQAICompany.PreRegister(engine);
SQAICompany.AddConstructor<void (AICompany::*)(), 1>(engine, "x");
- SQAICompany.DefSQConst(engine, AICompany::COMPANY_FIRST, "COMPANY_FIRST");
- SQAICompany.DefSQConst(engine, AICompany::COMPANY_LAST, "COMPANY_LAST");
- SQAICompany.DefSQConst(engine, AICompany::COMPANY_SELF, "COMPANY_SELF");
- SQAICompany.DefSQConst(engine, AICompany::COMPANY_INVALID, "COMPANY_INVALID");
- SQAICompany.DefSQConst(engine, AICompany::GENDER_MALE, "GENDER_MALE");
- SQAICompany.DefSQConst(engine, AICompany::GENDER_FEMALE, "GENDER_FEMALE");
- SQAICompany.DefSQConst(engine, AICompany::GENDER_INVALID, "GENDER_INVALID");
+ SQAICompany.DefSQConst(engine, AICompany::CURRENT_QUARTER, "CURRENT_QUARTER");
+ SQAICompany.DefSQConst(engine, AICompany::EARLIEST_QUARTER, "EARLIEST_QUARTER");
+ SQAICompany.DefSQConst(engine, AICompany::COMPANY_FIRST, "COMPANY_FIRST");
+ SQAICompany.DefSQConst(engine, AICompany::COMPANY_LAST, "COMPANY_LAST");
+ SQAICompany.DefSQConst(engine, AICompany::COMPANY_SELF, "COMPANY_SELF");
+ SQAICompany.DefSQConst(engine, AICompany::COMPANY_INVALID, "COMPANY_INVALID");
+ SQAICompany.DefSQConst(engine, AICompany::GENDER_MALE, "GENDER_MALE");
+ SQAICompany.DefSQConst(engine, AICompany::GENDER_FEMALE, "GENDER_FEMALE");
+ SQAICompany.DefSQConst(engine, AICompany::GENDER_INVALID, "GENDER_INVALID");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::ResolveCompanyID, "ResolveCompanyID", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::IsMine, "IsMine", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::SetName, "SetName", 2, "..");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetName, "GetName", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentName, "SetPresidentName", 2, "..");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetPresidentName, "GetPresidentName", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentGender, "SetPresidentGender", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetPresidentGender, "GetPresidentGender", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::SetLoanAmount, "SetLoanAmount", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::SetMinimumLoanAmount, "SetMinimumLoanAmount", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetLoanAmount, "GetLoanAmount", 1, ".");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetMaxLoanAmount, "GetMaxLoanAmount", 1, ".");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetLoanInterval, "GetLoanInterval", 1, ".");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetCompanyValue, "GetCompanyValue", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetBankBalance, "GetBankBalance", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::BuildCompanyHQ, "BuildCompanyHQ", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetCompanyHQ, "GetCompanyHQ", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::SetAutoRenewStatus, "SetAutoRenewStatus", 2, ".b");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetAutoRenewStatus, "GetAutoRenewStatus", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::SetAutoRenewMonths, "SetAutoRenewMonths", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetAutoRenewMonths, "GetAutoRenewMonths", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::SetAutoRenewMoney, "SetAutoRenewMoney", 2, ".i");
- SQAICompany.DefSQStaticMethod(engine, &AICompany::GetAutoRenewMoney, "GetAutoRenewMoney", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::ResolveCompanyID, "ResolveCompanyID", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::IsMine, "IsMine", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::SetName, "SetName", 2, "..");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetName, "GetName", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentName, "SetPresidentName", 2, "..");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetPresidentName, "GetPresidentName", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentGender, "SetPresidentGender", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetPresidentGender, "GetPresidentGender", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::SetLoanAmount, "SetLoanAmount", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::SetMinimumLoanAmount, "SetMinimumLoanAmount", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetLoanAmount, "GetLoanAmount", 1, ".");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetMaxLoanAmount, "GetMaxLoanAmount", 1, ".");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetLoanInterval, "GetLoanInterval", 1, ".");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetQuarterlyIncome, "GetQuarterlyIncome", 3, ".ii");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetQuarterlyExpenses, "GetQuarterlyExpenses", 3, ".ii");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetQuarterlyCargoDelivered, "GetQuarterlyCargoDelivered", 3, ".ii");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetQuarterlyPerformanceRating, "GetQuarterlyPerformanceRating", 3, ".ii");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetQuarterlyCompanyValue, "GetQuarterlyCompanyValue", 3, ".ii");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetBankBalance, "GetBankBalance", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::BuildCompanyHQ, "BuildCompanyHQ", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetCompanyHQ, "GetCompanyHQ", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::SetAutoRenewStatus, "SetAutoRenewStatus", 2, ".b");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetAutoRenewStatus, "GetAutoRenewStatus", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::SetAutoRenewMonths, "SetAutoRenewMonths", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetAutoRenewMonths, "GetAutoRenewMonths", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::SetAutoRenewMoney, "SetAutoRenewMoney", 2, ".i");
+ SQAICompany.DefSQStaticMethod(engine, &AICompany::GetAutoRenewMoney, "GetAutoRenewMoney", 2, ".i");
SQAICompany.PostRegister(engine);
}