# aviuz/prisonlabor architecture

> Architecture diagram of the GitHub repository aviuz/prisonlabor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aviuz/prisonlabor
- Repository: https://github.com/aviuz/prisonlabor

## Overview

#### 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: [`Source/Core/Components/PrisonerComp.cs`](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Components/PrisonerComp.cs) (PrisonerComp), [`Source/HarmonyPatches/HPatcher.cs`](https://github.com/aviuz/prisonlabor/blob/master/Source/HarmonyPatches/HPatcher.cs) (Harmony patch bootstrap), [`Source/Core/AI/JobGivers/JobGiver_Labor.cs`](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/AI/JobGivers/JobGiver_Labor.cs) (Labor job giver), [`Source/Initialization.cs`](https://github.com/aviuz/prisonlabor/blob/master/Source/Initialization.cs) (Mod initialization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime &amp; Content"]
  node_project["C&#35; assembly project<br/>build<br/>[PrisonLabor.csproj]"]
  node_bootstrap["Mod initialization<br/>bootstrap<br/>[Initialization.cs]"]
  node_metadata["Mod metadata &amp; routing<br/>mod manifest<br/>[LoadFolders.xml]"]
  node_defs["Versioned XML Defs<br/>RimWorld definitions<br/>[JobDef.xml]"]
  node_rimworld{{"RimWorld runtime<br/>game API"}}
end

subgraph group_state["Prisoner State"]
  node_prisonercomp["PrisonerComp<br/>per-prisoner component<br/>[PrisonerComp.cs]"]
  node_escape["Escape tracker<br/>state tracker<br/>[EscapeTracker.cs]"]
  node_worksettings["Labor work settings<br/>policy settings<br/>[WorkSettings.cs]"]
end

subgraph group_labor["Labor &amp; Supervision"]
  node_laborjobgiver["Labor job giver<br/>AI job giver<br/>[JobGiver_Labor.cs]"]
  node_supervisegiver["Supervise work giver<br/>AI work giver"]
  node_supervisedriver["Supervise job driver"]
end

subgraph group_integration["Integration &amp; Compatibility"]
  node_harmony["Harmony patch bootstrap<br/>[HPatcher.cs]"]
  node_workpatch["Work scanning patch<br/>Harmony patch"]
  node_areapatch["Labor-area scanner patch<br/>Harmony patch"]
  node_saves["Save upgrader<br/>save migration<br/>[SaveUpgrader.cs]"]
  node_compat["Third-party compatibility<br/>adapter assembly<br/>[HarmonyInit.cs]"]
end

subgraph group_player["Player Control &amp; Outcomes"]
  node_laborarea["Labor-area designator<br/>area control"]
  node_managementui["Prisoner management UI<br/>main tab window"]
  node_motivation["Motivation need<br/>custom need<br/>[Need_Motivation.cs]"]
  node_revolt["Revolt incident<br/>incident worker"]
  node_interrogation["Interrogation component<br/>expansion mechanic"]
end

node_project -->|"builds"| node_bootstrap
node_metadata -->|"routes to"| node_defs
node_bootstrap -->|"initializes"| node_harmony
node_bootstrap -->|"loads into"| node_rimworld
node_defs -->|"registered by"| node_rimworld
node_defs -->|"selects"| node_laborjobgiver
node_prisonercomp -->|"tracks"| node_escape
node_worksettings -->|"sets labor policy"| node_prisonercomp
node_prisonercomp -->|"supplies eligibility"| node_laborjobgiver
node_laborarea -->|"bounds reachable work"| node_laborjobgiver
node_laborjobgiver -->|"assigns prisoner jobs"| node_rimworld
node_supervisegiver -->|"assigns"| node_supervisedriver
node_supervisedriver -->|"updates restraints"| node_prisonercomp
node_managementui -->|"edits assignments"| node_worksettings
node_managementui -->|"controls"| node_laborarea
node_motivation -->|"affects behavior"| node_prisonercomp
node_escape -->|"contributes risk"| node_revolt
node_harmony -->|"applies"| node_workpatch
node_harmony -->|"applies"| node_areapatch
node_workpatch -->|"patches work logic"| node_rimworld
node_areapatch -->|"patches job scanning"| node_rimworld
node_saves -.->|"migrates state"| node_prisonercomp
node_compat -.->|"adds optional patches"| node_harmony
node_interrogation -->|"uses prisoner state"| node_prisonercomp

