mirror of
				https://github.com/vegapnk/RJW-Genes.git
				synced 2024-08-15 00:23:31 +00:00 
			
		
		
		
	PregnancyOverwrite now has all functions
This commit is contained in:
		
							parent
							
								
									832c3aa0b8
								
							
						
					
					
						commit
						991edfdff0
					
				
					 4 changed files with 69 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -115,7 +115,6 @@
 | 
			
		|||
            </li>
 | 
			
		||||
        </forcedTraits>
 | 
			
		||||
        <exclusionTags>
 | 
			
		||||
            
 | 
			
		||||
            <li>rjw_genes_homosexuality_trait_giver</li>
 | 
			
		||||
            <li>rjw_genes_sexual_orientation</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>
 | 
			
		||||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -51,22 +51,36 @@ 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;
 | 
			
		||||
 | 
			
		||||
            if (DiseaseHelper.IsImmuneAgainstGeneticDisease(pregnant, GeneDefOf.rjw_genes_pregnancy_overwrite))
 | 
			
		||||
            {
 | 
			
		||||
                ModLog.Debug($"{pregnant} is immune against rjw_genes_pregnancy_overwrite from {replacer}");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            ChanceExtension chanceExt = GeneDefOf.rjw_genes_pregnancy_overwrite.GetModExtension<ChanceExtension>();
 | 
			
		||||
            float chance = chanceExt != null ? chanceExt.chance : 0.25f;
 | 
			
		||||
            chance *= PregnancyUtility.PregnancyChanceForPartners(pregnant, replacer);
 | 
			
		||||
 | 
			
		||||
            if ((new Random()).Next() < chance)
 | 
			
		||||
            {
 | 
			
		||||
                float gestationProgress = pregnancyHediff.Severity;
 | 
			
		||||
 | 
			
		||||
                PregnancyUtility.ForceEndPregnancy(pregnant);
 | 
			
		||||
| 
						 | 
				
			
			@ -74,6 +88,12 @@ namespace RJW_Genes
 | 
			
		|||
                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])");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue