fix: pawns that leave for good, returns after caste edits, deleted policies, Assign by status during a work cycle
Freed foreign slaves, escaped pawns and pawns left on closing maps leave their caste; caravans, pods, shuttles and kidnapped pawns keep it. Former records keep which slots were managed and the pawn's own policies by reference. Weapons Tab Reborn's database is created on demand. Schedule painting needs a press on the grid. Column tooltip and first-load message fixes.
This commit is contained in:
parent
a0c809a7dd
commit
dd3490490d
Binary file not shown.
Binary file not shown.
|
|
@ -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.
|
- 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.
|
- 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.
|
- 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. Without the mod the row is hidden.
|
- 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.
|
- 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.
|
- 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 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.
|
- 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.
|
- 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.
|
- 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.
|
- 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.
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@
|
||||||
<BlaxCastes_SettingWarnOverlaps>Warn about mods that also set join defaults</BlaxCastes_SettingWarnOverlaps>
|
<BlaxCastes_SettingWarnOverlaps>Warn about mods that also set join defaults</BlaxCastes_SettingWarnOverlaps>
|
||||||
<BlaxCastes_SettingWarnOverlapsTip>Names active mods that also set policies when a pawn joins, here and in one message per save.</BlaxCastes_SettingWarnOverlapsTip>
|
<BlaxCastes_SettingWarnOverlapsTip>Names active mods that also set policies when a pawn joins, here and in one message per save.</BlaxCastes_SettingWarnOverlapsTip>
|
||||||
<BlaxCastes_SettingShowAssignColumn>Caste column in the Assign, Schedule and Work tabs (needs a restart)</BlaxCastes_SettingShowAssignColumn>
|
<BlaxCastes_SettingShowAssignColumn>Caste column in the Assign, Schedule and Work tabs (needs a restart)</BlaxCastes_SettingShowAssignColumn>
|
||||||
<BlaxCastes_SettingShowAssignColumnTip>Shows each pawn's caste left of the policy columns, the schedule and the work priorities. Click a cell to assign a caste.</BlaxCastes_SettingShowAssignColumnTip>
|
<BlaxCastes_SettingShowAssignColumnTip>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.</BlaxCastes_SettingShowAssignColumnTip>
|
||||||
<BlaxCastes_SettingNoIdeology>Slaves need the Ideology DLC. Without it, castes still work for colonists and prisoners.</BlaxCastes_SettingNoIdeology>
|
<BlaxCastes_SettingNoIdeology>Slaves need the Ideology DLC. Without it, castes still work for colonists and prisoners.</BlaxCastes_SettingNoIdeology>
|
||||||
<BlaxCastes_SettingsReset>Reset to defaults</BlaxCastes_SettingsReset>
|
<BlaxCastes_SettingsReset>Reset to defaults</BlaxCastes_SettingsReset>
|
||||||
|
|
||||||
|
|
|
||||||
16
README.md
16
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`
|
- 📦 **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.
|
- ✅ **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`
|
- 🛠️ **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`
|
- 🔗 **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`
|
- 🌱 **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`
|
- 📋 **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`
|
- 🚪 **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.
|
- 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 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.
|
- 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.
|
- 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.
|
- ↩️ **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.** 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`
|
- ⚠️ **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`
|
- ⚙️ **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).
|
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`.
|
- `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.
|
- 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.
|
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.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,20 @@ namespace BlaxCastes
|
||||||
|
|
||||||
public static PawnColumnDef Column => DefDatabase<PawnColumnDef>.GetNamedSilentFail(PawnColumnWorker_BlaxCaste.DefName);
|
public static PawnColumnDef Column => DefDatabase<PawnColumnDef>.GetNamedSilentFail(PawnColumnWorker_BlaxCaste.DefName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
public static bool Shown
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
PawnColumnDef column = Column;
|
||||||
|
return column != null && Table?.columns != null && Table.columns.Contains(column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Assign table only. Off: removes the column. On: adds it back right before HostilityResponse
|
/// 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
|
/// (or after the first column if that is gone) unless it is already there. Returns true if the
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using RimWorld;
|
||||||
using Verse;
|
using Verse;
|
||||||
|
|
||||||
namespace BlaxCastes
|
namespace BlaxCastes
|
||||||
|
|
@ -108,11 +110,15 @@ namespace BlaxCastes
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The caste a pawn had when it left the player side, was sold or became a prisoner, or "No caste"
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// (JoinDefaults.Restore): the slots it followed, and the ones the caste did not manage then, get the
|
||||||
/// changed by hand get that value back.
|
/// caste's current value; the ones it had changed by hand get that value back.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FormerCaste : IExposable
|
public class FormerCaste : IExposable
|
||||||
{
|
{
|
||||||
|
|
@ -125,11 +131,11 @@ namespace BlaxCastes
|
||||||
public bool auto;
|
public bool auto;
|
||||||
public int tick;
|
public int tick;
|
||||||
|
|
||||||
// The pawn's own settings just before it left; -1 or null where it had none.
|
// The pawn's own settings just before it left; null or -1 where it had none.
|
||||||
public int apparelId = Caste.Unmanaged;
|
public ApparelPolicy apparel;
|
||||||
public int foodId = Caste.Unmanaged;
|
public FoodPolicy food;
|
||||||
public int drugId = Caste.Unmanaged;
|
public DrugPolicy drug;
|
||||||
public int readingId = Caste.Unmanaged;
|
public ReadingPolicy reading;
|
||||||
public int medCare = Caste.Unmanaged;
|
public int medCare = Caste.Unmanaged;
|
||||||
public int loadoutId = Caste.Unmanaged;
|
public int loadoutId = Caste.Unmanaged;
|
||||||
public List<string> schedule;
|
public List<string> schedule;
|
||||||
|
|
@ -139,6 +145,22 @@ namespace BlaxCastes
|
||||||
public List<CasteSlot> followed = new List<CasteSlot>();
|
public List<CasteSlot> followed = new List<CasteSlot>();
|
||||||
/// <summary>The work types the caste decides where the pawn had the caste's value when it left.</summary>
|
/// <summary>The work types the caste decides where the pawn had the caste's value when it left.</summary>
|
||||||
public List<string> followedWork = new List<string>();
|
public List<string> followedWork = new List<string>();
|
||||||
|
/// <summary>
|
||||||
|
/// The slots the caste managed when the pawn left. Null in a record saved before this was kept:
|
||||||
|
/// read as "every slot", so the pawn keeps its own values, as it did then.
|
||||||
|
/// </summary>
|
||||||
|
public List<CasteSlot> managed;
|
||||||
|
/// <summary>
|
||||||
|
/// The work types the caste listed when the pawn left (not the ones only "Start from nothing"
|
||||||
|
/// decided). Null in a record saved before this was kept: read as "every type".
|
||||||
|
/// </summary>
|
||||||
|
public List<string> listedWork;
|
||||||
|
|
||||||
|
// Records saved before the policies were references hold their ids; looked up once on load.
|
||||||
|
private int legacyApparelId = Caste.Unmanaged;
|
||||||
|
private int legacyFoodId = Caste.Unmanaged;
|
||||||
|
private int legacyDrugId = Caste.Unmanaged;
|
||||||
|
private int legacyReadingId = Caste.Unmanaged;
|
||||||
|
|
||||||
public FormerCaste()
|
public FormerCaste()
|
||||||
{
|
{
|
||||||
|
|
@ -157,30 +179,74 @@ namespace BlaxCastes
|
||||||
|
|
||||||
public bool FollowedWork(string defName) => followedWork != null && followedWork.Contains(defName);
|
public bool FollowedWork(string defName) => followedWork != null && followedWork.Contains(defName);
|
||||||
|
|
||||||
|
/// <summary>The caste managed this slot when the pawn left (always true for a record saved before that was kept).</summary>
|
||||||
|
public bool WasManaged(CasteSlot slot) => managed == null || managed.Contains(slot);
|
||||||
|
|
||||||
|
/// <summary>The caste listed this work type when the pawn left (always true for a record saved before that was kept).</summary>
|
||||||
|
public bool WasListed(string defName) => listedWork == null || listedWork.Contains(defName);
|
||||||
|
|
||||||
public void ExposeData()
|
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 casteId, "casteId", Caste.Unmanaged);
|
||||||
Scribe_Values.Look(ref casteless, "casteless");
|
Scribe_Values.Look(ref casteless, "casteless");
|
||||||
Scribe_Values.Look(ref side, "side", JoinSide.None);
|
Scribe_Values.Look(ref side, "side", JoinSide.None);
|
||||||
Scribe_Values.Look(ref auto, "auto");
|
Scribe_Values.Look(ref auto, "auto");
|
||||||
Scribe_Values.Look(ref tick, "tick");
|
Scribe_Values.Look(ref tick, "tick");
|
||||||
Scribe_Values.Look(ref apparelId, "apparelId", Caste.Unmanaged);
|
Scribe_References.Look(ref apparel, "apparel");
|
||||||
Scribe_Values.Look(ref foodId, "foodId", Caste.Unmanaged);
|
Scribe_References.Look(ref food, "food");
|
||||||
Scribe_Values.Look(ref drugId, "drugId", Caste.Unmanaged);
|
Scribe_References.Look(ref drug, "drug");
|
||||||
Scribe_Values.Look(ref readingId, "readingId", Caste.Unmanaged);
|
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 medCare, "medCare", Caste.Unmanaged);
|
||||||
Scribe_Values.Look(ref loadoutId, "loadoutId", Caste.Unmanaged);
|
Scribe_Values.Look(ref loadoutId, "loadoutId", Caste.Unmanaged);
|
||||||
Scribe_Collections.Look(ref schedule, "schedule", LookMode.Value);
|
Scribe_Collections.Look(ref schedule, "schedule", LookMode.Value);
|
||||||
Scribe_Collections.Look(ref work, "work", LookMode.Value, LookMode.Value);
|
Scribe_Collections.Look(ref work, "work", LookMode.Value, LookMode.Value);
|
||||||
Scribe_Collections.Look(ref followed, "followed", LookMode.Value);
|
Scribe_Collections.Look(ref followed, "followed", LookMode.Value);
|
||||||
Scribe_Collections.Look(ref followedWork, "followedWork", 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)
|
if (Scribe.mode == LoadSaveMode.PostLoadInit)
|
||||||
{
|
{
|
||||||
followed ??= new List<CasteSlot>();
|
followed ??= new List<CasteSlot>();
|
||||||
followedWork ??= new List<string>();
|
followedWork ??= new List<string>();
|
||||||
|
// managed and listedWork stay null in an older record: see WasManaged and WasListed.
|
||||||
|
ResolveLegacyIds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>An older record's policy ids, looked up in the databases once, right after the load.</summary>
|
||||||
|
private void ResolveLegacyIds()
|
||||||
|
{
|
||||||
|
Game game = Current.Game;
|
||||||
|
if (game == null)
|
||||||
|
return;
|
||||||
|
if (apparel == null && legacyApparelId >= 0)
|
||||||
|
apparel = game.outfitDatabase?.AllOutfits?.FirstOrDefault(p => p.id == legacyApparelId);
|
||||||
|
if (food == null && legacyFoodId >= 0)
|
||||||
|
food = game.foodRestrictionDatabase?.AllFoodRestrictions?.FirstOrDefault(p => p.id == legacyFoodId);
|
||||||
|
if (drug == null && legacyDrugId >= 0)
|
||||||
|
drug = game.drugPolicyDatabase?.AllPolicies?.FirstOrDefault(p => p.id == legacyDrugId);
|
||||||
|
if (reading == null && legacyReadingId >= 0)
|
||||||
|
reading = game.readingPolicyDatabase?.AllReadingPolicies?.FirstOrDefault(p => p.id == legacyReadingId);
|
||||||
|
legacyApparelId = legacyFoodId = legacyDrugId = legacyReadingId = Caste.Unmanaged;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString() =>
|
public override string ToString() =>
|
||||||
"FormerCaste(" + (casteless ? "no caste" : casteId.ToString()) + ", " + side + ", tick " + tick + ")";
|
"FormerCaste(" + (casteless ? "no caste" : casteId.ToString()) + ", " + side + ", tick " + tick + ")";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -358,9 +358,10 @@ namespace BlaxCastes
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// "Assign pawns without a caste by status": puts each pawn of PawnsToAssignByStatus into the caste
|
/// "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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static int AssignByStatus()
|
public static int AssignByStatus(ICollection<Pawn> assigned = null)
|
||||||
{
|
{
|
||||||
GameComponent_BlaxCastes comp = Comp;
|
GameComponent_BlaxCastes comp = Comp;
|
||||||
if (comp == null)
|
if (comp == null)
|
||||||
|
|
@ -371,7 +372,10 @@ namespace BlaxCastes
|
||||||
string row = JoinDefaults.RowFor(JoinDefaults.StatusFallback, p);
|
string row = JoinDefaults.RowFor(JoinDefaults.StatusFallback, p);
|
||||||
Caste caste = row == null ? null : comp.ResolveRow(row);
|
Caste caste = row == null ? null : comp.ResolveRow(row);
|
||||||
if (caste != null && Assign(p, caste, true, row))
|
if (caste != null && Assign(p, caste, true, row))
|
||||||
|
{
|
||||||
count++;
|
count++;
|
||||||
|
assigned?.Add(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
@ -440,7 +444,9 @@ namespace BlaxCastes
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unmanages the caste's slots whose policy is no longer in its database, and its loadout when Weapons
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static int UnmanageMissingPolicies(Caste caste)
|
internal static int UnmanageMissingPolicies(Caste caste)
|
||||||
{
|
{
|
||||||
|
|
@ -456,7 +462,7 @@ namespace BlaxCastes
|
||||||
(missing ??= new List<string>()).Add(slot + " (" + policy.label + ")");
|
(missing ??= new List<string>()).Add(slot + " (" + policy.label + ")");
|
||||||
caste.SetSlotRaw(slot, null);
|
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<string>()).Add("weapon loadout (id " + caste.LoadoutId + ")");
|
(missing ??= new List<string>()).Add("weapon loadout (id " + caste.LoadoutId + ")");
|
||||||
caste.SetSlotRaw(CasteSlot.Loadout, Caste.Unmanaged);
|
caste.SetSlotRaw(CasteSlot.Loadout, Caste.Unmanaged);
|
||||||
|
|
|
||||||
|
|
@ -234,24 +234,26 @@ namespace BlaxCastes
|
||||||
// ---- former-caste records ----------------------------------------------------------------
|
// ---- former-caste records ----------------------------------------------------------------
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fills a former-caste record with the pawn's own settings (the slots it can take now; policies by
|
/// Fills a former-caste record with the pawn's own settings (the slots it can take now), with the
|
||||||
/// id) and with the slots and work types of its caste where it has the caste's value. caste is null
|
/// slots and work types of its caste where it has the caste's value, and with the slots the caste
|
||||||
/// for a pawn that is casteless by choice.
|
/// manages and the work types it lists now. caste is null for a pawn that is casteless by choice.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static void Snapshot(Pawn pawn, Caste caste, FormerCaste record)
|
internal static void Snapshot(Pawn pawn, Caste caste, FormerCaste record)
|
||||||
{
|
{
|
||||||
if (pawn == null || record == null)
|
if (pawn == null || record == null)
|
||||||
return;
|
return;
|
||||||
|
record.managed = caste == null ? new List<CasteSlot>() : AllSlots.Where(caste.IsManaged).ToList();
|
||||||
|
record.listedWork = caste == null ? new List<string>() : caste.WorkPriorities.Keys.ToList();
|
||||||
foreach (CasteSlot slot in AllSlots)
|
foreach (CasteSlot slot in AllSlots)
|
||||||
{
|
{
|
||||||
if (!CanUse(pawn, slot))
|
if (!CanUse(pawn, slot))
|
||||||
continue;
|
continue;
|
||||||
switch (slot)
|
switch (slot)
|
||||||
{
|
{
|
||||||
case CasteSlot.Apparel: record.apparelId = pawn.outfits.CurrentApparelPolicy?.id ?? Caste.Unmanaged; break;
|
case CasteSlot.Apparel: record.apparel = pawn.outfits.CurrentApparelPolicy; break;
|
||||||
case CasteSlot.Food: record.foodId = pawn.foodRestriction.CurrentFoodPolicy?.id ?? Caste.Unmanaged; break;
|
case CasteSlot.Food: record.food = pawn.foodRestriction.CurrentFoodPolicy; break;
|
||||||
case CasteSlot.Drug: record.drugId = pawn.drugs.CurrentPolicy?.id ?? Caste.Unmanaged; break;
|
case CasteSlot.Drug: record.drug = pawn.drugs.CurrentPolicy; break;
|
||||||
case CasteSlot.Reading: record.readingId = pawn.reading.CurrentPolicy?.id ?? Caste.Unmanaged; break;
|
case CasteSlot.Reading: record.reading = pawn.reading.CurrentPolicy; break;
|
||||||
case CasteSlot.MedCare: record.medCare = (int)pawn.playerSettings.medCare; break;
|
case CasteSlot.MedCare: record.medCare = (int)pawn.playerSettings.medCare; break;
|
||||||
case CasteSlot.Schedule: record.schedule = ScheduleSlot.Of(pawn)?.ToList(); break;
|
case CasteSlot.Schedule: record.schedule = ScheduleSlot.Of(pawn)?.ToList(); break;
|
||||||
case CasteSlot.Work: record.work = WorkSlot.Of(pawn); break;
|
case CasteSlot.Work: record.work = WorkSlot.Of(pawn); break;
|
||||||
|
|
@ -273,16 +275,19 @@ namespace BlaxCastes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>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.</summary>
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
internal static object OwnValue(FormerCaste record, CasteSlot slot)
|
internal static object OwnValue(FormerCaste record, CasteSlot slot)
|
||||||
{
|
{
|
||||||
Game game = Current.Game;
|
|
||||||
switch (slot)
|
switch (slot)
|
||||||
{
|
{
|
||||||
case CasteSlot.Apparel: return game?.outfitDatabase?.AllOutfits?.FirstOrDefault(p => p.id == record.apparelId);
|
case CasteSlot.Apparel: return PolicyExists(record.apparel) ? record.apparel : null;
|
||||||
case CasteSlot.Food: return game?.foodRestrictionDatabase?.AllFoodRestrictions?.FirstOrDefault(p => p.id == record.foodId);
|
case CasteSlot.Food: return PolicyExists(record.food) ? record.food : null;
|
||||||
case CasteSlot.Drug: return game?.drugPolicyDatabase?.AllPolicies?.FirstOrDefault(p => p.id == record.drugId);
|
case CasteSlot.Drug: return PolicyExists(record.drug) ? record.drug : null;
|
||||||
case CasteSlot.Reading: return game?.readingPolicyDatabase?.AllReadingPolicies?.FirstOrDefault(p => p.id == record.readingId);
|
case CasteSlot.Reading: return PolicyExists(record.reading) ? record.reading : null;
|
||||||
case CasteSlot.MedCare: return ToMedCare(record.medCare) < 0 ? null : (object)record.medCare;
|
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.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;
|
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
|
/// 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
|
/// 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
|
/// 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
|
/// it left or the caste did not manage it then (the Follow rule: a slot that becomes managed reaches
|
||||||
/// away's value, gets the pawn's own value from then. Everything else stays. Does nothing while the
|
/// every member), else the pawn's own value from then. A slot only away manages, where the pawn
|
||||||
/// "enabled" setting is off.
|
/// still has away's value, gets the pawn's own value from then. Everything else stays. Does nothing
|
||||||
|
/// while the "enabled" setting is off.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static void Restore(Pawn pawn, Caste previous, Caste away, FormerCaste record)
|
internal static void Restore(Pawn pawn, Caste previous, Caste away, FormerCaste record)
|
||||||
{
|
{
|
||||||
|
|
@ -315,7 +321,7 @@ namespace BlaxCastes
|
||||||
object own = OwnValue(record, slot);
|
object own = OwnValue(record, slot);
|
||||||
object target;
|
object target;
|
||||||
if (previous != null && previous.IsManaged(slot))
|
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)))
|
else if (away != null && away.IsManaged(slot) && Matches(pawn, slot, away.GetSlot(slot)))
|
||||||
target = own;
|
target = own;
|
||||||
else
|
else
|
||||||
|
|
@ -339,7 +345,12 @@ namespace BlaxCastes
|
||||||
CasteManager.UnmanageMissingPolicies(previous);
|
CasteManager.UnmanageMissingPolicies(previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Restore for work priorities, type by type over the types previous or away decide (WorkSlot.Decided).</summary>
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
private static void RestoreWork(Pawn pawn, Caste previous, Caste away, FormerCaste record)
|
private static void RestoreWork(Pawn pawn, Caste previous, Caste away, FormerCaste record)
|
||||||
{
|
{
|
||||||
Dictionary<string, int> mine = WorkSlot.Decided(previous);
|
Dictionary<string, int> mine = WorkSlot.Decided(previous);
|
||||||
|
|
@ -355,7 +366,8 @@ namespace BlaxCastes
|
||||||
bool casteValue = false;
|
bool casteValue = false;
|
||||||
if (mine != null && mine.TryGetValue(name, out int value))
|
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;
|
target = casteValue ? value : own;
|
||||||
}
|
}
|
||||||
else if (theirs != null && hasOwn && theirs.TryGetValue(name, out int awayValue) && WorkSlot.Matches(pawn, name, awayValue))
|
else if (theirs != null && hasOwn && theirs.TryGetValue(name, out int awayValue) && WorkSlot.Matches(pawn, name, awayValue))
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ namespace BlaxCastes
|
||||||
|
|
||||||
private static readonly List<Caste> NoCastes = new List<Caste>();
|
private static readonly List<Caste> NoCastes = new List<Caste>();
|
||||||
private static Texture2D[] medCareIcons;
|
private static Texture2D[] medCareIcons;
|
||||||
|
/// <summary>The left button went down on the schedule grid and is still held (SchedulePaintAllowed).</summary>
|
||||||
|
private static bool schedulePaintStarted;
|
||||||
|
|
||||||
private Vector2 scrollPosition;
|
private Vector2 scrollPosition;
|
||||||
private float contentHeight = 600f;
|
private float contentHeight = 600f;
|
||||||
|
|
@ -75,7 +77,7 @@ namespace BlaxCastes
|
||||||
SelectedPolicy = null;
|
SelectedPolicy = null;
|
||||||
base.DoWindowContents(inRect);
|
base.DoWindowContents(inRect);
|
||||||
DoMakeDefaultTip(inRect);
|
DoMakeDefaultTip(inRect);
|
||||||
DoAssignByStatusButton(inRect);
|
DoAssignByStatusButton(inRect, workCycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -101,7 +103,7 @@ namespace BlaxCastes
|
||||||
/// record whose status row gives them a caste. It replaces those pawns' own policies with their
|
/// 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".
|
/// caste's, which cannot be undone, so it asks first, like "Apply to all members".
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void DoAssignByStatusButton(Rect inRect)
|
private static void DoAssignByStatusButton(Rect inRect, WorkCycle cycle)
|
||||||
{
|
{
|
||||||
if (Comp == null)
|
if (Comp == null)
|
||||||
return;
|
return;
|
||||||
|
|
@ -113,13 +115,26 @@ namespace BlaxCastes
|
||||||
{
|
{
|
||||||
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(AssignByStatusConfirmText(count), () =>
|
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);
|
Messages.Message("BlaxCastes_AssignByStatusDone".Translate(assigned), MessageTypeDefOf.NeutralEvent, historical: false);
|
||||||
}, destructive: true));
|
}, destructive: true));
|
||||||
}
|
}
|
||||||
TooltipHandler.TipRegion(button, "BlaxCastes_AssignByStatusTip".Translate(count));
|
TooltipHandler.TipRegion(button, "BlaxCastes_AssignByStatusTip".Translate(count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
public static int AssignByStatus(WorkCycle cycle)
|
||||||
|
{
|
||||||
|
var assigned = new List<Pawn>();
|
||||||
|
int count = CasteManager.AssignByStatus(assigned);
|
||||||
|
cycle?.AddJoined(assigned);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>The confirm text for "Assign by status", naming the pawn count.</summary>
|
/// <summary>The confirm text for "Assign by status", naming the pawn count.</summary>
|
||||||
public static string AssignByStatusConfirmText(int count) =>
|
public static string AssignByStatusConfirmText(int count) =>
|
||||||
"BlaxCastes_AssignByStatusConfirm".Translate(count.Named("COUNT"));
|
"BlaxCastes_AssignByStatusConfirm".Translate(count.Named("COUNT"));
|
||||||
|
|
@ -432,9 +447,12 @@ namespace BlaxCastes
|
||||||
y += HourLabelHeight;
|
y += HourLabelHeight;
|
||||||
|
|
||||||
IReadOnlyList<string> names = caste.Schedule ?? ScheduleSlot.Default();
|
IReadOnlyList<string> names = caste.Schedule ?? ScheduleSlot.Default();
|
||||||
bool mouseDown = Input.GetMouseButton(0);
|
|
||||||
TimeAssignmentDef brush = TimeAssignmentSelector.selectedAssignment;
|
TimeAssignmentDef brush = TimeAssignmentSelector.selectedAssignment;
|
||||||
var grid = new Rect(ValueX, y, cellWidth * ScheduleSlot.Hours, HourCellHeight);
|
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++)
|
for (int hour = 0; hour < ScheduleSlot.Hours; hour++)
|
||||||
{
|
{
|
||||||
Rect cell = new Rect(ValueX + hour * cellWidth, y, cellWidth, HourCellHeight).ContractedBy(1f);
|
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.color = managed ? Color.white : new Color(1f, 1f, 1f, 0.35f);
|
||||||
GUI.DrawTexture(cell, def.ColorTexture);
|
GUI.DrawTexture(cell, def.ColorTexture);
|
||||||
GUI.color = Color.white;
|
GUI.color = Color.white;
|
||||||
if (!mouseDown)
|
if (!held)
|
||||||
MouseoverSounds.DoRegion(cell);
|
MouseoverSounds.DoRegion(cell);
|
||||||
if (!Mouse.IsOver(cell))
|
if (!Mouse.IsOver(cell))
|
||||||
continue;
|
continue;
|
||||||
Widgets.DrawBox(cell, 2);
|
Widgets.DrawBox(cell, 2);
|
||||||
if (mouseDown && brush != null && (def != brush || !managed))
|
if (paint && brush != null && (def != brush || !managed))
|
||||||
{
|
{
|
||||||
PaintHour(caste, hour, brush);
|
PaintHour(caste, hour, brush);
|
||||||
SoundDefOf.Designate_DragStandard_Changed_NoCam.PlayOneShotOnCamera();
|
SoundDefOf.Designate_DragStandard_Changed_NoCam.PlayOneShotOnCamera();
|
||||||
|
|
@ -467,6 +485,22 @@ namespace BlaxCastes
|
||||||
return y + SmallButtonHeight;
|
return y + SmallButtonHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The width of one schedule brush: the row's width shared by the brushes (four, five with Royalty),
|
/// 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
|
/// 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
|
/// 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
|
/// 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.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class WorkCycle
|
public sealed class WorkCycle
|
||||||
{
|
{
|
||||||
|
|
@ -641,6 +678,27 @@ namespace BlaxCastes
|
||||||
defName = null;
|
defName = null;
|
||||||
followers = null;
|
followers = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
public int AddJoined(IEnumerable<Pawn> joined)
|
||||||
|
{
|
||||||
|
if (followers == null || caste == null || joined == null)
|
||||||
|
return 0;
|
||||||
|
List<Pawn> 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 --------------------------
|
// ---- helpers the rows use; public so the tests can drive them --------------------------
|
||||||
|
|
@ -711,11 +769,12 @@ namespace BlaxCastes
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Posts the message that points to Assign > Manage castes. The game component calls this once
|
/// 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
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool ShowFirstLoadMessage()
|
public static bool ShowFirstLoadMessage()
|
||||||
{
|
{
|
||||||
if (BlaxCastesMod.Settings != null && !BlaxCastesMod.Settings.showAssignColumn)
|
if (!CasteColumns.Shown)
|
||||||
return false;
|
return false;
|
||||||
string text = "BlaxCastes_FirstLoadMessage".Translate();
|
string text = "BlaxCastes_FirstLoadMessage".Translate();
|
||||||
LongEventHandler.ExecuteWhenFinished(() => Messages.Message(text, MessageTypeDefOf.NeutralEvent));
|
LongEventHandler.ExecuteWhenFinished(() => Messages.Message(text, MessageTypeDefOf.NeutralEvent));
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,22 @@ namespace BlaxCastes
|
||||||
Comp?.LeftPawns.Add(pawn);
|
Comp?.LeftPawns.Add(pawn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Applies the joins queued on an earlier tick and ends the memberships of pawns that left.
|
/// Applies the joins queued on an earlier tick and ends the memberships of pawns that left.
|
||||||
/// Called by GameComponent_BlaxCastes every tick.
|
/// Called by GameComponent_BlaxCastes every tick.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using RimWorld;
|
using RimWorld;
|
||||||
|
using RimWorld.Planet;
|
||||||
using Verse;
|
using Verse;
|
||||||
|
|
||||||
namespace BlaxCastes
|
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
|
/// 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
|
/// 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
|
/// 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
|
/// sale nothing is queued; the sale writes the record itself. Leaving the map (Pawn.ExitMap, a closing
|
||||||
/// and SetGuestStatus reset medical care, areas, work and slave mode right after, so joins wait for
|
/// map) is judged as a whole, from the status before it to the status after it (AfterLeaving).
|
||||||
/// the next tick.
|
/// Nothing is applied here: SetFaction and SetGuestStatus reset medical care, areas, work and slave
|
||||||
|
/// mode right after, so joins wait for the next tick.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class JoinHooks
|
internal static class JoinHooks
|
||||||
{
|
{
|
||||||
|
|
@ -116,6 +119,8 @@ namespace BlaxCastes
|
||||||
if (was == now)
|
if (was == now)
|
||||||
return;
|
return;
|
||||||
string scope = JoinScopes.ReasonFor(pawn);
|
string scope = JoinScopes.ReasonFor(pawn);
|
||||||
|
if (scope == JoinScopes.Leaving)
|
||||||
|
return; // AfterLeaving judges the whole departure once it is over
|
||||||
if (scope == JoinScopes.Sold)
|
if (scope == JoinScopes.Sold)
|
||||||
{
|
{
|
||||||
if (now == JoinSide.None)
|
if (now == JoinSide.None)
|
||||||
|
|
@ -135,6 +140,109 @@ namespace BlaxCastes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- leaving the map ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>A closing map: BeforeLeaving for each of its pawns that matters. Null when none does.</summary>
|
||||||
|
public static List<LeaveState> BeforeMapClosed(Map map)
|
||||||
|
{
|
||||||
|
List<LeaveState> 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<LeaveState>()).Add(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogOnce("Closing map snapshot", e);
|
||||||
|
}
|
||||||
|
return states;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>After a closing map passed its pawns to the world: every scope closes first, then each pawn is judged.</summary>
|
||||||
|
public static void AfterMapClosed(List<LeaveState> states)
|
||||||
|
{
|
||||||
|
if (states == null || states.Count == 0)
|
||||||
|
return;
|
||||||
|
JoinScopes.Pop(states[0].token);
|
||||||
|
foreach (LeaveState state in states)
|
||||||
|
AfterLeaving(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Inside a transport pod or a shuttle, on the map or travelling.</summary>
|
||||||
|
private static bool InTransporter(Pawn pawn) =>
|
||||||
|
ThingOwnerUtility.AnyParentIs<ActiveTransporterInfo>(pawn) || ThingOwnerUtility.AnyParentIs<TravellingTransporters>(pawn);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
private static bool LeftForGood(Pawn pawn, LeaveState state) =>
|
||||||
|
!state.travelling && !pawn.Spawned && !pawn.Dead && pawn.IsWorldPawn() && !pawn.IsCaravanMember()
|
||||||
|
&& !InTransporter(pawn) && !pawn.IsKidnapped();
|
||||||
|
|
||||||
/// <summary>A sale finished: a colonist or slave that left the player side leaves the former-caste record taken before the sale.</summary>
|
/// <summary>A sale finished: a colonist or slave that left the player side leaves the former-caste record taken before the sale.</summary>
|
||||||
public static void AfterSale(Pawn pawn, JoinSide before, FormerCaste former)
|
public static void AfterSale(Pawn pawn, JoinSide before, FormerCaste former)
|
||||||
{
|
{
|
||||||
|
|
@ -150,6 +258,18 @@ namespace BlaxCastes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>What the leaving prefixes hand their finalizers (JoinHooks.BeforeLeaving).</summary>
|
||||||
|
internal struct LeaveState
|
||||||
|
{
|
||||||
|
public Pawn pawn;
|
||||||
|
/// <summary>The Leaving scope's token, 0 when none was opened.</summary>
|
||||||
|
public int token;
|
||||||
|
/// <summary>Invalid when the departure does not matter to Castes.</summary>
|
||||||
|
public JoinSnapshot before;
|
||||||
|
/// <summary>The pawn travels on: it was teleporting, or inside a transport pod or shuttle, when it left.</summary>
|
||||||
|
public bool travelling;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>What the PreTraded prefix hands its finalizer.</summary>
|
/// <summary>What the PreTraded prefix hands its finalizer.</summary>
|
||||||
internal struct TradeState
|
internal struct TradeState
|
||||||
{
|
{
|
||||||
|
|
@ -175,6 +295,39 @@ namespace BlaxCastes
|
||||||
public static void Postfix(Pawn ___pawn, JoinSnapshot __state) => JoinHooks.After(___pawn, __state);
|
public static void Postfix(Pawn ___pawn, JoinSnapshot __state) => JoinHooks.After(___pawn, __state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
[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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(MapDeiniter), "PassPawnsToWorld")]
|
||||||
|
internal static class Patch_MapDeiniter_PassPawnsToWorld
|
||||||
|
{
|
||||||
|
public static void Prefix(Map map, out List<LeaveState> __state) => __state = JoinHooks.BeforeMapClosed(map);
|
||||||
|
|
||||||
|
public static Exception Finalizer(Exception __exception, List<LeaveState> __state)
|
||||||
|
{
|
||||||
|
JoinHooks.AfterMapClosed(__state);
|
||||||
|
return __exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Buying: the pawn's status changes inside Pawn.PreTraded, so a "bought" scope covers it. Blax Slaves
|
/// 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
|
/// and Trade as Slave or Colonist only set guest.joinStatus before this call, so the final status
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,14 @@ namespace BlaxCastes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string Sold = "sold";
|
public const string Sold = "sold";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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).
|
||||||
|
/// </summary>
|
||||||
|
public const string Leaving = "leaving";
|
||||||
|
|
||||||
private struct Scope
|
private struct Scope
|
||||||
{
|
{
|
||||||
public string reason;
|
public string reason;
|
||||||
|
|
|
||||||
|
|
@ -162,14 +162,14 @@ namespace BlaxCastes
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The seeding message. It points to Assign > Manage castes, or, while the Caste column is turned off
|
/// The seeding message. It points to Assign > Manage castes, or, while the Caste column is not in the
|
||||||
/// (so that button is not there), to the mod settings, which open the same window.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string SeededMessageText(GameComponent_BlaxCastes comp)
|
public static string SeededMessageText(GameComponent_BlaxCastes comp)
|
||||||
{
|
{
|
||||||
string names = comp.Castes.Select(c => c.label).ToCommaList(useAnd: true);
|
string names = comp.Castes.Select(c => c.label).ToCommaList(useAnd: true);
|
||||||
bool column = BlaxCastesMod.Settings == null || BlaxCastesMod.Settings.showAssignColumn;
|
string key = CasteColumns.Shown ? "BlaxCastes_StarterSeededMessage" : "BlaxCastes_StarterSeededMessageNoColumn";
|
||||||
string key = column ? "BlaxCastes_StarterSeededMessage" : "BlaxCastes_StarterSeededMessageNoColumn";
|
|
||||||
return key.Translate(names.Named("CASTES"));
|
return key.Translate(names.Named("CASTES"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.
|
/// 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
|
/// 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.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class WeaponsTab
|
public static class WeaponsTab
|
||||||
{
|
{
|
||||||
|
|
@ -40,6 +44,8 @@ namespace BlaxCastes
|
||||||
private static Func<int> getDefaultLoadoutId;
|
private static Func<int> getDefaultLoadoutId;
|
||||||
private static Func<int, string> getLoadoutName;
|
private static Func<int, string> getLoadoutName;
|
||||||
private static Func<Dictionary<string, int>> getDatabase;
|
private static Func<Dictionary<string, int>> getDatabase;
|
||||||
|
/// <summary>LoadoutDictionary.GetCurrentLoadoutDatabase(): returns the database, creating it if it is null. Optional.</summary>
|
||||||
|
private static Func<object> ensureDatabase;
|
||||||
|
|
||||||
/// <summary>Weapons Tab Reborn is in the active mod list. The manager hides the loadout row without it.</summary>
|
/// <summary>Weapons Tab Reborn is in the active mod list. The manager hides the loadout row without it.</summary>
|
||||||
public static bool ModActive => modActive ??= Compat.IsActive(Compat.WeaponsTab);
|
public static bool ModActive => modActive ??= Compat.IsActive(Compat.WeaponsTab);
|
||||||
|
|
@ -72,6 +78,9 @@ namespace BlaxCastes
|
||||||
getDefaultLoadoutId = Make<Func<int>>(api, "BPC_GetDefaultLoadoutId", typeof(int));
|
getDefaultLoadoutId = Make<Func<int>>(api, "BPC_GetDefaultLoadoutId", typeof(int));
|
||||||
getLoadoutName = Make<Func<int, string>>(api, "BPC_GetLoadoutNamebyId", typeof(string), typeof(int));
|
getLoadoutName = Make<Func<int, string>>(api, "BPC_GetLoadoutNamebyId", typeof(string), typeof(int));
|
||||||
getDatabase = Make<Func<Dictionary<string, int>>>(api, "BPC_GetWeaponsLoadoutsDatabase", typeof(Dictionary<string, int>));
|
getDatabase = Make<Func<Dictionary<string, int>>>(api, "BPC_GetWeaponsLoadoutsDatabase", typeof(Dictionary<string, int>));
|
||||||
|
MethodInfo ensure = api.GetMethod("GetCurrentLoadoutDatabase", BindingFlags.Public | BindingFlags.Static, null, Type.EmptyTypes, null);
|
||||||
|
if (ensure != null && !ensure.ReturnType.IsValueType && ensure.ReturnType != typeof(void))
|
||||||
|
ensureDatabase = (Func<object>)Delegate.CreateDelegate(typeof(Func<object>), ensure, throwOnBindFailure: false);
|
||||||
var missing = new List<string>();
|
var missing = new List<string>();
|
||||||
if (getLoadoutId == null) missing.Add("BPC_GetLoadoutId");
|
if (getLoadoutId == null) missing.Add("BPC_GetLoadoutId");
|
||||||
if (setLoadoutId == null) missing.Add("BPC_SetLoadoutId");
|
if (setLoadoutId == null) missing.Add("BPC_SetLoadoutId");
|
||||||
|
|
@ -112,6 +121,9 @@ namespace BlaxCastes
|
||||||
|
|
||||||
// ---- calls -------------------------------------------------------------------------------
|
// ---- calls -------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// <summary>Creates Weapons Tab Reborn's loadout database if it is null, the way the mod itself does. Call inside the try.</summary>
|
||||||
|
private static void EnsureDatabase() => ensureDatabase?.Invoke();
|
||||||
|
|
||||||
/// <summary>The pawn's loadout id, or null when the API is not available.</summary>
|
/// <summary>The pawn's loadout id, or null when the API is not available.</summary>
|
||||||
public static int? LoadoutOf(Pawn pawn)
|
public static int? LoadoutOf(Pawn pawn)
|
||||||
{
|
{
|
||||||
|
|
@ -119,6 +131,7 @@ namespace BlaxCastes
|
||||||
return null;
|
return null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
EnsureDatabase();
|
||||||
return getLoadoutId(pawn);
|
return getLoadoutId(pawn);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -135,6 +148,7 @@ namespace BlaxCastes
|
||||||
return false;
|
return false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
EnsureDatabase();
|
||||||
setLoadoutId(pawn, id);
|
setLoadoutId(pawn, id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -152,6 +166,7 @@ namespace BlaxCastes
|
||||||
return null;
|
return null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
EnsureDatabase();
|
||||||
return getDefaultLoadoutId();
|
return getDefaultLoadoutId();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -168,6 +183,7 @@ namespace BlaxCastes
|
||||||
return null;
|
return null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
EnsureDatabase();
|
||||||
return getLoadoutName(id);
|
return getLoadoutName(id);
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException)
|
catch (InvalidOperationException)
|
||||||
|
|
@ -193,6 +209,7 @@ namespace BlaxCastes
|
||||||
Dictionary<string, int> database;
|
Dictionary<string, int> database;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
EnsureDatabase();
|
||||||
database = getDatabase();
|
database = getDatabase();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
||||||
|
|
@ -466,6 +466,37 @@ namespace BlaxCastesTests
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[BlaxTest("work: pawns Assign by status puts into the caste during a cycle run follow the run's next clicks; a hand-set member stays out")]
|
||||||
|
public static void WorkCycleRunTakesAssignedByStatus()
|
||||||
|
{
|
||||||
|
CheckWorkSlotUsable();
|
||||||
|
WithManualPriorities(true, () =>
|
||||||
|
{
|
||||||
|
Caste c = Fixtures.NewCaste("Work cycle assign by status");
|
||||||
|
CasteManager.SetWorkPriority(c, Growing.defName, 3);
|
||||||
|
T.Check(CasteManager.SetJoinRow(JoinReason.NewColonist, JoinRowMode.SpecificCaste, c), "setup: SetJoinRow failed");
|
||||||
|
Pawn a = PawnThatCan(Fixtures.Colonist, Growing);
|
||||||
|
Pawn b = PawnThatCan(Fixtures.Colonist, Growing);
|
||||||
|
foreach (Pawn p in new[] { a, b })
|
||||||
|
T.Check(CasteManager.Assign(p, c, false, JoinReason.Manual), "setup: Assign failed");
|
||||||
|
b.workSettings.SetPriority(Growing, 4); // by hand, on a value the run passes through
|
||||||
|
|
||||||
|
var run = new Dialog_ManageCastes.WorkCycle();
|
||||||
|
T.Equal(1, run.Click(c, Growing), "members moved by 3 -> 4 (A)");
|
||||||
|
Pawn u = PawnThatCan(Fixtures.Colonist, Growing);
|
||||||
|
T.Check(CasteManager.PawnsToAssignByStatus().Contains(u), "setup: Assign by status does not offer the new colonist");
|
||||||
|
T.Check(Dialog_ManageCastes.AssignByStatus(run) >= 1, "Assign by status assigned nobody");
|
||||||
|
T.Check(Fixtures.Comp.CasteOf(u) == c, "the new colonist is not in the caste after Assign by status");
|
||||||
|
T.Equal(4, Priority(u, Growing), "U's Growing after Assign by status (the caste's value)");
|
||||||
|
|
||||||
|
run.Click(c, Growing);
|
||||||
|
T.Equal(0, c.WorkPriorityOf(Growing.defName) ?? -1, "Growing after 4 -> off");
|
||||||
|
T.Equal(0, Priority(a, Growing), "A followed 4 -> off");
|
||||||
|
T.Equal(0, Priority(u, Growing), "U, assigned during the run, followed 4 -> off");
|
||||||
|
T.Equal(4, Priority(b, Growing), "B's hand-set 4 (it was not a follower when the run started)");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[BlaxTest("work: the cycle runs leave alone, 1, 2, 3, 4, off and back; labels are -, numbers and off")]
|
[BlaxTest("work: the cycle runs leave alone, 1, 2, 3, 4, off and back; labels are -, numbers and off")]
|
||||||
public static void WorkCycle()
|
public static void WorkCycle()
|
||||||
{
|
{
|
||||||
|
|
@ -633,6 +664,78 @@ namespace BlaxCastesTests
|
||||||
T.Check(!c2.IsManaged(CasteSlot.Loadout), "the deleted loadout is still managed after the load check");
|
T.Check(!c2.IsManaged(CasteSlot.Loadout), "the deleted loadout is still managed after the load check");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static FieldInfo LoadoutDatabaseField()
|
||||||
|
{
|
||||||
|
Type dictionary = AccessTools.TypeByName(WeaponsTab.ApiTypeName);
|
||||||
|
T.NotNull(dictionary, WeaponsTab.ApiTypeName);
|
||||||
|
FieldInfo field = AccessTools.Field(dictionary, "CurrentLoadoutDatabase");
|
||||||
|
T.NotNull(field, "LoadoutDictionary.CurrentLoadoutDatabase");
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BlaxTest("loadout: without Weapons Tab Reborn's loadout database (a save made without the mod) the database is created; nothing turns off or is unmanaged")]
|
||||||
|
public static void LoadoutDatabaseMissing()
|
||||||
|
{
|
||||||
|
NeedWeaponsTab();
|
||||||
|
FieldInfo field = LoadoutDatabaseField();
|
||||||
|
object saved = field.GetValue(null);
|
||||||
|
int? first = WeaponsTab.DefaultLoadoutId();
|
||||||
|
T.NotNull(first, "the default loadout id");
|
||||||
|
Caste c = Fixtures.NewCaste("Loadout before the database");
|
||||||
|
CasteManager.SetSlot(c, CasteSlot.Loadout, first.Value);
|
||||||
|
T.Equal(first.Value, c.LoadoutId, "setup: the caste's loadout");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// After loading a save without the mod's data its database is null until its tab or job giver runs.
|
||||||
|
field.SetValue(null, null);
|
||||||
|
CheckSlots();
|
||||||
|
T.Check(WeaponsTab.Available, "the load check with no database turned the loadout slot off");
|
||||||
|
T.Check(c.IsManaged(CasteSlot.Loadout) && c.LoadoutId == first.Value, "the load check with no database unmanaged the caste's loadout (" + c.LoadoutId + ")");
|
||||||
|
T.NotNull(field.GetValue(null), "the loadout database was not created");
|
||||||
|
|
||||||
|
field.SetValue(null, null);
|
||||||
|
T.NotNull(WeaponsTab.DefaultLoadoutId(), "the default loadout with no database (ticking the managed box)");
|
||||||
|
field.SetValue(null, null);
|
||||||
|
T.Check(WeaponsTab.Loadouts().Count > 0, "the loadout list with no database (the manager's dropdown) is empty");
|
||||||
|
T.Check(WeaponsTab.Available, "the loadout slot turned off");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
field.SetValue(null, saved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[BlaxTest("loadout: a Weapons Tab Reborn call that fails turns the slot off and never counts as a deleted loadout")]
|
||||||
|
public static void LoadoutCallFailureIsNotMissing()
|
||||||
|
{
|
||||||
|
NeedWeaponsTab();
|
||||||
|
FieldInfo field = LoadoutDatabaseField();
|
||||||
|
FieldInfo ensureField = AccessTools.Field(typeof(WeaponsTab), "ensureDatabase");
|
||||||
|
T.NotNull(ensureField, "WeaponsTab.ensureDatabase");
|
||||||
|
object saved = field.GetValue(null);
|
||||||
|
object ensure = ensureField.GetValue(null);
|
||||||
|
int? first = WeaponsTab.DefaultLoadoutId();
|
||||||
|
T.NotNull(first, "the default loadout id");
|
||||||
|
Caste c = Fixtures.NewCaste("Loadout through a failed call");
|
||||||
|
CasteManager.SetSlot(c, CasteSlot.Loadout, first.Value);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// No database and no way to create it: the API call throws inside the existence check.
|
||||||
|
field.SetValue(null, null);
|
||||||
|
ensureField.SetValue(null, null);
|
||||||
|
CheckSlots();
|
||||||
|
T.Check(!WeaponsTab.Available, "setup: the failed call did not turn the slot off");
|
||||||
|
T.Check(c.IsManaged(CasteSlot.Loadout) && c.LoadoutId == first.Value, "a failed call counted as a deleted loadout (" + c.LoadoutId + ")");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ensureField.SetValue(null, ensure);
|
||||||
|
field.SetValue(null, saved);
|
||||||
|
AccessTools.Method(typeof(WeaponsTab), "ResetForGame").Invoke(null, null);
|
||||||
|
}
|
||||||
|
T.Check(WeaponsTab.Available, "the loadout slot did not come back after ResetForGame");
|
||||||
|
}
|
||||||
|
|
||||||
// ---- every slot --------------------------------------------------------------------------
|
// ---- every slot --------------------------------------------------------------------------
|
||||||
|
|
||||||
[BlaxTest("slots: duplicating a caste copies the schedule, work priorities, Start from nothing and loadout as separate copies")]
|
[BlaxTest("slots: duplicating a caste copies the schedule, work priorities, Start from nothing and loadout as separate copies")]
|
||||||
|
|
|
||||||
|
|
@ -62,12 +62,17 @@ namespace BlaxCastesTests
|
||||||
T.Equal(1, MessagesWithText(text), "seeding messages after a second load");
|
T.Equal(1, MessagesWithText(text), "seeding messages after a second load");
|
||||||
}
|
}
|
||||||
|
|
||||||
[BlaxTest("starter: with the Caste column off, the seeding message points to the mod settings instead of the missing button")]
|
[BlaxTest("starter: without the Caste column (as the game started), the seeding message points to the mod settings instead of the missing button")]
|
||||||
public static void SeededMessageWithoutColumn()
|
public static void SeededMessageWithoutColumn()
|
||||||
{
|
{
|
||||||
|
if (!CasteColumns.Shown)
|
||||||
|
T.Skip("the Caste column is not in the Assign tab in this run");
|
||||||
Messages.Clear();
|
Messages.Clear();
|
||||||
Fixtures.Settings.showAssignColumn = false;
|
|
||||||
GameComponent_BlaxCastes fresh = Fresh();
|
GameComponent_BlaxCastes fresh = Fresh();
|
||||||
|
// The setting is on again, but the column waits for a restart: it is the column that counts.
|
||||||
|
CasteColumns.Apply(false);
|
||||||
|
try
|
||||||
|
{
|
||||||
// The message history keeps earlier tests' messages, so look only at what this load adds.
|
// The message history keeps earlier tests' messages, so look only at what this load adds.
|
||||||
var before = new HashSet<Message>(Find.Archive.ArchivablesListForReading.OfType<Message>());
|
var before = new HashSet<Message>(Find.Archive.ArchivablesListForReading.OfType<Message>());
|
||||||
fresh.LoadedGame();
|
fresh.LoadedGame();
|
||||||
|
|
@ -75,9 +80,18 @@ namespace BlaxCastesTests
|
||||||
T.Check(fresh.StarterCastesSeeded, "the save is not marked as seeded");
|
T.Check(fresh.StarterCastesSeeded, "the save is not marked as seeded");
|
||||||
string names = fresh.Castes.Select(c => c.label).ToCommaList(useAnd: true);
|
string names = fresh.Castes.Select(c => c.label).ToCommaList(useAnd: true);
|
||||||
string expected = ((string)"BlaxCastes_StarterSeededMessageNoColumn".Translate(names.Named("CASTES"))).CapitalizeFirst();
|
string expected = ((string)"BlaxCastes_StarterSeededMessageNoColumn".Translate(names.Named("CASTES"))).CapitalizeFirst();
|
||||||
T.Equal(expected, ((string)StarterCastes.SeededMessageText(fresh)).CapitalizeFirst(), "seeding message text with the column off");
|
T.Equal(expected, ((string)StarterCastes.SeededMessageText(fresh)).CapitalizeFirst(), "seeding message text without the column");
|
||||||
T.Equal(1, added.Count(t => t == expected), "seeding messages with the column off (added: " + string.Join(" | ", added) + ")");
|
T.Equal(1, added.Count(t => t == expected), "seeding messages without the column (added: " + string.Join(" | ", added) + ")");
|
||||||
T.Equal(0, added.Count(t => t == SeededMessageText(fresh)), "messages pointing to Assign > Manage castes after a load with the column off");
|
T.Equal(0, added.Count(t => t == SeededMessageText(fresh)), "messages pointing to Assign > Manage castes after a load without the column");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
CasteColumns.Apply(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The setting turned off in this session waits for a restart: the column is there, so the message points to it.
|
||||||
|
Fixtures.Settings.showAssignColumn = false;
|
||||||
|
T.Equal(SeededMessageText(fresh), ((string)StarterCastes.SeededMessageText(fresh)).CapitalizeFirst(), "seeding message text with the setting off and the column still shown");
|
||||||
}
|
}
|
||||||
|
|
||||||
[BlaxTest("starter: a save that already has castes, or seedStarterCastes off, gets no starter castes")]
|
[BlaxTest("starter: a save that already has castes, or seedStarterCastes off, gets no starter castes")]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using BlaxCastes;
|
using BlaxCastes;
|
||||||
|
using HarmonyLib;
|
||||||
using RimWorld;
|
using RimWorld;
|
||||||
|
using RimWorld.Planet;
|
||||||
using Verse;
|
using Verse;
|
||||||
|
|
||||||
namespace BlaxCastesTests
|
namespace BlaxCastesTests
|
||||||
|
|
@ -473,8 +477,339 @@ namespace BlaxCastesTests
|
||||||
T.Check(p.foodRestriction.CurrentFoodPolicy == Lavish(), Who(p) + " lost its hand-set food: " + p.foodRestriction.CurrentFoodPolicy.label);
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Lavish(), Who(p) + " lost its hand-set food: " + p.foodRestriction.CurrentFoodPolicy.label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- what changed while the pawn was away ----------------------------------------------
|
||||||
|
|
||||||
|
private static WorkTypeDef Firefighter() => Fixtures.NeedDef(DefDatabase<WorkTypeDef>.GetNamedSilentFail("Firefighter"), "work type Firefighter");
|
||||||
|
|
||||||
|
/// <summary>A spawned colonist that can do the work type (backstories and traits can disable some).</summary>
|
||||||
|
private static Pawn ColonistThatCan(WorkTypeDef def)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 12; i++)
|
||||||
|
{
|
||||||
|
Pawn p = Fixtures.Colonist();
|
||||||
|
Fixtures.Unqueue(p);
|
||||||
|
if (WorkSlot.CanDo(p, def))
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
T.Fail("no generated colonist could do " + def.defName + " in 12 tries");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BlaxTest("status: a slot and a work type the caste starts managing while the pawn is away reach it on its return; an older record keeps its own values")]
|
||||||
|
public static void ReturnGetsNewlyManagedSlots()
|
||||||
|
{
|
||||||
|
PlaySettings play = Find.PlaySettings;
|
||||||
|
bool manual = play.useWorkPriorities;
|
||||||
|
play.useWorkPriorities = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
WorkTypeDef fire = Firefighter();
|
||||||
|
Caste colonists = Make("Colonists (newly managed test)", Worker(), Fine());
|
||||||
|
Caste prisoners = Make("Prisoners (newly managed test)", null, Paste());
|
||||||
|
Caste wrong = Make("Wrong row (newly managed test)", Nudist(), Lavish());
|
||||||
|
Row(JoinReason.NewPrisoner, prisoners);
|
||||||
|
Row(JoinReason.NewColonist, wrong);
|
||||||
|
T.Check(!colonists.IsManaged(CasteSlot.Schedule) && colonists.WorkPriorityOf(fire.defName) == null, "setup: the caste manages the schedule or Firefighter");
|
||||||
|
|
||||||
|
Pawn p = ColonistThatCan(fire);
|
||||||
|
Pawn old = ColonistThatCan(fire);
|
||||||
|
foreach (Pawn pawn in new[] { p, old })
|
||||||
|
{
|
||||||
|
T.Check(CasteManager.Assign(pawn, colonists, true, JoinReason.NewColonist), "setup: Assign failed");
|
||||||
|
pawn.timetable.SetAssignment(3, TimeAssignmentDefOf.Joy); // its own day: the caste leaves the schedule alone
|
||||||
|
pawn.workSettings.SetPriority(fire, 3);
|
||||||
|
pawn.outfits.CurrentApparelPolicy = Nudist(); // by hand, on a slot the caste manages
|
||||||
|
pawn.guest.CapturedBy(Faction.OfPlayer, Warden());
|
||||||
|
}
|
||||||
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
||||||
|
T.NotNull(record, "former-caste record after the arrest");
|
||||||
|
T.Check(record.WasManaged(CasteSlot.Apparel) && !record.WasManaged(CasteSlot.Schedule), "managed slots in the record: " + string.Join(", ", record.managed ?? new List<CasteSlot>()));
|
||||||
|
T.Check(!record.WasListed(fire.defName), "the record lists Firefighter");
|
||||||
|
// A record saved before Castes kept the managed slots: read as "managed then", so the pawn keeps its own.
|
||||||
|
FormerCaste oldRecord = Fixtures.Comp.FormerOf(old);
|
||||||
|
T.NotNull(oldRecord, "former-caste record of the second pawn");
|
||||||
|
oldRecord.managed = null;
|
||||||
|
oldRecord.listedWork = null;
|
||||||
|
Fixtures.ApplyJoins(p, old);
|
||||||
|
CheckIn(p, prisoners, JoinReason.NewPrisoner, "after the arrest");
|
||||||
|
|
||||||
|
// While they are away, the caste starts managing the schedule and lists Firefighter: every member gets both.
|
||||||
|
CasteManager.SetSlot(colonists, CasteSlot.Schedule, NightShift());
|
||||||
|
CasteManager.SetWorkPriority(colonists, fire.defName, 1);
|
||||||
|
|
||||||
|
foreach (Pawn pawn in new[] { p, old })
|
||||||
|
GenGuest.PrisonerRelease(pawn);
|
||||||
|
Fixtures.ApplyJoins(p, old);
|
||||||
|
CheckIn(p, colonists, JoinReason.PreviousCaste, "after the release");
|
||||||
|
T.Equal(TimeAssignmentDefOf.Work, p.timetable.GetAssignment(3), Who(p) + "'s hour 3 (the caste's schedule, not its own Joy)");
|
||||||
|
T.Equal(TimeAssignmentDefOf.Sleep, p.timetable.GetAssignment(12), Who(p) + "'s hour 12 (the caste's schedule)");
|
||||||
|
T.Equal(1, p.workSettings.GetPriority(fire), Who(p) + "'s Firefighter (listed by the caste while it was away)");
|
||||||
|
T.Check(p.outfits.CurrentApparelPolicy == Nudist(), Who(p) + " lost its hand-set outfit: " + p.outfits.CurrentApparelPolicy.label);
|
||||||
|
List<CasteSlot> overrides = CasteManager.Overrides(p);
|
||||||
|
T.Check(overrides.Count == 1 && overrides[0] == CasteSlot.Apparel, Who(p) + "'s overrides: " + string.Join(", ", overrides));
|
||||||
|
|
||||||
|
CheckIn(old, colonists, JoinReason.PreviousCaste, "after the release with an older record");
|
||||||
|
T.Equal(TimeAssignmentDefOf.Joy, old.timetable.GetAssignment(3), Who(old) + "'s own hour 3 (older record)");
|
||||||
|
T.Equal(3, old.workSettings.GetPriority(fire), Who(old) + "'s own Firefighter (older record)");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
play.useWorkPriorities = manual;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[BlaxTest("status: a hand-set policy deleted while the pawn is away is skipped on return, even when a new policy got its id")]
|
||||||
|
public static void ReturnSkipsDeletedPolicy()
|
||||||
|
{
|
||||||
|
FoodRestrictionDatabase db = Current.Game.foodRestrictionDatabase;
|
||||||
|
FoodPolicy custom = db.MakeNewFoodRestriction();
|
||||||
|
custom.label = "Blax test custom food";
|
||||||
|
FoodPolicy reused = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Caste colonists = Make("Colonists (deleted policy test)", Worker(), Fine());
|
||||||
|
Caste prisoners = Make("Prisoners (deleted policy test)", null, Paste());
|
||||||
|
Row(JoinReason.NewPrisoner, prisoners);
|
||||||
|
|
||||||
|
Pawn p = Fixtures.Colonist();
|
||||||
|
Fixtures.Unqueue(p);
|
||||||
|
T.Check(CasteManager.Assign(p, colonists, true, JoinReason.NewColonist), "setup: Assign failed");
|
||||||
|
p.foodRestriction.CurrentFoodPolicy = custom; // by hand
|
||||||
|
p.guest.CapturedBy(Faction.OfPlayer, Warden());
|
||||||
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
||||||
|
T.Check(record != null && record.food == custom, "the record's food: " + (record?.food?.label ?? "none"));
|
||||||
|
Fixtures.ApplyJoins(p);
|
||||||
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Paste(), Who(p) + " does not eat the prisoner food");
|
||||||
|
|
||||||
|
int id = custom.id;
|
||||||
|
AcceptanceReport deleted = db.TryDelete(custom);
|
||||||
|
T.Check(deleted.Accepted, "the game refused to delete the custom food policy: " + deleted.Reason);
|
||||||
|
reused = db.MakeNewFoodRestriction();
|
||||||
|
T.Equal(id, reused.id, "setup: the new food policy's id (the game gives the highest id plus one)");
|
||||||
|
|
||||||
|
GenGuest.PrisonerRelease(p);
|
||||||
|
Fixtures.ApplyJoins(p);
|
||||||
|
CheckIn(p, colonists, JoinReason.PreviousCaste, "after the release");
|
||||||
|
T.Check(p.foodRestriction.CurrentFoodPolicy != reused, Who(p) + " got the new policy that reused the deleted one's id");
|
||||||
|
T.Check(p.foodRestriction.CurrentFoodPolicy == Fine(), Who(p) + " should fall back to the caste's food: " + p.foodRestriction.CurrentFoodPolicy.label);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (db.AllFoodRestrictions.Contains(custom))
|
||||||
|
db.TryDelete(custom);
|
||||||
|
if (reused != null && db.AllFoodRestrictions.Contains(reused))
|
||||||
|
db.TryDelete(reused);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- leaving the map ------------------------------------------------------------------
|
||||||
|
|
||||||
|
[BlaxTest("status: a freed slave from another faction that walks off the map leaves its caste with a slave record; nothing joins")]
|
||||||
|
public static void FreedForeignSlaveWalksOff()
|
||||||
|
{
|
||||||
|
Caste slaves = Make("Slaves (walk off test)", null, Simple());
|
||||||
|
Caste colonists = Make("Colonists (walk off test)", Worker(), Fine());
|
||||||
|
Row(JoinReason.NewColonist, colonists);
|
||||||
|
|
||||||
|
Pawn p = Fixtures.ColonySlave();
|
||||||
|
Fixtures.Unqueue(p);
|
||||||
|
T.Check(p.SlaveFaction != null && p.SlaveFaction != Faction.OfPlayer, "setup: the slave's own faction is " + p.SlaveFaction);
|
||||||
|
T.Check(CasteManager.Assign(p, slaves, true, JoinReason.NewSlave), "setup: Assign failed");
|
||||||
|
GenGuest.EmancipateSlave(Warden(), p);
|
||||||
|
T.Check(p.IsSlave && p.guest.Released, Who(p) + " should walk off still a slave: slave " + p.IsSlave + ", released " + p.guest.Released);
|
||||||
|
T.Check(!JoinDefaults.IsQueued(p), "freeing a slave from another faction queued a join before it left");
|
||||||
|
|
||||||
|
p.ExitMap(true, Rot4.North);
|
||||||
|
T.Equal(0, JoinScopes.Depth, "open join scopes after ExitMap");
|
||||||
|
T.Check(!p.Spawned, Who(p) + " is still on the map");
|
||||||
|
T.Check(!JoinDefaults.IsQueued(p), "walking off the map queued a join (" + JoinDefaults.QueuedFor(p)?.reason + ")");
|
||||||
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
||||||
|
T.Check(record != null && record.casteId == slaves.id && record.side == JoinSide.Slave, "former-caste record: " + (record?.ToString() ?? "none"));
|
||||||
|
Fixtures.ApplyJoins(p);
|
||||||
|
T.Check(Fixtures.Comp.MembershipOf(p) == null, Who(p) + " kept a membership: " + State(p));
|
||||||
|
T.Check(!CasteManager.LiveMembers(slaves).Contains(p) && !CasteManager.LiveMembers(colonists).Contains(p), Who(p) + " still counts as a member");
|
||||||
|
T.Info("faction after leaving: " + (p.Faction?.Name ?? "none"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[BlaxTest("status: an escaped slave and an escaped prisoner that leave the map leave their caste")]
|
||||||
|
public static void EscapedPawnsLeave()
|
||||||
|
{
|
||||||
|
Caste slaves = Make("Slaves (escape test)", null, Simple());
|
||||||
|
Caste prisoners = Make("Prisoners (escape test)", null, Paste());
|
||||||
|
|
||||||
|
Pawn prisoner = Fixtures.Prisoner();
|
||||||
|
Fixtures.Unqueue(prisoner);
|
||||||
|
T.Check(CasteManager.Assign(prisoner, prisoners, true, JoinReason.NewPrisoner), "setup: Assign the prisoner failed");
|
||||||
|
prisoner.ExitMap(true, Rot4.North);
|
||||||
|
T.Equal(0, JoinScopes.Depth, "open join scopes after the prisoner left");
|
||||||
|
T.Check(Fixtures.Comp.MembershipOf(prisoner) == null, Who(prisoner) + " kept a membership: " + State(prisoner));
|
||||||
|
T.Check(!CasteManager.LiveMembers(prisoners).Contains(prisoner), "the escaped prisoner still counts as a member");
|
||||||
|
T.Check(!JoinDefaults.IsQueued(prisoner), "the escaped prisoner was queued");
|
||||||
|
T.Info("escaped prisoner still a prisoner of the colony in the world: " + prisoner.IsPrisonerOfColony);
|
||||||
|
|
||||||
|
if (!ModsConfig.IdeologyActive)
|
||||||
|
T.Skip("slaves need Ideology; the escaped prisoner check passed");
|
||||||
|
Pawn slave = Fixtures.ColonySlave();
|
||||||
|
Fixtures.Unqueue(slave);
|
||||||
|
T.Check(CasteManager.Assign(slave, slaves, true, JoinReason.NewSlave), "setup: Assign the slave failed");
|
||||||
|
slave.ExitMap(true, Rot4.North);
|
||||||
|
T.Equal(0, JoinScopes.Depth, "open join scopes after the slave left");
|
||||||
|
T.Check(!JoinDefaults.IsQueued(slave), "the escaped slave was queued (" + JoinDefaults.QueuedFor(slave)?.reason + ")");
|
||||||
|
FormerCaste record = Fixtures.Comp.FormerOf(slave);
|
||||||
|
T.Check(record != null && record.casteId == slaves.id && record.side == JoinSide.Slave, "former-caste record: " + (record?.ToString() ?? "none"));
|
||||||
|
Fixtures.ApplyJoins(slave);
|
||||||
|
T.Check(Fixtures.Comp.MembershipOf(slave) == null, Who(slave) + " kept a membership: " + State(slave));
|
||||||
|
T.Check(!CasteManager.LiveMembers(slaves).Contains(slave), "the escaped slave still counts as a member");
|
||||||
|
}
|
||||||
|
|
||||||
|
[BlaxTest("status: a colonist that leaves in a caravan, or is kidnapped, keeps its caste")]
|
||||||
|
public static void CaravanAndKidnapKeepCaste()
|
||||||
|
{
|
||||||
|
Caste miner = Make("Miner (caravan test)", Worker(), Fine());
|
||||||
|
|
||||||
|
Pawn p = Fixtures.Colonist();
|
||||||
|
Fixtures.Unqueue(p);
|
||||||
|
T.Check(CasteManager.Assign(p, miner, false, JoinReason.Manual), "setup: Assign failed");
|
||||||
|
Map map = Fixtures.Map;
|
||||||
|
Caravan caravan = CaravanExitMapUtility.ExitMapAndCreateCaravan(new[] { p }, Faction.OfPlayer, map.Tile, map.Tile, PlanetTile.Invalid, sendMessage: false);
|
||||||
|
T.NotNull(caravan, "the caravan");
|
||||||
|
T.Equal(0, JoinScopes.Depth, "open join scopes after leaving in a caravan");
|
||||||
|
T.Check(p.IsCaravanMember() && p.Faction == Faction.OfPlayer, Who(p) + " is not a player caravan member");
|
||||||
|
T.Check(Fixtures.Comp.CasteOf(p) == miner, Who(p) + " lost its caste in the caravan: " + State(p));
|
||||||
|
T.Check(Fixtures.Comp.FormerOf(p) == null, "leaving in a caravan wrote a former-caste record");
|
||||||
|
T.Check(!JoinDefaults.IsQueued(p), "leaving in a caravan queued a join");
|
||||||
|
Fixtures.ApplyJoins(p);
|
||||||
|
T.Check(Fixtures.Comp.CasteOf(p) == miner, Who(p) + " lost its caste on the next tick: " + State(p));
|
||||||
|
CaravanEnterMapUtility.Enter(caravan, map, CaravanEnterMode.Edge);
|
||||||
|
T.Check(p.Spawned && Fixtures.Comp.CasteOf(p) == miner, Who(p) + " back from the caravan: spawned " + p.Spawned + ", " + State(p));
|
||||||
|
|
||||||
|
Faction raiders = Fixtures.HostileFaction();
|
||||||
|
if (raiders == null)
|
||||||
|
{
|
||||||
|
T.Info("no hostile faction: kidnapping not checked");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pawn q = Fixtures.Colonist();
|
||||||
|
Fixtures.Unqueue(q);
|
||||||
|
T.Check(CasteManager.Assign(q, miner, false, JoinReason.Manual), "setup: Assign the second colonist failed");
|
||||||
|
raiders.kidnapped.Kidnap(q, null);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
T.Check(q.IsKidnapped(), "setup: " + Who(q) + " is not kidnapped");
|
||||||
|
Fixtures.ApplyJoins(q);
|
||||||
|
T.Check(Fixtures.Comp.CasteOf(q) == miner, Who(q) + " lost its caste when kidnapped: " + State(q));
|
||||||
|
T.Check(Fixtures.Comp.FormerOf(q) == null, "being kidnapped wrote a former-caste record");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
raiders.kidnapped.RemoveKidnappedPawn(q);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[BlaxTest("status: a slave left on a closing map leaves its caste with a slave record; nothing joins")]
|
||||||
|
public static void SlaveLostWithClosingMap()
|
||||||
|
{
|
||||||
|
Caste slaves = Make("Slaves (closing map test)", null, Simple());
|
||||||
|
Caste colonists = Make("Colonists (closing map test)", Worker(), Fine());
|
||||||
|
Row(JoinReason.NewColonist, colonists);
|
||||||
|
Pawn p = Fixtures.ColonySlave();
|
||||||
|
Fixtures.Unqueue(p);
|
||||||
|
T.Check(CasteManager.Assign(p, slaves, true, JoinReason.NewSlave), "setup: Assign failed");
|
||||||
|
|
||||||
|
// The hook around MapDeiniter.PassPawnsToWorld, with that method's body for this one pawn (closing the test map would end the run).
|
||||||
|
MethodInfo target = AccessTools.Method(typeof(MapDeiniter), "PassPawnsToWorld");
|
||||||
|
T.NotNull(target, "MapDeiniter.PassPawnsToWorld");
|
||||||
|
var info = Harmony.GetPatchInfo(target);
|
||||||
|
T.Check(info != null && info.Prefixes.Any(x => x.owner == BlaxCastesStartup.HarmonyId) && info.Finalizers.Any(x => x.owner == BlaxCastesStartup.HarmonyId),
|
||||||
|
"Blax Castes did not patch MapDeiniter.PassPawnsToWorld");
|
||||||
|
Type patch = AccessTools.TypeByName("BlaxCastes.Patch_MapDeiniter_PassPawnsToWorld");
|
||||||
|
T.NotNull(patch, "the closing map patch class");
|
||||||
|
MethodInfo cleanUp = AccessTools.Method(typeof(MapDeiniter), "CleanUpAndPassToWorld");
|
||||||
|
T.NotNull(cleanUp, "MapDeiniter.CleanUpAndPassToWorld");
|
||||||
|
|
||||||
|
object[] prefixArgs = { Fixtures.Map, null };
|
||||||
|
AccessTools.Method(patch, "Prefix").Invoke(null, prefixArgs);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
p.DeSpawnOrDeselect();
|
||||||
|
cleanUp.Invoke(null, new object[] { p });
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
AccessTools.Method(patch, "Finalizer").Invoke(null, new object[] { null, prefixArgs[1] });
|
||||||
|
}
|
||||||
|
T.Equal(0, JoinScopes.Depth, "open join scopes after the map closed");
|
||||||
|
T.Check(!JoinDefaults.IsQueued(p), "the lost slave was queued (" + JoinDefaults.QueuedFor(p)?.reason + ")");
|
||||||
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
||||||
|
T.Check(record != null && record.casteId == slaves.id && record.side == JoinSide.Slave, "former-caste record: " + (record?.ToString() ?? "none"));
|
||||||
|
Fixtures.ApplyJoins(p);
|
||||||
|
T.Check(Fixtures.Comp.MembershipOf(p) == null, Who(p) + " kept a membership: " + State(p));
|
||||||
|
}
|
||||||
|
|
||||||
// ---- save and reload -----------------------------------------------------------------
|
// ---- save and reload -----------------------------------------------------------------
|
||||||
|
|
||||||
|
// The successor policy takes the deleted one's id and label, so both have the same load ID: a
|
||||||
|
// reference to the deleted policy left in the save would load as the successor.
|
||||||
|
[BlaxTest("status: set up a former-caste record whose own policy is deleted before the save, and a new policy with its id and label")]
|
||||||
|
public static void DeletedPolicyReloadSetup()
|
||||||
|
{
|
||||||
|
FoodRestrictionDatabase db = Current.Game.foodRestrictionDatabase;
|
||||||
|
FoodPolicy doomed = db.MakeNewFoodRestriction();
|
||||||
|
doomed.label = "Blax test doomed reload food";
|
||||||
|
Caste c = Fixtures.KeepCaste(Make("Deleted policy reload test", null, Fine()));
|
||||||
|
Pawn p = Fixtures.Colonist(); // destroyed by the cleanup: the record is keyed by ThingID
|
||||||
|
Fixtures.Unqueue(p);
|
||||||
|
CasteManager.Assign(p, c, true, JoinReason.NewColonist);
|
||||||
|
p.foodRestriction.CurrentFoodPolicy = doomed;
|
||||||
|
p.drugs.CurrentPolicy = Social();
|
||||||
|
Faction other = Fixtures.FriendlyFaction();
|
||||||
|
T.NotNull(other, "a friendly faction");
|
||||||
|
p.SetFaction(other);
|
||||||
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
||||||
|
T.Check(record != null && record.food == doomed, "setup: the record's food: " + (record?.food?.label ?? "none"));
|
||||||
|
if (p.foodRestriction != null)
|
||||||
|
p.foodRestriction.CurrentFoodPolicy = Fine();
|
||||||
|
AcceptanceReport deleted = db.TryDelete(doomed);
|
||||||
|
T.Check(deleted.Accepted, "the game refused to delete the food policy: " + deleted.Reason);
|
||||||
|
FoodPolicy successor = db.MakeNewFoodRestriction(); // kept for phase 2, deleted there
|
||||||
|
T.Equal(doomed.id, successor.id, "setup: the new food policy's id (the game gives the highest id plus one)");
|
||||||
|
successor.label = doomed.label;
|
||||||
|
T.Equal(doomed.GetUniqueLoadID(), successor.GetUniqueLoadID(), "setup: the new food policy's load ID");
|
||||||
|
T.Check(record.food == doomed, "setup: the record's food after the new policy was made: " + (record.food?.label ?? "none"));
|
||||||
|
T.Carry["deletedPolicyPawn"] = p.ThingID;
|
||||||
|
T.Carry["deletedPolicyLabel"] = doomed.label;
|
||||||
|
T.Carry["deletedPolicySuccessor"] = successor.id.ToString();
|
||||||
|
T.Carry["deletedPolicyDrug"] = Social().id.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BlaxTest("status: a record whose own policy was deleted loads without that policy, not as the new policy with its load ID, and without warnings", phase: 2)]
|
||||||
|
public static void DeletedPolicyRecordLoads()
|
||||||
|
{
|
||||||
|
FoodRestrictionDatabase db = Current.Game.foodRestrictionDatabase;
|
||||||
|
FoodPolicy successor = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string label = null, successorId = null;
|
||||||
|
T.Check(T.Carry.TryGetValue("deletedPolicyPawn", out string pawnId) && T.Carry.TryGetValue("deletedPolicyLabel", out label)
|
||||||
|
&& T.Carry.TryGetValue("deletedPolicySuccessor", out successorId), "phase 1 setup did not run");
|
||||||
|
successor = db.AllFoodRestrictions.FirstOrDefault(f => f.id.ToString() == successorId);
|
||||||
|
T.Check(successor != null && successor.label == label, "the new food policy with the deleted one's id and label did not survive the reload: " + (successor?.label ?? "none"));
|
||||||
|
T.Check(Fixtures.Comp.FormerCastes.TryGetValue(pawnId, out FormerCaste record), "the record for " + pawnId + " did not survive the reload");
|
||||||
|
T.Check(record.food != successor, "the record's deleted food policy came back as the new policy with its load ID (" + successor.GetUniqueLoadID() + ")");
|
||||||
|
T.Check(record.food == null, "the record's deleted food policy came back as " + record.food?.label);
|
||||||
|
T.Equal(T.Carry["deletedPolicyDrug"], record.drug?.id.ToString(), "the record's drug policy (still in the game) after the reload");
|
||||||
|
List<string> problems = Log.Messages
|
||||||
|
.Where(m => (m.type == LogMessageType.Error || m.type == LogMessageType.Warning) && m.text != null && m.text.Contains(label))
|
||||||
|
.Select(m => m.type + ": " + m.text).ToList();
|
||||||
|
T.Check(problems.Count == 0, "errors or warnings about the deleted policy: " + string.Join(" | ", problems.Take(2)));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (successor != null && db.AllFoodRestrictions.Contains(successor))
|
||||||
|
db.TryDelete(successor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Runs last in this class (source order): the record is checked after the reload.
|
// Runs last in this class (source order): the record is checked after the reload.
|
||||||
[BlaxTest("status: set up a former-caste record for the reload")]
|
[BlaxTest("status: set up a former-caste record for the reload")]
|
||||||
public static void ReloadSetup()
|
public static void ReloadSetup()
|
||||||
|
|
@ -488,10 +823,11 @@ namespace BlaxCastesTests
|
||||||
p.SetFaction(other);
|
p.SetFaction(other);
|
||||||
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
FormerCaste record = Fixtures.Comp.FormerOf(p);
|
||||||
T.NotNull(record, "setup: no former-caste record");
|
T.NotNull(record, "setup: no former-caste record");
|
||||||
T.Check(record.Followed(CasteSlot.Food) && record.foodId == Fine().id, "setup: the record's food: id " + record.foodId + ", followed " + string.Join(", ", record.followed));
|
T.Check(record.Followed(CasteSlot.Food) && record.food == Fine(), "setup: the record's food: " + record.food?.label + ", followed " + string.Join(", ", record.followed));
|
||||||
T.Carry["formerPawn"] = p.ThingID;
|
T.Carry["formerPawn"] = p.ThingID;
|
||||||
T.Carry["formerCaste"] = c.id.ToString();
|
T.Carry["formerCaste"] = c.id.ToString();
|
||||||
T.Carry["formerFood"] = record.foodId.ToString();
|
T.Carry["formerFood"] = record.food.id.ToString();
|
||||||
|
T.Carry["formerManaged"] = string.Join(",", record.managed);
|
||||||
T.Carry["formerSchedule"] = record.schedule == null ? "none" : string.Join(",", record.schedule);
|
T.Carry["formerSchedule"] = record.schedule == null ? "none" : string.Join(",", record.schedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -506,8 +842,9 @@ namespace BlaxCastesTests
|
||||||
T.Check(record.auto, "record auto flag");
|
T.Check(record.auto, "record auto flag");
|
||||||
T.NotNull(Fixtures.Comp.CasteById(record.casteId), "the record's caste after the reload");
|
T.NotNull(Fixtures.Comp.CasteById(record.casteId), "the record's caste after the reload");
|
||||||
T.Check(!record.casteless, "record turned into a No caste record");
|
T.Check(!record.casteless, "record turned into a No caste record");
|
||||||
T.Equal(T.Carry["formerFood"], record.foodId.ToString(), "record food id");
|
T.Equal(T.Carry["formerFood"], record.food?.id.ToString(), "record food policy");
|
||||||
T.Check(record.Followed(CasteSlot.Food), "record lost its followed slots: " + string.Join(", ", record.followed));
|
T.Check(record.Followed(CasteSlot.Food), "record lost its followed slots: " + string.Join(", ", record.followed));
|
||||||
|
T.Equal(T.Carry["formerManaged"], record.managed == null ? "null" : string.Join(",", record.managed), "record managed slots");
|
||||||
T.Equal(T.Carry["formerSchedule"], record.schedule == null ? "none" : string.Join(",", record.schedule), "record schedule");
|
T.Equal(T.Carry["formerSchedule"], record.schedule == null ? "none" : string.Join(",", record.schedule), "record schedule");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -482,20 +482,69 @@ namespace BlaxCastesTests
|
||||||
T.Equal(1, FirstLoadMessages(), "first-load messages in the history of a new game");
|
T.Equal(1, FirstLoadMessages(), "first-load messages in the history of a new game");
|
||||||
}
|
}
|
||||||
|
|
||||||
[BlaxTest("ui: the first-load message points to Manage castes, and waits while the column is off")]
|
[BlaxTest("ui: the first-load message points to Manage castes, and waits while the column is not there as the game started, whatever the setting says now")]
|
||||||
public static void FirstLoadMessage()
|
public static void FirstLoadMessage()
|
||||||
{
|
{
|
||||||
|
if (!CasteColumns.Shown)
|
||||||
|
T.Skip("the Caste column is not in the Assign tab in this run");
|
||||||
// Vanilla drops a message whose text is still on screen (the new game's copy), so clear the live ones first.
|
// Vanilla drops a message whose text is still on screen (the new game's copy), so clear the live ones first.
|
||||||
Messages.Clear();
|
Messages.Clear();
|
||||||
int before = FirstLoadMessages();
|
int before = FirstLoadMessages();
|
||||||
T.Check(Dialog_ManageCastes.ShowFirstLoadMessage(), "returned false with the column on");
|
T.Check(Dialog_ManageCastes.ShowFirstLoadMessage(), "returned false with the column on");
|
||||||
T.Equal(before + 1, FirstLoadMessages(), "first-load messages in the history after posting one");
|
T.Equal(before + 1, FirstLoadMessages(), "first-load messages in the history after posting one");
|
||||||
|
|
||||||
|
// The setting turned off in this session waits for a restart: the column and its button are still there.
|
||||||
Fixtures.Settings.showAssignColumn = false;
|
Fixtures.Settings.showAssignColumn = false;
|
||||||
T.Check(!Dialog_ManageCastes.ShowFirstLoadMessage(), "returned true with the column off");
|
Messages.Clear();
|
||||||
T.Equal(before + 1, FirstLoadMessages(), "first-load messages after a call with the column off");
|
T.Check(Dialog_ManageCastes.ShowFirstLoadMessage(), "returned false while the column is still shown (the setting waits for a restart)");
|
||||||
|
T.Equal(before + 2, FirstLoadMessages(), "first-load messages after a call with the setting off and the column shown");
|
||||||
|
|
||||||
|
// The game started without the column: the message waits, though the setting is on again.
|
||||||
|
Fixtures.Settings.showAssignColumn = true;
|
||||||
|
CasteColumns.Apply(false);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
T.Check(!CasteColumns.Shown, "setup: the column is still in the Assign table");
|
||||||
|
T.Check(!Dialog_ManageCastes.ShowFirstLoadMessage(), "returned true without the column (setting on, waiting for a restart)");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
CasteColumns.Apply(true);
|
||||||
|
}
|
||||||
|
T.Equal(before + 2, FirstLoadMessages(), "first-load messages after a call without the column");
|
||||||
T.Carry["firstLoadMessages"] = FirstLoadMessages().ToString();
|
T.Carry["firstLoadMessages"] = FirstLoadMessages().ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[BlaxTest("ui: the schedule grid paints only after a press that started on it, never while the scrollbar is dragged over it")]
|
||||||
|
public static void SchedulePaintNeedsPressOnGrid()
|
||||||
|
{
|
||||||
|
bool started = false;
|
||||||
|
// A press on the scrollbar (not over the grid; the scrollbar may also use the event), then a drag over the grid.
|
||||||
|
T.Check(!Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.MouseDown, 0, false, true), "a press beside the grid paints");
|
||||||
|
T.Check(!Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.Used, 0, true, true), "a press another control used paints");
|
||||||
|
T.Check(!Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.MouseDrag, 0, true, true), "dragging onto the grid after a press beside it paints");
|
||||||
|
T.Check(!Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.Repaint, 0, true, true), "a repaint over the grid during that drag paints");
|
||||||
|
T.Check(!Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.MouseUp, 0, true, false), "the release over the grid paints");
|
||||||
|
|
||||||
|
// A press on the grid paints, and goes on while the button is held.
|
||||||
|
T.Check(Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.MouseDown, 0, true, true), "a press on the grid does not paint");
|
||||||
|
T.Check(Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.MouseDrag, 0, true, true), "dragging along the grid does not paint");
|
||||||
|
T.Check(Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.Repaint, 0, true, true), "a repaint while dragging along the grid does not paint");
|
||||||
|
T.Check(!Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.MouseUp, 0, true, false), "the release paints");
|
||||||
|
T.Check(!Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.Repaint, 0, true, false), "a repaint after the release paints");
|
||||||
|
|
||||||
|
// A right press on the grid starts nothing.
|
||||||
|
T.Check(!Dialog_ManageCastes.SchedulePaintAllowed(ref started, UnityEngine.EventType.MouseDown, 1, true, false), "a right press on the grid paints");
|
||||||
|
}
|
||||||
|
|
||||||
|
[BlaxTest("ui: the Caste column setting's tooltip names where the column sits in each tab")]
|
||||||
|
public static void ColumnSettingTip()
|
||||||
|
{
|
||||||
|
string tip = "BlaxCastes_SettingShowAssignColumnTip".Translate();
|
||||||
|
T.Check(tip.Contains("right of the timetable"), "the tooltip does not say the column sits right of the timetable in the Schedule tab: " + tip);
|
||||||
|
T.Check(!tip.Contains("left of the policy columns, the schedule"), "the tooltip still puts the column left of the schedule: " + tip);
|
||||||
|
}
|
||||||
|
|
||||||
private static int FirstLoadMessages()
|
private static int FirstLoadMessages()
|
||||||
{
|
{
|
||||||
string text = ((string)"BlaxCastes_FirstLoadMessage".Translate()).CapitalizeFirst();
|
string text = ((string)"BlaxCastes_FirstLoadMessage".Translate()).CapitalizeFirst();
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ Change if you disagree.
|
||||||
- Memberships save with `Scribe_Collections` (LookMode.Reference / Deep) and `logNullErrors: false`, because world-pawn GC leaves null keys. Null, Discarded and destroyed-but-not-dead keys are purged on save and after load.
|
- Memberships save with `Scribe_Collections` (LookMode.Reference / Deep) and `logNullErrors: false`, because world-pawn GC leaves null keys. Null, Discarded and destroyed-but-not-dead keys are purged on save and after load.
|
||||||
- PostLoadInit checks every slot (`CasteManager.CheckSlots`): policies with `db.All*.Contains`, a missing one becomes unmanaged, with one warning per caste; a schedule hour whose `TimeAssignmentDef` is gone becomes Anything and a work type that is gone is dropped, each with one warning; a loadout id Weapons Tab Reborn no longer has becomes unmanaged with one warning (without the mod the id is kept). Apply checks the same before every write. The manager runs the same check every frame, and saving runs it too.
|
- PostLoadInit checks every slot (`CasteManager.CheckSlots`): policies with `db.All*.Contains`, a missing one becomes unmanaged, with one warning per caste; a schedule hour whose `TimeAssignmentDef` is gone becomes Anything and a work type that is gone is dropped, each with one warning; a loadout id Weapons Tab Reborn no longer has becomes unmanaged with one warning (without the mod the id is kept). Apply checks the same before every write. The manager runs the same check every frame, and saving runs it too.
|
||||||
- Policy load IDs contain the label. That is safe, because the caste and the policy sit in the same save.
|
- Policy load IDs contain the label. That is safe, because the caste and the policy sit in the same save.
|
||||||
- Former-caste records are keyed by ThingID string, not by reference, so a discarded pawn leaves no unresolved reference. The caste and the pawn's own policies in a record are stored by id; a policy deleted since is skipped on return.
|
- Former-caste records are keyed by ThingID string, not by reference, so a discarded pawn leaves no unresolved reference. The caste in a record is stored by id. The pawn's own policies are references, like a caste's policy slots, so a policy deleted since is skipped on return even when a new policy got its id (the game gives a new policy the highest id plus one, so deleting the newest one frees its id). A reference to a policy deleted since is dropped before each save, so loading never meets a reference it cannot resolve, or one that resolves to a new policy with the same load ID (`Policy.GetUniqueLoadID` is the label and the id, and a new policy that got the deleted one's id has its label too when both kept the default name). Records saved before that held the policy ids, which are looked up once on load.
|
||||||
- Former-caste records are pruned on save, after load and in the 2500-tick sweep when they are older than `formerCasteDays` or their caste is gone. Deleting a caste drops its records at once.
|
- Former-caste records are pruned on save, after load and in the 2500-tick sweep when they are older than `formerCasteDays` or their caste is gone. Deleting a caste drops its records at once.
|
||||||
- Removing the mod: pawns keep their last policies. The next load logs two red errors for the component: "Could not find class BlaxCastes.GameComponent_BlaxCastes" and "SaveableFromNode exception: Can't load abstract class Verse.GameComponent" (`ScribeExtractor.SaveableFromNode`). Both go away once the game is saved again.
|
- Removing the mod: pawns keep their last policies. The next load logs two red errors for the component: "Could not find class BlaxCastes.GameComponent_BlaxCastes" and "SaveableFromNode exception: Can't load abstract class Verse.GameComponent" (`ScribeExtractor.SaveableFromNode`). Both go away once the game is saved again.
|
||||||
- Adding it mid-save: `Game.ExposeData` creates the component. The starter castes are seeded once on `LoadedGame`.
|
- Adding it mid-save: `Game.ExposeData` creates the component. The starter castes are seeded once on `LoadedGame`.
|
||||||
|
|
@ -110,7 +110,7 @@ Moved to 1.1 to keep 1.0 near a week: starter castes, overlap warnings, the poli
|
||||||
- Menu: No caste (stored as casteless by choice), each caste, Reset to caste, Edit caste.
|
- Menu: No caste (stored as casteless by choice), each caste, Reset to caste, Edit caste.
|
||||||
- `Compare` sorts by caste label, casteless last. Width 100 to 160 px. Header buttons "Manage castes" and "Defaults" sit in the same 65 px area as the outfit column's.
|
- `Compare` sorts by caste label, casteless last. Width 100 to 160 px. Header buttons "Manage castes" and "Defaults" sit in the same 65 px area as the outfit column's.
|
||||||
- The Assign tab never lists prisoners. In 1.0 prisoners join castes only through the "New prisoner" row. The gizmo adds a manual path in 1.1.
|
- The Assign tab never lists prisoners. In 1.0 prisoners join castes only through the "New prisoner" row. The gizmo adds a manual path in 1.1.
|
||||||
- **Settings:** `showAssignColumn` (on). The column is removed from the table def at startup, so a change needs a restart. Since the 1.0 additions the setting covers the Caste column in all three tables (Assign, Schedule, Work); `CasteColumns.cs` handles them.
|
- **Settings:** `showAssignColumn` (on). The column is removed from the table def at startup, so a change needs a restart. Since the 1.0 additions the setting covers the Caste column in all three tables (Assign, Schedule, Work); `CasteColumns.cs` handles them. Messages that point to the column (the first-load and seeding messages) ask whether the column is in the Assign table (`CasteColumns.Shown`), not the setting, so a change waiting for the restart never sends the player to a button that is not there yet.
|
||||||
- **Replaces:** none.
|
- **Replaces:** none.
|
||||||
- **Effort:** S (0.5 days).
|
- **Effort:** S (0.5 days).
|
||||||
- **Tests:** At startup the Assign table def has `BlaxCastes_Caste` right before `HostilityResponse`, with and without the Ideology and Biotech columns (`run-tests.ps1 -NoDlc` runs the suite on the core game). The menu has No caste, one entry per caste and Reset, and invoking an entry assigns. Painting over a member of the same caste keeps its override. Drawing is checked by hand, since headless runs have no GUI.
|
- **Tests:** At startup the Assign table def has `BlaxCastes_Caste` right before `HostilityResponse`, with and without the Ideology and Biotech columns (`run-tests.ps1 -NoDlc` runs the suite on the core game). The menu has No caste, one entry per caste and Reset, and invoking an entry assigns. Painting over a member of the same caste keeps its override. Drawing is checked by hand, since headless runs have no GUI.
|
||||||
|
|
@ -127,7 +127,7 @@ Moved to 1.1 to keep 1.0 near a week: starter castes, overlap warnings, the poli
|
||||||
- A caste (or No caste) picked by hand between queue and apply beats the row. Each queued join remembers the membership object the pawn had when it was last queued; a different manual membership at apply time is a pick. After a load that reference is gone, and a manual membership set on or after the queueing tick counts instead.
|
- A caste (or No caste) picked by hand between queue and apply beats the row. Each queued join remembers the membership object the pawn had when it was last queued; a different manual membership at apply time is a pick. After a load that reference is gone, and a manual membership set on or after the queueing tick counts instead.
|
||||||
- Selling: a "sold" scope on `Pawn.PreTraded` with PlayerSells keeps the slave-to-free step inside the sale (`SetGuestStatus(null)` before `SetFaction(null)`) from queueing a join.
|
- Selling: a "sold" scope on `Pawn.PreTraded` with PlayerSells keeps the slave-to-free step inside the sale (`SetGuestStatus(null)` before `SetFaction(null)`) from queueing a join.
|
||||||
- If the row is No caste and a join row had put the pawn in its caste (membership auto), it leaves the caste. With `revertOnLeave`, each managed slot where the pawn still has the caste's value returns to the database default; medical care runs `ResetMedicalCare` only if the caste manages it and the pawn still has the caste's value. Slots changed by hand stay. This is PrisonerDefaults' revert on recruit. A caste picked by hand is never removed by a No caste row. The schedule, work priorities and loadout have no database default and are not reverted. Since the 1.0 additions the same revert runs when a row moves a row-set member to another caste, for the slots the new caste leaves alone.
|
- If the row is No caste and a join row had put the pawn in its caste (membership auto), it leaves the caste. With `revertOnLeave`, each managed slot where the pawn still has the caste's value returns to the database default; medical care runs `ResetMedicalCare` only if the caste manages it and the pawn still has the caste's value. Slots changed by hand stay. This is PrisonerDefaults' revert on recruit. A caste picked by hand is never removed by a No caste row. The schedule, work priorities and loadout have no database default and are not reverted. Since the 1.0 additions the same revert runs when a row moves a row-set member to another caste, for the slots the new caste leaves alone.
|
||||||
- Leaving the player faction, for example by being sold, ends the membership.
|
- Leaving the player faction, for example by being sold, ends the membership. Leaving the map is judged as a whole (see "Status changes and the old caste").
|
||||||
- Babies and quest lodgers are skipped until 1.3.
|
- Babies and quest lodgers are skipped until 1.3.
|
||||||
- **Settings:** `enableJoinDefaults` (on), `joinMessages` (on), `revertOnLeave` (on; only governs the revert when a row takes a pawn out of a row-set caste).
|
- **Settings:** `enableJoinDefaults` (on), `joinMessages` (on), `revertOnLeave` (on; only governs the revert when a row takes a pawn out of a row-set caste).
|
||||||
- **Replaces:** Automatic Slave Outfit (2912063732, 16,672 subs). PrisonerDefaults (3531556159, 1,086 subs). The join defaults of Better Pawn Control (1541460369, 227,665 subs), Better Pawn Control Forked (3724294345, 1,308 subs) and 1trickPwnyta's Defaults (3285178686, 75,424 subs).
|
- **Replaces:** Automatic Slave Outfit (2912063732, 16,672 subs). PrisonerDefaults (3531556159, 1,086 subs). The join defaults of Better Pawn Control (1541460369, 227,665 subs), Better Pawn Control Forked (3724294345, 1,308 subs) and 1trickPwnyta's Defaults (3285178686, 75,424 subs).
|
||||||
|
|
@ -156,11 +156,11 @@ Moved to 1.1 to keep 1.0 near a week: starter castes, overlap warnings, the poli
|
||||||
- The caste column is also added to `PawnTableDef` Restrict (the Schedule tab), right after the timetable column (see Built).
|
- The caste column is also added to `PawnTableDef` Restrict (the Schedule tab), right after the timetable column (see Built).
|
||||||
- **Settings:** covered by `enabled`.
|
- **Settings:** covered by `enabled`.
|
||||||
- **Replaces:** default schedules in 1trickPwnyta's Defaults (75k) and Better Pawn Control (228k).
|
- **Replaces:** default schedules in 1trickPwnyta's Defaults (75k) and Better Pawn Control (228k).
|
||||||
- **Tests:** a caste with a night schedule sets all 24 hours on a colonist and a slave; a prisoner skips it without errors; Follow rule (A follows, B with one hour changed keeps its own); an unknown defName becomes Anything; the schedule survives save and reload.
|
- **Tests:** a caste with a night schedule sets all 24 hours on a colonist and a slave; a prisoner skips it without errors; Follow rule (A follows, B with one hour changed keeps its own); an unknown defName becomes Anything; the schedule survives save and reload; the manager's grid paints only after a press that started on it.
|
||||||
- **Built (2026-11-29),** `ScheduleSlot.cs`:
|
- **Built (2026-11-29),** `ScheduleSlot.cs`:
|
||||||
- Checks: a timetable, not a quest lodger, not a prisoner (an arrested colonist keeps its timetable and is still skipped), not a mutant without policies, and not `IsSubhuman` (the vanilla Schedule tab leaves those out).
|
- Checks: a timetable, not a quest lodger, not a prisoner (an arrested colonist keeps its timetable and is still skipped), not a mutant without policies, and not `IsSubhuman` (the vanilla Schedule tab leaves those out).
|
||||||
- Unknown names become Anything three times over: `SetSlot` stores Anything, Apply resolves an unknown stored name to Anything, and `CheckSlots` rewrites it after a load with one warning. Without Royalty the Meditate def does not exist, so it resolves the same way.
|
- Unknown names become Anything three times over: `SetSlot` stores Anything, Apply resolves an unknown stored name to Anything, and `CheckSlots` rewrites it after a load with one warning. Without Royalty the Meditate def does not exist, so it resolves the same way.
|
||||||
- Manager: the selector is vanilla's `TimeAssignmentSelector.DrawTimeAssignmentSelectorGrid`, so the brush is shared with the Schedule tab. Painting copies `PawnColumnWorker_Timetable` (mouse button held over a cell). "Unmanaged" is the "Leave alone" button, the word the other rows use. While unmanaged the cells show the game's starting schedule faded; painting one hour starts from it and, the slot having no old value, gives every member the whole day (the unmanaged tooltip and the manager hint say so, and "Copy from pawn" says the same). Each painted hour is one `SetSlot`, so followers follow hour by hour.
|
- Manager: the selector is vanilla's `TimeAssignmentSelector.DrawTimeAssignmentSelectorGrid`, so the brush is shared with the Schedule tab. Painting copies `PawnColumnWorker_Timetable` (mouse button held over a cell), with one change: the grid ends where the scroll view's scrollbar starts, so painting needs a press that started on the grid (`Dialog_ManageCastes.SchedulePaintAllowed`). Without it, dragging the scrollbar with the cursor a pixel or two onto the grid painted the last hours. "Unmanaged" is the "Leave alone" button, the word the other rows use. While unmanaged the cells show the game's starting schedule faded; painting one hour starts from it and, the slot having no old value, gives every member the whole day (the unmanaged tooltip and the manager hint say so, and "Copy from pawn" says the same). Each painted hour is one `SetSlot`, so followers follow hour by hour.
|
||||||
- The column goes right after the timetable (`CasteColumns.ApplyToSchedule`, Patches/BlaxCastes_ScheduleWork.xml). The Schedule tab has no extra top space, so its header starts at y 0, and `MainTabWindow_Schedule` draws the time assignment selector at (0, 0, 191, 65) after the table: one row of brushes 95.5 px wide at y 2 to 29.5, reaching x 476 with Royalty. The brushes draw on top of the header, and the header's buttons take the click first, so a column with header buttons anywhere left of x 476 steals the brush clicks. Everything left of the timetable is narrower than that (name 80 px or more, ideo, xenotype, copy and paste 36), and the timetable is at least 360 px, so right of it the column is always clear. The copy and paste buttons still sit next to the timetable.
|
- The column goes right after the timetable (`CasteColumns.ApplyToSchedule`, Patches/BlaxCastes_ScheduleWork.xml). The Schedule tab has no extra top space, so its header starts at y 0, and `MainTabWindow_Schedule` draws the time assignment selector at (0, 0, 191, 65) after the table: one row of brushes 95.5 px wide at y 2 to 29.5, reaching x 476 with Royalty. The brushes draw on top of the header, and the header's buttons take the click first, so a column with header buttons anywhere left of x 476 steals the brush clicks. Everything left of the timetable is narrower than that (name 80 px or more, ideo, xenotype, copy and paste 36), and the timetable is at least 360 px, so right of it the column is always clear. The copy and paste buttons still sit next to the timetable.
|
||||||
- The brushes in the manager share the row's width (four, five with Royalty), 64 to 96 px each; at the window's starting size that is about 91 px, about what the Schedule tab gives them. At 64 px "Recreation" does not fit the Small font.
|
- The brushes in the manager share the row's width (four, five with Royalty), 64 to 96 px each; at the window's starting size that is about 91 px, about what the Schedule tab gives them. At 64 px "Recreation" does not fit the Small font.
|
||||||
|
|
||||||
|
|
@ -175,13 +175,13 @@ Moved to 1.1 to keep 1.0 near a week: starter castes, overlap warnings, the poli
|
||||||
- The caste column is also added to `PawnTableDef` Work, before the work columns.
|
- The caste column is also added to `PawnTableDef` Work, before the work columns.
|
||||||
- **Settings:** `manageWorkPriorities` (on). The row is greyed out with a note when Work Tab, Free Will, Work Manager, AutoPriorities or WorkRoles is active (packageIds checked before shipping), because they reset priorities all the time.
|
- **Settings:** `manageWorkPriorities` (on). The row is greyed out with a note when Work Tab, Free Will, Work Manager, AutoPriorities or WorkRoles is active (packageIds checked before shipping), because they reset priorities all the time.
|
||||||
- **Replaces:** default work priorities in 1trickPwnyta's Defaults (75k) and Plug and Play Joiner (1.5k).
|
- **Replaces:** default work priorities in 1trickPwnyta's Defaults (75k) and Plug and Play Joiner (1.5k).
|
||||||
- **Tests:** a slave in a caste with Growing 1 and Firefighting 1 has both, other types unchanged; a disabled work type stays 0 with no log error; "Start from nothing" leaves only the caste's types, plus Patient and Bed rest as they were; with manual priorities off, nonzero becomes on and turning them on detaches nobody; clicking the cycle button through other values moves only the members that followed before the first click; Follow rule per type; survives save and reload.
|
- **Tests:** a slave in a caste with Growing 1 and Firefighting 1 has both, other types unchanged; a disabled work type stays 0 with no log error; "Start from nothing" leaves only the caste's types, plus Patient and Bed rest as they were; with manual priorities off, nonzero becomes on and turning them on detaches nobody; clicking the cycle button through other values moves only the members that followed before the first click, and pawns "Assign by status" puts into the caste during the run follow its next clicks; Follow rule per type; survives save and reload.
|
||||||
- **Risks:** automatic work managers fight any fixed priorities, hence the detection.
|
- **Risks:** automatic work managers fight any fixed priorities, hence the detection.
|
||||||
- **Built (2026-11-29),** `WorkSlot.cs`:
|
- **Built (2026-11-29),** `WorkSlot.cs`:
|
||||||
- Colonists and slaves of the player with initialized work settings; prisoners and quest lodgers are skipped.
|
- Colonists and slaves of the player with initialized work settings; prisoners and quest lodgers are skipped.
|
||||||
- The slot is managed while at least one work type is listed. "Start from nothing" needs a listed type, takes effect on the next assign, Reset to caste or Apply to all members, and moves nobody when ticked. The Follow rule never turns work off; only a full apply does.
|
- The slot is managed while at least one work type is listed. "Start from nothing" needs a listed type, takes effect on the next assign, Reset to caste or Apply to all members, and moves nobody when ticked. The Follow rule never turns work off; only a full apply does.
|
||||||
- "Start from nothing" keeps the self-care work types (`WorkSlot.IsSelfCare`: `alwaysStartActive` and no work tags, which in the base game are Patient and Bed rest) as they are. A colonist or slave goes to bed for treatment or rest only through their work givers (`PatientGoToBedEmergencyTreatment`, `PatientGoToBedTreatment`, `PatientGoToBedRecuperate`); the `JobGiver_PatientGoToBed` think nodes cover prisoners, guests and crawling downed pawns only. Firefighting, Hauling and Cleaning are also `alwaysStartActive` but carry work tags, so they are turned off unless listed; the tooltip names the kept types and suggests listing Firefighting. Types are turned off one by one with `SetPriority(0)`, which also stops a job of that type.
|
- "Start from nothing" keeps the self-care work types (`WorkSlot.IsSelfCare`: `alwaysStartActive` and no work tags, which in the base game are Patient and Bed rest) as they are. A colonist or slave goes to bed for treatment or rest only through their work givers (`PatientGoToBedEmergencyTreatment`, `PatientGoToBedTreatment`, `PatientGoToBedRecuperate`); the `JobGiver_PatientGoToBed` think nodes cover prisoners, guests and crawling downed pawns only. Firefighting, Hauling and Cleaning are also `alwaysStartActive` but carry work tags, so they are turned off unless listed; the tooltip names the kept types and suggests listing Firefighting. Types are turned off one by one with `SetPriority(0)`, which also stops a job of that type.
|
||||||
- The cycle button works in runs (`Dialog_ManageCastes.WorkCycle`, one per window): the first click on a type takes its followers (`CasteManager.WorkFollowers`: members on the caste's value, or every member while the caste leaves the type alone), and every later click on the same type moves only them (`CasteManager.SetWorkPriority` with followers). Without that, each step would be a Follow rule step from the previous value: going 3, 4, off, leave alone, 1 picks up a pawn set to 4 by hand at the first step and every member at the leave-alone step. A click on another type or caste, a change to the type from anywhere else, "Apply to all members" or a new window starts a new run.
|
- The cycle button works in runs (`Dialog_ManageCastes.WorkCycle`, one per window): the first click on a type takes its followers (`CasteManager.WorkFollowers`: members on the caste's value, or every member while the caste leaves the type alone), and every later click on the same type moves only them (`CasteManager.SetWorkPriority` with followers). Without that, each step would be a Follow rule step from the previous value: going 3, 4, off, leave alone, 1 picks up a pawn set to 4 by hand at the first step and every member at the leave-alone step. A click on another type or caste, a change to the type from anywhere else, "Apply to all members" or a new window starts a new run. "Assign by status" does not end the run: the pawns it puts into the run's caste start on the caste's current value, so they join the run's followers (`WorkCycle.AddJoined`). Ending the run instead would let the next click take followers by value again and pick up a member set by hand to that value.
|
||||||
- Comparisons (Follow rule, overrides) use the priority as the game treats it: with manual priorities off, every nonzero value counts as on, so a caste value 1 and a pawn on 3 match. A work type the pawn cannot do never counts as an override.
|
- Comparisons (Follow rule, overrides) use the priority as the game treats it: with manual priorities off, every nonzero value counts as on, so a caste value 1 and a pawn on 3 match. A work type the pawn cannot do never counts as an override.
|
||||||
- Greyed out means off: while `manageWorkPriorities` is off or a work manager is active, nothing is written and work never counts as an override. The caste keeps its values. The manager shows the reason; the settings page names the active work manager.
|
- Greyed out means off: while `manageWorkPriorities` is off or a work manager is active, nothing is written and work never counts as an override. The caste keeps its values. The manager shows the reason; the settings page names the active work manager.
|
||||||
- The manager lists the visible work types in the Work tab's order (`WorkTypeDefsInPriorityOrder`), three columns, each with a cycle button (left click; the cycle wraps). The tooltip shows the work type's description.
|
- The manager lists the visible work types in the Work tab's order (`WorkTypeDefsInPriorityOrder`), three columns, each with a cycle button (left click; the cycle wraps). The tooltip shows the work type's description.
|
||||||
|
|
@ -194,11 +194,11 @@ Moved to 1.1 to keep 1.0 near a week: starter castes, overlap warnings, the poli
|
||||||
- **How:** Bound by reflection through the API Weapons Tab Reborn publishes for Better Pawn Control (`BPC_GetLoadoutId`, `BPC_SetLoadoutId`, `BPC_GetDefaultLoadoutId`, `BPC_GetLoadoutNamebyId`, the loadout database). The slot stores the loadout id; a missing id becomes unmanaged with one warning, like a missing policy. Detection by packageId `papercrane1001.weaponstab` (check the About.xml before shipping). Applied to colonists and slaves only. Follow rule as for policies. Any failure in the reflection disables the slot with one log line, never an exception.
|
- **How:** Bound by reflection through the API Weapons Tab Reborn publishes for Better Pawn Control (`BPC_GetLoadoutId`, `BPC_SetLoadoutId`, `BPC_GetDefaultLoadoutId`, `BPC_GetLoadoutNamebyId`, the loadout database). The slot stores the loadout id; a missing id becomes unmanaged with one warning, like a missing policy. Detection by packageId `papercrane1001.weaponstab` (check the About.xml before shipping). Applied to colonists and slaves only. Follow rule as for policies. Any failure in the reflection disables the slot with one log line, never an exception.
|
||||||
- **Settings:** `manageWeaponLoadout` (on).
|
- **Settings:** `manageWeaponLoadout` (on).
|
||||||
- **Replaces:** nothing; it removes the per-pawn loadout clicks.
|
- **Replaces:** nothing; it removes the per-pawn loadout clicks.
|
||||||
- **Tests:** skip without Weapons Tab Reborn. With it (a -Compat run): a caste with a loadout sets it on a colonist; Follow rule; a deleted loadout becomes unmanaged without errors.
|
- **Tests:** skip without Weapons Tab Reborn. With it (a -Compat run): a caste with a loadout sets it on a colonist; Follow rule; a deleted loadout becomes unmanaged without errors; with the mod's loadout database missing (a save made without it) the database is created and nothing turns off or is unmanaged; a call that fails turns the slot off and is not read as a deleted loadout.
|
||||||
- **Risks:** Weapons Tab Reborn has no 1.7 build and loads its 1.6 assembly. If its API changes or fails, the slot turns itself off.
|
- **Risks:** Weapons Tab Reborn has no 1.7 build and loads its 1.6 assembly. If its API changes or fails, the slot turns itself off.
|
||||||
- **Built (2026-11-29),** `WeaponsTab.cs`:
|
- **Built (2026-11-29),** `WeaponsTab.cs`:
|
||||||
- packageId `papercrane1001.WeaponsTab`, read from the installed Workshop copy's About.xml (2573988660); `Compat.IsActive` ignores case. The API sits in `WeaponsTabReborn.LoadoutDictionary`, read from its 1.6 assembly's metadata: `int BPC_GetLoadoutId(Pawn)`, `void BPC_SetLoadoutId(Pawn, int)`, `int BPC_GetDefaultLoadoutId()`, `string BPC_GetLoadoutNamebyId(int)`, `Dictionary<string, int> BPC_GetWeaponsLoadoutsDatabase()`. Bound once into typed delegates; a missing type or method turns the slot off for the session, a call that throws (anything but a missing id) turns it off until the next game is loaded. Each logs one warning.
|
- packageId `papercrane1001.WeaponsTab`, read from the installed Workshop copy's About.xml (2573988660); `Compat.IsActive` ignores case. The API sits in `WeaponsTabReborn.LoadoutDictionary`, read from its 1.6 assembly's metadata: `int BPC_GetLoadoutId(Pawn)`, `void BPC_SetLoadoutId(Pawn, int)`, `int BPC_GetDefaultLoadoutId()`, `string BPC_GetLoadoutNamebyId(int)`, `Dictionary<string, int> BPC_GetWeaponsLoadoutsDatabase()`. Bound once into typed delegates; a missing type or method turns the slot off for the session, a call that throws (anything but a missing id) turns it off until the next game is loaded. Each logs one warning. The load check tests the id first and the slot's availability after, so a call that fails inside the check is never read as a deleted loadout.
|
||||||
- Quirks Castes works around: `BPC_SetLoadoutId` with an unknown id clears the pawn's loadout, so the id is checked first. `BPC_GetLoadoutNamebyId` throws `InvalidOperationException` for an unknown id; that is how existence is checked. The database dictionary is static and only grows (deleted and renamed loadouts stay, and a new loadout whose label is already a key is left out), so the manager's list checks every id by name and also probes the 16 ids above the highest one. Loadout ids are the highest id plus one, so deleting the newest loadout frees its id for the next one; a caste still holding that id then points at the new loadout.
|
- Quirks Castes works around: `BPC_SetLoadoutId` with an unknown id clears the pawn's loadout, so the id is checked first. `BPC_GetLoadoutNamebyId` throws `InvalidOperationException` for an unknown id; that is how existence is checked. The database dictionary is static and only grows (deleted and renamed loadouts stay, and a new loadout whose label is already a key is left out), so the manager's list checks every id by name and also probes the 16 ids above the highest one. Loadout ids are the highest id plus one, so deleting the newest loadout frees its id for the next one; a caste still holding that id then points at the new loadout. The loadout database (`LoadoutDictionary.CurrentLoadoutDatabase`) is null after loading a save that has none (the mod added mid-save, or a save made without it) until the mod's own tab or job giver runs: its `Game.ExposeSmallComponents` prefix loads the field with `Scribe_Deep`, which sets null for a missing node. The BPC methods read the field directly and throw then; the mod's own code goes through the public `GetCurrentLoadoutDatabase()`, which creates the database. Castes calls that method before every API call, so the load check, the managed box and the dropdown work at once.
|
||||||
- Colonists and slaves of the player only. Without the mod, `SetSlot` refuses a loadout and a stored id is kept (not checked, not applied) for when the mod comes back.
|
- Colonists and slaves of the player only. Without the mod, `SetSlot` refuses a loadout and a stored id is kept (not checked, not applied) for when the mod comes back.
|
||||||
- Weapons Tab Reborn's own default loadout (Overlap warnings below) is explained in the setting's tooltip, not as an overlap warning: it is the mod this slot works with.
|
- Weapons Tab Reborn's own default loadout (Overlap warnings below) is explained in the setting's tooltip, not as an overlap warning: it is the mod this slot works with.
|
||||||
- Weapons Tab Reborn's job giver runs for every humanlike and logs "Non-colonist X tried to equip loadout." once for the first pawn of another faction that thinks. That is its own bug; the test harness lists it as a known foreign error (`KnownForeignErrors`), so it shows as a LOGERR line and does not fail the test that ticked the game.
|
- Weapons Tab Reborn's job giver runs for every humanlike and logs "Non-colonist X tried to equip loadout." once for the first pawn of another faction that thinks. That is its own bug; the test harness lists it as a known foreign error (`KnownForeignErrors`), so it shows as a LOGERR line and does not fail the test that ticked the game.
|
||||||
|
|
@ -213,22 +213,22 @@ Moved to 1.1 to keep 1.0 near a week: starter castes, overlap warnings, the poli
|
||||||
- Seeding writes the component directly (raw slot writes, no members yet), so it works on a component that is not the game's, which is how the tests check the load path.
|
- Seeding writes the component directly (raw slot writes, no members yet), so it works on a component that is not the game's, which is how the tests check the load path.
|
||||||
- A missed policy logs one line and its slot stays unmanaged. "Create Slave outfit" in the manager, shown while the caste's apparel is unmanaged and the game has no Slave outfit, makes one the way a new game does (apparel tagged for slaves, no deadman's apparel) and sets it on that caste. A caste with the Slave outfit warns about cold in the manager and in the column tooltip.
|
- A missed policy logs one line and its slot stays unmanaged. "Create Slave outfit" in the manager, shown while the caste's apparel is unmanaged and the game has no Slave outfit, makes one the way a new game does (apparel tagged for slaves, no deadman's apparel) and sets it on that caste. A caste with the Slave outfit warns about cold in the manager and in the column tooltip.
|
||||||
- "Assign by status" takes player colonists, slaves and prisoners (maps, caravans, transporters) that can join a caste, have no membership record, are not queued, and whose status row resolves to a caste. The button shows the count and only appears while there are such pawns. It asks first (`Dialog_MessageBox`, like "Apply to all members"): in an existing save the Colonist caste's default policies replace each colonist's own outfit, food, drug and reading policy, and nothing can undo that. A new game runs it without asking, since nothing is lost there.
|
- "Assign by status" takes player colonists, slaves and prisoners (maps, caravans, transporters) that can join a caste, have no membership record, are not queued, and whose status row resolves to a caste. The button shows the count and only appears while there are such pawns. It asks first (`Dialog_MessageBox`, like "Apply to all members"): in an existing save the Colonist caste's default policies replace each colonist's own outfit, food, drug and reading policy, and nothing can undo that. A new game runs it without asking, since nothing is lost there.
|
||||||
- While the Caste column is off, the seeding message points to the mod settings (whose buttons open the same windows) instead of Assign > Manage castes. "Apply to all members" writes every managed slot to every live member after a `Dialog_MessageBox` confirm naming the caste and the count.
|
- While the game runs without the Caste column (the setting it started with), the seeding message points to the mod settings (whose buttons open the same windows) instead of Assign > Manage castes. "Apply to all members" writes every managed slot to every live member after a `Dialog_MessageBox` confirm naming the caste and the count.
|
||||||
|
|
||||||
#### Status changes and the old caste
|
#### Status changes and the old caste
|
||||||
|
|
||||||
- Every transition between player colonist, player slave and player prisoner already goes through the status rows (new colonist, new slave, new prisoner). Freeing a slave lands in the new-colonist row, arresting a colonist in new prisoner, releasing back in new colonist.
|
- Every transition between player colonist, player slave and player prisoner already goes through the status rows (new colonist, new slave, new prisoner). Freeing a slave lands in the new-colonist row, arresting a colonist in new prisoner, releasing back in new colonist.
|
||||||
- Previous caste from 1.3, pulled forward: when a member leaves the player side, is sold or becomes a prisoner, Castes writes a former-caste record (caste id, status class, tick), keyed by ThingID. If the pawn comes back within `formerCasteDays` (60) with the same status class (colonist or slave), it gets that caste back instead of the row's, and keeps its hand changes (see How). A pawn set to No caste comes back to No caste. An arrested colonist who is then enslaved goes to the slave row. Order at apply time: previous caste, then the row.
|
- Previous caste from 1.3, pulled forward: when a member leaves the player side, is sold or becomes a prisoner, Castes writes a former-caste record (caste id, status class, tick), keyed by ThingID. If the pawn comes back within `formerCasteDays` (60) with the same status class (colonist or slave), it gets that caste back instead of the row's, and keeps its hand changes (see How). A pawn set to No caste comes back to No caste. An arrested colonist who is then enslaved goes to the slave row. Order at apply time: previous caste, then the row.
|
||||||
- **How (built 2026-11-29):**
|
- **How (built 2026-11-29):**
|
||||||
- Arresting a colonist and imprisoning a slave both run `Pawn_GuestTracker.CapturedBy(Faction.OfPlayer)` (the arrest job). Imprisoning a slave sets the pawn back to its slave faction inside `SetGuestStatus`, so the nested `SetFaction` notes it as leaving and the outer call queues it as a new prisoner. Releasing an arrested colonist ends in `SetGuestStatus(null)`, and so does freeing a slave whose home is the colony (`SlaveRelease`); both land in new colonist. A freed slave from another faction walks off and leaves when it exits the map.
|
- Arresting a colonist and imprisoning a slave both run `Pawn_GuestTracker.CapturedBy(Faction.OfPlayer)` (the arrest job). Imprisoning a slave sets the pawn back to its slave faction inside `SetGuestStatus`, so the nested `SetFaction` notes it as leaving and the outer call queues it as a new prisoner. Releasing an arrested colonist ends in `SetGuestStatus(null)`, and so does freeing a slave whose home is the colony (`SlaveRelease`); both land in new colonist. A freed slave from another faction walks off as a slave of the colony: at the map edge `Pawn.ExitMap` sets it free (`SetGuestStatus(null)`, a colonist for a moment), and `WorldPawns.PassToWorld` then moves it to another faction (`Pawn.Notify_PassedToWorld` does that for every player pawn that becomes a free world pawn). So a prefix and finalizer on `Pawn.ExitMap`, and on `MapDeiniter.PassPawnsToWorld` (a closing map sets its slaves free the same way), open a Leaving scope: status changes inside it queue and note nothing, and the finalizer compares the status before the departure with the status after it (`JoinHooks.AfterLeaving`). A freed or escaped slave therefore leaves with a slave record, never as a colonist who joined. Caravans, transport pods, shuttles, kidnapping and teleporting keep the pawn in the faction, so nothing changes and it keeps its 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 until the game reuses it; a freed slave a quest holds stays in the faction) leaves its caste at once, since nothing would end the membership later.
|
||||||
- The join hooks write the record when the status before the change was colonist or slave and the status after it is none or prisoner. Inside a sale nothing is written by the hooks; the `PreTraded` finalizer writes the record with the status the pawn had before the sale, once it is no longer player-side. A pawn set to No caste writes a No caste record; a pawn with no membership record writes none, so a status change moves it by its row.
|
- The join hooks write the record when the status before the change was colonist or slave and the status after it is none or prisoner. Inside a sale nothing is written by the hooks; the `PreTraded` finalizer writes the record with the status the pawn had before the sale, once it is no longer player-side. A pawn set to No caste writes a No caste record; a pawn with no membership record writes none, so a status change moves it by its row.
|
||||||
- The record is taken in the hook prefixes (`JoinHooks.Before`, the `PreTraded` prefix), before the game resets medical care inside the change, and written by the postfix or finalizer. Besides the caste id it holds the pawn's own settings: policies by id, medical care, the 24 hours, every work type's priority (as the game reads it), the loadout id, and which of the caste's managed slots and decided work types the pawn followed then.
|
- The record is taken in the hook prefixes (`JoinHooks.Before`, the `PreTraded` prefix), before the game resets medical care inside the change, and written by the postfix or finalizer. Besides the caste id it holds the pawn's own settings: policies (as references, see Save safety), medical care, the 24 hours, every work type's priority (as the game reads it), the loadout id, which of the caste's managed slots and decided work types the pawn followed then, and which slots the caste managed and which work types it listed then.
|
||||||
- Getting the caste back (`JoinDefaults.Restore`, `CasteUtility.Restore`) is not a full apply, because the game keeps policies, schedule and loadout through an arrest or a sale (it adds missing trackers and never removes them) and resets only medical care and, when the pawn joins the faction again, work priorities. A slot the caste manages gets the caste's current value if the pawn followed it when it left (so edits made while it was away reach it), else the pawn's own value from then. A slot the caste leaves alone is written only to undo the caste the pawn got while away: if that caste manages it and the pawn still has its value (the new-prisoner caste's food), the pawn gets its own value back. Values already in place are not written. A pawn that never left its caste (No caste rows) therefore gets nothing rewritten, and a pawn set to No caste goes back to No caste with its own food. Work goes type by type over the types either caste decides ("Start from nothing" decides every type but the self-care ones, at off).
|
- Getting the caste back (`JoinDefaults.Restore`, `CasteUtility.Restore`) is not a full apply, because the game keeps policies, schedule and loadout through an arrest or a sale (it adds missing trackers and never removes them) and resets only medical care and, when the pawn joins the faction again, work priorities. A slot the caste manages gets the caste's current value if the pawn followed it when it left (so edits made while it was away reach it) or if the caste did not manage it then (the Follow rule gives a slot that becomes managed to every member), else the pawn's own value from then. A work type the caste lists now but did not list then gets the caste's value the same way; a type only "Start from nothing" decides keeps the pawn's own value unless it followed it, since ticking "Start from nothing" moves nobody. A record saved before the managed slots were kept counts every slot and type as managed then, so the pawn keeps its own values, as it did before. A slot the caste leaves alone is written only to undo the caste the pawn got while away: if that caste manages it and the pawn still has its value (the new-prisoner caste's food), the pawn gets its own value back. Values already in place are not written. A pawn that never left its caste (No caste rows) therefore gets nothing rewritten, and a pawn set to No caste goes back to No caste with its own food. Work goes type by type over the types either caste decides ("Start from nothing" decides every type but the self-care ones, at off).
|
||||||
- A row that moves a pawn from a row-set caste to another caste resets, with `revertOnLeave`, the policies the old caste manages and the new one leaves alone, where the pawn still has the old value, as a No caste row does. This covers the plain row path; the previous-caste path undoes with the pawn's own values instead of the database defaults.
|
- A row that moves a pawn from a row-set caste to another caste resets, with `revertOnLeave`, the policies the old caste manages and the new one leaves alone, where the pawn still has the old value, as a No caste row does. This covers the plain row path; the previous-caste path undoes with the pawn's own values instead of the database defaults.
|
||||||
- A record stores the caste id (not a reference), the status, the membership's auto flag and the tick. It is restored with that auto flag and the reason "previousCaste", and removed when used. A record whose status does not match stays until it is pruned, so a colonist arrested, enslaved and later freed within the window still comes back to its colonist caste.
|
- A record stores the caste id (not a reference), the status, the membership's auto flag and the tick. It is restored with that auto flag and the reason "previousCaste", and removed when used. A record whose status does not match stays until it is pruned, so a colonist arrested, enslaved and later freed within the window still comes back to its colonist caste.
|
||||||
- Order at apply time: a hand pick after queueing, then the previous caste, then the row.
|
- Order at apply time: a hand pick after queueing, then the previous caste, then the row.
|
||||||
- **Settings:** `returnToPreviousCaste` (on), `formerCasteDays` (60, 1 to 120). Records are written even while the setting is off, so turning it on later works.
|
- **Settings:** `returnToPreviousCaste` (on), `formerCasteDays` (60, 1 to 120). Records are written even while the setting is off, so turning it on later works.
|
||||||
- **Tests:** a Miner colonist arrested and released returns to Miner; a Miner slave sold and re-bought returns to Miner slave; an arrested colonist who is enslaved goes to the slave row; a record older than `formerCasteDays` is ignored and pruned; records survive save and reload, with the pawn's own settings. An arrested and released colonist keeps its hand-set outfit, drugs, medical care and schedule hour, and a followed slot gets the caste's new value; a pawn that never left its caste (No caste rows) gets nothing rewritten; a No caste pawn comes back to No caste with its own food; the prisoner caste's food is undone for a caste that leaves food alone; a row move from a row-set caste resets the old caste's food. Plus one test per transition the harness can drive: arrest, release, freeing a home slave, imprisoning a slave, enslaving after an arrest, selling and buying back; recruiting, enslaving and capturing are in the join tests.
|
- **Tests:** a Miner colonist arrested and released returns to Miner; a Miner slave sold and re-bought returns to Miner slave; an arrested colonist who is enslaved goes to the slave row; a record older than `formerCasteDays` is ignored and pruned; records survive save and reload, with the pawn's own settings. An arrested and released colonist keeps its hand-set outfit, drugs, medical care and schedule hour, and a followed slot gets the caste's new value; a pawn that never left its caste (No caste rows) gets nothing rewritten; a No caste pawn comes back to No caste with its own food; the prisoner caste's food is undone for a caste that leaves food alone; a row move from a row-set caste resets the old caste's food; a slot and a work type the caste starts managing while the pawn is away reach it, and an older record without the managed slots keeps the pawn's own; a hand-set policy deleted while the pawn is away is skipped even when a new policy got its id, and a record whose policy was deleted before the save loads without that policy and without errors or warnings, even when a new policy got its id and label (the same load ID). Leaving the map: a freed slave from another faction that walks off, an escaped slave and an escaped prisoner leave their caste (the slaves with a slave record) and nothing is queued; a colonist in a caravan or kidnapped keeps its caste; a slave on a closing map leaves with a slave record (the hook around `MapDeiniter.PassPawnsToWorld`, driven with that method's body for one pawn). Plus one test per transition the harness can drive: arrest, release, freeing a home slave, imprisoning a slave, enslaving after an arrest, selling and buying back; recruiting, enslaving and capturing are in the join tests.
|
||||||
|
|
||||||
#### Overlap warnings
|
#### Overlap warnings
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue