]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix botany bugs (#27210)
authorCrotalus <Crotalus@users.noreply.github.com>
Sun, 18 Aug 2024 01:05:26 +0000 (03:05 +0200)
committerGitHub <noreply@github.com>
Sun, 18 Aug 2024 01:05:26 +0000 (03:05 +0200)
* Fixed bug with missing gas not getting reset

* Fix bug with MutateInt not using min/max in prob calculation

* Add divison by zero check

* Fix styling

Content.Server/Botany/Systems/MutationSystem.cs
Content.Server/Botany/Systems/PlantHolderSystem.cs

index c9272375102691b47564e928568a9b3f1828add0..d3159655f541d87d1595341a98426df58e4de5ad 100644 (file)
@@ -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))
         {
index 255ab00c7aad8a3a543795938c8a98b97584e8ec..21117b94bab2f4269642d2c17b31b455177c98f2 100644 (file)
@@ -522,10 +522,9 @@ 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)