From bb6fbb67d926775fbd5eb62c046dd6926e124bcd Mon Sep 17 00:00:00 2001 From: Vegapnk Date: Sun, 19 Mar 2023 17:17:33 +0100 Subject: [PATCH] Added more checks to pheromone, fixes #25 --- .../Special/Gene_Aphrodisiac_Pheromones.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Source/Genes/Special/Gene_Aphrodisiac_Pheromones.cs b/Source/Genes/Special/Gene_Aphrodisiac_Pheromones.cs index e3628dc..875d1dd 100644 --- a/Source/Genes/Special/Gene_Aphrodisiac_Pheromones.cs +++ b/Source/Genes/Special/Gene_Aphrodisiac_Pheromones.cs @@ -39,9 +39,25 @@ namespace RJW_Genes { foreach (Pawn pawn in map.mapPawns.AllPawns) { - if (pawn != null && this.pawn != null && pawn != this.pawn - && pos.DistanceTo(pawn.Position) < APHRODISIAC_DISTANCE && GenSight.LineOfSight(pos, pawn.Position, pawn.Map) - && !GeneUtility.HasGeneNullCheck(pawn, GeneDefOf.rjw_genes_aphrodisiac_pheromones)) + // Return for trivial errors + if (pawn == null || this.pawn == null || pawn == this.pawn) + continue; + // Check for position-existance + if (pawn.Position == null || pos == null || pawn.Map == null) + continue; + // Do nothing if pawn is carried + if (pawn.CarriedBy != null) + continue; + // Do nothing if Pawn is Baby or Child (#25) + if (!pawn.ageTracker.Adult) + continue; + // Do nothing for pawns that also have pheromones + if (GeneUtility.HasGeneNullCheck(pawn, GeneDefOf.rjw_genes_aphrodisiac_pheromones)) + continue; + + // Actual Logic: + // Pawn qualifies in right distance and needs line of sight. + if (pos.DistanceTo(pawn.Position) < APHRODISIAC_DISTANCE && GenSight.LineOfSight(pos, pawn.Position, pawn.Map)) { yield return pawn; }