summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-07-20 15:50:41 +0000
committersmatz <smatz@openttd.org>2008-07-20 15:50:41 +0000
commit7154069dd0edea462da229159045e8ae80cf67ae (patch)
tree28b1aded655e68d1d577a793eee737d31e1f0ea7
parentc2ddbd151698c8505cbbbb91b85d2480876d44ab (diff)
downloadopenttd-7154069dd0edea462da229159045e8ae80cf67ae.tar.xz
(svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
-rw-r--r--src/airport.h4
-rw-r--r--src/station_cmd.cpp39
2 files changed, 21 insertions, 22 deletions
diff --git a/src/airport.h b/src/airport.h
index 0f0e8ed36..ac2d369dd 100644
--- a/src/airport.h
+++ b/src/airport.h
@@ -197,8 +197,4 @@ const AirportFTAClass *GetAirport(const byte airport_type);
*/
uint32 GetValidAirports();
-
-/* Calculate the noise this type airport will generate */
-uint8 GetAirportNoiseLevelForTown(const AirportFTAClass *afc, TileIndex town_tile, TileIndex tile);
-
#endif /* AIRPORT_H */
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 2cfdfe38e..a14c7e35a 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1613,42 +1613,28 @@ static const byte * const _airport_sections[] = {
_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 @@ uint8 GetAirportNoiseLevelForTown(const AirportFTAClass *afc, TileIndex town_til
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