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 void ApplyForeground(WorldGenSettings settings, Chunk world, SetValuesFunction SetValues, float temperatureMin, float temperatureRange, SeededRandom rnd) { LogInfo("Apply foregreound", (node.tags != null).ToString(), (float)((node.tags != null) ? node.tags.Count : 0)); if (node.tags != null) { FeatureSettings featureSettings = settings.TryGetFeature(node.type); LogInfo("\tFeature?", (featureSettings != null).ToString(), 0f); if (featureSettings == null && node.tags != null) { List <Tag> list = new List <Tag>(); foreach (Tag tag2 in node.tags) { if (settings.HasFeature(tag2.Name)) { list.Add(tag2); } } LogInfo("\tNo feature, checking possible feature tags, found", string.Empty, (float)list.Count); if (list.Count > 0) { Tag tag = list[rnd.RandomSource().Next(list.Count)]; featureSettings = settings.GetFeature(tag.Name); LogInfo("\tPicked feature", tag.Name, 0f); } } if (featureSettings != null) { LogInfo("APPLY FOREGROUND", node.type, 0f); float num = featureSettings.blobSize.GetRandomValueWithinRange(rnd); float num2 = poly.DistanceToClosestEdge(null); if (!node.tags.Contains(WorldGenTags.AllowExceedNodeBorders) && num2 < num) { if (debugMode) { Debug.LogWarning(node.type + " " + featureSettings.shape + " blob size too large to fit in node. Size reduced. " + num + "->" + (num2 - 6f).ToString()); } num = num2 - 6f; } if (!(num <= 0f)) { featureSpawnPoints = DigFeature(featureSettings.shape, num, featureSettings.borders, rnd, out List <Vector2I> featureCenterPoints, out List <List <Vector2I> > featureBorders); LogInfo("\t\t", "claimed points", (float)featureSpawnPoints.Count); availableTerrainPoints.ExceptWith(featureSpawnPoints); ApplyPlaceElementForRoom(featureSettings, "RoomCenterElements", featureCenterPoints, world, SetValues, temperatureMin, temperatureRange, rnd); if (featureBorders != null) { for (int i = 0; i < featureBorders.Count; i++) { ApplyPlaceElementForRoom(featureSettings, "RoomBorderChoices" + i, featureBorders[i], world, SetValues, temperatureMin, temperatureRange, rnd); } } if (featureSettings.tags.Contains(WorldGenTags.HighPriorityFeature.Name)) { AddHighPriorityCells(featureSpawnPoints); } } } } }
public static Dictionary <int, string> PlaceFeatureAmbientMobs(WorldGenSettings settings, TerrainCell tc, SeededRandom rnd, Sim.Cell[] cells, float[] bgTemp, Sim.DiseaseCell[] dc, HashSet <int> avoidCells, bool isDebug) { Dictionary <int, string> spawnedMobs = new Dictionary <int, string>(); Node node = tc.node; HashSet <int> alreadyOccupiedCells = new HashSet <int>(); FeatureSettings featureSettings = null; foreach (Tag featureSpecificTag in node.featureSpecificTags) { if (settings.HasFeature(featureSpecificTag.Name)) { featureSettings = settings.GetFeature(featureSpecificTag.Name); break; } } if (featureSettings == null) { return(spawnedMobs); } if (featureSettings.internalMobs == null || featureSettings.internalMobs.Count == 0) { return(spawnedMobs); } List <int> availableSpawnCellsFeature = tc.GetAvailableSpawnCellsFeature(); tc.LogInfo("PlaceFeatureAmbientMobs", "possibleSpawnPoints", (float)availableSpawnCellsFeature.Count); for (int num = availableSpawnCellsFeature.Count - 1; num > 0; num--) { int num2 = availableSpawnCellsFeature[num]; if (ElementLoader.elements[cells[num2].elementIdx].id == SimHashes.Katairite || ElementLoader.elements[cells[num2].elementIdx].id == SimHashes.Unobtanium || avoidCells.Contains(num2)) { availableSpawnCellsFeature.RemoveAt(num); } } tc.LogInfo("mob spawns", "Id:" + node.node.Id + " possible cells", (float)availableSpawnCellsFeature.Count); if (availableSpawnCellsFeature.Count == 0) { if (isDebug) { Debug.LogWarning("No where to put mobs possibleSpawnPoints [" + tc.node.node.Id + "]"); } return(null); } foreach (MobReference internalMob in featureSettings.internalMobs) { Mob mob = settings.GetMob(internalMob.type); if (mob == null) { Debug.LogError("Missing mob description for internal mob [" + internalMob.type + "]"); } else { List <int> mobPossibleSpawnPoints = GetMobPossibleSpawnPoints(mob, availableSpawnCellsFeature, cells, alreadyOccupiedCells, rnd); if (mobPossibleSpawnPoints.Count == 0) { if (!isDebug) { continue; } } else { tc.LogInfo("\t\tpossible", internalMob.type + " mps: " + mobPossibleSpawnPoints.Count + " ps:", (float)availableSpawnCellsFeature.Count); int num3 = Mathf.RoundToInt(internalMob.count.GetRandomValueWithinRange(rnd)); tc.LogInfo("\t\tcount", internalMob.type, (float)num3); Tag mobPrefab = (mob.prefabName != null) ? new Tag(mob.prefabName) : new Tag(internalMob.type); SpawnCountMobs(mob, mobPrefab, num3, mobPossibleSpawnPoints, tc, ref spawnedMobs, ref alreadyOccupiedCells); } } } return(spawnedMobs); }