/// <summary> /// Try to find a connection between the current junction and a reconnect junction. /// We do a depth-first search, using the main tracks first. /// The result (the path) is stored in a list of linking tvns. /// In case there are DisAllowedJunctionIndexes we will not allow the connection to go over these junctions /// </summary> /// <param name="currentJunctionIndex">Index of the current junction</param> /// <param name="currentJunctionIsFacing">true if the current junction is a facing junction</param> /// <returns>true if a path was found</returns> private bool TryToFindConnection(int currentJunctionIndex, bool currentJunctionIsFacing) { if (autoConnectToNodeOptions.FoundConnection(currentJunctionIndex, currentJunctionIsFacing)) { return(autoConnectToNodeOptions.ConnectionIsGood); } // Did we go as deep as we want wanted to go? if (linkingTvns.Count == maxNumberNodesToCheckForAutoFix) { return(false); } // Search further along the next Tvns that we can try. TrackNode tn = TrackExtensions.TrackNode(currentJunctionIndex); if (tn is TrackEndNode) { return(false); } if (currentJunctionIsFacing) { //for debugging it is better to have multiple lines bool found; found = TryToFindConnectionVia(currentJunctionIndex, tn.MainTvn()); if (found) { return(true); } found = TryToFindConnectionVia(currentJunctionIndex, tn.SidingTvn()); return(found); } else { return(TryToFindConnectionVia(currentJunctionIndex, tn.TrailingTvn())); } }