Пример #1
0
        public override void Generate(Map map)
        {
            List <GenStep_Roads.NeededRoad> neededRoads = this.CalculateNeededRoads(map);

            if (neededRoads.Count == 0)
            {
                return;
            }
            List <GenStep_Roads.DrawCommand> list = new List <GenStep_Roads.DrawCommand>();

            DeepProfiler.Start("RebuildAllRegions");
            map.regionAndRoomUpdater.RebuildAllRegionsAndRooms();
            DeepProfiler.End();
            TerrainDef rockDef      = BaseGenUtility.RegionalRockTerrainDef(map.Tile, false);
            IntVec3    intVec       = CellFinderLoose.TryFindCentralCell(map, 3, 10, null);
            RoadDef    bestRoadType = (from rd in DefDatabase <RoadDef> .AllDefs
                                       where neededRoads.Count((GenStep_Roads.NeededRoad nr) => nr.road == rd) >= 2
                                       select rd).MaxByWithFallback((RoadDef rd) => rd.priority, null);

            if (bestRoadType != null)
            {
                GenStep_Roads.NeededRoad neededRoad = neededRoads[neededRoads.FindIndex((GenStep_Roads.NeededRoad nr) => nr.road == bestRoadType)];
                neededRoads.RemoveAt(neededRoads.FindIndex((GenStep_Roads.NeededRoad nr) => nr.road == bestRoadType));
                GenStep_Roads.NeededRoad neededRoad2 = neededRoads[neededRoads.FindIndex((GenStep_Roads.NeededRoad nr) => nr.road == bestRoadType)];
                neededRoads.RemoveAt(neededRoads.FindIndex((GenStep_Roads.NeededRoad nr) => nr.road == bestRoadType));
                RoadPathingDef pathingMode = neededRoad.road.pathingMode;
                IntVec3        intVec2     = this.FindRoadExitCell(map, neededRoad.angle, intVec, ref pathingMode);
                IntVec3        end         = this.FindRoadExitCell(map, neededRoad2.angle, intVec2, ref pathingMode);
                Action         action      = this.PrepDrawRoad(map, rockDef, intVec2, end, neededRoad.road, pathingMode, out intVec);
                list.Add(new GenStep_Roads.DrawCommand
                {
                    action  = action,
                    roadDef = bestRoadType
                });
            }
            foreach (GenStep_Roads.NeededRoad current in neededRoads)
            {
                RoadPathingDef pathingMode2 = current.road.pathingMode;
                IntVec3        intVec3      = this.FindRoadExitCell(map, current.angle, intVec, ref pathingMode2);
                if (!(intVec3 == IntVec3.Invalid))
                {
                    list.Add(new GenStep_Roads.DrawCommand
                    {
                        action  = this.PrepDrawRoad(map, rockDef, intVec, intVec3, current.road, pathingMode2),
                        roadDef = current.road
                    });
                }
            }
            foreach (GenStep_Roads.DrawCommand current2 in from dc in list
                     orderby dc.roadDef.priority
                     select dc)
            {
                if (current2.action != null)
                {
                    current2.action();
                }
            }
        }
Пример #2
0
        public override void Generate(Map map, GenStepParams parms)
        {
            List <NeededRoad> neededRoads = CalculateNeededRoads(map);

            if (neededRoads.Count == 0)
            {
                return;
            }
            List <DrawCommand> list = new List <DrawCommand>();

            DeepProfiler.Start("RebuildAllRegions");
            map.regionAndRoomUpdater.RebuildAllRegionsAndRooms();
            DeepProfiler.End();
            TerrainDef rockDef      = BaseGenUtility.RegionalRockTerrainDef(map.Tile, beautiful: false);
            IntVec3    centerpoint  = CellFinderLoose.TryFindCentralCell(map, 3, 10);
            RoadDef    bestRoadType = DefDatabase <RoadDef> .AllDefs.Where((RoadDef rd) => neededRoads.Count((NeededRoad nr) => nr.road == rd) >= 2).MaxByWithFallback((RoadDef rd) => rd.priority);

            DrawCommand item;

            if (bestRoadType != null)
            {
                NeededRoad neededRoad = neededRoads[neededRoads.FindIndex((NeededRoad nr) => nr.road == bestRoadType)];
                neededRoads.RemoveAt(neededRoads.FindIndex((NeededRoad nr) => nr.road == bestRoadType));
                NeededRoad neededRoad2 = neededRoads[neededRoads.FindIndex((NeededRoad nr) => nr.road == bestRoadType)];
                neededRoads.RemoveAt(neededRoads.FindIndex((NeededRoad nr) => nr.road == bestRoadType));
                RoadPathingDef pathingDef = neededRoad.road.pathingMode;
                IntVec3        intVec     = FindRoadExitCell(map, neededRoad.angle, centerpoint, ref pathingDef);
                IntVec3        end        = FindRoadExitCell(map, neededRoad2.angle, intVec, ref pathingDef);
                Action         action     = PrepDrawRoad(map, rockDef, intVec, end, neededRoad.road, pathingDef, out centerpoint);
                item = new DrawCommand
                {
                    action  = action,
                    roadDef = bestRoadType
                };
                list.Add(item);
            }
            foreach (NeededRoad item2 in neededRoads)
            {
                RoadPathingDef pathingDef2 = item2.road.pathingMode;
                IntVec3        intVec2     = FindRoadExitCell(map, item2.angle, centerpoint, ref pathingDef2);
                if (!(intVec2 == IntVec3.Invalid))
                {
                    item = new DrawCommand
                    {
                        action  = PrepDrawRoad(map, rockDef, centerpoint, intVec2, item2.road, pathingDef2),
                        roadDef = item2.road
                    };
                    list.Add(item);
                }
            }
            foreach (DrawCommand item3 in list.OrderBy((DrawCommand dc) => dc.roadDef.priority))
            {
                if (item3.action != null)
                {
                    item3.action();
                }
            }
        }
