summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--projects/openttd_vs80.vcproj4
-rw-r--r--projects/openttd_vs90.vcproj4
-rw-r--r--source.list1
-rw-r--r--src/pathfind.cpp23
-rw-r--r--src/rail.cpp34
-rw-r--r--src/track_func.h16
-rw-r--r--src/yapf/yapf_common.cpp31
-rw-r--r--src/yapf/yapf_costbase.hpp6
8 files changed, 54 insertions, 65 deletions
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index c51f6c5cc..d0832dc07 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -2200,10 +2200,6 @@
>
</File>
<File
- RelativePath=".\..\src\yapf\yapf_common.cpp"
- >
- </File>
- <File
RelativePath=".\..\src\yapf\yapf_common.hpp"
>
</File>
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj
index 2551d8a8f..6865d21fb 100644
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -2197,10 +2197,6 @@
>
</File>
<File
- RelativePath=".\..\src\yapf\yapf_common.cpp"
- >
- </File>
- <File
RelativePath=".\..\src\yapf\yapf_common.hpp"
>
</File>
diff --git a/source.list b/source.list
index ba30958e4..c209f3f02 100644
--- a/source.list
+++ b/source.list
@@ -472,7 +472,6 @@ yapf/track_dir.hpp
yapf/yapf.h
yapf/yapf.hpp
yapf/yapf_base.hpp
-yapf/yapf_common.cpp
yapf/yapf_common.hpp
yapf/yapf_costbase.hpp
yapf/yapf_costcache.hpp
diff --git a/src/pathfind.cpp b/src/pathfind.cpp
index ad2b40fae..84569bbe0 100644
--- a/src/pathfind.cpp
+++ b/src/pathfind.cpp
@@ -540,24 +540,6 @@ static bool NtpCheck(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint len
}
-static const uint16 _is_upwards_slope[15] = {
- 0, ///< no tileh
- (1 << TRACKDIR_X_SW) | (1 << TRACKDIR_Y_NW), ///< 1
- (1 << TRACKDIR_X_SW) | (1 << TRACKDIR_Y_SE), ///< 2
- (1 << TRACKDIR_X_SW), ///< 3
- (1 << TRACKDIR_X_NE) | (1 << TRACKDIR_Y_SE), ///< 4
- 0, ///< 5
- (1 << TRACKDIR_Y_SE), ///< 6
- 0, ///< 7
- (1 << TRACKDIR_X_NE) | (1 << TRACKDIR_Y_NW), ///< 8,
- (1 << TRACKDIR_Y_NW), ///< 9
- 0, ///< 10
- 0, ///< 11,
- (1 << TRACKDIR_X_NE), ///< 12
- 0, ///< 13
- 0, ///< 14
-};
-
static uint DistanceMoo(TileIndex t0, TileIndex t1)
{
const uint dx = Delta(TileX(t0), TileX(t1));
@@ -727,9 +709,8 @@ start_at:
si.cur_length += _length_of_track[track];
- /* Check if this rail is an upwards slope. If it is, then add a penalty.
- * Small optimization here.. if (track&7)>1 then it can't be a slope so we avoid calling GetTileSlope */
- if ((track & 7) <= 1 && (_is_upwards_slope[GetTileSlope(tile, NULL)] & (1 << track)) ) {
+ /* Check if this rail is an upwards slope. If it is, then add a penalty. */
+ if (IsDiagonalTrackdir(track) && IsUphillTrackdir(GetTileSlope(tile, NULL), track)) {
// upwards slope. add some penalty.
si.cur_length += 4 * DIAG_FACTOR;
}
diff --git a/src/rail.cpp b/src/rail.cpp
index ab94cc04c..aeda9ab98 100644
--- a/src/rail.cpp
+++ b/src/rail.cpp
@@ -113,6 +113,40 @@ extern const TrackBits _corner_to_trackbits[] = {
TRACK_BIT_LEFT, TRACK_BIT_LOWER, TRACK_BIT_RIGHT, TRACK_BIT_UPPER,
};
+extern const TrackdirBits _uphill_trackdirs[] = {
+ TRACKDIR_BIT_NONE , ///< 0 SLOPE_FLAT
+ TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_NW, ///< 1 SLOPE_W -> inclined for diagonal track
+ TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_SE, ///< 2 SLOPE_S -> inclined for diagonal track
+ TRACKDIR_BIT_X_SW , ///< 3 SLOPE_SW
+ TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE, ///< 4 SLOPE_E -> inclined for diagonal track
+ TRACKDIR_BIT_NONE , ///< 5 SLOPE_EW
+ TRACKDIR_BIT_Y_SE , ///< 6 SLOPE_SE
+ TRACKDIR_BIT_NONE , ///< 7 SLOPE_WSE -> leveled
+ TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_NW, ///< 8 SLOPE_N -> inclined for diagonal track
+ TRACKDIR_BIT_Y_NW , ///< 9 SLOPE_NW
+ TRACKDIR_BIT_NONE , ///< 10 SLOPE_NS
+ TRACKDIR_BIT_NONE , ///< 11 SLOPE_NWS -> leveled
+ TRACKDIR_BIT_X_NE , ///< 12 SLOPE_NE
+ TRACKDIR_BIT_NONE , ///< 13 SLOPE_ENW -> leveled
+ TRACKDIR_BIT_NONE , ///< 14 SLOPE_SEN -> leveled
+ TRACKDIR_BIT_NONE , ///< 15 invalid
+ TRACKDIR_BIT_NONE , ///< 16 invalid
+ TRACKDIR_BIT_NONE , ///< 17 invalid
+ TRACKDIR_BIT_NONE , ///< 18 invalid
+ TRACKDIR_BIT_NONE , ///< 19 invalid
+ TRACKDIR_BIT_NONE , ///< 20 invalid
+ TRACKDIR_BIT_NONE , ///< 21 invalid
+ TRACKDIR_BIT_NONE , ///< 22 invalid
+ TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_SE, ///< 23 SLOPE_STEEP_S -> inclined for diagonal track
+ TRACKDIR_BIT_NONE , ///< 24 invalid
+ TRACKDIR_BIT_NONE , ///< 25 invalid
+ TRACKDIR_BIT_NONE , ///< 26 invalid
+ TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_NW, ///< 27 SLOPE_STEEP_W -> inclined for diagonal track
+ TRACKDIR_BIT_NONE , ///< 28 invalid
+ TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_NW, ///< 29 SLOPE_STEEP_N -> inclined for diagonal track
+ TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE, ///< 30 SLOPE_STEEP_E -> inclined for diagonal track
+};
+
/* The default multiplier for the cost of building different types of railway
* track, which will be divided by 8. Can be changed by newgrf files. */
const int _default_railtype_cost_multiplier[RAILTYPE_END] = {
diff --git a/src/track_func.h b/src/track_func.h
index 38a1bba66..88d8d423e 100644
--- a/src/track_func.h
+++ b/src/track_func.h
@@ -574,4 +574,20 @@ static inline bool IsStraightRoadTrackdir(Trackdir dir)
return (dir & 0x06) == 0;
}
+/**
+ * Checks whether a trackdir on a specific slope is going uphill.
+ *
+ * Valid for rail and road tracks.
+ * Valid for tile-slopes (under foundation) and foundation-slopes (on foundation).
+ *
+ * @param slope The slope of the tile.
+ * @param dir The trackdir of interest.
+ * @return true iff the track goes upwards.
+ */
+static inline bool IsUphillTrackdir(Slope slope, Trackdir dir)
+{
+ extern const TrackdirBits _uphill_trackdirs[];
+ return HasBit(_uphill_trackdirs[RemoveHalftileSlope(slope)], dir);
+}
+
#endif /* TRACK_FUNC_H */
diff --git a/src/yapf/yapf_common.cpp b/src/yapf/yapf_common.cpp
deleted file mode 100644
index 31e3a7b2e..000000000
--- a/src/yapf/yapf_common.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/* $Id$ */
-
-/** @file yapf_common.cpp */
-
-#include "../stdafx.h"
-
-#include "yapf.hpp"
-#include "follow_track.hpp"
-#include "yapf_node_rail.hpp"
-#include "yapf_costbase.hpp"
-#include "yapf_costcache.hpp"
-
-/** translate tileh to the bitset of up-hill trackdirs */
-const TrackdirBits CYapfCostBase::c_upwards_slopes[] = {
- TRACKDIR_BIT_NONE , ///< no tileh
- TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_NW, ///< 1
- TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_SE, ///< 2
- TRACKDIR_BIT_X_SW , ///< 3
- TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE, ///< 4
- TRACKDIR_BIT_NONE , ///< 5
- TRACKDIR_BIT_Y_SE , ///< 6
- TRACKDIR_BIT_NONE , ///< 7
- TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_NW, ///< 8
- TRACKDIR_BIT_Y_NW , ///< 9
- TRACKDIR_BIT_NONE , ///< 10
- TRACKDIR_BIT_NONE , ///< 11
- TRACKDIR_BIT_X_NE , ///< 12
- TRACKDIR_BIT_NONE , ///< 13
- TRACKDIR_BIT_NONE , ///< 14
- TRACKDIR_BIT_NONE , ///< 15
-};
diff --git a/src/yapf/yapf_costbase.hpp b/src/yapf/yapf_costbase.hpp
index 010c53ce1..6aef7fbd0 100644
--- a/src/yapf/yapf_costbase.hpp
+++ b/src/yapf/yapf_costbase.hpp
@@ -4,8 +4,6 @@
#define YAPF_COSTBASE_HPP
struct CYapfCostBase {
- static const TrackdirBits c_upwards_slopes[16];
-
FORCEINLINE static bool stSlopeCost(TileIndex tile, Trackdir td)
{
if (IsDiagonalTrackdir(td)) {
@@ -19,8 +17,8 @@ struct CYapfCostBase {
} else {
// not bridge ramp
if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope
- uint tile_slope = GetTileSlope(tile, NULL) & 0x0F;
- if ((c_upwards_slopes[tile_slope] & TrackdirToTrackdirBits(td)) != 0) return true; // slopes uphill => apply penalty
+ Slope tile_slope = GetTileSlope(tile, NULL);
+ return IsUphillTrackdir(tile_slope, td); // slopes uphill => apply penalty
}
}
return false;