--- a/bin/ai/regression/regression.nut Sun Aug 19 13:01:41 2007 +0000
+++ b/bin/ai/regression/regression.nut Sun Aug 19 13:16:06 2007 +0000
@@ -133,6 +133,7 @@
print(" GetPresidentName(): " + company.GetPresidentName(AICompany.MY_COMPANY));
print(" GetCompanyValue(): " + company.GetCompanyValue(AICompany.MY_COMPANY));
print(" GetBankBalance(): " + company.GetBankBalance(AICompany.MY_COMPANY));
+ print(" GetCompanyName(): " + company.GetCompanyName(240));
print(" GetLoanAmount(): " + company.GetLoanAmount());
print(" GetMaxLoanAmount(): " + company.GetMaxLoanAmount());
print(" GetLoanInterval(): " + company.GetLoanInterval());
@@ -579,6 +580,7 @@
print("--Station--");
print(" IsValidStation(0): " + station.IsValidStation(0));
print(" IsValidStation(1000): " + station.IsValidStation(1000));
+ print(" GetName(0): " + station.GetName(0));
print(" GetLocation(1): " + station.GetLocation(1));
print(" GetLocation(1000): " + station.GetLocation(1000));
print(" GetStationID(33411): " + station.GetStationID(33411));
--- a/src/ai/api/ai_company.cpp Sun Aug 19 13:01:41 2007 +0000
+++ b/src/ai/api/ai_company.cpp Sun Aug 19 13:16:06 2007 +0000
@@ -28,16 +28,13 @@
char *AICompany::GetCompanyName(AICompany::CompanyIndex company)
{
company = this->ResolveCompanyIndex(company);
+ if (company == INVALID_COMPANY) return NULL;
static const int len = 64;
char *company_name = MallocT<char>(len);
- if (company != INVALID_COMPANY) {
- SetDParam(0, GetPlayer((PlayerID)company)->index);
- GetString(company_name, STR_COMPANY_NAME, &company_name[len - 1]);
- } else {
- *company_name = '\0';
- }
+ SetDParam(0, GetPlayer((PlayerID)company)->index);
+ GetString(company_name, STR_COMPANY_NAME, &company_name[len - 1]);
return company_name;
}
--- a/src/ai/api/ai_station.cpp Sun Aug 19 13:01:41 2007 +0000
+++ b/src/ai/api/ai_station.cpp Sun Aug 19 13:16:06 2007 +0000
@@ -8,6 +8,8 @@
#include "../../station.h"
#include "../../station_map.h"
#include "../../variables.h"
+#include "../../strings.h"
+#include "table/strings.h"
/* static */ bool AIStation::IsValidStation(StationID station_id)
{
@@ -20,6 +22,18 @@
return ::GetStationIndex(tile);
}
+/* static */ char *AIStation::GetName(StationID station_id)
+{
+ if (!AIStation::IsValidStation(station_id)) return NULL;
+
+ static const int len = 64;
+ char *station_name = MallocT<char>(len);
+
+ SetDParam(0, GetStation(station_id)->index);
+ GetString(station_name, STR_STATION, &station_name[len - 1]);
+ return station_name;
+}
+
/* static */ TileIndex AIStation::GetLocation(StationID station_id)
{
if (!AIStation::IsValidStation(station_id)) return INVALID_TILE;
--- a/src/ai/api/ai_station.hpp Sun Aug 19 13:01:41 2007 +0000
+++ b/src/ai/api/ai_station.hpp Sun Aug 19 13:16:06 2007 +0000
@@ -45,6 +45,14 @@
static StationID GetStationID(TileIndex tile);
/**
+ * Get the name of a station.
+ * @param station_id the station to get the name of.
+ * @pre IsValidStation(station_id).
+ * @return the name of the station.
+ */
+ static char *GetName(StationID station_id);
+
+ /**
* Get the current location of a station.
* @param station_id the station to get the location of.
* @pre IsValidStation(station_id).
--- a/src/ai/api/ai_station.hpp.sq Sun Aug 19 13:01:41 2007 +0000
+++ b/src/ai/api/ai_station.hpp.sq Sun Aug 19 13:16:06 2007 +0000
@@ -28,6 +28,7 @@
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetClassName, "GetClassName", 1, "x");
SQAIStation.DefSQStaticMethod(engine, &AIStation::IsValidStation, "IsValidStation", 2, "xi");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetStationID, "GetStationID", 2, "xi");
+ SQAIStation.DefSQStaticMethod(engine, &AIStation::GetName, "GetName", 2, "xi");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetLocation, "GetLocation", 2, "xi");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCargoWaiting, "GetCargoWaiting", 3, "xii");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCargoRating, "GetCargoRating", 3, "xii");