From cc38a42b072ebf94e211ba7e20f411a2ba3fbfd7 Mon Sep 17 00:00:00 2001
From: Joan Josep <juanjo.ng.83@gmail.com>
Date: Wed, 18 Aug 2021 14:33:32 +0200
Subject: [PATCH] Fix 659989af45: Set appropriate town window dirty when
 building/removing airports. (#9497)

---
 src/station_cmd.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 05e8372876..e2c232ac7e 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2359,7 +2359,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
 		InvalidateWindowData(WC_STATION_VIEW, st->index, -1);
 
 		if (_settings_game.economy.station_noise_level) {
-			SetWindowDirty(WC_TOWN_VIEW, st->town->index);
+			SetWindowDirty(WC_TOWN_VIEW, nearest->index);
 		}
 	}
 
@@ -2407,6 +2407,10 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
 		uint dist;
 		Town *nearest = AirportGetNearestTown(as, it, dist);
 		nearest->noise_reached -= GetAirportNoiseLevelForDistance(as, dist);
+
+		if (_settings_game.economy.station_noise_level) {
+			SetWindowDirty(WC_TOWN_VIEW, nearest->index);
+		}
 	}
 
 	for (TileIndex tile_cur : st->airport) {
@@ -2435,10 +2439,6 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
 
 		InvalidateWindowData(WC_STATION_VIEW, st->index, -1);
 
-		if (_settings_game.economy.station_noise_level) {
-			SetWindowDirty(WC_TOWN_VIEW, st->town->index);
-		}
-
 		Company::Get(st->owner)->infrastructure.airport--;
 
 		st->AfterStationTileSetChange(false, STATION_AIRPORT);