Example #1
0
        public override void PostWorldGenerate()
        {
            int num = 0;

            while (true)
            {
                StartingPawnUtility.ClearAllStartingPawns();
                for (int i = 0; i < this.pawnCount; i++)
                {
                    Find.GameInitData.startingPawns.Add(StartingPawnUtility.NewGeneratedStartingPawn());
                }
                num++;
                if (num > 20)
                {
                    break;
                }
                if (StartingPawnUtility.WorkTypeRequirementsSatisfied())
                {
                    goto Block_3;
                }
            }
            return;

Block_3:
            while (Find.GameInitData.startingPawns.Count < this.pawnChoiceCount)
            {
                Find.GameInitData.startingPawns.Add(StartingPawnUtility.NewGeneratedStartingPawn());
            }
            Find.GameInitData.startingPawnCount = this.pawnCount;
        }
        public override void PostWorldGenerate()
        {
            Find.GameInitData.startingPawnCount = pawnCount;
            int num = 0;

            do
            {
                StartingPawnUtility.ClearAllStartingPawns();
                for (int i = 0; i < pawnCount; i++)
                {
                    Find.GameInitData.startingAndOptionalPawns.Add(StartingPawnUtility.NewGeneratedStartingPawn());
                }
                num++;
            }while (num <= 20 && !StartingPawnUtility.WorkTypeRequirementsSatisfied());
            while (Find.GameInitData.startingAndOptionalPawns.Count < pawnChoiceCount)
            {
                Find.GameInitData.startingAndOptionalPawns.Add(StartingPawnUtility.NewGeneratedStartingPawn());
            }
        }
Example #3
0
        public override void PostMapGenerate(Map map)
        {
            if (Find.GameInitData == null)
            {
                return;
            }
            string str1 = Path.Combine(Path.Combine(GenFilePaths.SaveDataFolderPath, "Ships"), shipFactionName + ".rwship");
            string actualFactionName = shipFactionName;
            bool   isVersion2        = false;

            if (File.Exists(str1 + "2")) //woo 2.0
            {
                str1      += "2";
                isVersion2 = true;
            }
            Scribe.loader.InitLoading(str1);

            FactionDef     factionDef = Faction.OfPlayer.def;
            ShipDefinition ship       = null;

            ShipInteriorMod.Log("Loading base managers...");
            Scribe_Deep.Look(ref Current.Game.uniqueIDsManager, false, "uniqueIDsManager", new object[0]);
            Scribe_Deep.Look(ref Current.Game.tickManager, false, "tickManager", new object[0]);
            Scribe_Deep.Look(ref Current.Game.drugPolicyDatabase, false, "drugPolicyDatabase", new object[0]);
            Scribe_Deep.Look(ref Current.Game.outfitDatabase, false, "outfitDatabase", new object[0]);

            //spawn a temp pawn.
            Pawn tmpPawn = StartingPawnUtility.NewGeneratedStartingPawn();

            //Advancing time
            ShipInteriorMod.Log("Advancing time...");
            Current.Game.tickManager.DebugSetTicksGame(Current.Game.tickManager.TicksAbs + 3600000 * Rand.RangeInclusive(Mod.minTravelTime.Value, Mod.maxTravelTime.Value));

            if (isVersion2)
            {
                Scribe_Values.Look(ref actualFactionName, "playerFactionName");
                Scribe_Deep.Look(ref ship, "shipDefinition");
            }
            else
            {
                ship = new ShipDefinition();
                //load the data the more cludgey way.
                ship.ExposeData();
            }

            highCorner = ship.Max;
            lowCorner  = ship.Min;

            IntVec3 spot   = MapGenerator.PlayerStartSpot;
            int     width  = highCorner.x - lowCorner.x;
            int     height = highCorner.z - lowCorner.z;

            //try to position us over the start location
            spot.x -= width / 2;
            spot.z -= height / 2;

            //now offset the corners and the parts to the spot.
            int offsetx = spot.x - lowCorner.x;
            int offsety = spot.z - lowCorner.z;

            lowCorner.x  += offsetx;
            lowCorner.z  += offsety;
            highCorner.x += offsetx;
            highCorner.z += offsety;

            tmpPawn.Position = lowCorner - new IntVec3(3, 0, 3);
            tmpPawn.SpawnSetup(map, false);

            ShipInteriorMod.Log("Low Corner: " + lowCorner.x + ", " + lowCorner.y + ", " + lowCorner.z);
            ShipInteriorMod.Log("High Corner: " + highCorner.x + ", " + highCorner.y + ", " + highCorner.z);
            ShipInteriorMod.Log("Map Size: " + map.Size.x + ", " + map.Size.y + ", " + map.Size.z);

            ship.AdaptToNewGame(map, offsetx, offsety, "Landing", true, Handler);

            new MapScanner()
            .DestroyThings(-2, 2)
            .ForPoints((point, m) => m.roofGrid.SetRoof(point, null), -2, 2)
            .ForPoints((point, m) => m.terrainGrid.SetTerrain(point, TerrainDefOf.Gravel))
            .Unfog(-3, 3)
            .QueueAsLongEvent(map, lowCorner, highCorner, "Landing_Clean", true, Handler);

            ship.SpawnInNewGame(map, "Landing", true, Handler);


            LongEventHandler.QueueLongEvent(() =>
            {
                ShipInteriorMod.Log("Loading managers...");
                Scribe_Deep.Look(ref Current.Game.researchManager, false, "researchManager", new object[0]);
                Scribe_Deep.Look(ref Current.Game.taleManager, false, "taleManager", new object[0]);
                Scribe_Deep.Look(ref Current.Game.playLog, false, "playLog", new object[0]);
                Scribe.loader.FinalizeLoading();
                tmpPawn.DeSpawn();

                Faction.OfPlayer.Name = actualFactionName;

                ShipInteriorMod.Log("Done.");
            }, "Landing_Managers", true, Handler);
        }
