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 "../../company_func.h"
00017 #include "../../town.h"
00018
00019 bool ScriptAirport::IsValidAirportType(AirportType type)
00020 {
00021 return IsAirportInformationAvailable(type) && ::AirportSpec::Get(type)->IsAvailable();
00022 }
00023
00024 bool ScriptAirport::IsAirportInformationAvailable(AirportType type)
00025 {
00026 return type >= 0 && type < (AirportType)NUM_AIRPORTS && AirportSpec::Get(type)->enabled;
00027 }
00028
00029 Money ScriptAirport::GetPrice(AirportType type)
00030 {
00031 if (!IsValidAirportType(type)) return -1;
00032
00033 const AirportSpec *as = ::AirportSpec::Get(type);
00034 return _price[PR_BUILD_STATION_AIRPORT] * as->size_x * as->size_y;
00035 }
00036
00037 bool ScriptAirport::IsHangarTile(TileIndex tile)
00038 {
00039 if (!::IsValidTile(tile)) return false;
00040
00041 return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile);
00042 }
00043
00044 bool ScriptAirport::IsAirportTile(TileIndex tile)
00045 {
00046 if (!::IsValidTile(tile)) return false;
00047
00048 return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile);
00049 }
00050
00051 int32 ScriptAirport::GetAirportWidth(AirportType type)
00052 {
00053 if (!IsAirportInformationAvailable(type)) return -1;
00054
00055 return ::AirportSpec::Get(type)->size_x;
00056 }
00057
00058 int32 ScriptAirport::GetAirportHeight(AirportType type)
00059 {
00060 if (!IsAirportInformationAvailable(type)) return -1;
00061
00062 return ::AirportSpec::Get(type)->size_y;
00063 }
00064
00065 int32 ScriptAirport::GetAirportCoverageRadius(AirportType type)
00066 {
00067 if (!IsAirportInformationAvailable(type)) return -1;
00068
00069 return _settings_game.station.modified_catchment ? ::AirportSpec::Get(type)->catchment : (uint)CA_UNMODIFIED;
00070 }
00071
00072 bool ScriptAirport::BuildAirport(TileIndex tile, AirportType type, StationID station_id)
00073 {
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, ::IsValidTile(tile))
00086 EnforcePrecondition(false, IsAirportTile(tile) || IsHangarTile(tile));
00087
00088 return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
00089 }
00090
00091 int32 ScriptAirport::GetNumHangars(TileIndex tile)
00092 {
00093 if (!::IsValidTile(tile)) return -1;
00094 if (!::IsTileType(tile, MP_STATION)) return -1;
00095
00096 const Station *st = ::Station::GetByTile(tile);
00097 if (st->owner != _current_company) return -1;
00098 if ((st->facilities & FACIL_AIRPORT) == 0) return -1;
00099
00100 return st->airport.GetNumHangars();
00101 }
00102
00103 TileIndex ScriptAirport::GetHangarOfAirport(TileIndex tile)
00104 {
00105 if (!::IsValidTile(tile)) return INVALID_TILE;
00106 if (!::IsTileType(tile, MP_STATION)) return INVALID_TILE;
00107 if (GetNumHangars(tile) < 1) return INVALID_TILE;
00108
00109 const Station *st = ::Station::GetByTile(tile);
00110 if (st->owner != _current_company) return INVALID_TILE;
00111 if ((st->facilities & FACIL_AIRPORT) == 0) return INVALID_TILE;
00112
00113 return st->airport.GetHangarTile(0);
00114 }
00115
00116 ScriptAirport::AirportType ScriptAirport::GetAirportType(TileIndex tile)
00117 {
00118 if (!ScriptTile::IsStationTile(tile)) return AT_INVALID;
00119
00120 StationID station_id = ::GetStationIndex(tile);
00121
00122 if (!ScriptStation::HasStationType(station_id, ScriptStation::STATION_AIRPORT)) return AT_INVALID;
00123
00124 return (AirportType)::Station::Get(station_id)->airport.type;
00125 }
00126
00127
00128 int ScriptAirport::GetNoiseLevelIncrease(TileIndex tile, AirportType type)
00129 {
00130 extern Town *AirportGetNearestTown(const AirportSpec *as, TileIndex airport_tile);
00131 extern uint8 GetAirportNoiseLevelForTown(const AirportSpec *as, TileIndex town_tile, TileIndex tile);
00132
00133 if (!::IsValidTile(tile)) return -1;
00134 if (!IsAirportInformationAvailable(type)) return -1;
00135
00136 if (_settings_game.economy.station_noise_level) {
00137 const AirportSpec *as = ::AirportSpec::Get(type);
00138 const Town *t = AirportGetNearestTown(as, tile);
00139 return GetAirportNoiseLevelForTown(as, t->xy, tile);
00140 }
00141
00142 return 1;
00143 }
00144
00145 TownID ScriptAirport::GetNearestTown(TileIndex tile, AirportType type)
00146 {
00147 extern Town *AirportGetNearestTown(const AirportSpec *as, TileIndex airport_tile);
00148
00149 if (!::IsValidTile(tile)) return INVALID_TOWN;
00150 if (!IsAirportInformationAvailable(type)) return INVALID_TOWN;
00151
00152 return AirportGetNearestTown(AirportSpec::Get(type), tile)->index;
00153 }
00154
00155 uint16 ScriptAirport::GetMaintenanceCostFactor(AirportType type)
00156 {
00157 if (!IsAirportInformationAvailable(type)) return INVALID_TOWN;
00158
00159 return AirportSpec::Get(type)->maintenance_cost;
00160 }