예제 #1
0
 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);
                 }
             }
         }
     }
 }
예제 #2
0
        public void Process(WorldGen worldGen, Chunk world, SeededRandom rnd)
        {
            SetValuesFunction setValues = delegate(int index, object elem, Sim.PhysicsData pd, Sim.DiseaseCell dc)
            {
                SimMessages.ModifyCell(index, ElementLoader.GetElementIndex((elem as Element).id), pd.temperature, pd.mass, dc.diseaseIdx, dc.elementCount, SimMessages.ReplaceType.Replace, false, -1);
            };

            DoProcess(worldGen, world, setValues, rnd);
        }
예제 #3
0
        private void DoProcess(WorldGen worldGen, Chunk world, SetValuesFunction SetValues, SeededRandom rnd)
        {
            float min   = 265f;
            float range = 30f;

            InitializeCells();
            GetTemperatureRange(worldGen, ref min, ref range);
            ApplyForeground(worldGen.Settings, world, SetValues, min, range, rnd);
            for (int i = 0; i < node.tags.Count; i++)
            {
                GenerateActionCells(worldGen.Settings, node.tags[i], availableTerrainPoints, rnd);
            }
            ApplyBackground(worldGen, world, SetValues, min, range, rnd);
        }
예제 #4
0
        public void Process(WorldGen worldGen, Sim.Cell[] cells, float[] bgTemp, Sim.DiseaseCell[] dcs, Chunk world, SeededRandom rnd)
        {
            SetValuesFunction setValues = delegate(int index, object elem, Sim.PhysicsData pd, Sim.DiseaseCell dc)
            {
                if (Grid.IsValidCell(index))
                {
                    if (pd.temperature == 0f || (elem as Element).HasTag(GameTags.Special))
                    {
                        bgTemp[index] = -1f;
                    }
                    cells[index].SetValues(elem as Element, pd, ElementLoader.elements);
                    dcs[index] = dc;
                }
                else
                {
                    Debug.LogError("Process::SetValuesFunction Index [" + index + "] is not valid. cells.Length [" + cells.Length + "]");
                }
            };

            DoProcess(worldGen, world, setValues, rnd);
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        private void ApplyPlaceElementForRoom(FeatureSettings feature, string group, List <Vector2I> cells, Chunk world, SetValuesFunction SetValues, float temperatureMin, float temperatureRange, SeededRandom rnd)
        {
            if (cells != null && cells.Count != 0 && feature.HasGroup(group))
            {
                switch (feature.ElementChoiceGroups[group].selectionMethod)
                {
                case ProcGen.Room.Selection.Weighted:
                case ProcGen.Room.Selection.WeightedResample:
                    for (int j = 0; j < cells.Count; j++)
                    {
                        Vector2I vector2I3 = cells[j];
                        int      x2        = vector2I3.x;
                        Vector2I vector2I4 = cells[j];
                        int      num2      = Grid.XYToCell(x2, vector2I4.y);
                        if (Grid.IsValidCell(num2) && !highPriorityClaims.Contains(num2))
                        {
                            WeightedSimHash oneWeightedSimHash2 = feature.GetOneWeightedSimHash(group, rnd);
                            ElementOverride elementOverride2    = GetElementOverride(oneWeightedSimHash2.element, oneWeightedSimHash2.overrides);
                            if (!elementOverride2.overrideTemperature)
                            {
                                elementOverride2.pdelement.temperature = temperatureMin + world.heatOffset[num2] * temperatureRange;
                            }
                            if (!elementOverride2.overrideMass)
                            {
                                elementOverride2.pdelement.mass = GetDensityMassForCell(world, num2, elementOverride2.mass);
                            }
                            SetValues(num2, elementOverride2.element, elementOverride2.pdelement, elementOverride2.dc);
                        }
                    }
                    break;

                default:
                {
                    WeightedSimHash oneWeightedSimHash = feature.GetOneWeightedSimHash(group, rnd);
                    DebugUtil.LogArgs("Picked one: ", oneWeightedSimHash.element);
                    for (int i = 0; i < cells.Count; i++)
                    {
                        Vector2I vector2I  = cells[i];
                        int      x         = vector2I.x;
                        Vector2I vector2I2 = cells[i];
                        int      num       = Grid.XYToCell(x, vector2I2.y);
                        if (Grid.IsValidCell(num) && !highPriorityClaims.Contains(num))
                        {
                            ElementOverride elementOverride = GetElementOverride(oneWeightedSimHash.element, oneWeightedSimHash.overrides);
                            if (!elementOverride.overrideTemperature)
                            {
                                elementOverride.pdelement.temperature = temperatureMin + world.heatOffset[num] * temperatureRange;
                            }
                            if (!elementOverride.overrideMass)
                            {
                                elementOverride.pdelement.mass = GetDensityMassForCell(world, num, elementOverride.mass);
                            }
                            SetValues(num, elementOverride.element, elementOverride.pdelement, elementOverride.dc);
                        }
                    }
                    break;
                }
                }
            }
        }
예제 #7
0
        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);
                        }
                    }
                }
            }
        }