namespace Content.Server.Botany;
-public class MutationSystem : EntitySystem
+public sealed class MutationSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _robustRandom = default!;
/// </summary>
public void MutateSeed(SeedData seed, float severity)
{
+ if (!seed.Unique)
+ {
+ Logger.Error($"Attempted to mutate a shared seed");
+ return;
+ }
+
// Add up everything in the bits column and put the number here.
const int totalbits = 245;
{
SeedData result = b.Clone();
- result.Chemicals = random(0.5f) ? a.Chemicals : result.Chemicals;
+ result.Chemicals = Random(0.5f) ? a.Chemicals : result.Chemicals;
CrossFloat(ref result.NutrientConsumption, a.NutrientConsumption);
CrossFloat(ref result.WaterConsumption, a.WaterConsumption);
CrossBool(ref result.Bioluminescent, a.Bioluminescent);
CrossBool(ref result.TurnIntoKudzu, a.TurnIntoKudzu);
CrossBool(ref result.CanScream, a.CanScream);
- result.BioluminescentColor = random(0.5f) ? a.BioluminescentColor : result.BioluminescentColor;
+ result.BioluminescentColor = Random(0.5f) ? a.BioluminescentColor : result.BioluminescentColor;
// Hybrids have a high chance of being seedless. Balances very
// effective hybrid crossings.
- if (a.Name == result.Name && random(0.7f))
+ if (a.Name == result.Name && Random(0.7f))
{
result.Seedless = true;
}
{
// Probability that a bit flip happens for this value.
float p = mult*bits/totalbits;
- if (!random(p))
+ if (!Random(p))
{
return;
}
// Probability that the bit flip increases n.
float p_increase = 1-(float)n/bits;
int np;
- if (random(p_increase))
+ if (Random(p_increase))
{
np = n + 1;
}
{
// Probability that a bit flip happens for this value.
float p = mult*bits/totalbits;
- if (!random(p))
+ if (!Random(p))
{
return;
}
// Probability that the bit flip increases n.
float p_increase = 1-(float)n/bits;
int np;
- if (random(p_increase))
+ if (Random(p_increase))
{
np = n + 1;
}
{
// Probability that a bit flip happens for this value.
float p = mult*bits/totalbits;
- if (!random(p))
+ if (!Random(p))
{
return;
}
private void MutateHarvestType(ref HarvestType val, int bits, int totalbits, float mult)
{
float p = mult * bits/totalbits;
- if (!random(p))
+ if (!Random(p))
return;
if (val == HarvestType.NoRepeat)
private Color RandomColor(Color color, int bits, int totalbits, float mult)
{
float p = mult*bits/totalbits;
- if (random(p))
+ if (Random(p))
{
var colors = new List<Color>{
Color.White,
private void CrossFloat(ref float val, float other)
{
- val = random(0.5f) ? val : other;
+ val = Random(0.5f) ? val : other;
}
private void CrossInt(ref int val, int other)
{
- val = random(0.5f) ? val : other;
+ val = Random(0.5f) ? val : other;
}
private void CrossBool(ref bool val, bool other)
{
- val = random(0.5f) ? val : other;
+ val = Random(0.5f) ? val : other;
}
- private bool random(float p)
+ private bool Random(float p)
{
return _robustRandom.Prob(p);
}