OpenTTD Source: src/road_func.h Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 inline bool IsValidRoadBits(RoadBits r)
24{
25 return r < ROAD_END;
26}
27
37 inline RoadBits ComplementRoadBits(RoadBits r)
38{
39 assert(IsValidRoadBits(r));
40 return (RoadBits)(ROAD_ALL ^ r);
41}
42
51 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 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 inline bool IsStraightRoad(RoadBits r)
82{
83 assert(IsValidRoadBits(r));
84 return (r == ROAD_X || r == ROAD_Y);
85}
86
96 inline RoadBits DiagDirToRoadBits(DiagDirection d)
97{
98 assert(IsValidDiagDirection(d));
99 return (RoadBits)(ROAD_NW << (3 ^ d));
100}
101
111 inline RoadBits AxisToRoadBits(Axis a)
112{
113 assert(IsValidAxis(a));
114 return a == AXIS_X ? ROAD_X : ROAD_Y;
115}
116
117
125 inline Money RoadMaintenanceCost(RoadType roadtype, uint32_t num, uint32_t 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 inline bool HasRoadCatenary(RoadType roadtype)
136{
137 assert(roadtype < ROADTYPE_END);
138 return GetRoadTypeInfo(roadtype)->flags.Test(RoadTypeFlag::Catenary);
139}
140
145 inline bool HasRoadCatenaryDrawn(RoadType roadtype)
146{
147 return HasRoadCatenary(roadtype) && !IsInvisibilitySet(TO_CATENARY);
148}
149
150bool HasRoadTypeAvail(CompanyID company, RoadType roadtype);
151bool ValParamRoadType(RoadType roadtype);
152 RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces = true);
153 RoadTypes GetRoadTypes(bool introduces);
154 RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date);
155
156void UpdateLevelCrossing(TileIndex tile, bool sound = true, bool force_bar = false);
157void MarkDirtyAdjacentLevelCrossingTiles(TileIndex tile, Axis road_axis);
158void UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(TileIndex tile, Axis road_axis);
159void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count);
160
161struct TileInfo;
162enum class Roadside : uint8_t;
163void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset, bool draw_underlay = true);
164void DrawRoadGroundSprites(const TileInfo *ti, RoadBits road, RoadBits tram, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, Roadside roadside, bool snow_or_desert);
165
166#endif /* ROAD_FUNC_H */
bitmath_func.hpp
Functions related to bit mathematics.
GB
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
EnumBitSet< RoadType, uint64_t >
OverflowSafeInt< int64_t >
RoadTypeInfo
Definition road.h:52
RoadTypeInfo::flags
RoadTypeFlags flags
Bit mask of road type flags.
Definition road.h:101
IntSqrt
uint32_t IntSqrt(uint32_t num)
Compute the integer square root.
Definition math_func.cpp:42
IsValidAxis
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Definition direction_func.h:43
IsValidDiagDirection
bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Definition direction_func.h:21
DiagDirDiff
DiagDirDiff
Enumeration for the difference between to DiagDirection.
Definition direction_type.h:102
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
AXIS_X
@ AXIS_X
The X axis.
Definition direction_type.h:124
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
economy_func.h
Functions related to the economy.
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
road.h
Road specific functions.
RoadTypeFlag::Catenary
@ Catenary
Bit number for adding catenary.
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:215
HasRoadTypeAvail
bool HasRoadTypeAvail(CompanyID company, RoadType roadtype)
Finds out, whether given company has a given RoadType available for construction.
Definition road.cpp:123
AxisToRoadBits
RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition road_func.h:111
IsValidRoadBits
bool IsValidRoadBits(RoadBits r)
Whether the given roadtype is valid.
Definition road_func.h:23
HasRoadCatenaryDrawn
bool HasRoadCatenaryDrawn(RoadType roadtype)
Test if we should draw road catenary.
Definition road_func.h:145
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:1837
GetRoadTypes
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition road.cpp:238
DrawRoadGroundSprites
void DrawRoadGroundSprites(const TileInfo *ti, RoadBits road, RoadBits tram, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, Roadside roadside, bool snow_or_desert)
Draw road ground sprites.
Definition road_cmd.cpp:1607
ValParamRoadType
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition road.cpp:164
HasRoadCatenary
bool HasRoadCatenary(RoadType roadtype)
Test if a road type has catenary.
Definition road_func.h:135
UpdateCompanyRoadInfrastructure
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
Definition road_cmd.cpp:180
RoadMaintenanceCost
Money RoadMaintenanceCost(RoadType roadtype, uint32_t num, uint32_t total_num)
Calculates the maintenance cost of a number of road bits.
Definition road_func.h:125
IsStraightRoad
bool IsStraightRoad(RoadBits r)
Check if we've got a straight road.
Definition road_func.h:81
AddDateIntroducedRoadTypes
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date)
Add the road types that are to be introduced at the given date.
Definition road.cpp:177
MirrorRoadBits
RoadBits MirrorRoadBits(RoadBits r)
Calculate the mirrored RoadBits.
Definition road_func.h:51
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:1820
DiagDirToRoadBits
RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition road_func.h:96
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:1788
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:1505
RotateRoadBits
RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
Calculate rotated RoadBits.
Definition road_func.h:66
ComplementRoadBits
RoadBits ComplementRoadBits(RoadBits r)
Calculate the complement of a RoadBits value.
Definition road_func.h:37
GetCompanyRoadTypes
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces=true)
Get the road types the given company can build.
Definition road.cpp:210
Roadside
Roadside
The possible road side decorations.
Definition road_map.h:457
RoadBits
RoadBits
Enumeration for the road parts on a tile.
Definition road_type.h:56
ROAD_ALL
@ ROAD_ALL
Full 4-way crossing.
Definition road_type.h:70
ROAD_Y
@ ROAD_Y
Full road along the y-axis (north-west + south-east)
Definition road_type.h:63
ROAD_NW
@ ROAD_NW
North-west part.
Definition road_type.h:58
ROAD_X
@ ROAD_X
Full road along the x-axis (south-west + north-east)
Definition road_type.h:62
ROAD_END
@ ROAD_END
Out-of-range roadbits, used for iterations.
Definition road_type.h:72
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition road_type.h:27
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
transparency.h
Functions related to transparency.
IsInvisibilitySet
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:61
TO_CATENARY
@ TO_CATENARY
catenary
Definition transparency.h:31