Пример #3
0
        private List <NeededRoad> CalculateNeededRoads(Map map)
        {
            List <int> list = new List <int>();

            Find.WorldGrid.GetTileNeighbors(map.Tile, list);
            List <NeededRoad> list2 = new List <NeededRoad>();

            foreach (int item in list)
            {
                RoadDef roadDef = Find.WorldGrid.GetRoadDef(map.Tile, item);
                if (roadDef != null)
                {
                    list2.Add(new NeededRoad
                    {
                        angle = Find.WorldGrid.GetHeadingFromTo(map.Tile, item),
                        road  = roadDef
                    });
                }
            }
            if (list2.Count > 1)
            {
                Vector3 vector = Vector3.zero;
                foreach (NeededRoad item2 in list2)
                {
                    NeededRoad current2 = item2;
                    vector += Vector3Utility.HorizontalVectorFromAngle(current2.angle);
                }
                vector  /= (float)(-list2.Count);
                vector  += Rand.UnitVector3 * 1f / 6f;
                vector.y = 0f;
                for (int i = 0; i < list2.Count; i++)
                {
                    List <NeededRoad> list3 = list2;
                    int        index        = i;
                    NeededRoad value        = default(NeededRoad);
                    NeededRoad neededRoad   = list2[i];
                    value.angle = (Vector3Utility.HorizontalVectorFromAngle(neededRoad.angle) + vector).AngleFlat();
                    NeededRoad neededRoad2 = list2[i];
                    value.road   = neededRoad2.road;
                    list3[index] = value;
                }
            }
            return(list2);
        }
Пример #4
0
        private List <NeededRoad> CalculateNeededRoads(Map map)
        {
            List <int> list = new List <int>();

            Find.WorldGrid.GetTileNeighbors(map.Tile, list);
            List <NeededRoad> list2 = new List <NeededRoad>();
            NeededRoad        item;

            foreach (int item2 in list)
            {
                RoadDef roadDef = Find.WorldGrid.GetRoadDef(map.Tile, item2);
                if (roadDef != null)
                {
                    item = new NeededRoad
                    {
                        angle = Find.WorldGrid.GetHeadingFromTo(map.Tile, item2),
                        road  = roadDef
                    };
                    list2.Add(item);
                }
            }
            if (list2.Count > 1)
            {
                Vector3 zero = Vector3.zero;
                foreach (NeededRoad item3 in list2)
                {
                    zero += Vector3Utility.HorizontalVectorFromAngle(item3.angle);
                }
                zero  /= (float)(-list2.Count);
                zero  += Rand.UnitVector3 * 1f / 6f;
                zero.y = 0f;
                for (int i = 0; i < list2.Count; i++)
                {
                    item = (list2[i] = new NeededRoad
                    {
                        angle = (Vector3Utility.HorizontalVectorFromAngle(list2[i].angle) + zero).AngleFlat(),
                        road = list2[i].road
                    });
                }
            }
            return(list2);
        }
Пример #5
0
        private List <GenStep_Roads.NeededRoad> CalculateNeededRoads(Map map)
        {
            List <int> list = new List <int>();

            Find.WorldGrid.GetTileNeighbors(map.Tile, list);
            List <GenStep_Roads.NeededRoad> list2 = new List <GenStep_Roads.NeededRoad>();

            foreach (int current in list)
            {
                RoadDef roadDef = Find.WorldGrid.GetRoadDef(map.Tile, current, true);
                if (roadDef != null)
                {
                    list2.Add(new GenStep_Roads.NeededRoad
                    {
                        angle = Find.WorldGrid.GetHeadingFromTo(map.Tile, current),
                        road  = roadDef
                    });
                }
            }
            if (list2.Count > 1)
            {
                Vector3 vector = Vector3.zero;
                foreach (GenStep_Roads.NeededRoad current2 in list2)
                {
                    vector += Vector3Utility.HorizontalVectorFromAngle(current2.angle);
                }
                vector  /= (float)(-(float)list2.Count);
                vector  += Rand.UnitVector3 * 1f / 6f;
                vector.y = 0f;
                for (int i = 0; i < list2.Count; i++)
                {
                    list2[i] = new GenStep_Roads.NeededRoad
                    {
                        angle = (Vector3Utility.HorizontalVectorFromAngle(list2[i].angle) + vector).AngleFlat(),
                        road  = list2[i].road
                    };
                }
            }
            return(list2);
        }
