/* static */ bool ScriptAirport::IsNoiseLevelAllowed(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); } for (local type = 0; type <= 8; type++) { AILog.Info("type: " + WrightAI.GetAirportTypeName(type)); local percent = -1; for (local tile = 0; tile < alltiles; tile++) { 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.IsNoiseLevelAllowed(tile, type)); local newpercent = (tile + 1) * 100 / alltiles; if (percent != newpercent) AILog.Info(newpercent + "%"); percent = newpercent; } } AIController.Break("Iterated all types and tiles");