Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef ROAD_FUNC_H
00013 #define ROAD_FUNC_H
00014
00015 #include "core/bitmath_func.hpp"
00016 #include "road_type.h"
00017 #include "economy_func.h"
00018
00028 #define FOR_EACH_SET_ROADTYPE(var, road_types) FOR_EACH_SET_BIT_EX(RoadType, var, RoadTypes, road_types)
00029
00035 static inline bool IsValidRoadType(RoadType rt)
00036 {
00037 return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
00038 }
00039
00045 static inline bool IsValidRoadBits(RoadBits r)
00046 {
00047 return r < ROAD_END;
00048 }
00049
00056 static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
00057 {
00058 assert(IsValidRoadType(rt));
00059 return (RoadTypes)(1 << rt);
00060 }
00061
00070 static inline RoadTypes ComplementRoadTypes(RoadTypes r)
00071 {
00072 return (RoadTypes)(ROADTYPES_ALL ^ r);
00073 }
00074
00075
00085 static inline RoadBits ComplementRoadBits(RoadBits r)
00086 {
00087 assert(IsValidRoadBits(r));
00088 return (RoadBits)(ROAD_ALL ^ r);
00089 }
00090
00099 static inline RoadBits MirrorRoadBits(RoadBits r)
00100 {
00101 assert(IsValidRoadBits(r));
00102 return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
00103 }
00104
00114 static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
00115 {
00116 assert(IsValidRoadBits(r));
00117 for (; rot > (DiagDirDiff)0; rot--) {
00118 r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
00119 }
00120 return r;
00121 }
00122
00129 static inline bool IsStraightRoad(RoadBits r)
00130 {
00131 assert(IsValidRoadBits(r));
00132 return (r == ROAD_X || r == ROAD_Y);
00133 }
00134
00144 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
00145 {
00146 assert(IsValidDiagDirection(d));
00147 return (RoadBits)(ROAD_NW << (3 ^ d));
00148 }
00149
00159 static inline RoadBits AxisToRoadBits(Axis a)
00160 {
00161 assert(IsValidAxis(a));
00162 return a == AXIS_X ? ROAD_X : ROAD_Y;
00163 }
00164
00165
00172 static inline Money RoadMaintenanceCost(RoadType roadtype, uint32 num)
00173 {
00174 assert(IsValidRoadType(roadtype));
00175 return (_price[PR_INFRASTRUCTURE_ROAD] * (roadtype == ROADTYPE_TRAM ? 3 : 2) * num * (1 + IntSqrt(num))) >> 9;
00176 }
00177
00178 bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts);
00179 bool ValParamRoadType(const RoadType rt);
00180 RoadTypes GetCompanyRoadtypes(const CompanyID company);
00181
00182 void UpdateLevelCrossing(TileIndex tile, bool sound = true);
00183
00184 #endif