Compare commits

...

3 commits

7 changed files with 197 additions and 17 deletions

Binary file not shown.

View file

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<GeneCategoryDef>
<defName>Menstruation</defName>
<label>menstruation</label>
<displayPriorityInXenotype>402</displayPriorityInXenotype>
</GeneCategoryDef>
<GeneDef Name="Menstruation_EggLifetime" Abstract="True">
<displayCategory>Menstruation</displayCategory>
<exclusionTags>
<li>Menstruation_EggLifetime</li>
</exclusionTags>
</GeneDef>
<GeneDef ParentName="Menstruation_EggLifetime">
<defName>Menstruation_ShortEggLifetime</defName>
<label>short egg lifetime</label>
<description>Unfertilized eggs with this gene last three-quarters as long.</description>
<biostatMet>1</biostatMet>
<displayOrderInCategory>10</displayOrderInCategory>
</GeneDef>
<GeneDef ParentName="Menstruation_EggLifetime">
<defName>Menstruation_DoubleEggLifetime</defName>
<label>double egg lifetime</label>
<description>Unfertilized eggs with this gene last twice as long.</description>
<biostatMet>-1</biostatMet>
<displayOrderInCategory>12</displayOrderInCategory>
</GeneDef>
<GeneDef ParentName="Menstruation_EggLifetime">
<defName>Menstruation_QuadEggLifetime</defName>
<label>quadrule egg lifetime</label>
<description>Eggs with this gene last four times as long.</description>
<biostatMet>-2</biostatMet>
<biostatCpx>1</biostatCpx>
<displayOrderInCategory>16</displayOrderInCategory>
</GeneDef>
<GeneDef Name="Menstruation_Estrus" Abstract="True">
<displayCategory>Menstruation</displayCategory>
<exclusionTags>
<li>Menstruation_Estrus</li>
</exclusionTags>
</GeneDef>
<GeneDef ParentName="Menstruation_Estrus">
<defName>Menstruation_NeverEstrus</defName>
<label>never estrus</label>
<description>Carriers of this gene will never go into estrus.</description>
<biostatMet>1</biostatMet>
<displayOrderInCategory>20</displayOrderInCategory>
</GeneDef>
<GeneDef ParentName="Menstruation_Estrus">
<defName>Menstruation_FullEstrus</defName>
<label>full estrus</label>
<description>Carriers of this gene will enter full estrus every menstrual cycle, regardless of vagina type.</description>
<biostatMet>-1</biostatMet>
<biostatCpx>1</biostatCpx>
<displayOrderInCategory>25</displayOrderInCategory>
</GeneDef>
<GeneDef Name="Menstruation_Ovulation" Abstract="True">
<displayCategory>Menstruation</displayCategory>
<exclusionTags>
<li>Menstruation_Ovulation</li>
</exclusionTags>
</GeneDef>
<GeneDef ParentName="Menstruation_Ovulation">
<defName>Menstruation_DoubleOvulation</defName>
<label>double ovulation</label>
<description>Wombs with this gene will ovulate twice as many eggs.</description>
<biostatMet>-1</biostatMet>
<displayOrderInCategory>30</displayOrderInCategory>
</GeneDef>
<GeneDef ParentName="Menstruation_Ovulation">
<defName>Menstruation_QuadOvulation</defName>
<label>quadruple ovulation</label>
<description>Wombs with this gene will ovulate four times as many eggs.</description>
<biostatMet>-1</biostatMet>
<displayOrderInCategory>35</displayOrderInCategory>
</GeneDef>
<GeneDef>
<defName>Menstruation_NoBleeding</defName>
<label>no bleeding</label>
<displayCategory>Menstruation</displayCategory>
<description>Wombs with this gene will not bleed at the end of their cycle.</description>
<biostatMet>1</biostatMet>
<displayOrderInCategory>40</displayOrderInCategory>
</GeneDef>
<!-- Pheromones? -->
</Defs>

View file

@ -75,7 +75,7 @@ namespace RJW_Menstruation
case Stage.Ovulatory:
return true;
case Stage.Luteal:
return IsEggExist && curStageHrs < Props.eggLifespanDays * 24;
return IsEggExist && curStageHrs < EggLifespanHours * 24;
default:
return false;
}
@ -93,7 +93,7 @@ namespace RJW_Menstruation
case Stage.Ovulatory:
return true;
case Stage.Luteal:
return IsEggExist && curStageHrs < Props.eggLifespanDays * 24;
return IsEggExist && curStageHrs < EggLifespanHours * 24;
default:
return false;
}

View file

