Ejemplo n.º 1
0
 public TrackHistory(int x, int y, TrackSlope slope)
 {
     X     = (short)x;
     Y     = (short)y;
     Slope = slope;
     Mode  = TrackMode.Normal;
 }
Ejemplo n.º 2
0
 private static bool CanSlopesTouch(TrackSlope leftSlope, TrackSlope rightSlope)
 {
     if (leftSlope != rightSlope && leftSlope != 0)
     {
         return(rightSlope == TrackSlope.Straight);
     }
     return(true);
 }
Ejemplo n.º 3
0
        private void RewriteSlopeDirection(int index, TrackSlope slope)
        {
            int num = slope - _history[index].Slope;

            _history[index].Slope = slope;
            for (int i = index; i < _length; i++)
            {
                _history[i].Y += (short)num;
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
 private void AppendToHistory(TrackSlope slope, TrackMode mode = TrackMode.Normal)
 {
     _history[_length]      = new TrackHistory(_history[_length - 1].X + _xDirection, (int)_history[_length - 1].Y + (int)slope, slope);
     _history[_length].Mode = mode;
     _length++;
 }