bridge_map.h

Go to the documentation of this file.
00001 /* $Id: bridge_map.h 15643 2009-03-08 16:10:39Z smatz $ */
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].m6, 2, 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 = 0;
00172   _m[t].m3 = rt;
00173   _m[t].m4 = 0;
00174   _m[t].m5 = 1 << 7 | tt << 2 | d;
00175   SB(_m[t].m6, 2, 4, bridgetype);
00176   _me[t].m7 = 0;
00177 }
00178 
00187 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RoadTypes r)
00188 {
00189   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0);
00190   SetRoadOwner(t, ROADTYPE_ROAD, o);
00191   if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o);
00192   SetRoadTypes(t, r);
00193 }
00194 
00203 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
00204 {
00205   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
00206 }
00207 
00214 static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
00215 {
00216   MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
00217 }
00218 
00219 #endif /* BRIDGE_MAP_H */

Generated on Mon Dec 14 20:59:58 2009 for OpenTTD by  doxygen 1.5.6