# bridge_map.cpp

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 #include "stdafx.h"
    00013 #include "landscape.h"
    00014 #include "tunnelbridge_map.h"
    00015
    00016
    00022 static TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
    00023 {
    00024   TileIndexDiff delta = TileOffsByDiagDir(dir);
    00025
    00026   dir = ReverseDiagDir(dir);
    00027   do {
    00028     tile += delta;
    00029   } while (!IsBridgeTile(tile) || GetTunnelBridgeDirection(tile) != dir);
    00030
    00031   return tile;
    00032 }
    00033
    00034
    00039 TileIndex GetNorthernBridgeEnd(TileIndex t)
    00040 {
    00041   return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
    00042 }
    00043
    00044
    00049 TileIndex GetSouthernBridgeEnd(TileIndex t)
    00050 {
    00051   return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
    00052 }
    00053
    00054
    00059 TileIndex GetOtherBridgeEnd(TileIndex tile)
    00060 {
    00061   assert(IsBridgeTile(tile));
    00062   return GetBridgeEnd(tile, GetTunnelBridgeDirection(tile));
    00063 }
    00064
    00070 int GetBridgeHeight(TileIndex t)
    00071 {
    00072   int h;
    00073   Slope tileh = GetTileSlope(t, &h);
    00074   Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(t)));
    00075
    00076   /* one height level extra for the ramp */
    00077   return h + 1 + ApplyFoundationToSlope(f, &tileh);
    00078 }