using Verse;
namespace BlaxLaws
{
///
/// Subdue then jail (design: "Subdue"): the subdue job, and in the tick the hit downs the target, a
/// vanilla Capture to a prisoner bed at the front of the enforcer's queue (JailFlow.CaptureAfterSubdue).
/// From then on the case runs as Jail: activePunishment becomes "Jail" and PunishmentWorker_Jail sweeps
/// it. It jails without the beating when the break is over, when the pawn is already down, when its live
/// break fights back (the jail then waits), for a child (Biotech), and when the beating gives up. A slave
/// is never jailed in this release: subdued while in a break, else warned.
///
public class PunishmentWorker_SubdueThenJail : PunishmentWorker
{
public override void Start(LawCase c, Law law, LawStage stage)
{
Pawn o = c?.offender;
if (o == null || c.IsClosed || o.Dead || c.status == CaseStatus.Jailed)
return;
if (SubdueFlow.Runs(c) || JailFlow.ArrestRuns(c))
return;
if (DlcSupport.IsSlave(o))
{
JailFlow.SlaveFallback(c);
return;
}
// Conviction: guilt for the sentence when the case is filed; renewed right before the capture.
Guilt.AtLeast(o, JailFlow.SentenceTicks(c));
if (JailsWithoutBeating(c))
{
JailFlow.Become(c);
JailFlow.TryArrest(c, ignoreHold: false);
return;
}
SubdueFlow.TryIssue(c, EnforcerNeed.SubdueAndArrest);
}
public override void Sweep(LawCase c)
{
if (c == null || c.IsClosed)
return;
GameComponent_BlaxLaws comp = GameComponent_BlaxLaws.Instance;
if (!BlaxLawsMod.S.enforceLaws)
{
Stop(c);
comp?.CloseCase(c, CaseOutcomes.NotEnforced);
return;
}
Pawn o = c.offender;
if (o == null || o.Dead)
{
Stop(c);
comp?.CloseCase(c, CaseOutcomes.OffenderGone);
return;
}
if (SubdueFlow.Runs(c))
{
// A raid or a berserk colonist since the start: the warden is called off and the case waits.
SubdueFlow.CallOffInDanger(c);
return;
}
if (DlcSupport.IsSlave(o))
{
JailFlow.SlaveFallback(c);
return;
}
if (JailsWithoutBeating(c))
{
JailFlow.Become(c);
JailFlow.TryArrest(c, ignoreHold: false);
return;
}
SubdueFlow.TryIssue(c, EnforcerNeed.SubdueAndArrest);
}
public override void SentenceSweep(LawCase c) => Sentences.Check(c);
public override void Stop(LawCase c)
{
SubdueFlow.End(c);
JailFlow.EndArrest(c);
if (c != null && !c.IsClosed && c.status != CaseStatus.Jailed)
c.status = CaseStatus.Open;
}
/// Down already, the break over, a live break that fights back, or a child: jail without a beating.
private static bool JailsWithoutBeating(LawCase c)
{
Pawn o = c.offender;
return o.Downed || DlcSupport.IsChild(o) || Enforcers.FightsBack(o) || !SubdueFlow.InBreak(c);
}
}
}