summaryrefslogtreecommitdiff
path: root/src/pathfinder/yapf
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-02 10:44:38 +0000
committerrubidium <rubidium@openttd.org>2009-12-02 10:44:38 +0000
commitc10e95314156cfaf856a3075118b1bd2c698d139 (patch)
tree542edd8f84d6ac34d3012f25d783cefceaafcd97 /src/pathfinder/yapf
parentc56c892b2c9a30d7a5d4e7a59053e13471f038ab (diff)
downloadopenttd-c10e95314156cfaf856a3075118b1bd2c698d139.tar.xz
(svn r18373) -Codechange: unify some road pathfinder functions
Diffstat (limited to 'src/pathfinder/yapf')
-rw-r--r--src/pathfinder/yapf/yapf.h24
-rw-r--r--src/pathfinder/yapf/yapf_road.cpp21
-rw-r--r--src/pathfinder/yapf/yapf_ship.cpp2
3 files changed, 21 insertions, 26 deletions
diff --git a/src/pathfinder/yapf/yapf.h b/src/pathfinder/yapf/yapf.h
index 778ddf4ba..b020965d1 100644
--- a/src/pathfinder/yapf/yapf.h
+++ b/src/pathfinder/yapf/yapf.h
@@ -24,15 +24,17 @@
* @param tracks available tracks on the new tile (to choose from)
* @return the best trackdir for next turn or INVALID_TRACK if the path could not be found
*/
-Track YapfChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks);
+Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks);
-/** Finds the best path for given road vehicle.
- * @param v the RV that needs to find a path
- * @param tile the tile to find the path from (should be next tile the RV is about to enter)
- * @param enterdir diagonal direction which the RV will enter this new tile from
- * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
+/**
+ * Finds the best path for given road vehicle using YAPF.
+ * @param v the RV that needs to find a path
+ * @param tile the tile to find the path from (should be next tile the RV is about to enter)
+ * @param enterdir diagonal direction which the RV will enter this new tile from
+ * @param trackdirs available trackdirs on the new tile (to choose from)
+ * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
*/
-Trackdir YapfChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir);
+Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs);
/**
* Finds the best path for given train using YAPF.
@@ -62,15 +64,15 @@ uint YapfRoadVehDistanceToTile(const RoadVehicle *v, TileIndex tile);
*/
bool YapfFindNearestRoadVehicleCompatibleStop(const RoadVehicle *v, StationID station, TileIndex *stop_tile);
-/** Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing.
+/**
+ * Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.
* @param v vehicle that needs to go to some depot
* @param max_distance max distance (number of track tiles) from the current vehicle position
* (used also as optimization - the pathfinder can stop path finding if max_distance
* was reached and no depot was seen)
- * @param depot_tile receives the depot tile if depot was found
- * @return true if depot was found.
+ * @return the data about the depot
*/
-bool YapfFindNearestRoadDepot(const RoadVehicle *v, int max_distance, TileIndex *depot_tile);
+FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance);
/**
* Used when user sends train to the nearest depot or if train needs servicing using YAPF.
diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp
index 670ba23b1..9c9c9fe32 100644
--- a/src/pathfinder/yapf/yapf_road.cpp
+++ b/src/pathfinder/yapf/yapf_road.cpp
@@ -539,7 +539,7 @@ struct CYapfRoadAnyRoadVehicleCompatibleStopOfGivenStation1 : CYapfT<CYapfRoad_T
struct CYapfRoadAnyRoadVehicleCompatibleStopOfGivenStation2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyRoadVehicleCompatibleStopOfGivenStation2, CRoadNodeListExitDir , CYapfDestinationAnyRoadVehicleCompatibleStopOfGivenStationT> > {};
-Trackdir YapfChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir)
+Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs)
{
/* default is YAPF type 2 */
typedef Trackdir (*PfnChooseRoadTrack)(const RoadVehicle*, TileIndex, DiagDirection);
@@ -551,7 +551,7 @@ Trackdir YapfChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection
}
Trackdir td_ret = pfnChooseRoadTrack(v, tile, enterdir);
- return td_ret;
+ return (td_ret != INVALID_TRACKDIR) ? td_ret : (Trackdir)FindFirstBit2x64(trackdirs);
}
uint YapfRoadVehDistanceToTile(const RoadVehicle *v, TileIndex tile)
@@ -575,21 +575,12 @@ uint YapfRoadVehDistanceToTile(const RoadVehicle *v, TileIndex tile)
return dist;
}
-bool YapfFindNearestRoadDepot(const RoadVehicle *v, int max_distance, TileIndex *depot_tile)
+FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance)
{
- *depot_tile = INVALID_TILE;
-
TileIndex tile = v->tile;
Trackdir trackdir = v->GetVehicleTrackdir();
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
- return false;
- }
-
- /* handle the case when our vehicle is already in the depot tile */
- if (IsRoadDepotTile(tile)) {
- /* only what we need to return is the Depot* */
- *depot_tile = tile;
- return true;
+ return FindDepotData();
}
/* default is YAPF type 2 */
@@ -601,7 +592,9 @@ bool YapfFindNearestRoadDepot(const RoadVehicle *v, int max_distance, TileIndex
pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg
}
- bool ret = pfnFindNearestDepot(v, tile, trackdir, max_distance, depot_tile);
+ FindDepotData fdd;
+ bool ret = pfnFindNearestDepot(v, tile, trackdir, max_distance, &fdd.tile);
+ fdd.best_length = ret ? max_distance / 2 : UINT_MAX; // some fake distance or NOT_FOUND
return ret;
}
diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp
index b1a6e1698..3647efa2d 100644
--- a/src/pathfinder/yapf/yapf_ship.cpp
+++ b/src/pathfinder/yapf/yapf_ship.cpp
@@ -169,7 +169,7 @@ struct CYapfShip2 : CYapfT<CYapfShip_TypesT<CYapfShip2, CFollowTrackWater , C
struct CYapfShip3 : CYapfT<CYapfShip_TypesT<CYapfShip3, CFollowTrackWaterNo90, CShipNodeListTrackDir> > {};
/** Ship controller helper - path finder invoker */
-Track YapfChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
+Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
{
/* default is YAPF type 2 */
typedef Trackdir (*PfnChooseShipTrack)(const Ship*, TileIndex, DiagDirection, TrackBits);