Simplify a bunch of for loops into functions

This commit is contained in:
lutepickle 2022-07-14 18:51:16 -07:00
parent aa81fae8bd
commit 92fab44764
3 changed files with 12 additions and 51 deletions

Binary file not shown.

View file

@ -136,39 +136,24 @@ namespace RJW_Menstruation
{ {
get get
{ {
float res = 0;
if (cums.NullOrEmpty()) return 0; if (cums.NullOrEmpty()) return 0;
foreach (Cum cum in cums) return cums.Sum(cum => cum.Volume);
{
res += cum.Volume;
}
return res;
} }
} }
public float TotalFertCum public float TotalFertCum
{ {
get get
{ {
float res = 0;
if (cums.NullOrEmpty()) return 0; if (cums.NullOrEmpty()) return 0;
foreach (Cum cum in cums) return cums.Sum(cum => cum.FertVolume);
{
if (!cum.notcum) res += cum.FertVolume;
}
return res;
} }
} }
public float TotalCumPercent public float TotalCumPercent
{ {
get get
{ {
float res = 0;
if (cums.NullOrEmpty()) return 0; if (cums.NullOrEmpty()) return 0;
foreach (Cum cum in cums) return cums.Sum(cum => cum.Volume) / Props.maxCumCapacity;
{
res += cum.Volume;
}
return res / Props.maxCumCapacity;
} }
} }
public float CumCapacity public float CumCapacity
@ -372,11 +357,7 @@ namespace RJW_Menstruation
get get
{ {
if (eggs.NullOrEmpty() || cums.NullOrEmpty()) return false; if (eggs.NullOrEmpty() || cums.NullOrEmpty()) return false;
foreach (Cum cum in cums) return cums.Any(cum => cum.FertVolume > 0);
{
if (cum.FertVolume > 0) return true;
}
return false;
} }
} }
/// <summary> /// <summary>
@ -573,11 +554,8 @@ namespace RJW_Menstruation
/// <returns></returns> /// <returns></returns>
public Cum GetCum(Pawn pawn) public Cum GetCum(Pawn pawn)
{ {
if (!cums.NullOrEmpty()) foreach (Cum cum in cums) if (cums.NullOrEmpty()) return null;
{ return cums.Find(cum => !cum.notcum && cum.pawn == pawn);
if (!cum.notcum && cum.pawn.Equals(pawn)) return cum;
}
return null;
} }
/// <summary> /// <summary>
@ -1076,9 +1054,7 @@ namespace RJW_Menstruation
List<Cum> eligibleCum = cums.FindAll(cum => !cum.notcum && cum.FertVolume > 0 && cum.pawn != null && (RJWPregnancySettings.bestial_pregnancy_enabled || xxx.is_animal(parent.pawn) == xxx.is_animal(cum.pawn))); List<Cum> eligibleCum = cums.FindAll(cum => !cum.notcum && cum.FertVolume > 0 && cum.pawn != null && (RJWPregnancySettings.bestial_pregnancy_enabled || xxx.is_animal(parent.pawn) == xxx.is_animal(cum.pawn)));
if (eligibleCum.Count == 0) return null; if (eligibleCum.Count == 0) return null;
float totalFertPower = 0; float totalFertPower = eligibleCum.Sum(cum => cum.FertVolume);
foreach (Cum cum in eligibleCum)
totalFertPower += cum.FertVolume;
if (Rand.Range(0.0f, 1.0f) > 1.0f - Mathf.Pow(1.0f - Configurations.FertilizeChance, totalFertPower * Props.basefertilizationChanceFactor)) if (Rand.Range(0.0f, 1.0f) > 1.0f - Mathf.Pow(1.0f - Configurations.FertilizeChance, totalFertPower * Props.basefertilizationChanceFactor))
return null; return null;
@ -1093,20 +1069,7 @@ namespace RJW_Menstruation
} }
// We shouldn't reach here, but floating point errors exist, so just to be sure, select whomever came the most // We shouldn't reach here, but floating point errors exist, so just to be sure, select whomever came the most
return eligibleCum.MaxBy(cum => cum.FertVolume).pawn;
float mostCum = 0;
Pawn mostCummer = null;
foreach (Cum cum in eligibleCum)
{
if (cum.FertVolume > mostCum)
{
mostCum = cum.FertVolume;
mostCummer = cum.pawn;
}
}
return mostCummer;
} }

View file

@ -59,11 +59,9 @@ namespace RJW_Menstruation
Pawn pawn = props.partner; Pawn pawn = props.partner;
Hediff_BasePregnancy newestPregnancy = pawn.health.hediffSet.GetHediffs<Hediff_BasePregnancy>().MaxBy(hediff => hediff.loadID); Hediff_BasePregnancy newestPregnancy = pawn.health.hediffSet.GetHediffs<Hediff_BasePregnancy>().MaxBy(hediff => hediff.loadID);
if (newestPregnancy == null) return; if (newestPregnancy == null) return;
foreach (HediffComp_Menstruation comp in pawn.GetMenstruationComps())
{ if (pawn.GetMenstruationComps().Any(comp => comp.Pregnancy == newestPregnancy)) return; // One of the wombs did get it
if (comp.Pregnancy == newestPregnancy) return; // One of the wombs did get it else __state.Pregnancy = newestPregnancy;
}
__state.Pregnancy = newestPregnancy;
} }
/// <summary> /// <summary>