Exemplo n.º 1
0
 private static TrackGenerator.TrackPlacementState CalculateStateForLocation(
     int x,
     int y)
 {
     for (int index = 0; index < 6; ++index)
     {
         if (TrackGenerator.IsLocationInvalid(x, y - index))
         {
             return(TrackGenerator.TrackPlacementState.Invalid);
         }
     }
     for (int index = 0; index < 6; ++index)
     {
         if (TrackGenerator.IsMinecartTrack(x, y + index))
         {
             return(TrackGenerator.TrackPlacementState.Invalid);
         }
     }
     for (int index = 0; index < 6; ++index)
     {
         if (WorldGen.SolidTile(x, y - index, false))
         {
             return(TrackGenerator.TrackPlacementState.Obstructed);
         }
     }
     return(WorldGen.IsTileNearby(x, y, 314, 30) ? TrackGenerator.TrackPlacementState.Invalid : TrackGenerator.TrackPlacementState.Available);
 }
Exemplo n.º 2
0
 public bool Place(Point origin, int minLength, int maxLength)
 {
     if (!TrackGenerator.FindSuitableOrigin(ref origin))
     {
         return(false);
     }
     this.CreateTrackStart(origin);
     if (!this.FindPath(minLength, maxLength))
     {
         return(false);
     }
     this.PlacePath();
     return(true);
 }
Exemplo n.º 3
0
 private static bool FindSuitableOrigin(ref Point origin)
 {
     TrackGenerator.TrackPlacementState stateForLocation;
     while ((stateForLocation = TrackGenerator.CalculateStateForLocation(origin.X, origin.Y)) != TrackGenerator.TrackPlacementState.Obstructed)
     {
         ++origin.Y;
         if (stateForLocation == TrackGenerator.TrackPlacementState.Invalid)
         {
             return(false);
         }
     }
     --origin.Y;
     return(TrackGenerator.CalculateStateForLocation(origin.X, origin.Y) == TrackGenerator.TrackPlacementState.Available);
 }
Exemplo n.º 4
0
        private TrackGenerator.TrackPlacementState CreateTunnel()
        {
            TrackGenerator.TrackSlope trackSlope1 = TrackGenerator.TrackSlope.Straight;
            int num = 10;

            TrackGenerator.TrackPlacementState trackPlacementState1 = TrackGenerator.TrackPlacementState.Invalid;
            int x = (int)this._history[this._length - 1].X;
            int y = (int)this._history[this._length - 1].Y;

            for (TrackGenerator.TrackSlope trackSlope2 = TrackGenerator.TrackSlope.Up; trackSlope2 <= TrackGenerator.TrackSlope.Down; ++trackSlope2)
            {
                TrackGenerator.TrackPlacementState trackPlacementState2 = TrackGenerator.TrackPlacementState.Invalid;
                for (int index = 1; index < num; ++index)
                {
                    trackPlacementState2 = TrackGenerator.CalculateStateForLocation(x + index * this._xDirection, y + index * (int)trackSlope2);
                    switch (trackPlacementState2)
                    {
                    case TrackGenerator.TrackPlacementState.Obstructed:
                        continue;

                    case TrackGenerator.TrackPlacementState.Invalid:
                        goto label_6;

                    default:
                        trackSlope1          = trackSlope2;
                        num                  = index;
                        trackPlacementState1 = trackPlacementState2;
                        goto label_6;
                    }
                }
label_6:
                if (trackPlacementState1 != TrackGenerator.TrackPlacementState.Available && trackPlacementState2 == TrackGenerator.TrackPlacementState.Obstructed && (trackPlacementState1 != TrackGenerator.TrackPlacementState.Obstructed || trackSlope1 != TrackGenerator.TrackSlope.Straight))
                {
                    trackSlope1          = trackSlope2;
                    num                  = 10;
                    trackPlacementState1 = trackPlacementState2;
                }
            }
            if (this._length == 0 || !TrackGenerator.CanSlopesTouch(this._history[this._length - 1].Slope, trackSlope1))
            {
                this.RewriteSlopeDirection(this._length - 1, TrackGenerator.TrackSlope.Straight);
            }
            this._history[this._length - 1].Mode = TrackGenerator.TrackMode.Tunnel;
            for (int index = 1; index < num; ++index)
            {
                this.AppendToHistory(trackSlope1, TrackGenerator.TrackMode.Tunnel);
            }
            return(trackPlacementState1);
        }
Exemplo n.º 5
0
        private TrackGenerator.TrackPlacementState GetHistorySegmentPlacementState(
            int startIndex,
            int length)
        {
            TrackGenerator.TrackPlacementState trackPlacementState = TrackGenerator.TrackPlacementState.Available;
            for (int index = startIndex; index < startIndex + length; ++index)
            {
                TrackGenerator.TrackPlacementState stateForLocation = TrackGenerator.CalculateStateForLocation((int)this._history[index].X, (int)this._history[index].Y);
                switch (stateForLocation)
                {
                case TrackGenerator.TrackPlacementState.Obstructed:
                    if (this._history[index].Mode != TrackGenerator.TrackMode.Tunnel)
                    {
                        trackPlacementState = stateForLocation;
                        break;
                    }
                    break;

                case TrackGenerator.TrackPlacementState.Invalid:
                    return(stateForLocation);
                }
            }
            return(trackPlacementState);
        }
		private void SmoothTrack(TrackGenerator.TrackHistory[] history, int length)
		{
			int num = length - 1;
			bool flag = false;
			for (int i = length - 1; i >= 0; i--)
			{
				if (flag)
				{
					num = Math.Min(i + 15, num);
					if (history[i].Y >= history[num].Y)
					{
						int num2 = i + 1;
						while (history[num2].Y > history[i].Y)
						{
							history[num2].Y = history[i].Y;
							num2++;
						}
						if (history[i].Y == history[num].Y)
						{
							flag = false;
						}
					}
				}
				else if (history[i].Y > history[num].Y)
				{
					flag = true;
				}
				else
				{
					num = i;
				}
			}
		}