@ -126,6 +126,11 @@ namespace RJW_Menstruation
// RJW pregnancy, or Biotech pregnancy/labor/laborpushing
protected Hediff pregnancy = null;
protected int eggLifeSpanHours = 48;
protected EstrusLevel estrusLevel = EstrusLevel.Visible;
protected float ovulationFactor = 1f;
protected bool noBleeding = false;
private static readonly SimpleCurve SexFrequencyCurve = new SimpleCurve()
{
new CurvePoint(0.4f,0.05f),
@ -179,6 +184,7 @@ namespace RJW_Menstruation
// Any exceptions in that will have been reported elsewhere in the code by now
avglittersize = 1.0f;
};
avglittersize *= ovulationFactor;
const float yearsBeforeMenopause = 6.0f;
opcache = (int)(RaceCyclesPerYear() *
avglittersize *
@ -470,6 +476,15 @@ namespace RJW_Menstruation
return !eggs.NullOrEmpty();
}
}
public int EggLifespanHours
{
get
{
return eggLifeSpanHours;
}
}
public virtual bool IsDangerDay
{
get
@ -483,7 +498,7 @@ namespace RJW_Menstruation
case Stage.Ovulatory:
return true;
case Stage.Luteal:
return curStageHrs < Props.eggLifespanDays * 24;
return curStageHrs < EggLifespanHours * 24;
default:
return false;
}
@ -606,6 +621,28 @@ namespace RJW_Menstruation
}
}
public void Notify_UpdatedGenes()
{
eggLifeSpanHours = Props.eggLifespanDays * 24;
estrusLevel = Props.concealedEstrus ? EstrusLevel.Concealed : EstrusLevel.Visible;
ovulationFactor = 1f;
noBleeding = false;
if (Pawn.genes == null || !ModsConfig.BiotechActive) return;
if (Pawn.genes.HasGene(VariousDefOf.ShortEggLifetime)) eggLifeSpanHours = eggLifeSpanHours * 3 / 4;
else if (Pawn.genes.HasGene(VariousDefOf.DoubleEggLifetime)) eggLifeSpanHours *= 2;
else if (Pawn.genes.HasGene(VariousDefOf.QuadEggLifetime)) eggLifeSpanHours *= 4;
if (Pawn.genes.HasGene(VariousDefOf.NeverEstrus)) estrusLevel = EstrusLevel.None;
else if (Pawn.genes.HasGene(VariousDefOf.FullEstrus)) estrusLevel = EstrusLevel.Visible;
if (Pawn.genes.HasGene(VariousDefOf.DoubleOvulation)) ovulationFactor = 2f;
else if (Pawn.genes.HasGene(VariousDefOf.QuadOvulation)) ovulationFactor = 4f;
noBleeding = Pawn.genes.HasGene(VariousDefOf.NoBleeding);
}
public bool ShouldSimulate()
{
if (!Configurations.EnableAnimalCycle && Pawn.IsAnimal()) return false;
@ -1029,6 +1066,8 @@ namespace RJW_Menstruation
initError = true;
Props = (CompProperties_Menstruation)props;
Notify_UpdatedGenes();
if (Props.infertile)
{
if (cums == null) cums = new List<Cum>();
@ -1101,6 +1140,7 @@ namespace RJW_Menstruation
{
avglittersize = 1.0f;
}
avglittersize *= ovulationFactor;
float fertStartAge = Pawn.RaceProps.lifeStageAges?.Find(stage => stage.def.reproductive)?.minAge ?? 0.0f;
float fertEndAge = Pawn.RaceProps.lifeExpectancy * (Pawn.IsAnimal() ? RJWPregnancySettings.fertility_endage_female_animal : RJWPregnancySettings.fertility_endage_female_humanlike);
@ -1160,7 +1200,7 @@ namespace RJW_Menstruation
case Stage.Ovulatory:
return true;
case Stage.Luteal:
return curStageHrs < Props.eggLifespanDays * 24;
return curStageHrs < EggLifespanHours * 24;
default:
return false;
}
@ -1169,12 +1209,13 @@ namespace RJW_Menstruation
public EstrusLevel GetEstrusLevel()
{
if (!ShouldBeInEstrus()) return EstrusLevel.None;
else return Props.concealedEstrus ? EstrusLevel.Concealed : EstrusLevel.Visible;
else return estrusLevel;
}
public void SetEstrus()
{
Hediff hediff = HediffMaker.MakeHediff(Props.concealedEstrus ? VariousDefOf.Hediff_Estrus_Concealed : VariousDefOf.Hediff_Estrus, Pawn);
if (estrusLevel == EstrusLevel.None) return;
Hediff hediff = HediffMaker.MakeHediff(estrusLevel == EstrusLevel.Concealed ? VariousDefOf.Hediff_Estrus_Concealed : VariousDefOf.Hediff_Estrus, Pawn);
Pawn.health.AddHediff(hediff);
}
@ -1454,25 +1495,27 @@ namespace RJW_Menstruation
protected virtual void OvulatoryAction()
{
estrusflag = false;
int eggnum;
float eggnum;
int ovulated;
try
{
eggnum = Math.Max((int)Rand.ByCurve(Pawn.def.race.litterSizeCurve), 1);
eggnum = Math.Max(Rand.ByCurve(Pawn.def.race.litterSizeCurve), 1f);
}
catch (NullReferenceException)
{
eggnum = 1;
eggnum = 1f;
}
catch (ArgumentException e)
{
Log.Warning($"Invalid litterSizeCurve for {Pawn.def}: {e}");
eggnum = 1;
eggnum = 1f;
}
eggnum += eggstack;
eggnum *= ovulationFactor;
ovulated = (int)eggnum + eggstack;
for (int i = 0; i < eggnum; i++)
eggs.Add(new Egg((int)(Props.eggLifespanDays * 24 / CycleFactor)));
ovarypower -= eggnum;
for (int i = 0; i < ovulated; i++)
eggs.Add(new Egg((int)(EggLifespanHours * 24 / CycleFactor)));
ovarypower -= ovulated;
eggstack = 0;
if (EggHealth <= 0)
@ -1709,7 +1752,7 @@ namespace RJW_Menstruation
protected void GoFollicularOrBleeding()
{
if (Props.bleedingIntervalDays == 0)
if (Props.bleedingIntervalDays == 0 || noBleeding)
{
GoNextStage(Stage.Follicular);
}

View file

@ -73,6 +73,29 @@ namespace RJW_Menstruation
return null;
}
[Obsolete("This method is obsolete and can cause ambiguity. Use GetMenstruationCompFromVagina or GetMenstruationCompFromPregnancy instead.", true)]
public static HediffComp_Menstruation GetMenstruationComp(Hediff hediff)
{
switch (hediff)
{
case Hediff_BasePregnancy rjwPreg:
return rjwPreg.GetMenstruationCompFromPregnancy();
case Hediff_Pregnant vanillaPreg:
return vanillaPreg.GetMenstruationCompFromPregnancy();
case Hediff_Labor vanillaLabor:
return vanillaLabor.GetMenstruationCompFromPregnancy();
case Hediff_LaborPushing vanillaLaborPushing:
return vanillaLaborPushing.GetMenstruationCompFromPregnancy();
case Hediff_PartBaseNatural rjwNatrual:
return rjwNatrual.GetMenstruationCompFromVagina();
case Hediff_PartBaseArtifical rjwArtificial:
return rjwArtificial.GetMenstruationCompFromVagina();
default:
Log.Warning("Obsolete GetMenstruationComp called with unknown hediff. Ensure your submods are up to date.");
return null;
}
}
public static HediffComp_Anus GetAnusComp(this Hediff hediff)
{
if (hediff is Hediff_PartBaseNatural || hediff is Hediff_PartBaseArtifical)

View file

@ -177,4 +177,13 @@ namespace RJW_Menstruation
}
}
[HarmonyPatch(typeof(Pawn_GeneTracker), "Notify_GenesChanged")]
public class Notify_GenesChanged_Patch
{
public static void Postfix(Pawn_GeneTracker __instance)
{
foreach (HediffComp_Menstruation comp in __instance.pawn.GetMenstruationComps())
comp.Notify_UpdatedGenes();
}
}
}

