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 bridge.h Header file for bridges */
17 #include "slope_func.h"
18 #include "viewport_func.h"
21 * This enum is related to the definition of bridge pieces,
22 * which is used to determine the proper sprite table to use
23 * while drawing a given bridge part.
26 BRIDGE_PIECE_NORTH
= 0,
28 BRIDGE_PIECE_INNER_NORTH
,
29 BRIDGE_PIECE_INNER_SOUTH
,
30 BRIDGE_PIECE_MIDDLE_ODD
,
31 BRIDGE_PIECE_MIDDLE_EVEN
,
36 DECLARE_POSTFIX_INCREMENT(BridgePieces
)
38 static const uint MAX_BRIDGES
= 13; ///< Maximal number of available bridge specs.
40 typedef uint BridgeType
; ///< Bridge spec number.
43 * Struct containing information about a single bridge type
46 Year avail_year
; ///< the year where it becomes available
47 byte min_length
; ///< the minimum length (not counting start and end tile)
48 uint16 max_length
; ///< the maximum length (not counting start and end tile)
49 uint16 price
; ///< the price multiplier
50 uint16 speed
; ///< maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
51 SpriteID sprite
; ///< the sprite which is used in the GUI
52 PaletteID pal
; ///< the palette which is used in the GUI
53 StringID material
; ///< the string that contains the bridge description
54 StringID transport_name
[2]; ///< description of the bridge, when built for road or rail
55 PalSpriteID
**sprite_table
; ///< table of sprites for drawing the bridge
56 byte flags
; ///< bit 0 set: disable drawing of far pillars.
59 extern BridgeSpec _bridge
[MAX_BRIDGES
];
61 Foundation
GetBridgeFoundation(Slope tileh
, Axis axis
);
62 bool HasBridgeFlatRamp(Slope tileh
, Axis axis
);
65 * Get the height increase for a bridge ramp
66 * @param dir Bridge direction
67 * @param x x within the tile
68 * @param y y within the tile
70 static inline int GetBridgePartialPixelZ(DiagDirection dir
, uint x
, uint y
)
72 assert(x
< TILE_SIZE
);
73 assert(y
< TILE_SIZE
);
75 return DistanceFromTileEdge(ReverseDiagDir(dir
), x
, y
) / 2 + 1;
79 * Get the direction(s) to which rail/road can be connected in an extended bridgehead.
80 * @param tileh Slope of the tile
81 * @param dir Direction of the bridge
82 * @return DIAGDIRDIFF_SAME for all directions allowed; DIAGDIRDIFF_REVERSE for none (invalid slope); else invalid direction as a difference from dir
84 static inline DiagDirDiff
CheckExtendedBridgeHead(Slope tileh
, DiagDirection dir
)
86 extern const uint32 bridgehead_valid_slopes
[DIAGDIR_END
][2];
90 if (tileh
== InclinedSlope(ReverseDiagDir(dir
))) {
91 return DIAGDIRDIFF_SAME
;
92 } else if (HasBit (bridgehead_valid_slopes
[dir
][0], tileh
)) {
93 return DIAGDIRDIFF_90RIGHT
;
94 } else if (HasBit (bridgehead_valid_slopes
[dir
][1], tileh
)) {
95 return DIAGDIRDIFF_90LEFT
;
97 return DIAGDIRDIFF_REVERSE
;
102 * Get the specification of a bridge type.
103 * @param i The type of bridge to get the specification for.
104 * @return The specification.
106 static inline const BridgeSpec
*GetBridgeSpec(BridgeType i
)
108 assert(i
< lengthof(_bridge
));
112 int GetBridgeHeight(TileIndex tile
);
114 * Get the height ('z') of a bridge in pixels.
115 * @param tile the bridge ramp tile to get the bridge height from
116 * @return the height of the bridge in pixels
118 static inline int GetBridgePixelHeight(TileIndex tile
)
120 return GetBridgeHeight(tile
) * TILE_HEIGHT
;
123 void DrawBridgeTramBits(int x
, int y
, int z
, int offset
, bool overlay
, bool head
);
124 void DrawBridgeMiddle(const TileInfo
*ti
);
125 void DrawBridgeGround(TileInfo
*ti
);
126 const PalSpriteID
*GetBridgeRampSprite(int index
, int offset
, Slope slope
, DiagDirection dir
);
127 void DrawAqueductRamp(TileInfo
*ti
);
129 CommandCost
CheckBridgeAvailability(BridgeType bridge_type
, uint bridge_len
, DoCommandFlag flags
= DC_NONE
);
130 int CalcBridgeLenCostFactor(int x
);
134 CommandCost
CheckBridgeTiles(TileIndex tile1
, TileIndex tile2
, Axis
*axis
);
136 CommandCost
CheckBridgeBuildable (TileIndex tile1
, TileIndex tile2
,
137 DoCommandFlag flags
, bool clear1
, bool clear2
, int *height
,
138 bool restricted
= false);
140 CommandCost
CheckBridgeSlope(DiagDirection dir
, Slope
*tileh
, int *z
);
142 void MarkBridgeTilesDirty (TileIndex start
, TileIndex end
, DiagDirection dir
,
145 void SetBridgeMiddleTiles (TileIndex tile1
, TileIndex tile2
, Axis direction
,
148 void RemoveBridgeMiddleTiles(TileIndex tile1
, TileIndex tile2
);
150 #endif /* BRIDGE_H */