2006-03-13 12:55:20 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/** @file bridge_map.h Map accessor functions for bridges. */
|
2007-02-23 11:50:43 +00:00
|
|
|
|
2006-03-13 12:55:20 +00:00
|
|
|
#ifndef BRIDGE_MAP_H
|
|
|
|
#define BRIDGE_MAP_H
|
|
|
|
|
2007-12-18 19:52:14 +00:00
|
|
|
#include "direction_func.h"
|
2006-03-13 12:55:20 +00:00
|
|
|
#include "macros.h"
|
|
|
|
#include "map.h"
|
|
|
|
#include "rail.h"
|
2006-03-16 15:16:27 +00:00
|
|
|
#include "road_map.h"
|
2006-03-13 12:55:20 +00:00
|
|
|
#include "tile.h"
|
|
|
|
|
|
|
|
|
2007-04-03 17:19:06 +00:00
|
|
|
/**
|
|
|
|
* Checks if this is a bridge, instead of a tunnel
|
|
|
|
* @param t The tile to analyze
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE)
|
|
|
|
* @return true if the structure is a bridge one
|
|
|
|
*/
|
2006-03-16 15:16:27 +00:00
|
|
|
static inline bool IsBridge(TileIndex t)
|
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsTileType(t, MP_TUNNELBRIDGE));
|
2007-11-19 21:02:30 +00:00
|
|
|
return HasBit(_m[t].m5, 7);
|
2006-03-16 15:16:27 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 17:19:06 +00:00
|
|
|
/**
|
|
|
|
* checks if there is a bridge on this tile
|
|
|
|
* @param t The tile to analyze
|
|
|
|
* @return true if a bridge is present
|
|
|
|
*/
|
2006-03-16 15:16:27 +00:00
|
|
|
static inline bool IsBridgeTile(TileIndex t)
|
|
|
|
{
|
|
|
|
return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
|
|
|
|
}
|
|
|
|
|
2007-04-03 17:19:06 +00:00
|
|
|
/**
|
|
|
|
* checks for the possibility that a bridge may be on this tile
|
|
|
|
* These are in fact all the tile types on which a bridge can be found
|
|
|
|
* @param t The tile to analyze
|
|
|
|
* @return true if a bridge migh be present
|
|
|
|
*/
|
2006-12-27 12:38:02 +00:00
|
|
|
static inline bool MayHaveBridgeAbove(TileIndex t)
|
2006-03-16 05:28:15 +00:00
|
|
|
{
|
2006-12-27 12:38:02 +00:00
|
|
|
return
|
|
|
|
IsTileType(t, MP_CLEAR) ||
|
|
|
|
IsTileType(t, MP_RAILWAY) ||
|
2007-07-29 23:42:59 +00:00
|
|
|
IsTileType(t, MP_ROAD) ||
|
2006-12-27 12:38:02 +00:00
|
|
|
IsTileType(t, MP_WATER) ||
|
|
|
|
IsTileType(t, MP_TUNNELBRIDGE) ||
|
|
|
|
IsTileType(t, MP_UNMOVABLE);
|
2006-06-02 13:05:41 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 17:19:06 +00:00
|
|
|
/**
|
|
|
|
* checks if a bridge is set above the ground of this tile
|
|
|
|
* @param t The tile to analyze
|
2007-04-03 21:51:40 +00:00
|
|
|
* @pre MayHaveBridgeAbove(t)
|
2007-04-03 17:19:06 +00:00
|
|
|
* @return true if a bridge is detected above
|
|
|
|
*/
|
2006-12-27 12:38:02 +00:00
|
|
|
static inline bool IsBridgeAbove(TileIndex t)
|
2006-03-16 10:00:50 +00:00
|
|
|
{
|
2006-12-27 12:38:02 +00:00
|
|
|
assert(MayHaveBridgeAbove(t));
|
2007-01-11 02:05:13 +00:00
|
|
|
return GB(_m[t].m6, 6, 2) != 0;
|
2006-03-16 10:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the type of bridge on a tile
|
2007-04-03 17:19:06 +00:00
|
|
|
* @param t The tile to analyze
|
2007-04-03 21:51:40 +00:00
|
|
|
* @pre IsBridgeTile(t)
|
2006-03-16 10:00:50 +00:00
|
|
|
* @return The bridge type
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline uint GetBridgeType(TileIndex t)
|
2006-03-16 10:00:50 +00:00
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsBridgeTile(t));
|
|
|
|
return GB(_m[t].m2, 4, 4);
|
2006-03-16 10:00:50 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Get the axis of the bridge that goes over the tile. Not the axis or the ramp.
|
|
|
|
* @param t The tile to analyze
|
|
|
|
* @pre IsBridgeAbove(t)
|
|
|
|
* @return the above mentioned axis
|
|
|
|
*/
|
2006-03-16 05:28:15 +00:00
|
|
|
static inline Axis GetBridgeAxis(TileIndex t)
|
|
|
|
{
|
2006-12-27 12:38:02 +00:00
|
|
|
assert(IsBridgeAbove(t));
|
2007-01-11 02:05:13 +00:00
|
|
|
return (Axis)(GB(_m[t].m6, 6, 2) - 1);
|
2006-03-16 05:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the end of a bridge in the specified direction starting at a middle tile
|
2007-04-03 21:51:40 +00:00
|
|
|
* @param t the bridge tile to find the bridge ramp for
|
|
|
|
* @param d the direction to search in
|
2006-03-16 05:28:15 +00:00
|
|
|
*/
|
2007-04-03 21:51:40 +00:00
|
|
|
TileIndex GetBridgeEnd(TileIndex t, DiagDirection d);
|
2006-03-16 05:28:15 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
/**
|
|
|
|
* Finds the northern end of a bridge starting at a middle tile
|
2007-04-03 21:51:40 +00:00
|
|
|
* @param t the bridge tile to find the bridge ramp for
|
2006-12-27 12:38:02 +00:00
|
|
|
*/
|
|
|
|
TileIndex GetNorthernBridgeEnd(TileIndex t);
|
|
|
|
|
2006-03-16 05:28:15 +00:00
|
|
|
/**
|
|
|
|
* Finds the southern end of a bridge starting at a middle tile
|
2007-04-03 21:51:40 +00:00
|
|
|
* @param t the bridge tile to find the bridge ramp for
|
2006-03-16 05:28:15 +00:00
|
|
|
*/
|
|
|
|
TileIndex GetSouthernBridgeEnd(TileIndex t);
|
|
|
|
|
|
|
|
|
2006-03-15 16:44:50 +00:00
|
|
|
/**
|
|
|
|
* Starting at one bridge end finds the other bridge end
|
2007-04-03 21:51:40 +00:00
|
|
|
* @param t the bridge ramp tile to find the other bridge ramp for
|
2006-03-15 16:44:50 +00:00
|
|
|
*/
|
2007-04-03 21:51:40 +00:00
|
|
|
TileIndex GetOtherBridgeEnd(TileIndex t);
|
2006-03-15 16:44:50 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Get the height ('z') of a bridge in pixels.
|
|
|
|
* @param tile the bridge ramp tile to get the bridge height from
|
|
|
|
* @return the height of the bridge in pixels
|
|
|
|
*/
|
2006-12-27 12:38:02 +00:00
|
|
|
uint GetBridgeHeight(TileIndex tile);
|
2006-03-15 16:44:50 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Remove the bridge over the given axis.
|
|
|
|
* @param t the tile to remove the bridge from
|
|
|
|
* @param a the axis of the bridge to remove
|
|
|
|
* @pre MayHaveBridgeAbove(t)
|
|
|
|
*/
|
2006-12-27 12:38:02 +00:00
|
|
|
static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
|
2006-03-13 12:55:20 +00:00
|
|
|
{
|
2006-12-27 12:38:02 +00:00
|
|
|
assert(MayHaveBridgeAbove(t));
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(_m[t].m6, 6 + a);
|
2006-03-13 12:55:20 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Removes bridges from the given, that is bridges along the X and Y axis.
|
|
|
|
* @param t the tile to remove the bridge from
|
|
|
|
* @pre MayHaveBridgeAbove(t)
|
|
|
|
*/
|
2006-12-27 12:38:02 +00:00
|
|
|
static inline void ClearBridgeMiddle(TileIndex t)
|
2006-03-13 12:55:20 +00:00
|
|
|
{
|
2006-12-27 12:38:02 +00:00
|
|
|
ClearSingleBridgeMiddle(t, AXIS_X);
|
|
|
|
ClearSingleBridgeMiddle(t, AXIS_Y);
|
2006-06-07 19:35:21 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Set that there is a bridge over the given axis.
|
|
|
|
* @param t the tile to add the bridge to
|
|
|
|
* @param a the axis of the bridge to add
|
|
|
|
* @pre MayHaveBridgeAbove(t)
|
|
|
|
*/
|
2006-12-27 12:38:02 +00:00
|
|
|
static inline void SetBridgeMiddle(TileIndex t, Axis a)
|
2006-06-07 19:35:21 +00:00
|
|
|
{
|
2006-12-27 12:38:02 +00:00
|
|
|
assert(MayHaveBridgeAbove(t));
|
2007-11-20 13:35:54 +00:00
|
|
|
SetBit(_m[t].m6, 6 + a);
|
2006-03-13 12:55:20 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Generic part to make a bridge ramp for both roads and rails.
|
|
|
|
* @param t the tile to make a bridge ramp
|
|
|
|
* @param o the new owner of the bridge ramp
|
|
|
|
* @param bridgetype the type of bridge this bridge ramp belongs to
|
|
|
|
* @param d the direction this ramp must be facing
|
|
|
|
* @param tt the transport type of the bridge
|
2007-05-20 19:14:08 +00:00
|
|
|
* @param rt the road or rail type
|
2007-04-03 21:51:40 +00:00
|
|
|
* @note this function should not be called directly.
|
|
|
|
*/
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline void MakeBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, TransportType tt, uint rt)
|
2006-03-15 07:10:41 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_TUNNELBRIDGE);
|
|
|
|
SetTileOwner(t, o);
|
|
|
|
_m[t].m2 = bridgetype << 4;
|
2007-05-20 19:14:08 +00:00
|
|
|
_m[t].m3 = rt;
|
2006-03-15 07:10:41 +00:00
|
|
|
_m[t].m4 = 0;
|
2006-12-27 12:38:02 +00:00
|
|
|
_m[t].m5 = 1 << 7 | tt << 2 | d;
|
2006-03-15 07:10:41 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Make a bridge ramp for roads.
|
|
|
|
* @param t the tile to make a bridge ramp
|
|
|
|
* @param o the new owner of the bridge ramp
|
|
|
|
* @param bridgetype the type of bridge this bridge ramp belongs to
|
|
|
|
* @param d the direction this ramp must be facing
|
2007-05-20 19:14:08 +00:00
|
|
|
* @param r the road type of the bridge
|
2007-04-03 21:51:40 +00:00
|
|
|
*/
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, RoadTypes r)
|
2006-03-15 07:10:41 +00:00
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, r);
|
2006-03-15 07:10:41 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Make a bridge ramp for rails.
|
|
|
|
* @param t the tile to make a bridge ramp
|
|
|
|
* @param o the new owner of the bridge ramp
|
|
|
|
* @param bridgetype the type of bridge this bridge ramp belongs to
|
|
|
|
* @param d the direction this ramp must be facing
|
|
|
|
* @param r the rail type of the bridge
|
|
|
|
*/
|
2006-03-15 07:10:41 +00:00
|
|
|
static inline void MakeRailBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, RailType r)
|
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
|
2006-03-15 07:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#endif /* BRIDGE_MAP_H */
|