v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Reaction

From Dwarf Fortress Wiki
Revision as of 15:24, 9 February 2018 by Blaat (talk | contribs)
Jump to navigation Jump to search
This article is about the current version of DF.
Note that some content may still need to be updated.

Reactions are modular, editable formulas that take specific ingredients, or reagents, and use them to produce a desired item. A lot of reactions are hardcoded—building beds or creating glass, for example—but a few are freely editable, and it's (sometimes) quite simple to add additional ones. There is a separate page with custom reaction examples.

Reaction differences between modes

In fortress mode, reactions are linked to specific buildings, and must be added to a civilization's entity file to be usable by that civilization. This has the useful effect of limiting new items and materials (such as special wood or metal) to civilizations that have the requisite reaction—so that if you give your custom civilization a reaction to produce star metal or some other custom material, only they will be able to use it.

In adventure mode, reactions are freely available in the x menu via the create option, and any adventurer character can make free use of them. Reagents may be held in the hands or dropped on the ground, but cannot be used within a backpack or quiver. There are several bugs with Adventure mode reactions, chief of which is the fact that you cannot select liquid reagents.[Verify]

Anatomy of a reaction

Reactions are found within reaction_x files (such as reaction_smelter or reaction_other). Generally speaking they adhere to the following structure:

  [REACTION:<identifier>]
     [NAME:<name>]
     [BUILDING:<BUILDING NAME>:<BUILDING KEY>]
     [REAGENT:A:150:BAR:NONE:POTASH:NONE]
     [PRODUCT:100:1:BAR:NONE:PEARLASH:NONE][PRODUCT_DIMENSION:150]
     [FUEL] 
     [SKILL:<SKILL TOKEN>]
     [AUTOMATIC]
     [ADVENTURE_MODE_ENABLED]
  • identifier: The internal ID of the reaction.
  • name: The name of the reaction, visible to the player in the Fortress mode or Adventure mode menus.
  • building: The building ID that the reaction uses, and the relevant keyboard shortcut.
  • ...reagents...: Zero or more reagents (ingredients) that are required to be in stock for the reaction to be possible.
  • ...products...: Zero or more products that are created from the reaction.
  • fuel: (optional) If present, the reaction requires charcoal, coke or a magma-powered workshop.
  • skill: (optional) The skill required and trained by the reaction.
  • automatic: (optional) If present, the reaction will automatically be enqueued whenever it can possibly be performed.
  • adventure mode: (optional) If present, the reaction is used by the player in Adventure mode instead.

Reaction identifier

The reaction identifier may be anything, so long as it is unique within the raw data files. A good habit to get into is to append a short prefix or suffix to each name related to the name of your mod, to ensure nobody else is going to make an identical reaction and thereby mess up the game if their mod is run alongside yours.

Reaction name

This can be anything at all, and is usually used to describe the reaction. Tan a hide, for example, is the name of the default leather-producing reaction. Generally this should be written as a small descriptive verb phrase, with the first letter capitalized, for consistency with the existing reactions.

Building

   [BUILDING:<BUILDING NAME>:<BUILDING KEY>]
  • name: The ID (that is the internal TOKEN each building can be referred to into reactions) of the building where this reaction will appear in the tasks menu.
  • key: The keyboard shortcut used to queue up the reaction.

The BUILDING NAME is the name of the building that will house this reaction, and the building key is the keyboard shortcut that will queue up the reaction. If two reactions have the same key, then one of them will be assigned a different key, the first alphabetically available at the building.

Valid buildings TOKENS are as follows:

Specifying multiple BUILDING tokens will cause the reaction to be available at all of the specified buildings.

Category

Categories are custom submenus for buildings' reaction menus. A reaction doesn't require a category, but if you have a lot of reactions, categories can be invaluable for organizing and presenting those reactions to players.

Categories can be nested indefinitely—you can have a category within a category within a category within a category within a category within... but as a practical matter, nesting categories more than 2 deep is not recommended.

Categories currently have no effect on adventure mode reactions.

Defining a category

Each category needs to be defined within a reaction, usually one which should appear within its menu. Categories only need to be defined once.

Token Arguments Description
CATEGORY Category ID The category ID is a unique identifier for the category. It is only used in the raws, and will not appear in the game.

If you're defining multiple categories within the same reaction - for example, if you intend the reaction to be nested two deep, and haven't yet defined the super-category - the last CATEGORY token within the reaction definition is the one that the reaction will appear in.

CATEGORY_NAME String The name of the category as displayed in-game.
CATEGORY_DESCRIPTION String Optional. If present, when the category is highlighted in a building menu, this string will be displayed in the Helpful Hint box.
CATEGORY_PARENT Category ID Optional. If present, this category will be a submenu of the indicated category, rather than a submenu of the reaction's building.
CATEGORY_KEY Hotkey token Optional. If present, this category can be selected from its parent menu (whether a building or a parent category) using the given hotkey.

