yapf/yapf_rail.cpp
branchcustombridgeheads
changeset 5618 a7db50b9f817
parent 5573 afa6f92a71fd
child 5621 6ce400c0a2f4
equal deleted inserted replaced
5617:159f2791c340 5618:a7db50b9f817
    47 	}
    47 	}
    48 
    48 
    49 	FORCEINLINE bool FindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed)
    49 	FORCEINLINE bool FindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed)
    50 	{
    50 	{
    51 		// set origin and destination nodes
    51 		// set origin and destination nodes
    52 		Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true);
    52 		Yapf().SetOrigin(t1, TrackdirToTrackdirBits(td1), t2, TrackdirToTrackdirBits(td2), reverse_penalty, true);
    53 		Yapf().SetDestination(v);
    53 		Yapf().SetDestination(v);
    54 		Yapf().SetMaxCost(YAPF_TILE_LENGTH * max_distance);
    54 		Yapf().SetMaxCost(YAPF_TILE_LENGTH * max_distance);
    55 
    55 
    56 		// find the best path
    56 		// find the best path
    57 		bool bFound = Yapf().FindPath(v);
    57 		bool bFound = Yapf().FindPath(v);
   111 	}
   111 	}
   112 
   112 
   113 	FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool *path_not_found)
   113 	FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool *path_not_found)
   114 	{
   114 	{
   115 		// set origin and destination nodes
   115 		// set origin and destination nodes
   116 		Yapf().SetOrigin(v->tile, GetVehicleTrackdir(v), INVALID_TILE, INVALID_TRACKDIR, 1, true);
   116 		if (v->tile == tile) {
       
   117 			// probably bridge head
       
   118 			trackdirs = (TrackdirBits)(GetTileTrackStatus(tile, TRANSPORT_RAIL) & TRACKDIR_BIT_MASK);
       
   119 			trackdirs &= DiagdirReachesTrackdirs(ReverseDiagDir(TrackdirToExitdir(ReverseTrackdir(GetVehicleTrackdir(v)))));
       
   120 			Yapf().SetOrigin(tile, trackdirs, INVALID_TILE, INVALID_TRACKDIR_BIT, 1, true);
       
   121 		} else {
       
   122 			Yapf().SetOrigin(v->tile, TrackdirToTrackdirBits(GetVehicleTrackdir(v)), INVALID_TILE, INVALID_TRACKDIR_BIT, 1, true);
       
   123 		}
   117 		Yapf().SetDestination(v);
   124 		Yapf().SetDestination(v);
   118 
   125 
   119 		// find the best path
   126 		// find the best path
   120 		bool path_found = Yapf().FindPath(v);
   127 		bool path_found = Yapf().FindPath(v);
   121 		if (!path_found && path_not_found != NULL) {
   128 		if (!path_found && path_not_found != NULL) {
   133 			while (pNode->m_parent != NULL) {
   140 			while (pNode->m_parent != NULL) {
   134 				pPrev = pNode;
   141 				pPrev = pNode;
   135 				pNode = pNode->m_parent;
   142 				pNode = pNode->m_parent;
   136 			}
   143 			}
   137 			// return trackdir from the best origin node (one of start nodes)
   144 			// return trackdir from the best origin node (one of start nodes)
   138 			Node& best_next_node = *pPrev;
   145 			Node& best_next_node = (v->tile == tile ? *pNode : *pPrev);
   139 			assert(best_next_node.GetTile() == tile);
   146 			assert(v->tile == tile || best_next_node.GetTile() == tile);
   140 			next_trackdir = best_next_node.GetTrackdir();
   147 			next_trackdir = best_next_node.GetTrackdir();
   141 		}
   148 		}
   142 		return next_trackdir;
   149 		return next_trackdir;
   143 	}
   150 	}
   144 
   151 
   150 
   157 
   151 	FORCEINLINE bool CheckReverseTrain(Vehicle* v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2)
   158 	FORCEINLINE bool CheckReverseTrain(Vehicle* v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2)
   152 	{
   159 	{
   153 		// create pathfinder instance
   160 		// create pathfinder instance
   154 		// set origin and destination nodes
   161 		// set origin and destination nodes
   155 		Yapf().SetOrigin(t1, td1, t2, td2, 1, false);
   162 		Yapf().SetOrigin(t1, TrackdirToTrackdirBits(td1), t2, TrackdirToTrackdirBits(td2), 1, false);
   156 		Yapf().SetDestination(v);
   163 		Yapf().SetDestination(v);
   157 
   164 
   158 		// find the best path
   165 		// find the best path
   159 		bool bFound = Yapf().FindPath(v);
   166 		bool bFound = Yapf().FindPath(v);
   160 
   167