bridge_map.h

Go to the documentation of this file.
00001 /* $Id: bridge_map.h 18028 2009-11-09 10:40:33Z rubidium $ */
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 "direction_func.h"
00016 #include "rail_type.h"
00017 #include "transport_type.h"
00018 #include "road_map.h"
00019 #include "bridge.h"
00020 
00027 static inline bool IsBridge(TileIndex t)
00028 {
00029   assert(IsTileType(t, MP_TUNNELBRIDGE));
00030   return HasBit(_m[t].m5, 7);
00031 }
00032 
00038 static inline bool IsBridgeTile(TileIndex t)
00039 {
00040   return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
00041 }
00042 
00049 static inline bool MayHaveBridgeAbove(TileIndex t)
00050 {
00051   return
00052     IsTileType(t, MP_CLEAR) ||
00053     IsTileType(t, MP_RAILWAY) ||
00054     IsTileType(t, MP_ROAD) ||
00055     IsTileType(t, MP_WATER) ||
00056     IsTileType(t, MP_TUNNELBRIDGE) ||
00057     IsTileType(t, MP_UNMOVABLE);
00058 }
00059 
00066 static inline bool IsBridgeAbove(TileIndex t)
00067 {
00068   assert(MayHaveBridgeAbove(t));
00069   return GB(_m[t].m6, 6, 2) != 0;
00070 }
00071 
00078 static inline BridgeType GetBridgeType(TileIndex t)
00079 {
00080   assert(IsBridgeTile(t));
00081   return GB(_m[t].m6, 2, 4);
00082 }
00083 
00090 static inline Axis GetBridgeAxis(TileIndex t)
00091 {
00092   assert(IsBridgeAbove(t));
00093   return (Axis)(GB(_m[t].m6, 6, 2) - 1);
00094 }
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 Tue Jan 5 21:02:53 2010 for OpenTTD by  doxygen 1.5.6