feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
using System.Collections.Generic;
|
2026-11-29 12:09:10 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
using RimWorld;
|
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
|
|
|
using Verse;
|
|
|
|
|
|
|
|
|
|
namespace BlaxCastes
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A pawn's place in the caste system. Caste null means "casteless by choice": the player (or a
|
|
|
|
|
/// deleted caste) took the pawn out, and later safety nets leave it alone. A pawn with no record at
|
|
|
|
|
/// all never had a caste.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class CasteMembership : IExposable
|
|
|
|
|
{
|
|
|
|
|
public Caste caste;
|
|
|
|
|
/// <summary>True when a join row set it, false when the player did.</summary>
|
|
|
|
|
public bool auto;
|
|
|
|
|
public string reason;
|
|
|
|
|
public int tick;
|
|
|
|
|
|
|
|
|
|
public CasteMembership()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CasteMembership(Caste caste, bool auto, string reason, int tick)
|
|
|
|
|
{
|
|
|
|
|
this.caste = caste;
|
|
|
|
|
this.auto = auto;
|
|
|
|
|
this.reason = reason;
|
|
|
|
|
this.tick = tick;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Casteless => caste == null;
|
|
|
|
|
|
|
|
|
|
public void ExposeData()
|
|
|
|
|
{
|
|
|
|
|
Scribe_References.Look(ref caste, "caste");
|
|
|
|
|
Scribe_Values.Look(ref auto, "auto");
|
|
|
|
|
Scribe_Values.Look(ref reason, "reason");
|
|
|
|
|
Scribe_Values.Look(ref tick, "tick");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum JoinRowMode
|
|
|
|
|
{
|
|
|
|
|
NoCaste,
|
|
|
|
|
DefaultCaste,
|
|
|
|
|
SpecificCaste,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>What a way of joining does: no caste, the default caste, or one specific caste.</summary>
|
|
|
|
|
public class JoinRow : IExposable
|
|
|
|
|
{
|
|
|
|
|
public string reason;
|
|
|
|
|
public JoinRowMode mode = JoinRowMode.NoCaste;
|
|
|
|
|
/// <summary>Only used with SpecificCaste.</summary>
|
|
|
|
|
public Caste caste;
|
|
|
|
|
|
|
|
|
|
public JoinRow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JoinRow(string reason)
|
|
|
|
|
{
|
|
|
|
|
this.reason = reason;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExposeData()
|
|
|
|
|
{
|
|
|
|
|
Scribe_Values.Look(ref reason, "reason");
|
|
|
|
|
Scribe_Values.Look(ref mode, "mode", JoinRowMode.NoCaste);
|
|
|
|
|
Scribe_References.Look(ref caste, "caste");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>A join waiting for the next tick. Filled and applied by JoinDefaults.</summary>
|
|
|
|
|
public class QueuedJoin : IExposable
|
|
|
|
|
{
|
|
|
|
|
public Pawn pawn;
|
|
|
|
|
public string reason;
|
|
|
|
|
public int tick;
|
|
|
|
|
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// The pawn's membership when the join was last queued (not saved). A different membership at
|
|
|
|
|
/// apply time means the player picked a caste after the join was queued, even within one tick.
|
|
|
|
|
/// After a load, the ticks decide instead.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CasteMembership seen;
|
|
|
|
|
public bool seenKnown;
|
|
|
|
|
|
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
|
|
|
public QueuedJoin()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public QueuedJoin(Pawn pawn, string reason, int tick)
|
|
|
|
|
{
|
|
|
|
|
this.pawn = pawn;
|
|
|
|
|
this.reason = reason;
|
|
|
|
|
this.tick = tick;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExposeData()
|
|
|
|
|
{
|
|
|
|
|
Scribe_References.Look(ref pawn, "pawn");
|
|
|
|
|
Scribe_Values.Look(ref reason, "reason");
|
|
|
|
|
Scribe_Values.Look(ref tick, "tick");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// The caste a pawn had when it left the player side, was sold or became a prisoner, or "No caste"
|
|
|
|
|
/// when it was casteless by choice. Keyed by ThingID in GameComponent_BlaxCastes, so a discarded pawn
|
2026-11-29 12:09:10 +00:00
|
|
|
/// leaves no unresolved reference. The caste is stored by id for the same reason. The pawn's own
|
|
|
|
|
/// policies are references, like a caste's policy slots, so a policy deleted since never comes back
|
|
|
|
|
/// as another policy that got its id; a reference to a deleted policy is dropped before each save, so
|
|
|
|
|
/// the load never meets one it cannot resolve, or one that resolves to a new policy with the same load
|
|
|
|
|
/// ID (label and id).
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
/// If the pawn comes back within formerCasteDays with the same status (colonist or slave), it gets
|
|
|
|
|
/// that caste (or No caste) back instead of its join row's, and its own settings from when it left
|
2026-11-29 12:09:10 +00:00
|
|
|
/// (JoinDefaults.Restore): the slots it followed, and the ones the caste did not manage then, get the
|
|
|
|
|
/// caste's current value; the ones it had changed by hand get that value back.
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public class FormerCaste : IExposable
|
|
|
|
|
{
|
|
|
|
|
public int casteId = Caste.Unmanaged;
|
|
|
|
|
/// <summary>The pawn was casteless by choice; casteId is unused.</summary>
|
|
|
|
|
public bool casteless;
|
|
|
|
|
/// <summary>Colonist or Slave: the status the pawn had in that caste.</summary>
|
|
|
|
|
public JoinSide side;
|
|
|
|
|
/// <summary>The membership's auto flag, restored with the caste.</summary>
|
|
|
|
|
public bool auto;
|
|
|
|
|
public int tick;
|
|
|
|
|
|
2026-11-29 12:09:10 +00:00
|
|
|
// The pawn's own settings just before it left; null or -1 where it had none.
|
|
|
|
|
public ApparelPolicy apparel;
|
|
|
|
|
public FoodPolicy food;
|
|
|
|
|
public DrugPolicy drug;
|
|
|
|
|
public ReadingPolicy reading;
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
public int medCare = Caste.Unmanaged;
|
|
|
|
|
public int loadoutId = Caste.Unmanaged;
|
|
|
|
|
public List<string> schedule;
|
|
|
|
|
/// <summary>Every work type's priority, as the game read it.</summary>
|
|
|
|
|
public Dictionary<string, int> work;
|
|
|
|
|
/// <summary>The caste's managed slots where the pawn had the caste's value when it left.</summary>
|
|
|
|
|
public List<CasteSlot> followed = new List<CasteSlot>();
|
|
|
|
|
/// <summary>The work types the caste decides where the pawn had the caste's value when it left.</summary>
|
|
|
|
|
public List<string> followedWork = new List<string>();
|
2026-11-29 12:09:10 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// The slots the caste managed when the pawn left. Null in a record saved before this was kept:
|
|
|
|
|
/// read as "every slot", so the pawn keeps its own values, as it did then.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<CasteSlot> managed;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The work types the caste listed when the pawn left (not the ones only "Start from nothing"
|
|
|
|
|
/// decided). Null in a record saved before this was kept: read as "every type".
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<string> listedWork;
|
|
|
|
|
|
|
|
|
|
// Records saved before the policies were references hold their ids; looked up once on load.
|
|
|
|
|
private int legacyApparelId = Caste.Unmanaged;
|
|
|
|
|
private int legacyFoodId = Caste.Unmanaged;
|
|
|
|
|
private int legacyDrugId = Caste.Unmanaged;
|
|
|
|
|
private int legacyReadingId = Caste.Unmanaged;
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
|
|
|
|
|
public FormerCaste()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FormerCaste(int casteId, JoinSide side, bool auto, int tick)
|
|
|
|
|
{
|
|
|
|
|
this.casteId = casteId;
|
|
|
|
|
this.side = side;
|
|
|
|
|
this.auto = auto;
|
|
|
|
|
this.tick = tick;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The pawn followed the caste's value for this slot when it left.</summary>
|
|
|
|
|
public bool Followed(CasteSlot slot) => followed != null && followed.Contains(slot);
|
|
|
|
|
|
|
|
|
|
public bool FollowedWork(string defName) => followedWork != null && followedWork.Contains(defName);
|
|
|
|
|
|
2026-11-29 12:09:10 +00:00
|
|
|
/// <summary>The caste managed this slot when the pawn left (always true for a record saved before that was kept).</summary>
|
|
|
|
|
public bool WasManaged(CasteSlot slot) => managed == null || managed.Contains(slot);
|
|
|
|
|
|
|
|
|
|
/// <summary>The caste listed this work type when the pawn left (always true for a record saved before that was kept).</summary>
|
|
|
|
|
public bool WasListed(string defName) => listedWork == null || listedWork.Contains(defName);
|
|
|
|
|
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
public void ExposeData()
|
|
|
|
|
{
|
2026-11-29 12:09:10 +00:00
|
|
|
if (Scribe.mode == LoadSaveMode.Saving)
|
|
|
|
|
{
|
|
|
|
|
// A policy deleted since the pawn left is gone for good. Its reference would not resolve on load, or would
|
|
|
|
|
// resolve to a new policy with the same load ID (Policy.GetUniqueLoadID is label and id, and a new policy
|
|
|
|
|
// can get the deleted one's id, and its label too when both kept the default name).
|
|
|
|
|
if (!CasteUtility.PolicyExists(apparel)) apparel = null;
|
|
|
|
|
if (!CasteUtility.PolicyExists(food)) food = null;
|
|
|
|
|
if (!CasteUtility.PolicyExists(drug)) drug = null;
|
|
|
|
|
if (!CasteUtility.PolicyExists(reading)) reading = null;
|
|
|
|
|
}
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
Scribe_Values.Look(ref casteId, "casteId", Caste.Unmanaged);
|
|
|
|
|
Scribe_Values.Look(ref casteless, "casteless");
|
|
|
|
|
Scribe_Values.Look(ref side, "side", JoinSide.None);
|
|
|
|
|
Scribe_Values.Look(ref auto, "auto");
|
|
|
|
|
Scribe_Values.Look(ref tick, "tick");
|
2026-11-29 12:09:10 +00:00
|
|
|
Scribe_References.Look(ref apparel, "apparel");
|
|
|
|
|
Scribe_References.Look(ref food, "food");
|
|
|
|
|
Scribe_References.Look(ref drug, "drug");
|
|
|
|
|
Scribe_References.Look(ref reading, "reading");
|
|
|
|
|
if (Scribe.mode == LoadSaveMode.LoadingVars)
|
|
|
|
|
{
|
|
|
|
|
Scribe_Values.Look(ref legacyApparelId, "apparelId", Caste.Unmanaged);
|
|
|
|
|
Scribe_Values.Look(ref legacyFoodId, "foodId", Caste.Unmanaged);
|
|
|
|
|
Scribe_Values.Look(ref legacyDrugId, "drugId", Caste.Unmanaged);
|
|
|
|
|
Scribe_Values.Look(ref legacyReadingId, "readingId", Caste.Unmanaged);
|
|
|
|
|
}
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
Scribe_Values.Look(ref medCare, "medCare", Caste.Unmanaged);
|
|
|
|
|
Scribe_Values.Look(ref loadoutId, "loadoutId", Caste.Unmanaged);
|
|
|
|
|
Scribe_Collections.Look(ref schedule, "schedule", LookMode.Value);
|
|
|
|
|
Scribe_Collections.Look(ref work, "work", LookMode.Value, LookMode.Value);
|
|
|
|
|
Scribe_Collections.Look(ref followed, "followed", LookMode.Value);
|
|
|
|
|
Scribe_Collections.Look(ref followedWork, "followedWork", LookMode.Value);
|
2026-11-29 12:09:10 +00:00
|
|
|
Scribe_Collections.Look(ref managed, "managed", LookMode.Value);
|
|
|
|
|
Scribe_Collections.Look(ref listedWork, "listedWork", LookMode.Value);
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
if (Scribe.mode == LoadSaveMode.PostLoadInit)
|
|
|
|
|
{
|
|
|
|
|
followed ??= new List<CasteSlot>();
|
|
|
|
|
followedWork ??= new List<string>();
|
2026-11-29 12:09:10 +00:00
|
|
|
// managed and listedWork stay null in an older record: see WasManaged and WasListed.
|
|
|
|
|
ResolveLegacyIds();
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-29 12:09:10 +00:00
|
|
|
/// <summary>An older record's policy ids, looked up in the databases once, right after the load.</summary>
|
|
|
|
|
private void ResolveLegacyIds()
|
|
|
|
|
{
|
|
|
|
|
Game game = Current.Game;
|
|
|
|
|
if (game == null)
|
|
|
|
|
return;
|
|
|
|
|
if (apparel == null && legacyApparelId >= 0)
|
|
|
|
|
apparel = game.outfitDatabase?.AllOutfits?.FirstOrDefault(p => p.id == legacyApparelId);
|
|
|
|
|
if (food == null && legacyFoodId >= 0)
|
|
|
|
|
food = game.foodRestrictionDatabase?.AllFoodRestrictions?.FirstOrDefault(p => p.id == legacyFoodId);
|
|
|
|
|
if (drug == null && legacyDrugId >= 0)
|
|
|
|
|
drug = game.drugPolicyDatabase?.AllPolicies?.FirstOrDefault(p => p.id == legacyDrugId);
|
|
|
|
|
if (reading == null && legacyReadingId >= 0)
|
|
|
|
|
reading = game.readingPolicyDatabase?.AllReadingPolicies?.FirstOrDefault(p => p.id == legacyReadingId);
|
|
|
|
|
legacyApparelId = legacyFoodId = legacyDrugId = legacyReadingId = Caste.Unmanaged;
|
|
|
|
|
}
|
|
|
|
|
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
public override string ToString() =>
|
|
|
|
|
"FormerCaste(" + (casteless ? "no caste" : casteId.ToString()) + ", " + side + ", tick " + tick + ")";
|
|
|
|
|
}
|
|
|
|
|
|
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
|
|
|
/// <summary>Reason strings stored in memberships, join rows and the join queue.</summary>
|
|
|
|
|
public static class JoinReason
|
|
|
|
|
{
|
|
|
|
|
// The five join rows in 1.0.
|
|
|
|
|
public const string BoughtSlave = "boughtSlave";
|
|
|
|
|
public const string BoughtColonist = "boughtColonist";
|
|
|
|
|
public const string NewColonist = "newColonist";
|
|
|
|
|
public const string NewSlave = "newSlave";
|
|
|
|
|
public const string NewPrisoner = "newPrisoner";
|
|
|
|
|
|
|
|
|
|
// Reasons that are not join rows.
|
|
|
|
|
public const string Manual = "manual";
|
|
|
|
|
public const string CasteDeleted = "casteDeleted";
|
feat: Castes 1.0 scope: schedule, work priorities, loadouts, automatic status changes
Starter castes, join rows on every status change, old caste on return, overlap warnings, review fixes, test runner switches (-NoDlc, -Dlc, -Tasoc), Blax footer, deterministic DLL.
2026-11-29 10:57:22 +00:00
|
|
|
/// <summary>A returning pawn got back the caste it had before it left (FormerCaste).</summary>
|
|
|
|
|
public const string PreviousCaste = "previousCaste";
|
feat: Blax Castes 1.0, work in progress
Castes bundle a pawn's apparel, food, drug and reading policy and medical
care. Join defaults put bought slaves, bought colonists, new colonists,
new slaves and new prisoners into a caste one tick after they join.
Includes the caste manager window, the Caste column in the Assign tab,
the join defaults window, Workshop art and the in-game test suite.
State: core and join defaults pass the suite (47 pass, 1 compat-only
skip). The manager window and Assign column were merged afterwards and
build, but the merged state has not run through the tests or review yet.
2026-11-28 22:22:36 +00:00
|
|
|
|
|
|
|
|
/// <summary>The join rows in display order.</summary>
|
|
|
|
|
public static readonly string[] Rows = { BoughtSlave, BoughtColonist, NewColonist, NewSlave, NewPrisoner };
|
|
|
|
|
|
|
|
|
|
public static bool IsRow(string reason)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < Rows.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (Rows[i] == reason)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|