Hi everyone. I’m fairly new to DF (started my first fort a month or two before the v0.40.01 release, after extensive study of the wiki) so this is going to be big, and answer lots of people at once.
I have also considered this issue, and independently arrived at the xenosynthesis conclusion (though not the word) before I found the forums.
The basis comes back to Conservation of Energy, which NW_Kohaku made brief reference to in the original post, and somewhat more extensive reference to in the parent “Improved Farming” thread. The basic issue is that hard science methods of energy transfer do not supply nearly enough input to the caverns to support the abundant and diverse flora and fauna observed. There must be something else going on. The proposed solution was a magical “xenosynthesis energy” (XE) that cavern plants can use instead of light.
As described, XE is sphere-aligned, and most things that use it can only use certain spheres. It is also ambient in the environment: plants and animals put into and draw from a common “pool” of XE associated with the location itself, rather than any particular object in it.
I actually arrived at the magical energy source by way of [NO_EAT] creatures like undead. To respect Conservation of Energy, such creatures need to consume something to support their activities. Cavern plants using the same energy source was a development from that.
As I understand it, xenosynthesis is a way of supporting and enforcing Conservation of Energy. This description has implications for how it should be implemented.
1. Cavern plants consume XE as they grow. This isn’t to say that cavern plants can’t generate XE, but, to respect Conservation of Energy, they must consume (much) more than they produce. When they do produce XE, it may often be of a different sphere than what they consumed (for example, nether caps might consume XE of sphere Volcanoes and produce XE of sphere Frost or Caverns).
2. More precisely, xeno plants consume XE. Xeno plants have the distinction of being able to grow without light (underground in the caverns), but its presence will not necessarily interfere. In other words, cavern plants are xeno, but the reverse is not necessarily true. On the other hand, “light” also serves as a proxy for outside weather, which includes wide variations in temperature and humidity, much stronger wind, precipitation impacts (rain, snow, and hail) and other effects that xeno plants, adapted to the gentler conditions underground, may find overly hostile.
3. Certain creatures (including, but not limited to, [NO_EAT] ones) will also consume XE. I see a solution involving most of the same code as the current [GRAZER] token: the creature consumes one point of XE from the region to reduce “hunger” by an amount that varies with the creature. For that matter, the current [CARNIVORE] and [BONECARN] tags could also work with hunger just as easily, but that’s a matter for another thread.
4. The suggestion has been raised (rather extensively on page 1 of this thread) that certain player (or, more generally, civilization) actions should align the area to relevant spheres (in other words, generate XE of those spheres). Semi- and megabeasts might also generate XE for their spheres. Once deities are implemented better, temples and/or sacrifices to a deity might also generate XE for spheres claimed by that deity. This is all well and good, but nowhere near enough to sustain the cavern biosphere.
5. On page 6 of the thread, NW_Kohaku raised the idea of making certain plants magic fountains and magic sinks. This is something I can work with. Cavern plants and certain creatures are the magic sinks, as described above.
6. On the other hand, surface plants have access to mundane sunlight. With this source of energy, they can produce more XE than they consume. They become the (primary) magic fountain that sustains the caverns.
7. Cavern life may include fungi, which consume biological material and could also produce more XE than they consume. Certain animals may similarly help.
8. With both sources and sinks inherently present, a large amount of XE on the surface will tend to produce or attract a correspondingly large amount of things that consume it: xeno plants will grow more vigorously, and animals will move in (and, over the long term, both will produce more offspring). This negative feedback means that, as a rule, tilting the ecosystem’s magical alignment is quite difficult, and generally will not occur without a deliberate attempt by the player. I consider this a good thing: players that don’t want to deal with this usually don’t have to.
9. With the sources and sinks established, there must be some implementation of how XE gets from the surface to the caverns. In partial acknowledgement to jseah (page 1), my idea is that each region tile (48x48 game tiles), or possibly a larger area, has a counter for how much XE it contains. XE is thus tracked by sphere and by (horizontal) region. One number applies at all z-levels, with no vertical tracking at all.
10. To permit sphere alignments to spread horizontally and have smooth gradients, plants (and possibly creatures) can draw XE from regions adjacent to the one they are actually in, or possibly even a larger radius. This avoids the need to figure out how quickly and under what circumstances XE can flow around. It can simply be produced and consumed in place.
Having settled on the explanation that XE is (primarily) produced by certain plants, a new question emerges: How is outputting XE beneficial? This seems like the plant is simply wasting energy it could use. I do have a suitable chain of events that respects natural selection. It does not, however, respect mutation. Since we are dealing with magic anyway, certain events will simply occur “By the Gift of Armok.”
1. By the Gift of Armok, a plant gains the ability to produce XE. This plant DOES NOT simply export it to the environment. The energy is stored within its own tissues. Like the sugar and other molecules used by mundane plants, XE can be consumed during night (when sunlight is not available) and, for perennials, winter. Under this system, the XE is only released into the region at large after (that part of) the plant dies.
2. The plant contains magical energy, and this has implications for herbivores. Most can’t use the XE. When mundane herbivores eat the magical plant, the XE is released into their bodies in an uncontrolled way, and causes an unpleasant and possibly dangerous syndrome. The details obviously vary depending on sphere.
3. This opens a second, indirect use for XE: selectively remove or release it to steer herbivores to low-value parts of the plant, especially parts that were about to be dropped anyway. For example, deciduous trees may release XE in fall as their leaves change color.
4. By the Gift of Armok, an herbivore gains the ability to use the new type of energy. In addition to the direct benefits of XE as an energy source, this ability enables that herbivore to consume the formerly protected plant parts without any competition from its fellows.
5. The XE, being magical, has other beneficial effects on the creature, which again vary by sphere. Fire-aligned XE may allow it to tolerate heat better and possibly use fire attacks; Fae-aligned XE may allow the creature to grow larger. Regardless of the exact details, creatures that can use XE will out-compete those that can’t, and the ability is presumed to have a genetic basis. This obsoletes the previous claim that most herbivores can’t use XE.
6. These effects prompt herbivores to target parts of the plant where XE is stored, which applies a new selective pressure on the plant, opposite that of mundane herbivores. The plant is prompted to store XE in otherwise low-value parts, and might even store XE in fruit.
This description has gameplay implications.
1. I don’t recommend giving each plant an XE counter. Instead, its XE is released when certain things happen to it. At the very least, brewing, milling, or threshing the plant will release its XE into the region, as defined in plant and/or reaction raws. Relevant analogue in the current game: seeds. The reaction raws define that a seed is produced, and plant raws specify which seed.
2. Fruit (and possibly other plant parts) can contain XE in portable form. Intelligent creatures which require XE (such as necromancers) can carry appropriate types of fruit with them. A player wishing to terraform his/her site can also import and use suitable plants. This also has implications for alchemy. It might also open certain exploits with prepared meals.
3. To permit the “feed the caverns” purpose that started this thread, all (surface) trees will need to drop leaves periodically, and preferably dead branches (gathered as logs and possibly sticks). Both events release XE, if the plant is of the right type. Shrubs and crops will also release XE when they wither in the field. Chopping down a tree will drop a large number of logs (and leaves) at once, which releases a correspondingly large amount of XE.
4. Tropical regions will, as a rule, produce a steady trickle of XE to the caverns (wet and dry seasons will impact this). Temperate regions have the fall season, when all the deciduous trees drop all their leaves at once, and the winter when many shrubs die. Most of the XE release will occur during these times. This arrangement provides seasons to the caverns (as NW_Kohaku suggested on page 5 of this thread). The cavern spring season occurs during the surface fall, and the others follow, half a cycle out of phase with the surface.
5. Going back to the religion comment above, temples and the like will produce XE, generated by certain activities there. This may simply be released into the region at large, or be retained in a separate pool associated with the temple itself. I recommend the latter, to save on memory: a temple might plausibly use any of the spheres in the game (I counted 131 in the list on the wiki), but only a small fraction are “ecosystem” spheres likely to be widespread enough to be usable by xeno plants (I wound up with about two dozen; details to follow at some point in the “Organizing the Spheres” thread). The regions in general only need to track “ecosystem” spheres. The temple is in a particular region, and intelligent (and possibly non-intelligent) creatures can draw from the temple pool in the same way as that region one.
6. Certain other workshop tasks might also generate XE, such as a forge generating Metals and Fire (or Volcanoes for a magma forge) XE when used. As with temples, XE can be either released into the region or kept at the workshop. While the total list of spheres is quite long, the list relevant to any given temple tops out at a dozen or so, and almost any other building tops out around half that. A somewhat more programming-intensive but even more memory-saving solution is to release XE of the “ecosystem” spheres and retain the rest.
Implications part 2: Magical creatures
1. Creatures that can use XE will have a personal XE pool, separate from that of the region. They can fill it either by eating a plant that contains XE (the [NO_EAT] token may or may not prevent this), or more directly from the ambient pool. Death of the creature probably releases its energy into the region pool.
2. A creature that requires XE to avoid hunger can draw from its personal pool, or that of the surrounding region. The creature’s personal pool probably has a maximum size, and it can release XE into the environment when this fills up.
3. Wizards (starting with the necromancers already in the game) will use XE to power their spells. A wizard can draw from the region pool, from his own personal pool, from a sufficiently close (and suitably aligned) temple or other building, or from some inanimate object in his possession which contains XE, such as the fruit described above (this would consume the fruit).
4. This also opens another parameter in which magical secret types can vary: the size of personal mana pool it gives the wizard. Necromancers are [NO_EAT], which, given the above and their current sphere alignment, means they consume Death XE and will starve if deprived of it long enough. A necromancer with a larger personal XE pool, in addition to simply lasting longer, will be able to throw more spells around (animate more dead creatures he finds around your fort) without support from his base. This makes him a much more dangerous sieger.
Implications part 3: Magically Altered creatures
1. On the main Bay12 Dwarf Fortress page is a tab for “Threetoe’s Stories.” One in particular, titled “Forest Befouled” describes an area changing sphere alignment (from Good to Evil). This has a very curious effect: the satyrs (Good-aligned) living in the area transform to foul blendecs (Evil-aligned).
2. A different story, titled “Root,” has a scene where a squirrel is transformed by the Forest Spirit into a squirrel man. These two scenes lead to the question of exactly how to duplicate this behavior in the game.
3. The game already has the [APPLY_CREATURE_VARIATION] command, found in the raws of certain creatures. It can accept the arguments “animal person” and “giant” (and various “gaits” that are off this topic). Duplicating the behavior from “Forest Befouled” and “Root” would involve re-working this tag. The creature raws would instead say something like “Accept creature variation” and there would be some circumstances in the game under which it could be applied. To duplicate the events of “Forest Befouled,” Satyr and Foul Blendec would be different variations applied to the same mundane base creature (probably a goat).
4. Toady One has stated a desire for less-predictable magic, and this system can accommodate that: creature variations can be procedurally generated, and acceptance by creatures can be based on tags attached to the variation, rather than directly by its name.
5. “Forest Befouled” also requires circumstances under which a creature variation can be removed. A partial solution is a “hunger” counter associated with the variation, separate from that of the creature it is attached to. When this runs out, the variation wears off and the creature reverts to its mundane state. This supports the general “The Magic Goes Away” tone of Dwarf Fortress (Ages of Myth, Legends, and Heroes), but the immediate change described in the story would require different programming, which I don’t know enough to advise about.