# road_func.h

Go to the documentation of this file.

    00001 /* $Id: road_func.h 26105 2013-11-25 13:16:06Z 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 "economy_func.h"
    00018
    00028 #define FOR_EACH_SET_ROADTYPE(var, road_types) FOR_EACH_SET_BIT_EX(RoadType, var, RoadTypes, road_types)
    00029
    00035 static inline bool IsValidRoadType(RoadType rt)
    00036 {
    00037   return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
    00038 }
    00039
    00045 static inline bool IsValidRoadBits(RoadBits r)
    00046 {
    00047   return r < ROAD_END;
    00048 }
    00049
    00056 static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
    00057 {
    00058   assert(IsValidRoadType(rt));
    00059   return (RoadTypes)(1 << rt);
    00060 }
    00061
    00070 static inline RoadTypes ComplementRoadTypes(RoadTypes r)
    00071 {
    00072   return (RoadTypes)(ROADTYPES_ALL ^ r);
    00073 }
    00074
    00075
    00085 static inline RoadBits ComplementRoadBits(RoadBits r)
    00086 {
    00087   assert(IsValidRoadBits(r));
    00088   return (RoadBits)(ROAD_ALL ^ r);
    00089 }
    00090
    00099 static inline RoadBits MirrorRoadBits(RoadBits r)
    00100 {
    00101   assert(IsValidRoadBits(r));
    00102   return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
    00103 }
    00104
    00114 static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
    00115 {
    00116   assert(IsValidRoadBits(r));
    00117   for (; rot > (DiagDirDiff)0; rot--) {
    00118     r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
    00119   }
    00120   return r;
    00121 }
    00122
    00129 static inline bool IsStraightRoad(RoadBits r)
    00130 {
    00131   assert(IsValidRoadBits(r));
    00132   return (r == ROAD_X || r == ROAD_Y);
    00133 }
    00134
    00144 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
    00145 {
    00146   assert(IsValidDiagDirection(d));
    00147   return (RoadBits)(ROAD_NW << (3 ^ d));
    00148 }
    00149
    00159 static inline RoadBits AxisToRoadBits(Axis a)
    00160 {
    00161   assert(IsValidAxis(a));
    00162   return a == AXIS_X ? ROAD_X : ROAD_Y;
    00163 }
    00164
    00165
    00172 static inline Money RoadMaintenanceCost(RoadType roadtype, uint32 num)
    00173 {
    00174   assert(IsValidRoadType(roadtype));
    00175   return (_price[PR_INFRASTRUCTURE_ROAD] * (roadtype == ROADTYPE_TRAM ? 3 : 2) * num * (1 + IntSqrt(num))) >> 9; // 2 bits fraction for the multiplier and 7 bits scaling.
    00176 }
    00177
    00178 bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts);
    00179 bool ValParamRoadType(const RoadType rt);
    00180 RoadTypes GetCompanyRoadtypes(const CompanyID company);
    00181
    00182 void UpdateLevelCrossing(TileIndex tile, bool sound = true);
    00183
    00184 #endif /* ROAD_FUNC_H */