1 /* $Id: script_bridge.hpp 26149 2013-12-08 15:44:09Z frosch $ */
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/>.
10 /** @file script_bridge.hpp Everything to query and build bridges. */
12 #ifndef SCRIPT_BRIDGE_HPP
13 #define SCRIPT_BRIDGE_HPP
15 #include "script_vehicle.hpp"
18 * Class that handles all bridge related functions.
21 class ScriptBridge
: public ScriptObject
{
24 * All bridge related error messages.
27 /** Base for bridge related errors */
28 ERR_BRIDGE_BASE
= ScriptError::ERR_CAT_BRIDGE
<< ScriptError::ERR_CAT_BIT_SIZE
,
31 * The bridge you want to build is not available yet,
32 * or it is not available for the requested length.
34 ERR_BRIDGE_TYPE_UNAVAILABLE
, // [STR_ERROR_CAN_T_BUILD_BRIDGE_HERE]
36 /** One (or more) of the bridge head(s) ends in water. */
37 ERR_BRIDGE_CANNOT_END_IN_WATER
, // [STR_ERROR_ENDS_OF_BRIDGE_MUST_BOTH]
39 /** The bride heads need to be on the same height */
40 ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT
, // [STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT]
44 * Checks whether the given bridge type is valid.
45 * @param bridge_id The bridge to check.
46 * @return True if and only if the bridge type is valid.
48 static bool IsValidBridge(BridgeID bridge_id
);
51 * Checks whether the given tile is actually a bridge start or end tile.
52 * @param tile The tile to check.
53 * @pre ScriptMap::IsValidTile(tile).
54 * @return True if and only if the tile is the beginning or end of a bridge.
56 static bool IsBridgeTile(TileIndex tile
);
59 * Get the BridgeID of a bridge at a given tile.
60 * @param tile The tile to get the BridgeID from.
61 * @pre IsBridgeTile(tile).
62 * @return The BridgeID from the bridge at tile 'tile'.
64 static BridgeID
GetBridgeID(TileIndex tile
);
67 * Get the name of a bridge.
68 * @param bridge_id The bridge to get the name of.
69 * @pre IsValidBridge(bridge_id).
70 * @return The name the bridge has.
72 static char *GetName(BridgeID bridge_id
);
75 * Get the maximum speed of a bridge.
76 * @param bridge_id The bridge to get the maximum speed of.
77 * @pre IsValidBridge(bridge_id).
78 * @return The maximum speed the bridge has.
79 * @note The speed is in OpenTTD's internal speed unit.
80 * This is mph / 1.6, which is roughly km/h.
81 * To get km/h multiply this number by 1.00584.
83 static int32
GetMaxSpeed(BridgeID bridge_id
);
86 * Get the new cost of a bridge, excluding the road and/or rail.
87 * @param bridge_id The bridge to get the new cost of.
88 * @param length The length of the bridge.
89 * @pre IsValidBridge(bridge_id).
90 * @return The new cost the bridge has.
92 static Money
GetPrice(BridgeID bridge_id
, uint length
);
95 * Get the maximum length of a bridge.
96 * @param bridge_id The bridge to get the maximum length of.
97 * @pre IsValidBridge(bridge_id).
98 * @returns The maximum length the bridge has.
100 static int32
GetMaxLength(BridgeID bridge_id
);
103 * Get the minimum length of a bridge.
104 * @param bridge_id The bridge to get the minimum length of.
105 * @pre IsValidBridge(bridge_id).
106 * @returns The minimum length the bridge has.
108 static int32
GetMinLength(BridgeID bridge_id
);
111 * Internal function to help BuildBridge in case of road.
114 static bool _BuildBridgeRoad1();
117 * Internal function to help BuildBridge in case of road.
120 static bool _BuildBridgeRoad2();
123 * Build a bridge from one tile to the other.
124 * As an extra for road, this functions builds two half-pieces of road on
125 * each end of the bridge, making it easier for you to connect it to your
127 * @param vehicle_type The vehicle-type of bridge to build.
128 * @param bridge_id The bridge-type to build.
129 * @param start Where to start the bridge.
130 * @param end Where to end the bridge.
131 * @pre ScriptMap::IsValidTile(start).
132 * @pre ScriptMap::IsValidTile(end).
133 * @pre 'start' and 'end' are in a straight line, i.e.
134 * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or
135 * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
136 * @pre vehicle_type == ScriptVehicle::VT_WATER ||
137 * (vehicle_type == ScriptVehicle::VT_ROAD && ScriptRoad::IsRoadTypeAvailable(ScriptRoad::GetCurrentRoadType())) ||
138 * (vehicle_type == ScriptVehicle::VT_RAIL && ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType())).
139 * @game @pre Outside CompanyMode: vehicle_type == ScriptVehicle::VT_ROAD.
140 * @exception ScriptError::ERR_ALREADY_BUILT
141 * @exception ScriptError::ERR_AREA_NOT_CLEAR
142 * @exception ScriptError::ERR_LAND_SLOPED_WRONG
143 * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY
144 * @exception ScriptBridge::ERR_BRIDGE_TYPE_UNAVAILABLE
145 * @exception ScriptBridge::ERR_BRIDGE_CANNOT_END_IN_WATER
146 * @exception ScriptBridge::ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT
147 * @return Whether the bridge has been/can be build or not.
148 * @game @note Building a bridge (without CompanyMode) results in a bridge owned by towns.
149 * @note No matter if the road pieces were build or not, if building the
150 * bridge succeeded, this function returns true.
152 static bool BuildBridge(ScriptVehicle::VehicleType vehicle_type
, BridgeID bridge_id
, TileIndex start
, TileIndex end
);
155 * Removes a bridge, by executing it on either the start or end tile.
156 * @param tile An end or start tile of the bridge.
157 * @pre ScriptMap::IsValidTile(tile).
158 * @game @pre Valid ScriptCompanyMode active in scope.
159 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
160 * @return Whether the bridge has been/can be removed or not.
162 static bool RemoveBridge(TileIndex tile
);
165 * Get the tile that is on the other end of a bridge starting at tile.
166 * @param tile The tile that is an end of a bridge.
167 * @pre ScriptMap::IsValidTile(tile).
168 * @pre IsBridgeTile(tile).
169 * @return The TileIndex that is the other end of the bridge.
171 static TileIndex
GetOtherBridgeEnd(TileIndex tile
);
174 #endif /* SCRIPT_BRIDGE_HPP */