(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)

This commit is contained in:
yexo 2009-09-20 18:38:43 +00:00
parent 64ed7cc8de
commit 12ef0046dd
5 changed files with 101 additions and 67 deletions

View File

@ -213,10 +213,11 @@ function Regression::Airport()
print(" GetAirportType(): " + AIAirport.GetAirportType(32116)); print(" GetAirportType(): " + AIAirport.GetAirportType(32116));
for (local i = -1; i < 10; i++) { for (local i = -1; i < 10; i++) {
print(" IsValidAirportType(" + i + "): " + AIAirport.IsValidAirportType(i)); print(" IsAirportInformationAvailable(" + i + "): " + AIAirport.IsAirportInformationAvailable(i));
print(" GetAirportWidth(" + i + "): " + AIAirport.GetAirportWidth(i)); print(" IsValidAirportType(" + i + "): " + AIAirport.IsValidAirportType(i));
print(" GetAirportHeight(" + i + "): " + AIAirport.GetAirportHeight(i)); print(" GetAirportWidth(" + i + "): " + AIAirport.GetAirportWidth(i));
print(" GetAirportCoverageRadius(" + i + "): " + AIAirport.GetAirportCoverageRadius(i)); print(" GetAirportHeight(" + i + "): " + AIAirport.GetAirportHeight(i));
print(" GetAirportCoverageRadius(" + i + "): " + AIAirport.GetAirportCoverageRadius(i));
} }
print(" GetBankBalance(): " + AICompany.GetBankBalance(AICompany.COMPANY_SELF)); print(" GetBankBalance(): " + AICompany.GetBankBalance(AICompany.COMPANY_SELF));

View File

@ -626,50 +626,61 @@
IsAirportTile(): false IsAirportTile(): false
GetHangarOfAirport(): -1 GetHangarOfAirport(): -1
GetAirportType(): 255 GetAirportType(): 255
IsValidAirportType(-1): false IsAirportInformationAvailable(-1): false
GetAirportWidth(-1): -1 IsValidAirportType(-1): false
GetAirportHeight(-1): -1 GetAirportWidth(-1): -1
GetAirportCoverageRadius(-1): -1 GetAirportHeight(-1): -1
IsValidAirportType(0): true GetAirportCoverageRadius(-1): -1
GetAirportWidth(0): 4 IsAirportInformationAvailable(0): true
GetAirportHeight(0): 3 IsValidAirportType(0): true
GetAirportCoverageRadius(0): 4 GetAirportWidth(0): 4
IsValidAirportType(1): false GetAirportHeight(0): 3
GetAirportWidth(1): -1 GetAirportCoverageRadius(0): 4
GetAirportHeight(1): -1 IsAirportInformationAvailable(1): true
GetAirportCoverageRadius(1): -1 IsValidAirportType(1): false
IsValidAirportType(2): false GetAirportWidth(1): 6
GetAirportWidth(2): -1 GetAirportHeight(1): 6
GetAirportHeight(2): -1 GetAirportCoverageRadius(1): 5
GetAirportCoverageRadius(2): -1 IsAirportInformationAvailable(2): true
IsValidAirportType(3): false IsValidAirportType(2): false
GetAirportWidth(3): -1 GetAirportWidth(2): 1
GetAirportHeight(3): -1 GetAirportHeight(2): 1
GetAirportCoverageRadius(3): -1 GetAirportCoverageRadius(2): 4
IsValidAirportType(4): false IsAirportInformationAvailable(3): true
GetAirportWidth(4): -1 IsValidAirportType(3): false
GetAirportHeight(4): -1 GetAirportWidth(3): 6
GetAirportCoverageRadius(4): -1 GetAirportHeight(3): 6
IsValidAirportType(5): false GetAirportCoverageRadius(3): 6
GetAirportWidth(5): -1 IsAirportInformationAvailable(4): true
GetAirportHeight(5): -1 IsValidAirportType(4): false
GetAirportCoverageRadius(5): -1 GetAirportWidth(4): 7
IsValidAirportType(6): false GetAirportHeight(4): 7
GetAirportWidth(6): -1 GetAirportCoverageRadius(4): 8
GetAirportHeight(6): -1 IsAirportInformationAvailable(5): true
GetAirportCoverageRadius(6): -1 IsValidAirportType(5): false
IsValidAirportType(7): false GetAirportWidth(5): 5
GetAirportWidth(7): -1 GetAirportHeight(5): 4
GetAirportHeight(7): -1 GetAirportCoverageRadius(5): 4
GetAirportCoverageRadius(7): -1 IsAirportInformationAvailable(6): true
IsValidAirportType(8): false IsValidAirportType(6): false
GetAirportWidth(8): -1 GetAirportWidth(6): 2
GetAirportHeight(8): -1 GetAirportHeight(6): 2
GetAirportCoverageRadius(8): -1 GetAirportCoverageRadius(6): 4
IsValidAirportType(9): false IsAirportInformationAvailable(7): true
GetAirportWidth(9): -1 IsValidAirportType(7): false
GetAirportHeight(9): -1 GetAirportWidth(7): 9
GetAirportCoverageRadius(9): -1 GetAirportHeight(7): 11
GetAirportCoverageRadius(7): 10
IsAirportInformationAvailable(8): true
IsValidAirportType(8): false
GetAirportWidth(8): 4
GetAirportHeight(8): 2
GetAirportCoverageRadius(8): 4
IsAirportInformationAvailable(9): false
IsValidAirportType(9): false
GetAirportWidth(9): -1
GetAirportHeight(9): -1
GetAirportCoverageRadius(9): -1
GetBankBalance(): 1999999790 GetBankBalance(): 1999999790
GetPrice(): 5400 GetPrice(): 5400
BuildAirport(): true BuildAirport(): true