Adding reactions to an existing category

Just include the tag [CATEGORY:<category_id>] within your reaction definition, and if the category exists, your reaction will be added to its menu. You can only add reactions to custom categories.

Each reaction can belong to only one category.

Reagents

REAGENTs are a little bit complicated. They are the ingredients that the reaction will use. You can define as many as you like within a reaction.

   [REAGENT:<name>:<quantity>:<item token>:<material token>][...modifiers...]
  • name: The name of the reagent, local to the reaction.
  • quantity: The amount of the item that will be used in the reaction.
  • item token: The type (and subtype) of the item you require.
  • material token: The material the item should be made of.
  • ...modifiers...: Zero or more tokens which further clarify the acceptable types when the item type and material types are insufficient to distinguish them.

name

The name field is a small string used to identify the reagent within the reaction. The name is not visible to the player. It is local to the reaction and does not need to be unique across all of the reactions, so you can reuse the same names over and over, although each reagent within the same individual reaction must have a different name.

Most reagents are simply named A, B, and so forth in default reactions, although names such as TOOLSTONE or FLUX will also work equally well. The PRODUCT may make reference to this name – for instance, if a container B is specified as a reagent, PRODUCT_TO_CONTAINER:B specifies that container.

quantity

The quantity differs between item types. Generally speaking, cloth, thread, powder, bars, liquids and globs use numbers representing the size of material within one item, and everything else uses a static quantity. While REAGENT:A:10:THREAD:NONE:NONE:NONE thread is an extremely tiny portion of a random spool of thread, REAGENT:A:10:TOY:NONE:NONE:NONE is ten unique, solid toy items.

Sometimes the quantity of product is directly connected with the quantity of reagent; it seems to be 150 / REAGENT <quantity> (rounding down) so that Reagent <quantity> of 3 gives 50 product and a <quantity> of 4 gives 37. (150/4=37.5) [List of item types this applies to? Bars, for instance.]

item token

Item tokens are of the form ITEM_TYPE:ITEM_SUBTYPE.

The item type is the sort of item you require; WEAPON, TOY or SKIN_TANNED, for example. A full list is available.

For reagents, the item token can also be set to ANY_RAW_MATERIAL:NONE (to permit BAR, BOULDER, POWDER_MISC, or GLOB) or ANY_CRAFT:NONE (to permit FIGURINE, AMULET, SCEPTER, CROWN, RING, EARRING, or BRACELET). Internally, these special values are both converted to NONE:NONE and merely set special modifiers (similar to [BUILDMAT])—they cannot be used in any other context.

The item subtype is name of the exact item that you require. Examples are ITEM_WEAPON_SPEAR or ITEM_TOY_PUZZLEBOX. Some items, like quivers or backpacks, or chunks of stone or metal, only require the item token to be filled in, so if you're asking for those you should set the subtype to NONE. Subtypes are defined within the local raw data files and their exact names can be referenced by looking at the corresponding file.

For backwards compatibility, reagents can also accept "METAL_ORE:metal_id" in place of both the item and material tokens—this is equivalent to using the reagent BOULDER:NONE:NONE:NONE with the modifier [METAL_ORE:metal_id] (see below).

material token

Material tokens come in several forms. For most reagents, this will typically be INORGANIC:MATERIAL_ID or NONE:NONE (to allow multiple materials using other filters).

Modifiers

Reagents may also have extra tokens added on afterwards, placed just after the REAGENT tag.

Generally speaking, if you set a field in a reagent to NONE, the reaction won't discriminate when it comes to that particular field. For example, if you require a BOULDER reagent but leave the material as NONE:NONE, it will grab any available BOULDER-type item regardless of material.

A list of them follows:

