(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.

pull/155/head
frosch 16 years ago
parent 36678c0ae8
commit 4ec7f33f8c

@ -2199,10 +2199,6 @@
RelativePath=".\..\src\yapf\yapf_base.hpp"
>
</File>
<File
RelativePath=".\..\src\yapf\yapf_common.cpp"
>
</File>
<File
RelativePath=".\..\src\yapf\yapf_common.hpp"
>

@ -2196,10 +2196,6 @@
RelativePath=".\..\src\yapf\yapf_base.hpp"
>
</File>
<File
RelativePath=".\..\src\yapf\yapf_common.cpp"
>
</File>
<File
RelativePath=".\..\src\yapf\yapf_common.hpp"
>

@ -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

@ -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;
}

@ -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] = {

@ -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 */

@ -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
};

@ -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;

Loading…
Cancel
Save