diff --git a/src/road_type.h b/src/road_type.h index 5251a53..40b961e 100644 --- a/src/road_type.h +++ b/src/road_type.h @@ -29,22 +29,42 @@ enum RoadType { DECLARE_POSTFIX_INCREMENT(RoadType) template <> struct EnumPropsT : MakeEnumPropsT {}; -/** - * The different roadtypes we support, but then a bitmask of them - * @note currently only roadtypes with ROADTYPE_ROAD and ROADTYPE_TRAM are supported. - */ +// RoadTypes, with ability to get road type, tram type, or look up roadtype given subtype enum RoadTypes { - ROADTYPES_NONE = 0, ///< No roadtypes - ROADTYPES_ROAD = 1 << ROADTYPE_ROAD, ///< Road - ROADTYPES_TRAM = 1 << ROADTYPE_TRAM, ///< Trams - ROADTYPES_ALL = ROADTYPES_ROAD | ROADTYPES_TRAM, ///< Road + trams - ROADTYPES_END, ///< Used for iterations? - INVALID_ROADTYPES = 0xFF, ///< Invalid roadtypes + ROADTYPES_ROAD_BASE = 0, + ROADTYPES_ROAD_LENGTH = 4, ///< Number of bit + ROADTYPES_INVALID_ROAD = 0x7, ///< Road-type denoting 'no road'. + + ROADTYPES_TRAM_BASE = 4, ///< Start bit of the tram types. + ROADTYPES_TRAM_LENGTH = 4, ///< Number of bits for the tram types. + ROADTYPES_INVALID_TRAM = 0x7, ///< Tram-type denoting 'no tram'. }; -DECLARE_ENUM_AS_BIT_SET(RoadTypes) -template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef SimpleTinyEnumT RoadTypesByte; +static inline uint8 GetRoadType(RoadTypes rt) { + return GB(rt, ROADTYPES_ROAD_BASE, ROADTYPES_ROAD_LENGTH); +} + +static inline uint8 GetTramType(RoadTypes rt) { + return GB(rt, ROADTYPES_TRAM_BASE, ROADTYPES_TRAM_LENGTH); +} + +static inline RoadTypes SetRoadType(RoadTypes rt, uint8 road_type) { + assert((road_type & ((1 << ROADTYPES_ROAD_LENGTH) - 1)) == road_type); + return (RoadTypes)SB(rt, ROADTYPES_ROAD_BASE, ROADTYPES_ROAD_LENGTH, road_type); +} + +static inline RoadTypes SetTramType(RoadTypes rt, uint8 tram_type) { + assert((tram_type & ((1 << ROADTYPES_TRAM_LENGTH) - 1)) == tram_type); + return (RoadTypes)SB(rt, ROADTYPES_TRAM_BASE, ROADTYPES_TRAM_LENGTH, tram_type); +} + +static inline bool HasRoadType(rt) { + return GetRoadType(rt) != ROADTYPES_ROAD_INVALID; +} + +static inline bool HasTramType(rt) { + return GetTramType(rt) != ROADTYPES_TRAM_INVALID; +} /** * Enumeration for the road parts on a tile. @@ -73,4 +93,19 @@ enum RoadBits { DECLARE_ENUM_AS_BIT_SET(RoadBits) template <> struct EnumPropsT : MakeEnumPropsT {}; +static inline bool RoadSubtypeHasCatenary(uint8 subtype) { + if (subtype == 1) { + return true; + } else { + return false; + } +} +static inline bool TramSubtypeHasCatenary(uint8 subtype) { + if (subtype == 1) { + return true; + } else { + return false; + } +} + #endif /* ROAD_TYPE_H */