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()
{
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)));
if (eligibleCum.Count == 0) return null;
foreach (Cum cum in eligibleCum)
totalFertPower += cum.FertVolume;
if (Rand.Range(0.0f, 1.0f) > totalFertPower * Configurations.FertilizeChance * Props.basefertilizationChanceFactor)
return null;
float selection = Rand.Range(0.0f, totalFertPower);
foreach (Cum cum in eligibleCum)
{
float rand = Rand.Range(0.0f, 1.0f);
if (cum.pawn != null && !cum.notcum && rand < cum.FertVolume * Configurations.FertilizeChance * Props.basefertilizationChanceFactor)
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)
{
if (!RJWPregnancySettings.bestial_pregnancy_enabled && (xxx.is_animal(parent.pawn) ^ xxx.is_animal(cum.pawn))) continue;
parent.pawn.records.AddTo(VariousDefOf.AmountofFertilizedEggs, 1);
return cum.pawn;
mostCum = cum.FertVolume;
mostCummer = cum.pawn;
}
}
return null;
return mostCummer;
}