Changeset - r8653:9269fc7dde0d
[Not reviewed]
master
1 7 0
frosch - 16 years ago 2008-02-28 17:34:34
frosch@openttd.org
(svn r12313) -Fix: YAPF and NTP did not apply penalty for uphill tracks on steep slopes.
8 files changed with 54 insertions and 65 deletions:
0 comments (0 inline, 0 general)
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -2200,10 +2200,6 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\yapf\yapf_common.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\yapf\yapf_common.hpp"
 
				>
 
			</File>
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -2197,10 +2197,6 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\yapf\yapf_common.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\yapf\yapf_common.hpp"
 
				>
 
			</File>
source.list
Show inline comments
 
@@ -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
src/pathfind.cpp
Show inline comments
 
@@ -540,24 +540,6 @@ static bool NtpCheck(NewTrackPathFinder 
 
}
 

	
 

	
 
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;
 
			}
src/rail.cpp
Show inline comments
 
@@ -113,6 +113,40 @@ extern const TrackBits _corner_to_trackb
 
	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] = {
src/track_func.h
Show inline comments
 
@@ -574,4 +574,20 @@ static inline bool IsStraightRoadTrackdi
 
	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 */
src/yapf/yapf_common.cpp
Show inline comments
 
deleted file
src/yapf/yapf_costbase.hpp
Show inline comments
 
@@ -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;
0 comments (0 inline, 0 general)