Roles
Overview
Each elf can be assigned one of four roles that influence their task selection,
default gathering target, and behavior under the Cultural Policies system.
Roles are assigned by the patron (or AI curator) and stored in the
CulturalPolicies::workshop_assignments map. Unassigned elves follow a
general-purpose behavior tree.
How It Works
Role Types
| Role | Description |
|---|---|
| Unassigned | Default. Follows the general behavior tree; gathers the most-needed resource. |
| Composer | Gravitates toward composing at a Workshop when no urgent needs exist. |
| Builder | Prioritized for build queue assignments; default gather target is Stone. |
| Gatherer | Default gather target is Wood; handles general resource collection. |
(Source: src/sim/components.rs, enum ElfRole)
Role Assignment
Roles are set via CulturalPolicies::workshop_assignments, a map from elf
name to ElfRole. If an elf's name is not in the map, they default to
ElfRole::Unassigned.
role = workshop_assignments.get(name).unwrap_or(Unassigned)
(Source: src/sim/world.rs, CulturalPolicies::role_for())
Role-Resource Linkage
Each role has a default resource it will gather when sent to decide_default():
| Role | Default Resource |
|---|---|
| Gatherer | Wood |
| Builder | Stone |
| Composer | None (uses policy priority or most-needed) |
| Unassigned | None (uses policy priority or most-needed) |
(Source: src/sim/world.rs, CulturalPolicies::role_resource())
Values & Formulas
Task Decision Priority
The behavior tree (task_decision_system) evaluates priorities in strict
order. Roles only matter at Steps 3c and 4 -- critical needs always come
first.
| Priority | Condition | Action |
|---|---|---|
| Step 0: Preempt | Sustenance or Rest critical (< 20, or < 5 for construction) | Cancel current task, go idle |
| Step 1: Critical Needs | Sustenance < 20 | Eat (if Food available) or Gather Food |
| Rest < 20 | Rest (seek Dwelling) | |
| Step 1b: Discontented | Elf has Discontented marker | Only gather Food or idle; refuses creative/ambitious work |
| Step 1c: Mourning | Elf has Mourning marker | Compose at Workshop (tribute); Wander if no Workshop. Skips gathering/building. |
| Step 2: Creative Block | Elf has CreativeBlock | Seek Garden (if available) |
| Step 3: Moderate Needs | Beauty < 30 or Stimulation < 30 | Compose (Stimulation) or SeekGarden (Beauty), whichever is lower |
| Step 3b: Aspirations | Aspiration wants compose/socialize | Compose at Workshop or Wander to social buildings |
| Step 3c: Skill-Driven | Music skill >= 7 | Compose at Workshop |
| Building skill >= 7 + build queue not empty | Build | |
| Step 3d: Personal Time | 5% random chance | Seek favorite place or Garden for beauty/inspiration |
| Step 4: Cultural Policy | Role == Composer | Compose at Workshop |
| Any other role | decide_default() | |
| Breaking Morale | Morale < 20 (inserted between Steps 3 and 3b) | Idle (refuse all non-critical work) |
(Source: src/sim/systems.rs, task_decision_system())
Default Behavior (decide_default)
When an elf reaches the default branch:
- Check
resource_priority[0]-- if that resource stock < 10, gather it (override). - Otherwise, if the elf's role has a
role_resource, gather that. - Otherwise, use
resource_priority[0]if set. - Otherwise, gather
most_needed_resource()(lowest stock of Food/Wood/Stone). - If no source exists for the chosen resource, fall back to most-needed.
- If still no source, Wander.
(Source: src/sim/systems.rs, decide_default())
Build Queue Assignment
When the build queue is non-empty and resources are available:
- Prefer idle elf with Builder role.
- Then any idle elf.
- Then any Builder-role elf on a non-critical task (Sustenance >= 40 and Rest >= 40).
- Only one elf builds at a time (no double-assignment).
(Source: src/sim/systems.rs, build_queue_system())
Preemption Rules
Active tasks can be interrupted when needs become critical:
| Current Task | Preempt Threshold |
|---|---|
| Gather, Compose, SeekGarden, Wander | Sustenance < 20 OR Rest < 20 |
| Build, ClearForest | Sustenance < 5 OR Rest < 5 |
When preempted, the elf's task is set to Idle, their path is canceled, and any carried resources are dropped (lost). Construction tasks get a lower preemption threshold to avoid interrupting nearly-finished builds.
(Source: src/sim/systems.rs, task_decision_system(), Phase 0)
Revel Attendance Override
Elves attending an active revel skip the entire behavior tree. The
RevelAttending marker component is checked first, and those elves are
excluded from all task decisions until the revel ends.
(Source: src/sim/systems.rs, task_decision_system())
Role Behavior Summary Table
| Role | Idle Behavior | When Needs OK | When Needs Critical |
|---|---|---|---|
| Unassigned | Gather most-needed resource | Follow policy priority | Eat/Rest |
| Composer | Compose at Workshop | Compose at Workshop | Eat/Rest |
| Builder | Gather Stone | Assigned to build queue first | Eat/Rest |
| Gatherer | Gather Wood | Gather Wood | Eat/Rest |
Interactions
- Needs & Mood -- critical needs always override role behavior; morale tier affects willingness to work.
- Resources -- role determines which resource an elf gathers by default; resource priority can override role.
- Skills -- high Music skill (>= 7) self-selects to Compose regardless of role; high Building skill (>= 7) self-selects to Build.
- Buildings -- Builders are prioritized for the build queue; Composers require a Workshop.
Tips
- Composer is the only role that directly affects task selection at Step 4. Builder and Gatherer mostly influence which resource is gathered in the default branch.
- Skill-driven preferences (Step 3c) bypass role. An elf with Music 7+ will self-select to compose even if unassigned. Assign roles primarily for lower-skill elves.
- Aspirations (Step 3b) also bypass role. Elves pursuing a "compose works" aspiration will compose without needing the Composer role.
- Builders get pulled from non-critical tasks to fill the build queue. Make sure your Builder has adequate Sustenance and Rest (>= 40 each) or they will be skipped.
- Unassigned is not idle. Unassigned elves still gather the most-needed resource or follow the resource priority list. In a small settlement, leaving everyone Unassigned is a valid strategy.
- Resource priority override is powerful. Setting a priority resource effectively overrides all non-Builder roles when that resource drops below 10 units.