Пример #1
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();
                }
            }
        }
Пример #2
0
        public override void Generate(Map map)
        {
            List <NeededRoad> neededRoads = this.CalculateNeededRoads(map);

            if (neededRoads.Count != 0)
            {
                List <DrawCommand> list = new List <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((NeededRoad nr) => nr.road == rd) >= 2
                                           select rd).MaxByWithFallback((Func <RoadDef, int>)((RoadDef rd) => rd.priority), (RoadDef)null);
                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 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 DrawCommand
                    {
                        action  = action,
                        roadDef = bestRoadType
                    });
                }
                foreach (NeededRoad item in neededRoads)
                {
                    NeededRoad     current      = item;
                    RoadPathingDef pathingMode2 = current.road.pathingMode;
                    IntVec3        intVec3      = this.FindRoadExitCell(map, current.angle, intVec, ref pathingMode2);
                    if (!(intVec3 == IntVec3.Invalid))
                    {
                        list.Add(new DrawCommand
                        {
                            action  = this.PrepDrawRoad(map, rockDef, intVec, intVec3, current.road, pathingMode2),
                            roadDef = current.road
                        });
                    }
                }
                foreach (DrawCommand item2 in from dc in list
                         orderby dc.roadDef.priority
                         select dc)
                {
                    DrawCommand current2 = item2;
                    if (current2.action != null)
                    {
                        current2.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);
        }