src/road.h
branchNewGRF_ports
changeset 6743 cabfaa4a0295
parent 6719 4cc327ad39d5
child 6870 ca3fd1fbe311
equal deleted inserted replaced
6742:1337d6c9b97b 6743:cabfaa4a0295
     7 
     7 
     8 #include "helpers.hpp"
     8 #include "helpers.hpp"
     9 
     9 
    10 /**
    10 /**
    11  * The different roadtypes we support
    11  * The different roadtypes we support
    12  * @note currently only ROADTYPE_ROAD is supported.
    12  *
       
    13  * @note currently only ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
    13  */
    14  */
    14 enum RoadType {
    15 enum RoadType {
    15 	ROADTYPE_ROAD = 0,
    16 	ROADTYPE_ROAD = 0,      ///< Basic road type
    16 	ROADTYPE_TRAM = 1,
    17 	ROADTYPE_TRAM = 1,      ///< Trams
    17 	ROADTYPE_HWAY = 2, ///< Only a placeholder. Not sure what we are going to do with this road type.
    18 	ROADTYPE_HWAY = 2,      ///< Only a placeholder. Not sure what we are going to do with this road type.
    18 	ROADTYPE_END,
    19 	ROADTYPE_END,           ///< Used for iterations
    19 	INVALID_ROADTYPE = 0xFF
    20 	INVALID_ROADTYPE = 0xFF ///< flag for invalid roadtype
    20 };
    21 };
    21 DECLARE_POSTFIX_INCREMENT(RoadType);
    22 DECLARE_POSTFIX_INCREMENT(RoadType);
    22 
    23 
    23 /**
    24 /**
    24  * The different roadtypes we support, but then a bitmask of them
    25  * The different roadtypes we support, but then a bitmask of them
    25  * @note currently only ROADTYPES_ROAD is supported.
    26  * @note currently only roadtypes with ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
    26  */
    27  */
    27 enum RoadTypes {
    28 enum RoadTypes {
    28 	ROADTYPES_NONE     = 0,
    29 	ROADTYPES_NONE     = 0,                                                 ///< No roadtypes
    29 	ROADTYPES_ROAD     = 1 << ROADTYPE_ROAD,
    30 	ROADTYPES_ROAD     = 1 << ROADTYPE_ROAD,                                ///< Road
    30 	ROADTYPES_TRAM     = 1 << ROADTYPE_TRAM,
    31 	ROADTYPES_TRAM     = 1 << ROADTYPE_TRAM,                                ///< Trams
    31 	ROADTYPES_HWAY     = 1 << ROADTYPE_HWAY,
    32 	ROADTYPES_HWAY     = 1 << ROADTYPE_HWAY,                                ///< Highway (or whatever substitute)
    32 	ROADTYPES_ROADTRAM = ROADTYPES_ROAD | ROADTYPES_TRAM,
    33 	ROADTYPES_ROADTRAM = ROADTYPES_ROAD | ROADTYPES_TRAM,                   ///< Road + trams
    33 	ROADTYPES_ROADHWAY = ROADTYPES_ROAD | ROADTYPES_HWAY,
    34 	ROADTYPES_ROADHWAY = ROADTYPES_ROAD | ROADTYPES_HWAY,                   ///< Road + highway (or whatever substitute)
    34 	ROADTYPES_TRAMHWAY = ROADTYPES_TRAM | ROADTYPES_HWAY,
    35 	ROADTYPES_TRAMHWAY = ROADTYPES_TRAM | ROADTYPES_HWAY,                   ///< Trams + highway (or whatever substitute)
    35 	ROADTYPES_ALL      = ROADTYPES_ROAD | ROADTYPES_TRAM | ROADTYPES_HWAY,
    36 	ROADTYPES_ALL      = ROADTYPES_ROAD | ROADTYPES_TRAM | ROADTYPES_HWAY,  ///< Road + trams + highway (or whatever substitute)
    36 };
    37 };
    37 DECLARE_ENUM_AS_BIT_SET(RoadTypes);
    38 DECLARE_ENUM_AS_BIT_SET(RoadTypes);
    38 
    39 
    39 /**
    40 /**
    40  * Whether the given roadtype is valid.
    41  * Whether the given roadtype is valid.
    56 	return HASBIT(rts, ROADTYPE_ROAD) || HASBIT(rts, ROADTYPE_TRAM);
    57 	return HASBIT(rts, ROADTYPE_ROAD) || HASBIT(rts, ROADTYPE_TRAM);
    57 }
    58 }
    58 
    59 
    59 /**
    60 /**
    60  * Maps a RoadType to the corresponding RoadTypes value
    61  * Maps a RoadType to the corresponding RoadTypes value
       
    62  *
       
    63  * @param rt the roadtype to get the roadtypes from
       
    64  * @return the roadtypes with the given roadtype
    61  */
    65  */
    62 static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
    66 static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
    63 {
    67 {
    64 	return (RoadTypes)(1 << rt);
    68 	return (RoadTypes)(1 << rt);
    65 }
    69 }
    66 
    70 
       
    71 /**
       
    72  * Returns the RoadTypes which are not present in the given RoadTypes
       
    73  *
       
    74  * This function returns the complement of a given RoadTypes.
       
    75  *
       
    76  * @param r The given RoadTypes
       
    77  * @return The complement of the given RoadTypes
       
    78  * @note The unused value ROADTYPES_HWAY will be used, too.
       
    79  */
    67 static inline RoadTypes ComplementRoadTypes(RoadTypes r)
    80 static inline RoadTypes ComplementRoadTypes(RoadTypes r)
    68 {
    81 {
    69 	return (RoadTypes)(ROADTYPES_ALL ^ r);
    82 	return (RoadTypes)(ROADTYPES_ALL ^ r);
    70 }
    83 }
    71 
    84 
       
    85 /**
       
    86  * Enumeration for the road parts on a tile.
       
    87  *
       
    88  * This enumeration defines the possible road parts which
       
    89  * can be build on a tile.
       
    90  */
    72 enum RoadBits {
    91 enum RoadBits {
    73 	ROAD_NONE = 0U,
    92 	ROAD_NONE = 0U,                  ///< No road-part is build
    74 	ROAD_NW  = 1U,
    93 	ROAD_NW   = 1U,                  ///< North-west part
    75 	ROAD_SW  = 2U,
    94 	ROAD_SW   = 2U,                  ///< South-west part
    76 	ROAD_SE  = 4U,
    95 	ROAD_SE   = 4U,                  ///< South-east part
    77 	ROAD_NE  = 8U,
    96 	ROAD_NE   = 8U,                  ///< North-east part
    78 	ROAD_X   = ROAD_SW | ROAD_NE,
    97 	ROAD_X    = ROAD_SW | ROAD_NE,   ///< Full road along the x-axis (south-west + north-east)
    79 	ROAD_Y   = ROAD_NW | ROAD_SE,
    98 	ROAD_Y    = ROAD_NW | ROAD_SE,   ///< Full road along the y-axis (north-west + south-east)
    80 	ROAD_ALL = ROAD_X  | ROAD_Y
    99 	ROAD_ALL  = ROAD_X  | ROAD_Y     ///< Full 4-way crossing
    81 };
   100 };
    82 
   101 
    83 DECLARE_ENUM_AS_BIT_SET(RoadBits);
   102 DECLARE_ENUM_AS_BIT_SET(RoadBits);
    84 
   103 
       
   104 /**
       
   105  * Calculate the complement of a RoadBits value
       
   106  *
       
   107  * Simply flips all bits in the RoadBits value to get the complement
       
   108  * of the RoadBits.
       
   109  *
       
   110  * @param r The given RoadBits value
       
   111  * @return the complement
       
   112  */
    85 static inline RoadBits ComplementRoadBits(RoadBits r)
   113 static inline RoadBits ComplementRoadBits(RoadBits r)
    86 {
   114 {
    87 	return (RoadBits)(ROAD_ALL ^ r);
   115 	return (RoadBits)(ROAD_ALL ^ r);
    88 }
   116 }
    89 
   117 
       
   118 /**
       
   119  * Create the road-part which belongs to the given DiagDirection
       
   120  *
       
   121  * This function returns a RoadBits value which belongs to
       
   122  * the given DiagDirection.
       
   123  *
       
   124  * @param d The DiagDirection
       
   125  * @return The result RoadBits which the selected road-part set
       
   126  */
    90 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
   127 static inline RoadBits DiagDirToRoadBits(DiagDirection d)
    91 {
   128 {
    92 	return (RoadBits)(1U << (3 ^ d));
   129 	return (RoadBits)(1U << (3 ^ d));
    93 }
   130 }
    94 
   131 
    95 /** Checks whether the trackdir means that we are reversing */
   132 /**
       
   133  * Checks whether the trackdir means that we are reversing.
       
   134  * @param dir the trackdir to check
       
   135  * @return true if it is a reversing road trackdir
       
   136  */
    96 static inline bool IsReversingRoadTrackdir(Trackdir dir)
   137 static inline bool IsReversingRoadTrackdir(Trackdir dir)
    97 {
   138 {
    98 	return (dir & 0x07) >= 6;
   139 	return (dir & 0x07) >= 6;
    99 }
   140 }
   100 
   141 
   101 /** Checks whether the given trackdir is a straight road */
   142 /**
       
   143  * Checks whether the given trackdir is a straight road
       
   144  * @param dir the trackdir to check
       
   145  * @return true if it is a straight road trackdir
       
   146  */
   102 static inline bool IsStraightRoadTrackdir(Trackdir dir)
   147 static inline bool IsStraightRoadTrackdir(Trackdir dir)
   103 {
   148 {
   104 	return (dir & 0x06) == 0;
   149 	return (dir & 0x06) == 0;
   105 }
   150 }
   106 
   151 
   113  * @param rt        the road type to remove the bits from
   158  * @param rt        the road type to remove the bits from
   114  * @return true when it is allowed to remove the road bits
   159  * @return true when it is allowed to remove the road bits
   115  */
   160  */
   116 bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt);
   161 bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt);
   117 
   162 
       
   163 /**
       
   164  * Draw the catenary for tram road bits
       
   165  * @param ti   information about the tile (position, slope)
       
   166  * @param tram the roadbits to draw the catenary for
       
   167  */
   118 void DrawTramCatenary(TileInfo *ti, RoadBits tram);
   168 void DrawTramCatenary(TileInfo *ti, RoadBits tram);
   119 
   169 
   120 #endif /* ROAD_H */
   170 #endif /* ROAD_H */