OpenTTD Source  20241108-master-g80f628063a
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 
13 #include "../../bridge_map.h"
14 #include "../../tile_type.h"
15 #include "../../track_func.h"
16 #include "../../track_type.h"
17 #include "../../tunnelbridge_map.h"
18 
20 struct CYapfCostBase {
27  inline static bool stSlopeCost(TileIndex tile, Trackdir td)
28  {
29  if (IsDiagonalTrackdir(td)) {
30  if (IsBridgeTile(tile)) {
31  /* it is bridge ramp, check if we are entering the bridge */
32  if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are leaving it, no penalty
33  /* we are entering the bridge */
34  Slope tile_slope = GetTileSlope(tile);
36  return !HasBridgeFlatRamp(tile_slope, axis);
37  } else {
38  /* not bridge ramp */
39  if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope
40  Slope tile_slope = GetTileSlope(tile);
41  return IsUphillTrackdir(tile_slope, td); // slopes uphill => apply penalty
42  }
43  }
44  return false;
45  }
46 };
47 
48 #endif /* YAPF_COSTBASE_HPP */
bool HasBridgeFlatRamp(Slope tileh, Axis axis)
Determines if the track on a bridge ramp is flat or goes up/down.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Axis
Allow incrementing of DiagDirDiff variables.
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
Base implementation for cost accounting.
static bool stSlopeCost(TileIndex tile, Trackdir td)
Does the given track direction on the given tile yield an uphill penalty?
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition: tile_map.h:279
bool IsUphillTrackdir(Slope slope, Trackdir dir)
Checks whether a trackdir on a specific slope is going uphill.
Definition: track_func.h:700
bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition: track_func.h:631
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
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
bool IsTunnelTile(Tile t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:34
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.