# HG changeset patch
# Parent a43124a2d595dc1f05004db1716edbbb7b1dd672

diff -r a43124a2d595 src/ai/api/ai_airporttype.cpp
--- a/src/ai/api/ai_airporttype.cpp	Wed Sep 07 19:29:30 2011 +0200
+++ b/src/ai/api/ai_airporttype.cpp	Wed Sep 07 19:30:06 2011 +0200
@@ -53,6 +53,57 @@
 	return ::AirportSpec::Get(type)->size_y;
 }
 
+/* static */ int32 AIAirportType::GetNumHangars(AirportType type)
+{
+	if (!IsAirportTypeInformationAvailable(type)) return -1;
+
+	return ::AirportSpec::Get(type)->nof_depots;
+}
+
+/* static */ int32 AIAirportType::GetNumHelipads(AirportType type)
+{
+	if (!IsAirportTypeInformationAvailable(type)) return -1;
+
+	return ::AirportSpec::Get(type)->fsm->num_helipads;
+}
+
+/* static */ int32 AIAirportType::GetNumTerminals(AirportType type)
+{
+	if (!IsAirportTypeInformationAvailable(type)) return -1;
+
+	return ::GetNumTerminals(::AirportSpec::Get(type)->fsm);
+}
+
+/* static */ bool AIAirportType::CanPlaneTypeLand(AirportType type, AIAirportType::PlaneType plane_type)
+{
+	if (!IsAirportTypeInformationAvailable(type)) return false;
+	if (!IsValidPlaneType(plane_type)) return false;
+
+	/* Get the FTA flags */
+	AirportFTAClass::Flags fta_flags = ::AirportSpec::Get(type)->fsm->flags;	
+
+	switch(plane_type)
+	{
+		case PT_SMALL_PLANE:
+			/* FALL THROUGH */
+		case PT_BIG_PLANE:
+			return (fta_flags & AirportFTAClass::AIRPLANES) != 0;
+
+		case PT_HELICOPTER:
+			return (fta_flags & AirportFTAClass::HELICOPTERS) != 0;
+
+		default:
+			NOT_REACHED();
+	};
+}
+
+/* static */ bool AIAirportType::IsLandingExtraDangerous(AirportType type, AIAirportType::PlaneType plane_type)
+{
+	if (!IsAirportTypeInformationAvailable(type)) return false;
+
+	return plane_type == PT_BIG_PLANE && (::AirportSpec::Get(type)->fsm->flags & AirportFTAClass::SHORT_STRIP) != 0;
+}
+
 /* static */ int32 AIAirportType::GetAirportCoverageRadius(AirportType type)
 {
 	if (!IsAirportTypeInformationAvailable(type)) return -1;
diff -r a43124a2d595 src/ai/api/ai_airporttype.hpp
--- a/src/ai/api/ai_airporttype.hpp	Wed Sep 07 19:29:30 2011 +0200
+++ b/src/ai/api/ai_airporttype.hpp	Wed Sep 07 19:30:06 2011 +0200
@@ -84,6 +84,53 @@
 	static int32 GetAirportHeight(AirportType type);
 
 	/**
+	 * Get the number of hangars of the given airport type.
+	 * @param type The type of airport.
+	 * @pre IsAirportTypeInformationAvailable(type).
+	 * @return The number of hangars.
+	 */
+	static int32 GetNumHangars(AirportType type);
+
+	/**
+	 * Get the number of helipads of the given airport type.
+	 * @param type The type of airport.
+	 * @pre IsAirportTypeInformationAvailable(type).
+	 * @return The number of helipads.
+	 */
+	static int32 GetNumHelipads(AirportType type);
+
+	/**
+	 * Get the number of terminals of the given airport type.
+	 * @param type The type of airport.
+	 * @pre IsAirportTypeInformationAvailable(type).
+	 * @return The number of terminals.
+	 */
+	static int32 GetNumTerminals(AirportType type);
+
+	/**
+	 * Check if a plane type can land on a airport type
+	 * @param type The type of airport.
+	 * @param plane_type The plane type.
+	 * @pre IsAirportTypeInformationAvailable(type).
+	 * @pre IsValidPlaneType(plane_type).
+	 * @return True if and only if the given plane type can land on the given airport type.
+	 */
+	static bool CanPlaneTypeLand(AirportType type, PlaneType plane_type);
+
+	/**
+	 * Check if landing on the given airport type is extra dangerous for a given plane type. 
+	 * Extra dangerous airport and plane type combinations increase the chance that the 
+	 * airplane will crash on landing.
+	 * @param type The type of airport.
+	 * @param plane_type The plane type.
+	 * @pre IsAirportTypeInformationAvailable(type).
+	 * @pre IsValidPlaneType(plane_type).
+	 * @pre CanPlaneTypeLand(type, plane_type)
+	 * @return True if and only if the given plane type has a higher crash chance than usual when landing on the given airport type.
+	 */
+	static bool IsLandingExtraDangerous(AirportType type, PlaneType plane_type);
+
+	/**
 	 * Get the coverage radius of this type of airport.
 	 * @param type The type of airport.
 	 * @pre IsAirportTypeInformationAvailable(type).
diff -r a43124a2d595 src/ai/api/ai_airporttype.hpp.sq
--- a/src/ai/api/ai_airporttype.hpp.sq	Wed Sep 07 19:29:30 2011 +0200
+++ b/src/ai/api/ai_airporttype.hpp.sq	Wed Sep 07 19:30:06 2011 +0200
@@ -41,6 +41,11 @@
 	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::GetPrice,                          "GetPrice",                          2, ".i");
 	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::GetAirportWidth,                   "GetAirportWidth",                   2, ".i");
 	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::GetAirportHeight,                  "GetAirportHeight",                  2, ".i");
+	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::GetNumHangars,                     "GetNumHangars",                     2, ".i");
+	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::GetNumHelipads,                    "GetNumHelipads",                    2, ".i");
+	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::GetNumTerminals,                   "GetNumTerminals",                   2, ".i");
+	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::CanPlaneTypeLand,                  "CanPlaneTypeLand",                  3, ".ii");
+	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::IsLandingExtraDangerous,           "IsLandingExtraDangerous",           3, ".ii");
 	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::GetAirportCoverageRadius,          "GetAirportCoverageRadius",          2, ".i");
 	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::GetNoiseLevelIncrease,             "GetNoiseLevelIncrease",             3, ".ii");
 	SQAIAirportType.DefSQStaticMethod(engine, &AIAirportType::GetNearestTown,                    "GetNearestTown",                    3, ".ii");
diff -r a43124a2d595 src/aircraft_cmd.cpp
--- a/src/aircraft_cmd.cpp	Wed Sep 07 19:29:30 2011 +0200
+++ b/src/aircraft_cmd.cpp	Wed Sep 07 19:30:06 2011 +0200
@@ -1754,8 +1754,11 @@
  * @param afc Airport description.
  * @return Number of terminals.
  */
-static uint GetNumTerminals(const AirportFTAClass *apc)
+uint GetNumTerminals(const AirportFTAClass *apc)
 {
+	/* Handle the case when there are no terminals (eg. a helicopter only airport) */
+	if (apc->terminals == 0) return 0;
+
 	uint num = 0;
 
 	for (uint i = apc->terminals[0]; i > 0; i--) num += apc->terminals[i];
diff -r a43124a2d595 src/airport.h
--- a/src/airport.h	Wed Sep 07 19:29:30 2011 +0200
+++ b/src/airport.h	Wed Sep 07 19:30:06 2011 +0200
@@ -194,5 +194,6 @@
 
 const AirportFTAClass *GetAirport(const byte airport_type);
 byte GetVehiclePosOnBuild(TileIndex hangar_tile);
+uint GetNumTerminals(const AirportFTAClass *apc);
 
 #endif /* AIRPORT_H */
