(svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
This commit is contained in:
		@@ -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 */
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user