/// <summary> /// Returns the "satisfation" the given floral would have at the given temperature and humidity. /// Floral prefers to be in the center of its "satisfaction" range, and balances most factors. /// </summary> /// <param name="entry">The floral to check</param> /// <param name="temperature">The temperature to check</param> /// <param name="humidity">The humidity to check</param> /// /// <param name="height">The height to check</param> /// <returns></returns> private double FloralSatisfaction(FloralEntry entry, double temperature, double humidity, int height) { double temperatureSatisfaction = (temperature - entry.TemperatureRange.X) / (entry.TemperatureRange.Y - entry.TemperatureRange.X); if (temperatureSatisfaction >= 0.5f) { temperatureSatisfaction = 1 - temperatureSatisfaction; } double humiditySatisfaction = (humidity - entry.HumidityRange.X) / (entry.HumidityRange.Y - entry.HumidityRange.X); if (humiditySatisfaction >= 0.5f) { humiditySatisfaction = 1 - humiditySatisfaction; } double heightSatisfaction = (height - entry.HeightRange.X) / (entry.HeightRange.Y - entry.HeightRange.X); if (heightSatisfaction >= 0.5f) { heightSatisfaction = 1 - heightSatisfaction; } return((temperatureSatisfaction + humiditySatisfaction + heightSatisfaction) / 1.5); }
private bool GetFloral(Block blockBelow, double temperature, double humidity, int y, System.Random rng, out Block floral) { List <(FloralEntry, float)> canSpawn = new List <(FloralEntry, float)>(); for (int i = 0; i < PotentialFloral.Length; i++) { FloralEntry potentialFloral = PotentialFloral[i]; if (RangeContains(potentialFloral.TemperatureRange, temperature) && RangeContains(potentialFloral.HumidityRange, humidity) && RangeContains(potentialFloral.HeightRange, y) && potentialFloral.Floral.CanGrowOn(blockBelow)) { canSpawn.Add((potentialFloral, (float)FloralSatisfaction(potentialFloral, temperature, humidity, y))); } } if (canSpawn.Count == 0) { floral = null; return(false); } (FloralEntry choosenFlora, float satisfaction) = canSpawn[rng.Next(0, canSpawn.Count)]; float spawnChance = choosenFlora.SpawnChance * satisfaction; if (spawnChance >= 1) { floral = choosenFlora.Floral; return(true); } else if (rng.NextDouble() <= spawnChance) { floral = choosenFlora.Floral; return(true); } floral = null; return(false); }