Changeset - r22940:b114928ab861
[Not reviewed]
master
0 7 0
J0anJosep - 6 years ago 2018-05-12 16:19:40
juanjo.ng.83@gmail.com
Codechange: Use HasTrack(dir) to improve code readability.
7 files changed with 31 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/pathfinder/opf/opf_ship.cpp
Show inline comments
 
@@ -206,7 +206,7 @@ Track OPFShipChooseTrack(const Ship *v, 
 
	TrackBits rev_tracks = TrackStatusToTrackBits(GetTileTrackStatus(tile2, TRANSPORT_WATER, 0)) &
 
			DiagdirReachesTracks(rev_enterdir);
 

	
 
	if ((rev_tracks & TrackToTrackBits(cur_track) != TRACK_BIT_NONE) {
 
	if (HasTrack(rev_tracks, cur_track)) {
 
		rev_dist = FindShipTrack(v, tile2, rev_enterdir, TrackToTrackBits(cur_track), tile, &track);
 
		if (rev_dist != UINT_MAX) rev_dist++; // penalty for reversing
 
	}
src/pathfinder/yapf/yapf_common.hpp
Show inline comments
 
@@ -142,7 +142,7 @@ public:
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	inline bool PfDetectDestination(Node &n)
 
	{
 
		return (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE);
 
		return (n.m_key.m_tile == m_destTile) && HasTrackdir(m_destTrackdirs, n.GetTrackdir());
 
	}
 

	
 
	/**
src/pathfinder/yapf/yapf_costrail.hpp
Show inline comments
 
@@ -104,7 +104,7 @@ public:
 
		assert(IsValidTrackdir(td2));
 
		int cost = 0;
 
		if (TrackFollower::Allow90degTurns()
 
				&& ((TrackdirToTrackdirBits(td2) & TrackdirCrossesTrackdirs(td1)) != TRACKDIR_BIT_NONE)) {
 
				&& HasTrackdir(TrackdirCrossesTrackdirs(td1), td2)) {
 
			/* 90-deg curve penalty */
 
			cost += Yapf().PfGetSettings().rail_curve90_penalty;
 
		} else if (td2 != NextTrackdir(td1)) {
 
@@ -280,7 +280,7 @@ public:
 
	{
 
		assert(!n.flags_u.flags_s.m_targed_seen);
 
		assert(tf->m_new_tile == n.m_key.m_tile);
 
		assert((TrackdirToTrackdirBits(n.m_key.m_td) & tf->m_new_td_bits) != TRACKDIR_BIT_NONE);
 
		assert((HasTrackdir(tf->m_new_td_bits, n.m_key.m_td)));
 

	
 
		CPerfStart perf_cost(Yapf().m_perf_cost);
 

	
src/pathfinder/yapf/yapf_destrail.hpp
Show inline comments
 
@@ -172,7 +172,7 @@ public:
 
				&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
 
		}
 

	
 
		return (tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(td)) != TRACKDIR_BIT_NONE);
 
		return (tile == m_destTile) && HasTrackdir(m_destTrackdirs, td);
 
	}
 

	
 
	/**
src/pathfinder/yapf/yapf_road.cpp
Show inline comments
 
@@ -260,7 +260,7 @@ public:
 
				(m_non_artic || IsDriveThroughStopTile(tile));
 
		}
 

	
 
		return tile == m_destTile && ((m_destTrackdirs & TrackdirToTrackdirBits(trackdir)) != TRACKDIR_BIT_NONE);
 
		return tile == m_destTile && HasTrackdir(m_destTrackdirs, trackdir);
 
	}
 

	
 
	/**
 
@@ -420,7 +420,7 @@ public:
 
		/* set origin (tile, trackdir) */
 
		TileIndex src_tile = v->tile;
 
		Trackdir src_td = v->GetVehicleTrackdir();
 
		if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
 
		if (!HasTrackdir(TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->compatible_roadtypes)), src_td)) {
 
			/* sometimes the roadveh is not on the road (it resides on non-existing track)
 
			 * how should we handle that situation? */
 
			return false;
 
@@ -503,7 +503,7 @@ FindDepotData YapfRoadVehicleFindNearest
 
{
 
	TileIndex tile = v->tile;
 
	Trackdir trackdir = v->GetVehicleTrackdir();
 
	if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
 
	if (!HasTrackdir(TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)), trackdir)) {
 
		return FindDepotData();
 
	}
 

	
src/pathfinder/yapf/yapf_ship.cpp
Show inline comments
 
@@ -65,7 +65,7 @@ public:
 

	
 
			/* use vehicle's current direction if that's possible, otherwise use first usable one. */
 
			Trackdir veh_dir = v->GetVehicleTrackdir();
 
			return ((trackdirs & TrackdirToTrackdirBits(veh_dir)) != 0) ? veh_dir : (Trackdir)FindFirstBit2x64(trackdirs);
 
			return (HasTrackdir(trackdirs, veh_dir)) ? veh_dir : (Trackdir)FindFirstBit2x64(trackdirs);
 
		}
 

	
 
		/* move back to the old tile/trackdir (where ship is coming from) */
src/track_func.h
Show inline comments
 
@@ -332,6 +332,28 @@ static inline TrackdirBits TrackBitsToTr
 
}
 

	
 
/**
 
 * Checks whether a TrackBits has a given Track.
 
 * @param tracks The track bits.
 
 * @param track The track to check.
 
 */
 
static inline bool HasTrack(TrackBits tracks, Track track)
 
{
 
	assert(IsValidTrack(track));
 
	return HasBit(tracks, track);
 
}
 

	
 
/**
 
 * Checks whether a TrackdirBits has a given Trackdir.
 
 * @param trackdirs The trackdir bits.
 
 * @param trackdir The trackdir to check.
 
 */
 
static inline bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
 
{
 
	assert(IsValidTrackdir(trackdir));
 
	return HasBit(trackdirs, trackdir);
 
}
 

	
 
/**
 
 * Returns the present-trackdir-information of a TrackStatus.
 
 *
 
 * @param ts The TrackStatus returned by GetTileTrackStatus()
0 comments (0 inline, 0 general)