rimworld-blax-castes/README.md

11 KiB

Blax Castes

RimWorld mod (1.7) by Blax Gaming: policy bundles and join defaults. Every slave you buy needs its apparel, food, drug and reading policy set by hand. Blax Castes bundles those policies into castes such as Slave or Miner slave, and puts each new pawn into the right caste the moment it joins. Needs Harmony. Works without DLCs; slaves need Ideology.

Design and roadmap: docs/design.md.

Features (1.0)

  • Castes. A caste manages up to five slots: apparel, food, drug and reading policy, and medical care. Each slot is either a vanilla policy (or a medical care level) or left alone. Putting a pawn in a caste writes every managed slot through the vanilla setters. Source/BlaxCastes/Caste.cs, CasteUtility.cs
  • Per-slot checks. Apparel, drugs and reading need the pawn's tracker and skip quest lodgers, prisoners and mutants without policies. Food needs a configurable food tracker and skips babies. Medical care needs player settings and a flesh pawn. So a prisoner in a caste gets its food policy and medical care only.
  • Members follow their caste. Change a caste's slot and every member still on the old value gets the new one. Members you changed by hand keep theirs. A slot that was left alone and becomes managed reaches every member; a slot that stops being managed changes nobody. Edits inside a policy (the Slave outfit's filter) reach members through the vanilla reference. Source/BlaxCastes/CasteManager.cs
  • Caste manager. Assign tab > "Manage castes" above the Caste column. It is the vanilla policy manager: the caste list with new, duplicate, rename, delete and make default on the left, and one row per slot on the right with a "managed" checkbox, a dropdown and a pencil that opens the vanilla editor for that policy. Ticking a slot starts it at the game's default policy (or the colonist default medical care). Deleting a caste leaves its members casteless on their current policies, and join rows that pointed at it fall back to No caste. Source/BlaxCastes/Dialog_ManageCastes.cs
  • Caste column. A Caste column in the Assign tab, left of hostility, medical care and the policy columns. Click a cell for the menu (No caste, every caste, Reset to caste, Edit caste), or drag down the column to give several pawns the same caste. The cell shows the caste, the caste with "*" when one of the pawn's managed policies differs (the tooltip names each slot with both values), "No caste" when you took the pawn out by hand, "None" when it never had one, "(pending)" while a join waits for the next tick, and "Unchangeable" for quest lodgers. The column sorts by caste, pawns without one last. Source/BlaxCastes/PawnColumnWorker_BlaxCaste.cs, Patches/BlaxCastes_Assign.xml
  • Join defaults. Assign tab > "Defaults" above the Caste column. Five rows pick a caste for bought as slave, bought as colonist, new colonist, new slave and new prisoner: No caste, Default caste (the one marked default in the manager) or a specific caste. Every row starts at No caste, so nothing changes until you pick one. Without Ideology the two slave rows are hidden. Source/BlaxCastes/JoinDefaults.cs, Dialog_JoinDefaults.cs
    • Buying a pawn from a trader uses the bought rows; the pawn's final status picks slave or colonist. Everything else goes by final status: recruiting and freeing to new colonist, enslaving and returned runaways to new slave, capturing, quest prisoners and arrests to new prisoner.
    • Castes applies a join one tick after it happens, after the game's own status-change resets, so its choice wins over mods that set policies in the same call. A bought slave arrives wearing its caste's outfit and eating its food, and a message names the caste.
    • A caste you pick by hand before the join is applied wins over the row. A pawn sold or released before then is dropped.
    • A No caste row takes a pawn out of the caste it was in. With "Reset policies" on, the caste's managed policies go back to the game defaults and medical care is reset, so a recruited prisoner does not keep the prisoner food. This also applies to an arrested colonist while the new prisoner row is No caste.
    • Babies, quest lodgers and mutants without policies are skipped.
  • Leaving. A pawn that leaves your faction (sold, released, gone to another faction) leaves its caste on the next tick, and a check every 2500 ticks catches the rest. Its policies stay as they are.
  • First load. A new game, or the first load of a save with Castes, posts one message that points to Assign > Manage castes.
  • Settings. enabled (off: castes never write a policy; castes and memberships stay in the save), enableJoinDefaults, joinMessages, revertOnLeave ("Reset policies when a join takes a pawn out of its caste"), showAssignColumn (needs a restart). All on by default. While a game is loaded, the settings page also has "Manage castes" and "Join defaults" buttons, the way in while the column is off. Source/BlaxCastes/BlaxCastesMod.cs

Save safety: all state lives in one game component (GameComponent_BlaxCastes), nothing is stored on vanilla objects, and the only vanilla data Castes writes is each pawn's own policy fields. Memberships drop pawns that are discarded or destroyed without being dead, on every save and after loading. A policy that left its database (a mod deleting it without TryDelete, or a delete in a vanilla editor opened from the manager) becomes unmanaged with one warning per caste. Joins waiting for the next tick are saved with the game. Adding the mod to a running save works; removing it leaves every pawn on its last policies and one "type not found" line for the component.

Replaces: Automatic Slave Outfit and PrisonerDefaults, the join defaults of Better Pawn Control, Better Pawn Control Forked and 1trickPwnyta's Defaults, and partly Save My Settings (clothing and food presets per pawn).

