--- a/bin/ai/regression/regression.nut Sun Apr 27 15:05:17 2008 +0000
+++ b/bin/ai/regression/regression.nut Tue Apr 29 21:06:16 2008 +0000
@@ -782,6 +782,8 @@
print(" IsValidStation(0): " + AIStation.IsValidStation(0));
print(" IsValidStation(1000): " + AIStation.IsValidStation(1000));
print(" GetName(0): " + AIStation.GetName(0));
+ print(" SetName(0): " + AIStation.SetName(0, "Look, a station"));
+ print(" GetName(0): " + AIStation.GetName(0));
print(" GetLocation(1): " + AIStation.GetLocation(1));
print(" GetLocation(1000): " + AIStation.GetLocation(1000));
print(" GetStationID(33411): " + AIStation.GetStationID(33411));
--- a/bin/ai/regression/regression.txt Sun Apr 27 15:05:17 2008 +0000
+++ b/bin/ai/regression/regression.txt Tue Apr 29 21:06:16 2008 +0000
@@ -5433,6 +5433,8 @@
IsValidStation(0): true
IsValidStation(1000): false
GetName(0): Benville Airport
+ SetName(0): true
+ GetName(0): Look, a station
GetLocation(1): 29253
GetLocation(1000): -1
GetStationID(33411): 2
@@ -6483,11 +6485,11 @@
IsValidSubsidy(): true
IsAwarded(): false
GetAwardedTo(): 9
- GetExpireDate(): 712647
+ GetExpireDate(): 712800
SourceIsTown(): true
- GetSource(): 24
+ GetSource(): 6
DestionationIsTown(): true
- GetDestionation(): 21
+ GetDestionation(): 15
GetCargoType(): 0
IsEventWaiting: false
ERROR: We've got a suicidal AI for player 1
--- a/src/ai/api/ai_station.cpp Sun Apr 27 15:05:17 2008 +0000
+++ b/src/ai/api/ai_station.cpp Tue Apr 29 21:06:16 2008 +0000
@@ -7,9 +7,11 @@
#include "ai_map.hpp"
#include "ai_town.hpp"
#include "../../openttd.h"
+#include "../../command_func.h"
#include "../../debug.h"
#include "../../station_map.h"
#include "../../variables.h"
+#include "../../string_func.h"
#include "../../strings_func.h"
#include "../../core/alloc_func.hpp"
#include "../../player_func.h"
@@ -39,6 +41,15 @@
return station_name;
}
+/* static */ bool AIStation::SetName(StationID station_id, const char *name)
+{
+ EnforcePrecondition(false, IsValidStation(station_id));
+ EnforcePrecondition(false, !::StrEmpty(name));
+
+ _cmd_text = name;
+ return AIObject::DoCommand(0, 0, station_id, CMD_RENAME_STATION);
+}
+
/* static */ TileIndex AIStation::GetLocation(StationID station_id)
{
if (!IsValidStation(station_id)) return INVALID_TILE;
--- a/src/ai/api/ai_station.hpp Sun Apr 27 15:05:17 2008 +0000
+++ b/src/ai/api/ai_station.hpp Tue Apr 29 21:06:16 2008 +0000
@@ -71,6 +71,16 @@
static char *GetName(StationID station_id);
/**
+ * Set the name this station.
+ * @param name The new name of the station.
+ * @pre IsValidStation(station_id).
+ * @pre 'name' must have at least one character.
+ * @exception AIError::ERR_NAME_IS_NOT_UNIQUE
+ * @return True if the name was changed.
+ */
+ static bool SetName(StationID station_id, const char *name);
+
+ /**
* 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 Apr 27 15:05:17 2008 +0000
+++ b/src/ai/api/ai_station.hpp.sq Tue Apr 29 21:06:16 2008 +0000
@@ -53,6 +53,7 @@
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::SetName, "SetName", 3, "xis");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetLocation, "GetLocation", 2, "xi");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCargoWaiting, "GetCargoWaiting", 3, "xii");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCargoRating, "GetCargoRating", 3, "xii");