src/bridge_map.h
changeset 6914 3ba37b6fa39b
parent 6912 f1dafa4911fb
child 7157 270bc5b64e08
equal deleted inserted replaced
6913:cc3f6bb84d6d 6914:3ba37b6fa39b
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 /** @file bridge_map.h */
     3 /** @file bridge_map.h Map accessor functions for bridges. */
     4 
     4 
     5 #ifndef BRIDGE_MAP_H
     5 #ifndef BRIDGE_MAP_H
     6 #define BRIDGE_MAP_H
     6 #define BRIDGE_MAP_H
     7 
     7 
     8 #include "direction.h"
     8 #include "direction.h"
    53 }
    53 }
    54 
    54 
    55 /**
    55 /**
    56  * checks if a bridge is set above the ground of this tile
    56  * checks if a bridge is set above the ground of this tile
    57  * @param t The tile to analyze
    57  * @param t The tile to analyze
       
    58  * @pre MayHaveBridgeAbove(t)
    58  * @return true if a bridge is detected above
    59  * @return true if a bridge is detected above
    59  */
    60  */
    60 static inline bool IsBridgeAbove(TileIndex t)
    61 static inline bool IsBridgeAbove(TileIndex t)
    61 {
    62 {
    62 	assert(MayHaveBridgeAbove(t));
    63 	assert(MayHaveBridgeAbove(t));
    65 
    66 
    66 
    67 
    67 /**
    68 /**
    68  * Determines the type of bridge on a tile
    69  * Determines the type of bridge on a tile
    69  * @param t The tile to analyze
    70  * @param t The tile to analyze
       
    71  * @pre IsBridgeTile(t)
    70  * @return The bridge type
    72  * @return The bridge type
    71  */
    73  */
    72 static inline uint GetBridgeType(TileIndex t)
    74 static inline uint GetBridgeType(TileIndex t)
    73 {
    75 {
    74 	assert(IsBridgeTile(t));
    76 	assert(IsBridgeTile(t));
    77 
    79 
    78 
    80 
    79 /**
    81 /**
    80  * Get the direction pointing onto the bridge
    82  * Get the direction pointing onto the bridge
    81  * @param t The tile to analyze
    83  * @param t The tile to analyze
       
    84  * @pre IsBridgeTile(t)
    82  * @return the above mentionned direction
    85  * @return the above mentionned direction
    83  */
    86  */
    84 static inline DiagDirection GetBridgeRampDirection(TileIndex t)
    87 static inline DiagDirection GetBridgeRampDirection(TileIndex t)
    85 {
    88 {
    86 	assert(IsBridgeTile(t));
    89 	assert(IsBridgeTile(t));
    87 	return (DiagDirection)GB(_m[t].m5, 0, 2);
    90 	return (DiagDirection)GB(_m[t].m5, 0, 2);
    88 }
    91 }
    89 
    92 
    90 
    93 
       
    94 /**
       
    95  * Get the axis of the bridge that goes over the tile. Not the axis or the ramp.
       
    96  * @param t The tile to analyze
       
    97  * @pre IsBridgeAbove(t)
       
    98  * @return the above mentioned axis
       
    99  */
    91 static inline Axis GetBridgeAxis(TileIndex t)
   100 static inline Axis GetBridgeAxis(TileIndex t)
    92 {
   101 {
    93 	assert(IsBridgeAbove(t));
   102 	assert(IsBridgeAbove(t));
    94 	return (Axis)(GB(_m[t].m6, 6, 2) - 1);
   103 	return (Axis)(GB(_m[t].m6, 6, 2) - 1);
    95 }
   104 }
    96 
   105 
    97 
   106 
       
   107 /**
       
   108  * Get the transport type of the bridge's ramp.
       
   109  * @param t The ramp tile to analyze
       
   110  * @pre IsBridgeTile(t)
       
   111  * @return the transport type of the bridge
       
   112  */
    98 static inline TransportType GetBridgeTransportType(TileIndex t)
   113 static inline TransportType GetBridgeTransportType(TileIndex t)
    99 {
   114 {
   100 	assert(IsBridgeTile(t));
   115 	assert(IsBridgeTile(t));
   101 	return (TransportType)GB(_m[t].m5, 2, 2);
   116 	return (TransportType)GB(_m[t].m5, 2, 2);
   102 }
   117 }
   103 
   118 
   104 
   119 
       
   120 /**
       
   121  * Does the bridge ramp lie in a snow or desert area?
       
   122  * @param t The ramp tile to analyze
       
   123  * @pre IsBridgeTile(t)
       
   124  * @return true if and only if in a snow or desert area
       
   125  */
   105 static inline bool HasBridgeSnowOrDesert(TileIndex t)
   126 static inline bool HasBridgeSnowOrDesert(TileIndex t)
   106 {
   127 {
   107 	assert(IsBridgeTile(t));
   128 	assert(IsBridgeTile(t));
   108 	return HASBIT(_m[t].m4, 7);
   129 	return HASBIT(_m[t].m4, 7);
   109 }
   130 }
   110 
   131 
   111 
   132 
       
   133 /**
       
   134  * Sets whether the bridge ramp lies in a snow or desert area.
       
   135  * @param t              The ramp tile to set (un)make a snow/desert area
       
   136  * @param snow_or_desert Make (true) or unmake the tile a snow/desert area
       
   137  * @pre IsBridgeTile(t)
       
   138  */
   112 static inline void SetBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
   139 static inline void SetBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
   113 {
   140 {
   114 	assert(IsBridgeTile(t));
   141 	assert(IsBridgeTile(t));
   115 	SB(_m[t].m4, 7, 1, snow_or_desert);
   142 	SB(_m[t].m4, 7, 1, snow_or_desert);
   116 }
   143 }
   117 
   144 
   118 /**
   145 /**
   119  * Finds the end of a bridge in the specified direction starting at a middle tile
   146  * Finds the end of a bridge in the specified direction starting at a middle tile
   120  */
   147  * @param t the bridge tile to find the bridge ramp for
   121 TileIndex GetBridgeEnd(TileIndex, DiagDirection);
   148  * @param d the direction to search in
       
   149  */
       
   150 TileIndex GetBridgeEnd(TileIndex t, DiagDirection d);
   122 
   151 
   123 /**
   152 /**
   124  * Finds the northern end of a bridge starting at a middle tile
   153  * Finds the northern end of a bridge starting at a middle tile
       
   154  * @param t the bridge tile to find the bridge ramp for
   125  */
   155  */
   126 TileIndex GetNorthernBridgeEnd(TileIndex t);
   156 TileIndex GetNorthernBridgeEnd(TileIndex t);
   127 
   157 
   128 /**
   158 /**
   129  * Finds the southern end of a bridge starting at a middle tile
   159  * Finds the southern end of a bridge starting at a middle tile
       
   160  * @param t the bridge tile to find the bridge ramp for
   130  */
   161  */
   131 TileIndex GetSouthernBridgeEnd(TileIndex t);
   162 TileIndex GetSouthernBridgeEnd(TileIndex t);
   132 
   163 
   133 
   164 
   134 /**
   165 /**
   135  * Starting at one bridge end finds the other bridge end
   166  * Starting at one bridge end finds the other bridge end
   136  */
   167  * @param t the bridge ramp tile to find the other bridge ramp for
   137 TileIndex GetOtherBridgeEnd(TileIndex);
   168  */
   138 
   169 TileIndex GetOtherBridgeEnd(TileIndex t);
       
   170 
       
   171 /**
       
   172  * Get the height ('z') of a bridge in pixels.
       
   173  * @param tile the bridge ramp tile to get the bridge height from
       
   174  * @return the height of the bridge in pixels
       
   175  */
   139 uint GetBridgeHeight(TileIndex tile);
   176 uint GetBridgeHeight(TileIndex tile);
   140 uint GetBridgeFoundation(Slope tileh, Axis axis);
   177 
   141 
   178 /**
       
   179  * Remove the bridge over the given axis.
       
   180  * @param t the tile to remove the bridge from
       
   181  * @param a the axis of the bridge to remove
       
   182  * @pre MayHaveBridgeAbove(t)
       
   183  */
   142 static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
   184 static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
   143 {
   185 {
   144 	assert(MayHaveBridgeAbove(t));
   186 	assert(MayHaveBridgeAbove(t));
   145 	CLRBIT(_m[t].m6, 6 + a);
   187 	CLRBIT(_m[t].m6, 6 + a);
   146 }
   188 }
   147 
   189 
   148 
   190 
       
   191 /**
       
   192  * Removes bridges from the given, that is bridges along the X and Y axis.
       
   193  * @param t the tile to remove the bridge from
       
   194  * @pre MayHaveBridgeAbove(t)
       
   195  */
   149 static inline void ClearBridgeMiddle(TileIndex t)
   196 static inline void ClearBridgeMiddle(TileIndex t)
   150 {
   197 {
   151 	ClearSingleBridgeMiddle(t, AXIS_X);
   198 	ClearSingleBridgeMiddle(t, AXIS_X);
   152 	ClearSingleBridgeMiddle(t, AXIS_Y);
   199 	ClearSingleBridgeMiddle(t, AXIS_Y);
   153 }
   200 }
   154 
   201 
       
   202 /**
       
   203  * Set that there is a bridge over the given axis.
       
   204  * @param t the tile to add the bridge to
       
   205  * @param a the axis of the bridge to add
       
   206  * @pre MayHaveBridgeAbove(t)
       
   207  */
   155 static inline void SetBridgeMiddle(TileIndex t, Axis a)
   208 static inline void SetBridgeMiddle(TileIndex t, Axis a)
   156 {
   209 {
   157 	assert(MayHaveBridgeAbove(t));
   210 	assert(MayHaveBridgeAbove(t));
   158 	SETBIT(_m[t].m6, 6 + a);
   211 	SETBIT(_m[t].m6, 6 + a);
   159 }
   212 }
   160 
   213 
   161 
   214 
       
   215 /**
       
   216  * Generic part to make a bridge ramp for both roads and rails.
       
   217  * @param t          the tile to make a bridge ramp
       
   218  * @param o          the new owner of the bridge ramp
       
   219  * @param bridgetype the type of bridge this bridge ramp belongs to
       
   220  * @param d          the direction this ramp must be facing
       
   221  * @param tt         the transport type of the bridge
       
   222  * @note this function should not be called directly.
       
   223  */
   162 static inline void MakeBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, TransportType tt)
   224 static inline void MakeBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, TransportType tt)
   163 {
   225 {
   164 	SetTileType(t, MP_TUNNELBRIDGE);
   226 	SetTileType(t, MP_TUNNELBRIDGE);
   165 	SetTileOwner(t, o);
   227 	SetTileOwner(t, o);
   166 	_m[t].m2 = bridgetype << 4;
   228 	_m[t].m2 = bridgetype << 4;
   167 	_m[t].m4 = 0;
   229 	_m[t].m4 = 0;
   168 	_m[t].m5 = 1 << 7 | tt << 2 | d;
   230 	_m[t].m5 = 1 << 7 | tt << 2 | d;
   169 }
   231 }
   170 
   232 
       
   233 /**
       
   234  * Make a bridge ramp for roads.
       
   235  * @param t          the tile to make a bridge ramp
       
   236  * @param o          the new owner of the bridge ramp
       
   237  * @param bridgetype the type of bridge this bridge ramp belongs to
       
   238  * @param d          the direction this ramp must be facing
       
   239  */
   171 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d)
   240 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d)
   172 {
   241 {
   173 	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD);
   242 	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD);
   174 	_m[t].m3 = 0;
   243 	_m[t].m3 = 0;
   175 }
   244 }
   176 
   245 
       
   246 /**
       
   247  * Make a bridge ramp for rails.
       
   248  * @param t          the tile to make a bridge ramp
       
   249  * @param o          the new owner of the bridge ramp
       
   250  * @param bridgetype the type of bridge this bridge ramp belongs to
       
   251  * @param d          the direction this ramp must be facing
       
   252  * @param r          the rail type of the bridge
       
   253  */
   177 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, RailType r)
   254 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, RailType r)
   178 {
   255 {
   179 	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL);
   256 	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL);
   180 	_m[t].m3 = r;
   257 	_m[t].m3 = r;
   181 }
   258 }