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.

Creature variation token

From Dwarf Fortress Wiki
Revision as of 19:49, 7 November 2021 by 213.55.244.74 (talk)
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.

Creature variations are used to create creatures which are derived from another already-existing creature without having to duplicate every single token. They are defined as CREATURE_VARIATION objects, and the default variations are defined in c_variation_default.txt

From the raws:

Order of application: Remove tags are applied starting from the bottom, then convert tags from the bottom, then add tags from the top.

Arguments: If APPLY_CREATURE_VARIATION in the creature raws sends in arguments, you can use them below as !ARG1, !ARG2, etc. The GAIT variations below have some examples. In the creature raws, if an argument is of the form "5|6", for example, it'll be converted to "5:6" in the creature variation, so you can handle variable-token arguments with the | character.

Conditional tags: Change TAG to CTAG and add, for example, CV_REMOVE_CTAG:1:YES:<regular stuff> to require !ARG1 to be YES to execute the changes.

Token Arguments Description
CV_NEW_TAG
  • token (plus any additional parameters)
Adds a new token to the creature's variant.
CV_ADD_TAG
  • token
Alias for CV_NEW_TAG.
CV_REMOVE_TAG
  • token
Removes a token from the creature's variant.
CV_NEW_CTAG
  • ARG number
  • token
As CV_NEW_TAG, but only activates if !ARG(num) is YES, e.g. CV_NEW_CTAG:1:YES:<regular stuff> to require !ARG1 to be YES to execute the changes.
CV_ADD_CTAG
  • ARG number
  • token
Alias for CV_NEW_CTAG.
CV_REMOVE_CTAG
  • ARG number
  • token
As CV_REMOVE_TAG with conditions as described above.
CV_CONVERT_TAG Begins altering tokens within the creature's variant using the CVCT_MASTER, CVCT_TARGET, and CVCT_REPLACEMENT tokens below. If a variation template contains multiple CV_CONVERT_TAG blocks for the same CVCT_MASTER, the replacements will be applied in reverse order.
CVCT_MASTER
  • token
Specifies the token that will be modified.
CVCT_TARGET
  • value
Locates the specified parameter within the token specified by CVCT_MASTER.
CVCT_REPLACEMENT
  • value
Replaces the parameter specified by CVCT_TARGET within the token specified by CVCT_MASTER. If no replacement is specified, the target will simply be removed.
CV_CONVERT_CTAG As CV_CONVERT_TAG with conditions.

Creature variations are templates that creatures (CREATURE objects) may use.

