# 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
    00035 TileIndex GetNorthernBridgeEnd(TileIndex t)
    00036 {
    00037   return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
    00038 }
    00039
    00040
    00041 TileIndex GetSouthernBridgeEnd(TileIndex t)
    00042 {
    00043   return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
    00044 }
    00045
    00046
    00047 TileIndex GetOtherBridgeEnd(TileIndex tile)
    00048 {
    00049   assert(IsBridgeTile(tile));
    00050   return GetBridgeEnd(tile, GetTunnelBridgeDirection(tile));
    00051 }
    00052
    00053 uint GetBridgeHeight(TileIndex t)
    00054 {
    00055   uint h;
    00056   Slope tileh = GetTileSlope(t, &h);
    00057   Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(t)));
    00058
    00059   /* one height level extra for the ramp */
    00060   return h + TILE_HEIGHT + ApplyFoundationToSlope(f, &tileh);
    00061 }