Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ArkBreedingPseudoCode
- {
- public enum Gender { Female, Male }
- public class PrimalDinoCharacter
- {
- /// <summary>
- /// Stat levels (0: health, 1: stamina, 2: torpor, 3: oxygen, 4: food, 5: water, 6: temperature, 7: weight, 8: melee damage, 9: movement speed, 10: fortitude, 11: crafting speed)
- /// </summary>
- public int[] NumberOfLevelUpPointsApplied { get; set; }
- public int[] ColorSetIndices { get; set; }
- public int RandomMutationsMale { get; set; }
- public int RandomMutationsFemale { get; set; }
- public Gender Gender { get; set; }
- // Creature specific defines
- public bool[] CanLevelUpValue { get; set; }
- public bool[] DontUseValue { get; set; }
- public int RandomMutationRolls { get; set; }
- public float RandomMutationChance { get; set; }
- public float RandomMutationGivePoints { get; set; }
- public bool[] PreventColorizationRegions { get; set; }
- // Game specific defines
- public int RandomMutationCountLimit { get; set; }
- public PrimalDinoCharacter()
- {
- // Setup default values
- ColorSetIndices = new int[6];
- NumberOfLevelUpPointsApplied = new int[12];
- // Species settings (these may vary with different species)
- CanLevelUpValue = new[] { true, true, false, true, true, false, false, true, true, true, false, false };
- DontUseValue = new[] { false, false, false, false, false, false, false, false, false, false, false, false };
- PreventColorizationRegions = new[] { false, false, false, false, false, false };
- RandomMutationRolls = 3; //currently 3 for all species
- RandomMutationChance = 0.025f; //currently 0.025 for all species
- RandomMutationGivePoints = 2.0f; //currently +2 for all species
- // Game settings
- RandomMutationCountLimit = 20;
- }
- private Random _random = new Random();
- /// <summary>
- /// Generates a random floating-point number that is greater than or equal to 0.0, and less than 1.0.
- /// </summary>
- /// <remarks>ARK uses std::rand</remarks>
- private double NewRandom()
- {
- return _random.NextDouble();
- }
- /// <summary>
- /// Generates a random bounded integer.
- /// </summary>
- /// <remarks>ARK uses PCG_Random</remarks>
- private int NewBoundedRandom(int bound)
- {
- return _random.Next(0, bound);
- }
- /// <summary>
- /// Simulate when two ARK Creatures are mated
- /// </summary>
- public PrimalDinoCharacter DoMate(PrimalDinoCharacter withMate)
- {
- if (this.Gender == withMate.Gender) return null;
- var randomMutationCount = this.RandomMutationsMale + this.RandomMutationsFemale;
- var randomMutationCountMate = withMate.RandomMutationsMale + withMate.RandomMutationsFemale;
- var offspring = new PrimalDinoCharacter
- {
- RandomMutationsFemale = this.Gender == Gender.Female ? randomMutationCount : randomMutationCountMate,
- RandomMutationsMale = this.Gender == Gender.Male ? randomMutationCount : randomMutationCountMate
- };
- // Inherited colors (there is a 50/50 chance the color is inherited from each respective parent)
- for (var i = 0; i < 6; i++)
- {
- offspring.ColorSetIndices[i] = NewRandom() <= 0.5 ? withMate.ColorSetIndices[i] : this.ColorSetIndices[i];
- }
- // Inherited stats (there is a 55/45 chance to inherit the best stat)
- var mutatableStatIndices = new List<int>();
- for (var i = 0; i < 12; i++)
- {
- var chanceToInheritStat = this.NumberOfLevelUpPointsApplied[i] <= withMate.NumberOfLevelUpPointsApplied[i]
- ? 0.55000001f : 0.44999999f;
- offspring.NumberOfLevelUpPointsApplied[i] = NewRandom() <= chanceToInheritStat
- ? withMate.NumberOfLevelUpPointsApplied[i] : this.NumberOfLevelUpPointsApplied[i];
- if (this.CanLevelUpValue[i] && !this.DontUseValue[i]) mutatableStatIndices.Add(i);
- }
- // Random mutations
- if (mutatableStatIndices.Count > 0)
- {
- for (var i = 0; i < this.RandomMutationRolls; i++)
- {
- // A random stat is selected
- var randomStatIndex = mutatableStatIndices[NewBoundedRandom(mutatableStatIndices.Count)];
- // Mutation is tied to one parent (there is a 55/45 chance for it to be the parent with the best stat)
- var chanceForParent = this.NumberOfLevelUpPointsApplied[randomStatIndex] <= withMate.NumberOfLevelUpPointsApplied[randomStatIndex]
- ? 0.55000001f : 0.44999999f;
- var randomParentRoll = NewRandom();
- var randomMutationIsFromMate = randomParentRoll <= chanceForParent;
- // If the selected parent have exceeded the random mutation limit skip this roll
- if ((randomMutationIsFromMate ? randomMutationCountMate : randomMutationCount) >= this.RandomMutationCountLimit)
- continue;
- // Roll for a random mutation to this stat
- if (NewRandom() >= this.RandomMutationChance)
- continue;
- var newStatValue = offspring.NumberOfLevelUpPointsApplied[randomStatIndex] + this.RandomMutationGivePoints;
- // All stats are limited to 255
- if (newStatValue > 255.0)
- continue;
- // Update offspring
- offspring.NumberOfLevelUpPointsApplied[randomStatIndex] = (int)Math.Floor(newStatValue);
- if ((randomMutationIsFromMate ? withMate : this).Gender == Gender.Male) offspring.RandomMutationsMale++;
- else offspring.RandomMutationsFemale++;
- // Random color mutation code simplified (may not be perfectly accurate):
- // 1. Make sure the species have customizable colors
- // 2. Create an array with all color regions that are not disallowed (->PreventColorizationRegions)
- // 3. Roll a random color from the available ones
- // 4. Roll a random color index from the available ones
- var colors = 56;
- var colorIndices = Enumerable.Range(0, 6).Select(x => this.PreventColorizationRegions[i] ? null : (int?)x).Where(x => x.HasValue).Select(x => x.Value).ToArray();
- var randomColor = NewBoundedRandom(colors) + 1;
- var randomColorIndex = colorIndices[NewBoundedRandom(colorIndices.Length)];
- offspring.ColorSetIndices[randomColorIndex] = randomColor;
- }
- }
- return offspring;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement