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 System;
|
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Verse;
|
|
|
|
|
|
|
|
|
|
namespace BlaxCastes
|
|
|
|
|
{
|
|
|
|
|
public class BlaxCastesSettings : ModSettings
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Off: castes never write a pawn's policies. Castes, rows and memberships stay in the save.</summary>
|
|
|
|
|
public bool enabled = true;
|
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>Castes set the work priorities they list. Off: work priorities are never written.</summary>
|
|
|
|
|
public bool manageWorkPriorities = true;
|
|
|
|
|
/// <summary>With Weapons Tab Reborn, castes set the weapon loadout. Off: loadouts are never written.</summary>
|
|
|
|
|
public bool manageWeaponLoadout = true;
|
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>Joining pawns are put into the caste their join row picks.</summary>
|
|
|
|
|
public bool enableJoinDefaults = true;
|
|
|
|
|
/// <summary>A message names the caste a joining pawn was put into.</summary>
|
|
|
|
|
public bool joinMessages = true;
|
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 join row set to No caste takes a pawn out of a caste a join row put it in, and resets the
|
|
|
|
|
/// managed policies it still has from that caste. Only governs that revert.
|
|
|
|
|
/// </summary>
|
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 bool revertOnLeave = true;
|
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 pawn that comes back within formerCasteDays with the same status gets its old caste back.</summary>
|
|
|
|
|
public bool returnToPreviousCaste = true;
|
|
|
|
|
/// <summary>How long a former-caste record lasts, in days.</summary>
|
|
|
|
|
public int formerCasteDays = DefaultFormerCasteDays;
|
|
|
|
|
/// <summary>A new game, or a save without castes, gets the Colonist, Slave and Prisoner castes.</summary>
|
|
|
|
|
public bool seedStarterCastes = true;
|
|
|
|
|
/// <summary>The settings page and a message per save name active mods whose join defaults overlap.</summary>
|
|
|
|
|
public bool warnOverlaps = true;
|
|
|
|
|
/// <summary>The Caste column in the Assign, Schedule and Work tabs. Read once at startup.</summary>
|
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 bool showAssignColumn = true;
|
|
|
|
|
|
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 const int DefaultFormerCasteDays = 60;
|
|
|
|
|
public const int MinFormerCasteDays = 1;
|
|
|
|
|
public const int MaxFormerCasteDays = 120;
|
|
|
|
|
|
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 override void ExposeData()
|
|
|
|
|
{
|
|
|
|
|
base.ExposeData();
|
|
|
|
|
Scribe_Values.Look(ref enabled, "enabled", true);
|
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 manageWorkPriorities, "manageWorkPriorities", true);
|
|
|
|
|
Scribe_Values.Look(ref manageWeaponLoadout, "manageWeaponLoadout", true);
|
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
|
|
|
Scribe_Values.Look(ref enableJoinDefaults, "enableJoinDefaults", true);
|
|
|
|
|
Scribe_Values.Look(ref joinMessages, "joinMessages", true);
|
|
|
|
|
Scribe_Values.Look(ref revertOnLeave, "revertOnLeave", true);
|
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 returnToPreviousCaste, "returnToPreviousCaste", true);
|
|
|
|
|
Scribe_Values.Look(ref formerCasteDays, "formerCasteDays", DefaultFormerCasteDays);
|
|
|
|
|
Scribe_Values.Look(ref seedStarterCastes, "seedStarterCastes", true);
|
|
|
|
|
Scribe_Values.Look(ref warnOverlaps, "warnOverlaps", true);
|
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
|
|
|
Scribe_Values.Look(ref showAssignColumn, "showAssignColumn", true);
|
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)
|
|
|
|
|
formerCasteDays = Mathf.Clamp(formerCasteDays, MinFormerCasteDays, MaxFormerCasteDays);
|
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 void Reset()
|
|
|
|
|
{
|
|
|
|
|
var d = new BlaxCastesSettings();
|
|
|
|
|
enabled = d.enabled;
|
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
|
|
|
manageWorkPriorities = d.manageWorkPriorities;
|
|
|
|
|
manageWeaponLoadout = d.manageWeaponLoadout;
|
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
|
|
|
enableJoinDefaults = d.enableJoinDefaults;
|
|
|
|
|
joinMessages = d.joinMessages;
|
|
|
|
|
revertOnLeave = d.revertOnLeave;
|
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
|
|
|
returnToPreviousCaste = d.returnToPreviousCaste;
|
|
|
|
|
formerCasteDays = d.formerCasteDays;
|
|
|
|
|
seedStarterCastes = d.seedStarterCastes;
|
|
|
|
|
warnOverlaps = d.warnOverlaps;
|
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
|
|
|
showAssignColumn = d.showAssignColumn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class BlaxCastesMod : Mod
|
|
|
|
|
{
|
|
|
|
|
public static BlaxCastesSettings Settings;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raised after the settings window closes and the settings are written. Features that read
|
|
|
|
|
/// a setting once (the Assign column) can react here.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event Action SettingsChanged;
|
|
|
|
|
|
|
|
|
|
/// <summary>The "enabled" setting. True before the settings exist, so nothing is lost while loading.</summary>
|
|
|
|
|
public static bool Enabled => Settings == null || Settings.enabled;
|
|
|
|
|
|
|
|
|
|
public BlaxCastesMod(ModContentPack content) : base(content)
|
|
|
|
|
{
|
|
|
|
|
Settings = GetSettings<BlaxCastesSettings>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string SettingsCategory() => "Blax Castes";
|
|
|
|
|
|
|
|
|
|
public override void WriteSettings()
|
|
|
|
|
{
|
|
|
|
|
base.WriteSettings();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SettingsChanged?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("[Blax Castes] Re-applying settings failed: " + e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void DoSettingsWindowContents(Rect inRect)
|
|
|
|
|
{
|
|
|
|
|
BlaxCastesSettings s = Settings;
|
|
|
|
|
var l = new Listing_Standard();
|
|
|
|
|
l.maxOneColumn = true;
|
|
|
|
|
l.Begin(inRect);
|
|
|
|
|
|
|
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingEnabled".Translate(), ref s.enabled, "BlaxCastes_SettingEnabledTip".Translate());
|
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
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingWorkPriorities".Translate(), ref s.manageWorkPriorities, "BlaxCastes_SettingWorkPrioritiesTip".Translate());
|
|
|
|
|
string workManager = WorkSlot.ActiveManager();
|
|
|
|
|
if (workManager != null)
|
|
|
|
|
{
|
|
|
|
|
using (new TextBlock(ColorLibrary.Gold))
|
|
|
|
|
l.Label("BlaxCastes_WorkManagerActive".Translate(workManager));
|
|
|
|
|
}
|
|
|
|
|
if (WeaponsTab.ModActive)
|
|
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingWeaponLoadout".Translate(), ref s.manageWeaponLoadout, "BlaxCastes_SettingWeaponLoadoutTip".Translate());
|
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
|
|
|
l.GapLine();
|
|
|
|
|
|
|
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingJoinDefaults".Translate(), ref s.enableJoinDefaults, "BlaxCastes_SettingJoinDefaultsTip".Translate());
|
|
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingJoinMessages".Translate(), ref s.joinMessages, "BlaxCastes_SettingJoinMessagesTip".Translate());
|
|
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingRevertOnLeave".Translate(), ref s.revertOnLeave, "BlaxCastes_SettingRevertOnLeaveTip".Translate());
|
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
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingReturnToPrevious".Translate(), ref s.returnToPreviousCaste, "BlaxCastes_SettingReturnToPreviousTip".Translate());
|
|
|
|
|
if (s.returnToPreviousCaste)
|
|
|
|
|
{
|
|
|
|
|
s.formerCasteDays = Mathf.RoundToInt(l.SliderLabeled("BlaxCastes_SettingFormerCasteDays".Translate(s.formerCasteDays),
|
|
|
|
|
s.formerCasteDays, BlaxCastesSettings.MinFormerCasteDays, BlaxCastesSettings.MaxFormerCasteDays, 0.6f,
|
|
|
|
|
"BlaxCastes_SettingFormerCasteDaysTip".Translate()));
|
|
|
|
|
}
|
|
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingSeedStarter".Translate(), ref s.seedStarterCastes, "BlaxCastes_SettingSeedStarterTip".Translate());
|
|
|
|
|
l.GapLine();
|
|
|
|
|
|
|
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingWarnOverlaps".Translate(), ref s.warnOverlaps, "BlaxCastes_SettingWarnOverlapsTip".Translate());
|
|
|
|
|
string overlaps = OverlapWarnings.SettingsText();
|
|
|
|
|
if (!overlaps.NullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
using (new TextBlock(ColorLibrary.Gold))
|
|
|
|
|
l.Label(overlaps);
|
|
|
|
|
}
|
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
|
|
|
l.GapLine();
|
|
|
|
|
|
|
|
|
|
l.CheckboxLabeled("BlaxCastes_SettingShowAssignColumn".Translate(), ref s.showAssignColumn, "BlaxCastes_SettingShowAssignColumnTip".Translate());
|
|
|
|
|
if (Current.Game != null && GameComponent_BlaxCastes.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
// The way in while the Caste column is off.
|
|
|
|
|
l.Gap(6f);
|
|
|
|
|
l.Label("BlaxCastes_SettingOpenWindows".Translate());
|
|
|
|
|
if (l.ButtonText("BlaxCastes_ManageCastesButton".Translate()))
|
|
|
|
|
Find.WindowStack.Add(new Dialog_ManageCastes());
|
|
|
|
|
if (l.ButtonText("BlaxCastes_JoinDefaultsTitle".Translate()))
|
|
|
|
|
Find.WindowStack.Add(new Dialog_JoinDefaults());
|
|
|
|
|
}
|
|
|
|
|
if (!ModsConfig.IdeologyActive)
|
|
|
|
|
{
|
|
|
|
|
l.GapLine();
|
|
|
|
|
l.Label("BlaxCastes_SettingNoIdeology".Translate());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l.Gap();
|
|
|
|
|
if (l.ButtonText("BlaxCastes_SettingsReset".Translate()))
|
|
|
|
|
s.Reset();
|
|
|
|
|
l.End();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies the Harmony patches after every Mod class exists (so the Harmony mod has set up
|
|
|
|
|
/// its 1.7 backend), one class at a time so a single broken target can't take the rest down.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[StaticConstructorOnStartup]
|
|
|
|
|
public static class BlaxCastesStartup
|
|
|
|
|
{
|
|
|
|
|
public const string HarmonyId = "blax.castes";
|
|
|
|
|
public static readonly Harmony Harmony = new Harmony(HarmonyId);
|
|
|
|
|
|
|
|
|
|
static BlaxCastesStartup()
|
|
|
|
|
{
|
|
|
|
|
int ok = 0, failed = 0;
|
|
|
|
|
foreach (Type type in typeof(BlaxCastesStartup).Assembly.GetTypes())
|
|
|
|
|
{
|
|
|
|
|
if (!type.IsDefined(typeof(HarmonyPatch), false))
|
|
|
|
|
continue;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Harmony.CreateClassProcessor(type).Patch();
|
|
|
|
|
ok++;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
failed++;
|
|
|
|
|
Log.Error("[Blax Castes] Patch " + type.Name + " failed: " + e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Log.Message("[Blax Castes] " + ok + " patches applied" + (failed > 0 ? ", " + failed + " failed" : ""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|