View File

@ -19,7 +19,12 @@
/* static */ bool AIAirport::IsValidAirportType(AirportType type) /* 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) /* static */ Money AIAirport::GetPrice(AirportType type)
@ -46,21 +51,21 @@
/* static */ int32 AIAirport::GetAirportWidth(AirportType type) /* static */ int32 AIAirport::GetAirportWidth(AirportType type)
{ {
if (!IsValidAirportType(type)) return -1; if (!IsAirportInformationAvailable(type)) return -1;
return ::GetAirport(type)->size_x; return ::GetAirport(type)->size_x;
} }
/* static */ int32 AIAirport::GetAirportHeight(AirportType type) /* static */ int32 AIAirport::GetAirportHeight(AirportType type)
{ {
if (!IsValidAirportType(type)) return -1; if (!IsAirportInformationAvailable(type)) return -1;
return ::GetAirport(type)->size_y; return ::GetAirport(type)->size_y;
} }
/* static */ int32 AIAirport::GetAirportCoverageRadius(AirportType type) /* 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; 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); extern Town *AirportGetNearestTown(const AirportFTAClass *afc, TileIndex airport_tile);
if (!::IsValidTile(tile)) return INVALID_TOWN; if (!::IsValidTile(tile)) return INVALID_TOWN;
if (!IsValidAirportType(type)) return INVALID_TOWN; if (!IsAirportInformationAvailable(type)) return INVALID_TOWN;
return AirportGetNearestTown(GetAirport(type), tile)->index; return AirportGetNearestTown(GetAirport(type), tile)->index;
} }

View File

@ -57,12 +57,24 @@ public:
* Checks whether the given AirportType is valid and available. * Checks whether the given AirportType is valid and available.
* @param type The AirportType to check. * @param type The AirportType to check.
* @return True if and only if the AirportType is valid and available. * @return True if and only if the AirportType is valid and available.
* @post return value == true -> IsAirportInformationAvailable returns true.
*/ */
static bool IsValidAirportType(AirportType type); 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. * Get the cost to build this AirportType.
* @param type The AirportType to check. * @param type The AirportType to check.
* @pre AirportAvailable(type).
* @return The cost of building this AirportType. * @return The cost of building this AirportType.
*/ */
static Money GetPrice(AirportType type); static Money GetPrice(AirportType type);
@ -86,6 +98,7 @@ public:
/** /**
* Get the width of this type of airport. * Get the width of this type of airport.
* @param type The type of airport. * @param type The type of airport.
* @pre IsAirportInformationAvailable(type).
* @return The width in tiles. * @return The width in tiles.
*/ */
static int32 GetAirportWidth(AirportType type); static int32 GetAirportWidth(AirportType type);
@ -93,6 +106,7 @@ public:
/** /**
* Get the height of this type of airport. * Get the height of this type of airport.
* @param type The type of airport. * @param type The type of airport.
* @pre IsAirportInformationAvailable(type).
* @return The height in tiles. * @return The height in tiles.
*/ */
static int32 GetAirportHeight(AirportType type); static int32 GetAirportHeight(AirportType type);
@ -100,6 +114,7 @@ public:
/** /**
* Get the coverage radius of this type of airport. * Get the coverage radius of this type of airport.
* @param type The type of airport. * @param type The type of airport.
* @pre IsAirportInformationAvailable(type).
* @return The radius in tiles. * @return The radius in tiles.
*/ */
static int32 GetAirportCoverageRadius(AirportType type); static int32 GetAirportCoverageRadius(AirportType type);
@ -174,6 +189,7 @@ public:
* an airport at some tile. * an airport at some tile.
* @param tile The tile to check. * @param tile The tile to check.
* @param type The AirportType to check. * @param type The AirportType to check.
* @pre IsAirportInformationAvailable(type).
* @return The TownID of the town closest to the tile. * @return The TownID of the town closest to the tile.
*/ */
static TownID GetNearestTown(TileIndex tile, AirportType type); static TownID GetNearestTown(TileIndex tile, AirportType type);

