Beispiel #1
0
        internal void Arrive(IntVec3 targetCell, ShipArrivalAction arrivalAction, PawnsArrivalModeDef mapArrivalMode)
        {
            if (this.IsPlayerControlled && arrivalAction != ShipArrivalAction.BombingRun)
            {
                Messages.Message("MessageShipsArrived".Translate(), this, MessageTypeDefOf.NeutralEvent);
            }

            if (arrivalAction == ShipArrivalAction.EnterMapAssault || arrivalAction == ShipArrivalAction.EnterMapFriendly)
            {
                MapParent parent = Find.WorldObjects.MapParentAt(this.Tile);
                if (parent != null)
                {
                    Map map = parent.Map;
                    if (map == null)
                    {
                        LongEventHandler.QueueLongEvent(delegate
                        {
                            MapGeneratorDef def = WorldShipUtility.GetMapGeneratorDefForObject(parent);
                            map        = MapGenerator.GenerateMap(Find.World.info.initialMapSize, parent, MapGeneratorDefOf.Base_Faction);
                            targetCell = IntVec3.Zero;
                        }, "GeneratingMap", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap));
                    }
                    LongEventHandler.QueueLongEvent(delegate
                    {
                        WorldShipUtility.EnterMapWithShip(this, map, targetCell, arrivalAction, mapArrivalMode);
                    }, "SpawningColonists", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap));
                }
            }
            else if (arrivalAction == ShipArrivalAction.BombingRun)
            {
                if (BombingUtility.TryBombWorldTarget(this.Tile, this))
                {
                }
            }
        }
 public static void Postfix(MapParent __instance, ref MapGeneratorDef __result)
 {
     if (Find.World.worldObjects.AllWorldObjects.Find(o => o.Tile == __instance.Tile && o.def.HasModExtension <CustomGenOption>()) is WorldObject worldObject)
     {
         KLog.Message($"Generating worldObject {worldObject.LabelCap}");
         __result = DefDatabase <MapGeneratorDef> .GetNamed("KCSG_WorldObject_Gen");
     }
 }
Beispiel #3
0
        public static void Prefix(ref IntVec3 mapSize, MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs = null, Action <Map> extraInitBeforeContentGen = null)
        {
            var worldComp = Find.World.GetComponent <WorldComponentGeneration>();

            if (worldComp.tileSizes.ContainsKey(parent.Tile))
            {
                mapSize = worldComp.tileSizes[parent.Tile];
                worldComp.tileSizes.Remove(parent.Tile);
                Log.Message("Changing map size to " + mapSize);
            }
        }
Beispiel #4
0
        internal void OnMapGenerated(Map map, MapGeneratorDef usedMapGenerator)
        {
            RerollToolbox.StoreGeneratedThingIdsInMapState(map);
            var mapState = RerollToolbox.GetStateForMap(map);

            mapState.UsedMapGenerator = usedMapGenerator;
            if (!rerollInProgress)
            {
                mapState.ResourceBalance = MaxResourceBalance;
            }
        }