Token Meaning
[REACTION_CLASS:X] Reagent material must have the specified reaction class - see below for more details.
[HAS_MATERIAL_REACTION_PRODUCT:X] Reagent material must have the specified material reaction product - see below for more details.
[HAS_ITEM_REACTION_PRODUCT:X] Reagent material must have the specified item reaction product - see below for more details. This can be used interchangeably with HAS_MATERIAL_REACTION_PRODUCT.
[CONTAINS:X] Reagent is a container that holds the specified reagent (where X is the name of the reagent).
[UNROTTEN] Reagent must not be rotten, mainly for organic materials.
[CONTAINS_LYE] Reagent must be a BARREL or TOOL which contains at least one item of type LIQUID_MISC made of LYE. Use of this token is discouraged, as it does not work with buckets (instead, use [CONTAINS:lye] — note the colon — and a corresponding lye reagent [REAGENT:lye:150:LIQUID_MISC:NONE:LYE]).
[POTASHABLE] Alias for [CONTAINS_LYE].
[NOT_WEB] Reagent must be collected (to distinguish silk thread from webs). Only makes sense for items of type THREAD.
[WEB_ONLY] Reagent must be undisturbed (to distinguish silk thread from webs). Only makes sense for items of type THREAD.
[EMPTY] If the reagent is a container, it must be empty.
[NOT_CONTAIN_BARREL_ITEM] If the reagent is a container, it must not contain lye or milk. Not necessary if specifying [EMPTY].
[BAG] Reagent must be a bag - that is, a BOX made of plant fiber, silk, yarn, or leather.
[GLASS_MATERIAL] Reagent material must have the [IS_GLASS] token. All 3 types of glass have this token hardcoded.
[BUILDMAT] Reagent must be a general building material - BAR, BLOCKS, BOULDER, or WOOD.
[FIRE_BUILD_SAFE] Reagent material must be solid and stable at temperatures approaching 11000. Only works with items of type BAR, BLOCKS, BOULDER, WOOD, and ANVIL - all others are considered unsafe.
[MAGMA_BUILD_SAFE] Reagent material must be solid and stable at temperatures approaching 12000. Only works with items of type BAR, BLOCKS, BOULDER, WOOD, and ANVIL - all others are considered unsafe.
[CAN_USE_ARTIFACT] Reagent can be an Artifact. Using [PRESERVE_REAGENT] with this is strongly advised.
[WORTHLESS_STONE_ONLY] Reagent material must be non-economic.
[ANY_PLANT_MATERIAL] Reagent material must be subordinate to a PLANT object.
[ANY_SILK_MATERIAL] Reagent material must have the [SILK] token.
[ANY_YARN_MATERIAL] Reagent material must have the [YARN] token.
[ANY_SOAP_MATERIAL] Reagent material must have the [SOAP] token.
[ANY_LEATHER_MATERIAL] Reagent material must have the [LEATHER] token.
[ANY_BONE_MATERIAL] Reagent material must have the [BONE] token.
[ANY_STRAND_TISSUE] Reagent is made of a tissue having [TISSUE_SHAPE:STRANDS], intended for matching hair and wool. Must be used with [USE_BODY_COMPONENT].
[ANY_SHELL_MATERIAL] Reagent material must have the [SHELL] token.
[ANY_TOOTH_MATERIAL] Reagent material must have the [TOOTH] token.
[ANY_HORN_MATERIAL] Reagent material must have the [HORN] token.
[ANY_PEARL_MATERIAL] Reagent material must have the [PEARL] token.
[IS_SAND_MATERIAL] Reagent material must have the [SOIL_SAND] token.
[USE_BODY_COMPONENT] Reagent must be a body part (CORPSE or CORPSEPIECE). Must be used even if your reagent item type is CORPSE or CORPSEPIECE, otherwise it will match any item.
[NO_EDGE_ALLOWED] Reagent must not have an edge - excludes sharp stones (produced using knapping) and most types of weapon/ammo.
[HAS_EDGE]v0.42.01 Reagent must have an edge.
[NOT_ENGRAVED] Reagent has not been engraved (excludes memorial slabs).
[NOT_IMPROVED] Reagent has not been decorated.
[DOES_NOT_ABSORB] Reagent material must have [ABSORPTION:0]
[FOOD_STORAGE_CONTAINER] Reagent is either a BARREL or a TOOL with the FOOD_STORAGE use.
[HARD_ITEM_MATERIAL] Reagent material must have [ITEMS_HARD].
[METAL_ITEM_MATERIAL] Reagent material must have [ITEMS_METAL].
[NOT_PRESSED] Reagent must not be in the SOLID_PRESSED state.
[METAL_ORE:X] Reagent material must be an ore of the specified metal.
[MIN_DIMENSION:X] Reagent's item dimension must be at least this large. The reagent's item type must be BAR, POWDER_MISC, LIQUID_MISC, DRINK, THREAD, CLOTH, or GLOB for this to work.
[HAS_TOOL_USE:X] Reagent must be a tool with the specific TOOL_USE value. The reagent's item type must be TOOL:NONE for this to make any sense.
[PRESERVE_REAGENT] Reagent is not destroyed, which is the normal effect, at the completion of the reaction. Typically used for containers.
[DOES_NOT_DETERMINE_PRODUCT_AMOUNT] Reagent quantity is ignored for the purposes of producing extra outputs. Typically used for containers so that stacks of reagents will correctly produce additional outputs.

Products

Products are the end product of the reaction. A reaction can have as many products as it likes.