Пример #6
0
        private void ApplyDistanceField(DistanceElement[,] distance, Map map, TerrainDef rockDef, RoadDef roadDef, RoadPathingDef pathingDef)
        {
            int num = 0;

            while (true)
            {
                int     num2 = num;
                IntVec3 size = map.Size;
                if (num2 >= size.x)
                {
                    break;
                }
                int num3 = 0;
                while (true)
                {
                    int     num4  = num3;
                    IntVec3 size2 = map.Size;
                    if (num4 >= size2.z)
                    {
                        break;
                    }
                    DistanceElement distanceElement = distance[num, num3];
                    if (distanceElement.touched)
                    {
                        float b = Mathf.Abs(distanceElement.fromRoad + Rand.Value - 0.5f);
                        for (int i = 0; i < roadDef.roadGenSteps.Count; i++)
                        {
                            RoadDefGenStep roadDefGenStep = roadDef.roadGenSteps[i];
                            float          x    = Mathf.LerpUnclamped(distanceElement.fromRoad, b, roadDefGenStep.antialiasingMultiplier);
                            float          num5 = roadDefGenStep.chancePerPositionCurve.Evaluate(x);
                            if (!(num5 <= 0f) && (roadDefGenStep.periodicSpacing == 0 || !(distanceElement.alongPath / (float)roadDefGenStep.periodicSpacing % 1f * (float)roadDefGenStep.periodicSpacing >= 1f)))
                            {
                                IntVec3 position = new IntVec3(num, 0, num3);
                                if (Rand.Value < num5)
                                {
                                    roadDefGenStep.Place(map, position, rockDef, distanceElement.origin, distance);
                                }
                            }
                        }
                    }
                    num3++;
                }
                num++;
            }
        }
Пример #7
0
        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));

            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.NoPassClosedDoors));
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThingsNotWater));
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThings));
            }
            if (pawnPath == PawnPath.NotFound)
            {
                return(null);
            }
            List <IntVec3> list = RefinePath(pawnPath.NodesReversed, map);

            pawnPath.ReleaseToPool();
            IntVec3 size  = map.Size;
            int     x     = size.x;
            IntVec3 size2 = map.Size;

            DistanceElement[,] distance = new DistanceElement[x, size2.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));
                DrawCurveSegment(distance, list, pathStartIndex, pathEndIndex, pathingDef, map, centerpointIndex, ref centerpoint);
            }
            return(delegate
            {
                ApplyDistanceField(distance, map, rockDef, roadDef, pathingDef);
            });
        }
Пример #8
0
        private Action PrepDrawRoad(Map map, TerrainDef rockDef, IntVec3 start, IntVec3 end, RoadDef roadDef, RoadPathingDef pathingDef)
        {
            IntVec3 centerpoint;

            return(PrepDrawRoad(map, rockDef, start, end, roadDef, pathingDef, out centerpoint));
        }
Пример #9
0
        private Action PrepDrawRoad(Map map, TerrainDef rockDef, IntVec3 start, IntVec3 end, RoadDef roadDef, RoadPathingDef pathingDef)
        {
            IntVec3 intVec = default(IntVec3);

            return(this.PrepDrawRoad(map, rockDef, start, end, roadDef, pathingDef, out intVec));
        }
Пример #10
0
 private void ApplyDistanceField(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++)
         {
             DistanceElement distanceElement = distance[i, j];
             if (!distanceElement.touched)
             {
                 continue;
             }
             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) && (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, distanceElement.origin, distance);
                     }
                 }
             }
         }
     }
 }
Пример #11
0
        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);
            }
            if (pawnPath == PawnPath.NotFound)
            {
                return(null);
            }
            List <IntVec3> list = this.RefinePath(pawnPath.NodesReversed, map);

            pawnPath.ReleaseToPool();
            GenStep_Roads.DistanceElement[,] distance = new GenStep_Roads.DistanceElement[map.Size.x, map.Size.z];
            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 i = 0; i < num; i++)
            {
                int pathStartIndex = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)i);
                int pathEndIndex   = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)(i + 1));
                this.DrawCurveSegment(distance, list, pathStartIndex, pathEndIndex, pathingDef, map, centerpointIndex, ref centerpoint);
            }
            return(delegate
            {
                this.ApplyDistanceField(distance, map, rockDef, roadDef, pathingDef);
            });
        }
Пример #12
0
 private static int <Generate> m__0(RoadDef rd)
 {
     return(rd.priority);
 }