Beispiel #1
0
 private void ApplyDistanceField(GenStep_Roads.DistanceElement[,] distance, Map map, TerrainDef rockDef, RoadDef roadDef, RoadPathingDef pathingDef)
 {
     for (int i = 0; i < map.Size.x; i++)
     {
         for (int j = 0; j < map.Size.z; j++)
         {
             GenStep_Roads.DistanceElement distanceElement = distance[i, j];
             if (distanceElement.touched)
             {
                 float b = Mathf.Abs(distanceElement.fromRoad + Rand.Value - 0.5f);
                 for (int k = 0; k < roadDef.roadGenSteps.Count; k++)
                 {
                     RoadDefGenStep roadDefGenStep = roadDef.roadGenSteps[k];
                     float          x   = Mathf.LerpUnclamped(distanceElement.fromRoad, b, roadDefGenStep.antialiasingMultiplier);
                     float          num = roadDefGenStep.chancePerPositionCurve.Evaluate(x);
                     if (num > 0f)
                     {
                         if (roadDefGenStep.periodicSpacing == 0 || distanceElement.alongPath / (float)roadDefGenStep.periodicSpacing % 1f * (float)roadDefGenStep.periodicSpacing < 1f)
                         {
                             IntVec3 position = new IntVec3(i, 0, j);
                             if (Rand.Value < num)
                             {
                                 roadDefGenStep.Place(map, position, rockDef);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
        private Action PrepDrawRoad(Map map, TerrainDef rockDef, IntVec3 start, IntVec3 end, RoadDef roadDef, RoadPathingDef pathingDef, out IntVec3 centerpoint)
        {
            centerpoint = IntVec3.Invalid;
            PawnPath pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.NoPassClosedDoorsOrWater, Danger.Deadly, false), PathEndMode.OnCell);

            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), PathEndMode.OnCell);
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThingsNotWater, Danger.Deadly, false), PathEndMode.OnCell);
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThings, Danger.Deadly, false), PathEndMode.OnCell);
            }
            Action result;

            if (pawnPath == PawnPath.NotFound)
            {
                result = null;
            }
            else
            {
                List <IntVec3> list = this.RefinePath(pawnPath.NodesReversed, map);
                pawnPath.ReleaseToPool();
                GenStep_Roads.DistanceElement[,] distance = new GenStep_Roads.DistanceElement[map.Size.x, map.Size.z];
                for (int i = 0; i < distance.GetLength(0); i++)
                {
                    for (int j = 0; j < distance.GetLength(1); j++)
                    {
                        distance[i, j].origin = IntVec3.Invalid;
                    }
                }
                int count            = list.Count;
                int centerpointIndex = Mathf.RoundToInt(Rand.Range(0.3f, 0.7f) * (float)count);
                int num = Mathf.Max(1, GenMath.RoundRandom((float)count / (float)roadDef.tilesPerSegment));
                for (int k = 0; k < num; k++)
                {
                    int pathStartIndex = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)k);
                    int pathEndIndex   = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)(k + 1));
                    this.DrawCurveSegment(distance, list, pathStartIndex, pathEndIndex, pathingDef, map, centerpointIndex, ref centerpoint);
                }
                result = delegate()
                {
                    this.ApplyDistanceField(distance, map, rockDef, roadDef, pathingDef);
                };
            }
            return(result);
        }