515 lines
31 KiB
C#
515 lines
31 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BlaxCastes;
|
|
using RimWorld;
|
|
using Verse;
|
|
|
|
namespace BlaxCastesTests
|
|
{
|
|
/// <summary>
|
|
/// Status changes between player colonist, slave and prisoner go through the status rows, and a
|
|
/// pawn that comes back gets its previous caste. Arrests and imprisonments go through
|
|
/// Pawn_GuestTracker.CapturedBy, as the arrest job does. Joins are applied with Fixtures.ApplyJoins,
|
|
/// because fixture prisoners must not be ticked.
|
|
/// </summary>
|
|
public static class StatusTests
|
|
{
|
|
private static ApparelPolicy Worker() => Fixtures.Need(Fixtures.Outfit("OutfitWorker"), "Worker outfit");
|
|
private static ApparelPolicy Nudist() => Fixtures.Need(Fixtures.Outfit("OutfitNudist"), "Nudist outfit");
|
|
private static FoodPolicy Simple() => Fixtures.Need(Fixtures.Food("FoodRestrictionSimple"), "Simple food policy");
|
|
private static FoodPolicy Fine() => Fixtures.Need(Fixtures.Food("FoodRestrictionFine"), "Fine food policy");
|
|
private static FoodPolicy Paste() => Fixtures.Need(Fixtures.Food("FoodRestrictionPaste"), "Paste food policy");
|
|
private static FoodPolicy Lavish() => Fixtures.Need(Fixtures.Food("FoodRestrictionLavish"), "Lavish food policy");
|
|
|
|
private static Caste Make(string label, ApparelPolicy apparel, FoodPolicy food)
|
|
{
|
|
Caste c = Fixtures.NewCaste(label);
|
|
if (apparel != null)
|
|
CasteManager.SetSlot(c, CasteSlot.Apparel, apparel);
|
|
CasteManager.SetSlot(c, CasteSlot.Food, food);
|
|
return c;
|
|
}
|
|
|
|
private static void Row(string reason, Caste caste) =>
|
|
T.Check(CasteManager.SetJoinRow(reason, JoinRowMode.SpecificCaste, caste), "setup: SetJoinRow " + reason + " failed");
|
|
|
|
private static void NoCasteRow(string reason) =>
|
|
T.Check(CasteManager.SetJoinRow(reason, JoinRowMode.NoCaste), "setup: SetJoinRow " + reason + " failed");
|
|
|
|
private static string Who(Pawn p) => p.LabelShort + " [" + p.ThingID + "]";
|
|
|
|
private static string State(Pawn p)
|
|
{
|
|
CasteMembership m = Fixtures.Comp.MembershipOf(p);
|
|
return m == null ? "no record" : $"caste={m.caste?.label ?? "none"}, auto={m.auto}, reason={m.reason}";
|
|
}
|
|
|
|
private static void CheckIn(Pawn p, Caste caste, string reason, string when)
|
|
{
|
|
CasteMembership m = Fixtures.Comp.MembershipOf(p);
|
|
T.Check(m != null && m.caste == caste, Who(p) + " " + when + ": expected " + caste.label + ", got " + State(p));
|
|
if (reason != null)
|
|
T.Equal(reason, m.reason, Who(p) + "'s membership reason " + when);
|
|
}
|
|
|
|
private static Pawn Warden() => Fixtures.Colonist();
|
|
|
|
/// <summary>A spawned slave whose own faction is the colony, so freeing it keeps it as a colonist.</summary>
|
|
private static Pawn HomeSlave()
|
|
{
|
|
if (!ModsConfig.IdeologyActive)
|
|
T.Skip("slaves need Ideology");
|
|
Pawn p = Fixtures.Spawn(Fixtures.Generate(PawnKindDefOf.Slave, Faction.OfPlayer));
|
|
p.guest.SetGuestStatus(Faction.OfPlayer, GuestStatus.Slave);
|
|
T.Check(p.IsSlaveOfColony && p.HomeFaction == Faction.OfPlayer, "setup: home slave fixture: slave=" + p.IsSlaveOfColony + ", home=" + p.HomeFaction);
|
|
Fixtures.Unqueue(p);
|
|
return p;
|
|
}
|
|
|
|
// ---- every transition goes through the status rows ---------------------------------------
|
|
|
|
[BlaxTest("status: an arrested Miner colonist goes to the new-prisoner caste, and once released returns to Miner")]
|
|
public static void ArrestAndRelease()
|
|
{
|
|
Caste miner = Make("Miner (status test)", Worker(), Fine());
|
|
Caste prisoners = Make("Prisoners (status test)", null, Paste());
|
|
Caste wrong = Make("Wrong row (status test)", Nudist(), Lavish());
|
|
Row(JoinReason.NewPrisoner, prisoners);
|
|
Row(JoinReason.NewColonist, wrong);
|
|
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
T.Check(CasteManager.Assign(p, miner, false, JoinReason.Manual), "setup: Assign Miner failed");
|
|
|
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
T.Check(p.IsPrisonerOfColony && p.Faction == Faction.OfPlayer, Who(p) + " is not an arrested colonist after CapturedBy");
|
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
|
T.NotNull(record, Who(p) + "'s former-caste record after the arrest");
|
|
T.Check(record.casteId == miner.id && record.side == JoinSide.Colonist && !record.auto, "former-caste record: " + record);
|
|
T.Equal(JoinDefaults.StatusFallback, JoinDefaults.QueuedFor(p)?.reason, "queued reason after the arrest");
|
|
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, prisoners, JoinReason.NewPrisoner, "after the arrest");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Paste(), Who(p) + " does not eat the prisoner food");
|
|
|
|
GenGuest.PrisonerRelease(p);
|
|
T.Check(p.IsColonist && !p.IsPrisoner, Who(p) + " is not a free colonist after the release");
|
|
T.Check(JoinDefaults.IsQueued(p), Who(p) + " was not queued by the release");
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, miner, JoinReason.PreviousCaste, "after the release");
|
|
T.Check(!Fixtures.Comp.MembershipOf(p).auto, "the restored hand-picked caste is marked as set by a join row");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Fine() && p.outfits.CurrentApparelPolicy == Worker(), Who(p) + " does not have Miner's policies back");
|
|
T.Check(Fixtures.Comp.FormerOf(p) == null, "the used former-caste record is still there");
|
|
}
|
|
|
|
[BlaxTest("status: freeing a slave whose home is the colony lands in the new-colonist row and leaves no record")]
|
|
public static void FreedSlave()
|
|
{
|
|
Caste slaves = Make("Slaves (freed test)", null, Paste());
|
|
Caste colonists = Make("Colonists (freed test)", Worker(), Fine());
|
|
Row(JoinReason.NewColonist, colonists);
|
|
|
|
Pawn p = HomeSlave();
|
|
T.Check(CasteManager.Assign(p, slaves, true, JoinReason.NewSlave), "setup: Assign failed");
|
|
GenGuest.EmancipateSlave(Warden(), p);
|
|
T.Check(p.IsColonist && !p.IsSlave, Who(p) + " is not a free colonist after EmancipateSlave");
|
|
T.Check(Fixtures.Comp.FormerOf(p) == null, "freeing a slave wrote a former-caste record");
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, colonists, JoinReason.NewColonist, "after being freed");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Fine(), Who(p) + " still eats the slave food");
|
|
}
|
|
|
|
[BlaxTest("status: imprisoning a slave (the Imprison mode's arrest) goes to the new-prisoner row and records its slave caste")]
|
|
public static void ImprisonedSlave()
|
|
{
|
|
Caste minerSlaves = Make("Miner slaves (imprison test)", null, Simple());
|
|
Caste prisoners = Make("Prisoners (imprison test)", null, Paste());
|
|
Row(JoinReason.NewPrisoner, prisoners);
|
|
|
|
Pawn p = Fixtures.ColonySlave();
|
|
Fixtures.Unqueue(p);
|
|
T.Check(CasteManager.Assign(p, minerSlaves, true, JoinReason.NewSlave), "setup: Assign failed");
|
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
T.Check(p.IsPrisonerOfColony, Who(p) + " is not a prisoner of the colony after CapturedBy");
|
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
|
T.Check(record != null && record.casteId == minerSlaves.id && record.side == JoinSide.Slave, "former-caste record: " + (record?.ToString() ?? "none"));
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, prisoners, JoinReason.NewPrisoner, "after being imprisoned");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Paste(), Who(p) + " does not eat the prisoner food");
|
|
}
|
|
|
|
[BlaxTest("status: an arrested colonist who is then enslaved goes to the new-slave row, not its old colonist caste")]
|
|
public static void ArrestedThenEnslaved()
|
|
{
|
|
if (!ModsConfig.IdeologyActive)
|
|
T.Skip("slaves need Ideology");
|
|
Caste miner = Make("Miner (enslave test)", Worker(), Fine());
|
|
Caste prisoners = Make("Prisoners (enslave test)", null, Paste());
|
|
Caste slaves = Make("Slaves (enslave test)", null, Simple());
|
|
Row(JoinReason.NewPrisoner, prisoners);
|
|
Row(JoinReason.NewSlave, slaves);
|
|
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
CasteManager.Assign(p, miner, false, JoinReason.Manual);
|
|
Pawn warden = Warden();
|
|
p.guest.CapturedBy(Faction.OfPlayer, warden);
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, prisoners, JoinReason.NewPrisoner, "after the arrest");
|
|
|
|
GenGuest.EnslavePrisoner(warden, p);
|
|
T.Check(p.IsSlaveOfColony, Who(p) + " is not a slave after EnslavePrisoner");
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, slaves, JoinReason.NewSlave, "after being enslaved");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Simple(), Who(p) + " does not eat the slave food");
|
|
}
|
|
|
|
[BlaxTest("status: a Miner slave sold and bought back returns to Miner slave, not the bought-as-slave row")]
|
|
public static void SoldAndBoughtBack()
|
|
{
|
|
if (!ModsConfig.IdeologyActive)
|
|
T.Skip("slaves need Ideology");
|
|
Caste minerSlaves = Make("Miner slaves (sale test)", Worker(), Simple());
|
|
Caste wrong = Make("Wrong row (sale test)", Nudist(), Paste());
|
|
Row(JoinReason.BoughtSlave, wrong);
|
|
Row(JoinReason.NewColonist, wrong);
|
|
Row(JoinReason.NewSlave, wrong);
|
|
|
|
Pawn p = Fixtures.ColonySlave();
|
|
Fixtures.Unqueue(p);
|
|
T.Check(CasteManager.Assign(p, minerSlaves, true, JoinReason.NewSlave), "setup: Assign failed");
|
|
p.foodRestriction.CurrentFoodPolicy = Fine(); // by hand
|
|
var trader = new JoinTests.TestTrader();
|
|
Pawn negotiator = Fixtures.Colonist();
|
|
|
|
p.PreTraded(TradeAction.PlayerSells, negotiator, trader);
|
|
T.Check(p.Faction != Faction.OfPlayer, Who(p) + " is still in the player faction after being sold");
|
|
T.Equal(0, JoinScopes.Depth, "open join scopes after the sale");
|
|
T.Check(!JoinDefaults.IsQueued(p), "the sale queued a join (the slave-to-free step inside the sale)");
|
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
|
T.Check(record != null && record.casteId == minerSlaves.id && record.side == JoinSide.Slave, "former-caste record after the sale: " + (record?.ToString() ?? "none"));
|
|
Fixtures.ApplyJoins(p);
|
|
T.Check(Fixtures.Comp.MembershipOf(p) == null, "the sold slave kept its membership: " + State(p));
|
|
|
|
p.guest.Recruitable = true;
|
|
p.guest.joinStatus = JoinStatus.JoinAsSlave;
|
|
p.PreTraded(TradeAction.PlayerBuys, negotiator, trader);
|
|
T.Check(p.IsSlaveOfColony, Who(p) + " is not a slave of the colony after the purchase");
|
|
T.Equal(JoinScopes.Bought, JoinDefaults.QueuedFor(p)?.reason, "queued reason after buying back");
|
|
T.Check(JoinDefaults.WillChange(p), "the bought-back slave does not show as pending");
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, minerSlaves, JoinReason.PreviousCaste, "after buying it back");
|
|
T.Check(Fixtures.Comp.MembershipOf(p).auto, "the restored row-set caste is marked as set by hand");
|
|
T.Check(p.outfits.CurrentApparelPolicy == Worker(), Who(p) + " does not have Miner slave's outfit back: " + p.outfits.CurrentApparelPolicy.label);
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Fine(), Who(p) + " lost its hand-set food: " + p.foodRestriction.CurrentFoodPolicy.label);
|
|
}
|
|
|
|
[BlaxTest("status: a former-caste record older than formerCasteDays is ignored and pruned; with the setting off the row applies")]
|
|
public static void StaleRecordIgnored()
|
|
{
|
|
Caste miner = Make("Miner (stale test)", Worker(), Fine());
|
|
Caste prisoners = Make("Prisoners (stale test)", null, Paste());
|
|
Caste colonists = Make("Colonists (stale test)", Nudist(), Simple());
|
|
Row(JoinReason.NewPrisoner, prisoners);
|
|
Row(JoinReason.NewColonist, colonists);
|
|
GameComponent_BlaxCastes comp = Fixtures.Comp;
|
|
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
CasteManager.Assign(p, miner, false, JoinReason.Manual);
|
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
Fixtures.ApplyJoins(p);
|
|
FormerCaste record = comp.FormerOf(p);
|
|
T.NotNull(record, "setup: former-caste record after the arrest");
|
|
record.tick = Find.TickManager.TicksGame - (Fixtures.Settings.formerCasteDays + 1) * GenDate.TicksPerDay;
|
|
T.Check(JoinDefaults.PreviousCasteFor(p) == null, "a stale record still gives a previous caste");
|
|
|
|
GenGuest.PrisonerRelease(p);
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, colonists, JoinReason.NewColonist, "after the release with a stale record");
|
|
T.Check(comp.PruneFormerCastes() >= 1 && comp.FormerOf(p) == null, "the stale record was not pruned");
|
|
|
|
// The setting off: a fresh record is ignored too.
|
|
Fixtures.Settings.returnToPreviousCaste = false;
|
|
Pawn q = Fixtures.Colonist();
|
|
Fixtures.Unqueue(q);
|
|
CasteManager.Assign(q, miner, false, JoinReason.Manual);
|
|
q.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
Fixtures.ApplyJoins(q);
|
|
T.NotNull(comp.FormerOf(q), "no record was written with returnToPreviousCaste off (records are kept for when it is turned on)");
|
|
GenGuest.PrisonerRelease(q);
|
|
Fixtures.ApplyJoins(q);
|
|
CheckIn(q, colonists, JoinReason.NewColonist, "after the release with returnToPreviousCaste off");
|
|
}
|
|
|
|
[BlaxTest("status: deleting a caste drops the former-caste records that point at it")]
|
|
public static void DeletedCasteDropsRecords()
|
|
{
|
|
Caste doomed = Make("Doomed (record test)", null, Fine());
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
CasteManager.Assign(p, doomed, false, JoinReason.Manual);
|
|
Faction other = Fixtures.FriendlyFaction();
|
|
T.NotNull(other, "a friendly faction");
|
|
p.SetFaction(other);
|
|
T.NotNull(Fixtures.Comp.FormerOf(p), "leaving the faction wrote no former-caste record");
|
|
CasteManager.DeleteCaste(doomed);
|
|
T.Check(Fixtures.Comp.FormerOf(p) == null, "the record of a deleted caste survived");
|
|
}
|
|
|
|
// ---- hand changes survive a return ----------------------------------------------------
|
|
|
|
private static DrugPolicy NoDrugs() => Fixtures.Need(Fixtures.Drug("NoDrugs"), "No drugs policy");
|
|
private static DrugPolicy Social() => Fixtures.Need(Fixtures.Drug("SocialDrugs"), "Social drugs policy");
|
|
|
|
/// <summary>Work from 22 to 5, sleep the rest: nothing like the starting schedule.</summary>
|
|
private static List<string> NightShift() =>
|
|
Enumerable.Range(0, ScheduleSlot.Hours).Select(h => (h >= 22 || h <= 5 ? TimeAssignmentDefOf.Work : TimeAssignmentDefOf.Sleep).defName).ToList();
|
|
|
|
[BlaxTest("status: an arrested and released colonist gets its caste back with its hand changes; followed slots get the caste's value")]
|
|
public static void ReturnKeepsHandChanges()
|
|
{
|
|
Caste colonists = Make("Colonists (hand change test)", Worker(), Fine());
|
|
CasteManager.SetSlot(colonists, CasteSlot.Drug, NoDrugs());
|
|
CasteManager.SetSlot(colonists, CasteSlot.MedCare, MedicalCareCategory.NoMeds);
|
|
CasteManager.SetSlot(colonists, CasteSlot.Schedule, NightShift());
|
|
Caste prisoners = Make("Prisoners (hand change test)", null, Paste());
|
|
Caste wrong = Make("Wrong row (hand change test)", Nudist(), Lavish());
|
|
Row(JoinReason.NewPrisoner, prisoners);
|
|
Row(JoinReason.NewColonist, wrong);
|
|
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
T.Check(CasteManager.Assign(p, colonists, true, JoinReason.NewColonist), "setup: Assign failed");
|
|
// By hand: another outfit, Social drugs, best care and one hour of the schedule.
|
|
p.outfits.CurrentApparelPolicy = Nudist();
|
|
p.drugs.CurrentPolicy = Social();
|
|
p.playerSettings.medCare = MedicalCareCategory.Best;
|
|
TimeAssignmentDef hour3 = TimeAssignmentDefOf.Joy;
|
|
p.timetable.SetAssignment(3, hour3);
|
|
T.Equal(4, CasteManager.Overrides(p).Count, "setup: hand changes (" + string.Join(", ", CasteManager.Overrides(p)) + ")");
|
|
|
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
|
T.NotNull(record, "former-caste record after the arrest");
|
|
T.Check(record.Followed(CasteSlot.Food) && !record.Followed(CasteSlot.Apparel) && !record.Followed(CasteSlot.MedCare),
|
|
"followed slots in the record: " + string.Join(", ", record.followed));
|
|
T.Equal((int)MedicalCareCategory.Best, record.medCare, "medical care in the record (taken before the game's reset)");
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, prisoners, JoinReason.NewPrisoner, "after the arrest");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Paste(), Who(p) + " does not eat the prisoner food");
|
|
|
|
// While it was away the caste's food changed: a follower gets the new value.
|
|
CasteManager.SetSlot(colonists, CasteSlot.Food, Simple());
|
|
GenGuest.PrisonerRelease(p);
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, colonists, JoinReason.PreviousCaste, "after the release");
|
|
T.Check(Fixtures.Comp.MembershipOf(p).auto, "the restored row-set caste is marked as set by hand");
|
|
T.Check(p.outfits.CurrentApparelPolicy == Nudist(), Who(p) + " lost its hand-set outfit: " + p.outfits.CurrentApparelPolicy.label);
|
|
T.Check(p.drugs.CurrentPolicy == Social(), Who(p) + " lost its hand-set drug policy: " + p.drugs.CurrentPolicy.label);
|
|
T.Equal(MedicalCareCategory.Best, p.playerSettings.medCare, Who(p) + "'s hand-set medical care");
|
|
T.Equal(hour3, p.timetable.GetAssignment(3), Who(p) + "'s hand-set hour 3");
|
|
T.Equal(TimeAssignmentDefOf.Work, p.timetable.GetAssignment(23), Who(p) + "'s hour 23 (the caste's)");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Simple(), Who(p) + " does not follow the caste's new food: " + p.foodRestriction.CurrentFoodPolicy.label);
|
|
}
|
|
|
|
[BlaxTest("status: with No caste rows, an arrest and release rewrites nothing on a pawn that never left its caste")]
|
|
public static void NeverLeftKeepsHandChanges()
|
|
{
|
|
Caste miner = Make("Miner (never left test)", Worker(), Fine());
|
|
CasteManager.SetSlot(miner, CasteSlot.Schedule, NightShift());
|
|
NoCasteRow(JoinReason.NewPrisoner);
|
|
NoCasteRow(JoinReason.NewColonist);
|
|
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
CasteManager.Assign(p, miner, false, JoinReason.Manual);
|
|
p.outfits.CurrentApparelPolicy = Nudist();
|
|
p.foodRestriction.CurrentFoodPolicy = Lavish();
|
|
p.timetable.SetAssignment(12, TimeAssignmentDefOf.Joy);
|
|
|
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, miner, JoinReason.Manual, "after the arrest with a No caste prisoner row");
|
|
GenGuest.PrisonerRelease(p);
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, miner, JoinReason.PreviousCaste, "after the release");
|
|
T.Check(!Fixtures.Comp.MembershipOf(p).auto, "the hand-picked caste is marked as set by a join row");
|
|
T.Check(p.outfits.CurrentApparelPolicy == Nudist() && p.foodRestriction.CurrentFoodPolicy == Lavish(),
|
|
Who(p) + " lost its hand-set policies: " + p.outfits.CurrentApparelPolicy.label + ", " + p.foodRestriction.CurrentFoodPolicy.label);
|
|
T.Equal(TimeAssignmentDefOf.Joy, p.timetable.GetAssignment(12), Who(p) + "'s hand-set hour 12");
|
|
}
|
|
|
|
[BlaxTest("status: a pawn set to No caste goes back to No caste after an arrest and release, with its own policies")]
|
|
public static void CastelessComesBack()
|
|
{
|
|
Caste prisoners = Make("Prisoners (casteless test)", null, Paste());
|
|
Caste colonists = Make("Colonists (casteless test)", Worker(), Fine());
|
|
Row(JoinReason.NewPrisoner, prisoners);
|
|
Row(JoinReason.NewColonist, colonists);
|
|
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
p.outfits.CurrentApparelPolicy = Nudist();
|
|
p.foodRestriction.CurrentFoodPolicy = Lavish();
|
|
T.Check(CasteManager.MakeCasteless(p), "setup: MakeCasteless failed");
|
|
|
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
|
T.Check(record != null && record.casteless && record.side == JoinSide.Colonist, "former-caste record: " + (record?.ToString() ?? "none"));
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, prisoners, JoinReason.NewPrisoner, "after the arrest");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Paste(), Who(p) + " does not eat the prisoner food");
|
|
|
|
GenGuest.PrisonerRelease(p);
|
|
T.Check(JoinDefaults.WillChange(p), Who(p) + " does not show as pending before going back to No caste");
|
|
Fixtures.ApplyJoins(p);
|
|
CasteMembership m = Fixtures.Comp.MembershipOf(p);
|
|
T.Check(m != null && m.Casteless, Who(p) + " is not back at No caste: " + State(p));
|
|
T.Check(p.outfits.CurrentApparelPolicy == Nudist(), Who(p) + "'s outfit: " + p.outfits.CurrentApparelPolicy.label);
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Lavish(), Who(p) + "'s food (the prisoner caste's should be undone): " + p.foodRestriction.CurrentFoodPolicy.label);
|
|
T.Check(!CasteManager.PawnsToAssignByStatus().Contains(p), "Assign by status offers the pawn set to No caste");
|
|
}
|
|
|
|
[BlaxTest("status: the prisoner caste's food is undone when the pawn returns to a caste that leaves food alone")]
|
|
public static void PrisonerFoodUndone()
|
|
{
|
|
Caste miner = Make("Miner (food undo test)", Worker(), null);
|
|
CasteManager.SetSlot(miner, CasteSlot.Food, null);
|
|
T.Check(!miner.IsManaged(CasteSlot.Food), "setup: the Miner caste manages food");
|
|
Caste prisoners = Make("Prisoners (food undo test)", null, Paste());
|
|
Row(JoinReason.NewPrisoner, prisoners);
|
|
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
CasteManager.Assign(p, miner, false, JoinReason.Manual);
|
|
p.foodRestriction.CurrentFoodPolicy = Fine();
|
|
|
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
Fixtures.ApplyJoins(p);
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Paste(), Who(p) + " does not eat the prisoner food");
|
|
GenGuest.PrisonerRelease(p);
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, miner, JoinReason.PreviousCaste, "after the release");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Fine(), Who(p) + " kept the prisoner food: " + p.foodRestriction.CurrentFoodPolicy.label);
|
|
}
|
|
|
|
[BlaxTest("status: a row that moves a pawn on from a row-set caste resets what that caste set and the new one leaves alone")]
|
|
public static void RowMoveRevertsOldCaste()
|
|
{
|
|
FoodPolicy defaultFood = Current.Game.foodRestrictionDatabase.DefaultFoodRestriction();
|
|
T.Check(defaultFood != Paste(), "setup: Paste is the default food");
|
|
Caste prisoners = Make("Prisoners (row move test)", null, Paste());
|
|
Caste colonists = Make("Colonists (row move test)", Worker(), null);
|
|
CasteManager.SetSlot(colonists, CasteSlot.Food, null);
|
|
Row(JoinReason.NewPrisoner, prisoners);
|
|
Row(JoinReason.NewColonist, colonists);
|
|
|
|
// No record at all, so nothing comes back: the rows move it.
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
T.Check(Fixtures.Comp.MembershipOf(p) == null, "setup: the colonist has a membership record");
|
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
T.Check(Fixtures.Comp.FormerOf(p) == null, "a pawn without a record left a former-caste record");
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, prisoners, JoinReason.NewPrisoner, "after the arrest");
|
|
GenGuest.PrisonerRelease(p);
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, colonists, JoinReason.NewColonist, "after the release");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == defaultFood, Who(p) + " kept the prisoner food: " + p.foodRestriction.CurrentFoodPolicy.label);
|
|
|
|
// revertOnLeave off: the food stays.
|
|
Fixtures.Settings.revertOnLeave = false;
|
|
Pawn q = Fixtures.Colonist();
|
|
Fixtures.Unqueue(q);
|
|
q.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
Fixtures.ApplyJoins(q);
|
|
GenGuest.PrisonerRelease(q);
|
|
Fixtures.ApplyJoins(q);
|
|
CheckIn(q, colonists, JoinReason.NewColonist, "after the release with revertOnLeave off");
|
|
T.Check(q.foodRestriction.CurrentFoodPolicy == Paste(), Who(q) + "'s food with revertOnLeave off: " + q.foodRestriction.CurrentFoodPolicy.label);
|
|
}
|
|
|
|
// ---- the No caste rows ---------------------------------------------------------------
|
|
|
|
[BlaxTest("status: with No caste rows, an arrested and released colonist keeps its hand-picked caste and its policies")]
|
|
public static void HandPickSurvivesNoCasteRows()
|
|
{
|
|
Caste miner = Make("Miner (no caste rows test)", Worker(), Fine());
|
|
CasteManager.SetSlot(miner, CasteSlot.MedCare, MedicalCareCategory.HerbalOrWorse);
|
|
NoCasteRow(JoinReason.NewPrisoner);
|
|
NoCasteRow(JoinReason.NewColonist);
|
|
|
|
Pawn p = Fixtures.Colonist();
|
|
Fixtures.Unqueue(p);
|
|
CasteManager.Assign(p, miner, false, JoinReason.Manual);
|
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
|
Fixtures.ApplyJoins(p);
|
|
CheckIn(p, miner, JoinReason.Manual, "after the arrest with a No caste prisoner row");
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Fine(), Who(p) + "'s food changed: " + p.foodRestriction.CurrentFoodPolicy.label);
|
|
|
|
GenGuest.PrisonerRelease(p);
|
|
Fixtures.ApplyJoins(p);
|
|
T.Check(Fixtures.Comp.CasteOf(p) == miner, Who(p) + " lost Miner after the release: " + State(p));
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Fine() && p.outfits.CurrentApparelPolicy == Worker(), Who(p) + " lost Miner's policies");
|
|
}
|
|
|
|
[BlaxTest("status: a No caste row reverts only the slots still on the caste's value; a hand-changed slot stays")]
|
|
public static void RevertKeepsHandChanges()
|
|
{
|
|
Caste slaves = Make("Slaves (revert test)", Worker(), Paste());
|
|
NoCasteRow(JoinReason.NewColonist);
|
|
ApparelPolicy defaultOutfit = Current.Game.outfitDatabase.DefaultOutfit();
|
|
T.Check(defaultOutfit != Worker(), "setup: Worker is the default outfit");
|
|
|
|
// Freeing a home slave changes neither faction nor medical care, so only Castes touches the policies.
|
|
Pawn p = HomeSlave();
|
|
T.Check(CasteManager.Assign(p, slaves, true, JoinReason.NewSlave), "setup: Assign failed");
|
|
p.foodRestriction.CurrentFoodPolicy = Lavish(); // by hand
|
|
GenGuest.EmancipateSlave(Warden(), p);
|
|
Fixtures.ApplyJoins(p);
|
|
T.Check(Fixtures.Comp.MembershipOf(p) == null, Who(p) + " is still in a caste: " + State(p));
|
|
T.Check(p.outfits.CurrentApparelPolicy == defaultOutfit, Who(p) + "'s outfit did not return to the default: " + p.outfits.CurrentApparelPolicy.label);
|
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Lavish(), Who(p) + " lost its hand-set food: " + p.foodRestriction.CurrentFoodPolicy.label);
|
|
}
|
|
|
|
// ---- save and reload -----------------------------------------------------------------
|
|
|
|
// Runs last in this class (source order): the record is checked after the reload.
|
|
[BlaxTest("status: set up a former-caste record for the reload")]
|
|
public static void ReloadSetup()
|
|
{
|
|
Caste c = Fixtures.KeepCaste(Make("Former caste reload test", null, Fine()));
|
|
Pawn p = Fixtures.Colonist(); // destroyed by the cleanup: the record is keyed by ThingID, not by reference
|
|
Fixtures.Unqueue(p);
|
|
CasteManager.Assign(p, c, true, JoinReason.NewColonist);
|
|
Faction other = Fixtures.FriendlyFaction();
|
|
T.NotNull(other, "a friendly faction");
|
|
p.SetFaction(other);
|
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
|
T.NotNull(record, "setup: no former-caste record");
|
|
T.Check(record.Followed(CasteSlot.Food) && record.foodId == Fine().id, "setup: the record's food: id " + record.foodId + ", followed " + string.Join(", ", record.followed));
|
|
T.Carry["formerPawn"] = p.ThingID;
|
|
T.Carry["formerCaste"] = c.id.ToString();
|
|
T.Carry["formerFood"] = record.foodId.ToString();
|
|
T.Carry["formerSchedule"] = record.schedule == null ? "none" : string.Join(",", record.schedule);
|
|
}
|
|
|
|
[BlaxTest("status: former-caste records survive save and reload, keyed by ThingID", phase: 2)]
|
|
public static void RecordSurvives()
|
|
{
|
|
string casteId = null;
|
|
T.Check(T.Carry.TryGetValue("formerPawn", out string pawnId) && T.Carry.TryGetValue("formerCaste", out casteId), "phase 1 setup did not run");
|
|
T.Check(Fixtures.Comp.FormerCastes.TryGetValue(pawnId, out FormerCaste record), "the record for " + pawnId + " did not survive the reload");
|
|
T.Equal(casteId, record.casteId.ToString(), "record caste id");
|
|
T.Equal(JoinSide.Colonist, record.side, "record status");
|
|
T.Check(record.auto, "record auto flag");
|
|
T.NotNull(Fixtures.Comp.CasteById(record.casteId), "the record's caste after the reload");
|
|
T.Check(!record.casteless, "record turned into a No caste record");
|
|
T.Equal(T.Carry["formerFood"], record.foodId.ToString(), "record food id");
|
|
T.Check(record.Followed(CasteSlot.Food), "record lost its followed slots: " + string.Join(", ", record.followed));
|
|
T.Equal(T.Carry["formerSchedule"], record.schedule == null ? "none" : string.Join(",", record.schedule), "record schedule");
|
|
}
|
|
}
|
|
}
|