# bridge_map.h

Go to the documentation of this file.

    00001 /* $Id: bridge_map.h 24912 2013-01-13 13:17:12Z frosch $ */
    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
    00170 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes r)
    00171 {
    00172   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0);
    00173   SetRoadOwner(t, ROADTYPE_ROAD, owner_road);
    00174   if (owner_tram != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, owner_tram);
    00175   SetRoadTypes(t, r);
    00176 }
    00177
    00186 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
    00187 {
    00188   MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
    00189 }
    00190
    00197 static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
    00198 {
    00199   MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
    00200 }
    00201
    00202 #endif /* BRIDGE_MAP_H */