summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPeterN <peter@fuzzle.org>2019-03-29 17:43:06 +0000
committerGitHub <noreply@github.com>2019-03-29 17:43:06 +0000
commitb6e3e30d86e66e84d52e94a9f91b9952ae699ab5 (patch)
treea8353a549be4070c5faa41c2d2dcc19a7f725b9e /src/script
parent9244dad3f111b19950350f165dc2f61a62425f44 (diff)
downloadopenttd-b6e3e30d86e66e84d52e94a9f91b9952ae699ab5.tar.xz
Codechange: Distance between town and airport has already just been found, so use it. (#7427)
Previously the distance was thrown away, only to be expensively recalculated again.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/script_airport.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/script/api/script_airport.cpp b/src/script/api/script_airport.cpp
index 8e19d257d..dab868b75 100644
--- a/src/script/api/script_airport.cpp
+++ b/src/script/api/script_airport.cpp
@@ -130,8 +130,8 @@
/* static */ int ScriptAirport::GetNoiseLevelIncrease(TileIndex tile, AirportType type)
{
- extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it);
- extern uint8 GetAirportNoiseLevelForTown(const AirportSpec *as, TileIterator &it, TileIndex town_tile);
+ extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist);
+ extern uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance);
if (!::IsValidTile(tile)) return -1;
if (!IsAirportInformationAvailable(type)) return -1;
@@ -139,8 +139,9 @@
if (_settings_game.economy.station_noise_level) {
const AirportSpec *as = ::AirportSpec::Get(type);
AirportTileTableIterator it(as->table[0], tile);
- const Town *t = AirportGetNearestTown(as, it);
- return GetAirportNoiseLevelForTown(as, it, t->xy);
+ uint dist;
+ AirportGetNearestTown(as, it, dist);
+ return GetAirportNoiseLevelForDistance(as, dist);
}
return 1;
@@ -148,13 +149,14 @@
/* static */ TownID ScriptAirport::GetNearestTown(TileIndex tile, AirportType type)
{
- extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it);
+ extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist);
if (!::IsValidTile(tile)) return INVALID_TOWN;
if (!IsAirportInformationAvailable(type)) return INVALID_TOWN;
const AirportSpec *as = AirportSpec::Get(type);
- return AirportGetNearestTown(as, AirportTileTableIterator(as->table[0], tile))->index;
+ uint dist;
+ return AirportGetNearestTown(as, AirportTileTableIterator(as->table[0], tile), dist)->index;
}
/* static */ uint16 ScriptAirport::GetMaintenanceCostFactor(AirportType type)