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 #include "economy_func.h"
00021
00031 #define FOR_EACH_SET_ROADTYPE(var, road_types) FOR_EACH_SET_BIT_EX(RoadType, var, RoadTypes, road_types)
00032
00038 static inline bool IsValidRoadType(RoadType rt)
00039 {
00040 return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
00041 }
00042
00049 static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
00050 {
00051 return (RoadTypes)(1 << rt);
00052 }
00053
00062 static inline RoadTypes ComplementRoadTypes(RoadTypes r)
00063 {
00064 return (RoadTypes)(ROADTYPES_ALL ^ r);
00065 }
00066
00067
00077 static inline RoadBits ComplementRoadBits(RoadBits r)
00078 {
00079 return (RoadBits)(ROAD_ALL ^ r);
00080 }
00081
00090 static inline RoadBits MirrorRoadBits(RoadBits r)
00091 {
00092 return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
00093 }
00094
00104 static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
00105 {
00106 for (; rot > (DiagDirDiff)0; rot--) {
00107 r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
00108 }
00109 return r;
00110 }
00111
00118 static inline bool IsStraightRoad(RoadBits r)
00119 {
00120 return (r == ROAD_X || r == ROAD_Y);
00121 }
00122
00132 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
00133 {
00134 return (RoadBits)(ROAD_NW << (3 ^ d));
00135 }
00136
00146 static inline RoadBits AxisToRoadBits(Axis a)
00147 {
00148 return a == AXIS_X ? ROAD_X : ROAD_Y;
00149 }
00150
00151
00158 static inline Money RoadMaintenanceCost(RoadType roadtype, uint32 num)
00159 {
00160 assert(roadtype < ROADTYPE_END);
00161 return (_price[PR_INFRASTRUCTURE_ROAD] * (roadtype == ROADTYPE_TRAM ? 3 : 2) * num * (1 + IntSqrt(num))) >> 9;
00162 }
00163
00164 bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts);
00165 bool ValParamRoadType(const RoadType rt);
00166 RoadTypes GetCompanyRoadtypes(const CompanyID company);
00167
00168 void UpdateLevelCrossing(TileIndex tile, bool sound = true);
00169
00170 #endif