Merge branch 'cargo_type_order' into jgrpp

# Conflicts:
#	src/pathfinder/yapf/yapf_common.hpp
#	src/saveload/extended_ver_sl.cpp
#	src/saveload/order_sl.cpp
#	src/saveload/station_sl.cpp
#	src/track_func.h
This commit is contained in:
Jonathan G Rennison
2018-07-02 21:04:06 +01:00
45 changed files with 183 additions and 145 deletions

View File

@@ -74,7 +74,8 @@ struct CFollowTrackT
inline void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf)
{
assert((!IsRoadTT() || m_veh != NULL) && (!IsRailTT() || railtype_override != INVALID_RAILTYPES));
assert(!IsRoadTT() || m_veh != NULL);
assert(!IsRailTT() || railtype_override != INVALID_RAILTYPES);
m_veh_owner = o;
m_pPerf = pPerf;
/* don't worry, all is inlined so compiler should remove unnecessary initializations */
@@ -228,8 +229,6 @@ protected:
m_is_station = true;
} else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
m_is_station = true;
} else {
m_is_station = false;
}
}
@@ -242,7 +241,7 @@ protected:
} else {
m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), IsRoadTT() ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0));
if (IsTram() && m_new_td_bits == 0) {
if (IsTram() && m_new_td_bits == TRACKDIR_BIT_NONE) {
/* GetTileTrackStatus() returns 0 for single tram bits.
* As we cannot change it there (easily) without breaking something, change it here */
switch (GetSingleTramBit(m_new_tile)) {

View File

@@ -814,7 +814,7 @@ static TrackdirBits GetDriveableTrackdirBits(TileIndex dst_tile, Trackdir src_tr
{
TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, type, subtype));
if (trackdirbits == 0 && type == TRANSPORT_ROAD && HasBit(subtype, ROADTYPE_TRAM)) {
if (trackdirbits == TRACKDIR_BIT_NONE && type == TRANSPORT_ROAD && HasBit(subtype, ROADTYPE_TRAM)) {
/* GetTileTrackStatus() returns 0 for single tram bits.
* As we cannot change it there (easily) without breaking something, change it here */
switch (GetSingleTramBit(dst_tile)) {
@@ -907,7 +907,7 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current)
trackdirbits = GetDriveableTrackdirBits(dst_tile, src_trackdir, type, subtype);
if (trackdirbits == 0) {
if (trackdirbits == TRACKDIR_BIT_NONE) {
/* We cannot enter the next tile. Road vehicles can reverse, others reach dead end */
if (type != TRANSPORT_ROAD || HasBit(subtype, ROADTYPE_TRAM)) return;
@@ -931,7 +931,7 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current)
/* Enumerate possible track */
uint i = 0;
while (trackdirbits != 0) {
while (trackdirbits != TRACKDIR_BIT_NONE) {
Trackdir dst_trackdir = RemoveFirstTrackdir(&trackdirbits);
DEBUG(npf, 5, "Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits);

View File

@@ -193,9 +193,14 @@ bad:;
}
/**
* returns the track to choose on the next tile, or -1 when it's better to
* reverse. The tile given is the tile we are about to enter, enterdir is the
* direction in which we are entering the tile
* Finds the best track to choose on the next tile and
* returns INVALID_TRACK when it is better to reverse.
* @param v The ship.
* @param tile The tile we are about to enter.
* @param enterdir The direction entering the tile.
* @param tracks The tracks available on new tile.
* @param[out] path_found Whether a path has been found.
* @return Best track on next tile or INVALID_TRACK when better to reverse.
*/
Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
{
@@ -205,13 +210,15 @@ Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir,
Track track;
/* Let's find out how far it would be if we would reverse first */
Trackdir trackdir = v->GetVehicleTrackdir();
TrackBits b = TrackStatusToTrackBits(GetTileTrackStatus(tile2, TRANSPORT_WATER, 0)) & DiagdirReachesTracks(ReverseDiagDir(enterdir)) & TrackdirBitsToTrackBits(TrackdirToTrackdirBits(trackdir));
uint rev_dist = UINT_MAX; // distance if we reverse
Track cur_track = TrackdirToTrack(v->GetVehicleTrackdir()); // track on the current tile
DiagDirection rev_enterdir = ReverseDiagDir(enterdir);
TrackBits rev_tracks = TrackStatusToTrackBits(GetTileTrackStatus(tile2, TRANSPORT_WATER, 0)) &
DiagdirReachesTracks(rev_enterdir);
uint distr = UINT_MAX; // distance if we reversed
if (b != 0) {
distr = FindShipTrack(v, tile2, ReverseDiagDir(enterdir), b, tile, &track);
if (distr != UINT_MAX) distr++; // penalty for reversing
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
}
/* And if we would not reverse? */
@@ -219,6 +226,6 @@ Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir,
/* Due to the way this pathfinder works we cannot determine whether we're lost or not. */
path_found = true;
if (dist <= distr) return track;
if (dist <= rev_dist) return track;
return INVALID_TRACK; // We could better reverse
}

View File

@@ -105,7 +105,7 @@ public:
assert(IsValidTrackdir(td2));
int cost = 0;
if (TrackFollower::Allow90degTurns()
&& ((TrackdirToTrackdirBits(td2) & (TrackdirBits)TrackdirCrossesTrackdirs(td1)) != 0)) {
&& HasTrackdir(TrackdirCrossesTrackdirs(td1), td2)) {
/* 90-deg curve penalty */
cost += Yapf().PfGetSettings().rail_curve90_penalty;
} else if (td2 != NextTrackdir(td1)) {
@@ -418,7 +418,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);

View File

@@ -166,16 +166,13 @@ public:
/** Called by YAPF to detect if node ends in the desired destination */
inline bool PfDetectDestination(TileIndex tile, Trackdir td)
{
bool bDest;
if (m_dest_station_id != INVALID_STATION) {
bDest = HasStationTileRail(tile)
return HasStationTileRail(tile)
&& (GetStationIndex(tile) == m_dest_station_id)
&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
} else {
bDest = (tile == m_destTile)
&& ((m_destTrackdirs & TrackdirToTrackdirBits(td)) != TRACKDIR_BIT_NONE);
}
return bDest;
return (tile == m_destTile) && HasTrackdir(m_destTrackdirs, td);
}
/**

View File

@@ -197,8 +197,7 @@ public:
/** Called by YAPF to detect if node ends in the desired destination */
inline bool PfDetectDestination(Node &n)
{
bool bDest = IsRoadDepotTile(n.m_segment_last_tile);
return bDest;
return IsRoadDepotTile(n.m_segment_last_tile);
}
inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
@@ -273,7 +272,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);
}
/**
@@ -433,7 +432,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;
@@ -516,7 +515,7 @@ FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dist
{
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();
}

View File

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