@ -2303,18 +2303,19 @@ uint8_t GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance)
* Finds the town nearest to given airport . Based on minimal manhattan distance to any airport ' s tile .
* If two towns have the same distance , town with lower index is returned .
* @ param as airport ' s description
* @ param tile origin tile ( top corner of the airport )
* @ param it An iterator over all airport tiles
* @ param [ out ] mindist Minimum distance to town
* @ return nearest town to airport
*/
Town * AirportGetNearestTown ( const AirportSpec * as , const TileIterator & it , uint & mindist )
Town * AirportGetNearestTown ( const AirportSpec * as , TileIndex tile , const TileIterator & it , uint & mindist )
{
assert ( Town : : GetNumItems ( ) > 0 ) ;
Town * nearest = nullptr ;
uint perimeter_min_x = TileX ( i t) ;
uint perimeter_min_y = TileY ( i t) ;
uint perimeter_min_x = TileX ( tile ) ;
uint perimeter_min_y = TileY ( tile ) ;
uint perimeter_max_x = perimeter_min_x + as - > size_x - 1 ;
uint perimeter_max_y = perimeter_min_y + as - > size_y - 1 ;
@ -2322,6 +2323,8 @@ Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint
std : : unique_ptr < TileIterator > copy ( it . Clone ( ) ) ;
for ( TileIndex cur_tile = * copy ; cur_tile ! = INVALID_TILE ; cur_tile = + + * copy ) {
assert ( IsInsideBS ( TileX ( cur_tile ) , perimeter_min_x , as - > size_x ) ) ;
assert ( IsInsideBS ( TileY ( cur_tile ) , perimeter_min_y , as - > size_y ) ) ;
if ( TileX ( cur_tile ) = = perimeter_min_x | | TileX ( cur_tile ) = = perimeter_max_x | | TileY ( cur_tile ) = = perimeter_min_y | | TileY ( cur_tile ) = = perimeter_max_y ) {
Town * t = CalcClosestTownFromTile ( cur_tile , mindist + 1 ) ;
if ( t = = nullptr ) continue ;
@ -2349,7 +2352,7 @@ void UpdateAirportsNoise()
const AirportSpec * as = st - > airport . GetSpec ( ) ;
AirportTileIterator it ( st ) ;
uint dist ;
Town * nearest = AirportGetNearestTown ( as , it, dist ) ;
Town * nearest = AirportGetNearestTown ( as , st- > airport . tile , it, dist ) ;
nearest - > noise_reached + = GetAirportNoiseLevelForDistance ( as , dist ) ;
}
}
@ -2399,7 +2402,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, byte airport_ty
/* The noise level is the noise from the airport and reduce it to account for the distance to the town center. */
uint dist ;
Town * nearest = AirportGetNearestTown ( as , tile _iter, dist ) ;
Town * nearest = AirportGetNearestTown ( as , tile , tile _iter, dist ) ;
uint newnoise_level = GetAirportNoiseLevelForDistance ( as , dist ) ;
/* Check if local auth would allow a new airport */
@ -2527,7 +2530,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
* need of recalculation */
AirportTileIterator it ( st ) ;
uint dist ;
Town * nearest = AirportGetNearestTown ( as , it, dist ) ;
Town * nearest = AirportGetNearestTown ( as , st- > airport . tile , it, dist ) ;
nearest - > noise_reached - = GetAirportNoiseLevelForDistance ( as , dist ) ;
if ( _settings_game . economy . station_noise_level ) {