(svn r27770) -Fix [FS#6540]: Initialize variables in station_sl.cpp (JGR)
[openttd.git] / src / pathfinder / yapf / yapf_costbase.hpp
blob6b55585a837be2cbae1a0449223e8d3c2b61514c
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file yapf_costbase.hpp Handling of cost determination. */
12 #ifndef YAPF_COSTBASE_HPP
13 #define YAPF_COSTBASE_HPP
15 /** Base implementation for cost accounting. */
16 struct CYapfCostBase {
17 /**
18 * Does the given track direction on the given tile yield an uphill penalty?
19 * @param tile The tile to check.
20 * @param td The track direction to check.
21 * @return True if there's a slope, otherwise false.
23 inline static bool stSlopeCost(TileIndex tile, Trackdir td)
25 if (IsDiagonalTrackdir(td)) {
26 if (IsBridgeTile(tile)) {
27 /* it is bridge ramp, check if we are entering the bridge */
28 if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are leaving it, no penalty
29 /* we are entering the bridge */
30 Slope tile_slope = GetTileSlope(tile);
31 Axis axis = DiagDirToAxis(GetTunnelBridgeDirection(tile));
32 return !HasBridgeFlatRamp(tile_slope, axis);
33 } else {
34 /* not bridge ramp */
35 if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope
36 Slope tile_slope = GetTileSlope(tile);
37 return IsUphillTrackdir(tile_slope, td); // slopes uphill => apply penalty
40 return false;
44 #endif /* YAPF_COSTBASE_HPP */