Beispiel #5
0
 public static void Postfix(IntVec3 mapSize, MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs = null, Action <Map> extraInitBeforeContentGen = null)
 {
     Log.Message("GetOrGenerateMapPatch.caravanArrival: " + GetOrGenerateMapPatch.caravanArrival);
     if (!caravanArrival)
     {
         var preset = SettlementGeneration.GetPresetFor(parent, out LocationDef locationDef);
         if (preset != null && locationDef != null)
         {
             SettlementGeneration.DoSettlementGeneration(parent.Map, preset.FullName, locationDef, parent.Faction, false);
         }
     }
 }
        public static void Prefix(MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs)
        {
            const float MAX_MTN_VALUE = 0.7f;

            buMtnValue   = null;
            buWaterValue = null;

            if (shouldOverrideSettings(parent, mapGenerator, extraGenStepDefs))
            {
                buMtnValue   = MapSettings.Mountain;
                buWaterValue = MapSettings.Water;

                float value = buMtnValue.GetMultiplier();
                if (value > MAX_MTN_VALUE)
                {
                    Log.Warning($"[Configurable Maps] For quest maps, capping mountain density to {MAX_MTN_VALUE}");
                    MapSettings.Mountain = new RandomizableMultiplier0();
                    MapSettings.Mountain.SetIsRandom(false);
                    MapSettings.Mountain.SetMultiplier(MAX_MTN_VALUE);
                }

                value = buWaterValue.GetMultiplier();
                if (value > MAX_MTN_VALUE)
                {
                    Log.Warning($"[Configurable Maps] For quest maps, capping water density to {MAX_MTN_VALUE}");
                    MapSettings.Water = new RandomizableMultiplier0();
                    MapSettings.Water.SetIsRandom(false);
                    MapSettings.Water.SetMultiplier(MAX_MTN_VALUE);
                }

                //DefsUtil.Enable = false;
                //Log.Message("[Configurable Maps] this tile has a quest on it. Disabling map modifications.");
                //DefsUtil.EnableMountainSettings = false;
                //Log.Message("[Configurable Maps] fertility, water, and mountain settings will be disabled for this map since it has a quest on it.");
            }

            try
            {
                DefsUtil.Update();
            }
            catch
            {
                Log.Error("[Configurable Maps] failed to apply map settings.");
            }

            GenStep_RockChunks_GrowLowRockFormationFrom.ChunkLevel = MapSettings.ChunkLevel;
            if (MapSettings.ChunkLevel == ChunkLevelEnum.Random)
            {
                GenStep_RockChunks_GrowLowRockFormationFrom.ChunkLevel = (ChunkLevelEnum)Rand.RangeInclusive(0, Enum.GetNames(typeof(ChunkLevelEnum)).Length - 1);
            }
        }
Beispiel #7
0
 static void Prefix(ref IntVec3 mapSize, MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs, ref System.Action <Map> extraInitBeforeContentGen)
 {
     if (parent is City city)
     {
         var shouldLimitMapSize = !city.Abandoned;
         if (LoadedModManager.GetMod <Mod_Cities>().GetSettings <ModSettings_Cities>().limitCitySize)
         {
             mapSize.x = Mathf.Min(mapSize.x, 200);
             mapSize.z = Mathf.Min(mapSize.z, 200);
         }
         var prevInitAction = extraInitBeforeContentGen;
         extraInitBeforeContentGen = map => {
             city.PreMapGenerate(map);
             prevInitAction?.Invoke(map);
         };
     }
 }
 public static void Postfix(Settlement __instance, ref MapGeneratorDef __result)
 {
     if (__instance != null && __instance.Faction != null && __instance.Faction != Faction.OfPlayer)
     {
         KLog.Message($"Faction: {__instance.Faction.NameColored} - Generating");
         if (__instance.Faction.def.HasModExtension <CustomGenOption>())
         {
             KLog.Message($"Faction: {__instance.Faction.NameColored} - Faction have CustomGenOption extension");
             __result = DefDatabase <MapGeneratorDef> .GetNamed("KCSG_Base_Faction");
         }
         else if (Find.World.worldObjects.AllWorldObjects.FindAll(o => o.Tile == __instance.Tile && o.def.HasModExtension <CustomGenOption>()).Any())
         {
             KLog.Message($"Faction: {__instance.Faction.NameColored} - Faction do not have CustomGenOption extension");
             __result = DefDatabase <MapGeneratorDef> .GetNamed("KCSG_WorldObject_Gen");
         }
     }
 }
