Fix some daylength issues, possible division by zero in main menu.
[openttd-joker.git] / src / script / api / script_airport.hpp
blob858039d8bbd6079814720bab8228cd32eaec6b55
1 /* $Id: script_airport.hpp 25705 2013-08-09 18:43:44Z rubidium $ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file script_airport.hpp Everything to query and build airports. */
12 #ifndef SCRIPT_AIRPORT_HPP
13 #define SCRIPT_AIRPORT_HPP
15 #include "script_object.hpp"
16 #include "../../airport.h"
18 /**
19 * Class that handles all airport related functions.
20 * @api ai game
22 class ScriptAirport : public ScriptObject {
23 public:
24 /**
25 * The types of airports available in the game.
27 enum AirportType {
28 /* Note: these values represent part of the in-game AirportTypes enum */
29 AT_SMALL = ::AT_SMALL, ///< The small airport.
30 AT_LARGE = ::AT_LARGE, ///< The large airport.
31 AT_METROPOLITAN = ::AT_METROPOLITAN, ///< The metropolitan airport.
32 AT_INTERNATIONAL = ::AT_INTERNATIONAL, ///< The international airport.
33 AT_COMMUTER = ::AT_COMMUTER, ///< The commuter airport.
34 AT_INTERCON = ::AT_INTERCON, ///< The intercontinental airport.
35 AT_HELIPORT = ::AT_HELIPORT, ///< The heliport.
36 AT_HELISTATION = ::AT_HELISTATION, ///< The helistation.
37 AT_HELIDEPOT = ::AT_HELIDEPOT, ///< The helidepot.
38 AT_INVALID = ::AT_INVALID, ///< Invalid airport.
41 /**
42 * All plane types available.
44 enum PlaneType {
45 /* Note: these values represent part of the in-game values, which are not defined in an enum */
46 PT_HELICOPTER = 0, ///< A helicopter.
47 PT_SMALL_PLANE = 1, ///< A small plane.
48 PT_BIG_PLANE = 3, ///< A big plane.
50 PT_INVALID = -1, ///< An invalid PlaneType
53 /**
54 * Checks whether the given AirportType is valid and available.
55 * @param type The AirportType to check.
56 * @return True if and only if the AirportType is valid and available.
57 * @post return value == true -> IsAirportInformationAvailable returns true.
59 static bool IsValidAirportType(AirportType type);
61 /**
62 * Can you get information on this airport type? As opposed to
63 * IsValidAirportType this will return also return true when
64 * an airport type is no longer buildable.
65 * @param type The AirportType to check.
66 * @return True if and only if the AirportType is valid.
67 * @post return value == false -> IsValidAirportType returns false.
69 static bool IsAirportInformationAvailable(AirportType type);
71 /**
72 * Get the cost to build this AirportType.
73 * @param type The AirportType to check.
74 * @pre AirportAvailable(type).
75 * @return The cost of building this AirportType.
77 static Money GetPrice(AirportType type);
79 /**
80 * Checks whether the given tile is actually a tile with a hangar.
81 * @param tile The tile to check.
82 * @pre ScriptMap::IsValidTile(tile).
83 * @return True if and only if the tile has a hangar.
85 static bool IsHangarTile(TileIndex tile);
87 /**
88 * Checks whether the given tile is actually a tile with an airport.
89 * @param tile The tile to check.
90 * @pre ScriptMap::IsValidTile(tile).
91 * @return True if and only if the tile has an airport.
93 static bool IsAirportTile(TileIndex tile);
95 /**
96 * Get the width of this type of airport.
97 * @param type The type of airport.
98 * @pre IsAirportInformationAvailable(type).
99 * @return The width in tiles.
101 static int32 GetAirportWidth(AirportType type);
104 * Get the height of this type of airport.
105 * @param type The type of airport.
106 * @pre IsAirportInformationAvailable(type).
107 * @return The height in tiles.
109 static int32 GetAirportHeight(AirportType type);
112 * Get the coverage radius of this type of airport.
113 * @param type The type of airport.
114 * @pre IsAirportInformationAvailable(type).
115 * @return The radius in tiles.
117 static int32 GetAirportCoverageRadius(AirportType type);
120 * Get the number of hangars of the airport.
121 * @param tile Any tile of the airport.
122 * @pre ScriptMap::IsValidTile(tile).
123 * @return The number of hangars of the airport.
125 static int32 GetNumHangars(TileIndex tile);
128 * Get the first hangar tile of the airport.
129 * @param tile Any tile of the airport.
130 * @pre ScriptMap::IsValidTile(tile).
131 * @pre GetNumHangars(tile) > 0.
132 * @return The first hangar tile of the airport.
133 * @note Possible there are more hangars, but you won't be able to find them
134 * without walking over all the tiles of the airport and using
135 * IsHangarTile() on them.
137 static TileIndex GetHangarOfAirport(TileIndex tile);
140 * Builds a airport with tile at the topleft corner.
141 * @param tile The topleft corner of the airport.
142 * @param type The type of airport to build.
143 * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT.
144 * @pre ScriptMap::IsValidTile(tile).
145 * @pre AirportAvailable(type).
146 * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id).
147 * @game @pre Valid ScriptCompanyMode active in scope.
148 * @exception ScriptError::ERR_AREA_NOT_CLEAR
149 * @exception ScriptError::ERR_FLAT_LAND_REQUIRED
150 * @exception ScriptError::ERR_LOCAL_AUTHORITY_REFUSES
151 * @exception ScriptStation::ERR_STATION_TOO_LARGE
152 * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION
153 * @return Whether the airport has been/can be build or not.
155 static bool BuildAirport(TileIndex tile, AirportType type, StationID station_id);
158 * Removes an airport.
159 * @param tile Any tile of the airport.
160 * @pre ScriptMap::IsValidTile(tile).
161 * @game @pre Valid ScriptCompanyMode active in scope.
162 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
163 * @return Whether the airport has been/can be removed or not.
165 static bool RemoveAirport(TileIndex tile);
168 * Get the AirportType of an existing airport.
169 * @param tile Any tile of the airport.
170 * @pre ScriptTile::IsStationTile(tile).
171 * @pre ScriptStation::HasStationType(ScriptStation.GetStationID(tile), ScriptStation::STATION_AIRPORT).
172 * @return The AirportType of the airport.
174 static AirportType GetAirportType(TileIndex tile);
177 * Get the noise that will be added to the nearest town if an airport was
178 * built at this tile.
179 * @param tile The tile to check.
180 * @param type The AirportType to check.
181 * @pre IsAirportInformationAvailable(type).
182 * @return The amount of noise added to the nearest town.
183 * @note The noise will be added to the town with TownID GetNearestTown(tile, type).
185 static int GetNoiseLevelIncrease(TileIndex tile, AirportType type);
188 * Get the TownID of the town whose local authority will influence
189 * an airport at some tile.
190 * @param tile The tile to check.
191 * @param type The AirportType to check.
192 * @pre IsAirportInformationAvailable(type).
193 * @return The TownID of the town closest to the tile.
195 static TownID GetNearestTown(TileIndex tile, AirportType type);
198 * Get the maintenance cost factor of an airport type.
199 * @param type The airport type to get the maintenance factor of.
200 * @pre IsAirportInformationAvailable(type)
201 * @return Maintenance cost factor of the airport type.
203 static uint16 GetMaintenanceCostFactor(AirportType type);
206 #endif /* SCRIPT_AIRPORT_HPP */