Loading

Paste #pyujgn54c

  1. /* static */ bool ScriptAirport::IsNoiseLevelAllowed(TileIndex tile, AirportType type)
  2. {
  3.     extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist);
  4.     extern uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance);
  5.  
  6.     if (!::IsValidTile(tile)) return false;
  7.     if (!IsAirportInformationAvailable(type)) return false;
  8.  
  9.     const AirportSpec *as = ::AirportSpec::Get(type);
  10.     if (!as->IsWithinMapBounds(0, tile)) return false;
  11.  
  12.     AirportTileTableIterator it(as->table[0], tile);
  13.     uint dist;
  14.     Town *t = AirportGetNearestTown(as, it, dist);
  15.     if (!::Town::IsValidID(t->index)) return false;
  16.  
  17.     if (_settings_game.economy.station_noise_level) {
  18.         return GetAirportNoiseLevelForDistance(as, dist) <= t->MaxTownNoise() - t->noise_reached;
  19.     }
  20.  
  21.     int num = 0;
  22.     const Station *st;
  23.     FOR_ALL_STATIONS(st) {
  24.         if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
  25.     }
  26.     return 1 <= max(0, 2 - num);
  27. }
  28.  
  29.  
  30.         for (local type = 0; type <= 8; type++) {
  31.             AILog.Info("type: " + WrightAI.GetAirportTypeName(type));
  32.             local percent = -1;
  33.             for (local tile = 0; tile < alltiles; tile++) {
  34.                 local noise = AIAirport.GetNoiseLevelIncrease(tile, type);
  35.                 local allowed_noise = AITown.GetAllowedNoise(AIAirport.GetNearestTown(tile, type));
  36.                 local old_result = (noise != -1 && allowed_noise != -1 && noise <= allowed_noise);
  37.                 assert(old_result == AIAirport.IsNoiseLevelAllowed(tile, type));
  38.                 local newpercent = (tile + 1) * 100 / alltiles;
  39.                 if (percent != newpercent) AILog.Info(newpercent + "%");
  40.                 percent = newpercent;
  41.             }
  42.         }
  43.         AIController.Break("Iterated all types and tiles");

Comments