95 lines
3.8 KiB
C#
95 lines
3.8 KiB
C#
using Verse;
|
|
|
|
namespace BlaxLaws
|
|
{
|
|
/// <summary>
|
|
/// Jail for N days (design: "Jail for N days"). Start convicts (guilt for the sentence) and arrests
|
|
/// through JailFlow: guilt renewed right before the job, a prisoner bed, the old bed noted, Arrest or
|
|
/// Capture with reservation checks. A break hostile to the colony waits until it ends or the pawn is
|
|
/// down; a role holder or mechanitor waits for "Arrest now"; a slave falls back to subdue in a break,
|
|
/// else warn. The sweep retries waits (a missing bed every 2500 ticks) and gives the old bed back when an
|
|
/// arrest ended without a prisoner; Sentences takes over at the capture. An arrest or capture not yet
|
|
/// carrying the offender is called off when danger comes.
|
|
/// </summary>
|
|
public class PunishmentWorker_Jail : 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 || JailFlow.ArrestRuns(c))
|
|
return;
|
|
if (DlcSupport.IsSlave(o))
|
|
{
|
|
JailFlow.SlaveFallback(c);
|
|
return;
|
|
}
|
|
// Conviction: guilt for the sentence when the case is filed. The arrest may come days later; it
|
|
// renews the guilt right before the job, and the sentence counts from the capture.
|
|
Guilt.AtLeast(o, JailFlow.SentenceTicks(c));
|
|
JailFlow.Become(c);
|
|
JailFlow.TryArrest(c, ignoreHold: false);
|
|
}
|
|
|
|
public override void Sweep(LawCase c)
|
|
{
|
|
if (c == null || c.IsClosed || c.status == CaseStatus.Jailed)
|
|
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 (c.status == CaseStatus.Enforcing)
|
|
{
|
|
if (JailFlow.ArrestRuns(c))
|
|
{
|
|
// Danger since the start: the arrest or the queued capture is called off and the case waits.
|
|
JailFlow.CallOffInDanger(c);
|
|
return;
|
|
}
|
|
if (o.IsPrisonerOfColony)
|
|
{
|
|
JailFlow.AlreadyPrisoner(c);
|
|
return;
|
|
}
|
|
// The Arrest or Capture ended without a prisoner (interrupted, refused, reservations lost).
|
|
JailFlow.GiveOldBedBack(c);
|
|
c.status = CaseStatus.Open;
|
|
c.waitReason = null;
|
|
}
|
|
if (c.waitReason == WaitReasons.NoBed && (Find.TickManager.TicksGame % Enforcement.SentenceInterval) != 0)
|
|
return;
|
|
JailFlow.TryArrest(c, ignoreHold: false);
|
|
}
|
|
|
|
public override void SentenceSweep(LawCase c) => Sentences.Check(c);
|
|
|
|
/// <summary>
|
|
/// Ends an unfinished arrest and gives the old bed back (a later stage takes over). A jailed case is
|
|
/// stopped only when its law is repealed: the pawn Laws jailed gets "Release".
|
|
/// </summary>
|
|
public override void Stop(LawCase c)
|
|
{
|
|
if (c == null)
|
|
return;
|
|
if (c.status == CaseStatus.Jailed)
|
|
{
|
|
Sentences.ReleaseOnRepeal(c);
|
|
return;
|
|
}
|
|
JailFlow.EndArrest(c);
|
|
if (!c.IsClosed)
|
|
c.status = CaseStatus.Open;
|
|
}
|
|
}
|
|
}
|