Exemplo n.º 1
0
        public override void Generate(Map map, GenStepParams parms)
        {
            List <NeededRoad> neededRoads = 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, beautiful: false);
                IntVec3    centerpoint  = CellFinderLoose.TryFindCentralCell(map, 3, 10);
                RoadDef    bestRoadType = (from rd in DefDatabase <RoadDef> .AllDefs
                                           where neededRoads.Count((NeededRoad nr) => nr.road == rd) >= 2
                                           select rd).MaxByWithFallback((RoadDef rd) => rd.priority);
                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);
                    list.Add(new DrawCommand
                    {
                        action  = action,
                        roadDef = bestRoadType
                    });
                }
                foreach (NeededRoad item in neededRoads)
                {
                    NeededRoad     current     = item;
                    RoadPathingDef pathingDef2 = current.road.pathingMode;
                    IntVec3        intVec2     = FindRoadExitCell(map, current.angle, centerpoint, ref pathingDef2);
                    if (!(intVec2 == IntVec3.Invalid))
                    {
                        list.Add(new DrawCommand
                        {
                            action  = PrepDrawRoad(map, rockDef, centerpoint, intVec2, current.road, pathingDef2),
                            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();
                    }
                }
            }
        }