private static float GetNewParentSkinColorFactor(float?newParentMelanin, float?otherParentMelanin, float?childMelanin) { if (newParentMelanin.HasValue) { if (!otherParentMelanin.HasValue) { if (childMelanin.HasValue) { return(ChildRelationUtility.GetMelaninSimilarityFactor(newParentMelanin.Value, childMelanin.Value)); } return(PawnSkinColors.GetMelaninCommonalityFactor(newParentMelanin.Value)); } if (childMelanin.HasValue) { float reflectedSkin = ChildRelationUtility.GetReflectedSkin(otherParentMelanin.Value, childMelanin.Value); return(ChildRelationUtility.GetMelaninSimilarityFactor(newParentMelanin.Value, reflectedSkin)); } float melanin = (float)((newParentMelanin.Value + otherParentMelanin.Value) / 2.0); return(PawnSkinColors.GetMelaninCommonalityFactor(melanin)); } if (!otherParentMelanin.HasValue) { if (childMelanin.HasValue) { return(PawnSkinColors.GetMelaninCommonalityFactor(childMelanin.Value)); } return(1f); } if (childMelanin.HasValue) { float reflectedSkin2 = ChildRelationUtility.GetReflectedSkin(otherParentMelanin.Value, childMelanin.Value); return(PawnSkinColors.GetMelaninCommonalityFactor(reflectedSkin2)); } return(PawnSkinColors.GetMelaninCommonalityFactor(otherParentMelanin.Value)); }
public static float GetRandomSecondParentSkinColor(float otherParentSkin, float childSkin, float?secondChildSkin = null) { float mirror; if (secondChildSkin != null) { mirror = (childSkin + secondChildSkin.Value) / 2f; } else { mirror = childSkin; } float reflectedSkin = ChildRelationUtility.GetReflectedSkin(otherParentSkin, mirror); float num = childSkin; float num2 = childSkin; if (secondChildSkin != null) { num = Mathf.Min(num, secondChildSkin.Value); num2 = Mathf.Max(num2, secondChildSkin.Value); } float clampMin = 0f; float clampMax = 1f; if (reflectedSkin >= num2) { clampMin = num2; } else { clampMax = num; } return(PawnSkinColors.GetRandomMelaninSimilarTo(reflectedSkin, clampMin, clampMax)); }
public override float GenerationChance(Pawn generated, Pawn other, PawnGenerationRequest request) { float num = 1f; float num2 = 1f; if (other.GetFather() == null && other.GetMother() == null) { num2 = ((!request.FixedMelanin.HasValue) ? PawnSkinColors.GetMelaninCommonalityFactor(other.story.melanin) : ChildRelationUtility.GetMelaninSimilarityFactor(request.FixedMelanin.Value, other.story.melanin)); } else { num = ChildRelationUtility.ChanceOfBecomingChildOf(generated, other.GetFather(), other.GetMother(), request, null, null); } float num3 = Mathf.Abs(generated.ageTracker.AgeChronologicalYearsFloat - other.ageTracker.AgeChronologicalYearsFloat); float num4 = 1f; if (num3 > 40.0) { num4 = 0.2f; } else if (num3 > 10.0) { num4 = 0.65f; } return(num * num2 * num4 * base.BaseGenerationChanceFactor(generated, other, request)); }
public static float GetRandomSecondParentSkinColor(float otherParentSkin, float childSkin, float?secondChildSkin = default(float?)) { float num = 0f; num = (float)((!secondChildSkin.HasValue) ? childSkin : ((childSkin + secondChildSkin.Value) / 2.0)); float reflectedSkin = ChildRelationUtility.GetReflectedSkin(otherParentSkin, num); float num2 = childSkin; float num3 = childSkin; if (secondChildSkin.HasValue) { num2 = Mathf.Min(num2, secondChildSkin.Value); num3 = Mathf.Max(num3, secondChildSkin.Value); } float clampMin = 0f; float clampMax = 1f; if (reflectedSkin >= num3) { clampMin = num3; } else { clampMax = num2; } return(PawnSkinColors.GetRandomMelaninSimilarTo(reflectedSkin, clampMin, clampMax)); }
private static float GetSkinColorFactor(float?childMelanin, float?fatherMelanin, float?motherMelanin, bool fatherIsNew, bool motherIsNew) { if (childMelanin.HasValue && fatherMelanin.HasValue && motherMelanin.HasValue) { float num = Mathf.Min(fatherMelanin.Value, motherMelanin.Value); float num2 = Mathf.Max(fatherMelanin.Value, motherMelanin.Value); if (childMelanin.HasValue && childMelanin.GetValueOrDefault() < num - 0.05000000074505806) { return(0f); } if (childMelanin.HasValue && childMelanin.GetValueOrDefault() > num2 + 0.05000000074505806) { return(0f); } } float num3 = 1f; if (fatherIsNew) { num3 *= ChildRelationUtility.GetNewParentSkinColorFactor(fatherMelanin, motherMelanin, childMelanin); } if (motherIsNew) { num3 *= ChildRelationUtility.GetNewParentSkinColorFactor(motherMelanin, fatherMelanin, childMelanin); } return(num3); }
private static void ResolveMySkinColor(ref PawnGenerationRequest request, Pawn generated) { if (!request.FixedMelanin.HasValue) { request.SetFixedMelanin(ChildRelationUtility.GetRandomChildSkinColor(generated.GetFather().story.melanin, generated.GetMother().story.melanin)); } }
private static float GetParentAgeFactor(Pawn parent, Pawn child, float minAgeToHaveChildren, float usualAgeToHaveChildren, float maxAgeToHaveChildren) { float num = PawnRelationUtility.MaxPossibleBioAgeAt(parent.ageTracker.AgeBiologicalYearsFloat, parent.ageTracker.AgeChronologicalYearsFloat, child.ageTracker.AgeChronologicalYearsFloat); float num2 = PawnRelationUtility.MinPossibleBioAgeAt(parent.ageTracker.AgeBiologicalYearsFloat, child.ageTracker.AgeChronologicalYearsFloat); if (num <= 0f) { return(0f); } if (num2 > num) { if (num2 > num + 0.1f) { Log.Warning(string.Concat(new object[] { "Min possible bio age (", num2, ") is greater than max possible bio age (", num, ")." }), false); } return(0f); } if (num2 <= usualAgeToHaveChildren && num >= usualAgeToHaveChildren) { return(1f); } float ageFactor = ChildRelationUtility.GetAgeFactor(num2, minAgeToHaveChildren, maxAgeToHaveChildren, usualAgeToHaveChildren); float ageFactor2 = ChildRelationUtility.GetAgeFactor(num, minAgeToHaveChildren, maxAgeToHaveChildren, usualAgeToHaveChildren); return(Mathf.Max(ageFactor, ageFactor2)); }
private static float GetSkinColorFactor(float?childMelanin, float?fatherMelanin, float?motherMelanin, bool fatherIsNew, bool motherIsNew) { if (childMelanin != null && fatherMelanin != null && motherMelanin != null) { float num = Mathf.Min(fatherMelanin.Value, motherMelanin.Value); float num2 = Mathf.Max(fatherMelanin.Value, motherMelanin.Value); if (childMelanin < num - 0.05f) { return(0f); } if (childMelanin > num2 + 0.05f) { return(0f); } } float num3 = 1f; if (fatherIsNew) { num3 *= ChildRelationUtility.GetNewParentSkinColorFactor(fatherMelanin, motherMelanin, childMelanin); } if (motherIsNew) { num3 *= ChildRelationUtility.GetNewParentSkinColorFactor(motherMelanin, fatherMelanin, childMelanin); } return(num3); }
private static void ResolveMyName(ref PawnGenerationRequest request, Pawn child, Pawn otherParent) { if (request.FixedLastName != null) { return; } if (ChildRelationUtility.DefinitelyHasNotBirthName(child)) { return; } if (ChildRelationUtility.ChildWantsNameOfAnyParent(child)) { if (otherParent == null) { float num = 0.9f; if (Rand.Value < num) { request.SetFixedLastName(((NameTriple)child.Name).Last); } } else { string last = ((NameTriple)child.Name).Last; string last2 = ((NameTriple)otherParent.Name).Last; if (last != last2) { request.SetFixedLastName(last); } } } }
public static void TryToShareChildrenForGeneratedLovePartner(Pawn generated, Pawn other, PawnGenerationRequest request, float extraChanceFactor) { if (generated.gender != other.gender) { List <Pawn> list = other.relations.Children.ToList(); for (int i = 0; i < list.Count; i++) { Pawn pawn = list[i]; float num = 1f; if (generated.gender == Gender.Male) { num = ChildRelationUtility.ChanceOfBecomingChildOf(pawn, generated, other, null, request, null); } else if (generated.gender == Gender.Female) { num = ChildRelationUtility.ChanceOfBecomingChildOf(pawn, other, generated, null, null, request); } num *= extraChanceFactor; if (Rand.Value < num) { if (generated.gender == Gender.Male) { pawn.SetFather(generated); } else if (generated.gender == Gender.Female) { pawn.SetMother(generated); } } } } }
public static float LovePartnerRelationGenerationChance(Pawn generated, Pawn other, PawnGenerationRequest request, bool ex) { if (generated.ageTracker.AgeBiologicalYearsFloat < 14f) { return(0f); } if (other.ageTracker.AgeBiologicalYearsFloat < 14f) { return(0f); } if (generated.gender == other.gender && (!other.story.traits.HasTrait(TraitDefOf.Gay) || !request.AllowGay)) { return(0f); } if (generated.gender != other.gender && other.story.traits.HasTrait(TraitDefOf.Gay)) { return(0f); } float num = 1f; if (ex) { int num2 = 0; List <DirectPawnRelation> directRelations = other.relations.DirectRelations; for (int i = 0; i < directRelations.Count; i++) { if (LovePartnerRelationUtility.IsExLovePartnerRelation(directRelations[i].def)) { num2++; } } num = Mathf.Pow(0.2f, (float)num2); } else if (LovePartnerRelationUtility.HasAnyLovePartner(other)) { return(0f); } float num3 = (generated.gender != other.gender) ? 1f : 0.01f; float generationChanceAgeFactor = LovePartnerRelationUtility.GetGenerationChanceAgeFactor(generated); float generationChanceAgeFactor2 = LovePartnerRelationUtility.GetGenerationChanceAgeFactor(other); float generationChanceAgeGapFactor = LovePartnerRelationUtility.GetGenerationChanceAgeGapFactor(generated, other, ex); float num4 = 1f; if (generated.GetRelations(other).Any((PawnRelationDef x) => x.familyByBloodRelation)) { num4 = 0.01f; } float num5; if (request.FixedMelanin != null) { num5 = ChildRelationUtility.GetMelaninSimilarityFactor(request.FixedMelanin.Value, other.story.melanin); } else { num5 = PawnSkinColors.GetMelaninCommonalityFactor(other.story.melanin); } return(num * generationChanceAgeFactor * generationChanceAgeFactor2 * generationChanceAgeGapFactor * num3 * num5 * num4); }
private static void GenerateParentParams(float minChronologicalAge, float maxChronologicalAge, float midChronologicalAge, float minBioAgeToHaveChildren, Pawn generatedChild, Pawn existingChild, PawnGenerationRequest childRequest, out float biologicalAge, out float chronologicalAge, out float melanin, out string lastName) { chronologicalAge = Rand.GaussianAsymmetric(midChronologicalAge, (float)((midChronologicalAge - minChronologicalAge) / 2.0), (float)((maxChronologicalAge - midChronologicalAge) / 2.0)); chronologicalAge = Mathf.Clamp(chronologicalAge, minChronologicalAge, maxChronologicalAge); biologicalAge = Rand.Range(minBioAgeToHaveChildren, Mathf.Min(existingChild.RaceProps.lifeExpectancy, chronologicalAge)); if (existingChild.GetFather() != null) { melanin = ParentRelationUtility.GetRandomSecondParentSkinColor(existingChild.GetFather().story.melanin, existingChild.story.melanin, childRequest.FixedMelanin); } else if (existingChild.GetMother() != null) { melanin = ParentRelationUtility.GetRandomSecondParentSkinColor(existingChild.GetMother().story.melanin, existingChild.story.melanin, childRequest.FixedMelanin); } else if (!childRequest.FixedMelanin.HasValue) { melanin = PawnSkinColors.GetRandomMelaninSimilarTo(existingChild.story.melanin, 0f, 1f); } else { float num = Mathf.Min(childRequest.FixedMelanin.Value, existingChild.story.melanin); float num2 = Mathf.Max(childRequest.FixedMelanin.Value, existingChild.story.melanin); if (Rand.Value < 0.5) { melanin = PawnSkinColors.GetRandomMelaninSimilarTo(num, 0f, num); } else { melanin = PawnSkinColors.GetRandomMelaninSimilarTo(num2, num2, 1f); } } lastName = null; if (!ChildRelationUtility.DefinitelyHasNotBirthName(existingChild) && ChildRelationUtility.ChildWantsNameOfAnyParent(existingChild)) { if (existingChild.GetMother() == null && existingChild.GetFather() == null) { if (Rand.Value < 0.5) { lastName = ((NameTriple)existingChild.Name).Last; } } else { string last = ((NameTriple)existingChild.Name).Last; string b = null; if (existingChild.GetMother() != null) { b = ((NameTriple)existingChild.GetMother().Name).Last; } else if (existingChild.GetFather() != null) { b = ((NameTriple)existingChild.GetFather().Name).Last; } if (last != b) { lastName = last; } } } }
public static float ChanceOfBecomingChildOf(Pawn child, Pawn father, Pawn mother, PawnGenerationRequest?childGenerationRequest, PawnGenerationRequest?fatherGenerationRequest, PawnGenerationRequest?motherGenerationRequest) { try { return(ChildRelationUtility.ChanceOfBecomingChildOfInternal(child, father, mother, childGenerationRequest, fatherGenerationRequest, motherGenerationRequest)); } finally { } }
public override float GenerationChance(Pawn generated, Pawn other, PawnGenerationRequest request) { float num = 0f; if (generated.gender == Gender.Male) { num = ChildRelationUtility.ChanceOfBecomingChildOf(other, generated, other.GetMother(), null, request, null); } else if (generated.gender == Gender.Female) { num = ChildRelationUtility.ChanceOfBecomingChildOf(other, other.GetFather(), generated, null, null, request); } return(num * BaseGenerationChanceFactor(generated, other, request)); }
public override float GenerationChance(Pawn generated, Pawn other, PawnGenerationRequest request) { float num = 0f; if (other.gender == Gender.Male) { num = ChildRelationUtility.ChanceOfBecomingChildOf(generated, other, other.GetSpouseOppositeGender(), new PawnGenerationRequest?(request), null, null); } else if (other.gender == Gender.Female) { num = ChildRelationUtility.ChanceOfBecomingChildOf(generated, other.GetSpouseOppositeGender(), other, new PawnGenerationRequest?(request), null, null); } return(num * base.BaseGenerationChanceFactor(generated, other, request)); }
private static void ResolveMyName(ref PawnGenerationRequest request, Pawn generated) { if (request.FixedLastName == null && ChildRelationUtility.ChildWantsNameOfAnyParent(generated)) { if (Rand.Value < 0.5) { request.SetFixedLastName(((NameTriple)generated.GetFather().Name).Last); } else { request.SetFixedLastName(((NameTriple)generated.GetMother().Name).Last); } } }
private static float GetNewParentSkinColorFactor(float?newParentMelanin, float?otherParentMelanin, float?childMelanin) { float result; if (newParentMelanin != null) { if (otherParentMelanin == null) { if (childMelanin != null) { result = ChildRelationUtility.GetMelaninSimilarityFactor(newParentMelanin.Value, childMelanin.Value); } else { result = PawnSkinColors.GetMelaninCommonalityFactor(newParentMelanin.Value); } } else if (childMelanin != null) { float reflectedSkin = ChildRelationUtility.GetReflectedSkin(otherParentMelanin.Value, childMelanin.Value); result = ChildRelationUtility.GetMelaninSimilarityFactor(newParentMelanin.Value, reflectedSkin); } else { float melanin = (newParentMelanin.Value + otherParentMelanin.Value) / 2f; result = PawnSkinColors.GetMelaninCommonalityFactor(melanin); } } else if (otherParentMelanin == null) { if (childMelanin != null) { result = PawnSkinColors.GetMelaninCommonalityFactor(childMelanin.Value); } else { result = 1f; } } else if (childMelanin != null) { float reflectedSkin2 = ChildRelationUtility.GetReflectedSkin(otherParentMelanin.Value, childMelanin.Value); result = PawnSkinColors.GetMelaninCommonalityFactor(reflectedSkin2); } else { result = PawnSkinColors.GetMelaninCommonalityFactor(otherParentMelanin.Value); } return(result); }
private static void ResolveMySkinColor(ref PawnGenerationRequest request, Pawn generatedChild) { if (!request.FixedMelanin.HasValue) { if (generatedChild.GetFather() != null && generatedChild.GetMother() != null) { request.SetFixedMelanin(ChildRelationUtility.GetRandomChildSkinColor(generatedChild.GetFather().story.melanin, generatedChild.GetMother().story.melanin)); } else if (generatedChild.GetFather() != null) { request.SetFixedMelanin(PawnSkinColors.GetRandomMelaninSimilarTo(generatedChild.GetFather().story.melanin)); } else { request.SetFixedMelanin(PawnSkinColors.GetRandomMelaninSimilarTo(generatedChild.GetMother().story.melanin)); } } }
private static void ResolveMyName(ref PawnGenerationRequest request, Pawn generatedChild) { if (request.FixedLastName == null) { if (ChildRelationUtility.ChildWantsNameOfAnyParent(generatedChild)) { bool flag = Rand.Value < 0.5f || generatedChild.GetMother() == null; if (generatedChild.GetFather() == null) { flag = false; } if (flag) { request.SetFixedLastName(((NameTriple)generatedChild.GetFather().Name).Last); } else { request.SetFixedLastName(((NameTriple)generatedChild.GetMother().Name).Last); } } } }
public static float ChanceOfBecomingChildOf(Pawn child, Pawn father, Pawn mother, PawnGenerationRequest?childGenerationRequest, PawnGenerationRequest?fatherGenerationRequest, PawnGenerationRequest?motherGenerationRequest) { if (father != null && father.gender != Gender.Male) { Log.Warning("Tried to calculate chance for father with gender \"" + father.gender + "\".", false); return(0f); } if (mother != null && mother.gender != Gender.Female) { Log.Warning("Tried to calculate chance for mother with gender \"" + mother.gender + "\".", false); return(0f); } if (father != null && child.GetFather() != null && child.GetFather() != father) { return(0f); } if (mother != null && child.GetMother() != null && child.GetMother() != mother) { return(0f); } if (mother != null && father != null && !LovePartnerRelationUtility.LovePartnerRelationExists(mother, father) && !LovePartnerRelationUtility.ExLovePartnerRelationExists(mother, father)) { return(0f); } float?melanin = ChildRelationUtility.GetMelanin(child, childGenerationRequest); float?melanin2 = ChildRelationUtility.GetMelanin(father, fatherGenerationRequest); float?melanin3 = ChildRelationUtility.GetMelanin(mother, motherGenerationRequest); bool fatherIsNew = father != null && child.GetFather() != father; bool motherIsNew = mother != null && child.GetMother() != mother; float skinColorFactor = ChildRelationUtility.GetSkinColorFactor(melanin, melanin2, melanin3, fatherIsNew, motherIsNew); if (skinColorFactor <= 0f) { return(0f); } float num = 1f; float num2 = 1f; float num3 = 1f; float num4 = 1f; if (father != null && child.GetFather() == null) { num = ChildRelationUtility.GetParentAgeFactor(father, child, 14f, 30f, 50f); if (num == 0f) { return(0f); } if (father.story.traits.HasTrait(TraitDefOf.Gay)) { num4 = 0.1f; } } if (mother != null && child.GetMother() == null) { num2 = ChildRelationUtility.GetParentAgeFactor(mother, child, 16f, 27f, 45f); if (num2 == 0f) { return(0f); } int num5 = ChildRelationUtility.NumberOfChildrenFemaleWantsEver(mother); if (mother.relations.ChildrenCount >= num5) { return(0f); } num3 = 1f - (float)mother.relations.ChildrenCount / (float)num5; if (mother.story.traits.HasTrait(TraitDefOf.Gay)) { num4 = 0.1f; } } float num6 = 1f; if (mother != null) { Pawn firstDirectRelationPawn = mother.relations.GetFirstDirectRelationPawn(PawnRelationDefOf.Spouse, null); if (firstDirectRelationPawn != null && firstDirectRelationPawn != father) { num6 *= 0.15f; } } if (father != null) { Pawn firstDirectRelationPawn2 = father.relations.GetFirstDirectRelationPawn(PawnRelationDefOf.Spouse, null); if (firstDirectRelationPawn2 != null && firstDirectRelationPawn2 != mother) { num6 *= 0.15f; } } return(skinColorFactor * num * num2 * num3 * num6 * num4); }