bridge_map.h

Go to the documentation of this file.
00001 /* $Id: bridge_map.h 23106 2011-11-04 11:30:37Z 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 "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 int GetBridgeHeight(TileIndex tile);
00098 static inline int GetBridgePixelHeight(TileIndex tile)
00099 {
00100   return GetBridgeHeight(tile) * TILE_HEIGHT;
00101 }
00102 
00109 static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
00110 {
00111   assert(MayHaveBridgeAbove(t));
00112   ClrBit(_m[t].m6, 6 + a);
00113 }
00114 
00120 static inline void ClearBridgeMiddle(TileIndex t)
00121 {
00122   ClearSingleBridgeMiddle(t, AXIS_X);
00123   ClearSingleBridgeMiddle(t, AXIS_Y);
00124 }
00125 
00132 static inline void SetBridgeMiddle(TileIndex t, Axis a)
00133 {
00134   assert(MayHaveBridgeAbove(t));
00135   SetBit(_m[t].m6, 6 + a);
00136 }
00137 
00148 static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt)
00149 {
00150   SetTileType(t, MP_TUNNELBRIDGE);
00151   SetTileOwner(t, o);
00152   _m[t].m2 = 0;
00153   _m[t].m3 = rt;
00154   _m[t].m4 = 0;
00155   _m[t].m5 = 1 << 7 | tt << 2 | d;
00156   SB(_m[t].m6, 2, 4, bridgetype);
00157   _me[t].m7 = 0;
00158 }
00159 
00168 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RoadTypes r)
00169 {
00170   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0);
00171   SetRoadOwner(t, ROADTYPE_ROAD, o);
00172   if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o);
00173   SetRoadTypes(t, r);
00174 }
00175 
00184 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
00185 {
00186   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
00187 }
00188 
00195 static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
00196 {
00197   MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
00198 }
00199 
00200 #endif /* BRIDGE_MAP_H */