Products are almost identical to reagents, except that they do not need to be named, can't have fields undefined, and don't use the quantity field to determine the product size. Instead, the token PRODUCT_DIMENSION:X is tacked on after the PRODUCT token, determining the size of the product.

Products can be produced directly to a container using the [PRODUCT_TO_CONTAINER:<IDENTIFIER>] token, where the IDENTIFIER is the name of a reagent. This requires the reagent to have the PRESERVE_REAGENT token.

Restating this in the above style, we have:

  [PRODUCT:<probability>:<quantity>:<item token>:<material token>][...modifiers...]

probability

The percentage chance the product will be produced when the reaction is completed.

quantity

Determines how many of the product will be produced. For the item types AMMO, REMAINS, MEAT, FISH, FISH_RAW, PLANT, PLANT_GROWTH, DRINK, CHEESE, LIQUID_MISC, COIN, and EGG, the resulting items will be created as a single stack, while all other item types will produce multiple individual items.

If a reaction can take stacks of input items, then it will attempt to perform the reaction enough times to consume as many full sets of reagents as it can—for example, if a reaction "1 piece of meat + 2 pieces of fish -> 3 pieces of cheese" is given a stack of 5 meat and 5 fish, it will produce 6 pieces of cheese and leave 3 meat and 1 fish behind. Using the token DOES_NOT_DETERMINE_PRODUCT_AMOUNT allows a reagent to be excluded from this calculation - for example, with the reaction "1 plant + 1 barrel -> 5 alcohol (into barrel)", using this on the barrel allows the reaction to be performed as "5 plant + 1 barrel -> 25 alcohol" instead of "5 plant + 5 barrel -> 25 alcohol".

item token

The item token and subtype of the item you produce.

If you want the item type and material to be derived from one of the reagents, you can use GET_ITEM_DATA_FROM_REAGENT:reagent:REACTION_PRODUCT_ID in place of both the item token and the material token below. You can also specify GET_ITEM_DATA_FROM_REAGENT:reagent:NONE in order to make a direct copy of the source item, though this will not work for complex items such as corpses or prepared meals.

For products, this can also be set to CRAFTS:NONE to produce up to three random craft items. This value cannot be used in any other context.

material token

A material token describing what the product will be made of.

If you want the product's material to be derived from one of the reagents, you can use GET_MATERIAL_FROM_REAGENT:reagent:REACTION_PRODUCT_ID in place of the material token. You can also specify GET_MATERIAL_FROM_REAGENT:reagent:NONE in order to directly use the reagent's own material.

Product modifiers

Zero or more tokens which further clarify the acceptable types when the item type and material types are insufficient to distinguish them.

Token Meaning
[FORCE_EDGE] Product is given a sharp edge. Used for knapping.
[PRODUCT_PASTE] Product is created in the SOLID_PASTE state.
[PRODUCT_PRESSED] Product is created in the SOLID_PRESSED state.
[PRODUCT_DIMENSION:<size>] Specifies the dimensions of the product. A product of 150 is typical for BAR, POWDER_MISC, LIQUID_MISC, DRINK, and GLOB. 15000 is typical for THREAD, and a size of 10000 is typical for CLOTH. Has no effect on any other item types. Note: this is not the actual volume of the product, which is hard-coded by the item token.
[PRODUCT_TO_CONTAINER:<id>] Places the product in a container; <id> must be the name of a reagent with the PRESERVE_REAGENT token and a container item type.

Improvements

Improvements are applied to existing reagents. A reaction can have as many improvements as it likes.

Restating this in the above style, we have:

  [IMPROVEMENT:<probability>:<reagent name>:<improvement type>:<material token>]

probability

The percentage chance the improvement will be applied to the reagent when the reaction is completed.

reagent name

The name of the reagent that will be improved. In order to be meaningful, this reagent must have [PRESERVE_REAGENT].

improvement type

The following improvement types can be used:

Token Meaning
COVERED Item is encrusted/studded/decorated with <material>.
GLAZED Item is glazed with <material>.
RINGS_HANGING Item is adorned with hanging rings of <material>.
BANDS Item is encircled with bands of <material>.
SPIKES Item menaces with spikes of <material>.
PAGES Adds pages to a book.

All other item improvement tokens (ART_IMAGE, ITEMSPECIFIC, THREAD, CLOTH, SEWN_IMAGE, and ILLUSTRATION) are ignored.

material token

A material token describing what the decoration will be made of.

If you want the decoration's material to be derived from one of the reagents, you can use GET_MATERIAL_FROM_REAGENT:reagent:REACTION_PRODUCT_ID in place of the material token. You can also specify GET_MATERIAL_FROM_REAGENT:reagent:NONE in order to directly use the reagent's own material.

Other tokens

fuel

The FUEL token means that the reaction requires coke or charcoal to be performed. Fuel is not needed when the reaction is performed at a magma workshop (a magma kiln, magma smelter, or any custom building having [NEEDS_MAGMA]).

skill

The SKILL token determines what skill the reaction requires and what skill it trains. Only one skill may be specified. For custom reactions, the amount of experience gained is linearly correlated with the amount of product created; a reaction with no product will yield no experience for the performing dwarf. Similarly, the amount of time a reaction takes is correlated with experience gained; if a reaction has zero experience gain due to having no skill associated, the reaction will take minimal time.

automatic

The AUTOMATIC token means that the reaction will be queued automatically if the reaction reagents are all present.

This token only works with jobs performed at a kiln, smelter, tanner's shop, kitchen, or custom workshop, and standing orders allow you to limit which ones trigger; custom reactions performed at a quern, millstone[Verify], still[Verify] or craftsdwarf's workshop[Verify] cannot be made automatic.

adventure mode enabled

The ADVENTURE_MODE_ENABLED token means that this version of the reaction is not used by dwarves at home in a fortress, but rather the wanderers of Adventure Mode. When using this token, it will be allowed for adventurers of any race, without editing Entity files.

max multiplier

The [MAX_MULTIPLIER:<#>] specifies how many times to do the reaction. This can be used to limit stacked reagent use to the specified quantity instead of the whole stack.v0.42.01

Reaction classes and products

When you're doing things like tanning hides or brewing alcohol, having separate reactions for every single possible raw material is unwieldy and terrible. However, you can let the reaction itself ask the material for details and process them all with the same reaction. There are three types of tags to dictate this behavior.

Reaction classes

The simplest token is the reaction class. If it is tacked on a material, a reaction can limit reagents to only those materials that have the specified arbitrary [REACTION_CLASS:whatever] identifier.

We want a reaction that smelts iron and flux into pig iron. However, there's half-dozen different stones that count as flux. Instead of clogging up the smelter job menu with half-dozen nearly identical reactions that all take in either dolomite or limestone or marble for the same result, we use a reaction class.

  [REACTION:PIG_IRON_MAKING]
     [NAME:make pig iron bars]
     [BUILDING:SMELTER:NONE]
     [REAGENT:A:150:BAR:NO_SUBTYPE:METAL:IRON]
     [REAGENT:B:1:BOULDER:NO_SUBTYPE:NONE:NONE][REACTION_CLASS:FLUX]
     [REAGENT:C:150:BAR:NO_SUBTYPE:COAL:NO_MATGLOSS]
     [PRODUCT:100:1:BAR:NO_SUBTYPE:METAL:PIG_IRON][PRODUCT_DIMENSION:150]
     [FUEL]
     [SKILL:SMELT]

Note how reagent B asks for "NONE:NONE" as its material. This means "boulders of any kind as long as they have the reaction class named FLUX". Stuff like calcite, here:

  [INORGANIC:CALCITE]
     [USE_MATERIAL_TEMPLATE:STONE_TEMPLATE]
     [STATE_NAME_ADJ:ALL_SOLID:calcite][DISPLAY_COLOR:7:7:1][TILE:'"']
     [REACTION_CLASS:FLUX]
     [ENVIRONMENT_SPEC:LIMESTONE:CLUSTER_SMALL:100]
     [ENVIRONMENT_SPEC:MARBLE:CLUSTER_SMALL:100]
     [MATERIAL_VALUE:2]
     [IS_STONE]
     [MELTING_POINT:12902]
     [SOLID_DENSITY:2930]

The label itself can be absolutely anything. It's only used to find a match between the material and the reaction. Note that some reaction classes have special meanings to the game itself—notably, the site finder knows that "FLUX" should be connected to the "Flux stone" filter.

Material reaction products

But what if it's not all the same what materials the members of the reaction class put out? If a tanner starts working on a bear pelt, a horse hide, some dragon scales and a section of human skin, surely they all can't produce generic boot leather! No, the reaction must get the chance to ask the "reaction class" what the reagent should turn out as. We will declare a material reaction product.

  [REACTION:TAN_A_HIDE]
     [NAME:tan a hide]
     [BUILDING:TANNER:CUSTOM_T]
        [REAGENT:flaps of skin:1:NONE:NONE:NONE:NONE][USE_BODY_COMPONENT][UNROTTEN]
           [HAS_MATERIAL_REACTION_PRODUCT:BOOT_FABRIC]
        [PRODUCT:100:1:SKIN_TANNED:NONE:GET_MATERIAL_FROM_REAGENT:flaps of skin:BOOT_FABRIC]
     [SKILL:TANNER]
     [AUTOMATIC]

Where you'd usually have some fresh bodypart with the BOOT_FABRIC reaction class produce some generic SKIN_TANNED, this goes further. Instead of declaring a material, he spool of pattern-ready tailoring leather (SKIN_TANNED) now comes out as whatever the skin flaps' material reaction product (named BOOT_FABRIC) says in the material's definition (GET_MATERIAL_FROM_REAGENT). And what does it say?

  [MATERIAL_TEMPLATE:SKIN_TEMPLATE]
        [STATE_COLOR:ALL_SOLID:GRAY]
        [STATE_NAME:ALL_SOLID:skin]
        [STATE_ADJ:ALL_SOLID:skin]
        ...
        [ABSORPTION:100]
        [MATERIAL_REACTION_PRODUCT:BOOT_FABRIC:LOCAL_CREATURE_MAT:LEATHER]
        [IMPLIES_ANIMAL_KILL]
        [ROTS]

It says that the caller of the BOOT_FABRIC hook always comes out as the LEATHER of whatever creature the skin has been peeled off of (LOCAL_CREATURE_MAT). Make it BOOT_FABRIC:INORGANIC:GOLD instead and your tanner turns into Midas. Use your imagination.

As with reaction classes, some MATERIAL_REACTION_PRODUCT identifiers have special meanings to the game itself - notably, the site finder knows that "FIRED_MAT" should be connected to the "Clay" filter, and "CHEESE_MAT" is used when making cheese from milk.

Item reaction products

The version 0.40 added an even more powerful form of the above. Where material reaction products can only affect what type of stuff the predestined end product is made of, item reaction products can decide the entire end result ahead of time. Item AND material.

Let's assume for a moment that we're completely tired of leather earrings and hair crowns. We want a crafting reaction that takes cloth and only produces things that make sense.

     [REACTION:TAILOR_THE_BEST_THING]
           [NAME:weave something that makes sense]
           [BUILDING:CRAFTSMAN]
           [REAGENT:woven fabric:1:CLOTH:NONE:NONE:NONE]
              [HAS_ITEM_REACTION_PRODUCT:BEST_OPTION]
           [PRODUCT:100:1:GET_ITEM_DATA_FROM_REAGENT:woven fabric:BEST_OPTION]
           [SKILL:CLOTHIER]

Now we need to come up with the counterpart tags in the materials. Hmmm... cotton is thin and soft, so it makes pretty good undergarments. An undershirt, maybe?

        [PLANT:COTTON] Gossypium hirsutum / sp.
                 [NAME:cotton plant][NAME_PLURAL:cotton plants][ADJ:cotton plant]
                 [USE_MATERIAL_TEMPLATE:STRUCTURAL:STRUCTURAL_PLANT_TEMPLATE]
                 [BASIC_MAT:LOCAL_PLANT_MAT:STRUCTURAL]
                 [DRY][BIOME:ANY_TROPICAL]
                 [VALUE:2]
                 ...
                 [USE_MATERIAL_TEMPLATE:THREAD:THREAD_PLANT_TEMPLATE]
                    [MATERIAL_VALUE:2]
                    [ITEM_REACTION_PRODUCT:BEST_OPTION:ARMOR:ITEM_ARMOR_TUNIC:LOCAL_PLANT_MAT:THREAD]
                 ...

Then jute fabric. Isn't that burlap? And what's about the only thing they make from burlap?

        [PLANT:JUTE] Corchorus capsularis / Corchorus olitorius
                 [NAME:jute plant][NAME_PLURAL:jute plants][ADJ:jute plant]
                 [USE_MATERIAL_TEMPLATE:STRUCTURAL:STRUCTURAL_PLANT_TEMPLATE]
                 [BASIC_MAT:LOCAL_PLANT_MAT:STRUCTURAL]
                 [DRY][BIOME:ANY_TROPICAL]
                 [VALUE:2]
                 ...
                 [USE_MATERIAL_TEMPLATE:THREAD:THREAD_PLANT_TEMPLATE]
                    [MATERIAL_VALUE:2]
                    [ITEM_REACTION_PRODUCT:BEST_OPTION:BOX:NONE:LOCAL_PLANT_MAT:THREAD]
                 ...

Sacks, of course! Wait, how about silk?

        [CREATURE:SPIDER_CAVE]
                 [DESCRIPTION:A tiny underground bug, sought after for its thread.]
                 [NAME:cave spider:cave spiders:cave spider]
                 ...
                 [USE_MATERIAL_TEMPLATE:SILK:SILK_TEMPLATE]
                    [ITEM_REACTION_PRODUCT:BEST_OPTION:PANTS:ITEM_PANTS_THONG:LOCAL_CREATURE_MAT:SILK]
                 ...

This goes on for as long as you let it. The ITEM_REACTION_PRODUCT declares the identifier and then the item and material with subtypes, just like a normal reaction's product line would.

Do note that MATERIAL_REACTION_PRODUCT and ITEM_REACTION_PRODUCT use the same IDs, so you cannot have both a material and item reaction product of the same name. Also, though you cannot use GET_ITEM_DATA_FROM_REAGENT with a MATERIAL_REACTION_PRODUCT (there'd be no item type information), you can use GET_MATERIAL_FROM_REAGENT on an ITEM_REACTION_PRODUCT (in case you want to force your own item type).

Reactions and world generation

There are several things to keep in mind when you're adding reactions to a game that already exists.

  • Most entity changes require a regen, but adding PERMITTED_REACTION tokens for reactions that existed at the time of world generation to the entity file in the save directory do not.
  • Adding reactions to the raws in a save directory requires you to regen the world.
  • You can alter an existing reaction in any way you like without regenning the world, so long as you don't alter the reaction identifier.

Full token list

For the sake of convenience and readability, this is a complete compilation of the previously listed reaction tokens in alphabetical order:

Token Arguments Description
ADVENTURE_MODE_ENABLED this version of the reaction is not used by dwarves at home in a fortress, but rather the wanderers of Adventure Mode. When using this token, it will be allowed for adventurers of any race, without editing Entity files
ANY_BONE_MATERIAL Reagent material must have the [BONE] token.
ANY_HORN_MATERIAL Reagent material must have the [HORN] token.
ANY_LEATHER_MATERIAL Reagent material must have the [LEATHER] token.
ANY_PEARL_MATERIAL Reagent material must have the [PEARL] token.
ANY_PLANT_MATERIAL Reagent material must be subordinate to a PLANT object.
ANY_SHELL_MATERIAL Reagent material must have the [SHELL] token.
ANY_SILK_MATERIAL Reagent material must have the [SILK] token.
ANY_SOAP_MATERIAL Reagent material must have the [SOAP] token.
ANY_STRAND_TISSUE Reagent is made of a tissue having [TISSUE_SHAPE:STRANDS], intended for matching hair and wool. Must be used with [USE_BODY_COMPONENT].
ANY_TOOTH_MATERIAL Reagent material must have the [TOOTH] token.
ANY_YARN_MATERIAL Reagent material must have the [YARN] token.
AUTOMATIC the reaction will be queued automatically if the reaction reagents are all present.
BAG Reagent has to be a bag. Intended to be used with an item type of BOX, to prevent chests, coffers, and other containers from being used instead.
BUILDING
  • Building name
  • in-building reaction hotkey
Sets the building that the reaction will be performed in, and the button used to queue the reaction once that building's menu is accessed in-game
BUILDMAT Reagent is able to be used to build structures (Stone, Wood, Blocks, Bars?).
CAN_USE_ARTIFACT Reagent can be an Artifact. Using [PRESERVE_REAGENT] with this is strongly advised.
CAN_USE_LOCATION_RESERVEDv0.42.01 ?
CATEGORYv0.42.01 Category ID Puts the reaction in a category. Categories are custom submenus for reaction menus. The category ID is a unique identifier for the category. It is only used in the raws, and will not appear in the game.

If you're defining multiple categories within the same reaction - for example, if you intend the reaction to be nested two deep, and haven't yet defined the super-category - the last CATEGORY token within the reaction definition is the one that the reaction will appear in.

CATEGORY_NAMEv0.42.01 String The name of the category as displayed in-game.
CATEGORY_DESCRIPTIONv0.42.01 String If present, when the category is highlighted in a building menu, this string will be displayed in the Helpful Hint box.
CATEGORY_PARENTv0.42.01 Category ID If present, this category will be a submenu of the indicated category, rather than a submenu of the reaction's building.
CATEGORY_KEYv0.42.01 Hotkey token If present, this category can be selected from its parent menu (whether a building or a parent category) using the given hotkey.
CONTAINS required content Reagent is a container that holds the specified reagent.
CONTAINS_LYE If the reagent is a container, it must contain LYE. No longer used - instead, use one reagent for the LYE itself and another reagent with [CONTAINS:lye_reagent].
DOES_NOT_ABSORB Reagent material must have [ABSORPTION:0]
DOES_NOT_DETERMINE_PRODUCT_AMOUNT Performing a reaction with large stacks of inputs can allow multiple sets of outputs to be produced. Setting this flag causes the reagent to be ignored in this process - for example, with the reaction "1 plant + 1 barrel -> 5 alcohol (into barrel)", using this on the barrel allows the reaction to be performed as "5 plant + 1 barrel -> 25 alcohol" instead of "5 plant + 5 barrel -> 25 alcohol".
EMPTY If the reagent is a container, it must be empty.
FIRE_BUILD_SAFE Reagent must be considered fire safe - i.e. not wood, and not coal.
FORCE_EDGE Product is given a sharp edge. Used for knapping.
FOOD_STORAGE_CONTAINER Reagent must be a barrel or any non-absorbing tool with [TOOL_USE:FOOD_STORAGE]
FUEL Requires that the reaction either use up a unit of coal or charcoal or else be performed at a magma workshop
GLASS_MATERIAL Reagent material has [IS_GLASS].
HAS_ITEM_REACTION_PRODUCT PRODUCT_ID (custom) Similar to MATERIAL_REACTION_PRODUCT, but requires the reagen'ts material to have a matching ITEM_REACTION_PRODUCT entry.
HAS_MATERIAL_REACTION_PRODUCT PRODUCT_ID (custom) Similar to REACTION_CLASS, but requires the reagent's material to have a matching MATERIAL_REACTION_PRODUCT entry. Intended for reactions which transform one class of material into another, such as skin->leather and fat->tallow.
HAS_TOOL_USE Tool-use token Reagent must be a tool with the specific TOOL_USE value. The reagent's item type must be TOOL:NONE for this to make any sense.
HAS_WRITING_IMPROVEMENTv0.42.01 Reagent must contain writing.
IMPROVEMENT
  • Probability
  • Reagent Name
  • Improvement type
  • Material Token
Improvement types include BANDS, COVERED, GLAZED, RINGS_HANGING, and SPIKES
MAGMA_BUILD_SAFE Currently broken - behaves exactly the same as FIRE_BUILD_SAFE.
METAL_ORE
  • Inorganic material
Reagent material must be an ore of the specified metal
MIN_DIMENSION
  • size
Requires that the reagent have a dimension of at least this value. Only effective with BAR, POWDER_MISC, LIQUID_MISC, DRINK, THREAD, CLOTH, and GLOB items.
NAME name defines the name used by the reaction in-game
NO_EDGE_ALLOWED Reagent must not be sharpened (used for knapping).
HAS_EDGEv0.42.01 Reagent must be sharpened (used for carving).
NOT_CONTAIN_BARREL_ITEM If the reagent is a Barrel, it must not contain an item that has to reside in a barrel. Barrel items appear to be lye and milk. Alcohol appears to be covered as part of [EMPTY]. A reaction which places an item in a barrel should probably have both tags.
NOT_ENGRAVED Reagent must not be an engraved memorial slab.
NOT_IMPROVED Reagent has not been decorated.
NOT_PRESSED Reagent must not be in the SOLID_PRESSED state.
NOT_WEB Reagent must be "collected" - used with THREAD:NONE to exclude webs.
POTASHABLE Alias for CONTAINS_LYE.
PRESERVE_REAGENT Reagent is not destroyed, which is the normal effect, at the completion of the reaction. Typically used for containers.
PRODUCT
  • Probability of success (%)
  • Quantity
  • Item token:subtype
  • Material token:subtype
Defines a thing that comes out of the reaction. GET_MATERIAL_FROM_REAGENT and GET_ITEM_DATA_FROM_REAGENT can be used to defer the choice of material and/or item to the appropriate tag in a given reagent's material - the former comes in place of the material token, the latter replaces both the item and material tokens. See above for detailed information on how the hooks work.
PRODUCT_DIMENSION size Specifies the size of the product. A size of 150 is typical for BAR, POWDER_MISC, LIQUID_MISC, DRINK, and GLOB. A size of 15000 is typical for THREAD, and a size of 10000 is typical for CLOTH.
PRODUCT_PASTE Product is created in the SOLID_PASTE state.
PRODUCT_PRESSED Product is created in the SOLID_PRESSED state.
PRODUCT_TO_CONTAINER Reagent ID Places the product in a container; <id> must be the name of a reagent with the PRESERVE_REAGENT token and a container item type.
PRODUCT_TOKENv0.42.01 name Allows the product to be referred to by the given name, for the purpose of being passed down as argument in other tokens.
REACTION Identifier defines a new reaction
REACTION_CLASS CLASS_ID (custom) Requires the reagent's material to have a matching REACTION_CLASS entry. Intended for reactions which accept a variety of materials but where the input material does not determine the output material, such as FLUX (for making pig iron and steel) and GYPSUM (for producing plaster powder).
REAGENT Requires a given reagent as an input for a reaction
SKILL Skill Token Skill used by the reaction
TRANSFER_ARTIFACT_STATUSv0.42.01 Transfers artifact status from the reagent to the product.
UNROTTEN Reagent must not be rotten, mainly for organic materials.
USE_BODY_COMPONENT Reagent material must come off a creature's body.
WEB_ONLY Reagent must be "undisturbed" - used with THREAD:NONE to gather webs.
WORTHLESS_STONE_ONLY Reagent is not made of an economic stone.