# HG changeset patch # User yexo # Date 2009-05-07 21:30:18 # Node ID cdcc1e5aa2fb9338062eba14f0a0c82f59b066c2 # Parent 41f2823b0f67f5d151b9c4a7091c3b3a06726780 (svn r16252) -Add [NoAI]: AIAirport::GetPrice, returning the building cost of an airport diff --git a/bin/ai/regression/regression.nut b/bin/ai/regression/regression.nut --- a/bin/ai/regression/regression.nut +++ b/bin/ai/regression/regression.nut @@ -220,6 +220,7 @@ function Regression::Airport() } print(" GetBankBalance(): " + AICompany.GetBankBalance(AICompany.COMPANY_SELF)); + print(" GetPrice(): " + AIAirport.GetPrice(0)); print(" BuildAirport(): " + AIAirport.BuildAirport(32116, 0, AIStation.STATION_JOIN_ADJACENT)); print(" IsHangarTile(): " + AIAirport.IsHangarTile(32116)); print(" IsAirportTile(): " + AIAirport.IsAirportTile(32116)); diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -620,6 +620,7 @@ GetAirportHeight(9): -1 GetAirportCoverageRadius(9): -1 GetBankBalance(): 100000 + GetPrice(): 84 BuildAirport(): true IsHangarTile(): false IsAirportTile(): true diff --git a/src/ai/api/ai_airport.cpp b/src/ai/api/ai_airport.cpp --- 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 --- a/src/ai/api/ai_airport.hpp +++ b/src/ai/api/ai_airport.hpp @@ -54,6 +54,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. * @pre AIMap::IsValidTile(tile). diff --git a/src/ai/api/ai_airport.hpp.sq b/src/ai/api/ai_airport.hpp.sq --- a/src/ai/api/ai_airport.hpp.sq +++ b/src/ai/api/ai_airport.hpp.sq @@ -39,6 +39,7 @@ void SQAIAirport_Register(Squirrel *engi 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");