using RimWorld; using Verse; namespace BlaxLaws { /// /// Who the laws cover (design: "Detection", offender filter, shared by every hook): free colonists, /// children included, and colony slaves, spawned on a map. Never guests, Hospitality visitors, quest /// lodgers, prisoners, babies or subhumans. Caravan acts are skipped. /// public static class Offenders { /// The pawn can be an offender. public static bool IsCovered(Pawn p) { if (p == null || !p.Spawned || p.Map == null || p.Dead) return false; if (p.RaceProps == null || !p.RaceProps.Humanlike) return false; if (p.Faction == null || !p.Faction.IsPlayer) return false; // A slave in a break isn't IsColonist (Pawn.cs:518-527), so slaves are checked on their own. if (!p.IsFreeColonist && !p.IsSlaveOfColony) return false; if (p.IsPrisoner) return false; if (p.IsQuestLodger()) return false; if (p.DevelopmentalStage.Baby()) return false; // Mutants exist only with Anomaly; without it IsSubhuman reads a null field and is false. if (p.IsSubhuman) return false; return true; } /// /// The act is a player order: the pawn is drafted or its current job is player-forced (Job.cs:37). /// Exempt while "Player orders are exempt" is on. /// public static bool OnPlayerOrder(Pawn p) => p != null && (p.Drafted || (p.CurJob?.playerForced ?? false)); /// IsCovered and, while the setting is on, not on a player order. public static bool CountsAsOffender(Pawn p) => IsCovered(p) && !(BlaxLawsMod.S.playerOrdersExempt && OnPlayerOrder(p)); } }