Loading

Paste #pm1lubn4r

  1. diff --git a/src/road_type.h b/src/road_type.h
  2. index 5251a53..40b961e 100644
  3. --- a/src/road_type.h
  4. +++ b/src/road_type.h
  5. @@ -29,22 +29,42 @@ enum RoadType {
  6.  DECLARE_POSTFIX_INCREMENT(RoadType)
  7.  template <> struct EnumPropsT<RoadType> : MakeEnumPropsT<RoadType, byte, ROADTYPE_BEGIN, ROADTYPE_END, INVALID_ROADTYPE, 2> {};
  8.  
  9. -/**
  10. - * The different roadtypes we support, but then a bitmask of them
  11. - * @note currently only roadtypes with ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
  12. - */
  13. +// RoadTypes, with ability to get road type, tram type, or look up roadtype given subtype
  14.  enum RoadTypes {
  15. -   ROADTYPES_NONE     = 0,                                ///< No roadtypes
  16. -   ROADTYPES_ROAD     = 1 << ROADTYPE_ROAD,               ///< Road
  17. -   ROADTYPES_TRAM     = 1 << ROADTYPE_TRAM,               ///< Trams
  18. -   ROADTYPES_ALL      = ROADTYPES_ROAD | ROADTYPES_TRAM,  ///< Road + trams
  19. -   ROADTYPES_END,                                         ///< Used for iterations?
  20. -   INVALID_ROADTYPES  = 0xFF,                             ///< Invalid roadtypes
  21. +   ROADTYPES_ROAD_BASE = 0,
  22. +   ROADTYPES_ROAD_LENGTH = 4,    ///< Number of bit
  23. +   ROADTYPES_INVALID_ROAD = 0x7, ///< Road-type denoting 'no road'.
  24. +
  25. +   ROADTYPES_TRAM_BASE = 4,      ///< Start bit of the tram types.
  26. +   ROADTYPES_TRAM_LENGTH = 4,    ///< Number of bits for the tram types.
  27. +   ROADTYPES_INVALID_TRAM = 0x7, ///< Tram-type denoting 'no tram'.
  28.  };
  29. -DECLARE_ENUM_AS_BIT_SET(RoadTypes)
  30. -template <> struct EnumPropsT<RoadTypes> : MakeEnumPropsT<RoadTypes, byte, ROADTYPES_NONE, ROADTYPES_END, INVALID_ROADTYPES, 2> {};
  31. -typedef SimpleTinyEnumT<RoadTypes, byte> RoadTypesByte;
  32.  
  33. +static inline uint8 GetRoadType(RoadTypes rt) {
  34. +   return GB(rt, ROADTYPES_ROAD_BASE, ROADTYPES_ROAD_LENGTH);
  35. +}
  36. +
  37. +static inline uint8 GetTramType(RoadTypes rt) {
  38. +   return GB(rt, ROADTYPES_TRAM_BASE, ROADTYPES_TRAM_LENGTH);
  39. +}
  40. +
  41. +static inline RoadTypes SetRoadType(RoadTypes rt, uint8 road_type) {
  42. +   assert((road_type & ((1 << ROADTYPES_ROAD_LENGTH) - 1)) == road_type);
  43. +   return (RoadTypes)SB(rt, ROADTYPES_ROAD_BASE, ROADTYPES_ROAD_LENGTH, road_type);
  44. +}
  45. +
  46. +static inline RoadTypes SetTramType(RoadTypes rt, uint8 tram_type) {
  47. +   assert((tram_type & ((1 << ROADTYPES_TRAM_LENGTH) - 1)) == tram_type);
  48. +   return (RoadTypes)SB(rt, ROADTYPES_TRAM_BASE, ROADTYPES_TRAM_LENGTH, tram_type);
  49. +}
  50. +
  51. +static inline bool HasRoadType(rt) {
  52. +    return GetRoadType(rt) != ROADTYPES_ROAD_INVALID;
  53. +}
  54. +
  55. +static inline bool HasTramType(rt) {
  56. +    return GetTramType(rt) != ROADTYPES_TRAM_INVALID;
  57. +}
  58.  
  59.  /**
  60.   * Enumeration for the road parts on a tile.
  61. @@ -73,4 +93,19 @@ enum RoadBits {
  62.  DECLARE_ENUM_AS_BIT_SET(RoadBits)
  63.  template <> struct EnumPropsT<RoadBits> : MakeEnumPropsT<RoadBits, byte, ROAD_NONE, ROAD_END, ROAD_NONE, 4> {};
  64.  
  65. +static inline bool RoadSubtypeHasCatenary(uint8 subtype) {
  66. +    if (subtype == 1) {
  67. +        return true;
  68. +    } else {
  69. +        return false;
  70. +    }
  71. +}
  72. +static inline bool TramSubtypeHasCatenary(uint8 subtype) {
  73. +    if (subtype == 1) {
  74. +        return true;
  75. +    } else {
  76. +        return false;
  77. +    }
  78. +}
  79. +
  80.  #endif /* ROAD_TYPE_H */

Comments