bridge_map.h

Go to the documentation of this file.
00001 /* $Id: bridge_map.h 18809 2010-01-15 16:41:15Z 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
00049     IsTileType(t, MP_CLEAR) ||
00050     IsTileType(t, MP_RAILWAY) ||
00051     IsTileType(t, MP_ROAD) ||
00052     IsTileType(t, MP_WATER) ||
00053     IsTileType(t, MP_TUNNELBRIDGE) ||
00054     IsTileType(t, MP_UNMOVABLE);
00055 }
00056 
00063 static inline bool IsBridgeAbove(TileIndex t)
00064 {
00065   assert(MayHaveBridgeAbove(t));
00066   return GB(_m[t].m6, 6, 2) != 0;
00067 }
00068 
00075 static inline BridgeType GetBridgeType(TileIndex t)
00076 {
00077   assert(IsBridgeTile(t));
00078   return GB(_m[t].m6, 2, 4);
00079 }
00080 
00087 static inline Axis GetBridgeAxis(TileIndex t)
00088 {
00089   assert(IsBridgeAbove(t));
00090   return (Axis)(GB(_m[t].m6, 6, 2) - 1);
00091 }
00092 
00097 TileIndex GetNorthernBridgeEnd(TileIndex t);
00098 
00103 TileIndex GetSouthernBridgeEnd(TileIndex t);
00104 
00105 
00110 TileIndex GetOtherBridgeEnd(TileIndex t);
00111 
00117 uint GetBridgeHeight(TileIndex tile);
00118 
00125 static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
00126 {
00127   assert(MayHaveBridgeAbove(t));
00128   ClrBit(_m[t].m6, 6 + a);
00129 }
00130 
00136 static inline void ClearBridgeMiddle(TileIndex t)
00137 {
00138   ClearSingleBridgeMiddle(t, AXIS_X);
00139   ClearSingleBridgeMiddle(t, AXIS_Y);
00140 }
00141 
00148 static inline void SetBridgeMiddle(TileIndex t, Axis a)
00149 {
00150   assert(MayHaveBridgeAbove(t));
00151   SetBit(_m[t].m6, 6 + a);
00152 }
00153 
00164 static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt)
00165 {
00166   SetTileType(t, MP_TUNNELBRIDGE);
00167   SetTileOwner(t, o);
00168   _m[t].m2 = 0;
00169   _m[t].m3 = rt;
00170   _m[t].m4 = 0;
00171   _m[t].m5 = 1 << 7 | tt << 2 | d;
00172   SB(_m[t].m6, 2, 4, bridgetype);
00173   _me[t].m7 = 0;
00174 }
00175 
00184 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RoadTypes r)
00185 {
00186   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0);
00187   SetRoadOwner(t, ROADTYPE_ROAD, o);
00188   if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o);
00189   SetRoadTypes(t, r);
00190 }
00191 
00200 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
00201 {
00202   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
00203 }
00204 
00211 static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
00212 {
00213   MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
00214 }
00215 
00216 #endif /* BRIDGE_MAP_H */

Generated on Wed Mar 3 23:32:19 2010 for OpenTTD by  doxygen 1.6.1