click node_project "https://github.com/aviuz/prisonlabor/blob/master/Source/PrisonLabor.csproj"
click node_bootstrap "https://github.com/aviuz/prisonlabor/blob/master/Source/Initialization.cs"
click node_metadata "https://github.com/aviuz/prisonlabor/blob/master/LoadFolders.xml"
click node_defs "https://github.com/aviuz/prisonlabor/blob/master/1.6/Defs/JobDef.xml"
click node_prisonercomp "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Components/PrisonerComp.cs"
click node_escape "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Trackers/EscapeTracker.cs"
click node_worksettings "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/LaborWorkSettings/WorkSettings.cs"
click node_laborjobgiver "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/AI/JobGivers/JobGiver_Labor.cs"
click node_supervisegiver "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/AI/WorkGivers/WorkGiver_Supervise.cs"
click node_supervisedriver "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/AI/JobDrivers/JobDriver_Supervise.cs"
click node_laborarea "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/LaborArea/Designator_AreaLabor.cs"
click node_managementui "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/MainButton_Window/MainTabWindow_Labor.cs"
click node_motivation "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Needs/Need_Motivation.cs"
click node_revolt "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Incidents/IncidentWorker_Revolt.cs"
click node_interrogation "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Interrogation/Comp_Interrogation.cs"
click node_harmony "https://github.com/aviuz/prisonlabor/blob/master/Source/HarmonyPatches/HPatcher.cs"
click node_workpatch "https://github.com/aviuz/prisonlabor/blob/master/Source/HarmonyPatches/Patches_Work/Patch_WorkGiver_PrisonerFaction.cs"
click node_areapatch "https://github.com/aviuz/prisonlabor/blob/master/Source/HarmonyPatches/Patches_LaborArea/Patch_Scanner_HasJob.cs"
click node_saves "https://github.com/aviuz/prisonlabor/blob/master/Source/Core/GameSaves/SaveUpgrader.cs"
click node_compat "https://github.com/aviuz/prisonlabor/blob/master/Source/CompatibilityProjects/HospitalityCompatibility/HarmonyInit.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_project,node_bootstrap,node_metadata,node_defs,node_rimworld toneBlue
class node_prisonercomp,node_escape,node_worksettings toneAmber
class node_laborjobgiver,node_supervisegiver,node_supervisedriver toneMint
class node_harmony,node_workpatch,node_areapatch,node_saves,node_compat toneRose
class node_laborarea,node_managementui,node_motivation,node_revolt,node_interrogation toneIndigo
```

## Components

### Runtime & Content

- [C# assembly project](https://github.com/aviuz/prisonlabor/blob/master/Source/PrisonLabor.csproj): build · `Source/PrisonLabor.csproj`
- [Mod initialization](https://github.com/aviuz/prisonlabor/blob/master/Source/Initialization.cs): bootstrap · `Source/Initialization.cs`
- [Mod metadata & routing](https://github.com/aviuz/prisonlabor/blob/master/LoadFolders.xml): mod manifest · Selects version-specific content roots. · `LoadFolders.xml`
- [Versioned XML Defs](https://github.com/aviuz/prisonlabor/blob/master/1.6/Defs/JobDef.xml): RimWorld definitions · Registers jobs, work, needs, incidents, interactions, and think-tree changes. · `1.6/Defs/JobDef.xml`
- **RimWorld runtime**: game API

### Prisoner State

- [PrisonerComp](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Components/PrisonerComp.cs): per-prisoner component · Central prisoner labor, restraint, treatment, and status state. · `Source/Core/Components/PrisonerComp.cs`
- [Escape tracker](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Trackers/EscapeTracker.cs): state tracker · `Source/Core/Trackers/EscapeTracker.cs`
- [Labor work settings](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/LaborWorkSettings/WorkSettings.cs): policy settings · Controls prisoner work eligibility and assignments. · `Source/Core/LaborWorkSettings/WorkSettings.cs`

### Labor & Supervision

- [Labor job giver](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/AI/JobGivers/JobGiver_Labor.cs): AI job giver · Selects eligible prisoner labor jobs. · `Source/Core/AI/JobGivers/JobGiver_Labor.cs`
- [Supervise work giver](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/AI/WorkGivers/WorkGiver_Supervise.cs): AI work giver · `Source/Core/AI/WorkGivers/WorkGiver_Supervise.cs`
- [Supervise job driver](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/AI/JobDrivers/JobDriver_Supervise.cs): job driver · Executes supervision and restraint actions. · `Source/Core/AI/JobDrivers/JobDriver_Supervise.cs`

### Integration & Compatibility

- [Harmony patch bootstrap](https://github.com/aviuz/prisonlabor/blob/master/Source/HarmonyPatches/HPatcher.cs): patch bootstrap · Installs compatibility changes against RimWorld internals. · `Source/HarmonyPatches/HPatcher.cs`
- [Work scanning patch](https://github.com/aviuz/prisonlabor/blob/master/Source/HarmonyPatches/Patches_Work/Patch_WorkGiver_PrisonerFaction.cs): Harmony patch · Adjusts vanilla prisoner-faction work assumptions. · `Source/HarmonyPatches/Patches_Work/Patch_WorkGiver_PrisonerFaction.cs`
- [Labor-area scanner patch](https://github.com/aviuz/prisonlabor/blob/master/Source/HarmonyPatches/Patches_LaborArea/Patch_Scanner_HasJob.cs): Harmony patch · Applies labor-area rules during job scanning. · `Source/HarmonyPatches/Patches_LaborArea/Patch_Scanner_HasJob.cs`
- [Save upgrader](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/GameSaves/SaveUpgrader.cs): save migration · Cleans and upgrades persisted mod state. · `Source/Core/GameSaves/SaveUpgrader.cs`
- [Third-party compatibility](https://github.com/aviuz/prisonlabor/blob/master/Source/CompatibilityProjects/HospitalityCompatibility/HarmonyInit.cs): adapter assembly · Optional Harmony adapters integrate other mods. · `Source/CompatibilityProjects/HospitalityCompatibility/HarmonyInit.cs`

### Player Control & Outcomes

- [Labor-area designator](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/LaborArea/Designator_AreaLabor.cs): area control · Defines where prisoners may work. · `Source/Core/LaborArea/Designator_AreaLabor.cs`
- [Prisoner management UI](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/MainButton_Window/MainTabWindow_Labor.cs): main tab window · Provides overview, assignments, schedules, and prisoner status columns. · `Source/Core/MainButton_Window/MainTabWindow_Labor.cs`
- [Motivation need](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Needs/Need_Motivation.cs): custom need · Feeds prisoner behavior and handling outcomes. · `Source/Core/Needs/Need_Motivation.cs`
- [Revolt incident](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Incidents/IncidentWorker_Revolt.cs): incident worker · `Source/Core/Incidents/IncidentWorker_Revolt.cs`
- [Interrogation component](https://github.com/aviuz/prisonlabor/blob/master/Source/Core/Interrogation/Comp_Interrogation.cs): expansion mechanic · Supports interrogation and Ideology ritual mechanics. · `Source/Core/Interrogation/Comp_Interrogation.cs`

## Connections

- 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
