Loading

Paste #p0j4ujpqq

  1. // script_airport.hpp
  2.     /**
  3.      * Checks whether the noise that will be added to the nearest town if an airport would be
  4.      *  built at this tile is allowed.
  5.      * @param tile The tile to check.
  6.      * @param type The AirportType to check.
  7.      * @return true if and only if the noise level increase added by the airport is allowed.
  8.      * @note The noise will be added to the town with TownID GetNearestTown(tile, type).
  9.      */
  10.     static bool ScriptAirport::IsNoiseLevelIncreaseAllowed(TileIndex tile, AirportType type);
  11.  
  12. // script_airport.cpp
  13. /* static */ bool ScriptAirport::IsNoiseLevelIncreaseAllowed(TileIndex tile, AirportType type)
  14. {
  15.     extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist);
  16.     extern uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance);
  17.  
  18.     if (!::IsValidTile(tile)) return false;
  19.     if (!IsAirportInformationAvailable(type)) return false;
  20.  
  21.     const AirportSpec *as = ::AirportSpec::Get(type);
  22.     if (!as->IsWithinMapBounds(0, tile)) return false;
  23.  
  24.     AirportTileTableIterator it(as->table[0], tile);
  25.     uint dist;
  26.     Town *t = AirportGetNearestTown(as, it, dist);
  27.     if (!::Town::IsValidID(t->index)) return false;
  28.  
  29.     if (_settings_game.economy.station_noise_level) {
  30.         return GetAirportNoiseLevelForDistance(as, dist) <= t->MaxTownNoise() - t->noise_reached;
  31.     }
  32.  
  33.     int num = 0;
  34.     const Station *st;
  35.     FOR_ALL_STATIONS(st) {
  36.         if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
  37.     }
  38.     return 1 <= max(0, 2 - num);
  39. }

Comments