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.

User:Vasiln/Build order

From Dwarf Fortress Wiki
< User:Vasiln
Revision as of 02:19, 17 March 2012 by Vasiln (talk | contribs)
Jump to navigation Jump to search

I once did some careful examination of a creature triggering a pressure plate linked to various buildings built either before or after the pressure plate. I added those findings to the pressure plate page. However, some of the things I found felt inconsistent with Hussell's findings regarding build order. In particular, he found that build order of gear assemblies affected the period of his repeaters, whereas I found that gear assemblies were always triggered on the same tick, regardless of whether they were built before or after the triggering pressure plate.

That's always kind of bothered me, but I think I have a hypothesis that explains it.

The Grand Unified Hypothesis of Build Order

Every tick, the game evaluates every creature and building in sequence. Here's the order in which it does so (according to my hypothesis):

  • 1) Every creature checks its speed to determine whether it can move to the next tile in its path. If it can, it moves. If its next tile is occupied or inaccessible, it recomputes path.
  • 2) Power needs are computed for power generators. If power needs are greater than power output, power generators are considered unpowered. (This one requires a lot of research).
  • 3) Every variable-state building is evaluated (more on this later).
  • 4) Every tile of water is evaluated to determine whether it should flow (or maybe teleport), and it does so, if it should.

The important part of this is step 2. In particular, buildings are evaluated in the reverse order to which they were built. If you build a pressure plate, then a door, the game will first run the door's think function, then run the plate's think function.

Here are the think functions for various variable state buildings, as far as I can tell:

Door

  • If a close signal has been generated for this door, close the door. (Note that the door doesn't itself evaluate open signals.)

Pressure plate

  • If triggering criteria are met, and the device most recently sent a close signal, send an open signal. Additionally, open any doors or hatches linked to this pressure plate, and toggle any linked gear assemblies.
  • If triggering criteria are met and the device most recently sent an open signal, don't do anything, except remember this tick.
  • If triggering criteria are not met, and it has been exactly 99 ticks since triggering criteria were met, send a close signal. Additionally, toggle any linked gear assemblies.
  • If triggering criteria are not met, and it has been greater than or less than 99 ticks since triggering criteria were met, don't do anything.

Bridge

  • If no open or close scheduled for this device, check for a signal. If open, schedule an open in 100 ticks. If close, schedule a close in 99 ticks.
  • if no signal, or an open or close is already scheduled, don't do anything.

Screw Pump

  • If the pump is adjacent to a powered gear assembly, there is fluid in its intake tile, and there is no fluid in an acceptable output tile, destroy the water in its intake tile and generate an equivalent amount of water in the first acceptable output tile.
  • Otherwise, don't do anything.

Gear Assembly

  • If gear assembly is adjacent to a device with power and is engaged, consider this tile powered.
  • If gear assembly is not adjacent to a device with power or is not engaged, do not consider this tile powered.

Other Furniture

I believe that the think functions described earlier apply to all other forms of furniture. Hatches use the same think function as doors. Grates, bars, and floodgates use the same think function as bridges. Levers require a special note: I believe they function the same way as a pressure plate. However, there's a chance that the dwarf pulling them actually sends the signals, in which case you would expect to see levers functioning as if they were always built before the furniture they trigger.

How this reconciles Hussell's clock and my goblin repeater

This model of build order demonstrates how a gear assembly can both be engaged at the end of a tick, yet a pump attached to that gear assembly may or may not yet be powered, based on the order in which the two components were built. That disconnect between my data and Hussell's been bothering me, and this hypothesis explains both results.

Predictions

Now that I've got a working hypothesis (including bits that I'm not very sure of, for instance, exactly when non-dwarves are evaluated, exactly how power is evaluated, exactly when flow is evaluated), it's time to make some predictions.

Validated Predictions

Dropping a dwarf takes 7 ticks

Creatures fall at a constant rate of 6 ticks. However, when you drop a dwarf, it takes 7 ticks for the dwarf to fall the first z-level. This, according to my hypothesis, is because the dwarf doesn't know the ground isn't there during the tick the floor disappears, because the ground doesn't disappear during the dwarf's think, it disappears later, during the hatch's think.

Testable Predictions

Screw pumps and pressure plates

The following design, seen from the side, can behave multiple ways, depending on build order.

# %% #  Return pump
# %%^#  Feed pump, plate (1+/7 water)
# ####  7/7 reservoir
###
  • 1) Build return, feed, then plate. Plate doesn't trigger. Water is moved first from the feed, then to return, and stays in the reservoir.
  • 2) Feed, return, then plate. Plate doesn't trigger first tick, but triggers on the next tick. Water is moved first from the return, then the feed, and so stays on top of the pressure plate.
  • 3) Return, plate, then feed. Plate triggers, although water remains in the reservoir.
  • 4) Feed, plate, then return. Plate doesn't trigger, although water remains on top of the plate.
  • 5) Plate, return, feed. Plate doesn't trigger, and water remains in the reservoir.
  • 6) Plate, feed, return. Plate triggers, and water stays on top of the plate.

Those are the predictions. Time to test!

Findings

I forgot to take gravity into account in my predictions. Water takes a certain amount of time to fall, and until it falls fully into the reservoir, it cannot be pumped back by the feed. This changes where we expect water to sit, but it doesn't change our predictions regarding pressure plate activation.

  • 1) Plate doesn't trigger. Water stays in the reservoir side. Meets predictions.
  • 2) Plate triggers. Water stays mostly in the reservoir side. That's because it takes time to fall to get pumped by the feed again. I missed the first tick, can't say whether it only triggered on the second tick.
  • 3) Plate doesn't trigger. Doesn't meet predictions. Will rebuild to verify.
  • 4) Plate triggers. Doesn't meet predictions. Will rebuild to verify.
  • 5) Plate doesn't trigger.
  • 6) Plate triggers.

Note that both feed and destination tiles are muddy. I'll DFHack unmuddy them to see if water is actually never touching a the ground on the machines.