OpenTTD
yapf_costbase.hpp
Go to the documentation of this file.
1 /* $Id: yapf_costbase.hpp 24900 2013-01-08 22:46:42Z planetmaker $ */
2 
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  */
9 
12 #ifndef YAPF_COSTBASE_HPP
13 #define YAPF_COSTBASE_HPP
14 
16 struct CYapfCostBase {
23  inline static bool stSlopeCost(TileIndex tile, Trackdir td)
24  {
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);
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
38  }
39  }
40  return false;
41  }
42 };
43 
44 #endif /* YAPF_COSTBASE_HPP */
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:427
static bool IsUphillTrackdir(Slope slope, Trackdir dir)
Checks whether a trackdir on a specific slope is going uphill.
Definition: track_func.h:688
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:115
Base implementation for cost accounting.
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:74
static bool stSlopeCost(TileIndex tile, Trackdir td)
Does the given track direction on the given tile yield an uphill penalty?
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
bool HasBridgeFlatRamp(Slope tileh, Axis axis)
Determines if the track on a bridge ramp is flat or goes up/down.
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition: track_func.h:619
Slope
Enumeration for the slope-type.
Definition: slope_type.h:50
static bool IsTunnelTile(TileIndex t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:35
Axis
Allow incrementing of DiagDirDiff variables.