OpenTTD Source: src/bridge.h Source File

OpenTTD Source 15.3

bridge.h
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef BRIDGE_H
11#define BRIDGE_H
12
13#include "gfx_type.h"
14#include "tile_cmd.h"
15#include "timer/timer_game_calendar.h"
16#include "bridge_type.h"
17
18 static const uint MAX_BRIDGES = 13;
19 constexpr uint SPRITES_PER_BRIDGE_PIECE = 32;
20
21/* Container for Bridge pillar flags for each axis of each bridge middle piece. */
22using BridgeMiddlePillarFlags = std::array<std::array<BridgePillarFlags, AXIS_END>, NUM_BRIDGE_MIDDLE_PIECES>;
23
27 struct BridgeSpec {
29 enum class ControlFlag : uint8_t {
30 CustomPillarFlags,
31 InvalidPillarFlags,
32 };
33 using ControlFlags = EnumBitSet<ControlFlag, uint8_t>;
34
35 TimerGameCalendar::Year avail_year;
36 uint8_t min_length;
37 uint16_t max_length;
38 uint16_t price;
39 uint16_t speed;
40 SpriteID sprite;
41 PaletteID pal;
42 StringID material;
43 StringID transport_name[2];
44 std::vector<std::vector<PalSpriteID>> sprite_table;
45 uint8_t flags;
46 ControlFlags ctrl_flags{};
47 BridgeMiddlePillarFlags pillar_flags{};
48};
49
50extern BridgeSpec _bridge[MAX_BRIDGES];
51
52 Foundation GetBridgeFoundation(Slope tileh, Axis axis);
53bool HasBridgeFlatRamp(Slope tileh, Axis axis);
54
60 inline const BridgeSpec *GetBridgeSpec(BridgeType i)
61{
62 assert(i < lengthof(_bridge));
63 return &_bridge[i];
64}
65
66void DrawBridgeMiddle(const TileInfo *ti, BridgePillarFlags blocked_pillars);
67
68 CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlags flags = {});
69int CalcBridgeLenCostFactor(int x);
70
71void ResetBridges();
72
73#endif /* BRIDGE_H */
CalcBridgeLenCostFactor
int CalcBridgeLenCostFactor(int x)
Calculate the price factor for building a long bridge.
Definition tunnelbridge_cmd.cpp:94
GetBridgeSpec
const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition bridge.h:60
GetBridgeFoundation
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
Get the foundation for a bridge.
Definition tunnelbridge_cmd.cpp:115
SPRITES_PER_BRIDGE_PIECE
constexpr uint SPRITES_PER_BRIDGE_PIECE
Number of sprites there are per bridge piece.
Definition bridge.h:19
MAX_BRIDGES
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
Definition bridge.h:18
HasBridgeFlatRamp
bool HasBridgeFlatRamp(Slope tileh, Axis axis)
Determines if the track on a bridge ramp is flat or goes up/down.
Definition tunnelbridge_cmd.cpp:131
DrawBridgeMiddle
void DrawBridgeMiddle(const TileInfo *ti, BridgePillarFlags blocked_pillars)
Draw the middle bits of a bridge.
Definition tunnelbridge_cmd.cpp:1614
CheckBridgeAvailability
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlags flags={})
Is a bridge of the specified type and length available?
Definition tunnelbridge_cmd.cpp:240
_bridge
BridgeSpec _bridge[MAX_BRIDGES]
The specification of all bridges.
Definition tunnelbridge_cmd.cpp:49
ResetBridges
void ResetBridges()
Reset the data been eventually changed by the grf loaded.
Definition tunnelbridge_cmd.cpp:83
bridge_type.h
Header file for bridge types.
NUM_BRIDGE_MIDDLE_PIECES
static constexpr uint NUM_BRIDGE_MIDDLE_PIECES
Number of bridge middles pieces.
Definition bridge_type.h:36
BridgeType
uint BridgeType
Bridge spec number.
Definition bridge_type.h:15
CommandCost
Common return value for all commands.
Definition command_type.h:24
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
gfx_type.h
Types related to the graphics and/or input devices.
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
Foundation
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:271
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
BridgeSpec
Struct containing information about a single bridge type.
Definition bridge.h:27
BridgeSpec::price
uint16_t price
the price multiplier
Definition bridge.h:38
BridgeSpec::ctrl_flags
ControlFlags ctrl_flags
control flags
Definition bridge.h:46
BridgeSpec::pal
PaletteID pal
the palette which is used in the GUI
Definition bridge.h:41
BridgeSpec::ControlFlag
ControlFlag
Internal flags about each BridgeSpec.
Definition bridge.h:29
BridgeSpec::ControlFlag::CustomPillarFlags
@ CustomPillarFlags
Bridge has set custom pillar flags.
BridgeSpec::ControlFlag::InvalidPillarFlags
@ InvalidPillarFlags
Bridge pillar flags are not valid, i.e. only the tile layout has been modified.
BridgeSpec::min_length
uint8_t min_length
the minimum length (not counting start and end tile)
Definition bridge.h:36
BridgeSpec::pillar_flags
BridgeMiddlePillarFlags pillar_flags
bridge pillar flags.
Definition bridge.h:47
BridgeSpec::material
StringID material
the string that contains the bridge description
Definition bridge.h:42
BridgeSpec::sprite_table
std::vector< std::vector< PalSpriteID > > sprite_table
table of sprites for drawing the bridge
Definition bridge.h:44
BridgeSpec::avail_year
TimerGameCalendar::Year avail_year
the year where it becomes available
Definition bridge.h:35
BridgeSpec::transport_name
StringID transport_name[2]
description of the bridge, when built for road or rail
Definition bridge.h:43
BridgeSpec::sprite
SpriteID sprite
the sprite which is used in the GUI
Definition bridge.h:40
BridgeSpec::flags
uint8_t flags
bit 0 set: disable drawing of far pillars.
Definition bridge.h:45
BridgeSpec::speed
uint16_t speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition bridge.h:39
BridgeSpec::max_length
uint16_t max_length
the maximum length (not counting start and end tile)
Definition bridge.h:37
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
tile_cmd.h
Generic 'commands' that can be performed on all tiles.
timer_game_calendar.h
Definition of the game-calendar-timer.