mirror of
https://gitgud.io/lutepickle/rjw_menstruation.git
synced 2024-08-14 22:46:52 +00:00
Enzygotic twins get the same inherited traits
This commit is contained in:
parent
8013481634
commit
531313f5d2
2 changed files with 106 additions and 96 deletions
Binary file not shown.
|
@ -176,6 +176,101 @@ namespace RJW_Menstruation
|
||||||
//baby.story.birthLastName = last_name;
|
//baby.story.birthLastName = last_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// From RJW's trait code
|
||||||
|
protected List<Trait> GetInheritableTraits(Pawn mother, Pawn father)
|
||||||
|
{
|
||||||
|
List<Trait> traitpool = new List<Trait>();
|
||||||
|
List<Trait> momtraits = new List<Trait>();
|
||||||
|
List<Trait> poptraits = new List<Trait>();
|
||||||
|
List<Trait> traits_to_inherit = new List<Trait>();
|
||||||
|
System.Random rd = new System.Random();
|
||||||
|
int rand_trait_index = 0;
|
||||||
|
float max_num_momtraits_inherited = RJWPregnancySettings.max_num_momtraits_inherited;
|
||||||
|
float max_num_poptraits_inherited = RJWPregnancySettings.max_num_poptraits_inherited;
|
||||||
|
float max_num_traits_inherited = max_num_momtraits_inherited + max_num_poptraits_inherited;
|
||||||
|
int i = 1;
|
||||||
|
int j = 1;
|
||||||
|
if (xxx.has_traits(mother) && mother.RaceProps.Humanlike)
|
||||||
|
{
|
||||||
|
foreach (Trait momtrait in mother.story.traits.allTraits)
|
||||||
|
{
|
||||||
|
if (!non_genetic_traits.Contains(momtrait.def.defName) && !momtrait.ScenForced)
|
||||||
|
momtraits.Add(momtrait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (father != null && xxx.has_traits(father) && father.RaceProps.Humanlike)
|
||||||
|
{
|
||||||
|
foreach (Trait poptrait in father.story.traits.allTraits)
|
||||||
|
{
|
||||||
|
if (!non_genetic_traits.Contains(poptrait.def.defName) && !poptrait.ScenForced)
|
||||||
|
poptraits.Add(poptrait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!momtraits.NullOrEmpty())
|
||||||
|
{
|
||||||
|
i = 1;
|
||||||
|
while (momtraits.Count > 0 && i <= max_num_momtraits_inherited)
|
||||||
|
{
|
||||||
|
rand_trait_index = rd.Next(0, momtraits.Count);
|
||||||
|
traits_to_inherit.Add(momtraits[rand_trait_index]);
|
||||||
|
momtraits.RemoveAt(rand_trait_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!poptraits.NullOrEmpty())
|
||||||
|
{
|
||||||
|
j = 1;
|
||||||
|
while (poptraits.Count > 0 && j <= max_num_poptraits_inherited)
|
||||||
|
{
|
||||||
|
rand_trait_index = rd.Next(0, poptraits.Count);
|
||||||
|
traits_to_inherit.Add(poptraits[rand_trait_index]);
|
||||||
|
poptraits.RemoveAt(rand_trait_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (poptraits.NullOrEmpty() || momtraits.NullOrEmpty())
|
||||||
|
{
|
||||||
|
foreach (Trait traits in traits_to_inherit)
|
||||||
|
{
|
||||||
|
traitpool.Add(traits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (traits_to_inherit.Count() != max_num_traits_inherited)
|
||||||
|
{
|
||||||
|
if (momtraits.Count != 0 && i != max_num_momtraits_inherited)
|
||||||
|
{
|
||||||
|
while (poptraits != null && momtraits.Count() > 0 && i <= max_num_momtraits_inherited)
|
||||||
|
{
|
||||||
|
rand_trait_index = rd.Next(0, momtraits.Count);
|
||||||
|
if (!traits_to_inherit.Contains(momtraits[rand_trait_index]))
|
||||||
|
{
|
||||||
|
traits_to_inherit.Add(momtraits[rand_trait_index]);
|
||||||
|
}
|
||||||
|
momtraits.RemoveAt(rand_trait_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (poptraits != null && poptraits.Count != 0 && j != max_num_poptraits_inherited)
|
||||||
|
{
|
||||||
|
while (poptraits.Count > 0 && i < max_num_poptraits_inherited)
|
||||||
|
{
|
||||||
|
rand_trait_index = rd.Next(0, poptraits.Count);
|
||||||
|
if (!traits_to_inherit.Contains(poptraits[rand_trait_index]))
|
||||||
|
{
|
||||||
|
traits_to_inherit.Add(poptraits[rand_trait_index]);
|
||||||
|
}
|
||||||
|
poptraits.RemoveAt(rand_trait_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (Trait traits in traits_to_inherit)
|
||||||
|
{
|
||||||
|
traitpool.Add(traits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return traitpool;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void GenerateBabies()
|
protected override void GenerateBabies()
|
||||||
{
|
{
|
||||||
AddNewBaby(pawn, father);
|
AddNewBaby(pawn, father);
|
||||||
|
@ -253,10 +348,12 @@ namespace RJW_Menstruation
|
||||||
CrownType firstcrown = CrownType.Undefined;
|
CrownType firstcrown = CrownType.Undefined;
|
||||||
string firstheadpath = null;
|
string firstheadpath = null;
|
||||||
string firstHARcrown = null;
|
string firstHARcrown = null;
|
||||||
|
int traitSeed = Rand.Int;
|
||||||
|
List <Trait> parentTraits = GetInheritableTraits(mother, father);
|
||||||
while (Rand.Chance(Configurations.EnzygoticTwinsChance) && division < Configurations.MaxEnzygoticTwins) division++;
|
while (Rand.Chance(Configurations.EnzygoticTwinsChance) && division < Configurations.MaxEnzygoticTwins) division++;
|
||||||
for (int i = 0; i < division; i++)
|
for (int i = 0; i < division; i++)
|
||||||
{
|
{
|
||||||
Pawn baby = GenerateBaby(request, mother, father);
|
Pawn baby = GenerateBaby(request, mother, father, parentTraits, traitSeed);
|
||||||
if (division > 1)
|
if (division > 1)
|
||||||
{
|
{
|
||||||
if (i == 0 && baby.story != null)
|
if (i == 0 && baby.story != null)
|
||||||
|
@ -307,7 +404,7 @@ namespace RJW_Menstruation
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pawn GenerateBaby(PawnGenerationRequest request, Pawn mother, Pawn father)
|
public Pawn GenerateBaby(PawnGenerationRequest request, Pawn mother, Pawn father, List<Trait> parentTraits, int traitSeed)
|
||||||
{
|
{
|
||||||
Pawn baby = PawnGenerator.GeneratePawn(request);
|
Pawn baby = PawnGenerator.GeneratePawn(request);
|
||||||
if (baby != null)
|
if (baby != null)
|
||||||
|
@ -324,99 +421,11 @@ namespace RJW_Menstruation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// re-use the trait code from base RJW's rjw.Hediff_BasePregnancy.GenerateBabies()
|
// Ensure the same inherited traits are chosen each run
|
||||||
List<Trait> traitpool = new List<Trait>();
|
// Has to happen right here so GeneratePawn up there still gets unique results
|
||||||
List<Trait> momtraits = new List<Trait>();
|
Rand.PushState(traitSeed); // With a seed just to make sure that fraternal twins *don't* get trait-duped
|
||||||
List<Trait> poptraits = new List<Trait>();
|
updateTraits(baby, parentTraits);
|
||||||
List<Trait> traits_to_inherit = new List<Trait>();
|
Rand.PopState();
|
||||||
System.Random rd = new System.Random();
|
|
||||||
int rand_trait_index = 0;
|
|
||||||
float max_num_momtraits_inherited = RJWPregnancySettings.max_num_momtraits_inherited;
|
|
||||||
float max_num_poptraits_inherited = RJWPregnancySettings.max_num_poptraits_inherited;
|
|
||||||
float max_num_traits_inherited = max_num_momtraits_inherited + max_num_poptraits_inherited;
|
|
||||||
int i = 1;
|
|
||||||
int j = 1;
|
|
||||||
if (xxx.has_traits(pawn) && pawn.RaceProps.Humanlike)
|
|
||||||
{
|
|
||||||
foreach (Trait momtrait in pawn.story.traits.allTraits)
|
|
||||||
{
|
|
||||||
if(!non_genetic_traits.Contains(momtrait.def.defName) && !momtrait.ScenForced)
|
|
||||||
momtraits.Add(momtrait);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (father != null && xxx.has_traits(father) && father.RaceProps.Humanlike)
|
|
||||||
{
|
|
||||||
foreach (Trait poptrait in father.story.traits.allTraits)
|
|
||||||
{
|
|
||||||
if(!non_genetic_traits.Contains(poptrait.def.defName) && !poptrait.ScenForced)
|
|
||||||
poptraits.Add(poptrait);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!momtraits.NullOrEmpty())
|
|
||||||
{
|
|
||||||
i = 1;
|
|
||||||
while (momtraits.Count > 0 && i <= max_num_momtraits_inherited)
|
|
||||||
{
|
|
||||||
rand_trait_index = rd.Next(0, momtraits.Count);
|
|
||||||
traits_to_inherit.Add(momtraits[rand_trait_index]);
|
|
||||||
momtraits.RemoveAt(rand_trait_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!poptraits.NullOrEmpty())
|
|
||||||
{
|
|
||||||
j = 1;
|
|
||||||
while (poptraits.Count > 0 && j <= max_num_poptraits_inherited)
|
|
||||||
{
|
|
||||||
rand_trait_index = rd.Next(0, poptraits.Count);
|
|
||||||
traits_to_inherit.Add(poptraits[rand_trait_index]);
|
|
||||||
poptraits.RemoveAt(rand_trait_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(poptraits.NullOrEmpty() || momtraits.NullOrEmpty())
|
|
||||||
{
|
|
||||||
foreach(Trait traits in traits_to_inherit)
|
|
||||||
{
|
|
||||||
traitpool.Add(traits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (traits_to_inherit.Count() != max_num_traits_inherited)
|
|
||||||
{
|
|
||||||
if (momtraits.Count != 0 && i != max_num_momtraits_inherited)
|
|
||||||
{
|
|
||||||
while (poptraits != null && momtraits.Count() > 0 && i <= max_num_momtraits_inherited)
|
|
||||||
{
|
|
||||||
rand_trait_index = rd.Next(0, momtraits.Count);
|
|
||||||
if (!traits_to_inherit.Contains(momtraits[rand_trait_index]))
|
|
||||||
{
|
|
||||||
traits_to_inherit.Add(momtraits[rand_trait_index]);
|
|
||||||
}
|
|
||||||
momtraits.RemoveAt(rand_trait_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (poptraits != null && poptraits.Count != 0 && j != max_num_poptraits_inherited)
|
|
||||||
{
|
|
||||||
while (poptraits.Count > 0 && i < max_num_poptraits_inherited)
|
|
||||||
{
|
|
||||||
rand_trait_index = rd.Next(0, poptraits.Count);
|
|
||||||
if (!traits_to_inherit.Contains(poptraits[rand_trait_index]))
|
|
||||||
{
|
|
||||||
traits_to_inherit.Add(poptraits[rand_trait_index]);
|
|
||||||
}
|
|
||||||
poptraits.RemoveAt(rand_trait_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (Trait traits in traits_to_inherit)
|
|
||||||
{
|
|
||||||
traitpool.Add(traits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTraits(baby, traitpool);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (baby.relations != null)
|
else if (baby.relations != null)
|
||||||
{
|
{
|
||||||
|
@ -606,6 +615,7 @@ namespace RJW_Menstruation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pawn"></param>
|
/// <param name="pawn"></param>
|
||||||
/// <param name="parenttraits"></param>
|
/// <param name="parenttraits"></param>
|
||||||
|
///
|
||||||
public void updateTraits(Pawn pawn, List<Trait> parenttraits)
|
public void updateTraits(Pawn pawn, List<Trait> parenttraits)
|
||||||
{
|
{
|
||||||
if (pawn?.story?.traits == null) return;
|
if (pawn?.story?.traits == null) return;
|
||||||
|
@ -623,9 +633,9 @@ namespace RJW_Menstruation
|
||||||
res.AddRange(forcedTraits);
|
res.AddRange(forcedTraits);
|
||||||
|
|
||||||
var comparer = new TraitComparer(); // trait comparision implementation, because without game compares traits *by reference*, makeing them all unique.
|
var comparer = new TraitComparer(); // trait comparision implementation, because without game compares traits *by reference*, makeing them all unique.
|
||||||
|
|
||||||
while (res.Count < traitlist.Count && traitlist.Count > 0)
|
while (res.Count < traitlist.Count && traitlist.Count > 0)
|
||||||
{
|
{
|
||||||
|
// Has to be the only use of Rand in the function for the push/pop trick to work right
|
||||||
int index = Rand.Range(0, traitlist.Count); // getting trait and removing from the pull
|
int index = Rand.Range(0, traitlist.Count); // getting trait and removing from the pull
|
||||||
var trait = traitlist[index];
|
var trait = traitlist[index];
|
||||||
traitlist.RemoveAt(index);
|
traitlist.RemoveAt(index);
|
||||||
|
|
Loading…
Reference in a new issue