(svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile noai
authortruelight
Sun, 15 Jul 2007 12:56:41 +0000
branchnoai
changeset 9666 5765eb70736d
parent 9665 e889ac1e663a
child 9667 053afa64f977
(svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
src/ai/api/ai_station.cpp
src/ai/api/ai_station.hpp
src/ai/api/ai_station.hpp.sq
--- a/bin/ai/regression/regression.nut	Sun Jul 15 12:36:43 2007 +0000
+++ b/bin/ai/regression/regression.nut	Sun Jul 15 12:56:41 2007 +0000
@@ -491,6 +491,8 @@
 	print("  IsValidStation(1000):     " + station.IsValidStation(1000));
 	print("  GetLocation(1):           " + station.GetLocation(1));
 	print("  GetLocation(1000):        " + station.GetLocation(1000));
+	print("  GetStationID(33411):      " + station.GetStationID(33411));
+	print("  GetStationID(34411):      " + station.GetStationID(34411));
 	print("  GetCargoWaiting(0, 0):    " + station.GetCargoWaiting(0, 0));
 	print("  GetCargoWaiting(1000, 0): " + station.GetCargoWaiting(1000, 0));
 	print("  GetCargoWaiting(0, 1000): " + station.GetCargoWaiting(0, 1000));
--- a/bin/ai/regression/regression.txt	Sun Jul 15 12:36:43 2007 +0000
+++ b/bin/ai/regression/regression.txt	Sun Jul 15 12:56:41 2007 +0000
@@ -1102,6 +1102,8 @@
   IsValidStation(1000):     false
   GetLocation(1):           33411
   GetLocation(1000):        -1
+  GetStationID(33411):      1
+  GetStationID(34411):      65535
   GetCargoWaiting(0, 0):    0
   GetCargoWaiting(1000, 0): -1
   GetCargoWaiting(0, 1000): -1
--- a/src/ai/api/ai_station.cpp	Sun Jul 15 12:36:43 2007 +0000
+++ b/src/ai/api/ai_station.cpp	Sun Jul 15 12:56:41 2007 +0000
@@ -5,12 +5,19 @@
 #include "ai_station.hpp"
 #include "ai_cargo.hpp"
 #include "../../station.h"
+#include "../../station_map.h"
 
 /* static */ bool AIStation::IsValidStation(StationID station_id)
 {
 	return ::IsValidStationID(station_id) && ::GetStation(station_id)->owner == _current_player;
 }
 
+/* static */ StationID AIStation::GetStationID(TileIndex tile)
+{
+	if (!::IsTileType(tile, MP_STATION)) return INVALID_STATION;
+	return ::GetStationIndex(tile);
+}
+
 /* static */ TileIndex AIStation::GetLocation(StationID station_id)
 {
 	if (!AIStation::IsValidStation(station_id)) return INVALID_TILE;
--- a/src/ai/api/ai_station.hpp	Sun Jul 15 12:36:43 2007 +0000
+++ b/src/ai/api/ai_station.hpp	Sun Jul 15 12:56:41 2007 +0000
@@ -25,6 +25,14 @@
 	static bool IsValidStation(StationID station_id);
 
 	/**
+	 * Get the stationID of a tile, if there is a station.
+	 * @param tile the tile to find the stationID of
+	 * @return StationID of the station.
+	 * @post use IsValidStation to see if the station is valid.
+	 */
+	static StationID GetStationID(TileIndex tile);
+
+	/**
 	 * 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 Jul 15 12:36:43 2007 +0000
+++ b/src/ai/api/ai_station.hpp.sq	Sun Jul 15 12:56:41 2007 +0000
@@ -15,6 +15,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::GetLocation,     "GetLocation",     2, "xi");
 	SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCargoWaiting, "GetCargoWaiting", 3, "xii");
 	SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCargoRating,  "GetCargoRating",  3, "xii");