src/yapf/yapf_ship.cpp
branchNewGRF_ports
changeset 6719 4cc327ad39d5
parent 6458 5cd016e1f018
child 6720 35756db7e577
equal deleted inserted replaced
6718:5a8b295aa345 6719:4cc327ad39d5
    24 	/** Called by YAPF to move from the given node to the next tile. For each
    24 	/** Called by YAPF to move from the given node to the next tile. For each
    25 	 *  reachable trackdir on the new tile creates new node, initializes it
    25 	 *  reachable trackdir on the new tile creates new node, initializes it
    26 	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
    26 	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
    27 	inline void PfFollowNode(Node& old_node)
    27 	inline void PfFollowNode(Node& old_node)
    28 	{
    28 	{
    29 		TrackFollower F;
    29 		TrackFollower F(Yapf().GetVehicle());
    30 		if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td))
    30 		if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td))
    31 			Yapf().AddMultipleNodes(&old_node, F);
    31 			Yapf().AddMultipleNodes(&old_node, F);
    32 	}
    32 	}
    33 
    33 
    34 	/// return debug report character to identify the transportation type
    34 	/// return debug report character to identify the transportation type
    51 		assert(IsValidTrackdir(trackdir));
    51 		assert(IsValidTrackdir(trackdir));
    52 
    52 
    53 		// convert origin trackdir to TrackdirBits
    53 		// convert origin trackdir to TrackdirBits
    54 		TrackdirBits trackdirs = TrackdirToTrackdirBits(trackdir);
    54 		TrackdirBits trackdirs = TrackdirToTrackdirBits(trackdir);
    55 		// get available trackdirs on the destination tile
    55 		// get available trackdirs on the destination tile
    56 		TrackdirBits dest_trackdirs = (TrackdirBits)(GetTileTrackStatus(v->dest_tile, TRANSPORT_WATER) & TRACKDIR_BIT_MASK);
    56 		TrackdirBits dest_trackdirs = (TrackdirBits)(GetTileTrackStatus(v->dest_tile, TRANSPORT_WATER, 0) & TRACKDIR_BIT_MASK);
    57 
    57 
    58 		// create pathfinder instance
    58 		// create pathfinder instance
    59 		Tpf pf;
    59 		Tpf pf;
    60 		// set origin and destination nodes
    60 		// set origin and destination nodes
    61 		pf.SetOrigin(src_tile, trackdirs);
    61 		pf.SetOrigin(src_tile, trackdirs);
    62 		pf.SetDestination(v->dest_tile, dest_trackdirs);
    62 		pf.SetDestination(v->dest_tile, dest_trackdirs);
    63 		// find best path
    63 		// find best path
    64 		bool bFound = pf.FindPath(v);
    64 		pf.FindPath(v);
    65 
    65 
    66 		Trackdir next_trackdir = INVALID_TRACKDIR; // this would mean "path not found"
    66 		Trackdir next_trackdir = INVALID_TRACKDIR; // this would mean "path not found"
    67 		if (bFound) {
    67 
    68 			// path was found
    68 		Node* pNode = pf.GetBestNode();
       
    69 		if (pNode != NULL) {
    69 			// walk through the path back to the origin
    70 			// walk through the path back to the origin
    70 			Node* pNode = &pf.GetBestNode();
       
    71 			Node* pPrevNode = NULL;
    71 			Node* pPrevNode = NULL;
    72 			while (pNode->m_parent != NULL) {
    72 			while (pNode->m_parent != NULL) {
    73 				pPrevNode = pNode;
    73 				pPrevNode = pNode;
    74 				pNode = pNode->m_parent;
    74 				pNode = pNode->m_parent;
    75 			}
    75 			}