diff options
author | yexo <yexo@openttd.org> | 2009-09-20 18:38:43 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2009-09-20 18:38:43 +0000 |
commit | 12ef0046dde205e0e111ed7e6d830ea4f93c45c9 (patch) | |
tree | 725c12c7662b29bea2b46b1ed10469a1fa44947c /src/ai/api | |
parent | 64ed7cc8de1dd551e9222119ec75465371494f3b (diff) | |
download | openttd-12ef0046dde205e0e111ed7e6d830ea4f93c45c9.tar.xz |
(svn r17591) -Add [NoAI] [FS#3212]: AIAirport::IsAirportInformationAvailable. Also update several preconditions so it's now possible to get information on airports types that can no longer be build (small airport after 1960)
Diffstat (limited to 'src/ai/api')
-rw-r--r-- | src/ai/api/ai_airport.cpp | 15 | ||||
-rw-r--r-- | src/ai/api/ai_airport.hpp | 16 | ||||
-rw-r--r-- | src/ai/api/ai_airport.hpp.sq | 29 |
3 files changed, 41 insertions, 19 deletions
diff --git a/src/ai/api/ai_airport.cpp b/src/ai/api/ai_airport.cpp index 3ddb4666d..d3a5f90b6 100644 --- a/src/ai/api/ai_airport.cpp +++ b/src/ai/api/ai_airport.cpp @@ -19,7 +19,12 @@ /* static */ bool AIAirport::IsValidAirportType(AirportType type) { - return type >= 0 && type < (AirportType)NUM_AIRPORTS && ::GetAirport(type)->IsAvailable(); + return IsAirportInformationAvailable(type) && ::GetAirport(type)->IsAvailable(); +} + +/* static */ bool AIAirport::IsAirportInformationAvailable(AirportType type) +{ + return type >= 0 && type < (AirportType)NUM_AIRPORTS; } /* static */ Money AIAirport::GetPrice(AirportType type) @@ -46,21 +51,21 @@ /* static */ int32 AIAirport::GetAirportWidth(AirportType type) { - if (!IsValidAirportType(type)) return -1; + if (!IsAirportInformationAvailable(type)) return -1; return ::GetAirport(type)->size_x; } /* static */ int32 AIAirport::GetAirportHeight(AirportType type) { - if (!IsValidAirportType(type)) return -1; + if (!IsAirportInformationAvailable(type)) return -1; return ::GetAirport(type)->size_y; } /* static */ int32 AIAirport::GetAirportCoverageRadius(AirportType type) { - if (!IsValidAirportType(type)) return -1; + if (!IsAirportInformationAvailable(type)) return -1; return _settings_game.station.modified_catchment ? ::GetAirport(type)->catchment : (uint)CA_UNMODIFIED; } @@ -143,7 +148,7 @@ extern Town *AirportGetNearestTown(const AirportFTAClass *afc, TileIndex airport_tile); if (!::IsValidTile(tile)) return INVALID_TOWN; - if (!IsValidAirportType(type)) return INVALID_TOWN; + if (!IsAirportInformationAvailable(type)) return INVALID_TOWN; return AirportGetNearestTown(GetAirport(type), tile)->index; } diff --git a/src/ai/api/ai_airport.hpp b/src/ai/api/ai_airport.hpp index 344cec64a..f0c52bc45 100644 --- a/src/ai/api/ai_airport.hpp +++ b/src/ai/api/ai_airport.hpp @@ -57,12 +57,24 @@ public: * Checks whether the given AirportType is valid and available. * @param type The AirportType to check. * @return True if and only if the AirportType is valid and available. + * @post return value == true -> IsAirportInformationAvailable returns true. */ static bool IsValidAirportType(AirportType type); /** + * Can you get information on this airport type? As opposed to + * IsValidAirportType this will return also return true when + * an airport type is no longer buildable. + * @param type The AirportType to check. + * @return True if and only if the AirportType is valid. + * @post return value == false -> IsValidAirportType returns false. + */ + static bool IsAirportInformationAvailable(AirportType type); + + /** * Get the cost to build this AirportType. * @param type The AirportType to check. + * @pre AirportAvailable(type). * @return The cost of building this AirportType. */ static Money GetPrice(AirportType type); @@ -86,6 +98,7 @@ public: /** * Get the width of this type of airport. * @param type The type of airport. + * @pre IsAirportInformationAvailable(type). * @return The width in tiles. */ static int32 GetAirportWidth(AirportType type); @@ -93,6 +106,7 @@ public: /** * Get the height of this type of airport. * @param type The type of airport. + * @pre IsAirportInformationAvailable(type). * @return The height in tiles. */ static int32 GetAirportHeight(AirportType type); @@ -100,6 +114,7 @@ public: /** * Get the coverage radius of this type of airport. * @param type The type of airport. + * @pre IsAirportInformationAvailable(type). * @return The radius in tiles. */ static int32 GetAirportCoverageRadius(AirportType type); @@ -174,6 +189,7 @@ public: * an airport at some tile. * @param tile The tile to check. * @param type The AirportType to check. + * @pre IsAirportInformationAvailable(type). * @return The TownID of the town closest to the tile. */ static TownID GetNearestTown(TileIndex tile, AirportType type); diff --git a/src/ai/api/ai_airport.hpp.sq b/src/ai/api/ai_airport.hpp.sq index a63dee040..dd98768f3 100644 --- a/src/ai/api/ai_airport.hpp.sq +++ b/src/ai/api/ai_airport.hpp.sq @@ -46,20 +46,21 @@ void SQAIAirport_Register(Squirrel *engine) { SQAIAirport.DefSQConst(engine, AIAirport::PT_BIG_PLANE, "PT_BIG_PLANE"); 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"); - SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportHeight, "GetAirportHeight", 2, ".i"); - SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportCoverageRadius, "GetAirportCoverageRadius", 2, ".i"); - SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNumHangars, "GetNumHangars", 2, ".i"); - SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetHangarOfAirport, "GetHangarOfAirport", 2, ".i"); - SQAIAirport.DefSQStaticMethod(engine, &AIAirport::BuildAirport, "BuildAirport", 4, ".iii"); - SQAIAirport.DefSQStaticMethod(engine, &AIAirport::RemoveAirport, "RemoveAirport", 2, ".i"); - SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportType, "GetAirportType", 2, ".i"); - SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNoiseLevelIncrease, "GetNoiseLevelIncrease", 3, ".ii"); - SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNearestTown, "GetNearestTown", 3, ".ii"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsValidAirportType, "IsValidAirportType", 2, ".i"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsAirportInformationAvailable, "IsAirportInformationAvailable", 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"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportHeight, "GetAirportHeight", 2, ".i"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportCoverageRadius, "GetAirportCoverageRadius", 2, ".i"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNumHangars, "GetNumHangars", 2, ".i"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetHangarOfAirport, "GetHangarOfAirport", 2, ".i"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::BuildAirport, "BuildAirport", 4, ".iii"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::RemoveAirport, "RemoveAirport", 2, ".i"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportType, "GetAirportType", 2, ".i"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNoiseLevelIncrease, "GetNoiseLevelIncrease", 3, ".ii"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNearestTown, "GetNearestTown", 3, ".ii"); SQAIAirport.PostRegister(engine); } |