Example #4
0
        public static void GenerateEmptyMap()
        {
            LongEventHandler.QueueLongEvent(delegate()
            {
                var game = new Game
                {
                    InitData = new GameInitData()
                    {
                        mapSize = 75, permadeath = false
                    },
                    Scenario    = ScenarioDefOf.Crashlanded.scenario,
                    storyteller = new Storyteller(StorytellerDefOf.Cassandra, DifficultyDefOf.Rough)
                };
                Find.Scenario.PreConfigure();
                Current.Game = game;

                Find.GameInitData.PrepForMapGen();
                Find.GameInitData.startedFromEntry = true;
                Find.Scenario.PreMapGenerate();

                Find.GameInitData.ResetWorldRelatedMapInitData();
                Current.Game.World = WorldGenerator.GenerateWorld(0.05f, GenText.RandomSeedString(), OverallRainfall.Normal, OverallTemperature.Normal, OverallPopulation.Normal);
                MemoryUtility.UnloadUnusedUnityAssets();
                Find.World.renderer.RegenerateAllLayersNow();

                MemoryUtility.UnloadUnusedUnityAssets();

                Current.ProgramState = ProgramState.MapInitializing;

                var mapSize = new IntVec3(game.InitData.mapSize, 1, game.InitData.mapSize);
                game.World.info.initialMapSize = mapSize;
                if (game.InitData.permadeath)
                {
                    game.Info.permadeathMode           = true;
                    game.Info.permadeathModeUniqueName = PermadeathModeUtility.GeneratePermadeathSaveName();
                }

                game.tickManager.gameStartAbsTick = GenTicks.ConfiguredTicksAbsAtGameStart;

                _ = Find.Scenario.parts.RemoveAll(part => part is ScenPart_GameStartDialog);
                var arrivalMethod    = Find.Scenario.AllParts.OfType <ScenPart_PlayerPawnsArriveMethod>().First();
                arrivalMethod.method = PlayerPawnsArriveMethod.Standing;

                var tile = TileFinder.RandomStartingTile();

                Find.GameInitData.startingAndOptionalPawns.Clear();

                for (var i = 1; i <= 3; i++)
                {
                    var pawn = StartingPawnUtility.NewGeneratedStartingPawn();
                    pawn.playerSettings.hostilityResponse = HostilityResponseMode.Ignore;
                    DefDatabase <SkillDef> .AllDefsListForReading.Do(skillDef => pawn.skills.GetSkill(skillDef).EnsureMinLevelWithMargin(1));
                    Find.GameInitData.startingAndOptionalPawns.Add(pawn);
                }

                var settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                settlement.SetFaction(Find.GameInitData.playerFaction);
                settlement.Tile = tile;
                settlement.Name = NameGenerator.GenerateName(Faction.OfPlayer.def.factionNameMaker);
                Find.WorldObjects.Add(settlement);

                Current.Game.CurrentMap = MapGenerator.GenerateMap(mapSize, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs, null);
                PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism);

                game.FinalizeInit();
                game.playSettings.useWorkPriorities = true;

                Find.CameraDriver.JumpToCurrentMapLoc(MapGenerator.PlayerStartSpot);
                Find.CameraDriver.ResetSize();
                Find.Scenario.PostGameStart();

                foreach (var researchProjectDef in DefDatabase <ResearchProjectDef> .AllDefs)
                {
                    game.researchManager.FinishProject(researchProjectDef, false, null);
                }

                GameComponentUtility.StartedNewGame();
                game.InitData = null;
            }, "GeneratingMap", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap), true);
            LongEventHandler.QueueLongEvent(delegate()
            {
                ScreenFader.SetColor(Color.black);
                ScreenFader.StartFade(Color.clear, 0.5f);
            }, null, false, null, true);
        }