local noise = AIAirport.GetNoiseLevelIncrease(tile, type); local allowed_noise = AITown.GetAllowedNoise(AIAirport.GetNearestTown(tile, type)); local old_result = (noise != -1 && allowed_noise != -1 && noise <= allowed_noise); assert(old_result == AIAirport.IsNoiseLevelIncreaseAllowed(tile, type)); /* static */ int ScriptAirport::GetNoiseLevelIncrease(TileIndex tile, AirportType type) { extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist); extern uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance); if (!::IsValidTile(tile)) return -1; if (!IsAirportInformationAvailable(type)) return -1; const AirportSpec *as = ::AirportSpec::Get(type); if (!as->IsWithinMapBounds(0, tile)) return -1; if (_settings_game.economy.station_noise_level) { AirportTileTableIterator it(as->table[0], tile); uint dist; AirportGetNearestTown(as, it, dist); return GetAirportNoiseLevelForDistance(as, dist); } return 1; } /* static */ TownID ScriptAirport::GetNearestTown(TileIndex tile, AirportType type) { extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist); if (!::IsValidTile(tile)) return INVALID_TOWN; if (!IsAirportInformationAvailable(type)) return INVALID_TOWN; const AirportSpec *as = AirportSpec::Get(type); if (!as->IsWithinMapBounds(0, tile)) return INVALID_TOWN; uint dist; return AirportGetNearestTown(as, AirportTileTableIterator(as->table[0], tile), dist)->index; } /* static */ int ScriptTown::GetAllowedNoise(TownID town_id) { if (!IsValidTown(town_id)) return -1; const Town *t = ::Town::Get(town_id); if (_settings_game.economy.station_noise_level) { return t->MaxTownNoise() - t->noise_reached; } int num = 0; const Station *st; FOR_ALL_STATIONS(st) { if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++; } return max(0, 2 - num); } /* static */ bool ScriptAirport::IsNoiseLevelIncreaseAllowed(TileIndex tile, AirportType type) { extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist); extern uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance); if (!::IsValidTile(tile)) return false; if (!IsAirportInformationAvailable(type)) return false; const AirportSpec *as = ::AirportSpec::Get(type); if (!as->IsWithinMapBounds(0, tile)) return false; AirportTileTableIterator it(as->table[0], tile); uint dist; Town *t = AirportGetNearestTown(as, it, dist); if (!::Town::IsValidID(t->index)) return false; if (_settings_game.economy.station_noise_level) { return GetAirportNoiseLevelForDistance(as, dist) <= t->MaxTownNoise() - t->noise_reached; } int num = 0; const Station *st; FOR_ALL_STATIONS(st) { if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++; } return 1 <= max(0, 2 - num); }