From 96f279608beda2113b10cf1cb9717954fd1ff329 Mon Sep 17 00:00:00 2001 From: Yexo Date: Thu, 5 Feb 2009 01:15:54 +0000 Subject: (svn r15346) -Add [NoAI]: Add AIAirport::GetNearestTown() so AIs can known in which town the noise level will increase. --- src/ai/api/ai_airport.cpp | 10 ++++++++++ src/ai/api/ai_airport.hpp | 13 +++++++++++-- src/ai/api/ai_airport.hpp.sq | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ai/api/ai_airport.cpp b/src/ai/api/ai_airport.cpp index ec3d40029..cfe4df084 100644 --- a/src/ai/api/ai_airport.cpp +++ b/src/ai/api/ai_airport.cpp @@ -125,3 +125,13 @@ return 1; } + +/* static */ TownID AIAirport::GetNearestTown(TileIndex tile, AirportType type) +{ + extern Town *AirportGetNearestTown(const AirportFTAClass *afc, TileIndex airport_tile); + + if (!::IsValidTile(tile)) return INVALID_TOWN; + if (!IsValidAirportType(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 d1d18714b..7693774e6 100644 --- a/src/ai/api/ai_airport.hpp +++ b/src/ai/api/ai_airport.hpp @@ -155,10 +155,19 @@ public: * built at this tile. * @param tile The tile to check. * @param type The AirportType to check. - * @return The TownID of the town closest to the tile. - * @note The noise will be added to the town with TownID AITile.GetClosestTown(tile). + * @return The amount of noise added to the nearest town. + * @note The noise will be added to the town with TownID GetNearestTown(itle, type). */ static int GetNoiseLevelIncrease(TileIndex tile, AirportType type); + + /** + * Get the TownID of the town whose local authority will influence + * an airport at some tile. + * @param tile The tile to check. + * @param type The AirportType to check. + * @return The TownID of the town closest to the tile. + */ + static TownID GetNearestTown(TileIndex tile, AirportType type); }; #endif /* AI_AIRPORT_HPP */ diff --git a/src/ai/api/ai_airport.hpp.sq b/src/ai/api/ai_airport.hpp.sq index 355a2ab12..fdfed7836 100644 --- a/src/ai/api/ai_airport.hpp.sq +++ b/src/ai/api/ai_airport.hpp.sq @@ -52,6 +52,7 @@ void SQAIAirport_Register(Squirrel *engine) { SQAIAirport.DefSQStaticMethod(engine, &AIAirport::RemoveAirport, "RemoveAirport", 2, "xi"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetAirportType, "GetAirportType", 2, "xi"); SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNoiseLevelIncrease, "GetNoiseLevelIncrease", 3, "xii"); + SQAIAirport.DefSQStaticMethod(engine, &AIAirport::GetNearestTown, "GetNearestTown", 3, "xii"); SQAIAirport.PostRegister(engine); } -- cgit v1.2.3-54-g00ecf