bridge_map.h
changeset 3369 00c2ca209a89
parent 3355 a653b8e47f27
child 3466 4e819837395e
equal deleted inserted replaced
3368:57034dcd7978 3369:00c2ca209a89
    11 #include "tile.h"
    11 #include "tile.h"
    12 
    12 
    13 
    13 
    14 static inline bool IsBridge(TileIndex t)
    14 static inline bool IsBridge(TileIndex t)
    15 {
    15 {
       
    16 	assert(IsTileType(t, MP_TUNNELBRIDGE));
    16 	return HASBIT(_m[t].m5, 7);
    17 	return HASBIT(_m[t].m5, 7);
    17 }
    18 }
    18 
    19 
    19 static inline bool IsBridgeTile(TileIndex t)
    20 static inline bool IsBridgeTile(TileIndex t)
    20 {
    21 {
    22 }
    23 }
    23 
    24 
    24 
    25 
    25 static inline bool IsBridgeRamp(TileIndex t)
    26 static inline bool IsBridgeRamp(TileIndex t)
    26 {
    27 {
       
    28 	assert(IsBridgeTile(t));
    27 	return !HASBIT(_m[t].m5, 6);
    29 	return !HASBIT(_m[t].m5, 6);
    28 }
    30 }
    29 
    31 
    30 static inline bool IsBridgeMiddle(TileIndex t)
    32 static inline bool IsBridgeMiddle(TileIndex t)
    31 {
    33 {
       
    34 	assert(IsBridgeTile(t));
    32 	return HASBIT(_m[t].m5, 6);
    35 	return HASBIT(_m[t].m5, 6);
    33 }
    36 }
    34 
    37 
    35 
    38 
    36 /**
    39 /**
    37  * Determines which piece of a bridge is contained in the current tile
    40  * Determines which piece of a bridge is contained in the current tile
    38  * @param tile The tile to analyze
    41  * @param tile The tile to analyze
    39  * @return the piece
    42  * @return the piece
    40  */
    43  */
    41 static inline uint GetBridgePiece(TileIndex tile)
    44 static inline uint GetBridgePiece(TileIndex t)
    42 {
    45 {
    43 	return GB(_m[tile].m2, 0, 4);
    46 	assert(IsBridgeMiddle(t));
       
    47 	return GB(_m[t].m2, 0, 4);
    44 }
    48 }
    45 
    49 
    46 
    50 
    47 /**
    51 /**
    48  * Determines the type of bridge on a tile
    52  * Determines the type of bridge on a tile
    49  * @param tile The tile to analyze
    53  * @param tile The tile to analyze
    50  * @return The bridge type
    54  * @return The bridge type
    51  */
    55  */
    52 static inline uint GetBridgeType(TileIndex tile)
    56 static inline uint GetBridgeType(TileIndex t)
    53 {
    57 {
    54 	return GB(_m[tile].m2, 4, 4);
    58 	assert(IsBridgeTile(t));
       
    59 	return GB(_m[t].m2, 4, 4);
    55 }
    60 }
    56 
    61 
    57 
    62 
    58 /**
    63 /**
    59  * Get the direction pointing onto the bridge
    64  * Get the direction pointing onto the bridge
    60  */
    65  */
    61 static inline DiagDirection GetBridgeRampDirection(TileIndex t)
    66 static inline DiagDirection GetBridgeRampDirection(TileIndex t)
    62 {
    67 {
       
    68 	assert(IsBridgeRamp(t));
    63 	/* Heavy wizardry to convert the X/Y (bit 0) + N/S (bit 5) encoding of
    69 	/* Heavy wizardry to convert the X/Y (bit 0) + N/S (bit 5) encoding of
    64 	 * bridges to a DiagDirection
    70 	 * bridges to a DiagDirection
    65 	 */
    71 	 */
    66 	return (DiagDirection)((6 - (_m[t].m5 >> 4 & 2) - (_m[t].m5 & 1)) % 4);
    72 	return (DiagDirection)((6 - (_m[t].m5 >> 4 & 2) - (_m[t].m5 & 1)) % 4);
    67 }
    73 }
    68 
    74 
    69 
    75 
    70 static inline Axis GetBridgeAxis(TileIndex t)
    76 static inline Axis GetBridgeAxis(TileIndex t)
    71 {
    77 {
       
    78 	assert(IsBridgeMiddle(t));
    72 	return (Axis)GB(_m[t].m5, 0, 1);
    79 	return (Axis)GB(_m[t].m5, 0, 1);
    73 }
    80 }
    74 
    81 
    75 
    82 
    76 static inline TransportType GetBridgeTransportType(TileIndex t)
    83 static inline TransportType GetBridgeTransportType(TileIndex t)
    77 {
    84 {
       
    85 	assert(IsBridgeTile(t));
    78 	return (TransportType)GB(_m[t].m5, 1, 2);
    86 	return (TransportType)GB(_m[t].m5, 1, 2);
    79 }
    87 }
    80 
    88 
    81 
    89 
    82 static inline bool IsClearUnderBridge(TileIndex t)
    90 static inline bool IsClearUnderBridge(TileIndex t)
    83 {
    91 {
       
    92 	assert(IsBridgeMiddle(t));
    84 	return GB(_m[t].m5, 3, 3) == 0;
    93 	return GB(_m[t].m5, 3, 3) == 0;
    85 }
    94 }
    86 
    95 
    87 static inline bool IsWaterUnderBridge(TileIndex t)
    96 static inline bool IsWaterUnderBridge(TileIndex t)
    88 {
    97 {
       
    98 	assert(IsBridgeMiddle(t));
    89 	return GB(_m[t].m5, 3, 3) == 1;
    99 	return GB(_m[t].m5, 3, 3) == 1;
    90 }
   100 }
    91 
   101 
    92 
   102 
    93 static inline bool IsTransportUnderBridge(TileIndex t)
   103 static inline bool IsTransportUnderBridge(TileIndex t)
    94 {
   104 {
       
   105 	assert(IsBridgeMiddle(t));
    95 	return HASBIT(_m[t].m5, 5);
   106 	return HASBIT(_m[t].m5, 5);
    96 }
   107 }
    97 
   108 
    98 static inline TransportType GetTransportTypeUnderBridge(TileIndex t)
   109 static inline TransportType GetTransportTypeUnderBridge(TileIndex t)
    99 {
   110 {
       
   111 	assert(IsTransportUnderBridge(t));
   100 	return (TransportType)GB(_m[t].m5, 3, 2);
   112 	return (TransportType)GB(_m[t].m5, 3, 2);
   101 }
   113 }
   102 
   114 
   103 static inline RoadBits GetRoadBitsUnderBridge(TileIndex t)
   115 static inline RoadBits GetRoadBitsUnderBridge(TileIndex t)
   104 {
   116 {
       
   117 	assert(GetTransportTypeUnderBridge(t) == TRANSPORT_ROAD);
   105 	return GetBridgeAxis(t) == AXIS_X ? ROAD_Y : ROAD_X;
   118 	return GetBridgeAxis(t) == AXIS_X ? ROAD_Y : ROAD_X;
   106 }
   119 }
   107 
   120 
   108 static inline TrackBits GetRailBitsUnderBridge(TileIndex t)
   121 static inline TrackBits GetRailBitsUnderBridge(TileIndex t)
   109 {
   122 {
       
   123 	assert(GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL);
   110 	return GetBridgeAxis(t) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X;
   124 	return GetBridgeAxis(t) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X;
   111 }
   125 }
   112 
   126 
   113 
   127 
   114 /**
   128 /**
   129 
   143 
   130 uint GetBridgeHeight(TileIndex t);
   144 uint GetBridgeHeight(TileIndex t);
   131 
   145 
   132 static inline void SetClearUnderBridge(TileIndex t)
   146 static inline void SetClearUnderBridge(TileIndex t)
   133 {
   147 {
       
   148 	assert(IsBridgeMiddle(t));
   134 	SetTileOwner(t, OWNER_NONE);
   149 	SetTileOwner(t, OWNER_NONE);
   135 	SB(_m[t].m5, 3, 3, 0 << 2 | 0);
   150 	SB(_m[t].m5, 3, 3, 0 << 2 | 0);
   136 }
   151 }
   137 
   152 
   138 static inline void SetWaterUnderBridge(TileIndex t)
   153 static inline void SetWaterUnderBridge(TileIndex t)
   139 {
   154 {
       
   155 	assert(IsBridgeMiddle(t));
   140 	SetTileOwner(t, OWNER_WATER);
   156 	SetTileOwner(t, OWNER_WATER);
   141 	SB(_m[t].m5, 3, 3, 0 << 2 | 1);
   157 	SB(_m[t].m5, 3, 3, 0 << 2 | 1);
   142 }
   158 }
   143 
   159 
   144 static inline void SetRailUnderBridge(TileIndex t, Owner o, RailType r)
   160 static inline void SetRailUnderBridge(TileIndex t, Owner o, RailType r)
   145 {
   161 {
       
   162 	assert(IsBridgeMiddle(t));
   146 	SetTileOwner(t, o);
   163 	SetTileOwner(t, o);
   147 	SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_RAIL);
   164 	SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_RAIL);
   148 	SB(_m[t].m3, 0, 4, r);
   165 	SB(_m[t].m3, 0, 4, r);
   149 }
   166 }
   150 
   167 
   151 static inline void SetRoadUnderBridge(TileIndex t, Owner o)
   168 static inline void SetRoadUnderBridge(TileIndex t, Owner o)
   152 {
   169 {
       
   170 	assert(IsBridgeMiddle(t));
   153 	SetTileOwner(t, o);
   171 	SetTileOwner(t, o);
   154 	SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD);
   172 	SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD);
   155 }
   173 }
   156 
   174 
   157 
   175