(svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
authorsmatz
Sun, 20 Jul 2008 15:50:41 +0000
changeset 9669 da2ecea5561e
parent 9668 b0863ac5794b
child 9670 ce7645fdaed5
(svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
src/airport.h
src/station_cmd.cpp
--- a/src/airport.h	Sun Jul 20 15:39:20 2008 +0000
+++ b/src/airport.h	Sun Jul 20 15:50:41 2008 +0000
@@ -197,8 +197,4 @@
  */
 uint32 GetValidAirports();
 
-
-/* Calculate the noise this type airport will generate */
-uint8 GetAirportNoiseLevelForTown(const AirportFTAClass *afc, TileIndex town_tile, TileIndex tile);
-
 #endif /* AIRPORT_H */
--- a/src/station_cmd.cpp	Sun Jul 20 15:39:20 2008 +0000
+++ b/src/station_cmd.cpp	Sun Jul 20 15:50:41 2008 +0000
@@ -1613,42 +1613,28 @@
 	_airport_sections_helistation        // Helistation
 };
 
-/** Recalculate the noise generated by the airports of each town */
-void UpdateAirportsNoise()
-{
-	Town *t;
-	const Station *st;
-
-	FOR_ALL_TOWNS(t) t->noise_reached = 0;
-
-	FOR_ALL_STATIONS(st) {
-		if (IsAirport(st->xy)) {
-			st->town->noise_reached += GetAirportNoiseLevelForTown(GetAirport(st->airport_type), st->town->xy, st->xy);
-		}
-	}
-}
 
 /** Get a possible noise reduction factor based on distance from town center.
  * The further you get, the less noise you generate.
  * So all those folks at city council can now happily slee...  work in their offices
  * @param afc AirportFTAClass pointer of the class being proposed
  * @param town_tile TileIndex of town's center, the one who will receive the airport's candidature
- * @param tile TileIndex where the new airport might be built
+ * @param tile TileIndex of northern tile of an airport (present or to-be-built), NOT the station tile
  * @return the noise that will be generated, according to distance
  */
-uint8 GetAirportNoiseLevelForTown(const AirportFTAClass *afc, TileIndex town_tile, TileIndex tile)
+static uint8 GetAirportNoiseLevelForTown(const AirportFTAClass *afc, TileIndex town_tile, TileIndex tile)
 {
 	struct TileIndexDistance {
 		TileIndex index;
 		uint distance;
 	};
 
-	uint distance;
-
 	/* 0 cannot be accounted, and 1 is the lowest that can be reduced from town.
 	 * So no need to go any further*/
 	if (afc->noise_level < 2) return afc->noise_level;
 
+	uint distance;
+
 	/* Find the airport-to-be's closest corner to the town */
 	if (afc->size_x == 1 && afc->size_y == 1) {
 		distance = DistanceManhattan(town_tile, tile);  // ont tile, one corner, it's THE corner
@@ -1692,6 +1678,23 @@
 	return noise_reduction >= afc->noise_level ? 1 : afc->noise_level - noise_reduction;
 }
 
+
+/** Recalculate the noise generated by the airports of each town */
+void UpdateAirportsNoise()
+{
+	Town *t;
+	const Station *st;
+
+	FOR_ALL_TOWNS(t) t->noise_reached = 0;
+
+	FOR_ALL_STATIONS(st) {
+		if (st->airport_tile != 0) {
+			st->town->noise_reached += GetAirportNoiseLevelForTown(GetAirport(st->airport_type), st->town->xy, st->airport_tile);
+		}
+	}
+}
+
+
 /** Place an Airport.
  * @param tile tile where airport will be built
  * @param flags operation to perform