From c9b7cfd868ee1ef464ccae8de80cab8975f86e8a Mon Sep 17 00:00:00 2001 From: RedBurningPhoenix <147742474+RedBurningPhoenix@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:16:00 +0500 Subject: [PATCH] Botany produce fix (#622) https://github.com/space-wizards/space-station-14/pull/27210 --- .../Botany/Systems/MutationSystem.cs | 28 +++++++++++++++---- .../Botany/Systems/PlantHolderSystem.cs | 4 +-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Content.Server/Botany/Systems/MutationSystem.cs b/Content.Server/Botany/Systems/MutationSystem.cs index c7ce5d47ef..946ab2579b 100644 --- a/Content.Server/Botany/Systems/MutationSystem.cs +++ b/Content.Server/Botany/Systems/MutationSystem.cs @@ -40,7 +40,7 @@ public sealed class MutationSystem : EntitySystem } // Add up everything in the bits column and put the number here. - const int totalbits = 275; + const int totalbits = 270; // Tolerances (55) MutateFloat(ref seed.NutrientConsumption , 0.05f, 1.2f, 5, totalbits, severity); @@ -66,7 +66,7 @@ public sealed class MutationSystem : EntitySystem // Kill the plant (30) MutateBool(ref seed.Viable , false, 30, totalbits, severity); - // Fun (90) + // Fun (80) MutateBool(ref seed.Seedless , true , 10, totalbits, severity); MutateBool(ref seed.Slip , true , 10, totalbits, severity); MutateBool(ref seed.Sentient , true , 10, totalbits, severity); @@ -153,6 +153,12 @@ public sealed class MutationSystem : EntitySystem if (!Random(probBitflip)) return; + if (min == max) + { + val = min; + return; + } + // Starting number of bits that are high, between 0 and bits. // In other words, it's val mapped linearly from range [min, max] to range [0, bits], and then rounded. int valInt = (int)MathF.Round((val - min) / (max - min) * bits); @@ -186,10 +192,22 @@ public sealed class MutationSystem : EntitySystem if (!Random(probBitflip)) return; + if (min == max) + { + val = min; + return; + } + + // Starting number of bits that are high, between 0 and bits. + // In other words, it's val mapped linearly from range [min, max] to range [0, bits], and then rounded. + int valInt = (int)MathF.Round((val - min) / (max - min) * bits); + // val may be outside the range of min/max due to starting prototype values, so clamp. + valInt = Math.Clamp(valInt, 0, bits); + // Probability that the bit flip increases n. - // The higher the current value is, the lower the probability of increasing value is, and the higher the probability of decreasive it it. + // The higher the current value is, the lower the probability of increasing value is, and the higher the probability of decreasing it. // In other words, it tends to go to the middle. - float probIncrease = 1 - (float)val / bits; + float probIncrease = 1 - (float)valInt / bits; int valMutated; if (Random(probIncrease)) { @@ -274,7 +292,7 @@ public sealed class MutationSystem : EntitySystem seedChemQuantity.Max = 1 + amount; seedChemQuantity.Inherent = false; } - int potencyDivisor = (int) Math.Ceiling(100.0f / seedChemQuantity.Max); + int potencyDivisor = (int)Math.Ceiling(100.0f / seedChemQuantity.Max); seedChemQuantity.PotencyDivisor = potencyDivisor; chemicals[chemicalId] = seedChemQuantity; } diff --git a/Content.Server/Botany/Systems/PlantHolderSystem.cs b/Content.Server/Botany/Systems/PlantHolderSystem.cs index 7b7c7c85d4..855c70971c 100644 --- a/Content.Server/Botany/Systems/PlantHolderSystem.cs +++ b/Content.Server/Botany/Systems/PlantHolderSystem.cs @@ -518,10 +518,10 @@ public sealed class PlantHolderSystem : EntitySystem var environment = _atmosphere.GetContainingMixture(uid, true, true) ?? GasMixture.SpaceGas; + component.MissingGas = 0; + if (component.Seed.ConsumeGasses.Count > 0) { - component.MissingGas = 0; - foreach (var (gas, amount) in component.Seed.ConsumeGasses) { if (environment.GetMoles(gas) < amount)