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); } }
public static void Postfix() { //DefsUtil.EnableMountainSettings = true; //DefsUtil.Enable = true; if (buMtnValue != null) { MapSettings.Mountain = buMtnValue; buMtnValue = null; } if (buWaterValue != null) { MapSettings.Water = buWaterValue; buWaterValue = null; } DefsUtil.Restore(); }
public static void Initialize() { if (Fertility == null) { Fertility = new RandomizableMultiplier0(); } Fertility.DefaultValue = 0; Fertility.RandomMin = -3; Fertility.RandomMax = 3; if (Water == null) { Water = new RandomizableMultiplier0(); } Water.DefaultValue = 0; Water.RandomMin = -0.75f; Water.RandomMax = 0.75f; var ms = MineableStuff.GetMineables(); if (Mineables == null && ms != null && ms.Count > 0) { Mineables = new List <RandomizableMultiplier>(ms.Count); foreach (var m in ms) { Mineables.Add(new RandomizableMultiplier() { ThingDef = m, ThingDefName = m.defName, DefaultValue = m.building.mineableScatterCommonality, }); } } else if (!initMineables && ms.Count > 0) { initMineables = true; for (int i = Mineables.Count - 1; i >= 0; --i) { var m = Mineables[i]; if (m.ThingDef == null && m.ThingDefName != "") { m.ThingDef = DefDatabase <ThingDef> .GetNamed(m.ThingDefName, false); if (m.ThingDef == null) { Mineables.RemoveAt(i); Log.Message($"[Configurable Maps] Unable to load mineable thing def {m.ThingDefName}"); } } } foreach (var m in ms) { bool found = false; foreach (var r in Mineables) { found = r.ThingDefName == m.defName; if (found) { r.ThingDef = m; r.DefaultValue = m.building.mineableScatterCommonality; break; } } if (!found) { Mineables.Add(new RandomizableMultiplier() { ThingDef = m, ThingDefName = m.defName }); } } } if (Geysers == null) { Geysers = new RandomizableMultiplier(); } Geysers.DefaultValue = 1; if (Mountain == null) { Mountain = new RandomizableMultiplier0(); } Mountain.Max = 1.4f; Mountain.DefaultValue = 0; Mountain.RandomMin = -0.15f; Mountain.RandomMax = 1.4f; if (AnimalDensity == null) { AnimalDensity = new RandomizableMultiplier(); } AnimalDensity.RandomMax = 6; if (PlantDensity == null) { PlantDensity = new RandomizableMultiplier(); } PlantDensity.RandomMax = 6; if (Ruins == null) { Ruins = new RandomizableMultiplier(); } Ruins.RandomMax = 50f; if (Shrines == null) { Shrines = new RandomizableMultiplier(); } Shrines.RandomMax = 50; if (AncientPipelineSection == null) { AncientPipelineSection = new RandomizableMultiplier(); } AncientPipelineSection.RandomMax = 50; if (AncientJunkClusters == null) { AncientJunkClusters = new RandomizableMultiplier(); } AncientJunkClusters.RandomMax = 50; if (OreLevels == null) { OreLevels = new RandomizableMultiplier(); } OreLevels.DefaultValue = 1; OreLevels.Min = 0; OreLevels.RandomMin = 0; OreLevels.RandomMax = 6; int resetCount = 0; if (Mineables != null) { foreach (var m in Mineables) { if (m.GetMultiplier() == 1.0f) { ++resetCount; } } if (resetCount > 3) { Log.Message("[Configurable Maps] Correcting default values for mineables to their default values."); foreach (var m in Mineables) { m.SetMultiplier(m.DefaultValue); } } } resetCount = 0; resetCount += (Fertility?.GetMultiplier() == 1f) ? 1 : 0; resetCount += (Water?.GetMultiplier() == 1f) ? 1 : 0; resetCount += (Mountain?.GetMultiplier() == 1f) ? 1 : 0; if (resetCount >= 2) { Fertility.SetMultiplier(Fertility.DefaultValue); Water.SetMultiplier(Water.DefaultValue); Mountain.SetMultiplier(Mountain.DefaultValue); Log.Message("[Configurable Maps] Correcting default values for Fertility, Water, and Mountain to their default values."); } }