예제 #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
        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);
        }