# bridge_map.h

Go to the documentation of this file.

    00001 /* $Id: bridge_map.h 13464 2008-06-11 13:54:01Z rubidium $ */
    00002
    00005 #ifndef BRIDGE_MAP_H
    00006 #define BRIDGE_MAP_H
    00007
    00008 #include "direction_func.h"
    00009 #include "rail_type.h"
    00010 #include "transport_type.h"
    00011 #include "road_map.h"
    00012 #include "bridge.h"
    00013
    00020 static inline bool IsBridge(TileIndex t)
    00021 {
    00022   assert(IsTileType(t, MP_TUNNELBRIDGE));
    00023   return HasBit(_m[t].m5, 7);
    00024 }
    00025
    00031 static inline bool IsBridgeTile(TileIndex t)
    00032 {
    00033   return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
    00034 }
    00035
    00042 static inline bool MayHaveBridgeAbove(TileIndex t)
    00043 {
    00044   return
    00045     IsTileType(t, MP_CLEAR) ||
    00046     IsTileType(t, MP_RAILWAY) ||
    00047     IsTileType(t, MP_ROAD) ||
    00048     IsTileType(t, MP_WATER) ||
    00049     IsTileType(t, MP_TUNNELBRIDGE) ||
    00050     IsTileType(t, MP_UNMOVABLE);
    00051 }
    00052
    00059 static inline bool IsBridgeAbove(TileIndex t)
    00060 {
    00061   assert(MayHaveBridgeAbove(t));
    00062   return GB(_m[t].m6, 6, 2) != 0;
    00063 }
    00064
    00071 static inline BridgeType GetBridgeType(TileIndex t)
    00072 {
    00073   assert(IsBridgeTile(t));
    00074   return GB(_m[t].m2, 4, 4);
    00075 }
    00076
    00083 static inline Axis GetBridgeAxis(TileIndex t)
    00084 {
    00085   assert(IsBridgeAbove(t));
    00086   return (Axis)(GB(_m[t].m6, 6, 2) - 1);
    00087 }
    00088
    00094 TileIndex GetBridgeEnd(TileIndex t, DiagDirection d);
    00095
    00100 TileIndex GetNorthernBridgeEnd(TileIndex t);
    00101
    00106 TileIndex GetSouthernBridgeEnd(TileIndex t);
    00107
    00108
    00113 TileIndex GetOtherBridgeEnd(TileIndex t);
    00114
    00120 uint GetBridgeHeight(TileIndex tile);
    00121
    00128 static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
    00129 {
    00130   assert(MayHaveBridgeAbove(t));
    00131   ClrBit(_m[t].m6, 6 + a);
    00132 }
    00133
    00139 static inline void ClearBridgeMiddle(TileIndex t)
    00140 {
    00141   ClearSingleBridgeMiddle(t, AXIS_X);
    00142   ClearSingleBridgeMiddle(t, AXIS_Y);
    00143 }
    00144
    00151 static inline void SetBridgeMiddle(TileIndex t, Axis a)
    00152 {
    00153   assert(MayHaveBridgeAbove(t));
    00154   SetBit(_m[t].m6, 6 + a);
    00155 }
    00156
    00167 static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt)
    00168 {
    00169   SetTileType(t, MP_TUNNELBRIDGE);
    00170   SetTileOwner(t, o);
    00171   _m[t].m2 = bridgetype << 4;
    00172   _m[t].m3 = rt;
    00173   _m[t].m4 = 0;
    00174   _m[t].m5 = 1 << 7 | tt << 2 | d;
    00175 }
    00176
    00185 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RoadTypes r)
    00186 {
    00187   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, r);
    00188 }
    00189
    00198 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
    00199 {
    00200   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
    00201 }
    00202
    00209 static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
    00210 {
    00211   MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
    00212 }
    00213
    00214 #endif /* BRIDGE_MAP_H */