Properly generate babies with mismatched pawn def and pawnkind

This commit is contained in:
lutepickle 2022-07-17 22:55:28 -07:00
parent f89bdaad46
commit 76c2a67390
2 changed files with 30 additions and 16 deletions

View file

@ -451,6 +451,16 @@ namespace RJW_Menstruation
return baby; return baby;
} }
public PawnKindDef GetRacesPawnKind(Pawn pawn)
{
if (pawn == null) return null;
if (pawn.kindDef?.race == pawn.def) return pawn.kindDef;
return VariousDefOf.AllKinds.Find(kind => kind.race == pawn.def && kind.defName.Contains("Colonist")) ??
VariousDefOf.AllKinds.Find(kind => kind.race == pawn.def) ??
pawn.def.race?.AnyPawnKind ??
pawn.kindDef;
}
/// <summary> /// <summary>
/// Decide pawnkind from mother and father <para/> /// Decide pawnkind from mother and father <para/>
/// Come from RJW /// Come from RJW
@ -460,7 +470,10 @@ namespace RJW_Menstruation
/// <returns></returns> /// <returns></returns>
public PawnKindDef BabyPawnKindDecider(Pawn mother, Pawn father) public PawnKindDef BabyPawnKindDecider(Pawn mother, Pawn father)
{ {
PawnKindDef spawn_kind_def = mother.kindDef; PawnKindDef motherKindDef = GetRacesPawnKind(mother);
PawnKindDef fatherKindDef = GetRacesPawnKind(father);
PawnKindDef spawn_kind_def = motherKindDef;
int flag = 0; int flag = 0;
if (xxx.is_human(mother)) flag += 2; if (xxx.is_human(mother)) flag += 2;
@ -474,18 +487,18 @@ namespace RJW_Menstruation
switch (flag) switch (flag)
{ {
case 3: case 3:
if (!Rand.Chance(RJWPregnancySettings.humanlike_DNA_from_mother)) spawn_kind_def = father.kindDef; if (!Rand.Chance(RJWPregnancySettings.humanlike_DNA_from_mother)) spawn_kind_def = fatherKindDef;
break; break;
case 2: case 2:
if (RJWPregnancySettings.bestiality_DNA_inheritance == 0f) spawn_kind_def = father.kindDef; if (RJWPregnancySettings.bestiality_DNA_inheritance == 0f) spawn_kind_def = fatherKindDef;
else if (!Rand.Chance(RJWPregnancySettings.bestial_DNA_from_mother)) spawn_kind_def = father.kindDef; else if (!Rand.Chance(RJWPregnancySettings.bestial_DNA_from_mother)) spawn_kind_def = fatherKindDef;
break; break;
case 1: case 1:
if (RJWPregnancySettings.bestiality_DNA_inheritance == 1f) spawn_kind_def = father.kindDef; if (RJWPregnancySettings.bestiality_DNA_inheritance == 1f) spawn_kind_def = fatherKindDef;
else if (!Rand.Chance(RJWPregnancySettings.bestial_DNA_from_mother)) spawn_kind_def = father.kindDef; else if (!Rand.Chance(RJWPregnancySettings.bestial_DNA_from_mother)) spawn_kind_def = fatherKindDef;
break; break;
case 0: case 0:
if (!Rand.Chance(RJWPregnancySettings.bestial_DNA_from_mother)) spawn_kind_def = father.kindDef; if (!Rand.Chance(RJWPregnancySettings.bestial_DNA_from_mother)) spawn_kind_def = fatherKindDef;
break; break;
} }
@ -493,19 +506,19 @@ namespace RJW_Menstruation
bool IsAndroidfather = AndroidsCompatibility.IsAndroid(father); bool IsAndroidfather = AndroidsCompatibility.IsAndroid(father);
if (IsAndroidmother && !IsAndroidfather) if (IsAndroidmother && !IsAndroidfather)
{ {
spawn_kind_def = father.kindDef; spawn_kind_def = fatherKindDef;
} }
else if (!IsAndroidmother && IsAndroidfather) else if (!IsAndroidmother && IsAndroidfather)
{ {
spawn_kind_def = mother.kindDef; spawn_kind_def = motherKindDef;
} }
string MotherRaceName = ""; string MotherRaceName = "";
string FatherRaceName = ""; string FatherRaceName = "";
MotherRaceName = mother.kindDef?.race?.defName; MotherRaceName = motherKindDef?.race?.defName;
PawnKindDef non_hybrid_kind_def = spawn_kind_def; PawnKindDef non_hybrid_kind_def = spawn_kind_def;
if (father != null) if (father != null)
FatherRaceName = father.kindDef?.race?.defName; FatherRaceName = fatherKindDef?.race?.defName;
if (FatherRaceName != "" && Configurations.UseHybridExtention) if (FatherRaceName != "" && Configurations.UseHybridExtention)
@ -530,9 +543,9 @@ namespace RJW_Menstruation
{ {
//ModLog.Message(" has hybridRaceParents"); //ModLog.Message(" has hybridRaceParents");
if (t.hybridChildKindDef.Contains("MotherKindDef")) if (t.hybridChildKindDef.Contains("MotherKindDef"))
spawn_kind_def = mother.kindDef; spawn_kind_def = motherKindDef;
else if (t.hybridChildKindDef.Contains("FatherKindDef") && father != null) else if (t.hybridChildKindDef.Contains("FatherKindDef") && father != null)
spawn_kind_def = father.kindDef; spawn_kind_def = fatherKindDef;
else else
{ {
//ModLog.Message(" trying hybridChildKindDef " + t.defName); //ModLog.Message(" trying hybridChildKindDef " + t.defName);
@ -550,7 +563,7 @@ namespace RJW_Menstruation
} }
else if (!Configurations.UseHybridExtention || spawn_kind_def == null) else if (!Configurations.UseHybridExtention || spawn_kind_def == null)
{ {
spawn_kind_def = mother.RaceProps?.AnyPawnKind ?? mother.kindDef; spawn_kind_def = mother.RaceProps?.AnyPawnKind ?? motherKindDef;
} }
if (spawn_kind_def.defName.Contains("Nymph")) if (spawn_kind_def.defName.Contains("Nymph"))
@ -560,10 +573,10 @@ namespace RJW_Menstruation
spawn_kind_def_list.AddRange(DefDatabase<PawnKindDef>.AllDefs.Where(x => x.race == spawn_kind_def.race && !x.defName.Contains("Nymph"))); spawn_kind_def_list.AddRange(DefDatabase<PawnKindDef>.AllDefs.Where(x => x.race == spawn_kind_def.race && !x.defName.Contains("Nymph")));
//no other PawnKindDef found try mother //no other PawnKindDef found try mother
if (spawn_kind_def_list.NullOrEmpty()) if (spawn_kind_def_list.NullOrEmpty())
spawn_kind_def_list.AddRange(DefDatabase<PawnKindDef>.AllDefs.Where(x => x.race == mother.kindDef.race && !x.defName.Contains("Nymph"))); spawn_kind_def_list.AddRange(DefDatabase<PawnKindDef>.AllDefs.Where(x => x.race == motherKindDef.race && !x.defName.Contains("Nymph")));
//no other PawnKindDef found try father //no other PawnKindDef found try father
if (spawn_kind_def_list.NullOrEmpty() && father != null) if (spawn_kind_def_list.NullOrEmpty() && father != null)
spawn_kind_def_list.AddRange(DefDatabase<PawnKindDef>.AllDefs.Where(x => x.race == father.kindDef.race && !x.defName.Contains("Nymph"))); spawn_kind_def_list.AddRange(DefDatabase<PawnKindDef>.AllDefs.Where(x => x.race == fatherKindDef.race && !x.defName.Contains("Nymph")));
//no other PawnKindDef found fallback to generic colonist //no other PawnKindDef found fallback to generic colonist
if (spawn_kind_def_list.NullOrEmpty()) if (spawn_kind_def_list.NullOrEmpty())
spawn_kind_def = PawnKindDefOf.Colonist; spawn_kind_def = PawnKindDefOf.Colonist;

View file

@ -3,6 +3,7 @@ Version 1.0.7.0
- Experimental support for multiple vaginas. - Experimental support for multiple vaginas.
- Super-experimental support for multiple concurrent pregnancies. - Super-experimental support for multiple concurrent pregnancies.
- Properly generate a baby's race when using pawnkind diversification mods.
- Overhauled many things under the hood. - Overhauled many things under the hood.
- Cycle randomization completely redone. Everyone now has a (hidden) cycle speed and cycle variability. - Cycle randomization completely redone. Everyone now has a (hidden) cycle speed and cycle variability.
- Ovary initialization redone. All pawns now get a total number of eggs based on their age and racial properties. - Ovary initialization redone. All pawns now get a total number of eggs based on their age and racial properties.