Changeset - r16768:069c18958074
[Not reviewed]
master
0 7 0
rubidium - 13 years ago 2010-12-13 21:56:40
rubidium@openttd.org
(svn r21511) -Feature: vehicle lost message for ships
7 files changed with 26 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/pathfinder/npf/npf.cpp
Show inline comments
 
@@ -1156,13 +1156,13 @@ Trackdir NPFRoadVehicleChooseTrack(const
 
	path_found = (ftd.best_bird_dist == 0);
 
	return ftd.best_trackdir;
 
}
 

	
 
/*** Ships ***/
 

	
 
Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
 
Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
 
{
 
	NPFFindStationOrTileData fstd;
 
	Trackdir trackdir = v->GetVehicleTrackdir();
 
	assert(trackdir != INVALID_TRACKDIR); // Check that we are not in a depot
 

	
 
	NPFFillWithOrderData(&fstd, v);
 
@@ -1170,12 +1170,13 @@ Track NPFShipChooseTrack(const Ship *v, 
 
	NPFFoundTargetData ftd = NPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, true, &fstd, TRANSPORT_WATER, 0, v->owner, INVALID_RAILTYPES);
 

	
 
	/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains
 
	 * the direction we need to take to get there, if ftd.best_bird_dist is not 0,
 
	 * 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;
 
	return TrackdirToTrack(ftd.best_trackdir);
 
}
 

	
 
/*** Trains ***/
 

	
src/pathfinder/npf/npf_func.h
Show inline comments
 
@@ -41,15 +41,16 @@ Trackdir NPFRoadVehicleChooseTrack(const
 
/**
 
 * Finds the best path for given ship using NPF.
 
 * @param v        the ship that needs to find a path
 
 * @param tile     the tile to find the path from (should be next tile the ship is about to enter)
 
 * @param enterdir diagonal direction which the ship will enter this new tile from
 
 * @param tracks   available tracks on the new tile (to choose from)
 
 * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
 
 * @return         the best trackdir for next turn or INVALID_TRACK if the path could not be found
 
 */
 
Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks);
 
Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found);
 

	
 
/**
 
 * Used when user sends train to the nearest depot or if train needs servicing using NPF
 
 * @param v            train that needs to go to some depot
 
 * @param max_penalty  max max_penalty (in pathfinder penalty) from the current train position
 
 *                     (used also as optimization - the pathfinder can stop path finding if max_penalty
src/pathfinder/opf/opf_ship.cpp
Show inline comments
 
@@ -180,13 +180,13 @@ 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
 
 */
 
Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
 
Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
 
{
 
	assert(IsValidDiagDirection(enterdir));
 

	
 
	TileIndex tile2 = TILE_ADD(tile, -TileOffsByDiagDir(enterdir));
 
	Track track;
 

	
 
@@ -199,9 +199,12 @@ Track OPFShipChooseTrack(const Ship *v, 
 
		if (distr != UINT_MAX) distr++; // penalty for reversing
 
	}
 

	
 
	/* And if we would not reverse? */
 
	uint dist = FindShipTrack(v, tile, enterdir, tracks, 0, &track);
 

	
 
	/* If the dist equals zero, or distr equals one (the extra reversing penalty),
 
	 * then we found our destination and we are not lost. */
 
	path_found = (dist == 0 || distr == 1);
 
	if (dist <= distr) return track;
 
	return INVALID_TRACK; // We could better reverse
 
}
src/pathfinder/opf/opf_ship.h
Show inline comments
 
@@ -20,11 +20,12 @@
 
/**
 
 * Finds the best path for given ship using OPF.
 
 * @param v        the ship that needs to find a path
 
 * @param tile     the tile to find the path from (should be next tile the ship is about to enter)
 
 * @param enterdir diagonal direction which the ship will enter this new tile from
 
 * @param tracks   available tracks on the new tile (to choose from)
 
 * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
 
 * @return         the best trackdir for next turn or INVALID_TRACK if the path could not be found
 
 */
 
Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks);
 
Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found);
 

	
 
#endif /* OPF_SHIP_H */
src/pathfinder/yapf/yapf.h
Show inline comments
 
@@ -20,15 +20,16 @@
 
/**
 
 * Finds the best path for given ship using YAPF.
 
 * @param v        the ship that needs to find a path
 
 * @param tile     the tile to find the path from (should be next tile the ship is about to enter)
 
 * @param enterdir diagonal direction which the ship will enter this new tile from
 
 * @param tracks   available tracks on the new tile (to choose from)
 
 * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
 
 * @return         the best trackdir for next turn or INVALID_TRACK if the path could not be found
 
 */
 
Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks);
 
Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_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
src/pathfinder/yapf/yapf_ship.cpp
Show inline comments
 
