/// "Jail for N days", the early end (CHANGELOG 1.0.0: "A jailed colonist that is recruited, released by
/// you or another mod, escapes or dies closes its sentence"). Recruitment is JailTests.RecruitEndsEarly;
/// these cover the release through GenGuest.PrisonerRelease (a warden on your order, Prisoner Sentencing
/// or Prison Expanded, design: "Compat runs"), a prison break that leaves the map, and death. Each case
/// closes at the real 2500-tick sentence sweep with its own outcome and one message, and leaves nothing
/// behind: no running punishment, no wait, no countdown, no queued task, no open case for the pawn.
/// </summary>
publicstaticclassSentenceEndTests
{
privatestaticintNow=>Find.TickManager.TicksGame;
[BlaxTest("jail end: a jailed colonist released through GenGuest.PrisonerRelease before its release day (by your warden, Prisoner Sentencing or Prison Expanded) closes as released early at the next sentence sweep with one message; capturing it again by hand later doesn't reopen the case")]
T.Check(!o.IsPrisonerOfColony&&o.IsFreeColonist&&o.Spawned,"fixture: "+o.LabelShort+" isn't a free colonist on the map after PrisonerRelease");
T.Check(c.releaseTick>Now+Enforcement.SentenceInterval,"fixture: the sentence would be served by the next sweep; release tick "+c.releaseTick+", now "+Now);
EnforceFixtures.TickPastSentenceSweep();
CheckClosedClean(c,o,CaseOutcomes.ReleasedEarly,"after the release");
T.Check(o.IsFreeColonist,o.LabelShort+" isn't a free colonist after the case closed");
T.Check(!EnforceFixtures.AnyEnforcementJobOn(o),"an enforcement job on the released colonist");
// A later capture by the same warden (by hand, or another mod) is not Laws' capture of a closed case.
intclosedAt=c.closeTick;
o.guest.CapturedBy(Faction.OfPlayer,warden);
T.Check(o.IsPrisonerOfColony,"fixture: the capture by hand left "+o.LabelShort+" free");
T.Check(c.IsClosed&&c.outcome==CaseOutcomes.ReleasedEarly,"the capture by hand reopened the case: "+c);
T.Check(!Enforcement.IsQueued(c,CaseTask.MaintainOnly),"the capture by hand queued Maintain only for the closed case");
Fixtures.Tick(Enforcement.MaintainOnlyDelay+1);
T.Check(c.IsClosed&&c.outcome==CaseOutcomes.ReleasedEarly,"the case after the capture by hand and two ticks: "+c);
T.Equal(closedAt,c.closeTick,"the close tick after the capture by hand");
T.Check(Fixtures.Comp.CasesOf(o).All(x=>x.IsClosed),"an open case for the prisoner taken by hand: "+string.Join(", ",Fixtures.Comp.CasesOf(o).Select(x=>x.ToString())));
T.Equal(1,EnforceFixtures.MessagesWith(text)-messages,"released-early messages after the capture by hand");
}
[BlaxTest("jail end: a jailed colonist in a prison break stays jailed while it is on the map; once it leaves the map the next sentence sweep closes the case as escaped with one message, and a later sweep past its release day changes nothing")]
publicstaticvoidEscapeEndsSentence()
{
LawCasec=JailInCell(outPawno,out_);
NoWorldPawnGcBeforeNextSweep();
Mapmap=o.Map;
StartPrisonBreak(o,map);
Sentences.Check(c);
T.Equal(CaseStatus.Jailed,c.status,"the case's status while the escapee is still on the map");
T.Check(o.IsPrisonerOfColony&&o.Spawned,"fixture: "+o.LabelShort+" is no prisoner on the map before it leaves");
T.Check(c.IsClosed&&c.outcome==EnforcementOutcomes.Escaped&&c.closeTick==closedAt,"a sweep past the release day changed the closed case: "+c);
T.Equal(1,EnforceFixtures.MessagesWith(text)-messages,"escape messages after a second sweep");
T.Check(!o.Spawned,"a sweep brought the escapee back");
}
[BlaxTest("jail end: a jailed colonist that leaves the map and is discarded by the world before the next sentence sweep still closes as escaped with one message, not as offender gone")]
[BlaxTest("jail end: a jailed colonist that escapes and dies off the map before the next sentence sweep closes as escaped with one escape message and no died-in-jail message")]
publicstaticvoidEscapeeDiesOffMap()
{
EscapeeDiesOffMap(discard:false);
}
[BlaxTest("jail end: a jailed colonist that escapes, dies off the map and is discarded by the world before the next sentence sweep closes as escaped with one escape message, not as offender gone or died in jail")]
publicstaticvoidEscapeeDiesOffMapDiscarded()
{
EscapeeDiesOffMap(discard:true);
}
/// <summary>
/// An escapee stays a prisoner of the colony off the map (Pawn.ExitMap clears the guest status only for a
/// released prisoner, Verse/Pawn.cs:2556-2589), and world pawns keep ticking (RimWorld.Planet/WorldPawns.cs:73-101),
/// so a bleeding escapee can die there before the sweep. A world pawn dies with no corpse
/// (Verse/Pawn.cs:2221-2224) and stays a world pawn among the dead.
[BlaxTest("jail end: a jailed colonist destroyed in its cell alive (another mod, a dev tool), not escaped, closes as offender gone at the next sentence sweep with no escape message, also when the world discards it before that sweep")]
T.Check(c.releaseTick>Now+Enforcement.SentenceInterval,"fixture: the sentence would be served by the next sweep; release tick "+c.releaseTick+", now "+Now);
o.Destroy(DestroyMode.Vanish);
T.Check(o.Destroyed&&!o.Dead&&!o.Discarded,"fixture: "+o.LabelShort+" isn't destroyed alive and undiscarded: destroyed "+o.Destroyed+", dead "+o.Dead+", discarded "+o.Discarded);
// Pawn.Destroy passes it to the world (Verse/Pawn.cs:2392-2395), and nothing keeps it there, so the next
// WorldPawnGC pass discards it (RimWorld.Planet/WorldPawnGC.cs:153-177), possibly before the 2500-tick
// sentence sweep: discarded alive, as an escapee the GC took is. Done here so every run covers it.
Find.WorldPawns.RemoveAndDiscardPawnViaGC(o);
T.Check(o.Discarded&&!o.Dead,"fixture: the destroyed prisoner wasn't discarded alive");
EnforceFixtures.TickPastSentenceSweep();
T.Check(c.IsClosed,"the case of the destroyed prisoner isn't closed: "+c);
T.Equal(CaseOutcomes.OffenderGone,c.outcome,"the outcome after the prisoner was destroyed in its cell");
[BlaxTest("jail end: a jailed colonist that dies closes as died in jail at the next sentence sweep, not as offender gone, with one message and nothing left queued")]
T.Check(c.IsClosed&&c.outcome==EnforcementOutcomes.Died&&c.closeTick==closedAt,"a second sweep changed the closed case: "+c);
T.Equal(1,EnforceFixtures.MessagesWith(text)-messages,"died-in-jail messages after a second sweep");
}
[BlaxTest("jail end: a jailed colonist that escapes after its release tick, while Release waits for a colonist, closes as escaped with one message, not as served")]
T.Check(caravan.ContainsPawn(o),"the colonist left the caravan");
}
[BlaxTest("jail end: a jailed colonist taken along in a caravan is released there a day after its release tick: the case closes as served and the colonist is a free caravan member")]
publicstaticvoidCaravanFallbackReleases()
{
LawCasec=JailInCell(outPawno,out_);
Caravancaravan=IntoCaravan(o);
T.Check(o.IsPrisonerOfColony&&o.IsCaravanMember()&&!o.Spawned,"fixture: "+o.LabelShort+" isn't a prisoner in the caravan");
Sentences.Check(c);
T.Equal(CaseStatus.Jailed,c.status,"the case's status in the caravan before the release tick");
c.releaseTick=Now-Sentences.FallbackTicks-1;
Sentences.Check(c);
T.Check(c.IsClosed,"the case of the prisoner in the caravan isn't closed a day past its release tick: "+c+", prisoner "+o.IsPrisonerOfColony);
T.Equal(CaseOutcomes.Served,c.outcome,"the outcome in the caravan");
T.Check(!o.IsPrisonerOfColony&&o.IsFreeColonist,o.LabelShort+" isn't a free colonist after the release in the caravan");
T.Check(caravan.ContainsPawn(o)&&o.IsCaravanMember(),o.LabelShort+" is no member of the caravan after the release");
}
[BlaxTest("jail end: a jailed colonist sold to an orbital trader closes as offender gone with a left-custody message and no escape message")]
[BlaxTest("jail end: a jailed colonist given away by transport pod to another faction's settlement stays jailed in the pod, then closes as offender gone with a left-custody message and no escape or released-early message")]
"fixture: the gift isn't a world pawn of "+f+": faction "+o.Faction+", prisoner "+o.IsPrisonerOfColony+", world pawn "+o.IsWorldPawn()+", spawned "+o.Spawned);
T.Equal(-1,c.escapedTick,"the escape note after the gift");
Sentences.Check(c);
T.Check(c.IsClosed,"the case of the colonist given away isn't closed: "+c);
T.Equal(CaseOutcomes.OffenderGone,c.outcome,"the outcome after the gift");
[BlaxTest("jail end: a jailed colonist lost with an abandoned or closed map closes as offender gone with a left-custody message and no escape or released-early message")]
publicstaticvoidLostWithMapIsGone()
{
LawCasec=JailInCell(outPawno,out_);
// Vanilla's own per-pawn step of a map's deinit (Verse/MapDeiniter.cs:218-237, reached from
// Game.DeinitAndRemoveMap through PassPawnsToWorld, :142), run on the one prisoner: no second map needed.
T.Check(o.IsWorldPawn()&&!o.IsPrisonerOfColony&&!o.Spawned,"fixture: the prisoner isn't a free world pawn after the deinit: world pawn "+o.IsWorldPawn()+
[BlaxTest("jail end: an escapee discarded by the world and then saved before the next sentence sweep (the save drops the reference) still closes as escaped with one message")]
[BlaxTest("jail end save: after the reload the case of the discarded escapee has no offender reference and still closes as escaped with one message", phase: 2, Order = -1)]
publicstaticvoidEscapeSaveRoundTrip()
{
T.Check(T.Carry.TryGetValue(EscapeSaveKey,outstringcarry)&&!carry.NullOrEmpty(),"the phase-1 escape setup did not run");
string[]parts=carry.Split('|');
T.Check(parts.Length==4&&int.Parse(parts[1])>=0&&parts[2]=="True","fixture: the escape wasn't noted and discarded at the save: "+carry);