示例#1
0
        //================================================================================================//
        //
        // Get distance between objects
        //

        public float GetDistanceBetweenObjects(int startSectionIndex, float startOffset, int startDirection,
                                               int endSectionIndex, float endOffset)
        {
            int thisSectionIndex = startSectionIndex;
            int direction        = startDirection;

            TrackCircuitSection thisSection = signalRef.TrackCircuitList[thisSectionIndex];

            float distanceM = 0.0f;
            int   lastIndex = -2; // set to non-occuring value

            while (thisSectionIndex != endSectionIndex && thisSectionIndex > 0)
            {
                distanceM += thisSection.Length;
                TrPin nextLink = thisSection.GetNextActiveLink(direction, lastIndex);

                lastIndex        = thisSectionIndex;
                thisSectionIndex = nextLink.Link;
                direction        = nextLink.Direction;

                if (thisSectionIndex > 0)
                {
                    thisSection = signalRef.TrackCircuitList[thisSectionIndex];
                }
            }

            // use found distance, correct for begin and end offset

            if (thisSectionIndex == endSectionIndex)
            {
                distanceM += endOffset - startOffset;
                return(distanceM);
            }

            return(-1.0f);
        }