Exemplo n.º 1
0
        private void DoEnter(bool first)
        {
            if (first)
            {
                generator = MapGenDefGetter;

                IntVec3 mapSize = new IntVec3(generator.size.x, 1, generator.size.z);

                mapHolder      = (RandomPlaceWorldObject)WorldObjectMaker.MakeWorldObject(WorldObjectsDefOfLocal.RandomPlace);
                mapHolder.Tile = parent.Tile;
                Find.WorldObjects.Add(mapHolder);

                PreMapGenerate(mapHolder);

                Map map = null;
                LongEventHandler.QueueLongEvent(delegate
                {
                    map = Verse.MapGenerator.GenerateMap(mapSize, mapHolder, MapGeneratorDefOfLocal.EmptyMap);

                    LongEventHandler.ExecuteWhenFinished(delegate
                    {
                        PostMapGenerate(map, mapHolder);

                        MapGeneratorHandler.GenerateMap(generator, map, out List <Pawn> pawns, ClearMap, SetTerrain, Fog, UnFogRooms, SpawnPawns, CreateRoof, GeneratePlants, forceFaction, forceLord, BreakdownBuildings);

                        var things = GenRadial.RadialDistinctThingsAround(parent.Position, parent.Map, CollectThingsRadius, false).Where(x => x.Faction == Faction.OfPlayer);
                        foreach (var t in things)
                        {
                            t.DeSpawn();

                            GenSpawn.Spawn(t, generator.PawnsSpawnPos, map);
                        }

                        PostMapDefGenerate(map, mapHolder);

                        if (OneUse)
                        {
                            parent.Destroy();
                        }
                    });
                }, "GeneratingMapForNewEncounter", doAsynchronously: false, null);
            }
            else
            {
                var things = GenRadial.RadialDistinctThingsAround(parent.Position, parent.Map, CollectThingsRadius, false).Where(x => x.Faction == Faction.OfPlayer);
                foreach (var t in things)
                {
                    t.DeSpawn();

                    GenSpawn.Spawn(t, generator.PawnsSpawnPos, mapHolder.Map);
                }
            }
        }
Exemplo n.º 2
0
        public static void GenerateMap(MapGeneratorDef mapGenerator, Map map, out List <Pawn> spawnedPawns, bool clearMap = false, bool setTerrain = false, bool fog = true, bool unFogRoom = false, bool spawnPawns = true
                                       , bool createRoof = false, bool generatePlants = false, Faction forceFaction = null, Lord forceLord = null, bool breakDownBuildings = false, bool refuel = true)
        {
            spawnedPawns = new List <Pawn>();

            map.regionAndRoomUpdater.Enabled = false;
            if (clearMap)
            {
                Thing.allowDestroyNonDestroyable = true;

                foreach (var position in map.AllCells)
                {
                    if (position.Roofed(map))
                    {
                        map.roofGrid.SetRoof(position, null);
                    }
                }

                foreach (Thing item5 in map.listerThings.AllThings.ToList())
                {
                    item5.Destroy();
                }

                Thing.allowDestroyNonDestroyable = false;
            }

            if (generatePlants)
            {
                GenStep genStep = (GenStep)Activator.CreateInstance(typeof(GenStep_Plants));
                genStep.Generate(map, default(GenStepParams));
            }

            if (setTerrain)
            {
                ClearCells(mapGenerator.MapData, map);
                SetTerrain(mapGenerator.MapData, map);
            }

            PlaceBuildingsAndItems(mapGenerator.MapData, map, forceFaction, refuel);

            if (spawnPawns)
            {
                SpawnPawns(mapGenerator.MapData, map, forceFaction, spawnedPawns, forceLord);
            }

            map.powerNetManager.UpdatePowerNetsAndConnections_First();

            map.regionAndRoomUpdater.Enabled = true;
            map.regionAndRoomUpdater.RebuildAllRegionsAndRooms();

            if (createRoof && mapGenerator.RoofData != null)
            {
                CreateRoof(mapGenerator.RoofData, map);
            }

            if (fog)
            {
                RefogMap(map);
            }

            if (unFogRoom)
            {
                foreach (IntVec3 current in map.AllCells)
                {
                    Room room = current.GetRoom(map);
                    if (room != null && !room.TouchesMapEdge)
                    {
                        map.fogGrid.Unfog(current);
                    }
                }
            }
        }