1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
8 /** @file script_marine.hpp Everything to query and build marine. */
9 
10 #ifndef SCRIPT_MARINE_HPP
11 #define SCRIPT_MARINE_HPP
12 
13 #include "script_error.hpp"
14 
15 /**
16  * Class that handles all marine related functions.
17  * @api ai game
18  */
19 class ScriptMarine : public ScriptObject {
20 public:
21 	/**
22 	 * All marine related error messages.
23 	 */
24 	enum ErrorMessages {
25 		/** Base for marine related errors */
26 		ERR_MARINE_BASE = ScriptError::ERR_CAT_MARINE << ScriptError::ERR_CAT_BIT_SIZE,
27 
28 		/** Infrastructure must be built on water */
29 		ERR_MARINE_MUST_BE_BUILT_ON_WATER,                  // [STR_ERROR_MUST_BE_BUILT_ON_WATER]
30 	};
31 
32 	/**
33 	 * Types of water-related objects in the game.
34 	 */
35 	enum BuildType {
36 		BT_DOCK,  ///< Build a dock
37 		BT_DEPOT, ///< Build a ship depot
38 		BT_BUOY,  ///< Build a buoy
39 		BT_LOCK,  ///< Build a lock
40 		BT_CANAL, ///< Build a canal
41 	};
42 
43 	/**
44 	 * Checks whether the given tile is actually a tile with a water depot.
45 	 * @param tile The tile to check.
46 	 * @pre ScriptMap::IsValidTile(tile).
47 	 * @return True if and only if the tile has a water depot.
48 	 */
49 	static bool IsWaterDepotTile(TileIndex tile);
50 
51 	/**
52 	 * Checks whether the given tile is actually a tile with a dock.
53 	 * @param tile The tile to check.
54 	 * @pre ScriptMap::IsValidTile(tile).
55 	 * @return True if and only if the tile has a dock.
56 	 */
57 	static bool IsDockTile(TileIndex tile);
58 
59 	/**
60 	 * Checks whether the given tile is actually a tile with a buoy.
61 	 * @param tile The tile to check.
62 	 * @pre ScriptMap::IsValidTile(tile).
63 	 * @return True if and only if the tile has a buoy.
64 	 */
65 	static bool IsBuoyTile(TileIndex tile);
66 
67 	/**
68 	 * Checks whether the given tile is actually a tile with a lock.
69 	 * @param tile The tile to check.
70 	 * @pre ScriptMap::IsValidTile(tile).
71 	 * @return True if and only if the tile has a lock.
72 	 */
73 	static bool IsLockTile(TileIndex tile);
74 
75 	/**
76 	 * Checks whether the given tile is actually a tile with a canal.
77 	 * @param tile The tile to check.
78 	 * @pre ScriptMap::IsValidTile(tile).
79 	 * @return True if and only if the tile has a canal.
80 	 */
81 	static bool IsCanalTile(TileIndex tile);
82 
83 	/**
84 	 * Checks whether the given tiles are directly connected, i.e. whether
85 	 *  a ship vehicle can travel from the center of the first tile to the
86 	 *  center of the second tile.
87 	 * @param tile_from The source tile.
88 	 * @param tile_to The destination tile.
89 	 * @pre ScriptMap::IsValidTile(tile_from).
90 	 * @pre ScriptMap::IsValidTile(tile_to).
91 	 * @pre 'tile_from' and 'tile_to' are directly neighbouring tiles.
92 	 * @return True if and only if a ship can go from tile_from to tile_to.
93 	 */
94 	static bool AreWaterTilesConnected(TileIndex tile_from, TileIndex tile_to);
95 
96 	/**
97 	 * Builds a water depot on tile.
98 	 * @param tile The tile where the water depot will be build.
99 	 * @param front A tile on the same axis with 'tile' as the depot shall be oriented.
100 	 * @pre ScriptMap::IsValidTile(tile).
101 	 * @pre ScriptMap::IsValidTile(front).
102 	 * @game @pre Valid ScriptCompanyMode active in scope.
103 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
104 	 * @exception ScriptError::ERR_SITE_UNSUITABLE
105 	 * @exception ScriptMarine::ERR_MARINE_MUST_BE_BUILT_ON_WATER
106 	 * @return Whether the water depot has been/can be build or not.
107 	 * @note A WaterDepot is 1 tile in width, and 2 tiles in length.
108 	 * @note The depot will be built towards the south from 'tile', not necessarily towards 'front'.
109 	 */
110 	static bool BuildWaterDepot(TileIndex tile, TileIndex front);
111 
112 	/**
113 	 * Builds a dock where tile is the tile still on land.
114 	 * @param tile The tile still on land of the dock.
115 	 * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT.
116 	 * @pre ScriptMap::IsValidTile(tile).
117 	 * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id).
118 	 * @game @pre Valid ScriptCompanyMode active in scope.
119 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
120 	 * @exception ScriptError::ERR_SITE_UNSUITABLE
121 	 * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION
122 	 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS
123 	 * @return Whether the dock has been/can be build or not.
124 	 */
125 	static bool BuildDock(TileIndex tile, StationID station_id);
126 
127 	/**
128 	 * Builds a buoy on tile.
129 	 * @param tile The tile where the buoy will be build.
130 	 * @pre ScriptMap::IsValidTile(tile).
131 	 * @game @pre Valid ScriptCompanyMode active in scope.
132 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
133 	 * @exception ScriptError::ERR_SITE_UNSUITABLE
134 	 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS
135 	 * @return Whether the buoy has been/can be build or not.
136 	 */
137 	static bool BuildBuoy(TileIndex tile);
138 
139 	/**
140 	 * Builds a lock on tile.
141 	 * @param tile The tile where the lock will be build.
142 	 * @pre ScriptMap::IsValidTile(tile).
143 	 * @game @pre Valid ScriptCompanyMode active in scope.
144 	 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
145 	 * @exception ScriptError::ERR_SITE_UNSUITABLE
146 	 * @return Whether the lock has been/can be build or not.
147 	 */
148 	static bool BuildLock(TileIndex tile);
149 
150 	/**
151 	 * Builds a canal on tile.
152 	 * @param tile The tile where the canal will be build.
153 	 * @pre ScriptMap::IsValidTile(tile).
154 	 * @game @pre Valid ScriptCompanyMode active in scope.
155 	 * @exception ScriptError::ERR_AREA_NOT_CLEAR
156 	 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
157 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
158 	 * @exception ScriptError::ERR_ALREADY_BUILT
159 	 * @return Whether the canal has been/can be build or not.
160 	 */
161 	static bool BuildCanal(TileIndex tile);
162 
163 	/**
164 	 * Removes a water depot.
165 	 * @param tile Any tile of the water depot.
166 	 * @pre ScriptMap::IsValidTile(tile).
167 	 * @game @pre Valid ScriptCompanyMode active in scope.
168 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
169 	 * @return Whether the water depot has been/can be removed or not.
170 	 */
171 	static bool RemoveWaterDepot(TileIndex tile);
172 
173 	/**
174 	 * Removes a dock.
175 	 * @param tile Any tile of the dock.
176 	 * @pre ScriptMap::IsValidTile(tile).
177 	 * @game @pre Valid ScriptCompanyMode active in scope.
178 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
179 	 * @return Whether the dock has been/can be removed or not.
180 	 */
181 	static bool RemoveDock(TileIndex tile);
182 
183 	/**
184 	 * Removes a buoy.
185 	 * @param tile Any tile of the buoy.
186 	 * @pre ScriptMap::IsValidTile(tile).
187 	 * @game @pre Valid ScriptCompanyMode active in scope.
188 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
189 	 * @return Whether the buoy has been/can be removed or not.
190 	 */
191 	static bool RemoveBuoy(TileIndex tile);
192 
193 	/**
194 	 * Removes a lock.
195 	 * @param tile Any tile of the lock.
196 	 * @pre ScriptMap::IsValidTile(tile).
197 	 * @game @pre Valid ScriptCompanyMode active in scope.
198 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
199 	 * @return Whether the lock has been/can be removed or not.
200 	 */
201 	static bool RemoveLock(TileIndex tile);
202 
203 	/**
204 	 * Removes a canal.
205 	 * @param tile Any tile of the canal.
206 	 * @pre ScriptMap::IsValidTile(tile).
207 	 * @game @pre Valid ScriptCompanyMode active in scope.
208 	 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
209 	 * @return Whether the canal has been/can be removed or not.
210 	 */
211 	static bool RemoveCanal(TileIndex tile);
212 
213 	/**
214 	 * Get the baseprice of building a water-related object.
215 	 * @param build_type the type of object to build
216 	 * @return The baseprice of building the given object.
217 	 */
218 	static Money GetBuildCost(BuildType build_type);
219 };
220 
221 #endif /* SCRIPT_MARINE_HPP */
222