Add a proper weighted random algo for selecting paternity

This commit is contained in:
lutepickle 2022-06-02 12:31:31 -07:00
parent 8b48fe51e5
commit c082c70e68
2 changed files with 29 additions and 7 deletions

Binary file not shown.

View file

@ -1115,17 +1115,39 @@ namespace RJW_Menstruation
protected Pawn Fertilize() protected Pawn Fertilize()
{ {
if (cums.NullOrEmpty()) return null; if (cums.NullOrEmpty()) return null;
foreach (Cum cum in cums) float totalFertPower = 0;
{ List<Cum> eligibleCum = cums.FindAll(c => c.FertVolume > 0 && (RJWPregnancySettings.bestial_pregnancy_enabled || xxx.is_animal(parent.pawn) == xxx.is_animal(c.pawn)));
float rand = Rand.Range(0.0f, 1.0f); if (eligibleCum.Count == 0) return null;
if (cum.pawn != null && !cum.notcum && rand < cum.FertVolume * Configurations.FertilizeChance * Props.basefertilizationChanceFactor)
{ foreach (Cum cum in eligibleCum)
if (!RJWPregnancySettings.bestial_pregnancy_enabled && (xxx.is_animal(parent.pawn) ^ xxx.is_animal(cum.pawn))) continue; totalFertPower += cum.FertVolume;
parent.pawn.records.AddTo(VariousDefOf.AmountofFertilizedEggs, 1);
return cum.pawn; if (Rand.Range(0.0f, 1.0f) > totalFertPower * Configurations.FertilizeChance * Props.basefertilizationChanceFactor)
}
}
return null; return null;
float selection = Rand.Range(0.0f, totalFertPower);
foreach (Cum cum in eligibleCum)
{
selection -= cum.FertVolume;
if (selection <= 0) return cum.pawn;
}
// We shouldn't reach here, but floating point errors exist, so just to be sure, select whomever came the most
float mostCum = 0;
Pawn mostCummer = null;
foreach (Cum cum in eligibleCum)
{
if(cum.FertVolume > mostCum)
{
mostCum = cum.FertVolume;
mostCummer = cum.pawn;
}
}
return mostCummer;
} }