@@ -48,13 +48,13 @@ public:
 
	/** return debug report character to identify the transportation type */
 
	FORCEINLINE char TransportTypeChar() const
 
	{
 
		return 'w';
 
	}
 

	
 
	static Trackdir ChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
 
	static Trackdir ChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
 
	{
 
		/* handle special case - when next tile is destination tile */
 
		if (tile == v->dest_tile) {
 
			/* convert tracks to trackdirs */
 
			TrackdirBits trackdirs = (TrackdirBits)(tracks | ((int)tracks << 8));
 
			/* choose any trackdir reachable from enterdir */
 
@@ -75,13 +75,13 @@ public:
 
		/* create pathfinder instance */
 
		Tpf pf;
 
		/* set origin and destination nodes */
 
		pf.SetOrigin(src_tile, trackdirs);
 
		pf.SetDestination(v->dest_tile, dest_trackdirs);
 
		/* find best path */
 
		pf.FindPath(v);
 
		path_found = pf.FindPath(v);
 

	
 
		Trackdir next_trackdir = INVALID_TRACKDIR; // this would mean "path not found"
 

	
 
		Node *pNode = pf.GetBestNode();
 
		if (pNode != NULL) {
 
			/* walk through the path back to the origin */
 
@@ -171,22 +171,22 @@ struct CYapfShip1 : CYapfT<CYapfShip_Typ
 
/* YAPF type 2 - uses TileIndex/DiagDirection as Node key, allows 90-deg turns */
 
struct CYapfShip2 : CYapfT<CYapfShip_TypesT<CYapfShip2, CFollowTrackWater    , CShipNodeListExitDir > > {};
 
/* YAPF type 3 - uses TileIndex/Trackdir as Node key, forbids 90-deg turns */
 
struct CYapfShip3 : CYapfT<CYapfShip_TypesT<CYapfShip3, CFollowTrackWaterNo90, CShipNodeListTrackDir> > {};
 

	
 
/** Ship controller helper - path finder invoker */
 
Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
 
Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
 
{
 
	/* default is YAPF type 2 */
 
	typedef Trackdir (*PfnChooseShipTrack)(const Ship*, TileIndex, DiagDirection, TrackBits);
 
	typedef Trackdir (*PfnChooseShipTrack)(const Ship*, TileIndex, DiagDirection, TrackBits, bool &path_found);
 
	PfnChooseShipTrack pfnChooseShipTrack = CYapfShip2::ChooseShipTrack; // default: ExitDir, allow 90-deg
 

	
 
	/* check if non-default YAPF type needed */
 
	if (_settings_game.pf.forbid_90_deg) {
 
		pfnChooseShipTrack = &CYapfShip3::ChooseShipTrack; // Trackdir, forbid 90-deg
 
	} else if (_settings_game.pf.yapf.disable_node_optimization) {
 
		pfnChooseShipTrack = &CYapfShip1::ChooseShipTrack; // Trackdir, allow 90-deg
 
	}
 

	
 
	Trackdir td_ret = pfnChooseShipTrack(v, tile, enterdir, tracks);
 
	Trackdir td_ret = pfnChooseShipTrack(v, tile, enterdir, tracks, path_found);
 
	return (td_ret != INVALID_TRACKDIR) ? TrackdirToTrack(td_ret) : INVALID_TRACK;
 
}
src/ship_cmd.cpp
Show inline comments
 
@@ -350,22 +350,27 @@ static void ShipArrivesAt(const Vehicle 
 

	
 
/**
 
 * 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
 
 */
 
static Track ChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
 
static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
 
{
 
	assert(IsValidDiagDirection(enterdir));
 

	
 
	bool path_found = true;
 
	Track track;
 
	switch (_settings_game.pf.pathfinder_for_ships) {
 
		case VPF_OPF: return OPFShipChooseTrack(v, tile, enterdir, tracks);
 
		case VPF_NPF: return NPFShipChooseTrack(v, tile, enterdir, tracks);
 
		case VPF_YAPF: return YapfShipChooseTrack(v, tile, enterdir, tracks);
 
		case VPF_OPF: track = OPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break;
 
		case VPF_NPF: track = NPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break;
 
		case VPF_YAPF: track = YapfShipChooseTrack(v, tile, enterdir, tracks, path_found); break;
 
		default: NOT_REACHED();
 
	}
 

	
 
	v->HandlePathfindingResult(path_found);
 
	return track;
 
}
 

	
 
static const Direction _new_vehicle_direction_table[] = {
 
	DIR_N , DIR_NW, DIR_W , INVALID_DIR,
 
	DIR_NE, DIR_N , DIR_SW, INVALID_DIR,
 
	DIR_E , DIR_SE, DIR_S
0 comments (0 inline, 0 general)