bridge_map.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef BRIDGE_MAP_H
00013 #define BRIDGE_MAP_H
00014 
00015 #include "road_map.h"
00016 #include "bridge.h"
00017 
00024 static inline bool IsBridge(TileIndex t)
00025 {
00026   assert(IsTileType(t, MP_TUNNELBRIDGE));
00027   return HasBit(_m[t].m5, 7);
00028 }
00029 
00035 static inline bool IsBridgeTile(TileIndex t)
00036 {
00037   return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
00038 }
00039 
00046 static inline bool MayHaveBridgeAbove(TileIndex t)
00047 {
00048   return IsTileType(t, MP_CLEAR) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_ROAD) ||
00049       IsTileType(t, MP_WATER) || IsTileType(t, MP_TUNNELBRIDGE) || IsTileType(t, MP_OBJECT);
00050 }
00051 
00058 static inline bool IsBridgeAbove(TileIndex t)
00059 {
00060   assert(MayHaveBridgeAbove(t));
00061   return GB(_m[t].m6, 6, 2) != 0;
00062 }
00063 
00070 static inline BridgeType GetBridgeType(TileIndex t)
00071 {
00072   assert(IsBridgeTile(t));
00073   return GB(_m[t].m6, 2, 4);
00074 }
00075 
00082 static inline Axis GetBridgeAxis(TileIndex t)
00083 {
00084   assert(IsBridgeAbove(t));
00085   return (Axis)(GB(_m[t].m6, 6, 2) - 1);
00086 }
00087 
00088 TileIndex GetNorthernBridgeEnd(TileIndex t);
00089 TileIndex GetSouthernBridgeEnd(TileIndex t);
00090 TileIndex GetOtherBridgeEnd(TileIndex t);
00091 
00092 uint GetBridgeHeight(TileIndex tile);
00093 
00100 static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
00101 {
00102   assert(MayHaveBridgeAbove(t));
00103   ClrBit(_m[t].m6, 6 + a);
00104 }
00105 
00111 static inline void ClearBridgeMiddle(TileIndex t)
00112 {
00113   ClearSingleBridgeMiddle(t, AXIS_X);
00114   ClearSingleBridgeMiddle(t, AXIS_Y);
00115 }
00116 
00123 static inline void SetBridgeMiddle(TileIndex t, Axis a)
00124 {
00125   assert(MayHaveBridgeAbove(t));
00126   SetBit(_m[t].m6, 6 + a);
00127 }
00128 
00139 static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt)
00140 {
00141   SetTileType(t, MP_TUNNELBRIDGE);
00142   SetTileOwner(t, o);
00143   _m[t].m2 = 0;
00144   _m[t].m3 = rt;
00145   _m[t].m4 = 0;
00146   _m[t].m5 = 1 << 7 | tt << 2 | d;
00147   SB(_m[t].m6, 2, 4, bridgetype);
00148   _me[t].m7 = 0;
00149 }
00150 
00159 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RoadTypes r)
00160 {
00161   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0);
00162   SetRoadOwner(t, ROADTYPE_ROAD, o);
00163   if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o);
00164   SetRoadTypes(t, r);
00165 }
00166 
00175 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
00176 {
00177   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
00178 }
00179 
00186 static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
00187 {
00188   MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
00189 }
00190 
00191 #endif /* BRIDGE_MAP_H */