diff --git a/1.7/Assemblies/BlaxCastes.dll b/1.7/Assemblies/BlaxCastes.dll
index 3459a6c..4b8189e 100644
Binary files a/1.7/Assemblies/BlaxCastes.dll and b/1.7/Assemblies/BlaxCastes.dll differ
diff --git a/1.7/Assemblies/BlaxCastes.pdb b/1.7/Assemblies/BlaxCastes.pdb
index 3706e1b..9875e67 100644
Binary files a/1.7/Assemblies/BlaxCastes.pdb and b/1.7/Assemblies/BlaxCastes.pdb differ
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 350d061..166f4d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,14 +4,14 @@
- Castes: a caste bundles an apparel, food, drug and reading policy, a medical care level, a schedule, work priorities and, with [1001] Weapons Tab Reborn, a weapon loadout. Putting a pawn in a caste sets every slot the caste manages in one step. Prisoners get the food policy and medical care only; quest lodgers skip apparel, drugs, reading and the schedule; babies skip food.
- Schedule: paint a caste's 24 hours in the caste manager like the vanilla Schedule tab, or copy them from a pawn. Colonists and slaves get it; prisoners keep theirs until they become colonists or slaves.
-- Work priorities: a caste sets only the work types you pick (1 to 4 or off), so every caste can set Firefighting to 1. Work a pawn cannot do is skipped; with manual priorities off, any number means on, and the number is kept for when you turn them on. "Start from nothing" turns all other work off except Patient and Bed rest, so hurt and sick pawns still go to bed. Clicking a work type's button through several values moves only the members that followed it before the first click. Off while Work Tab, Free Will, Work Manager, AutoPriorities or WorkRoles is active.
-- Weapon loadout: with Weapons Tab Reborn active, a caste can hand out a loadout to its colonists and slaves. A loadout deleted in Weapons Tab Reborn becomes unmanaged. Without the mod the row is hidden.
+- Work priorities: a caste sets only the work types you pick (1 to 4 or off), so every caste can set Firefighting to 1. Work a pawn cannot do is skipped; with manual priorities off, any number means on, and the number is kept for when you turn them on. "Start from nothing" turns all other work off except Patient and Bed rest, so hurt and sick pawns still go to bed. Clicking a work type's button through several values moves only the members that followed it before the first click, plus pawns "Assign by status" put into the caste in between. Off while Work Tab, Free Will, Work Manager, AutoPriorities or WorkRoles is active.
+- Weapon loadout: with Weapons Tab Reborn active, a caste can hand out a loadout to its colonists and slaves. A loadout deleted in Weapons Tab Reborn becomes unmanaged. Works at once in a save made without the mod. Without the mod the row is hidden.
- Change a caste's slot and its members follow, except pawns you changed by hand. Schedules follow as a whole day, work priorities per work type.
- Starter castes: a new game starts with Colonist (your default policies), Slave (Slave outfit, Simple food, No drugs) and Prisoner (Simple food), already picked in the join defaults, and the starting colonists in Colonist. Their schedule, work priorities and loadout start unmanaged: set them once on the caste and every member follows. A save without castes gets them once, on load; nobody moves until you click "Assign by status", which asks first because it replaces those pawns' own policies. Without Ideology there is no Slave caste.
- Caste manager (Assign tab > Manage castes), built on the vanilla policy window: new, duplicate, rename, delete, make default, and per policy a managed checkbox, a dropdown and a pencil that opens the vanilla editor, plus the schedule grid, the work priority buttons and the loadout. Below the slots: the member count and "Apply to all members" (asks first). "Assign by status" puts pawns without a caste into the caste of their status. "Create Slave outfit" shows when the game has none, and a caste with the Slave outfit warns that it has no cold protection.
- Caste column in the Assign, Schedule and Work tabs (in the Schedule tab right of the timetable, in the Work tab left of the work columns): click a cell or drag down the column to assign; dragging keeps the hand changes of pawns already in that caste. Shows "*" and a tooltip when a pawn's settings differ from its caste, and "(pending)" until a join that changes its caste is applied.
- Join defaults (Assign tab > Defaults): pick No caste, the default caste or a specific caste for bought slaves, bought colonists, new colonists, new slaves and new prisoners. Every status change goes through these rows: buying, recruiting, enslaving, freeing, arresting, releasing, imprisoning a slave and capturing. A bought slave arrives with its caste's outfit and food policy already set, and a message names the caste. A No caste row takes a pawn out of a caste a join row put it in (a caste you picked by hand stays) and, with Reset policies on, resets the policies it still has from that caste; so does a row that moves it on to a caste that leaves those policies alone. Replaces Automatic Slave Outfit and PrisonerDefaults, and the join, schedule and work defaults of Better Pawn Control, Better Pawn Control Forked and 1trickPwnyta's Defaults.
-- A colonist or slave that leaves, is sold or becomes a prisoner and comes back within 60 days with the same status gets its old caste (or No caste) back, with the changes you made by hand; what the caste it had while away set goes back to how it was.
+- A colonist or slave that leaves, is sold or becomes a prisoner and comes back within 60 days with the same status gets its old caste (or No caste) back, with the changes you made by hand; what the caste started managing while it was away reaches it, a policy deleted in the meantime is skipped, and what the caste it had while away set goes back to how it was.
- Warnings on the settings page and one message per save when Better Pawn Control, its fork, 1trickPwnyta's Defaults, Automatic Slave Outfit or PrisonerDefaults is active.
-- A pawn that leaves your faction leaves its caste. Deleting a caste leaves its members casteless on their current settings.
+- A pawn that leaves your faction leaves its caste, and so does a freed slave from another faction that walks off, an escaped slave or prisoner, and a pawn left on a map that closes. A pawn that leaves in a caravan, a transport pod or a shuttle, or is kidnapped, keeps its caste. Deleting a caste leaves its members casteless on their current settings.
- Settings: castes on or off, work priorities, weapon loadout, join defaults, join messages, reset policies a caste set when a join moves the pawn on, old caste on return and for how many days, starter castes, overlap warnings, the Caste column. While a game is loaded, the settings page also opens the caste manager and the join defaults.
diff --git a/Languages/English/Keyed/BlaxCastes.xml b/Languages/English/Keyed/BlaxCastes.xml
index 4d436f3..b47b3b4 100644
--- a/Languages/English/Keyed/BlaxCastes.xml
+++ b/Languages/English/Keyed/BlaxCastes.xml
@@ -69,7 +69,7 @@
Warn about mods that also set join defaultsNames active mods that also set policies when a pawn joins, here and in one message per save.Caste column in the Assign, Schedule and Work tabs (needs a restart)
- Shows each pawn's caste left of the policy columns, the schedule and the work priorities. Click a cell to assign a caste.
+ Shows each pawn's caste left of the policy columns in the Assign tab, right of the timetable in the Schedule tab and left of the work priorities in the Work tab. Click a cell to assign a caste.Slaves need the Ideology DLC. Without it, castes still work for colonists and prisoners.Reset to defaults
diff --git a/README.md b/README.md
index f138690..2bc8186 100644
--- a/README.md
+++ b/README.md
@@ -15,12 +15,12 @@ Design and roadmap: `docs/design.md`.
- đĻ **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. "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`
+- đ **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. A loadout deleted in Weapons Tab Reborn becomes unmanaged in the caste, with one warning. `Source/BlaxCastes/WeaponsTab.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. 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 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.
@@ -28,13 +28,13 @@ Design and roadmap: `docs/design.md`.
- 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. 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.
+- âŠī¸ **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.
+- đŦ **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), `returnToPreviousCaste` and `formerCasteDays` (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. 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.
+đž 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).
@@ -70,7 +70,7 @@ RimWorld 1.7 no longer runs on Unity/Mono. It runs on .NET 10 (CoreCLR) with Lud
- `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`).
+- 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] 5 patches applied` (the join hooks on `Pawn.SetFaction`, `Pawn_GuestTracker.SetGuestStatus` and `Pawn.PreTraded`, and the leaving hooks on `Pawn.ExitMap` and `MapDeiniter.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.
diff --git a/Source/BlaxCastes/CasteColumns.cs b/Source/BlaxCastes/CasteColumns.cs
index 097189b..16df9bd 100644
--- a/Source/BlaxCastes/CasteColumns.cs
+++ b/Source/BlaxCastes/CasteColumns.cs
@@ -70,6 +70,20 @@ namespace BlaxCastes
public static PawnColumnDef Column => DefDatabase.GetNamedSilentFail(PawnColumnWorker_BlaxCaste.DefName);
+ ///
+ /// The Caste column, with its "Manage castes" button, is in the Assign tab: the showAssignColumn setting
+ /// the game started with. A change to the setting waits for a restart, so messages that point to the
+ /// column read this, not the setting.
+ ///
+ public static bool Shown
+ {
+ get
+ {
+ PawnColumnDef column = Column;
+ return column != null && Table?.columns != null && Table.columns.Contains(column);
+ }
+ }
+
///
/// The Assign table only. Off: removes the column. On: adds it back right before HostilityResponse
/// (or after the first column if that is gone) unless it is already there. Returns true if the
diff --git a/Source/BlaxCastes/CasteData.cs b/Source/BlaxCastes/CasteData.cs
index e0c70c8..597a449 100644
--- a/Source/BlaxCastes/CasteData.cs
+++ b/Source/BlaxCastes/CasteData.cs
@@ -1,4 +1,6 @@
using System.Collections.Generic;
+using System.Linq;
+using RimWorld;
using Verse;
namespace BlaxCastes
@@ -108,11 +110,15 @@ namespace BlaxCastes
///
/// 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
- /// leaves no unresolved reference. The caste and the policies are stored by id for the same reason.
+ /// 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).
/// 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
- /// (JoinDefaults.Restore): the slots it followed get the caste's current value, the ones it had
- /// changed by hand get that value back.
+ /// (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.
///
public class FormerCaste : IExposable
{
@@ -125,11 +131,11 @@ namespace BlaxCastes
public bool auto;
public int tick;
- // The pawn's own settings just before it left; -1 or null where it had none.
- public int apparelId = Caste.Unmanaged;
- public int foodId = Caste.Unmanaged;
- public int drugId = Caste.Unmanaged;
- public int readingId = Caste.Unmanaged;
+ // 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;
public int medCare = Caste.Unmanaged;
public int loadoutId = Caste.Unmanaged;
public List schedule;
@@ -139,6 +145,22 @@ namespace BlaxCastes
public List followed = new List();
/// The work types the caste decides where the pawn had the caste's value when it left.
public List followedWork = new List();
+ ///
+ /// 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.
+ ///
+ public List managed;
+ ///
+ /// 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".
+ ///
+ public List 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;
public FormerCaste()
{
@@ -157,30 +179,74 @@ namespace BlaxCastes
public bool FollowedWork(string defName) => followedWork != null && followedWork.Contains(defName);
+ /// The caste managed this slot when the pawn left (always true for a record saved before that was kept).
+ public bool WasManaged(CasteSlot slot) => managed == null || managed.Contains(slot);
+
+ /// The caste listed this work type when the pawn left (always true for a record saved before that was kept).
+ public bool WasListed(string defName) => listedWork == null || listedWork.Contains(defName);
+
public void ExposeData()
{
+ 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;
+ }
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");
- Scribe_Values.Look(ref apparelId, "apparelId", Caste.Unmanaged);
- Scribe_Values.Look(ref foodId, "foodId", Caste.Unmanaged);
- Scribe_Values.Look(ref drugId, "drugId", Caste.Unmanaged);
- Scribe_Values.Look(ref readingId, "readingId", Caste.Unmanaged);
+ 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);
+ }
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);
+ Scribe_Collections.Look(ref managed, "managed", LookMode.Value);
+ Scribe_Collections.Look(ref listedWork, "listedWork", LookMode.Value);
if (Scribe.mode == LoadSaveMode.PostLoadInit)
{
followed ??= new List();
followedWork ??= new List();
+ // managed and listedWork stay null in an older record: see WasManaged and WasListed.
+ ResolveLegacyIds();
}
}
+ /// An older record's policy ids, looked up in the databases once, right after the load.
+ 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;
+ }
+
public override string ToString() =>
"FormerCaste(" + (casteless ? "no caste" : casteId.ToString()) + ", " + side + ", tick " + tick + ")";
}
diff --git a/Source/BlaxCastes/CasteManager.cs b/Source/BlaxCastes/CasteManager.cs
index 8979da4..b5072bb 100644
--- a/Source/BlaxCastes/CasteManager.cs
+++ b/Source/BlaxCastes/CasteManager.cs
@@ -358,9 +358,10 @@ namespace BlaxCastes
///
/// "Assign pawns without a caste by status": puts each pawn of PawnsToAssignByStatus into the caste
- /// of its new colonist, new slave or new prisoner row. Returns how many were assigned.
+ /// of its new colonist, new slave or new prisoner row. Returns how many were assigned; assigned, when
+ /// given, gets each of them.
///
- public static int AssignByStatus()
+ public static int AssignByStatus(ICollection assigned = null)
{
GameComponent_BlaxCastes comp = Comp;
if (comp == null)
@@ -371,7 +372,10 @@ namespace BlaxCastes
string row = JoinDefaults.RowFor(JoinDefaults.StatusFallback, p);
Caste caste = row == null ? null : comp.ResolveRow(row);
if (caste != null && Assign(p, caste, true, row))
+ {
count++;
+ assigned?.Add(p);
+ }
}
return count;
}
@@ -440,7 +444,9 @@ namespace BlaxCastes
///
/// Unmanages the caste's slots whose policy is no longer in its database, and its loadout when Weapons
- /// Tab Reborn is active and no longer has it (without the mod the id is kept). Returns how many.
+ /// Tab Reborn is active and no longer has it (without the mod the id is kept). The loadout is checked
+ /// first and the mod's availability after: a call that fails inside the check turns the slot off, and
+ /// must not count as a deleted loadout. Returns how many.
///
internal static int UnmanageMissingPolicies(Caste caste)
{
@@ -456,7 +462,7 @@ namespace BlaxCastes
(missing ??= new List()).Add(slot + " (" + policy.label + ")");
caste.SetSlotRaw(slot, null);
}
- if (caste.IsManaged(CasteSlot.Loadout) && WeaponsTab.Available && !WeaponsTab.Exists(caste.LoadoutId))
+ if (caste.IsManaged(CasteSlot.Loadout) && !WeaponsTab.Exists(caste.LoadoutId) && WeaponsTab.Available)
{
(missing ??= new List()).Add("weapon loadout (id " + caste.LoadoutId + ")");
caste.SetSlotRaw(CasteSlot.Loadout, Caste.Unmanaged);
diff --git a/Source/BlaxCastes/CasteUtility.cs b/Source/BlaxCastes/CasteUtility.cs
index 85f84a1..7e6c8f7 100644
--- a/Source/BlaxCastes/CasteUtility.cs
+++ b/Source/BlaxCastes/CasteUtility.cs
@@ -234,24 +234,26 @@ namespace BlaxCastes
// ---- former-caste records ----------------------------------------------------------------
///
- /// Fills a former-caste record with the pawn's own settings (the slots it can take now; policies by
- /// id) and with the slots and work types of its caste where it has the caste's value. caste is null
- /// for a pawn that is casteless by choice.
+ /// Fills a former-caste record with the pawn's own settings (the slots it can take now), with the
+ /// slots and work types of its caste where it has the caste's value, and with the slots the caste
+ /// manages and the work types it lists now. caste is null for a pawn that is casteless by choice.
///
internal static void Snapshot(Pawn pawn, Caste caste, FormerCaste record)
{
if (pawn == null || record == null)
return;
+ record.managed = caste == null ? new List() : AllSlots.Where(caste.IsManaged).ToList();
+ record.listedWork = caste == null ? new List() : caste.WorkPriorities.Keys.ToList();
foreach (CasteSlot slot in AllSlots)
{
if (!CanUse(pawn, slot))
continue;
switch (slot)
{
- case CasteSlot.Apparel: record.apparelId = pawn.outfits.CurrentApparelPolicy?.id ?? Caste.Unmanaged; break;
- case CasteSlot.Food: record.foodId = pawn.foodRestriction.CurrentFoodPolicy?.id ?? Caste.Unmanaged; break;
- case CasteSlot.Drug: record.drugId = pawn.drugs.CurrentPolicy?.id ?? Caste.Unmanaged; break;
- case CasteSlot.Reading: record.readingId = pawn.reading.CurrentPolicy?.id ?? Caste.Unmanaged; break;
+ case CasteSlot.Apparel: record.apparel = pawn.outfits.CurrentApparelPolicy; break;
+ case CasteSlot.Food: record.food = pawn.foodRestriction.CurrentFoodPolicy; break;
+ case CasteSlot.Drug: record.drug = pawn.drugs.CurrentPolicy; break;
+ case CasteSlot.Reading: record.reading = pawn.reading.CurrentPolicy; break;
case CasteSlot.MedCare: record.medCare = (int)pawn.playerSettings.medCare; break;
case CasteSlot.Schedule: record.schedule = ScheduleSlot.Of(pawn)?.ToList(); break;
case CasteSlot.Work: record.work = WorkSlot.Of(pawn); break;
@@ -273,16 +275,19 @@ namespace BlaxCastes
}
}
- /// The pawn's own value for a slot from a former-caste record, or null where the record has none or its policy is gone.
+ ///
+ /// The pawn's own value for a slot from a former-caste record, or null where the record has none or
+ /// its policy is gone. A policy counts only while that very policy is still in its database, so a
+ /// new policy that got a deleted one's id is never mistaken for it.
+ ///
internal static object OwnValue(FormerCaste record, CasteSlot slot)
{
- Game game = Current.Game;
switch (slot)
{
- case CasteSlot.Apparel: return game?.outfitDatabase?.AllOutfits?.FirstOrDefault(p => p.id == record.apparelId);
- case CasteSlot.Food: return game?.foodRestrictionDatabase?.AllFoodRestrictions?.FirstOrDefault(p => p.id == record.foodId);
- case CasteSlot.Drug: return game?.drugPolicyDatabase?.AllPolicies?.FirstOrDefault(p => p.id == record.drugId);
- case CasteSlot.Reading: return game?.readingPolicyDatabase?.AllReadingPolicies?.FirstOrDefault(p => p.id == record.readingId);
+ case CasteSlot.Apparel: return PolicyExists(record.apparel) ? record.apparel : null;
+ case CasteSlot.Food: return PolicyExists(record.food) ? record.food : null;
+ case CasteSlot.Drug: return PolicyExists(record.drug) ? record.drug : null;
+ case CasteSlot.Reading: return PolicyExists(record.reading) ? record.reading : null;
case CasteSlot.MedCare: return ToMedCare(record.medCare) < 0 ? null : (object)record.medCare;
case CasteSlot.Schedule: return record.schedule != null && record.schedule.Count == ScheduleSlot.Hours ? ScheduleSlot.Normalize(record.schedule) : null;
case CasteSlot.Loadout: return record.loadoutId >= 0 ? (object)record.loadoutId : null;
@@ -294,9 +299,10 @@ namespace BlaxCastes
/// Gives a returning pawn its own settings back (JoinDefaults.Restore). previous is the caste it
/// returns to (null for No caste), away the caste it got while it was gone (null when none, or the
/// same caste). A slot previous manages gets the caste's current value if the pawn followed it when
- /// it left, else the pawn's own value from then. A slot only away manages, where the pawn still has
- /// away's value, gets the pawn's own value from then. Everything else stays. Does nothing while the
- /// "enabled" setting is off.
+ /// it left or the caste did not manage it then (the Follow rule: a slot that becomes managed reaches
+ /// every member), else the pawn's own value from then. A slot only away manages, where the pawn
+ /// still has away's value, gets the pawn's own value from then. Everything else stays. Does nothing
+ /// while the "enabled" setting is off.
///
internal static void Restore(Pawn pawn, Caste previous, Caste away, FormerCaste record)
{
@@ -315,7 +321,7 @@ namespace BlaxCastes
object own = OwnValue(record, slot);
object target;
if (previous != null && previous.IsManaged(slot))
- target = record.Followed(slot) || own == null ? previous.GetSlot(slot) : own;
+ target = record.Followed(slot) || !record.WasManaged(slot) || own == null ? previous.GetSlot(slot) : own;
else if (away != null && away.IsManaged(slot) && Matches(pawn, slot, away.GetSlot(slot)))
target = own;
else
@@ -339,7 +345,12 @@ namespace BlaxCastes
CasteManager.UnmanageMissingPolicies(previous);
}
- /// Restore for work priorities, type by type over the types previous or away decide (WorkSlot.Decided).
+ ///
+ /// Restore for work priorities, type by type over the types previous or away decide (WorkSlot.Decided).
+ /// A type previous lists now but did not list when the pawn left gets the caste's value, as the
+ /// Follow rule gives a newly listed type to every member; a type only "Start from nothing" decides
+ /// moves nobody when it is ticked, so it keeps the pawn's own value unless the pawn followed it.
+ ///
private static void RestoreWork(Pawn pawn, Caste previous, Caste away, FormerCaste record)
{
Dictionary mine = WorkSlot.Decided(previous);
@@ -355,7 +366,8 @@ namespace BlaxCastes
bool casteValue = false;
if (mine != null && mine.TryGetValue(name, out int value))
{
- casteValue = record.FollowedWork(name) || !hasOwn;
+ bool listedSince = previous.WorkPriorities.ContainsKey(name) && !record.WasListed(name);
+ casteValue = record.FollowedWork(name) || listedSince || !hasOwn;
target = casteValue ? value : own;
}
else if (theirs != null && hasOwn && theirs.TryGetValue(name, out int awayValue) && WorkSlot.Matches(pawn, name, awayValue))
diff --git a/Source/BlaxCastes/Dialog_ManageCastes.cs b/Source/BlaxCastes/Dialog_ManageCastes.cs
index 052bc74..c4e9fc0 100644
--- a/Source/BlaxCastes/Dialog_ManageCastes.cs
+++ b/Source/BlaxCastes/Dialog_ManageCastes.cs
@@ -44,6 +44,8 @@ namespace BlaxCastes
private static readonly List NoCastes = new List();
private static Texture2D[] medCareIcons;
+ /// The left button went down on the schedule grid and is still held (SchedulePaintAllowed).
+ private static bool schedulePaintStarted;
private Vector2 scrollPosition;
private float contentHeight = 600f;
@@ -75,7 +77,7 @@ namespace BlaxCastes
SelectedPolicy = null;
base.DoWindowContents(inRect);
DoMakeDefaultTip(inRect);
- DoAssignByStatusButton(inRect);
+ DoAssignByStatusButton(inRect, workCycle);
}
///
@@ -101,7 +103,7 @@ namespace BlaxCastes
/// record whose status row gives them a caste. It replaces those pawns' own policies with their
/// caste's, which cannot be undone, so it asks first, like "Apply to all members".
///
- private static void DoAssignByStatusButton(Rect inRect)
+ private static void DoAssignByStatusButton(Rect inRect, WorkCycle cycle)
{
if (Comp == null)
return;
@@ -113,13 +115,26 @@ namespace BlaxCastes
{
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(AssignByStatusConfirmText(count), () =>
{
- int assigned = CasteManager.AssignByStatus();
+ int assigned = AssignByStatus(cycle);
Messages.Message("BlaxCastes_AssignByStatusDone".Translate(assigned), MessageTypeDefOf.NeutralEvent, historical: false);
}, destructive: true));
}
TooltipHandler.TipRegion(button, "BlaxCastes_AssignByStatusTip".Translate(count));
}
+ ///
+ /// The confirmed "Assign by status": CasteManager.AssignByStatus, and the pawns it put into the caste
+ /// of the window's work cycle run join that run's followers (WorkCycle.AddJoined). Returns how many
+ /// were assigned.
+ ///
+ public static int AssignByStatus(WorkCycle cycle)
+ {
+ var assigned = new List();
+ int count = CasteManager.AssignByStatus(assigned);
+ cycle?.AddJoined(assigned);
+ return count;
+ }
+
/// The confirm text for "Assign by status", naming the pawn count.
public static string AssignByStatusConfirmText(int count) =>
"BlaxCastes_AssignByStatusConfirm".Translate(count.Named("COUNT"));
@@ -432,9 +447,12 @@ namespace BlaxCastes
y += HourLabelHeight;
IReadOnlyList names = caste.Schedule ?? ScheduleSlot.Default();
- bool mouseDown = Input.GetMouseButton(0);
TimeAssignmentDef brush = TimeAssignmentSelector.selectedAssignment;
var grid = new Rect(ValueX, y, cellWidth * ScheduleSlot.Hours, HourCellHeight);
+ Event current = Event.current;
+ // The grid ends where the scrollbar starts: only a press that started on the grid paints.
+ bool held = Input.GetMouseButton(0);
+ bool paint = SchedulePaintAllowed(ref schedulePaintStarted, current.type, current.button, Mouse.IsOver(grid), held);
for (int hour = 0; hour < ScheduleSlot.Hours; hour++)
{
Rect cell = new Rect(ValueX + hour * cellWidth, y, cellWidth, HourCellHeight).ContractedBy(1f);
@@ -442,12 +460,12 @@ namespace BlaxCastes
GUI.color = managed ? Color.white : new Color(1f, 1f, 1f, 0.35f);
GUI.DrawTexture(cell, def.ColorTexture);
GUI.color = Color.white;
- if (!mouseDown)
+ if (!held)
MouseoverSounds.DoRegion(cell);
if (!Mouse.IsOver(cell))
continue;
Widgets.DrawBox(cell, 2);
- if (mouseDown && brush != null && (def != brush || !managed))
+ if (paint && brush != null && (def != brush || !managed))
{
PaintHour(caste, hour, brush);
SoundDefOf.Designate_DragStandard_Changed_NoCam.PlayOneShotOnCamera();
@@ -467,6 +485,22 @@ namespace BlaxCastes
return y + SmallButtonHeight;
}
+ ///
+ /// Whether the schedule grid paints during this GUI event. Vanilla's Schedule tab paints whenever the
+ /// left button is held over a cell; here the grid ends where the scroll view's scrollbar starts, so a
+ /// drag of the scrollbar that drifts over the grid would paint (and give every member a day the caste
+ /// left alone). So painting needs a press that started on the grid: started is set by a left press,
+ /// to whether it was over the grid, and cleared when the button is up.
+ ///
+ public static bool SchedulePaintAllowed(ref bool started, EventType type, int button, bool overGrid, bool buttonHeld)
+ {
+ if (type == EventType.MouseDown && button == 0)
+ started = overGrid;
+ else if (!buttonHeld || (type == EventType.MouseUp && button == 0))
+ started = false;
+ return started;
+ }
+
///
/// The width of one schedule brush: the row's width shared by the brushes (four, five with Royalty),
/// between 64 and 96 px. The vanilla Schedule tab gives each about 92 px; 64 is too narrow for
@@ -609,6 +643,9 @@ namespace BlaxCastes
/// only them. Stepping 3, 4, off, leave alone, 1 to reach 1 therefore never picks up a pawn set to 4
/// or off by hand on the way. A click on another type or caste, a change to the type from anywhere
/// else, "Apply to all members" or closing the window starts a new run. Each window has its own.
+ /// Pawns "Assign by status" puts into the run's caste get the caste's current value, so they join
+ /// the run's followers (AddJoined) instead of ending the run, which would let the next click pick up
+ /// a member set by hand to that value.
///
public sealed class WorkCycle
{
@@ -641,6 +678,27 @@ namespace BlaxCastes
defName = null;
followers = null;
}
+
+ ///
+ /// Pawns that just joined a caste (Assign by status). Those in the run's caste that follow its type
+ /// now, as a fresh assign leaves them, are added to the run's followers. Returns how many were added.
+ ///
+ public int AddJoined(IEnumerable joined)
+ {
+ if (followers == null || caste == null || joined == null)
+ return 0;
+ List following = CasteManager.WorkFollowers(caste, defName);
+ int added = 0;
+ foreach (Pawn pawn in joined)
+ {
+ if (pawn != null && following.Contains(pawn) && !followers.Contains(pawn))
+ {
+ followers.Add(pawn);
+ added++;
+ }
+ }
+ return added;
+ }
}
// ---- helpers the rows use; public so the tests can drive them --------------------------
@@ -711,11 +769,12 @@ namespace BlaxCastes
///
/// Posts the message that points to Assign > Manage castes. The game component calls this once
/// per save and stores the result. Returns false (try again on the next load) while the Caste
- /// column is turned off, because the message would point to a button that is not there.
+ /// column is not in the Assign tab, because the message would point to a button that is not there.
+ /// That is the setting the game started with (CasteColumns.Shown), not a change waiting for a restart.
///
public static bool ShowFirstLoadMessage()
{
- if (BlaxCastesMod.Settings != null && !BlaxCastesMod.Settings.showAssignColumn)
+ if (!CasteColumns.Shown)
return false;
string text = "BlaxCastes_FirstLoadMessage".Translate();
LongEventHandler.ExecuteWhenFinished(() => Messages.Message(text, MessageTypeDefOf.NeutralEvent));
diff --git a/Source/BlaxCastes/JoinDefaults.cs b/Source/BlaxCastes/JoinDefaults.cs
index 5c27acc..e09d9a7 100644
--- a/Source/BlaxCastes/JoinDefaults.cs
+++ b/Source/BlaxCastes/JoinDefaults.cs
@@ -291,6 +291,22 @@ namespace BlaxCastes
Comp?.LeftPawns.Add(pawn);
}
+ ///
+ /// A pawn walked off the map for good while the game still counts it as player-side (JoinHooks.AfterLeaving):
+ /// it leaves its caste now, with a former-caste record if it was a colonist or slave, and a join waiting
+ /// for it is dropped. Nothing else would end the membership, since the pawn stays player-side.
+ ///
+ internal static void NoteGone(Pawn pawn, JoinSide side, FormerCaste captured)
+ {
+ GameComponent_BlaxCastes comp = Comp;
+ if (comp == null || pawn == null)
+ return;
+ NoteFormer(pawn, side, captured);
+ comp.JoinQueue.RemoveAll(q => q != null && q.pawn == pawn);
+ comp.LeftPawns.Remove(pawn);
+ CasteManager.EndMembership(pawn);
+ }
+
///
/// Applies the joins queued on an earlier tick and ends the memberships of pawns that left.
/// Called by GameComponent_BlaxCastes every tick.
diff --git a/Source/BlaxCastes/JoinHooks.cs b/Source/BlaxCastes/JoinHooks.cs
index 58f8d97..fcbdafb 100644
--- a/Source/BlaxCastes/JoinHooks.cs
+++ b/Source/BlaxCastes/JoinHooks.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using HarmonyLib;
using RimWorld;
+using RimWorld.Planet;
using Verse;
namespace BlaxCastes
@@ -42,9 +44,10 @@ namespace BlaxCastes
/// noted, and the membership ends on the next tick if the pawn is still gone by then. A colonist or
/// slave that leaves the player side or becomes a prisoner leaves a former-caste record, taken in the
/// prefix, so it holds the pawn's settings from before the game changed any of them. Inside a
- /// sale nothing is queued; the sale writes the record itself. Nothing is applied here: SetFaction
- /// and SetGuestStatus reset medical care, areas, work and slave mode right after, so joins wait for
- /// the next tick.
+ /// sale nothing is queued; the sale writes the record itself. Leaving the map (Pawn.ExitMap, a closing
+ /// map) is judged as a whole, from the status before it to the status after it (AfterLeaving).
+ /// Nothing is applied here: SetFaction and SetGuestStatus reset medical care, areas, work and slave
+ /// mode right after, so joins wait for the next tick.
///
internal static class JoinHooks
{
@@ -116,6 +119,8 @@ namespace BlaxCastes
if (was == now)
return;
string scope = JoinScopes.ReasonFor(pawn);
+ if (scope == JoinScopes.Leaving)
+ return; // AfterLeaving judges the whole departure once it is over
if (scope == JoinScopes.Sold)
{
if (now == JoinSide.None)
@@ -135,6 +140,109 @@ namespace BlaxCastes
}
}
+ // ---- leaving the map ---------------------------------------------------------------------
+
+ ///
+ /// Before a pawn leaves the map (Pawn.ExitMap) or is passed to the world by a closing map: the
+ /// snapshot, and a Leaving scope, so the status changes inside the departure wait for AfterLeaving.
+ /// Only for pawns that are player-side or have a membership record; the rest change nothing here.
+ ///
+ public static LeaveState BeforeLeaving(Pawn pawn)
+ {
+ var state = new LeaveState { pawn = pawn };
+ JoinSnapshot before = Before(pawn);
+ if (!before.valid)
+ return state;
+ try
+ {
+ if (before.Side == JoinSide.None && GameComponent_BlaxCastes.Instance?.MembershipOf(pawn) == null)
+ return state;
+ state.before = before;
+ state.travelling = pawn.teleporting || InTransporter(pawn);
+ state.token = JoinScopes.Push(JoinScopes.Leaving, pawn);
+ }
+ catch (Exception e)
+ {
+ LogOnce("Leaving snapshot", e);
+ }
+ return state;
+ }
+
+ ///
+ /// After the departure: the status before it is compared with the status now, the way After compares
+ /// one status change. A pawn the game moved out of the faction (a freed slave from another faction
+ /// that walked off, an escaped slave, a colonist left behind on a closing map) therefore leaves its
+ /// caste with the status it had before it left, never as a colonist who joined. Leaving in a caravan,
+ /// a transport pod or a shuttle, or being kidnapped, changes nothing: the game keeps those pawns in the
+ /// faction, so they keep their caste. A pawn that walked off for good while the game still counts it
+ /// as player-side (an escaped prisoner keeps its prisoner status in the world; a freed slave a quest
+ /// holds stays in the faction) leaves its caste at once, since nothing would end the membership later.
+ ///
+ public static void AfterLeaving(LeaveState state)
+ {
+ JoinScopes.Pop(state.token);
+ if (!state.before.valid)
+ return;
+ Pawn pawn = state.pawn;
+ try
+ {
+ JoinSide was = state.before.Side;
+ JoinSide now = JoinDefaults.SideOf(pawn);
+ if (now != JoinSide.None && LeftForGood(pawn, state) && (now != was || pawn.Faction != Faction.OfPlayer))
+ JoinDefaults.NoteGone(pawn, was, state.before.former);
+ else
+ After(pawn, state.before);
+ }
+ catch (Exception e)
+ {
+ LogOnce("Leaving check", e);
+ }
+ }
+
+ /// A closing map: BeforeLeaving for each of its pawns that matters. Null when none does.
+ public static List BeforeMapClosed(Map map)
+ {
+ List states = null;
+ try
+ {
+ if (map?.mapPawns == null || Current.Game == null)
+ return null;
+ foreach (Pawn pawn in map.mapPawns.AllPawns.ToList())
+ {
+ LeaveState state = BeforeLeaving(pawn);
+ if (state.before.valid)
+ (states ??= new List()).Add(state);
+ }
+ }
+ catch (Exception e)
+ {
+ LogOnce("Closing map snapshot", e);
+ }
+ return states;
+ }
+
+ /// After a closing map passed its pawns to the world: every scope closes first, then each pawn is judged.
+ public static void AfterMapClosed(List states)
+ {
+ if (states == null || states.Count == 0)
+ return;
+ JoinScopes.Pop(states[0].token);
+ foreach (LeaveState state in states)
+ AfterLeaving(state);
+ }
+
+ /// Inside a transport pod or a shuttle, on the map or travelling.
+ private static bool InTransporter(Pawn pawn) =>
+ ThingOwnerUtility.AnyParentIs(pawn) || ThingOwnerUtility.AnyParentIs(pawn);
+
+ ///
+ /// The pawn is off every map and does not travel on: a living world pawn outside caravans, transport
+ /// pods and shuttles, not teleporting and not kidnapped.
+ ///
+ private static bool LeftForGood(Pawn pawn, LeaveState state) =>
+ !state.travelling && !pawn.Spawned && !pawn.Dead && pawn.IsWorldPawn() && !pawn.IsCaravanMember()
+ && !InTransporter(pawn) && !pawn.IsKidnapped();
+
/// A sale finished: a colonist or slave that left the player side leaves the former-caste record taken before the sale.
public static void AfterSale(Pawn pawn, JoinSide before, FormerCaste former)
{
@@ -150,6 +258,18 @@ namespace BlaxCastes
}
}
+ /// What the leaving prefixes hand their finalizers (JoinHooks.BeforeLeaving).
+ internal struct LeaveState
+ {
+ public Pawn pawn;
+ /// The Leaving scope's token, 0 when none was opened.
+ public int token;
+ /// Invalid when the departure does not matter to Castes.
+ public JoinSnapshot before;
+ /// The pawn travels on: it was teleporting, or inside a transport pod or shuttle, when it left.
+ public bool travelling;
+ }
+
/// What the PreTraded prefix hands its finalizer.
internal struct TradeState
{
@@ -175,6 +295,39 @@ namespace BlaxCastes
public static void Postfix(Pawn ___pawn, JoinSnapshot __state) => JoinHooks.After(___pawn, __state);
}
+ ///
+ /// A pawn leaves the map. A freed slave from another faction is set free at the map edge (inside this
+ /// call) and then moved out of the faction when the game passes it to the world, so the departure is
+ /// judged as a whole (JoinHooks.AfterLeaving). The finalizer runs even when ExitMap throws.
+ ///
+ [HarmonyPatch(typeof(Pawn), nameof(Pawn.ExitMap))]
+ internal static class Patch_Pawn_ExitMap
+ {
+ public static void Prefix(Pawn __instance, out LeaveState __state) => __state = JoinHooks.BeforeLeaving(__instance);
+
+ public static Exception Finalizer(Exception __exception, LeaveState __state)
+ {
+ JoinHooks.AfterLeaving(__state);
+ return __exception;
+ }
+ }
+
+ ///
+ /// A map closes (an abandoned settlement, a caravan site left behind) and passes the pawns still on it to
+ /// the world: a slave there is set free, then moved out of the faction. Judged per pawn like ExitMap.
+ ///
+ [HarmonyPatch(typeof(MapDeiniter), "PassPawnsToWorld")]
+ internal static class Patch_MapDeiniter_PassPawnsToWorld
+ {
+ public static void Prefix(Map map, out List __state) => __state = JoinHooks.BeforeMapClosed(map);
+
+ public static Exception Finalizer(Exception __exception, List __state)
+ {
+ JoinHooks.AfterMapClosed(__state);
+ return __exception;
+ }
+ }
+
///
/// Buying: the pawn's status changes inside Pawn.PreTraded, so a "bought" scope covers it. Blax Slaves
/// and Trade as Slave or Colonist only set guest.joinStatus before this call, so the final status
diff --git a/Source/BlaxCastes/JoinScopes.cs b/Source/BlaxCastes/JoinScopes.cs
index 968ed0a..d615e38 100644
--- a/Source/BlaxCastes/JoinScopes.cs
+++ b/Source/BlaxCastes/JoinScopes.cs
@@ -21,6 +21,14 @@ namespace BlaxCastes
///
public const string Sold = "sold";
+ ///
+ /// Pawn.ExitMap, or a closing map passing its pawns to the world. Status changes inside it queue and
+ /// note nothing (a freed slave from another faction is set free at the map edge, the moment before
+ /// the game moves it out of the faction); the hook compares the status before and after the whole
+ /// departure instead (JoinHooks.AfterLeaving).
+ ///
+ public const string Leaving = "leaving";
+
private struct Scope
{
public string reason;
diff --git a/Source/BlaxCastes/StarterCastes.cs b/Source/BlaxCastes/StarterCastes.cs
index 934ae38..5aae340 100644
--- a/Source/BlaxCastes/StarterCastes.cs
+++ b/Source/BlaxCastes/StarterCastes.cs
@@ -162,14 +162,14 @@ namespace BlaxCastes
}
///
- /// The seeding message. It points to Assign > Manage castes, or, while the Caste column is turned off
- /// (so that button is not there), to the mod settings, which open the same window.
+ /// The seeding message. It points to Assign > Manage castes, or, while the Caste column is not in the
+ /// Assign tab (so that button is not there), to the mod settings, which open the same window. The
+ /// column is there as the game started (CasteColumns.Shown), whatever the setting says until a restart.
///
public static string SeededMessageText(GameComponent_BlaxCastes comp)
{
string names = comp.Castes.Select(c => c.label).ToCommaList(useAnd: true);
- bool column = BlaxCastesMod.Settings == null || BlaxCastesMod.Settings.showAssignColumn;
- string key = column ? "BlaxCastes_StarterSeededMessage" : "BlaxCastes_StarterSeededMessageNoColumn";
+ string key = CasteColumns.Shown ? "BlaxCastes_StarterSeededMessage" : "BlaxCastes_StarterSeededMessageNoColumn";
return key.Translate(names.Named("CASTES"));
}
}
diff --git a/Source/BlaxCastes/WeaponsTab.cs b/Source/BlaxCastes/WeaponsTab.cs
index a637a86..f0b9235 100644
--- a/Source/BlaxCastes/WeaponsTab.cs
+++ b/Source/BlaxCastes/WeaponsTab.cs
@@ -22,6 +22,10 @@ namespace BlaxCastes
/// Loadout ids are the highest id plus one, so an id freed by deleting the newest loadout can come back.
/// A missing type or method turns the slot off for the session; a call that throws anything else turns
/// it off for the rest of the game. Either logs one warning and never throws.
+ /// The loadout database is null after loading a save that has none (the mod added mid-save, or saved
+ /// without it), until the mod's own tab or job giver creates it through GetCurrentLoadoutDatabase(). The
+ /// BPC methods read the field directly and would throw, so every call goes through that public method
+ /// first, which creates the database the same way the mod does.
///
public static class WeaponsTab
{
@@ -40,6 +44,8 @@ namespace BlaxCastes
private static Func getDefaultLoadoutId;
private static Func getLoadoutName;
private static Func> getDatabase;
+ /// LoadoutDictionary.GetCurrentLoadoutDatabase(): returns the database, creating it if it is null. Optional.
+ private static Func