Crafting¶
Responsibility¶
Crafting resolves recipe knowledge, component/tool requirements, accessible inventories,
batch/time calculations, selections, work progress, and creation or disassembly of item
results. craft_command records a chosen execution plan.
Entry points¶
Start with src/crafting.h, src/crafting.cpp, and src/craft_command.h. Character-specific
access is in character_crafting.cpp, presentation in crafting_gui.cpp, and static recipe
contracts in recipe and requirement loaders.
Data ownership¶
Registries own recipes and requirements. Characters and nearby containers own source items; temporary crafting inventories are views. An in-progress craft item owns selected components and progress needed to resume work.
Dependencies¶
Crafting depends on recipes, requirement data, item locations and pockets, skills, proficiencies, qualities, map/vehicle inventories, activities, calories and time.
Lifecycle¶
Recipes load and finalize; a character builds an accessible inventory, checks knowledge and requirements, chooses components, starts an activity, advances work, then completes, aborts, or resumes the craft.
Invariants¶
Selections satisfy the exact requirement alternative; consumed items still belong to valid locations; batch math and progress use consistent units; completion cannot consume twice; and resume data matches the recipe and components.
Extension points¶
Add recipes and requirements in JSON. Native extensions should add a reusable requirement or activity rule rather than a recipe-ID special case, and must cover UI and non-UI callers.
Serialization¶
craft_command selections and in-progress craft data have serialization in the native save
layer. Persist IDs and selected components, not temporary inventory caches or UI filters.
Tests¶
Use crafting, requirements, temporary-inventory, uncraft, GUI, attention, proficiency, and activity tests. Cover competing alternatives and interrupted/resumed work.
Performance¶
Recipe filtering repeatedly queries large inventories. Reuse scoped requirement caches and avoid rebuilding map-wide crafting inventories for each displayed recipe.
CCB divergence¶
CCB recipes and crafting behaviors may differ from upstream even when recipe IDs match. Ports must load CCB data and validate requirement, duration, and resume semantics.
Technical debt¶
Requirement solving, UI selection, and activity execution cross several layers. Keep their contracts explicit and do not let UI state become execution authority.