road_func.h

Go to the documentation of this file.
00001 /* $Id: road_func.h 18809 2010-01-15 16:41:15Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
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 
00036 static inline bool AreValidRoadTypes(RoadTypes rts)
00037 {
00038   return HasBit(rts, ROADTYPE_ROAD) || HasBit(rts, ROADTYPE_TRAM);
00039 }
00040 
00047 static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
00048 {
00049   return (RoadTypes)(1 << rt);
00050 }
00051 
00061 static inline RoadTypes ComplementRoadTypes(RoadTypes r)
00062 {
00063   return (RoadTypes)(ROADTYPES_ALL ^ r);
00064 }
00065 
00066 
00076 static inline RoadBits ComplementRoadBits(RoadBits r)
00077 {
00078   return (RoadBits)(ROAD_ALL ^ r);
00079 }
00080 
00089 static inline RoadBits MirrorRoadBits(RoadBits r)
00090 {
00091   return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
00092 }
00093 
00103 static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
00104 {
00105   for (; rot > (DiagDirDiff)0; rot--) {
00106     r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
00107   }
00108   return r;
00109 }
00110 
00117 static inline bool IsStraightRoad(RoadBits r)
00118 {
00119   return (r == ROAD_X || r == ROAD_Y);
00120 }
00121 
00131 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
00132 {
00133   return (RoadBits)(ROAD_NW << (3 ^ d));
00134 }
00135 
00145 static inline RoadBits AxisToRoadBits(Axis a)
00146 {
00147   return a == AXIS_X ? ROAD_X : ROAD_Y;
00148 }
00149 
00156 bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts);
00157 
00163 bool ValParamRoadType(const RoadType rt);
00164 
00170 RoadTypes GetCompanyRoadtypes(const CompanyID company);
00171 
00172 void UpdateLevelCrossing(TileIndex tile, bool sound = true);
00173 
00174 #endif /* ROAD_FUNC_H */

Generated on Wed Jan 20 23:38:38 2010 for OpenTTD by  doxygen 1.5.6