View file

@ -44,8 +44,14 @@ namespace RJW_Menstruation
public static readonly RecordDef AmountofCreampied = DefDatabase<RecordDef>.GetNamed("AmountofCreampied");
public static readonly RecordDef AmountofFertilizedEggs = DefDatabase<RecordDef>.GetNamed("AmountofFertilizedEggs");
public static readonly TaleDef TaleCameInside = DefDatabase<TaleDef>.GetNamed("CameInside");
public static readonly GeneDef ShortEggLifetime = DefDatabase<GeneDef>.GetNamed("Menstruation_ShortEggLifetime");
public static readonly GeneDef DoubleEggLifetime = DefDatabase<GeneDef>.GetNamed("Menstruation_DoubleEggLifetime");
public static readonly GeneDef QuadEggLifetime = DefDatabase<GeneDef>.GetNamed("Menstruation_QuadEggLifetime");
public static readonly GeneDef NeverEstrus = DefDatabase<GeneDef>.GetNamed("Menstruation_NeverEstrus");
public static readonly GeneDef FullEstrus = DefDatabase<GeneDef>.GetNamed("Menstruation_FullEstrus");
public static readonly GeneDef DoubleOvulation = DefDatabase<GeneDef>.GetNamed("Menstruation_DoubleOvulation");
public static readonly GeneDef QuadOvulation = DefDatabase<GeneDef>.GetNamed("Menstruation_QuadOvulation");
public static readonly GeneDef NoBleeding = DefDatabase<GeneDef>.GetNamed("Menstruation_NoBleeding");
private static List<ThingDef> allraces = null;
private static List<PawnKindDef> allkinds = null;