23 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, its schedule and its work priorities set by hand. Blax Castes bundles those settings into castes such as Slave or Miner slave, and puts each pawn into the right caste the moment it joins or changes status. Needs Harmony. Works without DLCs; slaves need Ideology.
Design and roadmap: docs/design.md.
Features (1.0)
- 📦 Castes. A caste manages up to eight slots: apparel, food, drug and reading policy, medical care, schedule, work priorities and, with [1001] Weapons Tab Reborn, the weapon loadout. Each slot is set or left alone. Putting a pawn in a caste writes every managed slot through the vanilla setters (and Weapons Tab Reborn's own API for the loadout).
Source/BlaxCastes/Caste.cs,CasteUtility.cs - ✅ Per-slot checks. Apparel, drugs, reading and the schedule need the pawn's tracker and skip quest lodgers, prisoners and mutants without policies; apparel also skips mutants that wear no apparel, and the schedule skips the mutants the Schedule tab leaves out. Food needs a configurable food tracker and skips babies and mutants without policies. Medical care needs player settings and a flesh pawn. Work priorities and the loadout are for colonists and slaves only. So a prisoner in a caste gets its food policy and medical care only.
- 🕒 Schedule. A caste can carry a full day: 24 hours of anything, work, recreation, sleep or meditate. The manager paints it like the vanilla Schedule tab: pick the activity with the vanilla selector, then click or drag over the hours. A drag paints only when it starts on the hours, so dragging the scrollbar past them never paints. "Copy from pawn" takes the schedule of one of your colonists or slaves, and "Leave alone" stops managing it. While the caste leaves the schedule alone, the first painted hour (or a copy) gives every member the whole day; the tooltips say so. A pawn whose whole day matches the caste follows every change; one hour changed by hand and the pawn keeps its own. An hour whose activity no longer exists (Meditate without Royalty, a removed mod) becomes Anything.
Source/BlaxCastes/ScheduleSlot.cs - 🛠️ Work priorities. A caste sets only the work types you pick, each to 1, 2, 3, 4 or off; the rest stay as they are. So every caste can set Firefighting to 1, and a Field slave caste Growing 1 and Plant cutting 2. Work types a pawn cannot do are skipped. With manual priorities off, any number means on; Castes still stores the caste's number, so turning manual priorities on later leaves every member following its caste. "Start from nothing" turns every other work type off first, for castes that should do only their listed work; Patient and Bed rest stay as they are, because they are how a hurt or sick colonist or slave goes to bed. The Follow rule works per work type. The slot turns itself off while Work Tab, Free Will, Work Manager, AutoPriorities or WorkRoles is active, because those set priorities all the time.
Source/BlaxCastes/WorkSlot.cs - 🗡️ Weapon loadout. With [1001] Weapons Tab Reborn active, a caste can set the pawn's weapon loadout: a Guard caste the rifle loadout, a Slave caste the unarmed one. Without the mod the row is hidden. Castes calls the API Weapons Tab Reborn publishes for Better Pawn Control, found by reflection; if that API is missing or fails, the slot turns itself off with one warning in the log, and a call that fails never counts as a deleted loadout. In a save made without Weapons Tab Reborn, Castes creates the mod's loadout database the way the mod does, so the slot works at once. A loadout deleted in Weapons Tab Reborn becomes unmanaged in the caste, with one warning.
Source/BlaxCastes/WeaponsTab.cs - 🔗 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 - 🌱 Starter castes. A new game starts with three castes, already picked in the join defaults: Colonist (your current default apparel, food, drug and reading policy, medical care left alone), Slave (the Slave outfit, Simple food, No drugs; reading and medical care left alone) and Prisoner (Simple food). Bought and new colonists use Default caste, which is Colonist; bought and new slaves use Slave; new prisoners use Prisoner. The starting colonists go into Colonist, so their policies do not change. Policies are found by their starting names (No drugs by its source def); one that was renamed or deleted leaves its slot alone. Without Ideology there is no Slave caste and the slave rows stay at No caste. A save without castes gets the starter castes once, on load, with one message (it points to the mod settings while the Caste column is off); nobody moves until you click "Assign by status", which gives each pawn its caste's policies in place of its own.
Source/BlaxCastes/StarterCastes.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 on the right a scrolling list of the slots: one row per policy with a "managed" checkbox, a dropdown and a pencil that opens the vanilla editor for that policy, the weapon loadout row while Weapons Tab Reborn is active, the schedule grid and a cycle button per work type (leave alone, 1, 2, 3, 4, off) with "Start from nothing". Clicking a cycle button several times in a row moves only the members that followed the work type before the first click, so a pawn you set by hand to a value the cycle passes through keeps it; pawns "Assign by status" puts into the caste in between start on the caste's value and follow the next clicks too. Ticking a slot starts it at the game's default policy (or the colonist default medical care, or Weapons Tab Reborn's default loadout). The work priorities are greyed out, with a note, while the setting is off or an automatic work manager is active. Below the slots: the member count and "Apply to all members", which asks first, naming the count, and then sets every managed slot on every member, hand changes included. Next to the close button, "Assign by status (N)" shows while pawns without a caste exist: it asks first, because it replaces those pawns' own policies with their caste's, then puts each into the caste of its new colonist, new slave or new prisoner row, and skips pawns you set to No caste. "Make default" explains the default caste in its tooltip. When the game has no Slave outfit, a "Create Slave outfit" button makes one. A caste using the Slave outfit warns that it has no cold protection. 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; the same column sits right of the timetable in the Schedule tab (clear of the tab's activity selector) and left of the work columns in the Work tab. In the Work tab only "Manage castes" sits above it, so the header keeps the work columns' height. 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; pawns already in that caste keep their hand changes while you drag. The cell shows the caste, the caste with "*" when one of the pawn's managed slots differs (the tooltip names each slot with both values; for the schedule it says "Schedule", for work priorities it names each work type that differs), "No caste" when you took the pawn out by hand or its caste was deleted, "None" when it is not in a caste, "(pending)" while a join will change its caste on the next tick, and "Unchangeable" for quest lodgers. The first click on the header sorts by caste, pawns without one last; the second click reverses it.
Source/BlaxCastes/PawnColumnWorker_BlaxCaste.cs,CasteColumns.cs,Patches/BlaxCastes_Assign.xml,Patches/BlaxCastes_ScheduleWork.xml - 🚪 Join defaults and status changes. 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. 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. Every other change between colonist, slave and prisoner goes by the final status: recruiting, freeing a slave and releasing an arrested colonist to new colonist; enslaving and returned runaways to new slave; capturing, quest prisoners, arresting a colonist and imprisoning a slave 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 with its caste's outfit and food policy already set, 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 a caste a join row had put it in; a caste you picked by hand stays. With "Reset policies" on, the policies it still has from that caste go back to the game defaults (medical care to the game's default for its status, if the caste set it); policies you changed by hand stay. The same happens when a row moves a pawn on from a row-set caste to a caste that leaves some of those policies alone, so a recruited prisoner does not keep the prisoner food. The schedule, work priorities and loadout have no game default and stay as they are.
- Babies, quest lodgers and mutants without policies are skipped.
- ↩️ The old caste comes back. When a colonist or slave leaves your faction, is sold or becomes a prisoner, Castes remembers its caste (or No caste, if you set that) and its own settings from just before the change. If it comes back within 60 days (a setting) with the same status, it gets that caste back instead of its row's: an arrested Miner who is released is a Miner again, a Miner slave you sell and buy back is a Miner slave again, and a pawn you set to No caste is back at No caste. It keeps what you had changed by hand: settings that followed the caste get the caste's current value, settings you had changed get your value back, and a setting the caste started managing while it was away (a schedule, a work type) gets the caste's value, as it did for every member. A policy you deleted in the meantime is skipped, even if a new policy got its number. What the caste it had while it was away set (the prisoner caste's food) goes back to how it was. An arrested colonist who is then enslaved goes to the new slave row. Records are saved with the game, keyed by the pawn's ID, and dropped when they are older than the setting or their caste is deleted.
- 👋 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. Leaving the map counts by where the pawn ends up: a freed slave from another faction that walks off, an escaped slave or prisoner, or a pawn left on a map that closes leaves its caste (a slave with its slave caste remembered), and nothing joins a caste on the way out. A pawn that leaves in a caravan, a transport pod or a shuttle, or is kidnapped, is still yours and keeps its caste.
- ⚠️ Overlap warnings. If Better Pawn Control, Better Pawn Control Forked, 1trickPwnyta's Defaults, Automatic Slave Outfit or PrisonerDefaults is active, the settings page names it and what it sets, and one message per save suggests turning those options off. Castes still wins, because it applies a tick later. Detection only; Castes patches none of them.
Source/BlaxCastes/OverlapWarnings.cs,Compat.cs - 💬 First load. A new game, or the first load of a save that already has castes, posts one message that points to Assign > Manage castes. While the game runs without the Caste column it waits; a change to the column setting counts after the restart it needs, for this message and the starter castes message.
- ⚙️ Settings.
enabled(off: castes never write a policy, schedule, work priority or loadout; castes and memberships stay in the save),manageWorkPriorities,manageWeaponLoadout(shown while Weapons Tab Reborn is active),enableJoinDefaults,joinMessages,revertOnLeave("Reset policies a caste set when a join moves the pawn on"; only governs that revert),returnToPreviousCasteandformerCasteDays(60),seedStarterCastes,warnOverlaps,showAssignColumn(the Caste column in the Assign, Schedule and Work tabs; needs a restart). All toggles are 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 policies, medical care, timetable and work priorities (and its Weapons Tab Reborn loadout, through that mod's API). Schedules and work priorities are saved as def names and loadouts as ids, never as references. 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) or a loadout Weapons Tab Reborn no longer has becomes unmanaged with one warning per caste; a schedule hour whose activity is gone becomes Anything, and a work type that is gone is dropped, each with one warning. Without Weapons Tab Reborn a caste keeps its loadout id for when the mod comes back. Joins waiting for the next tick are saved with the game. Former-caste records are keyed by the pawn's ID, not by reference; the pawn's own policies in a record are kept like a caste's, and a policy deleted since is dropped before the save, so loading never meets one it cannot find or mistakes a new policy with the same number and name for it. Adding the mod to a running save works. Removing it leaves every pawn on its last policies; the next load logs two red errors for the missing component ("Could not find class BlaxCastes.GameComponent_BlaxCastes" and "Can't load abstract class Verse.GameComponent"). They do no harm and go away once the game is saved again.
Replaces: Automatic Slave Outfit and PrisonerDefaults, the join, schedule and work defaults of Better Pawn Control, Better Pawn Control Forked and 1trickPwnyta's Defaults, the joiner work priorities of Plug and Play Joiner, 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 (or their old caste). Castes calls nothing in Blax Slaves.
- Trade as Slave or Colonist: same as Blax Slaves' buy mode. Blax Slaves' buy mode stands down while it is active.
- Better Pawn Control, its fork, 1trickPwnyta's Defaults, Automatic Slave Outfit and PrisonerDefaults set policies of their own when a pawn joins. Castes applies a tick after the join, so its row wins, and it warns while one of them is active. Turn theirs off so two mods don't write the same policies.
- [1001] Weapons Tab Reborn: the weapon loadout slot. It has no 1.7 build; 1.7 loads its 1.6 assembly, and its loadout API works there. A caste that sets the loadout writes it a tick after a join, so it wins over Weapons Tab Reborn's default loadout; a caste that leaves it alone leaves Weapons Tab Reborn in charge.
- Work Tab, Free Will, Work Manager, AutoPriorities and WorkRoles set work priorities themselves, so while one of them is active the work priorities slot is off and greyed out in the manager.
- Tested next to Hospitality, Custom Prisoner Interactions, Prisoner Realism and Weapons Tab Reborn.
- Numbers builds its own tables, so the Caste column shows only in the vanilla Assign, Schedule and Work tabs.
Not supported yet: multiplayer, animal castes. A caste button on selected pawns comes 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.dllandUnityStubs.dll(Rect, Color...) sit in the install root, and targetnet10.0.- Harmony for 1.7 is the Harmony mod's
1.7/Assemblies/0Harmony.dll(Workshop 2009463077). Reference it, don't ship it. ParameterlessPatchAll()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. CheckPlayer.logfor[Blax Castes] 5 patches applied(the join hooks onPawn.SetFaction,Pawn_GuestTracker.SetGuestStatusandPawn.PreTraded, and the leaving hooks onPawn.ExitMapandMapDeiniter.PassPawnsToWorld).
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. Every run starts from default mod settings. 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
.\Tests\run-tests.ps1 -AllowWhileRunning -Compat -Tasoc -NoBuild
.\Tests\run-tests.ps1 -AllowWhileRunning -NoDlc -NoBuild
If PowerShell blocks scripts, run it as powershell -ExecutionPolicy Bypass -File .\Tests\run-tests.ps1 -AllowWhileRunning.
-Compatalso loads Blax Slaves and the installed mods Castes is tested next to (Hospitality, Custom Prisoner Interactions, Prisoner Realism, Weapons Tab Reborn), in the load order Castes, then Slaves. Trade as Slave or Colonist stays out, so the buy-mode test drives Blax Slaves' own buy mode. The loadout tests run only here; without Weapons Tab Reborn they skip, and one test checks the slot stays off.-Tasocadds Trade as Slave or Colonist; Blax Slaves' buy mode stands down for it, and the buy-mode test drives that mod instead.-NoDlcruns on the core game alone;-Dlc Royalty,Biotechloads only the named installed DLCs. Every installed DLC is still listed as known, so the game does not switch a left-out one on.-NoBuildskips the build.
The mods whose join defaults overlap with Castes (Better Pawn Control, its fork, 1trickPwnyta's Defaults, Automatic Slave Outfit, PrisonerDefaults) and the automatic work managers are not installed on the test machine. Their package ids were read from each mod's About.xml in its public source repository (listed in Source/BlaxCastes/Compat.cs), and the overlap and work manager tests inject an id into the detection list.
A test fails when Blax Castes logs an error, or when an error's stack passes through the mod or the test code. Errors another mod logs from its own code while a test ticks the game are listed as LOGERR lines instead; the harness keeps a short list of them (KnownForeignErrors in Harness.cs). Today that is Weapons Tab Reborn's "tried to equip loadout" error, which it logs once for the first pawn of another faction that thinks.
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, ticks and queued joins. 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 or -Tasoc, the loadout tests -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.
Made by Blax
🛠️ Blax Gaming is a project of Blax Software, an Austrian software practice. We write Austrian-quality code in many fields: web platforms, mobile apps, backends, infrastructure, and the mods we play in our own colonies. Need something built? 👉 www.blax.at
