How aviuz/prisonlabor works
Purpose and Runtime
Prison Labor is a RimWorld mod that extends prisoner management so designated prisoners can perform colony work under supervision. It runs as a C# RimWorld assembly, loaded with version-specific XML content for game versions 1.0–1.6. Primary bootstrapping is Source/Initialization.cs; project entry/build definition is Source/PrisonLabor.csproj. Mod metadata and load-folder routing are About/About.xml and LoadFolders.xml.
Definition-Driven Game Integration
Each supported RimWorld version has a content root (1.0 through 1.6) containing compiled assemblies and XML Defs. The Def layer registers jobs, work types/givers, needs, thoughts, incidents, prisoner interaction modes, and AI think-tree changes—for example 1.6/Defs/JobDef.xml, 1.6/Defs/WorkGiverDef.xml, and 1.6/Defs/ThinkTreeDef.xml. This is the boundary where RimWorld’s data loader discovers mod behavior.
Prisoner State and Policy
PrisonerComp is the per-prisoner state model, with properties and related trackers for cuffs, escape risk, and inspiration. It supports work eligibility, restraints, treatment, and operational status that downstream AI and UI consume. Core paths: Source/Core/Components/PrisonerComp.cs, Source/Core/Trackers/EscapeTracker.cs, Source/Core/LaborWorkSettings/WorkSettings.cs.
AI, Work, and Supervision Flow
RimWorld’s think trees select prisoner-specific job givers; labor-enabled prisoners are assigned jobs subject to motivation, schedules, reachable labor areas, reservations, and permissions. Supervisors receive dedicated work/jobs, while prisoner job drivers handle restraints and related actions. Relevant implementation: Source/Core/AI/JobGivers/JobGiver_Labor.cs, Source/Core/AI/WorkGivers/WorkGiver_Supervise.cs, Source/Core/AI/JobDrivers/JobDriver_Supervise.cs.
Labor Boundaries and Game Patching
Harmony patches alter vanilla work scanning, job execution, food, arrest, forbidden/reservation logic, work settings, and escape behavior so prisoners can perform work without violating vanilla faction/prisoner assumptions. The patch layer is the key compatibility boundary with RimWorld internals: Source/HarmonyPatches/HPatcher.cs, Source/HarmonyPatches/Patches_Work/Patch_WorkGiver_PrisonerFaction.cs, Source/HarmonyPatches/Patches_LaborArea/Patch_Scanner_HasJob.cs.
Management UI and Player Control
A custom main prisoner-management window exposes overview, labor assignments, schedules, and prisoner-specific columns such as motivation, treatment, work state, restraints, and escape tracking. Labor-area designators define where prisoners may work. Paths: Source/Core/MainButton_Window/PrisonerButtonWindow.cs, Source/Core/MainButton_Window/MainTabWindow_Labor.cs, Source/Core/LaborArea/Designator_AreaLabor.cs.
Needs, Outcomes, and Events
Motivation and treatment are custom needs feeding thoughts and behavior; low motivation can affect prisoner handling. The mod also introduces prisoner incidents and supports recreation, chains, and interrogation/Ideology ritual mechanics in newer versions. Paths: Source/Core/Needs/Need_Motivation.cs, Source/Core/Incidents/IncidentWorker_Revolt.cs, Source/Core/Interrogation/Comp_Interrogation.cs.
Persistence, Expansions, and Mod Compatibility
Save cleanup/upgrading and version patches preserve old-save compatibility. Optional content and independently compiled Harmony adapters integrate third-party mods such as Hospitality, Quarry, Cash Registry, Therapy, Kijin, and Colony Groups; their assemblies are deployed under versioned folders. Paths: Source/Core/GameSaves/SaveUpgrader.cs, Source/CompatibilityPatches/OlderVersions.cs, Source/CompatibilityProjects/HospitalityCompatibility/HarmonyInit.cs.
Main entry points: PrisonerComp.cs PrisonerComp · HPatcher.cs Harmony patch bootstrap · JobGiver_Labor.cs Labor job giver · Initialization.cs Mod initialization
Components 21
Runtime & Content
- C# assembly project
Source/PrisonLabor.csproj - Mod initialization
Source/Initialization.cs - Mod metadata & routing · Selects version-specific content roots.
LoadFolders.xml - Versioned XML Defs · Registers jobs, work, needs, incidents, interactions, and think-tree changes.
1.6/Defs/JobDef.xml - RimWorld runtime
Prisoner State
- PrisonerComp · Central prisoner labor, restraint, treatment, and status state.
Source/Core/Components/PrisonerComp.cs - Escape tracker
Source/Core/Trackers/EscapeTracker.cs - Labor work settings · Controls prisoner work eligibility and assignments.
Source/Core/LaborWorkSettings/WorkSettings.cs
Labor & Supervision
- Labor job giver · Selects eligible prisoner labor jobs.
Source/Core/AI/JobGivers/JobGiver_Labor.cs - Supervise work giver
Source/Core/AI/WorkGivers/WorkGiver_Supervise.cs - Supervise job driver · Executes supervision and restraint actions.
Source/Core/AI/JobDrivers/JobDriver_Supervise.cs
Integration & Compatibility
- Harmony patch bootstrap · Installs compatibility changes against RimWorld internals.
Source/HarmonyPatches/HPatcher.cs - Work scanning patch · Adjusts vanilla prisoner-faction work assumptions.
Source/HarmonyPatches/Patches_Work/Patch_WorkGiver_PrisonerFaction.cs - Labor-area scanner patch · Applies labor-area rules during job scanning.
Source/HarmonyPatches/Patches_LaborArea/Patch_Scanner_HasJob.cs - Save upgrader · Cleans and upgrades persisted mod state.
Source/Core/GameSaves/SaveUpgrader.cs - Third-party compatibility · Optional Harmony adapters integrate other mods.
Source/CompatibilityProjects/HospitalityCompatibility/HarmonyInit.cs
Player Control & Outcomes
- Labor-area designator · Defines where prisoners may work.
Source/Core/LaborArea/Designator_AreaLabor.cs - Prisoner management UI · Provides overview, assignments, schedules, and prisoner status columns.
Source/Core/MainButton_Window/MainTabWindow_Labor.cs - Motivation need · Feeds prisoner behavior and handling outcomes.
Source/Core/Needs/Need_Motivation.cs - Revolt incident
Source/Core/Incidents/IncidentWorker_Revolt.cs - Interrogation component · Supports interrogation and Ideology ritual mechanics.
Source/Core/Interrogation/Comp_Interrogation.cs
Connections 24
- C# assembly project → Mod initialization: builds
- Mod metadata & routing → Versioned XML Defs: routes to
- Mod initialization → Harmony patch bootstrap: initializes
- Mod initialization → RimWorld runtime: loads into
- Versioned XML Defs → RimWorld runtime: registered by
- Versioned XML Defs → Labor job giver: selects
- PrisonerComp → Escape tracker: tracks
- Labor work settings → PrisonerComp: sets labor policy
- PrisonerComp → Labor job giver: supplies eligibility
- Labor-area designator → Labor job giver: bounds reachable work
- Labor job giver → RimWorld runtime: assigns prisoner jobs
- Supervise work giver → Supervise job driver: assigns
- Supervise job driver → PrisonerComp: updates restraints
- Prisoner management UI → Labor work settings: edits assignments
- Prisoner management UI → Labor-area designator: controls
- Motivation need → PrisonerComp: affects behavior
- Escape tracker → Revolt incident: contributes risk
- Harmony patch bootstrap → Work scanning patch: applies
- Harmony patch bootstrap → Labor-area scanner patch: applies
- Work scanning patch → RimWorld runtime: patches work logic
- Labor-area scanner patch → RimWorld runtime: patches job scanning
- Save upgrader → PrisonerComp: migrates state
- Third-party compatibility → Harmony patch bootstrap: adds optional patches
- Interrogation component → PrisonerComp: uses prisoner state