Esempio n. 1
0
        /// <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()));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get the index of the vectornode leaving this junction again, given the incoming vector node.
        /// This uses only the track database, no trainpath nodes.
        /// When having a choice (in case of facing point), it will take the main node.
        /// </summary>
        /// <param name="junctionIndex">index of junction tracknode</param>
        /// <param name="incomingTvnIndex">index of incoming vector node</param>
        /// <returns>index of the leaving vector node or 0 if none found.</returns>
        public static int GetLeavingTvnIndex(int junctionIndex, int incomingTvnIndex)
        {
            if (junctionIndex <= 0)
            {
                return(0);                    // something wrong in database
            }
            TrackNode junctionTrackNode = trackNodes[junctionIndex];

            if (junctionTrackNode == null)
            {
                return(0);
            }

            if (junctionTrackNode.TrEndNode)
            {
                return(0);
            }
            if (incomingTvnIndex == junctionTrackNode.TrailingTvn())
            {
                return(junctionTrackNode.MainTvn());
            }
            return(junctionTrackNode.TrailingTvn());
        }