Merge branch 'more_cond_orders-sx' into jgrpp
# Conflicts: # config.lib # projects/openttd_vs100.vcxproj # projects/openttd_vs100.vcxproj.filters # projects/openttd_vs80.vcproj # projects/openttd_vs90.vcproj # src/order_gui.cpp # src/order_type.h # src/saveload/afterload.cpp # src/saveload/extended_ver_sl.cpp
This commit is contained in:
@@ -432,8 +432,9 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
/* single tram bits cause reversing */
|
||||
if (IsTram() && GetSingleTramBit(m_old_tile) == ReverseDiagDir(m_exitdir)) {
|
||||
/* Single tram bits and standard road stops cause reversing. */
|
||||
if (IsRoadTT() && ((IsTram() && GetSingleTramBit(m_old_tile) == ReverseDiagDir(m_exitdir)) ||
|
||||
(IsStandardRoadStopTile(m_old_tile) && GetRoadStopDir(m_old_tile) == ReverseDiagDir(m_exitdir)))) {
|
||||
/* reverse */
|
||||
m_new_tile = m_old_tile;
|
||||
m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
|
||||
|
@@ -970,12 +970,13 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current)
|
||||
* multiple targets that are spread around, we should perform a breadth first
|
||||
* search by specifiying CalcZero as our heuristic.
|
||||
*/
|
||||
static NPFFoundTargetData NPFRouteInternal(AyStarNode *start1, bool ignore_start_tile1, AyStarNode *start2, bool ignore_start_tile2, NPFFindStationOrTileData *target, AyStar_EndNodeCheck target_proc, AyStar_CalculateH heuristic_proc, AyStarUserData *user, uint reverse_penalty, bool ignore_reserved = false)
|
||||
static NPFFoundTargetData NPFRouteInternal(AyStarNode *start1, bool ignore_start_tile1, AyStarNode *start2, bool ignore_start_tile2, NPFFindStationOrTileData *target, AyStar_EndNodeCheck target_proc, AyStar_CalculateH heuristic_proc, AyStarUserData *user, uint reverse_penalty, bool ignore_reserved = false, int max_penalty = 0)
|
||||
{
|
||||
int r;
|
||||
NPFFoundTargetData result;
|
||||
|
||||
/* Initialize procs */
|
||||
_npf_aystar.max_path_cost = max_penalty;
|
||||
_npf_aystar.CalculateH = heuristic_proc;
|
||||
_npf_aystar.EndNodeCheck = target_proc;
|
||||
_npf_aystar.FoundEndNode = NPFSaveTargetData;
|
||||
@@ -1063,7 +1064,7 @@ static NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, Trackdir track
|
||||
* reverse_penalty applied (NPF_TILE_LENGTH is the equivalent of one full
|
||||
* tile).
|
||||
*/
|
||||
static NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Trackdir trackdir1, bool ignore_start_tile1, TileIndex tile2, Trackdir trackdir2, bool ignore_start_tile2, NPFFindStationOrTileData *target, AyStarUserData *user, uint reverse_penalty)
|
||||
static NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Trackdir trackdir1, bool ignore_start_tile1, TileIndex tile2, Trackdir trackdir2, bool ignore_start_tile2, NPFFindStationOrTileData *target, AyStarUserData *user, uint reverse_penalty, int max_penalty)
|
||||
{
|
||||
AyStarNode start1;
|
||||
AyStarNode start2;
|
||||
@@ -1075,7 +1076,7 @@ static NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Tra
|
||||
|
||||
/* perform a breadth first search. Target is NULL,
|
||||
* since we are just looking for any depot...*/
|
||||
return NPFRouteInternal(&start1, ignore_start_tile1, (IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty);
|
||||
return NPFRouteInternal(&start1, ignore_start_tile1, (IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty, false, max_penalty);
|
||||
}
|
||||
|
||||
void InitializeNPF()
|
||||
@@ -1121,7 +1122,7 @@ FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penal
|
||||
Trackdir trackdir = v->GetVehicleTrackdir();
|
||||
|
||||
AyStarUserData user = { v->owner, TRANSPORT_ROAD, INVALID_RAILTYPES, v->compatible_roadtypes };
|
||||
NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, v->tile, ReverseTrackdir(trackdir), false, NULL, &user, 0);
|
||||
NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, INVALID_TILE, INVALID_TRACKDIR, false, NULL, &user, 0, max_penalty);
|
||||
|
||||
if (ftd.best_bird_dist != 0) return FindDepotData();
|
||||
|
||||
@@ -1176,7 +1177,7 @@ Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir,
|
||||
* we did not find our target, but ftd.best_trackdir contains the direction leading
|
||||
* to the tile closest to our target. */
|
||||
path_found = (ftd.best_bird_dist == 0);
|
||||
if (ftd.best_trackdir == 0xff) return INVALID_TRACK;
|
||||
if (ftd.best_trackdir == INVALID_TRACKDIR) return INVALID_TRACK;
|
||||
return TrackdirToTrack(ftd.best_trackdir);
|
||||
}
|
||||
|
||||
@@ -1211,7 +1212,7 @@ FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_penalty)
|
||||
|
||||
assert(trackdir != INVALID_TRACKDIR);
|
||||
AyStarUserData user = { v->owner, TRANSPORT_RAIL, v->compatible_railtypes, ROADTYPES_NONE };
|
||||
NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, last->tile, trackdir_rev, false, &fstd, &user, NPF_INFINITE_PENALTY);
|
||||
NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, last->tile, trackdir_rev, false, &fstd, &user, NPF_INFINITE_PENALTY, max_penalty);
|
||||
if (ftd.best_bird_dist != 0) return FindDepotData();
|
||||
|
||||
/* Found target */
|
||||
|
@@ -20,8 +20,8 @@ static const int NPF_TILE_LENGTH = 100;
|
||||
/**
|
||||
* This penalty is the equivalent of "infinite", which means that paths that
|
||||
* get this penalty will be chosen, but only if there is no other route
|
||||
* without it. Be careful with not applying this penalty to often, or the
|
||||
* total path cost might overflow..
|
||||
* without it. Be careful with not applying this penalty too often, or the
|
||||
* total path cost might overflow.
|
||||
*/
|
||||
static const int NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH;
|
||||
|
||||
@@ -35,8 +35,8 @@ static const int YAPF_TILE_CORNER_LENGTH = 71;
|
||||
/**
|
||||
* This penalty is the equivalent of "infinite", which means that paths that
|
||||
* get this penalty will be chosen, but only if there is no other route
|
||||
* without it. Be careful with not applying this penalty to often, or the
|
||||
* total path cost might overflow..
|
||||
* without it. Be careful with not applying this penalty too often, or the
|
||||
* total path cost might overflow.
|
||||
*/
|
||||
static const int YAPF_INFINITE_PENALTY = 1000 * YAPF_TILE_LENGTH;
|
||||
|
||||
|
@@ -35,6 +35,10 @@ public:
|
||||
typedef typename Node::Key Key; ///< key to hash tables
|
||||
|
||||
protected:
|
||||
int m_max_cost;
|
||||
|
||||
CYapfCostRoadT() : m_max_cost(0) {};
|
||||
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
@@ -105,6 +109,11 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
inline void SetMaxCost(int max_cost)
|
||||
{
|
||||
m_max_cost = max_cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by YAPF to calculate the cost from the origin to the given node.
|
||||
* Calculates only the cost of given node, adds it to the parent node cost
|
||||
@@ -120,6 +129,8 @@ public:
|
||||
/* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
|
||||
TileIndex tile = n.m_key.m_tile;
|
||||
Trackdir trackdir = n.m_key.m_td;
|
||||
int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0;
|
||||
|
||||
for (;;) {
|
||||
/* base tile cost depending on distance between edges */
|
||||
segment_cost += Yapf().OneTileCost(tile, trackdir);
|
||||
@@ -128,6 +139,12 @@ public:
|
||||
/* we have reached the vehicle's destination - segment should end here to avoid target skipping */
|
||||
if (Yapf().PfDetectDestinationTile(tile, trackdir)) break;
|
||||
|
||||
/* Finish if we already exceeded the maximum path cost (i.e. when
|
||||
* searching for the nearest depot). */
|
||||
if (m_max_cost > 0 && (parent_cost + segment_cost) > m_max_cost) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* stop if we have just entered the depot */
|
||||
if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
|
||||
/* next time we will reverse and leave the depot */
|
||||
@@ -172,7 +189,6 @@ public:
|
||||
n.m_segment_last_td = trackdir;
|
||||
|
||||
/* save also tile cost */
|
||||
int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0;
|
||||
n.m_cost = parent_cost + segment_cost;
|
||||
return true;
|
||||
}
|
||||
@@ -453,15 +469,12 @@ public:
|
||||
* @param tile Tile of the vehicle.
|
||||
* @param td Trackdir of the vehicle.
|
||||
* @param max_distance max length (penalty) for paths.
|
||||
* @todo max_distance not used by YAPF for road vehicles.
|
||||
* It can be removed or copy the SetMaxCost() strategy
|
||||
* applied in YAPF for rail. The best depot can be at
|
||||
* a distance greater than max_distance.
|
||||
*/
|
||||
inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
|
||||
{
|
||||
/* Set origin. */
|
||||
Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
|
||||
Yapf().SetMaxCost(max_distance);
|
||||
|
||||
/* Find the best path and return if no depot is found. */
|
||||
if (!Yapf().FindPath(v)) return FindDepotData();
|
||||
|
Reference in New Issue
Block a user