Little optimization in Fertilize calculation

This commit is contained in:
lutepickle 2023-04-20 12:31:27 -07:00
parent db6e12fa8b
commit baeff0ea29
2 changed files with 9 additions and 6 deletions

View file

@ -21,6 +21,7 @@ namespace RJW_Menstruation
public const int ColonistTickIntervalDefault = 2500; // 1 hour
public const int NonColonistTickIntervalDefault = 2500;
public const int AnimalTickIntervalDefault = 2500;
public const int TickIntervalMinimum = 20;
public const float EnzygoticTwinsChanceDefault = 0.002f;
public const int EnzygoticTwinsChanceAdjustDefault = 2;
public const int MaxEnzygoticTwinsDefault = 9;
@ -431,15 +432,15 @@ namespace RJW_Menstruation
Configurations.CycleAcceleration = (int)listmain.Slider(Configurations.CycleAcceleration, 1, 50);
listmain.LabelDouble(Translations.Option_ColonistUpdateInterval_Label, GenDate.ToStringTicksToPeriod(Configurations.ColonistTickInterval), Translations.Option_ColonistUpdateInterval_Desc);
Configurations.ColonistTickInterval = (int)Mathf.Exp(listmain.Slider(Mathf.Log(Configurations.ColonistTickInterval), Mathf.Log(20), Mathf.Log(4 * GenDate.TicksPerHour)));
Configurations.ColonistTickInterval = (int)Mathf.Exp(listmain.Slider(Mathf.Log(Configurations.ColonistTickInterval), Mathf.Log(Configurations.TickIntervalMinimum), Mathf.Log(4 * GenDate.TicksPerHour)));
listmain.LabelDouble(Translations.Option_NonColonistUpdateInterval_Label, GenDate.ToStringTicksToPeriod(Configurations.NonColonistTickInterval), Translations.Option_NonColonistUpdateInterval_Desc);
Configurations.NonColonistTickInterval = (int)Mathf.Exp(listmain.Slider(Mathf.Log(Configurations.NonColonistTickInterval), Mathf.Log(20), Mathf.Log(4 * GenDate.TicksPerHour)));
Configurations.NonColonistTickInterval = (int)Mathf.Exp(listmain.Slider(Mathf.Log(Configurations.NonColonistTickInterval), Mathf.Log(Configurations.TickIntervalMinimum), Mathf.Log(4 * GenDate.TicksPerHour)));
if(Configurations.EnableAnimalCycle)
{
listmain.LabelDouble(Translations.Option_AnimalUpdateInterval_Label, GenDate.ToStringTicksToPeriod(Configurations.AnimalTickInterval), Translations.Option_AnimalUpdateInterval_Desc);
Configurations.AnimalTickInterval = (int)Mathf.Exp(listmain.Slider(Mathf.Log(Configurations.AnimalTickInterval), Mathf.Log(20), Mathf.Log(4 * GenDate.TicksPerHour)));
Configurations.AnimalTickInterval = (int)Mathf.Exp(listmain.Slider(Mathf.Log(Configurations.AnimalTickInterval), Mathf.Log(Configurations.TickIntervalMinimum), Mathf.Log(4 * GenDate.TicksPerHour)));
}
float var2 = EstimatedBleedingAmountPerHour;

View file

@ -170,6 +170,7 @@ namespace RJW_Menstruation
}
return tickInterval;
}
set => tickInterval = value;
}
public Hediff Pregnancy {
@ -716,7 +717,7 @@ namespace RJW_Menstruation
Initialize();
}
if (Pawn.IsHashIntervalTick(recalculateTickInterval)) tickInterval = -1; // Every so often, force TickInterval to be recalculated in case the pawn's status changed.
if (Pawn.IsHashIntervalTick(recalculateTickInterval)) TickInterval = -1; // Every so often, force TickInterval to be recalculated in case the pawn's status changed.
if (!Pawn.IsHashIntervalTick(TickInterval)) return;
if (initError) Log.Warning($"Attempting to process {Pawn}'s womb uninitialized");
@ -1331,8 +1332,9 @@ namespace RJW_Menstruation
float totalFertPower = eligibleCum.Sum(cum => cum.FertVolume);
float fertFailChancePerHour = Mathf.Pow(1.0f - Configurations.FertilizeChance, totalFertPower * Props.basefertilizationChanceFactor);
float fertFailChancePerInterval = Mathf.Pow(fertFailChancePerHour, (float)TickInterval / GenDate.TicksPerHour);
//float fertFailChancePerHour = Mathf.Pow(1.0f - Configurations.FertilizeChance, totalFertPower * Props.basefertilizationChanceFactor);
//float fertFailChancePerInterval = Mathf.Pow(fertFailChancePerHour, (float)TickInterval / GenDate.TicksPerHour);
float fertFailChancePerInterval = Mathf.Pow(1.0f - Configurations.FertilizeChance, totalFertPower * Props.basefertilizationChanceFactor * TickInterval / GenDate.TicksPerHour);
if (Rand.Chance(fertFailChancePerInterval)) return null;