road_func.h

Go to the documentation of this file.
00001 /* $Id: road_func.h 14422 2008-09-30 20:51:04Z rubidium $ */
00002 
00005 #ifndef ROAD_FUNC_H
00006 #define ROAD_FUNC_H
00007 
00008 #include "core/bitmath_func.hpp"
00009 #include "road_type.h"
00010 #include "direction_func.h"
00011 #include "company_type.h"
00012 
00018 static inline bool IsValidRoadType(RoadType rt)
00019 {
00020   return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
00021 }
00022 
00028 static inline bool AreValidRoadTypes(RoadTypes rts)
00029 {
00030   return HasBit(rts, ROADTYPE_ROAD) || HasBit(rts, ROADTYPE_TRAM);
00031 }
00032 
00039 static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
00040 {
00041   return (RoadTypes)(1 << rt);
00042 }
00043 
00053 static inline RoadTypes ComplementRoadTypes(RoadTypes r)
00054 {
00055   return (RoadTypes)(ROADTYPES_ALL ^ r);
00056 }
00057 
00058 
00068 static inline RoadBits ComplementRoadBits(RoadBits r)
00069 {
00070   return (RoadBits)(ROAD_ALL ^ r);
00071 }
00072 
00081 static inline RoadBits MirrorRoadBits(RoadBits r)
00082 {
00083   return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
00084 }
00085 
00095 static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
00096 {
00097   for (; rot > (DiagDirDiff)0; rot--){
00098     r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
00099   }
00100   return r;
00101 }
00102 
00109 static inline bool IsStraightRoad(RoadBits r)
00110 {
00111   return (r == ROAD_X || r == ROAD_Y);
00112 }
00113 
00123 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
00124 {
00125   return (RoadBits)(ROAD_NW << (3 ^ d));
00126 }
00127 
00137 static inline RoadBits AxisToRoadBits(Axis a)
00138 {
00139   return a == AXIS_X ? ROAD_X : ROAD_Y;
00140 }
00141 
00148 bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts);
00149 
00155 bool ValParamRoadType(const RoadType rt);
00156 
00162 RoadTypes GetCompanyRoadtypes(const CompanyID company);
00163 
00164 void UpdateLevelCrossing(TileIndex tile, bool sound = true);
00165 
00166 #endif /* ROAD_FUNC_H */

Generated on Thu Oct 1 11:03:16 2009 for OpenTTD by  doxygen 1.5.6