387 lines
26 KiB
C#
387 lines
26 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Reflection;
|
||
|
|
using System.Runtime.CompilerServices;
|
||
|
|
using BlaxCastes;
|
||
|
|
using HarmonyLib;
|
||
|
|
using RimWorld;
|
||
|
|
using Verse;
|
||
|
|
|
||
|
|
namespace BlaxCastesTests
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Castes works with any combination of DLCs. These run in every DLC set (run-tests.ps1 with no switch,
|
||
|
|
/// -NoDlc, -Dlc ...) and check the DLC-off side: names of a DLC that is off stay in a caste with no warning
|
||
|
|
/// (the state a save made with the DLC is in when it loads without it), a mutant whose def is gone throws
|
||
|
|
/// nothing, and the slave rows and Ideology texts. Which DLC work types are off is read at run time
|
||
|
|
/// (DlcOffWork), so the tests hold with every DLC set, Anomaly and Odyssey included; a test that needs a
|
||
|
|
/// DLC, or a DLC that is off, skips with "needs ..." after its core part.
|
||
|
|
/// </summary>
|
||
|
|
public static class DlcTests
|
||
|
|
{
|
||
|
|
private const string Royalty = "ludeon.rimworld.royalty";
|
||
|
|
private const string Biotech = "ludeon.rimworld.biotech";
|
||
|
|
private const string Anomaly = "ludeon.rimworld.anomaly";
|
||
|
|
private const string Odyssey = "ludeon.rimworld.odyssey";
|
||
|
|
|
||
|
|
private static void CheckSlots() => AccessTools.Method(typeof(CasteManager), "CheckSlots").Invoke(null, new object[] { Fixtures.Comp });
|
||
|
|
|
||
|
|
private static void SetScheduleRaw(Caste c, List<string> names) => AccessTools.Field(typeof(Caste), "schedule").SetValue(c, names);
|
||
|
|
|
||
|
|
private static void SetWorkRaw(Caste c, Dictionary<string, int> work) => AccessTools.Field(typeof(Caste), "workPriorities").SetValue(c, work);
|
||
|
|
|
||
|
|
private static WorkTypeDef Growing => Fixtures.NeedDef(DefDatabase<WorkTypeDef>.GetNamedSilentFail("Growing"), "work type Growing");
|
||
|
|
|
||
|
|
/// <summary>The work types of a DLC: Childcare (Biotech), Dark study (Anomaly), Fishing (Odyssey).</summary>
|
||
|
|
private static readonly string[] DlcWork = { "Childcare", "DarkStudy", "Fishing" };
|
||
|
|
|
||
|
|
/// <summary>The DLC work types whose DLC is off in this run.</summary>
|
||
|
|
private static List<string> DlcOffWork() => DlcWork.Where(WorkSlot.IsDlcOff).ToList();
|
||
|
|
|
||
|
|
/// <summary>"Dark study 2 (needs Anomaly)" as the summary words a DLC work type that is off.</summary>
|
||
|
|
private static string NeedsNote(string defName) => "(needs " + DlcSupport.DlcName(DlcSupport.OwnerOf(typeof(WorkTypeDef), defName)) + ")";
|
||
|
|
|
||
|
|
/// <summary>Night shift with Meditate at hours 3 and 4.</summary>
|
||
|
|
private static List<string> MeditateSchedule()
|
||
|
|
{
|
||
|
|
var names = new List<string>();
|
||
|
|
for (int h = 0; h < ScheduleSlot.Hours; h++)
|
||
|
|
names.Add(h == 3 || h == 4 ? "Meditate" : h < 8 ? TimeAssignmentDefOf.Sleep.defName : TimeAssignmentDefOf.Work.defName);
|
||
|
|
return names;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- which DLC a def belongs to ----------------------------------------------------------
|
||
|
|
|
||
|
|
[BlaxTest("dlc: Meditate is Royalty's, Childcare Biotech's, Dark study Anomaly's and Fishing Odyssey's; core and made-up names belong to no DLC")]
|
||
|
|
public static void DlcOwners()
|
||
|
|
{
|
||
|
|
T.Equal(Royalty, DlcSupport.OwnerOf(typeof(TimeAssignmentDef), "Meditate"), "owner of Meditate");
|
||
|
|
T.Equal(Biotech, DlcSupport.OwnerOf(typeof(WorkTypeDef), "Childcare"), "owner of Childcare");
|
||
|
|
T.Equal(Anomaly, DlcSupport.OwnerOf(typeof(WorkTypeDef), "DarkStudy"), "owner of DarkStudy");
|
||
|
|
T.Equal(Odyssey, DlcSupport.OwnerOf(typeof(WorkTypeDef), "Fishing"), "owner of Fishing");
|
||
|
|
T.Equal(null, DlcSupport.OwnerOf(typeof(TimeAssignmentDef), "Sleep"), "owner of Sleep");
|
||
|
|
T.Equal(null, DlcSupport.OwnerOf(typeof(WorkTypeDef), "Growing"), "owner of Growing");
|
||
|
|
T.Equal(null, DlcSupport.OwnerOf(typeof(WorkTypeDef), "BlaxCastesNoSuchWork"), "owner of a made-up work type");
|
||
|
|
T.Equal(null, DlcSupport.OwnerOf(typeof(WorkTypeDef), "Meditate"), "owner of Meditate as a work type");
|
||
|
|
|
||
|
|
T.Equal(ModsConfig.RoyaltyActive ? null : "Royalty", DlcSupport.InactiveDlcFor(typeof(TimeAssignmentDef), "Meditate"), "inactive DLC for Meditate");
|
||
|
|
T.Equal(ModsConfig.BiotechActive ? null : "Biotech", DlcSupport.InactiveDlcFor(typeof(WorkTypeDef), "Childcare"), "inactive DLC for Childcare");
|
||
|
|
T.Equal(ModsConfig.AnomalyActive ? null : "Anomaly", DlcSupport.InactiveDlcFor(typeof(WorkTypeDef), "DarkStudy"), "inactive DLC for DarkStudy");
|
||
|
|
T.Equal(ModsConfig.OdysseyActive ? null : "Odyssey", DlcSupport.InactiveDlcFor(typeof(WorkTypeDef), "Fishing"), "inactive DLC for Fishing");
|
||
|
|
T.Check(ScheduleSlot.IsKept("Meditate") && !ScheduleSlot.IsKept("BlaxCastesNoSuchAssignment"), "IsKept: Meditate " + ScheduleSlot.IsKept("Meditate"));
|
||
|
|
T.Check(ScheduleSlot.IsDlcOff("Meditate") == !ModsConfig.RoyaltyActive, "IsDlcOff(Meditate) with Royalty " + ModsConfig.RoyaltyActive);
|
||
|
|
T.Check(WorkSlot.IsDlcOff("Childcare") == !ModsConfig.BiotechActive, "IsDlcOff(Childcare) with Biotech " + ModsConfig.BiotechActive);
|
||
|
|
T.Check(!WorkSlot.IsDlcOff("Growing") && !WorkSlot.IsDlcOff("BlaxCastesNoSuchWork"), "a core or made-up work type counts as a DLC's");
|
||
|
|
T.Check("BlaxCastes_NeedsDlc".CanTranslate() && "BlaxCastes_ScheduleDlcOffNote".CanTranslate() && "BlaxCastes_WorkDlcOffNote".CanTranslate(),
|
||
|
|
"DLC note strings missing from Keyed");
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- a caste that holds names of a DLC that is off ---------------------------------------
|
||
|
|
|
||
|
|
[BlaxTest("dlc: stored Meditate hours stay in the caste through the load check, painting and Apply with no warning; without Royalty they apply as Anything and the manager notes them")]
|
||
|
|
public static void MeditateKeptWithoutRoyalty()
|
||
|
|
{
|
||
|
|
string anything = TimeAssignmentDefOf.Anything.defName;
|
||
|
|
Caste c = Fixtures.NewCaste("Meditate kept");
|
||
|
|
SetScheduleRaw(c, MeditateSchedule()); // as a save made with Royalty loads
|
||
|
|
CheckSlots();
|
||
|
|
T.Equal("Meditate", c.Schedule[3], "stored hour 3 after the load check");
|
||
|
|
|
||
|
|
Pawn p = Fixtures.Colonist();
|
||
|
|
T.Check(CasteManager.Assign(p, c, false, JoinReason.Manual), "Assign failed");
|
||
|
|
string expected = ModsConfig.RoyaltyActive ? "Meditate" : anything;
|
||
|
|
T.Equal(expected, p.timetable.GetAssignment(3).defName, "pawn's hour 3 (Royalty " + ModsConfig.RoyaltyActive + ")");
|
||
|
|
T.Equal(0, CasteManager.Overrides(p).Count, "overrides right after Assign");
|
||
|
|
|
||
|
|
// Painting another hour rewrites the whole day: the Meditate hours must survive it.
|
||
|
|
Dialog_ManageCastes.PaintHour(c, 12, TimeAssignmentDefOf.Joy);
|
||
|
|
T.Equal("Meditate", c.Schedule[4], "stored hour 4 after painting hour 12");
|
||
|
|
T.Equal(TimeAssignmentDefOf.Joy.defName, c.Schedule[12], "stored hour 12 after painting it");
|
||
|
|
T.Equal(TimeAssignmentDefOf.Joy, p.timetable.GetAssignment(12), "pawn's hour 12 after painting");
|
||
|
|
CheckSlots();
|
||
|
|
T.Equal("Meditate", c.Schedule[3], "stored hour 3 after a second load check");
|
||
|
|
|
||
|
|
// The Anything brush replaces a stored Meditate hour, also while that hour shows as Anything (no Royalty).
|
||
|
|
TimeAssignmentDef anythingBrush = TimeAssignmentDefOf.Anything;
|
||
|
|
T.Check(Dialog_ManageCastes.PaintsHour(c, 3, anythingBrush), "the Anything brush does not paint a stored Meditate hour");
|
||
|
|
Dialog_ManageCastes.PaintHour(c, 3, anythingBrush);
|
||
|
|
T.Equal(anything, c.Schedule[3], "stored hour 3 after painting it Anything");
|
||
|
|
T.Check(!Dialog_ManageCastes.PaintsHour(c, 3, anythingBrush), "the Anything brush paints an hour that is already Anything");
|
||
|
|
T.Equal("Meditate", c.Schedule[4], "stored hour 4 after painting hour 3");
|
||
|
|
|
||
|
|
string note = Dialog_ManageCastes.ScheduleDlcNote(c);
|
||
|
|
if (ModsConfig.RoyaltyActive)
|
||
|
|
{
|
||
|
|
T.Check(note == null, "schedule DLC note with Royalty on: " + note);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
T.Check(note != null && note.Contains("Meditate") && note.Contains("Royalty"), "schedule DLC note without Royalty: " + note);
|
||
|
|
T.Check(!ScheduleSlot.Summary(c.Schedule).NullOrEmpty(), "the schedule summary is empty");
|
||
|
|
}
|
||
|
|
|
||
|
|
[BlaxTest("dlc: stored work types of a DLC that is off (Childcare, Dark study, Fishing) stay listed with no warning and are skipped; the summary names their DLC instead of the def name")]
|
||
|
|
public static void DlcWorkKept()
|
||
|
|
{
|
||
|
|
if (WorkSlot.ActiveManager() != null)
|
||
|
|
T.Skip(WorkSlot.ActiveManager() + " is active, so the work slot is off");
|
||
|
|
Caste c = Fixtures.NewCaste("DLC work kept");
|
||
|
|
CasteManager.SetWorkPriority(c, Growing.defName, 1);
|
||
|
|
var work = new Dictionary<string, int>(c.WorkPriorities) { ["Childcare"] = 1, ["DarkStudy"] = 2, ["Fishing"] = 3 };
|
||
|
|
SetWorkRaw(c, work); // as a save made with those DLCs loads
|
||
|
|
CheckSlots();
|
||
|
|
foreach (string name in new[] { "Childcare", "DarkStudy", "Fishing", "Growing" })
|
||
|
|
T.Check(c.WorkPriorities.ContainsKey(name), name + " was dropped by the load check: " + WorkSlot.Summary(c.WorkPriorities));
|
||
|
|
List<string> off = DlcOffWork();
|
||
|
|
T.Info("DLC work types that are off: " + (off.Count == 0 ? "none" : string.Join(", ", off)));
|
||
|
|
T.Check(DlcOwnerActive("Childcare") == ModsConfig.BiotechActive && DlcOwnerActive("DarkStudy") == ModsConfig.AnomalyActive
|
||
|
|
&& DlcOwnerActive("Fishing") == ModsConfig.OdysseyActive, "a DLC work type resolves although its DLC is off, or the other way round");
|
||
|
|
|
||
|
|
Pawn p = Fixtures.Colonist();
|
||
|
|
Fixtures.Unqueue(p);
|
||
|
|
PlaySettings play = Find.PlaySettings;
|
||
|
|
bool manual = play.useWorkPriorities;
|
||
|
|
play.useWorkPriorities = true; // so GetPriority shows the caste's number
|
||
|
|
try
|
||
|
|
{
|
||
|
|
T.Check(CasteManager.Assign(p, c, false, JoinReason.Manual), "Assign failed");
|
||
|
|
if (!p.WorkTypeIsDisabled(Growing))
|
||
|
|
T.Equal(1, p.workSettings.GetPriority(Growing), "pawn's Growing");
|
||
|
|
foreach (string name in DlcWork)
|
||
|
|
{
|
||
|
|
WorkTypeDef def = WorkSlot.Resolve(name);
|
||
|
|
if (WorkSlot.CanDo(p, def))
|
||
|
|
T.Equal(work[name], p.workSettings.GetPriority(def), "pawn's " + name + " with its DLC on");
|
||
|
|
}
|
||
|
|
T.Equal(0, CasteManager.Overrides(p).Count, "overrides from work types of a DLC that is off");
|
||
|
|
}
|
||
|
|
finally
|
||
|
|
{
|
||
|
|
play.useWorkPriorities = manual;
|
||
|
|
}
|
||
|
|
|
||
|
|
string summary = WorkSlot.Summary(c.WorkPriorities);
|
||
|
|
string note = Dialog_ManageCastes.WorkDlcNote(c);
|
||
|
|
foreach (string name in DlcWork)
|
||
|
|
{
|
||
|
|
if (off.Contains(name))
|
||
|
|
{
|
||
|
|
string label = GenText.SplitCamelCase(name).ToLowerInvariant().CapitalizeFirst();
|
||
|
|
T.Check(summary.Contains(label + " " + work[name] + " " + NeedsNote(name)), "summary for " + name + " with its DLC off: " + summary);
|
||
|
|
T.Check(name == label || !summary.Contains(name), "summary names the def " + name + ": " + summary);
|
||
|
|
T.Check(note != null && note.Contains(NeedsNote(name)), "work DLC note for " + name + ": " + note);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
T.Check(summary.Contains(WorkSlot.TypeLabel(name) + " " + work[name]) && !summary.Contains(NeedsNote(name)), "summary for " + name + " with its DLC on: " + summary);
|
||
|
|
T.Check(note == null || !note.Contains(NeedsNote(name)), "work DLC note names " + name + " with its DLC on: " + note);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
T.Check((note == null) == (off.Count == 0), "work DLC note with " + off.Count + " types off: " + note);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>The DLC that owns the work type is active, read from the def being in the game.</summary>
|
||
|
|
private static bool DlcOwnerActive(string defName) => WorkSlot.Resolve(defName) != null;
|
||
|
|
|
||
|
|
[BlaxTest("dlc: Start from nothing with only work types of a DLC that is off turns no work off; with a core type listed it still does")]
|
||
|
|
public static void StartFromNothingDlcOnly()
|
||
|
|
{
|
||
|
|
if (WorkSlot.ActiveManager() != null)
|
||
|
|
T.Skip(WorkSlot.ActiveManager() + " is active, so the work slot is off");
|
||
|
|
List<string> off = DlcOffWork();
|
||
|
|
if (off.Count == 0)
|
||
|
|
T.Skip("needs a DLC that is off (Childcare, Dark study, Fishing all active)");
|
||
|
|
Caste c = Fixtures.NewCaste("DLC work only");
|
||
|
|
SetWorkRaw(c, off.ToDictionary(name => name, name => 1));
|
||
|
|
CasteManager.SetWorkStartFromNothing(c, true);
|
||
|
|
T.Check(c.IsManaged(CasteSlot.Work), "setup: the caste does not manage work");
|
||
|
|
T.Check(!WorkSlot.StripsOthers(c.WorkPriorities, true), "StripsOthers with only work types of a DLC that is off (" + string.Join(", ", off) + ")");
|
||
|
|
T.Equal(off.Count, WorkSlot.Decided(c).Count, "work types the caste decides (" + string.Join(", ", WorkSlot.Decided(c).Keys) + ")");
|
||
|
|
|
||
|
|
Pawn p = Fixtures.Colonist();
|
||
|
|
Fixtures.Unqueue(p);
|
||
|
|
Dictionary<string, int> before = WorkSlot.Of(p);
|
||
|
|
int on = before.Count(kv => kv.Value > 0);
|
||
|
|
T.Check(on > 2, "setup: the colonist has only " + on + " work types on");
|
||
|
|
T.Check(CasteManager.Assign(p, c, false, JoinReason.Manual), "Assign failed");
|
||
|
|
List<string> changed = WorkSlot.Of(p).Where(kv => before[kv.Key] != kv.Value).Select(kv => kv.Key).ToList();
|
||
|
|
T.Check(changed.Count == 0, "Start from nothing changed work with no listed type in the game: " + string.Join(", ", changed));
|
||
|
|
|
||
|
|
// A core type listed next to them: the other work goes off again.
|
||
|
|
CasteManager.SetWorkPriority(c, Growing.defName, 1);
|
||
|
|
T.Check(WorkSlot.StripsOthers(c.WorkPriorities, true), "StripsOthers with Growing listed");
|
||
|
|
CasteManager.ResetToCaste(p);
|
||
|
|
int stillOn = WorkSlot.Of(p).Count(kv => kv.Value > 0 && kv.Key != Growing.defName && !WorkSlot.IsSelfCare(WorkSlot.Resolve(kv.Key)));
|
||
|
|
T.Equal(0, stillOn, "other work types on after Start from nothing with Growing listed");
|
||
|
|
}
|
||
|
|
|
||
|
|
[BlaxTest("dlc: a caste whose only work types are of a DLC that is off shows no Apply to all members; Forget these drops those types, keeps the rest and moves nobody")]
|
||
|
|
public static void ForgetDlcWork()
|
||
|
|
{
|
||
|
|
if (WorkSlot.ActiveManager() != null)
|
||
|
|
T.Skip(WorkSlot.ActiveManager() + " is active, so the work slot is off");
|
||
|
|
Caste c = Fixtures.NewCaste("DLC work forget");
|
||
|
|
T.Check(!Dialog_ManageCastes.AppliesAnything(c), "a new caste shows Apply to all members");
|
||
|
|
CasteManager.SetWorkPriority(c, Growing.defName, 1);
|
||
|
|
T.Check(Dialog_ManageCastes.AppliesAnything(c), "a caste with Growing 1 shows no Apply to all members");
|
||
|
|
T.Equal(0, Dialog_ManageCastes.ForgetDlcOffWork(c), "types Forget these dropped from a caste without DLC work");
|
||
|
|
T.Equal(1, c.WorkPriorities.Count, "work types after Forget these on a caste without DLC work");
|
||
|
|
|
||
|
|
List<string> off = DlcOffWork();
|
||
|
|
if (off.Count == 0)
|
||
|
|
T.Skip("needs a DLC that is off (Childcare, Dark study, Fishing all active); the core part passed");
|
||
|
|
SetWorkRaw(c, off.ToDictionary(name => name, name => 2)); // as a save made with those DLCs loads
|
||
|
|
T.Check(c.IsManaged(CasteSlot.Work) && WorkSlot.AllDlcOff(c.WorkPriorities), "setup: the caste lists only work of a DLC that is off");
|
||
|
|
T.Check(!Dialog_ManageCastes.AppliesAnything(c), "Apply to all members shows for a caste whose only work types are of a DLC that is off");
|
||
|
|
|
||
|
|
var mixed = off.ToDictionary(name => name, name => 2);
|
||
|
|
mixed[Growing.defName] = 1;
|
||
|
|
SetWorkRaw(c, mixed);
|
||
|
|
T.Check(Dialog_ManageCastes.AppliesAnything(c), "Apply to all members hidden while Growing is listed");
|
||
|
|
Pawn p = Fixtures.Colonist();
|
||
|
|
Fixtures.Unqueue(p);
|
||
|
|
T.Check(CasteManager.Assign(p, c, false, JoinReason.Manual), "Assign failed");
|
||
|
|
Dictionary<string, int> before = WorkSlot.Of(p);
|
||
|
|
T.Equal(off.Count, Dialog_ManageCastes.ForgetDlcOffWork(c), "types Forget these dropped");
|
||
|
|
T.Check(c.WorkPriorities.Count == 1 && c.WorkPriorityOf(Growing.defName) == 1, "work after Forget these: " + WorkSlot.Summary(c.WorkPriorities));
|
||
|
|
T.Check(Dialog_ManageCastes.WorkDlcNote(c) == null, "work DLC note after Forget these: " + Dialog_ManageCastes.WorkDlcNote(c));
|
||
|
|
List<string> changed = WorkSlot.Of(p).Where(kv => before[kv.Key] != kv.Value).Select(kv => kv.Key).ToList();
|
||
|
|
T.Check(changed.Count == 0, "Forget these changed a member's work: " + string.Join(", ", changed));
|
||
|
|
T.Equal(0, CasteManager.Overrides(p).Count, "member's overrides after Forget these");
|
||
|
|
|
||
|
|
// Only work of a DLC that is off: forgetting it leaves work alone.
|
||
|
|
SetWorkRaw(c, off.ToDictionary(name => name, name => 2));
|
||
|
|
Dialog_ManageCastes.ForgetDlcOffWork(c);
|
||
|
|
T.Check(!c.IsManaged(CasteSlot.Work), "the caste still manages work after forgetting its only work types");
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- Anomaly: a mutant whose def is gone -------------------------------------------------
|
||
|
|
|
||
|
|
[BlaxTest("dlc: a mutant whose def is gone (a save made with Anomaly loaded without it) is left alone: no slot, no join, and the slot checks and the Caste column throw nothing")]
|
||
|
|
public static void MutantWithoutDef()
|
||
|
|
{
|
||
|
|
Pawn p = Fixtures.Colonist();
|
||
|
|
Fixtures.Unqueue(p);
|
||
|
|
Caste c = Fixtures.NewCaste("Mutant without def");
|
||
|
|
CasteManager.SetSlot(c, CasteSlot.Food, Current.Game.foodRestrictionDatabase.DefaultFoodRestriction());
|
||
|
|
T.Check(CasteManager.Assign(p, c, false, JoinReason.Manual), "setup: Assign failed");
|
||
|
|
T.Check(!p.IsMutant, "setup: the colonist is already a mutant");
|
||
|
|
|
||
|
|
// The game's own policy getters throw for this pawn (they read mutant.Def), so Castes must not call them.
|
||
|
|
var tracker = (Pawn_MutantTracker)RuntimeHelpers.GetUninitializedObject(typeof(Pawn_MutantTracker));
|
||
|
|
AccessTools.Field(typeof(Pawn_MutantTracker), "pawn").SetValue(tracker, p);
|
||
|
|
p.mutant = tracker;
|
||
|
|
try
|
||
|
|
{
|
||
|
|
T.Check(p.IsMutant && p.mutant.Def == null, "setup: not a mutant without a def");
|
||
|
|
foreach (CasteSlot slot in CasteUtility.AllSlots)
|
||
|
|
T.Check(!CasteUtility.CanUse(p, slot), "CanUse(" + slot + ") is true for a mutant without a def");
|
||
|
|
T.Check(!JoinDefaults.Eligible(p), "a mutant without a def is eligible for a caste");
|
||
|
|
JoinDefaults.Enqueue(p, JoinDefaults.StatusFallback);
|
||
|
|
T.Check(!JoinDefaults.IsQueued(p), "a mutant without a def was queued");
|
||
|
|
T.Equal(0, CasteManager.Overrides(p).Count, "overrides of a mutant without a def");
|
||
|
|
CasteManager.WorkOverrides(p);
|
||
|
|
T.Equal(0, CasteUtility.Apply(p, c).Count, "slots Apply wrote on a mutant without a def");
|
||
|
|
T.Check(!JoinDefaults.WillChange(p), "a mutant without a def shows as pending");
|
||
|
|
T.Check(!PawnColumnWorker_BlaxCaste.CellLabel(p).NullOrEmpty(), "the Caste column has no label for the pawn");
|
||
|
|
PawnColumnWorker_BlaxCaste.CellTip(p);
|
||
|
|
PawnColumnWorker_BlaxCaste.MenuEntries(p);
|
||
|
|
CasteManager.PawnsToAssignByStatus();
|
||
|
|
}
|
||
|
|
finally
|
||
|
|
{
|
||
|
|
p.mutant = null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- Ideology: slave rows and texts ------------------------------------------------------
|
||
|
|
|
||
|
|
[BlaxTest("dlc: the join defaults show the slave rows with Ideology; without it only while a slave row picks a caste, with a Needs Ideology note")]
|
||
|
|
public static void SlaveRowsWithoutIdeology()
|
||
|
|
{
|
||
|
|
const string tipKey = "BlaxCastes_AssignByStatusTip";
|
||
|
|
List<string> rows = Dialog_JoinDefaults.VisibleRows();
|
||
|
|
if (ModsConfig.IdeologyActive)
|
||
|
|
{
|
||
|
|
T.Equal(5, rows.Count, "rows with Ideology");
|
||
|
|
T.Check(Dialog_JoinDefaults.SlaveRowsNote() == null, "Needs Ideology note with Ideology on");
|
||
|
|
T.Equal(tipKey, Dialog_ManageCastes.AssignByStatusTipKey(), "Assign by status tooltip with Ideology on");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
T.Check(!PawnsFinder.AllMapsCaravansAndTravellingTransporters_Alive_OfPlayerFaction.Any(x => x.IsSlaveOfColony), "setup: a slave exists without Ideology");
|
||
|
|
T.Equal(3, rows.Count, "rows without Ideology while the slave rows pick nothing (" + string.Join(", ", rows) + ")");
|
||
|
|
T.Check(Dialog_JoinDefaults.SlaveRowsNote() == null, "Needs Ideology note while the slave rows are hidden");
|
||
|
|
T.Equal(tipKey + "NoIdeology", Dialog_ManageCastes.AssignByStatusTipKey(), "Assign by status tooltip while the slave rows are hidden");
|
||
|
|
|
||
|
|
// A save made with Ideology: its slave row still picks a caste, so the rows show, with the note, and
|
||
|
|
// Assign by status still names the new-slave row.
|
||
|
|
Caste c = Fixtures.NewCaste("Slave row without Ideology");
|
||
|
|
T.Check(CasteManager.SetJoinRow(JoinReason.BoughtSlave, JoinRowMode.SpecificCaste, c), "setup: SetJoinRow failed");
|
||
|
|
rows = Dialog_JoinDefaults.VisibleRows();
|
||
|
|
T.Equal(5, rows.Count, "rows without Ideology while a slave row picks a caste");
|
||
|
|
string note = Dialog_JoinDefaults.SlaveRowsNote();
|
||
|
|
T.Check(note != null && note.Contains("Ideology"), "Needs Ideology note: " + note);
|
||
|
|
T.Equal(tipKey, Dialog_ManageCastes.AssignByStatusTipKey(), "Assign by status tooltip while the slave rows show");
|
||
|
|
}
|
||
|
|
|
||
|
|
[BlaxTest("dlc: without Ideology the texts that name slave events or the Slave caste use their Ideology-free variant; with it the original")]
|
||
|
|
public static void IdeologyTexts()
|
||
|
|
{
|
||
|
|
string[] keys =
|
||
|
|
{
|
||
|
|
"BlaxCastes_AssignByStatusTip", "BlaxCastes_JoinDefaultsButtonTip", "BlaxCastes_SettingJoinDefaultsTip",
|
||
|
|
"BlaxCastes_SettingReturnToPreviousTip", "BlaxCastes_SettingSeedStarter", "BlaxCastes_SettingSeedStarterTip",
|
||
|
|
"BlaxCastes_RowTip_newColonist", "BlaxCastes_RowTip_newPrisoner",
|
||
|
|
};
|
||
|
|
foreach (string key in keys)
|
||
|
|
{
|
||
|
|
T.Check((key + "NoIdeology").CanTranslate(), key + "NoIdeology is missing from Keyed");
|
||
|
|
string picked = DlcSupport.IdeologyKey(key);
|
||
|
|
T.Equal(ModsConfig.IdeologyActive ? key : key + "NoIdeology", picked, "text picked for " + key);
|
||
|
|
string text = picked.Translate();
|
||
|
|
if (!ModsConfig.IdeologyActive)
|
||
|
|
T.Check(!text.Contains("enslave") && !text.Contains("freed") && !text.Contains("imprisoned slave") && !text.Contains("Slave caste,"),
|
||
|
|
key + " without Ideology names a slave event: " + text);
|
||
|
|
}
|
||
|
|
T.Equal("BlaxCastes_CellHint", DlcSupport.IdeologyKey("BlaxCastes_CellHint"), "a key without a variant");
|
||
|
|
T.Check(BlaxCastesMod.ShowsNoIdeologyNote == !ModsConfig.IdeologyActive, "the settings page's Ideology note");
|
||
|
|
T.Check((BlaxCastesMod.SeedStarterNote() == null) == ModsConfig.IdeologyActive, "the starter castes note: " + BlaxCastesMod.SeedStarterNote());
|
||
|
|
T.Check("BlaxCastes_JoinSlaveRowsNoIdeology".CanTranslate() && "BlaxCastes_StarterSlaveAddedMessage".CanTranslate(), "Ideology strings missing from Keyed");
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- a save made with a DLC, loaded without it ---------------------------------------------
|
||
|
|
|
||
|
|
[BlaxTest("dlc: set up a caste with Meditate hours and Childcare, Dark study and Fishing priorities for the reload")]
|
||
|
|
public static void ReloadSetup()
|
||
|
|
{
|
||
|
|
Caste c = Fixtures.KeepCaste(Fixtures.NewCaste("DLC names reload"));
|
||
|
|
SetScheduleRaw(c, MeditateSchedule());
|
||
|
|
SetWorkRaw(c, new Dictionary<string, int> { ["Growing"] = 1, ["Childcare"] = 1, ["DarkStudy"] = 2, ["Fishing"] = 3 });
|
||
|
|
Pawn member = Fixtures.Keep(Fixtures.Colonist());
|
||
|
|
Fixtures.Unqueue(member);
|
||
|
|
T.Check(CasteManager.Assign(member, c, false, JoinReason.Manual), "Assign failed");
|
||
|
|
T.Carry["dlcCaste"] = c.id.ToString();
|
||
|
|
T.Carry["dlcMember"] = member.ThingID;
|
||
|
|
}
|
||
|
|
|
||
|
|
[BlaxTest("dlc: after the reload the caste still has every DLC name, no Blax Castes warning was logged by the load, and its member applies cleanly", phase: 2)]
|
||
|
|
public static void ReloadKeepsDlcNames()
|
||
|
|
{
|
||
|
|
T.Check(T.Carry.TryGetValue("dlcCaste", out string id), "phase 1 did not set up the caste");
|
||
|
|
List<string> stray = TestRunner.StrayWarnings();
|
||
|
|
T.Check(stray.Count == 0, "Blax Castes warnings outside the tests (the save or the load): " + string.Join(" | ", stray.Take(3)));
|
||
|
|
Caste c = Fixtures.Comp.Castes.FirstOrDefault(x => x.id.ToString() == id);
|
||
|
|
T.NotNull(c, "caste " + id + " after reload");
|
||
|
|
T.Check(c.Schedule != null && c.Schedule[3] == "Meditate" && c.Schedule[4] == "Meditate", "Meditate hours after reload: " + (c.Schedule == null ? "none" : string.Join(",", c.Schedule)));
|
||
|
|
foreach (string name in new[] { "Growing", "Childcare", "DarkStudy", "Fishing" })
|
||
|
|
T.Check(c.WorkPriorities.ContainsKey(name), name + " lost over the reload: " + WorkSlot.Summary(c.WorkPriorities));
|
||
|
|
Pawn member = Fixtures.FindPawnById(T.Carry["dlcMember"]);
|
||
|
|
T.NotNull(member, "member after reload");
|
||
|
|
T.Check(Fixtures.Comp.CasteOf(member) == c, "member's caste after reload");
|
||
|
|
CasteManager.ResetToCaste(member);
|
||
|
|
T.Equal(ModsConfig.RoyaltyActive ? "Meditate" : TimeAssignmentDefOf.Anything.defName, member.timetable.GetAssignment(3).defName, "member's hour 3 after the reload");
|
||
|
|
T.Equal(0, CasteManager.Overrides(member).Count, "member's overrides after Reset to caste");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|