Codefix: Documentation comment in IndustryDirectoryWindow (#13059)
[openttd-github.git] / src / road_func.h
blobed3e3db6d0282303f3b63224854c8d61fa8b2b5e
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 */
8 /** @file road_func.h Functions related to roads. */
10 #ifndef ROAD_FUNC_H
11 #define ROAD_FUNC_H
13 #include "core/bitmath_func.hpp"
14 #include "road.h"
15 #include "economy_func.h"
16 #include "transparency.h"
18 /**
19 * Whether the given roadtype is valid.
20 * @param r the roadtype to check for validness
21 * @return true if and only if valid
23 inline bool IsValidRoadBits(RoadBits r)
25 return r < ROAD_END;
28 /**
29 * Calculate the complement of a RoadBits value
31 * Simply flips all bits in the RoadBits value to get the complement
32 * of the RoadBits.
34 * @param r The given RoadBits value
35 * @return the complement
37 inline RoadBits ComplementRoadBits(RoadBits r)
39 assert(IsValidRoadBits(r));
40 return (RoadBits)(ROAD_ALL ^ r);
43 /**
44 * Calculate the mirrored RoadBits
46 * Simply move the bits to their new position.
48 * @param r The given RoadBits value
49 * @return the mirrored
51 inline RoadBits MirrorRoadBits(RoadBits r)
53 assert(IsValidRoadBits(r));
54 return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
57 /**
58 * Calculate rotated RoadBits
60 * Move the Roadbits clockwise until they are in their final position.
62 * @param r The given RoadBits value
63 * @param rot The given Rotation angle
64 * @return the rotated
66 inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
68 assert(IsValidRoadBits(r));
69 for (; rot > (DiagDirDiff)0; rot--) {
70 r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
72 return r;
75 /**
76 * Check if we've got a straight road
78 * @param r The given RoadBits
79 * @return true if we've got a straight road
81 inline bool IsStraightRoad(RoadBits r)
83 assert(IsValidRoadBits(r));
84 return (r == ROAD_X || r == ROAD_Y);
87 /**
88 * Create the road-part which belongs to the given DiagDirection
90 * This function returns a RoadBits value which belongs to
91 * the given DiagDirection.
93 * @param d The DiagDirection
94 * @return The result RoadBits which the selected road-part set
96 inline RoadBits DiagDirToRoadBits(DiagDirection d)
98 assert(IsValidDiagDirection(d));
99 return (RoadBits)(ROAD_NW << (3 ^ d));
103 * Create the road-part which belongs to the given Axis
105 * This function returns a RoadBits value which belongs to
106 * the given Axis.
108 * @param a The Axis
109 * @return The result RoadBits which the selected road-part set
111 inline RoadBits AxisToRoadBits(Axis a)
113 assert(IsValidAxis(a));
114 return a == AXIS_X ? ROAD_X : ROAD_Y;
119 * Calculates the maintenance cost of a number of road bits.
120 * @param roadtype Road type to get the cost for.
121 * @param num Number of road bits.
122 * @param total_num Total number of road bits of all road/tram-types.
123 * @return Total cost.
125 inline Money RoadMaintenanceCost(RoadType roadtype, uint32_t num, uint32_t total_num)
127 assert(roadtype < ROADTYPE_END);
128 return (_price[PR_INFRASTRUCTURE_ROAD] * GetRoadTypeInfo(roadtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 12;
132 * Test if a road type has catenary
133 * @param roadtype Road type to test
135 inline bool HasRoadCatenary(RoadType roadtype)
137 assert(roadtype < ROADTYPE_END);
138 return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_CATENARY);
142 * Test if we should draw road catenary
143 * @param roadtype Road type to test
145 inline bool HasRoadCatenaryDrawn(RoadType roadtype)
147 return HasRoadCatenary(roadtype) && !IsInvisibilitySet(TO_CATENARY);
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, TimerGameCalendar::Date date);
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);
161 struct TileInfo;
162 enum Roadside : uint8_t;
163 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);
164 void DrawRoadGroundSprites(const TileInfo *ti, RoadBits road, RoadBits tram, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, Roadside roadside, bool snow_or_desert);
166 #endif /* ROAD_FUNC_H */