View File

@ -46,20 +46,21 @@ void SQAIAirport_Register(Squirrel *engine) {
SQAIAirport.DefSQConst(engine, AIAirport::PT_BIG_PLANE, "PT_BIG_PLANE"); SQAIAirport.DefSQConst(engine, AIAirport::PT_BIG_PLANE, "PT_BIG_PLANE");
SQAIAirport.DefSQConst(engine, AIAirport::PT_INVALID, "PT_INVALID"); SQAIAirport.DefSQConst(engine, AIAirport::PT_INVALID, "PT_INVALID");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsValidAirportType, "IsValidAirportType", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsValidAirportType, "IsValidAirportType", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetPrice, "GetPrice", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsAirportInformationAvailable, "IsAirportInformationAvailable", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsHangarTile, "IsHangarTile", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetPrice, "GetPrice", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsAirportTile, "IsAirportTile", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsHangarTile, "IsHangarTile", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportWidth, "GetAirportWidth", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::IsAirportTile, "IsAirportTile", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportHeight, "GetAirportHeight", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportWidth, "GetAirportWidth", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportCoverageRadius, "GetAirportCoverageRadius", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportHeight, "GetAirportHeight", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNumHangars, "GetNumHangars", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportCoverageRadius, "GetAirportCoverageRadius", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetHangarOfAirport, "GetHangarOfAirport", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNumHangars, "GetNumHangars", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::BuildAirport, "BuildAirport", 4, ".iii"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetHangarOfAirport, "GetHangarOfAirport", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::RemoveAirport, "RemoveAirport", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::BuildAirport, "BuildAirport", 4, ".iii");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportType, "GetAirportType", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::RemoveAirport, "RemoveAirport", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNoiseLevelIncrease, "GetNoiseLevelIncrease", 3, ".ii"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportType, "GetAirportType", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNearestTown, "GetNearestTown", 3, ".ii"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNoiseLevelIncrease, "GetNoiseLevelIncrease", 3, ".ii");
SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNearestTown, "GetNearestTown", 3, ".ii");
SQAIAirport.PostRegister(engine); SQAIAirport.PostRegister(engine);
} }