road_func.h
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 "direction_type.h"
00018 #include "company_type.h"
00019 #include "tile_type.h"
00020
00026 static inline bool IsValidRoadType(RoadType rt)
00027 {
00028 return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
00029 }
00030
00037 static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
00038 {
00039 return (RoadTypes)(1 << rt);
00040 }
00041
00051 static inline RoadTypes ComplementRoadTypes(RoadTypes r)
00052 {
00053 return (RoadTypes)(ROADTYPES_ALL ^ r);
00054 }
00055
00056
00066 static inline RoadBits ComplementRoadBits(RoadBits r)
00067 {
00068 return (RoadBits)(ROAD_ALL ^ r);
00069 }
00070
00079 static inline RoadBits MirrorRoadBits(RoadBits r)
00080 {
00081 return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
00082 }
00083
00093 static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
00094 {
00095 for (; rot > (DiagDirDiff)0; rot--) {
00096 r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
00097 }
00098 return r;
00099 }
00100
00107 static inline bool IsStraightRoad(RoadBits r)
00108 {
00109 return (r == ROAD_X || r == ROAD_Y);
00110 }
00111
00121 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
00122 {
00123 return (RoadBits)(ROAD_NW << (3 ^ d));
00124 }
00125
00135 static inline RoadBits AxisToRoadBits(Axis a)
00136 {
00137 return a == AXIS_X ? ROAD_X : ROAD_Y;
00138 }
00139
00146 bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts);
00147
00153 bool ValParamRoadType(const RoadType rt);
00154
00160 RoadTypes GetCompanyRoadtypes(const CompanyID company);
00161
00162 void UpdateLevelCrossing(TileIndex tile, bool sound = true);
00163
00164 #endif