bridge_map.h
changeset 5385 3868f2e6db9b
parent 4666 172a0cdf28a6
child 5410 2dae82c6ea63
equal deleted inserted replaced
5384:10b6d955e1ac 5385:3868f2e6db9b
     7 #include "macros.h"
     7 #include "macros.h"
     8 #include "map.h"
     8 #include "map.h"
     9 #include "rail.h"
     9 #include "rail.h"
    10 #include "road_map.h"
    10 #include "road_map.h"
    11 #include "tile.h"
    11 #include "tile.h"
       
    12 
       
    13 
       
    14 void DrawBridgeMiddle(const TileInfo* ti); // XXX
    12 
    15 
    13 
    16 
    14 static inline bool IsBridge(TileIndex t)
    17 static inline bool IsBridge(TileIndex t)
    15 {
    18 {
    16 	assert(IsTileType(t, MP_TUNNELBRIDGE));
    19 	assert(IsTileType(t, MP_TUNNELBRIDGE));
    21 {
    24 {
    22 	return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
    25 	return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
    23 }
    26 }
    24 
    27 
    25 
    28 
    26 static inline bool IsBridgeRamp(TileIndex t)
    29 static inline bool MayHaveBridgeAbove(TileIndex t)
    27 {
    30 {
    28 	assert(IsBridgeTile(t));
    31 	return
    29 	return !HASBIT(_m[t].m5, 6);
    32 		IsTileType(t, MP_CLEAR) ||
    30 }
    33 		IsTileType(t, MP_RAILWAY) ||
    31 
    34 		IsTileType(t, MP_STREET) ||
    32 static inline bool IsBridgeMiddle(TileIndex t)
    35 		IsTileType(t, MP_WATER) ||
    33 {
    36 		IsTileType(t, MP_TUNNELBRIDGE) ||
    34 	assert(IsBridgeTile(t));
    37 		IsTileType(t, MP_UNMOVABLE);
    35 	return HASBIT(_m[t].m5, 6);
       
    36 }
    38 }
    37 
    39 
    38 
    40 
    39 /**
    41 static inline bool IsBridgeAbove(TileIndex t)
    40  * Determines which piece of a bridge is contained in the current tile
       
    41  * @param tile The tile to analyze
       
    42  * @return the piece
       
    43  */
       
    44 static inline uint GetBridgePiece(TileIndex t)
       
    45 {
    42 {
    46 	assert(IsBridgeMiddle(t));
    43 	assert(MayHaveBridgeAbove(t));
    47 	return GB(_m[t].m2, 0, 4);
    44 	return GB(_m[t].extra, 6, 2) != 0;
    48 }
    45 }
    49 
    46 
    50 
    47 
    51 /**
    48 /**
    52  * Determines the type of bridge on a tile
    49  * Determines the type of bridge on a tile
    63 /**
    60 /**
    64  * Get the direction pointing onto the bridge
    61  * Get the direction pointing onto the bridge
    65  */
    62  */
    66 static inline DiagDirection GetBridgeRampDirection(TileIndex t)
    63 static inline DiagDirection GetBridgeRampDirection(TileIndex t)
    67 {
    64 {
    68 	assert(IsBridgeRamp(t));
    65 	assert(IsBridgeTile(t));
    69 	return ReverseDiagDir(XYNSToDiagDir((Axis)GB(_m[t].m5, 0, 1), GB(_m[t].m5, 5, 1)));
    66 	return (DiagDirection)GB(_m[t].m5, 0, 2);
    70 }
    67 }
    71 
    68 
    72 
    69 
    73 static inline Axis GetBridgeAxis(TileIndex t)
    70 static inline Axis GetBridgeAxis(TileIndex t)
    74 {
    71 {
    75 	assert(IsBridgeMiddle(t));
    72 	assert(IsBridgeAbove(t));
    76 	return (Axis)GB(_m[t].m5, 0, 1);
    73 	return (Axis)(GB(_m[t].extra, 6, 2) - 1);
    77 }
    74 }
    78 
    75 
    79 
    76 
    80 static inline TransportType GetBridgeTransportType(TileIndex t)
    77 static inline TransportType GetBridgeTransportType(TileIndex t)
    81 {
    78 {
    82 	assert(IsBridgeTile(t));
    79 	assert(IsBridgeTile(t));
    83 	return (TransportType)GB(_m[t].m5, 1, 2);
    80 	return (TransportType)GB(_m[t].m5, 2, 2);
    84 }
       
    85 
       
    86 
       
    87 static inline bool IsClearUnderBridge(TileIndex t)
       
    88 {
       
    89 	assert(IsBridgeMiddle(t));
       
    90 	return GB(_m[t].m5, 3, 3) == 0;
       
    91 }
       
    92 
       
    93 static inline bool IsWaterUnderBridge(TileIndex t)
       
    94 {
       
    95 	assert(IsBridgeMiddle(t));
       
    96 	return GB(_m[t].m5, 3, 3) == 1;
       
    97 }
       
    98 
       
    99 
       
   100 static inline bool IsTransportUnderBridge(TileIndex t)
       
   101 {
       
   102 	assert(IsBridgeMiddle(t));
       
   103 	return HASBIT(_m[t].m5, 5);
       
   104 }
       
   105 
       
   106 static inline TransportType GetTransportTypeUnderBridge(TileIndex t)
       
   107 {
       
   108 	assert(IsTransportUnderBridge(t));
       
   109 	return (TransportType)GB(_m[t].m5, 3, 2);
       
   110 }
       
   111 
       
   112 static inline RoadBits GetRoadBitsUnderBridge(TileIndex t)
       
   113 {
       
   114 	assert(GetTransportTypeUnderBridge(t) == TRANSPORT_ROAD);
       
   115 	return GetBridgeAxis(t) == AXIS_X ? ROAD_Y : ROAD_X;
       
   116 }
       
   117 
       
   118 static inline Track GetRailUnderBridge(TileIndex t)
       
   119 {
       
   120 	assert(GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL);
       
   121 	return AxisToTrack(OtherAxis(GetBridgeAxis(t)));
       
   122 }
       
   123 
       
   124 static inline TrackBits GetRailBitsUnderBridge(TileIndex t)
       
   125 {
       
   126 	return TrackToTrackBits(GetRailUnderBridge(t));
       
   127 }
    81 }
   128 
    82 
   129 
    83 
   130 /**
    84 /**
   131  * Finds the end of a bridge in the specified direction starting at a middle tile
    85  * Finds the end of a bridge in the specified direction starting at a middle tile
   132  */
    86  */
   133 TileIndex GetBridgeEnd(TileIndex, DiagDirection);
    87 TileIndex GetBridgeEnd(TileIndex, DiagDirection);
       
    88 
       
    89 /**
       
    90  * Finds the northern end of a bridge starting at a middle tile
       
    91  */
       
    92 TileIndex GetNorthernBridgeEnd(TileIndex t);
   134 
    93 
   135 /**
    94 /**
   136  * Finds the southern end of a bridge starting at a middle tile
    95  * Finds the southern end of a bridge starting at a middle tile
   137  */
    96  */
   138 TileIndex GetSouthernBridgeEnd(TileIndex t);
    97 TileIndex GetSouthernBridgeEnd(TileIndex t);
   141 /**
   100 /**
   142  * Starting at one bridge end finds the other bridge end
   101  * Starting at one bridge end finds the other bridge end
   143  */
   102  */
   144 TileIndex GetOtherBridgeEnd(TileIndex);
   103 TileIndex GetOtherBridgeEnd(TileIndex);
   145 
   104 
   146 uint GetBridgeHeight(TileIndex t);
   105 uint GetBridgeHeight(TileIndex tile);
       
   106 uint GetBridgeFoundation(Slope tileh, Axis axis);
   147 
   107 
   148 static inline void SetClearUnderBridge(TileIndex t)
   108 static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
   149 {
   109 {
   150 	assert(IsBridgeMiddle(t));
   110 	assert(MayHaveBridgeAbove(t));
   151 	SetTileOwner(t, OWNER_NONE);
   111 	CLRBIT(_m[t].extra, 6 + a);
   152 	SB(_m[t].m5, 3, 3, 0 << 2 | 0);
       
   153 	SB(_m[t].m3, 0, 4, 0);
       
   154 }
   112 }
   155 
   113 
   156 static inline void SetWaterUnderBridge(TileIndex t)
   114 
       
   115 static inline void ClearBridgeMiddle(TileIndex t)
   157 {
   116 {
   158 	assert(IsBridgeMiddle(t));
   117 	ClearSingleBridgeMiddle(t, AXIS_X);
   159 	SetTileOwner(t, OWNER_WATER);
   118 	ClearSingleBridgeMiddle(t, AXIS_Y);
   160 	SB(_m[t].m5, 3, 3, 0 << 2 | 1);
       
   161 	SB(_m[t].m3, 0, 4, 0);
       
   162 }
   119 }
   163 
   120 
   164 static inline void SetCanalUnderBridge(TileIndex t, Owner o)
   121 static inline void SetBridgeMiddle(TileIndex t, Axis a)
   165 {
   122 {
   166 	assert(IsBridgeMiddle(t));
   123 	assert(MayHaveBridgeAbove(t));
   167 	SetTileOwner(t, o);
   124 	SETBIT(_m[t].extra, 6 + a);
   168 	SB(_m[t].m5, 3, 3, 0 << 2 | 1);
       
   169 	SB(_m[t].m3, 0, 4, 0);
       
   170 }
       
   171 
       
   172 static inline void SetRailUnderBridge(TileIndex t, Owner o, RailType r)
       
   173 {
       
   174 	assert(IsBridgeMiddle(t));
       
   175 	SetTileOwner(t, o);
       
   176 	SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_RAIL);
       
   177 	SB(_m[t].m3, 0, 4, r);
       
   178 }
       
   179 
       
   180 static inline void SetRoadUnderBridge(TileIndex t, Owner o)
       
   181 {
       
   182 	assert(IsBridgeMiddle(t));
       
   183 	SetTileOwner(t, o);
       
   184 	SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD);
       
   185 	SB(_m[t].m3, 0, 4, 0);
       
   186 }
   125 }
   187 
   126 
   188 
   127 
   189 static inline void MakeBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, TransportType tt)
   128 static inline void MakeBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, TransportType tt)
   190 {
   129 {
   191 	uint northsouth = (d == DIAGDIR_NE || d == DIAGDIR_NW);
       
   192 
       
   193 	SetTileType(t, MP_TUNNELBRIDGE);
   130 	SetTileType(t, MP_TUNNELBRIDGE);
   194 	SetTileOwner(t, o);
   131 	SetTileOwner(t, o);
   195 	_m[t].m2 = bridgetype << 4;
   132 	_m[t].m2 = bridgetype << 4;
   196 	_m[t].m4 = 0;
   133 	_m[t].m4 = 0;
   197 	_m[t].m5 = 1 << 7 | 0 << 6 | northsouth << 5 | tt << 1 | DiagDirToAxis(d);
   134 	_m[t].m5 = 1 << 7 | tt << 2 | d;
   198 }
   135 }
   199 
   136 
   200 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d)
   137 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d)
   201 {
   138 {
   202 	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD);
   139 	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD);
   208 	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL);
   145 	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL);
   209 	_m[t].m3 = r;
   146 	_m[t].m3 = r;
   210 }
   147 }
   211 
   148 
   212 
   149 
   213 static inline void MakeBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a, TransportType tt)
       
   214 {
       
   215 	SetTileType(t, MP_TUNNELBRIDGE);
       
   216 	SetTileOwner(t, OWNER_NONE);
       
   217 	_m[t].m2 = bridgetype << 4 | piece;
       
   218 	_m[t].m3 = 0;
       
   219 	_m[t].m4 = 0;
       
   220 	_m[t].m5 = 1 << 7 | 1 << 6 | 0 << 5 | 0 << 3 | tt << 1 | a;
       
   221 }
       
   222 
       
   223 static inline void MakeRoadBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a)
       
   224 {
       
   225 	MakeBridgeMiddle(t, bridgetype, piece, a, TRANSPORT_ROAD);
       
   226 }
       
   227 
       
   228 static inline void MakeRailBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a, RailType r)
       
   229 {
       
   230 	MakeBridgeMiddle(t, bridgetype, piece, a, TRANSPORT_RAIL);
       
   231 	SB(_m[t].m3, 4, 4, r);
       
   232 }
       
   233 
       
   234 
       
   235 #endif /* BRIDGE_MAP_H */
   150 #endif /* BRIDGE_MAP_H */