Loading

Paste #pwvjchy87

  1. local noise = AIAirport.GetNoiseLevelIncrease(tile, type);
  2. local allowed_noise = AITown.GetAllowedNoise(AIAirport.GetNearestTown(tile, type));
  3. local old_result = (noise != -1 && allowed_noise != -1 && noise <= allowed_noise);
  4. assert(old_result == AIAirport.IsNoiseLevelIncreaseAllowed(tile, type));
  5.  
  6.  
  7. /* static */ int ScriptAirport::GetNoiseLevelIncrease(TileIndex tile, AirportType type)
  8. {
  9.     extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist);
  10.     extern uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance);
  11.  
  12.     if (!::IsValidTile(tile)) return -1;
  13.     if (!IsAirportInformationAvailable(type)) return -1;
  14.  
  15.     const AirportSpec *as = ::AirportSpec::Get(type);
  16.     if (!as->IsWithinMapBounds(0, tile)) return -1;
  17.  
  18.     if (_settings_game.economy.station_noise_level) {
  19.         AirportTileTableIterator it(as->table[0], tile);
  20.         uint dist;
  21.         AirportGetNearestTown(as, it, dist);
  22.         return GetAirportNoiseLevelForDistance(as, dist);
  23.     }
  24.  
  25.     return 1;
  26. }
  27.  
  28. /* static */ TownID ScriptAirport::GetNearestTown(TileIndex tile, AirportType type)
  29. {
  30.     extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist);
  31.  
  32.     if (!::IsValidTile(tile)) return INVALID_TOWN;
  33.     if (!IsAirportInformationAvailable(type)) return INVALID_TOWN;
  34.  
  35.     const AirportSpec *as = AirportSpec::Get(type);
  36.     if (!as->IsWithinMapBounds(0, tile)) return INVALID_TOWN;
  37.  
  38.     uint dist;
  39.     return AirportGetNearestTown(as, AirportTileTableIterator(as->table[0], tile), dist)->index;
  40. }
  41.  
  42. /* static */ int ScriptTown::GetAllowedNoise(TownID town_id)
  43. {
  44.     if (!IsValidTown(town_id)) return -1;
  45.  
  46.     const Town *t = ::Town::Get(town_id);
  47.     if (_settings_game.economy.station_noise_level) {
  48.         return t->MaxTownNoise() - t->noise_reached;
  49.     }
  50.  
  51.     int num = 0;
  52.     const Station *st;
  53.     FOR_ALL_STATIONS(st) {
  54.         if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
  55.     }
  56.     return max(0, 2 - num);
  57. }
  58.  
  59.  
  60.  
  61. /* static */ bool ScriptAirport::IsNoiseLevelIncreaseAllowed(TileIndex tile, AirportType type)
  62. {
  63.     extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist);
  64.     extern uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance);
  65.  
  66.     if (!::IsValidTile(tile)) return false;
  67.     if (!IsAirportInformationAvailable(type)) return false;
  68.  
  69.     const AirportSpec *as = ::AirportSpec::Get(type);
  70.     if (!as->IsWithinMapBounds(0, tile)) return false;
  71.  
  72.     AirportTileTableIterator it(as->table[0], tile);
  73.     uint dist;
  74.     Town *t = AirportGetNearestTown(as, it, dist);
  75.     if (!::Town::IsValidID(t->index)) return false;
  76.  
  77.     if (_settings_game.economy.station_noise_level) {
  78.         return GetAirportNoiseLevelForDistance(as, dist) <= t->MaxTownNoise() - t->noise_reached;
  79.     }
  80.  
  81.     int num = 0;
  82.     const Station *st;
  83.     FOR_ALL_STATIONS(st) {
  84.         if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
  85.     }
  86.     return 1 <= max(0, 2 - num);
  87. }

Comments