PregnancyOverwrite now has all functions

This commit is contained in:
Vegapnk 2024-07-08 19:23:27 +02:00
parent 832c3aa0b8
commit 991edfdff0
4 changed files with 69 additions and 15 deletions

View file

@ -162,6 +162,12 @@
<biostatCpx>4</biostatCpx>
<biostatMet>-2</biostatMet>
<modExtensions>
<!-- DevNote: The chance will be multiplied by both pawns' Fertility! -->
<li Class="RJW_Genes.ChanceExtension">
<chance>0.5</chance>
</li>
</modExtensions>
</GeneDef>
</Defs>

View file

@ -115,7 +115,6 @@
</li>
</forcedTraits>
<exclusionTags>
<li>rjw_genes_homosexuality_trait_giver</li>
<li>rjw_genes_sexual_orientation</li>
</exclusionTags>
@ -144,7 +143,7 @@
</li>
</forcedTraits>
<exclusionTags>
<li>rjw_genes_sexual_orientation</li>
<li>rjw_genes_sexual_orientation</li>
<li>rjw_genes_bisexuality_trait_giver</li>
</exclusionTags>
@ -207,4 +206,28 @@
</exclusionTags>
</GeneDef>
<GeneDef>
<defName>rjw_genes_pregnancy_overwrite</defName>
<label>Sperm Displacement</label>
<displayCategory>Reproduction</displayCategory>
<description>Carriers of this gene can 'overwrite' an existing pregnancy, keeping the
progress but effectively replacing the father.</description>
<iconPath>Genes/Icons/RJW_Genes_PheromoneSpit</iconPath>
<displayOrderInCategory>120</displayOrderInCategory>
<biostatCpx>4</biostatCpx>
<biostatMet>-2</biostatMet>
<modExtensions>
<!-- DevNote: The chance will be multiplied by both pawns' Fertility! -->
<li Class="RJW_Genes.ChanceExtension">
<chance>0.5</chance>
</li>
<li MayRequire="OskarPotocki.VanillaFactionsExpanded.Core"
Class="VanillaGenesExpanded.GeneExtension">
<backgroundPathEndogenes>Genes/Icons/RJW_Genes_Endogene_Background</backgroundPathEndogenes>
<backgroundPathXenogenes>Genes/Icons/RJW_Genes_Xenogene_Background</backgroundPathXenogenes>
</li>
</modExtensions>
</GeneDef>
</Defs>

View file

@ -10,4 +10,9 @@
<label>Youthed a pawn with youth fountain</label>
</HistoryEventDef>
<HistoryEventDef>
<defName>rjw_genes_GoodwillChangedReason_OverwritePregnancy</defName>
<label>Replaced a pregnancy</label>
</HistoryEventDef>
</Defs>

View file

@ -51,29 +51,49 @@ namespace RJW_Genes
TryReplacePregnancy(pawn, partner);
}
/// <summary>
/// Tries to replace an existing pregnancy with a new pregnancy at the same gestation process.
/// The new pregnancy will have the same mother, but a new father and a new set of genes.
///
/// There is a check for pregnancy that checks for the general fertility (using Vanilla Functions) and multiplies it with a xml-configurable chance.
/// If anything is replaced, there will be a faction penalty applied.
/// </summary>
/// <param name="replacer"></param>
/// <param name="pregnant"></param>
public static void TryReplacePregnancy(Pawn replacer, Pawn pregnant)
{
// TODO: This mostly works, but needs some more checks.
// - Check if there is a pregnancy occurring
// - Check for Disease Immunity
// - Add Faction Penalties
ModLog.Debug($"Firing Pregnancy Overwrite for {replacer} and {pregnant}");
// The "CanImpregnate" does not work as I want, as the pawn is already pregnant, so it wont allow to be pregnated.
//PregnancyHelper.CanImpregnate(pawn, partner, props.sexType)
Hediff pregnancyHediff = PregnancyUtility.GetPregnancyHediff(pregnant);
if (pregnancyHediff == null)
return;
float gestationProgress = pregnancyHediff.Severity;
if (DiseaseHelper.IsImmuneAgainstGeneticDisease(pregnant, GeneDefOf.rjw_genes_pregnancy_overwrite))
{
ModLog.Debug($"{pregnant} is immune against rjw_genes_pregnancy_overwrite from {replacer}");
return;
}
PregnancyUtility.ForceEndPregnancy(pregnant);
ChanceExtension chanceExt = GeneDefOf.rjw_genes_pregnancy_overwrite.GetModExtension<ChanceExtension>();
float chance = chanceExt != null ? chanceExt.chance : 0.25f;
chance *= PregnancyUtility.PregnancyChanceForPartners(pregnant, replacer);
PregnancyHelper.StartVanillaPregnancy(pregnant, replacer);
Hediff replacementPregnancyHediff = PregnancyUtility.GetPregnancyHediff(pregnant);
replacementPregnancyHediff.Severity = gestationProgress;
if ((new Random()).Next() < chance)
{
float gestationProgress = pregnancyHediff.Severity;
PregnancyUtility.ForceEndPregnancy(pregnant);
PregnancyHelper.StartVanillaPregnancy(pregnant, replacer);
Hediff replacementPregnancyHediff = PregnancyUtility.GetPregnancyHediff(pregnant);
replacementPregnancyHediff.Severity = gestationProgress;
FactionUtility.HandleFactionGoodWillPenalties(replacer, pregnant, "rjw_genes_GoodwillChangedReason_OverwritePregnancy", FACTION_GOODWILL_CHANGE);
} else
{
ModLog.Debug($"Did not Pregnancy-Overwrite for {replacer} and {pregnant}. Failed: roll<({chanceExt.chance} x {PregnancyUtility.PregnancyChanceForPartners(pregnant,replacer)}[PregnancyChance for Pawns])");
}
}
}