(svn r13414) [NoAI] -Add: added AIStation::HasStationType(station_id, station_type) to check if a given station has a given station-type noai
authortruebrain
Sun, 08 Jun 2008 12:45:11 +0000
branchnoai
changeset 10863 7b31d67e1553
parent 10859 4c14a8041c0a
child 10864 9a6616a1dce6
(svn r13414) [NoAI] -Add: added AIStation::HasStationType(station_id, station_type) to check if a given station has a given station-type
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 Jun 08 10:37:30 2008 +0000
+++ b/bin/ai/regression/regression.nut	Sun Jun 08 12:45:11 2008 +0000
@@ -820,10 +820,12 @@
 	print("  HasRoadType(3, ROAD):     " + AIStation.HasRoadType(3, AIRoad.ROADTYPE_ROAD));
 	print("  HasRoadType(33411, TRAM): " + AIRoad.HasRoadType(33411, AIRoad.ROADTYPE_TRAM));
 	print("  HasRoadType(33411, ROAD): " + AIRoad.HasRoadType(33411, AIRoad.ROADTYPE_ROAD));
+	print("  HasStationType(3, BUS):   " + AIStation.HasStationType(3, AIStation.STATION_BUS_STOP));
+	print("  HasStationType(3, TRAIN): " + AIStation.HasStationType(3, AIStation.STATION_TRAIN));
 
-	print("  GetCoverageRadius(bus):   " + AIStation.GetCoverageRadius(AIStation.STATION_BUS_STOP));
-	print("  GetCoverageRadius(truck): " + AIStation.GetCoverageRadius(AIStation.STATION_TRUCK_STOP));
-	print("  GetCoverageRadius(train): " + AIStation.GetCoverageRadius(AIStation.STATION_TRAIN));
+	print("  GetCoverageRadius(BUS):   " + AIStation.GetCoverageRadius(AIStation.STATION_BUS_STOP));
+	print("  GetCoverageRadius(TRUCK): " + AIStation.GetCoverageRadius(AIStation.STATION_TRUCK_STOP));
+	print("  GetCoverageRadius(TRAIN): " + AIStation.GetCoverageRadius(AIStation.STATION_TRAIN));
 
 	local list = AIStationList(AIStation.STATION_BUS_STOP + AIStation.STATION_TRUCK_STOP);
 
--- a/bin/ai/regression/regression.txt	Sun Jun 08 10:37:30 2008 +0000
+++ b/bin/ai/regression/regression.txt	Sun Jun 08 12:45:11 2008 +0000
@@ -5830,9 +5830,11 @@
   HasRoadType(3, ROAD):     true
   HasRoadType(33411, TRAM): false
   HasRoadType(33411, ROAD): true
-  GetCoverageRadius(bus):   3
-  GetCoverageRadius(truck): 3
-  GetCoverageRadius(train): 4
+  HasStationType(3, BUS):   true
+  HasStationType(3, TRAIN): false
+  GetCoverageRadius(BUS):   3
+  GetCoverageRadius(TRUCK): 3
+  GetCoverageRadius(TRAIN): 4
 
 --StationList--
   Count():             2
--- a/src/ai/api/ai_station.cpp	Sun Jun 08 10:37:30 2008 +0000
+++ b/src/ai/api/ai_station.cpp	Sun Jun 08 12:45:11 2008 +0000
@@ -73,15 +73,16 @@
 	return ::GetStation(station_id)->goods[cargo_id].rating * 101 >> 8;
 }
 
-/* static */ int32 AIStation::GetCoverageRadius(AIStation::StationType type)
+/* static */ int32 AIStation::GetCoverageRadius(AIStation::StationType station_type)
 {
-	if (type == STATION_AIRPORT) {
+	if (station_type == STATION_AIRPORT) {
 		DEBUG(ai, 0, "GetCoverageRadius(): coverage radius of airports needs to be requested via AIAirport::GetAirportCoverageRadius(), as it requires AirportType");
 		return -1;
 	}
+	if (CountBits(station_type) != 1) return -1;
 	if (!_settings_game.station.modified_catchment) return CA_UNMODIFIED;
 
-	switch (type) {
+	switch (station_type) {
 		case STATION_TRAIN:      return CA_TRAIN;
 		case STATION_TRUCK_STOP: return CA_TRUCK;
 		case STATION_BUS_STOP:   return CA_BUS;
@@ -111,6 +112,14 @@
 	return AITown::IsWithinTownInfluence(town_id, GetLocation(station_id));
 }
 
+/* static */ bool AIStation::HasStationType(StationID station_id, StationType station_type)
+{
+	if (!IsValidStation(station_id)) return false;
+	if (CountBits(station_type) != 1) return false;
+
+	return (::GetStation(station_id)->facilities & station_type) != 0;
+}
+
 /* static */ bool AIStation::HasRoadType(StationID station_id, AIRoad::RoadType road_type)
 {
 	if (!IsValidStation(station_id)) return false;
--- a/src/ai/api/ai_station.hpp	Sun Jun 08 10:37:30 2008 +0000
+++ b/src/ai/api/ai_station.hpp	Sun Jun 08 12:45:11 2008 +0000
@@ -115,7 +115,7 @@
 	 * @param type The type of station.
 	 * @return The radius in tiles.
 	 */
-	static int32 GetCoverageRadius(AIStation::StationType type);
+	static int32 GetCoverageRadius(AIStation::StationType station_type);
 
 	/**
 	 * Get the manhattan distance from the tile to the AIStation::GetLocation()
@@ -148,6 +148,15 @@
 
 	/**
 	 * Check if any part of the station contains a station of the type
+	 *  StationType
+	 * @param station_id The station to look at.
+	 * @param station_type The StationType to look for.
+	 * @return True if the station has a station part of the type StationType.
+	 */
+	static bool HasStationType(StationID station_id, StationType station_type);
+
+	/**
+	 * Check if any part of the station contains a station of the type
 	 *  RoadType.
 	 * @param station_id The station to look at.
 	 * @param road_type The RoadType to look for.
--- a/src/ai/api/ai_station.hpp.sq	Sun Jun 08 10:37:30 2008 +0000
+++ b/src/ai/api/ai_station.hpp.sq	Sun Jun 08 12:45:11 2008 +0000
@@ -61,6 +61,7 @@
 	SQAIStation.DefSQStaticMethod(engine, &AIStation::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, "xii");
 	SQAIStation.DefSQStaticMethod(engine, &AIStation::GetDistanceSquareToTile,    "GetDistanceSquareToTile",    3, "xii");
 	SQAIStation.DefSQStaticMethod(engine, &AIStation::IsWithinTownInfluence,      "IsWithinTownInfluence",      3, "xii");
+	SQAIStation.DefSQStaticMethod(engine, &AIStation::HasStationType,             "HasStationType",             3, "xii");
 	SQAIStation.DefSQStaticMethod(engine, &AIStation::HasRoadType,                "HasRoadType",                3, "xii");
 
 	SQAIStation.PostRegister(engine);