# road_func.h

Go to the documentation of this file.

    00001 /* $Id: road_func.h 12390 2008-03-22 10:56:08Z 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 "player_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
    00112 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
    00113 {
    00114   return (RoadBits)(ROAD_NW << (3 ^ d));
    00115 }
    00116
    00126 static inline RoadBits AxisToRoadBits(Axis a)
    00127 {
    00128   return a == AXIS_X ? ROAD_X : ROAD_Y;
    00129 }
    00130
    00137 bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts);
    00138
    00144 bool ValParamRoadType(const RoadType rt);
    00145
    00151 RoadTypes GetPlayerRoadtypes(const PlayerID p);
    00152
    00153 void UpdateLevelCrossing(TileIndex tile, bool sound = true);
    00154
    00155 #endif /* ROAD_FUNC_H */