Beispiel #9
0
        static void Prefix(MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs)
        {
            Patch_GenStep_Terrain.ClearMiddleAreaCells();
            foreach (var q in Current.Game.questManager.QuestsListForReading)
            {
                if (q.State == QuestState.Ongoing)
                {
                    foreach (var qt in q.QuestLookTargets)
                    {
                        if (qt.Tile == parent.Tile)
                        {
                            IsQuestMap = true;
                            return;
                        }
                    }
                }
            }

            foreach (var d in mapGenerator.genSteps)
            {
                if (d.genStep.def.defName.Contains("Archonexus"))
                {
                    IsQuestMap = true;
                    return;
                }
            }

            if (extraGenStepDefs != null)
            {
                foreach (var d in extraGenStepDefs)
                {
                    if (d.def.defName.Contains("Archonexus"))
                    {
                        IsQuestMap = true;
                        return;
                    }
                }
            }
            IsQuestMap = false;
            return;
        }
Beispiel #10
0
        static void Prefix(ref IntVec3 mapSize, MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs, ref System.Action <Map> extraInitBeforeContentGen)
        {
            // if (Find.GameInitData.QuickStarted && Config_QuickStart.MapGenerator != null) {
            //     mapGenerator = DefDatabase<MapGeneratorDef>.GetNamed(Config_QuickStart.MapGenerator);
            // }

            if (parent is City city)
            {
                mapSize = city.ChooseMapSize(mapSize);
                var prevInitAction = extraInitBeforeContentGen;
                extraInitBeforeContentGen = map => {
                    city.PreMapGenerate(map);
                    prevInitAction?.Invoke(map);
                };
            }

            // if (Config_Cities.Instance.customMapSizes) {
            //     mapSize.x = Config_Cities.Instance.customMapX;
            //     mapSize.z = Config_Cities.Instance.customMapZ;
            // }
        }
