OpenTTD
road_func.h
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
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/>.
8  */
9 
12 #ifndef ROAD_FUNC_H
13 #define ROAD_FUNC_H
14 
15 #include "core/bitmath_func.hpp"
16 #include "road.h"
17 #include "economy_func.h"
18 #include "transparency.h"
19 
25 static inline bool IsValidRoadBits(RoadBits r)
26 {
27  return r < ROAD_END;
28 }
29 
40 {
41  assert(IsValidRoadBits(r));
42  return (RoadBits)(ROAD_ALL ^ r);
43 }
44 
54 {
55  assert(IsValidRoadBits(r));
56  return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
57 }
58 
69 {
70  assert(IsValidRoadBits(r));
71  for (; rot > (DiagDirDiff)0; rot--) {
72  r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
73  }
74  return r;
75 }
76 
83 static inline bool IsStraightRoad(RoadBits r)
84 {
85  assert(IsValidRoadBits(r));
86  return (r == ROAD_X || r == ROAD_Y);
87 }
88 
99 {
100  assert(IsValidDiagDirection(d));
101  return (RoadBits)(ROAD_NW << (3 ^ d));
102 }
103 
113 static inline RoadBits AxisToRoadBits(Axis a)
114 {
115  assert(IsValidAxis(a));
116  return a == AXIS_X ? ROAD_X : ROAD_Y;
117 }
118 
119 
127 static inline Money RoadMaintenanceCost(RoadType roadtype, uint32 num, uint32 total_num)
128 {
129  assert(roadtype < ROADTYPE_END);
130  return (_price[PR_INFRASTRUCTURE_ROAD] * GetRoadTypeInfo(roadtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 12;
131 }
132 
137 static inline bool HasRoadCatenary(RoadType roadtype)
138 {
139  assert(roadtype < ROADTYPE_END);
140  return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_CATENARY);
141 }
142 
147 static inline bool HasRoadCatenaryDrawn(RoadType roadtype)
148 {
149  return HasRoadCatenary(roadtype) && !IsInvisibilitySet(TO_CATENARY);
150 }
151 
152 bool HasRoadTypeAvail(CompanyID company, RoadType roadtype);
153 bool ValParamRoadType(RoadType roadtype);
154 RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces = true);
155 RoadTypes GetRoadTypes(bool introduces);
157 
158 void UpdateLevelCrossing(TileIndex tile, bool sound = true);
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);
163 
164 #endif /* ROAD_FUNC_H */
bool HasRoadTypeAvail(CompanyID company, RoadType roadtype)
Finds out, whether given company has a given RoadType available for construction. ...
Definition: road.cpp:113
Owner
Enum for all companies/owners.
Definition: company_type.h:20
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:20
Tile information, used while rendering the tile.
Definition: tile_cmd.h:44
static RoadBits ComplementRoadBits(RoadBits r)
Calculate the complement of a RoadBits value.
Definition: road_func.h:39
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:41
static bool HasRoadCatenaryDrawn(RoadType roadtype)
Test if we should draw road catenary.
Definition: road_func.h:147
Full road along the x-axis (south-west + north-east)
Definition: road_type.h:61
Used for iterations.
Definition: road_type.h:31
Road specific functions.
static RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
Calculate rotated RoadBits.
Definition: road_func.h:68
Functions related to bit mathematics.
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition: road.cpp:144
RoadType
The different roadtypes we support.
Definition: road_type.h:27
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition: road.cpp:219
Bit number for adding catenary.
Definition: road.h:41
Out-of-range roadbits, used for iterations.
Definition: road_type.h:71
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:226
static RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition: road_func.h:98
Full 4-way crossing.
Definition: road_type.h:69
void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset)
Draw road underlay and overlay sprites.
Definition: road_cmd.cpp:1501
static Money RoadMaintenanceCost(RoadType roadtype, uint32 num, uint32 total_num)
Calculates the maintenance cost of a number of road bits.
Definition: road_func.h:127
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:55
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces=true)
Get the road types the given company can build.
Definition: road.cpp:190
DiagDirDiff
Enumeration for the difference between to DiagDirection.
void UpdateLevelCrossing(TileIndex tile, bool sound=true)
Sets correct crossing state.
Definition: train_cmd.cpp:1678
catenary
Definition: transparency.h:32
North-west part.
Definition: road_type.h:57
The X axis.
static RoadBits MirrorRoadBits(RoadBits r)
Calculate the mirrored RoadBits.
Definition: road_func.h:53
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Functions related to transparency.
Functions related to the economy.
static bool IsStraightRoad(RoadBits r)
Check if we&#39;ve got a straight road.
Definition: road_func.h:83
static bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
Definition: road_cmd.cpp:199
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date)
Add the road types that are to be introduced at the given date.
Definition: road.cpp:157
int32 Date
The type to store our dates in.
Definition: date_type.h:16
uint32 IntSqrt(uint32 num)
Compute the integer square root.
Definition: math_func.cpp:79
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static bool IsValidRoadBits(RoadBits r)
Whether the given roadtype is valid.
Definition: road_func.h:25
DiagDirection
Enumeration for diagonal directions.
Full road along the y-axis (north-west + south-east)
Definition: road_type.h:62
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren&#39;t in the game menu (there&#39;s never transpar...
Definition: transparency.h:61
static bool HasRoadCatenary(RoadType roadtype)
Test if a road type has catenary.
Definition: road_func.h:137
Axis
Allow incrementing of DiagDirDiff variables.
static RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition: road_func.h:113