Compat:

  • Blax Slaves: its buy-as-slave-or-colonist button lands in the right bought row, and returned runaways land in the new slave row. Castes calls nothing in Blax Slaves.
  • Trade as Slave or Colonist: same as Blax Slaves' buy mode.
  • Better Pawn Control, its fork and 1trickPwnyta's Defaults have join defaults of their own. Castes applies a tick after the join, so its row wins. Turn theirs off so two mods don't write the same policies.
  • Tested next to Hospitality, Custom Prisoner Interactions and Prisoner Realism.
  • Numbers builds its own tables, so the Caste column shows only in the vanilla Assign tab.

Not supported yet: multiplayer, animal castes. Ready-made castes, a caste button on selected pawns and overlap warnings come in 1.1.

Development

The repo is the mod folder. Link it into the game with a directory junction, run from the repo root (adjust the RimWorld path); Tests/run-tests.ps1 creates it if it is missing:

New-Item -ItemType Junction -Path "E:\SteamLibrary\steamapps\common\RimWorld\Mods\BlaxCastes" -Target (Get-Location).Path

Build (needs the .NET 10 SDK; output goes to 1.7/Assemblies/BlaxCastes.dll):

dotnet build Source\BlaxCastes\BlaxCastes.csproj -c Release

RimWorldDir and HarmonyDir in the csproj point at the Steam install and the Harmony mod; override them with -p:RimWorldDir=... elsewhere.

RimWorld 1.7 no longer runs on Unity/Mono. It runs on .NET 10 (CoreCLR) with Ludeon's own engine ("Waylith"):

  • Assembly-CSharp.dll and UnityStubs.dll (Rect, Color...) sit in the install root, and target net10.0.
  • Harmony for 1.7 is the Harmony mod's 1.7/Assemblies/0Harmony.dll (Workshop 2009463077). Reference it, don't ship it. Parameterless PatchAll() is obsolete in Harmony 3.
  • Patches are applied from a [StaticConstructorOnStartup] class, one class at a time, so one broken target can't disable the rest. Check Player.log for [Blax Castes] 3 patches applied (the join hooks on Pawn.SetFaction, Pawn_GuestTracker.SetGuestStatus and Pawn.PreTraded).

Every change to castes, memberships, join rows and the default caste goes through CasteManager, so the sync rules and the enabled switch hold whichever window or hook made the change.

Works with the other Blax mods: Castes has no hard dependency on Blax Slaves or Blax Zones and calls nothing in them. Load order is Castes, Zones, Slaves; Castes lists no sibling in loadAfter. Detection goes through Compat.IsActive(packageId), which matches a local copy next to a Workshop copy. Before 1.3 there is no API.

Workshop art (About/Preview.png, About/ModIcon.png) is rendered from Source/Art; see Source/Art/README.md.

Tests

Tests/BlaxCastesTests is a separate test mod. Tests/run-tests.ps1 builds both projects, links the test mod into the game's Mods folder for the run, and starts RimWorld headless (-headless -quicktest -blaxcastestests, no window) with its own save data folder in %TEMP%\BlaxCastesTest, so your mod list, saves and settings stay untouched. The suite runs in a quick-test colony, saves and reloads the game, runs the persistence tests, writes BlaxCastesTestResults.txt and quits. It takes under a minute and needs Steam running.

.\Tests\run-tests.ps1                     # refuses while RimWorld is open
.\Tests\run-tests.ps1 -AllowWhileRunning  # runs next to an open game, at below-normal priority
.\Tests\run-tests.ps1 -AllowWhileRunning -Compat -NoBuild

If PowerShell blocks scripts, run it as powershell -ExecutionPolicy Bypass -File .\Tests\run-tests.ps1 -AllowWhileRunning.

-Compat also loads Blax Slaves and the installed mods Castes overlaps with (Hospitality, Trade as Slave or Colonist, Custom Prisoner Interactions, Prisoner Realism), in the load order Castes, then Slaves. -NoBuild skips the build. Only one run at a time: a lock file in the data folder holds the running script's process id, and a lock left by a dead process is taken over. Mods\BlaxCastes must be a junction to this repo; the script creates it if missing and stops if a real folder is in the way. Exit code 0 means all passed, 1 failures, 2 the run didn't finish (see game.log and game.err.log in the data folder).

Tests are public static void methods marked [BlaxTest("area: what", phase: 1)], using T for assertions and Fixtures for colonists, prisoners, slaves, quest lodgers, babies, castes, policies and ticks. Phase 2 runs after the save and reload; carry ids through T.Carry, or T.CarryAtSave for values later phase-1 tests may still change. Without Ideology the slave tests skip; without Biotech the baby tests skip. The buy-mode compat test needs -Compat. Headless runs have no GUI, so the tests drive the logic behind the windows and the column; drawing is checked by hand.

Useful 1.7 switches for manual runs: -quicktest (straight into a generated colony), -headless, -savedatafolder=<dir>, -QuitAfterBoot, -NoFileLog.

A decompiled copy of the 1.7 game code for reference lives outside the repo in ..\rimworld-src-1.7 (never commit or publish it).