48 lines
1.9 KiB
C#
48 lines
1.9 KiB
C#
using RimWorld;
|
|
using Verse;
|
|
|
|
namespace BlaxLaws
|
|
{
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static class Offenders
|
|
{
|
|
/// <summary>The pawn can be an offender.</summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static bool OnPlayerOrder(Pawn p) => p != null && (p.Drafted || (p.CurJob?.playerForced ?? false));
|
|
|
|
/// <summary>IsCovered and, while the setting is on, not on a player order.</summary>
|
|
public static bool CountsAsOffender(Pawn p) =>
|
|
IsCovered(p) && !(BlaxLawsMod.S.playerOrdersExempt && OnPlayerOrder(p));
|
|
}
|
|
}
|