Creature variations are not the only kind of templates for creatures, there are also tissue templates (TISSUE_TEMPLATE objects using tissue definition tokens, material templates (MATERIAL_TEMPLATE objects using material definition tokens), and body detail plans (BODY_DETAIL_PLAN objects using body detail plan tokens). Creature variations are the newest one of these, from 2009, and also the most advanced of the four. The reason they are called "creature variations" is presumably because they were initially made for the giant animals and animal people, variations of existing creatures, but this name is misleading. Creature variations are very general type of template, and creatures using creature variations do not need to be based on any other like the giant animals and animal people are. More examples will be given below, but creature variations are already used in the vanilla raws for gaits and (sometimes) attacks.

Chapter 1 - How to use creature variations, and their basic tokens: Creature variations may be used in two ways. They may either appear as fully fletched CREATURE_VARIATION objects in their own files (the default being c_variation_default.txt) and called using APPLY_CREATURE_VARIATION, or their tokens may live "freely" inside creature raws and called use APPLY_CURRENT_CREATURE_VARIATION. The latter is for when you would like to use the powers of creature variations, like removing tokens or "converting" parts of them, without having to define a new object for it. There are 11 creature definition tokens (not counting those applying them, they are creature tokens, being called on the creature level), but almost half of them are copies of the other with the difference that they are "conditional" (see Chapter 2), and as three of them are there for the completion of another one (and it's conditional twin), really there are only 3 functions performed by the creature variations: adding tokens, removing tokens, and "converting" tokens.

Adding tokens is done using CV_NEW_TAG or CV_ADD_TAG. CV_NEW_TAG takes any token (with arguments) as its own argument and adds it to the target creature. CV_ADD_TAG is seemingly an alias for CV_NEW_TAG, so it is unclear why they both exist. E.g. [CV_NEW_TAG:BIOME:ANY_FOREST] gives the creature [BIOME:ANY_FOREST].

Removing tokens is done using CV_REMOVE_TAG. CV_REMOVE_TAG takes whole token (names and) arguments, and removes tokens that start that way. So [CV_REMOVE_TAG:BODY:HUMANOID_SIMPLE] would remove [BODY:HUMANOID_SIMPLE:3_EYES], but [CV_REMOVE_TAG:BODY:3_EYES] would not. Neither would [CV_REMOVE_TAG:BODY:HUMANOID_SIMPLE] be able to remove [BODY:HUMANOID_SIMPLE_NECK:3_EYES], as it looks for whole arguments. [CV_REMOVE_TAG:BODY] would remove all examples above, as they start with "BODY".

"Converting" tokens is done using CV_CONVERT_TAG, CVCT_MASTER, CVCT_TARGET, and CVCT_REPLACEMENT. These are used in a block, with one of each in each block. CV_CONVERT_TAG starts the block. CVCT_MASTER selects which tokens may be converted, by looking at full arguments at the start of said token (like CV_REMOVE_TAG). If no CVCT_MASTER is given, it is given no arguments, or the only argument it is given is blank (i.e. [CVCT_MASTER:]), all tokens of the target creature are selected. CVCT_TARGET and CVCT_REPLACEMENT are a search-and-replace for strings within the selected tokens. This means the targeted part of a token can be changed anywhere in the token, so e.g. Code: [Select]

[CV_CONVERT_TAG] [CVCT_MASTER:BODY] [CVCT_TARGET:2EYES] [CVCT_REPLACEMENT:2EYESTALKS]

would affect both [BODY:QUADRUPED_NECK:2EYES:NOSE:2LUNGS:...] and [BODY:INSECT:2EYES:HEART:GUTS:BRAIN:MOUTH:2WINGS], converting them into [BODY:QUADRUPED_NECK:2EYESTALKS:NOSE:2LUNGS:...] and [BODY:INSECT:2EYESTALKS:HEART:GUTS:BRAIN:MOUTH:2WINGS] respectively. Colons can be included as part of both the target and the replacement string, e.g. given Code: [Select]

[CV_CONVERT_TAG] [CVCT_MASTER:BODY] [CVCT_TARGET:BASIC_1PARTBODY:BASIC_HEAD] [CVCT_REPLACEMENT:HUMANOID:3FINGERS]

and [BODY:BASIC_1PARTBODY:BASIC_HEAD:HEART:GUTS:BRAIN:MOUTH:2EYESTALKS], you will get [BODY:HUMANOID:3FINGERS:HEART:GUTS:BRAIN:MOUTH:2EYESTALKS]. All occurrences of the target string are replaced, e.g. given Code: [Select]

[CV_CONVERT_TAG] [CVCT_MASTER:DESCRIPTION] [CVCT_TARGET:TRAIT] [CVCT_REPLACEMENT:modderiffic]

and [DESCRIPTION:This is an example creature. It is TRAIT, very very TRAIT.], you will get [DESCRIPTION:This is an example creature. It is modderiffic, very very modderiffic.]. If no CVCT_TARGET is given, it is given no arguments, or the only argument it is given is blank (i.e. [CVCT_TARGET:]), the game will freeze when loading the creature. If no CVCT_REPLACEMENT is given, the target string is simply removed.

Creature variations have an unusual order of application. First, remove tokens are applied (bottom-up according to Toady's notes, but I don't think this could affect anything). Then, convert tokens are applied bottom-up (in "reverse" order). Finally, add tokens are applied from the top. This means that CV_REMOVE_TAG won't remove any token added by the same creature variations. It is also why more general conversions can (must) be higher up when overlapping CVCT_MASTERs are used. If they were not read bottom-up, e.g. Code: [Select]

[CV_CONVERT_TAG] [CVCT_MASTER:BODY] [CVCT_TARGET:QUADRUPED] [CVCT_REPLACEMENT:HUMANOID]

would convert [BODY:QUADRUPED_FRONT_GRASP:...] and [BODY:QUADRUPED_NECK:...] into [BODY:HUMANOID_FRONT_GRASP:...] and [BODY:HUMANOID_NECK:...] respectively, before Code: [Select]

[CV_CONVERT_TAG] [CVCT_MASTER:BODY] [CVCT_TARGET:QUADRUPED_FRONT_GRASP] [CVCT_REPLACEMENT:HUMANOID] [CV_CONVERT_TAG] [CVCT_MASTER:BODY] [CVCT_TARGET:QUADRUPED_NECK] [CVCT_REPLACEMENT:HUMANOID_NECK:3FINGERS]

could convert them into the expected [BODY:HUMANOID:...] and [BODY:HUMANOID_NECK:3_FINGERS:...].

APPLY_CURRENT_CREATURE_VARIATION takes all creature variation tokens before it in the creature raws (and after previous APPLY_CURRENT_CREATURE_VARIATION tokens, if they exist) and applies them. When tokens are added through APPLY_CURRENT_CREATURE_VARIATION, they are added in the place of APPLY_CURRENT_CREATURE_VARIATION.


Chapter 2 - Arguments and conditional tokens: APPLY_CREATURE_VARIATION may be given arguments. These arguments will replace instances of "!ARGn", where n is the index of the argument given to APPLY_CREATURE_VARIATION; the first argument will replace any "!ARG1", the second any "!ARG2" and so on. You may use any number of arguments**. If you have an "!ARGn" of a higher number than the argument given the replacements will act oddly, depending on if n has more digits than the number of arguments given. E.g. [APPLY_CREATURE_VARIATION:EXAMPLE_CV:one:two:three], which has three arguments given, will leave all "!ARG5" in EXAMPLE_CV intact as "!ARG5", but "!ARG10" will become "one0".

The pipe character "|" is turned into ":" when inserted, so single arguments in APPLY_CREATURE_VARIATION may be turned into multi-argument segments in the output. E.g. given Code: [Select]

[CREATURE_VARIATION:DIMORPHIC_FEATHER_COLORS] [CV_NEW_TAG:SELECT_CASTE:FEMALE] [CV_NEW_TAG:SET_TL_GROUP:BY_CATEGORY:ALL:FEATHER] [CV_NEW_TAG:TL_COLOR_MODIFIER:!ARG1] [CV_NEW_TAG:TLCM_NOUN:feathers:PLURAL] [CV_NEW_TAG:SELECT_CASTE:MALE] [CV_NEW_TAG:SET_TL_GROUP:BY_CATEGORY:ALL:FEATHER] [CV_NEW_TAG:TL_COLOR_MODIFIER:!ARG2] [CV_NEW_TAG:TLCM_NOUN:feathers:PLURAL] [CV_NEW_TAG:SELECT_CASTE:ALL]

and [APPLY_CREATURE_VARIATION:DIMORPHIC_FEATHER_COLORS:BROWN|1:BLUE|10|GREEN|1|BLACK|1] we get Code: [Select]

[SELECT_CASTE:FEMALE] [SET_TL_GROUP:BY_CATEGORY:ALL:FEATHER] [TL_COLOR_MODIFIER:BROWN:1] [TLCM_NOUN:feathers:PLURAL] [SELECT_CASTE:MALE] [SET_TL_GROUP:BY_CATEGORY:ALL:FEATHER] [TL_COLOR_MODIFIER:BLUE:10:GREEN:1:BLACK:1] [TLCM_NOUN:feathers:PLURAL] [SELECT_CASTE:ALL]

as the tokens added to the target creature.

The conditional tags (CV_NEW_CTAG/CV_ADD_CTAG, CV_REMOVE_CTAG and CV_CONVERT_CTAG) are copies of CV_NEW_TAG/CV_ADD_TAG, CV_REMOVE_TAG and CV_CONVERT_TAG, except they only work if a numbered argument of APPLY_CREATURE_VARIATION has an arbitrary value. E.g. [CV_NEW_TOKEN:2:HUMANOID:CAN_SPEAK] will only add [CAN_SPEAK] if argument number two is "HUMANOID". CV_CONVERT_CTAG still uses CVCT_MASTER, CVCT_TARGET, and CVCT_REPLACEMENT.