|
@@ -46,49 +46,49 @@ public:
|
|
|
}
|
|
|
|
|
|
// move back to the old tile/trackdir (where ship is coming from)
|
|
|
TileIndex src_tile = TILE_ADD(tile, TileOffsByDiagDir(ReverseDiagDir(enterdir)));
|
|
|
Trackdir trackdir = GetVehicleTrackdir(v);
|
|
|
assert(IsValidTrackdir(trackdir));
|
|
|
|
|
|
// convert origin trackdir to TrackdirBits
|
|
|
TrackdirBits trackdirs = TrackdirToTrackdirBits(trackdir);
|
|
|
// get available trackdirs on the destination tile
|
|
|
TrackdirBits dest_trackdirs = (TrackdirBits)(GetTileTrackStatus(v->dest_tile, TRANSPORT_WATER) & TRACKDIR_BIT_MASK);
|
|
|
|
|
|
// 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
|
|
|
bool bFound = pf.FindPath(v);
|
|
|
|
|
|
Trackdir next_trackdir = INVALID_TRACKDIR; // this would mean "path not found"
|
|
|
if (bFound) {
|
|
|
// path was found
|
|
|
// walk through the path back to the origin
|
|
|
Node* pNode = &pf.GetBestNode();
|
|
|
Node* pNode = pf.GetBestNode();
|
|
|
Node* pPrevNode = NULL;
|
|
|
while (pNode->m_parent != NULL) {
|
|
|
pPrevNode = pNode;
|
|
|
pNode = pNode->m_parent;
|
|
|
}
|
|
|
// return trackdir from the best next node (direct child of origin)
|
|
|
Node& best_next_node = *pPrevNode;
|
|
|
assert(best_next_node.GetTile() == tile);
|
|
|
next_trackdir = best_next_node.GetTrackdir();
|
|
|
}
|
|
|
return next_trackdir;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/** Cost Provider module of YAPF for ships */
|
|
|
template <class Types>
|
|
|
class CYapfCostShipT
|
|
|
{
|
|
|
public:
|
|
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
|
|
typedef typename Types::TrackFollower TrackFollower;
|
|
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
|
|
typedef typename Node::Key Key; ///< key to hash tables
|
|
|
|