示例#1
0
        private TrackPlacementState CreateTunnel()
        {
            TrackSlope          trackSlope          = TrackSlope.Straight;
            int                 num                 = 10;
            TrackPlacementState trackPlacementState = TrackPlacementState.Invalid;
            int                 x = _history[_length - 1].X;
            int                 y = _history[_length - 1].Y;

            for (TrackSlope trackSlope2 = TrackSlope.Up; trackSlope2 <= TrackSlope.Down; trackSlope2++)
            {
                TrackPlacementState trackPlacementState2 = TrackPlacementState.Invalid;
                for (int i = 1; i < num; i++)
                {
                    trackPlacementState2 = CalculateStateForLocation(x + i * _xDirection, y + i * (int)trackSlope2);
                    switch (trackPlacementState2)
                    {
                    default:
                        trackSlope          = trackSlope2;
                        num                 = i;
                        trackPlacementState = trackPlacementState2;
                        break;

                    case TrackPlacementState.Obstructed:
                        continue;

                    case TrackPlacementState.Invalid:
                        break;
                    }
                    break;
                }
                if (trackPlacementState != 0 && trackPlacementState2 == TrackPlacementState.Obstructed && (trackPlacementState != TrackPlacementState.Obstructed || trackSlope != 0))
                {
                    trackSlope          = trackSlope2;
                    num                 = 10;
                    trackPlacementState = trackPlacementState2;
                }
            }
            if (_length == 0 || !CanSlopesTouch(_history[_length - 1].Slope, trackSlope))
            {
                RewriteSlopeDirection(_length - 1, TrackSlope.Straight);
            }
            _history[_length - 1].Mode = TrackMode.Tunnel;
            for (int j = 1; j < num; j++)
            {
                AppendToHistory(trackSlope, TrackMode.Tunnel);
            }
            return(trackPlacementState);
        }
示例#2
0
        private TrackPlacementState TryRewriteHistoryToAvoidTiles()
        {
            int num  = _length - 1;
            int num2 = Math.Min(_length, _rewriteHistory.Length);

            for (int i = 0; i < num2; i++)
            {
                _rewriteHistory[i] = _history[num - i];
            }
            while (num >= _length - num2)
            {
                if (_history[num].Slope == TrackSlope.Down)
                {
                    TrackPlacementState historySegmentPlacementState = GetHistorySegmentPlacementState(num, _length - num);
                    if (historySegmentPlacementState == TrackPlacementState.Available)
                    {
                        return(historySegmentPlacementState);
                    }
                    RewriteSlopeDirection(num, TrackSlope.Straight);
                }
                num--;
            }
            if (GetHistorySegmentPlacementState(num + 1, _length - (num + 1)) == TrackPlacementState.Available)
            {
                return(TrackPlacementState.Available);
            }
            for (num = _length - 1; num >= _length - num2 + 1; num--)
            {
                if (_history[num].Slope == TrackSlope.Straight)
                {
                    TrackPlacementState historySegmentPlacementState2 = GetHistorySegmentPlacementState(_length - num2, num2);
                    if (historySegmentPlacementState2 == TrackPlacementState.Available)
                    {
                        return(historySegmentPlacementState2);
                    }
                    RewriteSlopeDirection(num, TrackSlope.Up);
                }
            }
            for (int j = 0; j < num2; j++)
            {
                _history[_length - 1 - j] = _rewriteHistory[j];
            }
            RewriteSlopeDirection(_length - 1, TrackSlope.Straight);
            return(GetHistorySegmentPlacementState(num + 1, _length - (num + 1)));
        }
示例#3
0
        private TrackPlacementState GetHistorySegmentPlacementState(int startIndex, int length)
        {
            TrackPlacementState result = TrackPlacementState.Available;

            for (int i = startIndex; i < startIndex + length; i++)
            {
                TrackPlacementState trackPlacementState = CalculateStateForLocation(_history[i].X, _history[i].Y);
                switch (trackPlacementState)
                {
                case TrackPlacementState.Invalid:
                    return(trackPlacementState);

                case TrackPlacementState.Obstructed:
                    if (_history[i].Mode != TrackMode.Tunnel)
                    {
                        result = trackPlacementState;
                    }
                    break;
                }
            }
            return(result);
        }
示例#4
0
        private bool FindPath(int minLength, int maxLength)
        {
            int length = _length;

            while (_length < _history.Length - 100)
            {
                TrackSlope slope = (_history[_length - 1].Slope != TrackSlope.Up) ? TrackSlope.Down : TrackSlope.Straight;
                AppendToHistory(slope);
                TrackPlacementState trackPlacementState = TryRewriteHistoryToAvoidTiles();
                if (trackPlacementState == TrackPlacementState.Invalid)
                {
                    break;
                }
                length = _length;
                TrackPlacementState trackPlacementState2 = trackPlacementState;
                while (trackPlacementState2 != 0)
                {
                    trackPlacementState2 = CreateTunnel();
                    if (trackPlacementState2 == TrackPlacementState.Invalid)
                    {
                        break;
                    }
                    length = _length;
                }
                if (_length >= maxLength)
                {
                    break;
                }
            }
            _length = Math.Min(maxLength, length);
            if (_length < minLength)
            {
                return(false);
            }
            SmoothTrack();
            return(GetHistorySegmentPlacementState(0, _length) != TrackPlacementState.Invalid);
        }