OpenTTD Source: src/pathfinder/yapf/yapf_costbase.hpp Source File

OpenTTD Source 14.0-RC3

yapf_costbase.hpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #ifndef YAPF_COSTBASE_HPP
11 #define YAPF_COSTBASE_HPP
12
14 struct CYapfCostBase {
21 inline static bool stSlopeCost(TileIndex tile, Trackdir td)
22 {
23 if (IsDiagonalTrackdir(td)) {
24 if (IsBridgeTile(tile)) {
25 /* it is bridge ramp, check if we are entering the bridge */
26 if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are leaving it, no penalty
27 /* we are entering the bridge */
28 Slope tile_slope = GetTileSlope(tile);
29 Axis axis = DiagDirToAxis(GetTunnelBridgeDirection(tile));
30 return !HasBridgeFlatRamp(tile_slope, axis);
31 } else {
32 /* not bridge ramp */
33 if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope
34 Slope tile_slope = GetTileSlope(tile);
35 return IsUphillTrackdir(tile_slope, td); // slopes uphill => apply penalty
36 }
37 }
38 return false;
39 }
40 };
41
42 #endif /* YAPF_COSTBASE_HPP */
IsUphillTrackdir
bool IsUphillTrackdir(Slope slope, Trackdir dir)
Checks whether a trackdir on a specific slope is going uphill.
Definition: track_func.h:700
IsTunnelTile
bool IsTunnelTile(Tile t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:34
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:116
TrackdirToExitdir
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:439
DiagDirToAxis
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
CYapfCostBase
Base implementation for cost accounting.
Definition: yapf_costbase.hpp:14
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
CYapfCostBase::stSlopeCost
static bool stSlopeCost(TileIndex tile, Trackdir td)
Does the given track direction on the given tile yield an uphill penalty?
Definition: yapf_costbase.hpp:21
IsBridgeTile
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
HasBridgeFlatRamp
bool HasBridgeFlatRamp(Slope tileh, Axis axis)
Determines if the track on a bridge ramp is flat or goes up/down.
Definition: tunnelbridge_cmd.cpp:145
IsDiagonalTrackdir
bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition: track_func.h:631
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26