Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../../stdafx.h"
00013 #include "script_airport.hpp"
00014 #include "script_station.hpp"
00015 #include "../../station_base.h"
00016 #include "../../town.h"
00017
00018 bool ScriptAirport::IsValidAirportType(AirportType type)
00019 {
00020 return IsAirportInformationAvailable(type) && ::AirportSpec::Get(type)->IsAvailable();
00021 }
00022
00023 bool ScriptAirport::IsAirportInformationAvailable(AirportType type)
00024 {
00025 return type >= 0 && type < (AirportType)NUM_AIRPORTS && AirportSpec::Get(type)->enabled;
00026 }
00027
00028 Money ScriptAirport::GetPrice(AirportType type)
00029 {
00030 if (!IsValidAirportType(type)) return -1;
00031
00032 const AirportSpec *as = ::AirportSpec::Get(type);
00033 return _price[PR_BUILD_STATION_AIRPORT] * as->size_x * as->size_y;
00034 }
00035
00036 bool ScriptAirport::IsHangarTile(TileIndex tile)
00037 {
00038 if (!::IsValidTile(tile)) return false;
00039
00040 return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile);
00041 }
00042
00043 bool ScriptAirport::IsAirportTile(TileIndex tile)
00044 {
00045 if (!::IsValidTile(tile)) return false;
00046
00047 return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile);
00048 }
00049
00050 int32 ScriptAirport::GetAirportWidth(AirportType type)
00051 {
00052 if (!IsAirportInformationAvailable(type)) return -1;
00053
00054 return ::AirportSpec::Get(type)->size_x;
00055 }
00056
00057 int32 ScriptAirport::GetAirportHeight(AirportType type)
00058 {
00059 if (!IsAirportInformationAvailable(type)) return -1;
00060
00061 return ::AirportSpec::Get(type)->size_y;
00062 }
00063
00064 int32 ScriptAirport::GetAirportCoverageRadius(AirportType type)
00065 {
00066 if (!IsAirportInformationAvailable(type)) return -1;
00067
00068 return _settings_game.station.modified_catchment ? ::AirportSpec::Get(type)->catchment : (uint)CA_UNMODIFIED;
00069 }
00070
00071 bool ScriptAirport::BuildAirport(TileIndex tile, AirportType type, StationID station_id)
00072 {
00073 EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
00074 EnforcePrecondition(false, ::IsValidTile(tile));
00075 EnforcePrecondition(false, IsValidAirportType(type));
00076 EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
00077
00078 uint p2 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 1;
00079 p2 |= (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
00080 return ScriptObject::DoCommand(tile, type, p2, CMD_BUILD_AIRPORT);
00081 }
00082
00083 bool ScriptAirport::RemoveAirport(TileIndex tile)
00084 {
00085 EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
00086 EnforcePrecondition(false, ::IsValidTile(tile))
00087 EnforcePrecondition(false, IsAirportTile(tile) || IsHangarTile(tile));
00088
00089 return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
00090 }
00091
00092 int32 ScriptAirport::GetNumHangars(TileIndex tile)
00093 {
00094 if (!::IsValidTile(tile)) return -1;
00095 if (!::IsTileType(tile, MP_STATION)) return -1;
00096
00097 const Station *st = ::Station::GetByTile(tile);
00098 if (st->owner != ScriptObject::GetCompany() && ScriptObject::GetCompany() != OWNER_DEITY) return -1;
00099 if ((st->facilities & FACIL_AIRPORT) == 0) return -1;
00100
00101 return st->airport.GetNumHangars();
00102 }
00103
00104 TileIndex ScriptAirport::GetHangarOfAirport(TileIndex tile)
00105 {
00106 if (!::IsValidTile(tile)) return INVALID_TILE;
00107 if (!::IsTileType(tile, MP_STATION)) return INVALID_TILE;
00108 if (GetNumHangars(tile) < 1) return INVALID_TILE;
00109
00110 const Station *st = ::Station::GetByTile(tile);
00111 if (st->owner != ScriptObject::GetCompany() && ScriptObject::GetCompany() != OWNER_DEITY) return INVALID_TILE;
00112 if ((st->facilities & FACIL_AIRPORT) == 0) return INVALID_TILE;
00113
00114 return st->airport.GetHangarTile(0);
00115 }
00116
00117 ScriptAirport::AirportType ScriptAirport::GetAirportType(TileIndex tile)
00118 {
00119 if (!ScriptTile::IsStationTile(tile)) return AT_INVALID;
00120
00121 StationID station_id = ::GetStationIndex(tile);
00122
00123 if (!ScriptStation::HasStationType(station_id, ScriptStation::STATION_AIRPORT)) return AT_INVALID;
00124
00125 return (AirportType)::Station::Get(station_id)->airport.type;
00126 }
00127
00128
00129 int ScriptAirport::GetNoiseLevelIncrease(TileIndex tile, AirportType type)
00130 {
00131 extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it);
00132 extern uint8 GetAirportNoiseLevelForTown(const AirportSpec *as, TileIterator &it, TileIndex town_tile);
00133
00134 if (!::IsValidTile(tile)) return -1;
00135 if (!IsAirportInformationAvailable(type)) return -1;
00136
00137 if (_settings_game.economy.station_noise_level) {
00138 const AirportSpec *as = ::AirportSpec::Get(type);
00139 AirportTileTableIterator it(as->table[0], tile);
00140 const Town *t = AirportGetNearestTown(as, it);
00141 return GetAirportNoiseLevelForTown(as, it, t->xy);
00142 }
00143
00144 return 1;
00145 }
00146
00147 TownID ScriptAirport::GetNearestTown(TileIndex tile, AirportType type)
00148 {
00149 extern Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it);
00150
00151 if (!::IsValidTile(tile)) return INVALID_TOWN;
00152 if (!IsAirportInformationAvailable(type)) return INVALID_TOWN;
00153
00154 const AirportSpec *as = AirportSpec::Get(type);
00155 return AirportGetNearestTown(as, AirportTileTableIterator(as->table[0], tile))->index;
00156 }
00157
00158 uint16 ScriptAirport::GetMaintenanceCostFactor(AirportType type)
00159 {
00160 if (!IsAirportInformationAvailable(type)) return INVALID_TOWN;
00161
00162 return AirportSpec::Get(type)->maintenance_cost;
00163 }