private void HandleSprinkleOfElement(WorldGenSettings settings, Tag targetTag, Chunk world, SetValuesFunction SetValues, float temperatureMin, float temperatureRange, SeededRandom rnd) { FeatureSettings feature = settings.GetFeature(targetTag.Name); string element = feature.GetOneWeightedSimHash("SprinkleOfElementChoices", rnd).element; Element element2 = ElementLoader.FindElementByName(element); ProcGen.Room value = null; SettingsCache.rooms.TryGetValue(targetTag.Name, out value); SampleDescriber sampleDescriber = value; Sim.PhysicsData defaultValues = element2.defaultValues; Sim.DiseaseCell invalid = Sim.DiseaseCell.Invalid; for (int i = 0; i < terrainPositions.Count; i++) { if (!(terrainPositions[i].Value != targetTag)) { float radius = rnd.RandomRange(sampleDescriber.blobSize.min, sampleDescriber.blobSize.max); Vector2 center = Grid.CellToPos2D(terrainPositions[i].Key); List <Vector2I> filledCircle = ProcGen.Util.GetFilledCircle(center, radius); for (int j = 0; j < filledCircle.Count; j++) { Vector2I vector2I = filledCircle[j]; int x = vector2I.x; Vector2I vector2I2 = filledCircle[j]; int num = Grid.XYToCell(x, vector2I2.y); if (Grid.IsValidCell(num)) { defaultValues.mass = GetDensityMassForCell(world, num, element2.defaultValues.mass); defaultValues.temperature = temperatureMin + world.heatOffset[num] * temperatureRange; SetValues(num, element2, defaultValues, invalid); } } } } }
private static void Prefix(WorldGen __instance, Sim.Cell[] cells, Chunk world, SeededRandom rnd, ref HashSet <int> borderCells, ref List <RectInt> poiBounds, WorldGen.OfflineCallbackFunction updateProgressFn) { bool boolSetting = __instance.Settings.GetBoolSetting("DrawWorldBorderBottom"); int intSetting = __instance.Settings.GetIntSetting("WorldBorderThickness"); int intSetting2 = __instance.Settings.GetIntSetting("WorldBorderRange"); byte new_elem_idx = (byte)ElementLoader.elements.IndexOf(WorldGen.unobtaniumElement); float temperature = WorldGen.unobtaniumElement.defaultValues.temperature; float mass = WorldGen.unobtaniumElement.defaultValues.mass; for (int l = 0; l < world.size.x; l++) { updateProgressFn(UI.WORLDGEN.DRAWWORLDBORDER.key, l / world.size.x * 0.66f + 0.33f, WorldGenProgressStages.Stages.DrawWorldBorder); var num9 = Mathf.Max(-intSetting2, Mathf.Min(rnd.RandomRange(-2, 2), intSetting2)); for (int m = 0; m < intSetting + num9; m++) { int num13 = Grid.XYToCell(l, m); if (boolSetting) { borderCells.Add(num13); cells[num13].SetValues(new_elem_idx, temperature, mass); } } } }
public static List <Vector2I> GetFilledRectangle(Vector2 center, float width, float height, SeededRandom rand, float jitterMaxStep = 2f, float jitterRange = 2f) { HashSet <Vector2I> hashSet = new HashSet <Vector2I>(); if (width < 1f) { width = 1f; } if (height < 1f) { height = 1f; } float num = 0f; float num2 = 0f; int num3 = (int)(center.x - width / 2f); int num4 = (int)(center.x + width / 2f); int num5 = (int)(center.y - height / 2f); int num6 = (int)(center.y + height / 2f); for (int i = num5; i < num6; i++) { num = Mathf.Max(0f - jitterRange, Mathf.Min(num + rand.RandomRange(0f - jitterMaxStep, jitterMaxStep), jitterRange)); num2 = Mathf.Max(0f - jitterRange, Mathf.Min(num2 + rand.RandomRange(0f - jitterMaxStep, jitterMaxStep), jitterRange)); for (int j = (int)((float)num3 - num); (float)j < (float)num4 + num2; j++) { hashSet.Add(new Vector2I(j, i)); } } float num7 = 0f; float num8 = 0f; for (int k = num3; k < num4; k++) { num7 = Mathf.Max(0f - jitterRange, Mathf.Min(num7 + rand.RandomRange(0f - jitterMaxStep, jitterMaxStep), jitterRange)); num8 = Mathf.Max(0f - jitterRange, Mathf.Min(num8 + rand.RandomRange(0f - jitterMaxStep, jitterMaxStep), jitterRange)); for (int l = (int)((float)num5 - num7); l < num5; l++) { hashSet.Add(new Vector2I(k, l)); } for (int m = num6; (float)m < (float)num6 + num8; m++) { hashSet.Add(new Vector2I(k, m)); } } return(new List <Vector2I>(hashSet)); }
private int GetIndexForLocation(List <Vector2I> points, Mob.Location location, SeededRandom rnd) { int num = -1; if (points == null || points.Count == 0) { return(num); } if (location == Mob.Location.Air || location == Mob.Location.Solid) { return(rnd.RandomRange(0, points.Count)); } for (int i = 0; i < points.Count; i++) { Vector2I vector2I = points[i]; int x = vector2I.x; Vector2I vector2I2 = points[i]; int cell = Grid.XYToCell(x, vector2I2.y); if (Grid.IsValidCell(cell)) { if (num == -1) { num = i; } else { switch (location) { case Mob.Location.Ceiling: { Vector2I vector2I5 = points[i]; int y2 = vector2I5.y; Vector2I vector2I6 = points[num]; if (y2 > vector2I6.y) { num = i; } break; } case Mob.Location.Floor: { Vector2I vector2I3 = points[i]; int y = vector2I3.y; Vector2I vector2I4 = points[num]; if (y < vector2I4.y) { num = i; } break; } } } } } return(num); }
public void PlaceSites(List <Diagram.Site> sites, int seed) { SeededRandom seededRandom = new SeededRandom(seed); List <Vector2> list = null; List <Vector2> list2 = new List <Vector2>(); for (int i = 0; i < sites.Count; i++) { list2.Add(sites[i].position); } int num = 0; for (int j = 0; j < sites.Count; j++) { if (!site.poly.Contains(sites[j].position)) { if (list == null) { list = PointGenerator.GetRandomPoints(site.poly, 5f, 1f, list2, PointGenerator.SampleBehaviour.PoissonDisk, true, seededRandom, true, true); } if (num >= list.Count - 1) { list2.AddRange(list); list = PointGenerator.GetRandomPoints(site.poly, 0.5f, 0.5f, list2, PointGenerator.SampleBehaviour.PoissonDisk, true, seededRandom, true, true); num = 0; } if (list.Count == 0) { sites[j].position = sites[0].position + Vector2.one * seededRandom.RandomValue(); } else { sites[j].position = list[num++]; } } } HashSet <Vector2> hashSet = new HashSet <Vector2>(); for (int k = 0; k < sites.Count; k++) { if (hashSet.Contains(sites[k].position)) { visited = VisitedType.Error; sites[k].position += new Vector2((float)seededRandom.RandomRange(0, 1), (float)seededRandom.RandomRange(0, 1)); } hashSet.Add(sites[k].position); sites[k].poly = null; } }
public List <Segment> Stagger(SeededRandom rnd, float maxDistance = 10f, float staggerRange = 3f) { List <Segment> list = new List <Segment>(); Vector2 a = e1 - e0; Vector2 vector = e0; Vector2 vector2 = e1; float magnitude = a.magnitude; float num = magnitude / maxDistance; Vector2 normalized = new Vector2(0f - a.y, a.x).normalized; for (int i = 0; (float)i < num; i++) { vector2 = e0 + a * (1f / num) * (float)i + normalized * rnd.RandomRange(0f - staggerRange, staggerRange); list.Add(new Segment(vector, vector2)); vector = vector2; } list.Add(new Segment(vector2, e1)); return(list); }
private List <Vector2> Sample(Vector2 topLeft, Vector2 lowerRight, float?rejectionDistance, float minimumDistance, int pointsPerIteration) { Settings settings = default(Settings); settings.TopLeft = topLeft; settings.LowerRight = lowerRight; settings.Dimensions = lowerRight - topLeft; settings.Center = (topLeft + lowerRight) / 2f; settings.CellSize = minimumDistance / SquareRootTwo; settings.MinimumDistance = minimumDistance; settings.RejectionSqDistance = ((!rejectionDistance.HasValue) ? null : (rejectionDistance * rejectionDistance)); Settings settings2 = settings; settings2.GridWidth = (int)(settings2.Dimensions.x / settings2.CellSize) + 1; settings2.GridHeight = (int)(settings2.Dimensions.y / settings2.CellSize) + 1; State state = default(State); state.Grid = new Vector2?[settings2.GridWidth, settings2.GridHeight]; state.ActivePoints = new List <Vector2>(); state.Points = new List <Vector2>(); State state2 = state; AddFirstPoint(ref settings2, ref state2); while (state2.ActivePoints.Count != 0) { int index = myRandom.RandomRange(0, state2.ActivePoints.Count - 1); Vector2 point = state2.ActivePoints[index]; bool flag = false; for (int i = 0; i < pointsPerIteration; i++) { flag |= AddNextPoint(point, ref settings2, ref state2); } if (!flag) { state2.ActivePoints.RemoveAt(index); } } return(state2.Points); }
public static void CalculateGeysers(SeededRandom rnd) { Dictionary <string, Dictionary <string, int> > calculatedGeysers = new Dictionary <string, Dictionary <string, int> >(); foreach (KeyValuePair <string, GeyserState> data in WorldGenReloadedData.GeyserConfig) { int geyserCount = rnd.RandomRange(data.Value.Minimum, data.Value.Maximum + 1); string[] subworlds = data.Value.SubWorlds; subworlds.ShuffleSeeded(rnd.RandomSource()); for (int i = 0; i < geyserCount; i++) { string subworld = subworlds[i % subworlds.Length]; if (!calculatedGeysers.ContainsKey(subworld)) { calculatedGeysers[subworld] = new Dictionary <string, int>(); } if (!calculatedGeysers[subworld].ContainsKey(data.Key)) { calculatedGeysers[subworld][data.Key] = 0; } calculatedGeysers[subworld][data.Key]++; } } Debug.Log("Calculated Geysers: "); foreach (KeyValuePair <string, Dictionary <string, int> > subworld in calculatedGeysers) { Debug.Log("Subworld: " + subworld.Key); foreach (KeyValuePair <string, int> geyser in subworld.Value) { Debug.Log("\t" + geyser.Key + " = " + geyser.Value); } } WorldGenReloadedData.CalculatedGeysers = calculatedGeysers; }
public static List <Vector2I> StaggerLine(Vector2 p0, Vector2 p1, int numberOfBreaks, SeededRandom rand, float staggerRange = 3f) { List <Vector2I> list = new List <Vector2I>(); if (numberOfBreaks == 0) { return(GetLine(p0, p1)); } Vector2 a = p1 - p0; Vector2 p2 = p0; Vector2 vector = p1; for (int i = 0; i < numberOfBreaks; i++) { vector = p0 + a * (1f / (float)numberOfBreaks) * (float)i + Vector2.one * rand.RandomRange(0f - staggerRange, staggerRange); list.AddRange(GetLine(p2, vector)); p2 = vector; } list.AddRange(GetLine(vector, p1)); return(list); }
public static T GetRandom <T>(this List <T> tList, SeededRandom rand) { return(tList[rand.RandomRange(0, tList.Count)]); }
public static T GetRandom <T>(this T[] tArray, SeededRandom rand) { return(tArray[rand.RandomRange(0, tArray.Length)]); }
private void ApplyBackground(WorldGen worldGen, Chunk world, SetValuesFunction SetValues, float temperatureMin, float temperatureRange, SeededRandom rnd) { LogInfo("Apply Background", node.type, 0f); float floatSetting = worldGen.Settings.GetFloatSetting("CaveOverrideMaxValue"); float floatSetting2 = worldGen.Settings.GetFloatSetting("CaveOverrideSliverValue"); Leaf leafForTerrainCell = worldGen.GetLeafForTerrainCell(this); bool flag = leafForTerrainCell.tags.Contains(WorldGenTags.IgnoreCaveOverride); bool flag2 = leafForTerrainCell.tags.Contains(WorldGenTags.CaveVoidSliver); bool flag3 = leafForTerrainCell.tags.Contains(WorldGenTags.ErodePointToCentroid); bool flag4 = leafForTerrainCell.tags.Contains(WorldGenTags.ErodePointToCentroidInv); bool flag5 = leafForTerrainCell.tags.Contains(WorldGenTags.ErodePointToEdge); bool flag6 = leafForTerrainCell.tags.Contains(WorldGenTags.ErodePointToEdgeInv); bool flag7 = leafForTerrainCell.tags.Contains(WorldGenTags.ErodePointToBorder); bool flag8 = leafForTerrainCell.tags.Contains(WorldGenTags.ErodePointToBorderInv); bool flag9 = leafForTerrainCell.tags.Contains(WorldGenTags.ErodePointToWorldTop); bool flag10 = leafForTerrainCell.tags.Contains(WorldGenTags.DistFunctionPointCentroid); bool flag11 = leafForTerrainCell.tags.Contains(WorldGenTags.DistFunctionPointEdge); Sim.DiseaseCell diseaseCell = default(Sim.DiseaseCell); diseaseCell.diseaseIdx = byte.MaxValue; if (node.tags.Contains(WorldGenTags.Infected)) { diseaseCell.diseaseIdx = (byte)rnd.RandomRange(0, WorldGen.diseaseIds.Count); node.tags.Add(new Tag("Infected:" + WorldGen.diseaseIds[diseaseCell.diseaseIdx])); diseaseCell.elementCount = rnd.RandomRange(10000, 1000000); } LogInfo("Getting Element Bands", node.type, 0f); ElementBandConfiguration elementBandConfiguration = worldGen.Settings.GetElementBandForBiome(node.type); if (elementBandConfiguration == null && node.biomeSpecificTags != null) { LogInfo("\tType is not a biome, checking tags", string.Empty, (float)node.tags.Count); List <ElementBandConfiguration> list = new List <ElementBandConfiguration>(); foreach (Tag biomeSpecificTag in node.biomeSpecificTags) { ElementBandConfiguration elementBandForBiome = worldGen.Settings.GetElementBandForBiome(biomeSpecificTag.Name); if (elementBandForBiome != null) { list.Add(elementBandForBiome); LogInfo("\tFound biome", biomeSpecificTag.Name, 0f); } } if (list.Count > 0) { int num = rnd.RandomSource().Next(list.Count); elementBandConfiguration = list[num]; LogInfo("\tPicked biome", string.Empty, (float)num); } } DebugUtil.Assert(elementBandConfiguration != null, "A node didn't get assigned a biome! ", node.type); foreach (Vector2I availableTerrainPoint in availableTerrainPoints) { Vector2I current2 = availableTerrainPoint; int num2 = Grid.XYToCell(current2.x, current2.y); if (!highPriorityClaims.Contains(num2)) { float num3 = world.overrides[num2]; if (!flag && num3 >= 100f) { if (num3 >= 300f) { SetValues(num2, WorldGen.voidElement, WorldGen.voidElement.defaultValues, Sim.DiseaseCell.Invalid); } else if (num3 >= 200f) { SetValues(num2, WorldGen.unobtaniumElement, WorldGen.unobtaniumElement.defaultValues, Sim.DiseaseCell.Invalid); } else { SetValues(num2, WorldGen.katairiteElement, WorldGen.katairiteElement.defaultValues, Sim.DiseaseCell.Invalid); } } else { float num4 = 1f; Vector2 vector = new Vector2((float)current2.x, (float)current2.y); if (flag3 || flag4) { float num5 = 15f; if (flag11) { float timeOnEdge = 0f; MathUtil.Pair <Vector2, Vector2> closestEdge = poly.GetClosestEdge(vector, ref timeOnEdge); Vector2 a = closestEdge.First + (closestEdge.Second - closestEdge.First) * timeOnEdge; num5 = Vector2.Distance(a, vector); } num4 = Vector2.Distance(poly.Centroid(), vector) / num5; num4 = Mathf.Max(0f, Mathf.Min(1f, num4)); if (flag4) { num4 = 1f - num4; } } if (flag6 || flag5) { float timeOnEdge2 = 0f; MathUtil.Pair <Vector2, Vector2> closestEdge2 = poly.GetClosestEdge(vector, ref timeOnEdge2); Vector2 a2 = closestEdge2.First + (closestEdge2.Second - closestEdge2.First) * timeOnEdge2; float num6 = 15f; if (flag10) { num6 = Vector2.Distance(poly.Centroid(), vector); } num4 = Vector2.Distance(a2, vector) / num6; num4 = Mathf.Max(0f, Mathf.Min(1f, num4)); if (flag6) { num4 = 1f - num4; } } if (flag8 || flag7) { List <Edge> edgesWithTag = worldGen.WorldLayout.overworldGraph.GetEdgesWithTag(WorldGenTags.EdgeClosed); float num7 = 3.40282347E+38f; foreach (Edge item in edgesWithTag) { MathUtil.Pair <Vector2, Vector2> segment = new MathUtil.Pair <Vector2, Vector2>(item.corner0.position, item.corner1.position); float closest_point = 0f; float a3 = Mathf.Abs(MathUtil.GetClosestPointBetweenPointAndLineSegment(segment, vector, ref closest_point)); num7 = Mathf.Min(a3, num7); } float num8 = 7f; if (flag10) { num8 = Vector2.Distance(poly.Centroid(), vector); } num4 = num7 / num8; num4 = Mathf.Max(0f, Mathf.Min(1f, num4)); if (flag8) { num4 = 1f - num4; } } if (flag9) { Vector2I worldSize = worldGen.WorldSize; int y = worldSize.y; float num9 = 38f; float num10 = 58f; float num11 = (float)y - vector.y; num4 = ((num11 < num9) ? 0f : ((!(num11 < num10)) ? 1f : Mathf.Clamp01((num11 - num9) / (num10 - num9)))); } worldGen.GetElementForBiomePoint(world, elementBandConfiguration, current2, out Element element, out Sim.PhysicsData pd, out Sim.DiseaseCell dc, num4); if (!element.IsVacuum && element.id != SimHashes.Katairite && element.id != SimHashes.Unobtanium) { if (element.lowTempTransition != null && temperatureMin < element.lowTemp) { temperatureMin = element.lowTemp + 20f; } pd.temperature = temperatureMin + world.heatOffset[num2] * temperatureRange; } if (element.IsSolid && !flag && num3 > floatSetting && num3 < 100f) { element = ((!flag2 || !(num3 > floatSetting2)) ? WorldGen.vacuumElement : WorldGen.voidElement); pd = element.defaultValues; } if (dc.diseaseIdx == 255) { dc = diseaseCell; } SetValues(num2, element, pd, dc); } } } if (node.tags.Contains(WorldGenTags.SprinkleOfOxyRock)) { HandleSprinkleOfElement(worldGen.Settings, WorldGenTags.SprinkleOfOxyRock, world, SetValues, temperatureMin, temperatureRange, rnd); } if (node.tags.Contains(WorldGenTags.SprinkleOfMetal)) { HandleSprinkleOfElement(worldGen.Settings, WorldGenTags.SprinkleOfMetal, world, SetValues, temperatureMin, temperatureRange, rnd); } }
public float GetRandomValueWithinRange(SeededRandom rnd) { return(rnd.RandomRange(min, max)); }
private static void ProcessGeysers(WorldGen __instance, ref List <KeyValuePair <Vector2I, TemplateContainer> > templateList, SeededRandom myRandom) { WorldGenReloadedData.CalculateGeysers(myRandom, __instance); List <TemplateContainer> featuresList = TemplateCache.CollectBaseTemplateAssets("features/"); foreach (SubWorld subWorld in __instance.Settings.GetSubWorldList()) { Debug.Log("Processing zone: " + subWorld.name); if (!WorldGenReloadedData.CalculatedGeysers.ContainsKey(subWorld.name)) { continue; } Dictionary <string, int> subworldConfig = WorldGenReloadedData.CalculatedGeysers[subWorld.name]; if (subWorld.pointsOfInterest != null) { foreach (KeyValuePair <string, int> item6 in subworldConfig) { Debug.Log("Processing geyser: [" + item6.Key + "," + item6.Value + "]"); for (int numGeysers = 0; numGeysers < item6.Value; numGeysers++) { List <TerrainCell> terrainCellsForTag2 = __instance.GetTerrainCellsForTag(subWorld.name.ToTag()); for (int num = terrainCellsForTag2.Count - 1; num >= 0; num--) { if (!__instance.IsSafeToSpawnPOI(terrainCellsForTag2[num])) { terrainCellsForTag2.Remove(terrainCellsForTag2[num]); } } /* * if (terrainCellsForTag2.Count <= 0 && WorldGenReloadedData.Config.ForceSpawnGeyserUnsafePlace) * { * terrainCellsForTag2 = WorldGen.GetTerrainCellsForTag(subWorld.name.ToTag()); * } */ Debug.Log("Available cells = " + terrainCellsForTag2.Count); if (terrainCellsForTag2.Count > 0) { string template = null; TemplateContainer templateContainer = null; int num2 = 0; /* * while (templateContainer == null && num2 < item6.Value.Length) * { * template = item6.Value[myRandom.RandomRange(0, item6.Value.Length)]; * templateContainer = list3.Find((TemplateContainer value) => value.name == template); * num2++; * } */ // Constructs a template using the already existing feature generic geyser. first() cause there is only one feature in the folder. TODO templateContainer = GetGeyserTemplate(featuresList.First(), item6.Key); Debug.Log("Adding geyser: " + templateContainer.name + " [" + item6.Key + "]"); if (templateContainer != null) { //list3.Remove(templateContainer); bool geyserPlaced = false; for (int i = 0; i < terrainCellsForTag2.Count; i++) { TerrainCell terrainCell = terrainCellsForTag2[myRandom.RandomRange(0, terrainCellsForTag2.Count)]; if (!terrainCell.node.tags.Contains(WorldGenTags.POI)) { if (!(templateContainer.info.size.Y > terrainCell.poly.MaxY - terrainCell.poly.MinY)) { List <KeyValuePair <Vector2I, TemplateContainer> > list4 = templateList; Vector2 vector3 = terrainCell.poly.Centroid(); int a2 = (int)vector3.x; Vector2 vector4 = terrainCell.poly.Centroid(); list4.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a2, (int)vector4.y), templateContainer)); terrainCell.node.tags.Add(template.ToTag()); terrainCell.node.tags.Add(WorldGenTags.POI); geyserPlaced = true; break; } float num3 = templateContainer.info.size.Y - (terrainCell.poly.MaxY - terrainCell.poly.MinY); float num4 = templateContainer.info.size.X - (terrainCell.poly.MaxX - terrainCell.poly.MinX); if (terrainCell.poly.MaxY + num3 < (float)Grid.HeightInCells && terrainCell.poly.MinY - num3 > 0f && terrainCell.poly.MaxX + num4 < (float)Grid.WidthInCells && terrainCell.poly.MinX - num4 > 0f) { List <KeyValuePair <Vector2I, TemplateContainer> > list5 = templateList; Vector2 vector5 = terrainCell.poly.Centroid(); int a3 = (int)vector5.x; Vector2 vector6 = terrainCell.poly.Centroid(); list5.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a3, (int)vector6.y), templateContainer)); terrainCell.node.tags.Add(template.ToTag()); terrainCell.node.tags.Add(WorldGenTags.POI); geyserPlaced = true; break; } } else { Debug.Log("Cannot find a place for geyser. POI in the way: " + item6.Key); } } if (!geyserPlaced) { Debug.Log("Cannot find a place for geyser. Not enought space: " + item6.Key); } } else { Debug.Log("Cannot build geyser template: " + item6.Key); } } else { Debug.Log("Cannot find a place for geyser. Empty space: " + item6.Key); } } } } } }
private static Sim.Cell[] RenderOffline(WorldGen __instance, bool doSettle, ref Sim.DiseaseCell[] dc) { Debug.Log(" === WorldGenReloadedMod_WorldGen_RenderOffline ==="); WorldGen.OfflineCallbackFunction successCallbackFn = ((WorldGen.OfflineCallbackFunction)successCallbackFnF.GetValue(__instance)); SeededRandom myRandom = ((SeededRandom)myRandomF.GetValue(__instance)); Data data = ((Data)dataF.GetValue(__instance)); Action <OfflineWorldGen.ErrorInfo> errorCallback = ((Action <OfflineWorldGen.ErrorInfo>)errorCallbackF.GetValue(__instance)); Sim.Cell[] cells = null; float[] bgTemp = null; dc = null; HashSet <int> borderCells = new HashSet <int>(); //CompleteLayout(successCallbackFn); __instance.CompleteLayout(successCallbackFn); //WriteOverWorldNoise(successCallbackFn); __instance.WriteOverWorldNoise(successCallbackFn); if (!__instance.RenderToMap(successCallbackFn, ref cells, ref bgTemp, ref dc, ref borderCells)) { successCallbackFn(UI.WORLDGEN.FAILED.key, -100f, WorldGenProgressStages.Stages.Failure); return(null); } __instance.EnsureEnoughAlgaeInStartingBiome(cells); List <KeyValuePair <Vector2I, TemplateContainer> > list = new List <KeyValuePair <Vector2I, TemplateContainer> >(); TemplateContainer baseStartingTemplate = TemplateCache.GetBaseStartingTemplate(); List <TerrainCell> terrainCellsForTag = __instance.GetTerrainCellsForTag(WorldGenTags.StartLocation); foreach (TerrainCell item5 in terrainCellsForTag) { List <KeyValuePair <Vector2I, TemplateContainer> > list2 = list; Vector2 vector = item5.poly.Centroid(); int a = (int)vector.x; Vector2 vector2 = item5.poly.Centroid(); list2.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a, (int)vector2.y), baseStartingTemplate)); } List <TemplateContainer> list3 = TemplateCache.CollectBaseTemplateAssets("poi/"); foreach (SubWorld subWorld in __instance.Settings.GetSubWorldList()) { if (subWorld.pointsOfInterest != null) { //// Disable default POI geysers if (WorldGenReloadedData.Config.DisableDefaultPoiGeysers) { SubWorld _subWorld = subWorld; DisableDefaultPoiGeysers(ref _subWorld); } //// foreach (KeyValuePair <string, string[]> item6 in subWorld.pointsOfInterest) { List <TerrainCell> terrainCellsForTag2 = __instance.GetTerrainCellsForTag(subWorld.name.ToTag()); for (int num = terrainCellsForTag2.Count - 1; num >= 0; num--) { if (!__instance.IsSafeToSpawnPOI(terrainCellsForTag2[num])) { terrainCellsForTag2.Remove(terrainCellsForTag2[num]); } } if (terrainCellsForTag2.Count > 0) { string template = null; TemplateContainer templateContainer = null; int num2 = 0; while (templateContainer == null && num2 < item6.Value.Length) { template = item6.Value[myRandom.RandomRange(0, item6.Value.Length)]; templateContainer = list3.Find((TemplateContainer value) => value.name == template); num2++; } if (templateContainer != null) { list3.Remove(templateContainer); for (int i = 0; i < terrainCellsForTag2.Count; i++) { TerrainCell terrainCell = terrainCellsForTag2[myRandom.RandomRange(0, terrainCellsForTag2.Count)]; if (!terrainCell.node.tags.Contains(WorldGenTags.POI)) { if (!(templateContainer.info.size.Y > terrainCell.poly.MaxY - terrainCell.poly.MinY)) { List <KeyValuePair <Vector2I, TemplateContainer> > list4 = list; Vector2 vector3 = terrainCell.poly.Centroid(); int a2 = (int)vector3.x; Vector2 vector4 = terrainCell.poly.Centroid(); list4.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a2, (int)vector4.y), templateContainer)); terrainCell.node.tags.Add(template.ToTag()); terrainCell.node.tags.Add(WorldGenTags.POI); break; } float num3 = templateContainer.info.size.Y - (terrainCell.poly.MaxY - terrainCell.poly.MinY); float num4 = templateContainer.info.size.X - (terrainCell.poly.MaxX - terrainCell.poly.MinX); if (terrainCell.poly.MaxY + num3 < (float)Grid.HeightInCells && terrainCell.poly.MinY - num3 > 0f && terrainCell.poly.MaxX + num4 < (float)Grid.WidthInCells && terrainCell.poly.MinX - num4 > 0f) { List <KeyValuePair <Vector2I, TemplateContainer> > list5 = list; Vector2 vector5 = terrainCell.poly.Centroid(); int a3 = (int)vector5.x; Vector2 vector6 = terrainCell.poly.Centroid(); list5.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a3, (int)vector6.y), templateContainer)); terrainCell.node.tags.Add(template.ToTag()); terrainCell.node.tags.Add(WorldGenTags.POI); break; } } } } } } } } //// ProcessGeysers(__instance, ref list, myRandom); //// // Generation of geyser Overwrited in the previous line /* * List<TemplateContainer> list6 = TemplateCache.CollectBaseTemplateAssets("features/"); * foreach (SubWorld subWorld2 in WorldGen.Settings.GetSubWorldList()) * { * if (subWorld2.featureTemplates != null && subWorld2.featureTemplates.Count > 0) * { * List<string> list7 = new List<string>(); * foreach (KeyValuePair<string, int> featureTemplate in subWorld2.featureTemplates) * { * for (int j = 0; j < featureTemplate.Value; j++) * { * list7.Add(featureTemplate.Key); * } * } * list7.ShuffleSeeded(myRandom.RandomSource()); * List<TerrainCell> terrainCellsForTag3 = WorldGen.GetTerrainCellsForTag(subWorld2.name.ToTag()); * terrainCellsForTag3.ShuffleSeeded(myRandom.RandomSource()); * foreach (TerrainCell item7 in terrainCellsForTag3) * { * if (list7.Count == 0) * { * break; * } * if (item7.IsSafeToSpawnFeatureTemplate()) * { * string template2 = list7[list7.Count - 1]; * list7.RemoveAt(list7.Count - 1); * TemplateContainer templateContainer2 = list6.Find((TemplateContainer value) => value.name == template2); * if (templateContainer2 != null) * { * List<KeyValuePair<Vector2I, TemplateContainer>> list8 = list; * Vector2 vector7 = item7.poly.Centroid(); * int a4 = (int)vector7.x; * Vector2 vector8 = item7.poly.Centroid(); * list8.Add(new KeyValuePair<Vector2I, TemplateContainer>(new Vector2I(a4, (int)vector8.y), templateContainer2)); * item7.node.tags.Add(template2.ToTag()); * item7.node.tags.Add(WorldGenTags.POI); * } * } * } * } * } */ foreach (int item8 in borderCells) { cells[item8].SetValues(WorldGen.unobtaniumElement, ElementLoader.elements); } if (doSettle) { //this.running = WorldGenSimUtil.DoSettleSim(this.Settings, array, bgTemp, dc, this.successCallbackFn, this.data, list, this.errorCallback, delegate(Sim.Cell[] updatedCells, float[] updatedBGTemp, Sim.DiseaseCell[] updatedDisease) runningF.SetValue(__instance, WorldGenSimUtil.DoSettleSim(__instance.Settings, cells, bgTemp, dc, successCallbackFn, data, list, errorCallback, delegate(Sim.Cell[] updatedCells, float[] updatedBGTemp, Sim.DiseaseCell[] updatedDisease) { //SpawnMobsAndTemplates(updatedCells, updatedBGTemp, updatedDisease, borderCells); SpawnMobsAndTemplatesM.Invoke(__instance, new object[] { updatedCells, updatedBGTemp, updatedDisease, borderCells }); })); } foreach (KeyValuePair <Vector2I, TemplateContainer> item9 in list) { //PlaceTemplateSpawners(item9.Key, item9.Value); PlaceTemplateSpawnersM.Invoke(__instance, new object[] { item9.Key, item9.Value }); } for (int num5 = data.gameSpawnData.buildings.Count - 1; num5 >= 0; num5--) { int item = Grid.XYToCell(data.gameSpawnData.buildings[num5].location_x, data.gameSpawnData.buildings[num5].location_y); if (borderCells.Contains(item)) { data.gameSpawnData.buildings.RemoveAt(num5); } } for (int num6 = data.gameSpawnData.elementalOres.Count - 1; num6 >= 0; num6--) { int item2 = Grid.XYToCell(data.gameSpawnData.elementalOres[num6].location_x, data.gameSpawnData.elementalOres[num6].location_y); if (borderCells.Contains(item2)) { data.gameSpawnData.elementalOres.RemoveAt(num6); } } for (int num7 = data.gameSpawnData.otherEntities.Count - 1; num7 >= 0; num7--) { int item3 = Grid.XYToCell(data.gameSpawnData.otherEntities[num7].location_x, data.gameSpawnData.otherEntities[num7].location_y); if (borderCells.Contains(item3)) { data.gameSpawnData.otherEntities.RemoveAt(num7); } } for (int num8 = data.gameSpawnData.pickupables.Count - 1; num8 >= 0; num8--) { int item4 = Grid.XYToCell(data.gameSpawnData.pickupables[num8].location_x, data.gameSpawnData.pickupables[num8].location_y); if (borderCells.Contains(item4)) { data.gameSpawnData.pickupables.RemoveAt(num8); } } __instance.SaveWorldGen(); successCallbackFn(UI.WORLDGEN.COMPLETE.key, 101f, WorldGenProgressStages.Stages.Complete); //running = false; runningF.SetValue(__instance, false); return(cells); }
public float Get(SeededRandom rnd) { return(rnd.RandomRange(min, max)); }
public static void CalculateGeysers(SeededRandom rnd, WorldGen worldgen) { Dictionary <string, Dictionary <string, int> > calculatedGeysers = new Dictionary <string, Dictionary <string, int> >(); foreach (KeyValuePair <string, GeyserState> data in WorldGenReloadedData.GeyserConfig) { int geyserCount = rnd.RandomRange(data.Value.Minimum, data.Value.Maximum + 1); Debug.Log("geyserCount [" + data.Key + "] = " + geyserCount); if (geyserCount <= 0) { continue; } List <string> _subworlds = new List <string>(data.Value.SubWorlds); // Remove invalid subworlds for (int i = _subworlds.Count - 1; i >= 0; i--) { List <TerrainCell> terrainCellsForTag2 = WorldGen.GetTerrainCellsForTag(_subworlds[i]); for (int num = terrainCellsForTag2.Count - 1; num >= 0; num--) { if (!worldgen.IsSafeToSpawnPOI(terrainCellsForTag2[num])) { terrainCellsForTag2.RemoveAt(num); } } Debug.Log("Available cells [" + _subworlds[i] + "] = " + terrainCellsForTag2.Count); if (terrainCellsForTag2.Count <= 0 || terrainCellsForTag2.Count / geyserCount < 3) { Debug.Log("Invalid subworld: " + _subworlds[i]); _subworlds.RemoveAt(i); } } _subworlds.ShuffleSeeded(rnd.RandomSource()); string[] subworlds = _subworlds.ToArray(); for (int i = 0; i < geyserCount; i++) { string subworld = subworlds[i % subworlds.Length]; if (!calculatedGeysers.ContainsKey(subworld)) { calculatedGeysers[subworld] = new Dictionary <string, int>(); } if (!calculatedGeysers[subworld].ContainsKey(data.Key)) { calculatedGeysers[subworld][data.Key] = 0; } calculatedGeysers[subworld][data.Key]++; } } Debug.Log("Calculated Geysers: "); foreach (KeyValuePair <string, Dictionary <string, int> > subworld in calculatedGeysers) { Debug.Log("Subworld: " + subworld.Key); foreach (KeyValuePair <string, int> geyser in subworld.Value) { Debug.Log("\t" + geyser.Key + " = " + geyser.Value); } } WorldGenReloadedData.CalculatedGeysers = calculatedGeysers; }