Beispiel #11
0
        public bool FindScenPart()
        {
            if (DefDatabase <MapGeneratorDef> .AllDefs.Count() == 1)
            {
                MapGeneratorDef def = DefDatabase <MapGeneratorDef> .AllDefs.First();

                if (def != null)
                {
                    foreach (var g in def.GenStepsInOrder)
                    {
                        if (g.genStep != null && g.genStep.GetType().FullName.Equals(typeof(EdB.PrepareCarefully.GenStep_ScenParts).FullName))
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
            }
            // TODO: We can't figure this out in every situation.  If there's more than one
            // map generator, the game is going to pick one at random, and we can't know at this
            // point which one it's going to pick.  In that case, we'll assume that everything is
            // good.
            return(true);
        }
        private static bool shouldOverrideSettings(MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs)
        {
            foreach (var q in Current.Game.questManager.QuestsListForReading)
            {
                if (q.State == QuestState.Ongoing)
                {
                    foreach (var qt in q.QuestLookTargets)
                    {
                        if (qt.Tile == parent.Tile)
                        {
                            return(true);
                        }
                    }
                }
            }

            foreach (var d in mapGenerator.genSteps)
            {
                if (d.genStep.def.defName.Contains("Archonexus"))
                {
                    return(true);
                }
            }

            if (extraGenStepDefs != null)
            {
                foreach (var d in extraGenStepDefs)
                {
                    if (d.def.defName.Contains("Archonexus"))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #13
0
        public static bool GenerateMap(ref Map __result, IntVec3 mapSize, MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs = null, Action <Map> extraInitBeforeContentGen = null)
        {
            int tID = Thread.CurrentThread.ManagedThreadId;

            if (RimThreaded.mainRequestWaits.TryGetValue(tID, out EventWaitHandle eventWaitStart))
            {
                object[] functionAndParameters = new object[] { safeFunction, new object[] { mapSize, parent, mapGenerator, extraGenStepDefs, extraInitBeforeContentGen } };
                lock (RimThreaded.timeoutExemptThreads2)
                {
                    RimThreaded.timeoutExemptThreads2.Add(tID, 60000); //60 sec timeout
                }
                lock (RimThreaded.safeFunctionRequests)
                {
                    RimThreaded.safeFunctionRequests[tID] = functionAndParameters;
                }
                lock (RimThreaded.timeoutExemptThreads2)
                {
                    if (RimThreaded.timeoutExemptThreads2.ContainsKey(tID))
                    {
                        RimThreaded.timeoutExemptThreads2.Remove(tID);
                    }
                }
                RimThreaded.mainThreadWaitHandle.Set();
                eventWaitStart.WaitOne();
                RimThreaded.safeFunctionResults.TryGetValue(tID, out object safeFunctionResult);
                __result = (Map)safeFunctionResult;
                return(false);
            }
            return(true);
        }
Beispiel #14
0
 public static bool GenerateMap(ref Map __result, IntVec3 mapSize, MapParent parent, MapGeneratorDef mapGenerator, IEnumerable <GenStepWithParams> extraGenStepDefs = null, Action <Map> extraInitBeforeContentGen = null)
 {
     if (allThreads2.TryGetValue(CurrentThread, out ThreadInfo threadInfo))
     {
         threadInfo.timeoutExempt       = 60000;
         threadInfo.safeFunctionRequest = new object[] { safeFunction, new object[] {
                                                             mapSize, parent, mapGenerator, extraGenStepDefs, extraInitBeforeContentGen
                                                         } };
         mainThreadWaitHandle.Set();
         threadInfo.eventWaitStart.WaitOne();
         threadInfo.timeoutExempt = 0;
         __result = (Map)threadInfo.safeFunctionResult;
         return(false);
     }
     return(true);
 }
Beispiel #15
0
 private static void OnMapGenerated(Map map, MapGeneratorDef def)
 {
     MapRerollController.Instance.OnMapGenerated(map, def);
 }
Beispiel #16
0
        static void Postfix(ref Map __result, MapGeneratorDef mapGenerator)
        {
            if (__result.TileInfo.hilliness == Hilliness.Impassable && Settings.OuterShape == ImpassableShape.Fill)
            {
                int maxX = __result.Size.x - 1;
                int maxZ = __result.Size.z - 1;
                foreach (IntVec3 current in __result.AllCells)
                {
                    if (Settings.CoverRoadAndRiver && __result.roofGrid.RoofAt(current) == null)
                    {
                        if (Patch_GenStep_Terrain.IsWithinCornerOfMap(current, maxX + 1, maxZ + 1))
                        {
                            __result.roofGrid.SetRoof(current, null);
                            continue;
                        }
                        else if (Patch_GenStep_Terrain.IsInMiddleArea(current))
                        {
                            __result.roofGrid.SetRoof(current, null);
                            continue;
                        }
                        __result.roofGrid.SetRoof(current, RoofDefOf.RoofRockThick);
                    }

                    if (Settings.RoofEdgeDepth > 0)
                    {
                        if (current.x == 0 ||
                            current.x == maxX ||
                            current.z == 0 ||
                            current.z == maxZ)
                        {
                            __result.roofGrid.SetRoof(current, null);
                        }
                    }
                    if (Settings.HasMiddleArea == false)
                    {
                        for (var x = Math.Max(0, MapGenerator.PlayerStartSpot.x - 5); x < Math.Min(__result.Size.x, MapGenerator.PlayerStartSpot.x + 5); ++x)
                        {
                            for (var z = Math.Max(0, MapGenerator.PlayerStartSpot.z - 5); z < Math.Min(__result.Size.z, MapGenerator.PlayerStartSpot.z + 5); ++z)
                            {
                                var i = new IntVec3(x, 0, z);
                                foreach (var t in __result.thingGrid.ThingsAt(i))
                                {
                                    if (t.def.passability == Traversability.Impassable)
                                    {
                                        t.Destroy();
                                    }
                                }
                                __result.roofGrid.SetRoof(i, null);
                            }
                        }
                    }
                    else
                    {
                        __result.roofGrid.SetRoof(MapGenerator.PlayerStartSpot, null);
                    }
                }

                /*
                 * var map = __result;
                 * Patch_GenStep_Terrain.ClearMiddleAreaCells();
                 * Task.Delay(new TimeSpan(0, 0, 3)).ContinueWith(t => {
                 *  try
                 *  {
                 *      FloodFillerFog.DebugRefogMap(map);
                 *  }
                 *  catch { }
                 * });*/
            }
        }