OpenTTD Source: src/road_func.h Source File

OpenTTD Source 13.2.1

road_func.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 <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef ROAD_FUNC_H
11 #define ROAD_FUNC_H
12
13 #include "core/bitmath_func.hpp"
14 #include "road.h"
15 #include "economy_func.h"
16 #include "transparency.h"
17
23 static inline bool IsValidRoadBits(RoadBits r)
24 {
25 return r < ROAD_END;
26 }
27
37 static inline RoadBits ComplementRoadBits(RoadBits r)
38 {
39 assert(IsValidRoadBits(r));
40 return (RoadBits)(ROAD_ALL ^ r);
41 }
42
51 static inline RoadBits MirrorRoadBits(RoadBits r)
52 {
53 assert(IsValidRoadBits(r));
54 return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
55 }
56
66 static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
67 {
68 assert(IsValidRoadBits(r));
69 for (; rot > (DiagDirDiff)0; rot--) {
70 r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
71 }
72 return r;
73 }
74
81 static inline bool IsStraightRoad(RoadBits r)
82 {
83 assert(IsValidRoadBits(r));
84 return (r == ROAD_X || r == ROAD_Y);
85 }
86
96 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
97 {
98 assert(IsValidDiagDirection(d));
99 return (RoadBits)(ROAD_NW << (3 ^ d));
100 }
101
111 static inline RoadBits AxisToRoadBits(Axis a)
112 {
113 assert(IsValidAxis(a));
114 return a == AXIS_X ? ROAD_X : ROAD_Y;
115 }
116
117
125 static inline Money RoadMaintenanceCost(RoadType roadtype, uint32 num, uint32 total_num)
126 {
127 assert(roadtype < ROADTYPE_END);
128 return (_price[PR_INFRASTRUCTURE_ROAD] * GetRoadTypeInfo(roadtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 12;
129 }
130
135 static inline bool HasRoadCatenary(RoadType roadtype)
136 {
137 assert(roadtype < ROADTYPE_END);
138 return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_CATENARY);
139 }
140
145 static inline bool HasRoadCatenaryDrawn(RoadType roadtype)
146 {
147 return HasRoadCatenary(roadtype) && !IsInvisibilitySet(TO_CATENARY);
148 }
149
150 bool HasRoadTypeAvail(CompanyID company, RoadType roadtype);
151 bool ValParamRoadType(RoadType roadtype);
152 RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces = true);
153 RoadTypes GetRoadTypes(bool introduces);
154 RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date);
155
156 void UpdateLevelCrossing(TileIndex tile, bool sound = true, bool force_bar = false);
157 void MarkDirtyAdjacentLevelCrossingTiles(TileIndex tile, Axis road_axis);
158 void UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(TileIndex tile, Axis road_axis);
159 void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count);
160
161 struct TileInfo;
162 void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset, bool draw_underlay = true);
163
164 #endif /* ROAD_FUNC_H */
RoadTypeInfo
Definition: road.h:76
TO_CATENARY
@ TO_CATENARY
catenary
Definition: transparency.h:30
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:26
IsValidAxis
static bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Definition: direction_func.h:43
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
ROTF_CATENARY
@ ROTF_CATENARY
Bit number for adding catenary.
Definition: road.h:39
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:125
DiagDirDiff
DiagDirDiff
Enumeration for the difference between to DiagDirection.
Definition: direction_type.h:104
MarkDirtyAdjacentLevelCrossingTiles
void MarkDirtyAdjacentLevelCrossingTiles(TileIndex tile, Axis road_axis)
Find adjacent level crossing tiles in this multi-track crossing and mark them dirty.
Definition: train_cmd.cpp:1785
GetCompanyRoadTypes
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces=true)
Get the road types the given company can build.
Definition: road.cpp:188
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
IsValidDiagDirection
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Definition: direction_func.h:21
IntSqrt
uint32 IntSqrt(uint32 num)
Compute the integer square root.
Definition: math_func.cpp:77
economy_func.h
GetRoadTypes
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition: road.cpp:216
AddDateIntroducedRoadTypes
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date)
Add the road types that are to be introduced at the given date.
Definition: road.cpp:155
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
IsValidRoadBits
static bool IsValidRoadBits(RoadBits r)
Whether the given roadtype is valid.
Definition: road_func.h:23
IsStraightRoad
static bool IsStraightRoad(RoadBits r)
Check if we've got a straight road.
Definition: road_func.h:81
DiagDirToRoadBits
static RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition: road_func.h:96
AxisToRoadBits
static RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition: road_func.h:111
ROAD_X
@ ROAD_X
Full road along the x-axis (south-west + north-east)
Definition: road_type.h:56
ROAD_Y
@ ROAD_Y
Full road along the y-axis (north-west + south-east)
Definition: road_type.h:57
bitmath_func.hpp
ROAD_ALL
@ ROAD_ALL
Full 4-way crossing.
Definition: road_type.h:64
RotateRoadBits
static RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
Calculate rotated RoadBits.
Definition: road_func.h:66
ComplementRoadBits
static RoadBits ComplementRoadBits(RoadBits r)
Calculate the complement of a RoadBits value.
Definition: road_func.h:37
HasRoadTypeAvail
bool HasRoadTypeAvail(CompanyID company, RoadType roadtype)
Finds out, whether given company has a given RoadType available for construction.
Definition: road.cpp:111
ROAD_END
@ ROAD_END
Out-of-range roadbits, used for iterations.
Definition: road_type.h:66
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
IsInvisibilitySet
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:59
HasRoadCatenaryDrawn
static bool HasRoadCatenaryDrawn(RoadType roadtype)
Test if we should draw road catenary.
Definition: road_func.h:145
RoadTypes
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
RoadMaintenanceCost
static Money RoadMaintenanceCost(RoadType roadtype, uint32 num, uint32 total_num)
Calculates the maintenance cost of a number of road bits.
Definition: road_func.h:125
UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval
void UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(TileIndex tile, Axis road_axis)
Update adjacent level crossing tiles in this multi-track crossing, due to removal of a level crossing...
Definition: train_cmd.cpp:1802
road.h
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
ValParamRoadType
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition: road.cpp:142
UpdateCompanyRoadInfrastructure
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
Definition: road_cmd.cpp:197
HasRoadCatenary
static bool HasRoadCatenary(RoadType roadtype)
Test if a road type has catenary.
Definition: road_func.h:135
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
transparency.h
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:225
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
RoadBits
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:50
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:126
UpdateLevelCrossing
void UpdateLevelCrossing(TileIndex tile, bool sound=true, bool force_bar=false)
Update a level crossing to barred or open (crossing may include multiple adjacent tiles).
Definition: train_cmd.cpp:1753
ROAD_NW
@ ROAD_NW
North-west part.
Definition: road_type.h:52
DrawRoadOverlays
void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset, bool draw_underlay=true)
Draw road underlay and overlay sprites.
Definition: road_cmd.cpp:1495
OverflowSafeInt< int64 >
MirrorRoadBits
static RoadBits MirrorRoadBits(RoadBits r)
Calculate the mirrored RoadBits.
Definition: road_func.h:51