From 9b4a32deb41a33ea1a83ee1f14256e087460e1e5 Mon Sep 17 00:00:00 2001 From: yexo Date: Thu, 7 May 2009 21:30:18 +0000 Subject: (svn r16252) -Add [NoAI]: AIAirport::GetPrice, returning the building cost of an airport --- src/ai/api/ai_airport.cpp | 9 +++++++++ src/ai/api/ai_airport.hpp | 7 +++++++ src/ai/api/ai_airport.hpp.sq | 1 + 3 files changed, 17 insertions(+) (limited to 'src/ai') diff --git a/src/ai/api/ai_airport.cpp b/src/ai/api/ai_airport.cpp index ed58701c3..819880f97 100644 --- a/src/ai/api/ai_airport.cpp +++ b/src/ai/api/ai_airport.cpp @@ -8,12 +8,21 @@ #include "../../company_func.h" #include "../../command_type.h" #include "../../town.h" +#include "../../economy_func.h" /* static */ bool AIAirport::IsValidAirportType(AirportType type) { return type >= AT_SMALL && type <= AT_HELISTATION && HasBit(::GetValidAirports(), type); } +/* static */ Money AIAirport::GetPrice(AirportType type) +{ + if (!IsValidAirportType(type)) return -1; + + const AirportFTAClass *afc = ::GetAirport(type); + return _price.build_airport * afc->size_x * afc->size_y; +} + /* static */ bool AIAirport::IsHangarTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; diff --git a/src/ai/api/ai_airport.hpp b/src/ai/api/ai_airport.hpp index 245661364..e4541edf6 100644 --- a/src/ai/api/ai_airport.hpp +++ b/src/ai/api/ai_airport.hpp @@ -53,6 +53,13 @@ public: */ static bool IsValidAirportType(AirportType type); + /** + * Get the cost to build this AirportType. + * @param type The AirportType to check. + * @return The cost of building this AirportType. + */ + static Money GetPrice(AirportType type); + /** * Checks whether the given tile is actually a tile with a hangar. * @param tile The tile to check. diff --git a/src/ai/api/ai_airport.hpp.sq b/src/ai/api/ai_airport.hpp.sq index 0a42aa2d7..3825c29ae 100644 --- a/src/ai/api/ai_airport.hpp.sq +++ b/src/ai/api/ai_airport.hpp.sq @@ -39,6 +39,7 @@ void SQAIAirport_Register(Squirrel *engine) { SQAIAirport.DefSQConst(engine, AIAirport::PT_INVALID, "PT_INVALID"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsValidAirportType, "IsValidAirportType", 2, ".i"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetPrice, "GetPrice", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsHangarTile, "IsHangarTile", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsAirportTile, "IsAirportTile", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportWidth, "GetAirportWidth", 2, ".i"); -- cgit v1.2.3-70-g09d2