# HG changeset patch # User truelight # Date 1184504201 0 # Node ID 5765eb70736dd90215e34804aff13e318c5798cd # Parent e889ac1e663aafba52da90d189887ce0b614e063 (svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile diff -r e889ac1e663a -r 5765eb70736d bin/ai/regression/regression.nut --- 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)); diff -r e889ac1e663a -r 5765eb70736d bin/ai/regression/regression.txt --- 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 diff -r e889ac1e663a -r 5765eb70736d src/ai/api/ai_station.cpp --- 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; diff -r e889ac1e663a -r 5765eb70736d src/ai/api/ai_station.hpp --- 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). diff -r e889ac1e663a -r 5765eb70736d src/ai/api/ai_station.hpp.sq --- 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");