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.

Difference between revisions of "v0.31:Computing"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(Undo revision 89953 by SL (Talk))
Line 1: Line 1:
 
{{av}}
 
{{av}}
 
{{human}}
 
{{human}}
Mechanical logic is a discipline of {{l|Computing|Computing}} which uses axles, gears, {{l|power|power}}, and load to perform logical computations and turn power on and off. At present, to convert a power output into a link signal output such as most dwarven devices (bridge, door, hatch, cage, etc) can use, you would need to build a power -> signal converter (aka "rotation sensor") out of a pump and pressure plate with (currently, no other designs have been made) an unlimited water source and drain - one for each gate.
+
Computing in dwarf fortress is the practice of setting up complex constructions to perform logical operations and calculations, ideally to control some functionality of your fortress. Even if it isn't a young concept anymore, there is still lots of room for improvement and development. One reason is that there are many ways to solve one problem. Innovation and invention is encouraged.
 +
=== Binary information ===
 +
Binary information can have one of two possible states: true or false, respectively 1 or 0. In dwarf fortress they can be represented by different entities:
 +
* on/off state or signal of a [[DF2010:trigger|trigger]] (pressure plate, lever)
 +
* power or connection state of a [[DF2010:machine component|machine component]]
 +
* open or closed state of a [[DF2010:door|door]] or similar buildings
 +
* [[DF2010:pressure plate|low/high]] or [[DF2010:flow|flowing/standing]] [[DF2010:water|fluid]]
 +
* present [[DF2010:creature|creature]]s and [[DF2010:dwarf|borgs]]
  
The principles powering mechanical logic are simple: Gears linked to {{l|trigger|triggers}} will be disconnected when they receive an OFF signal. In this manner, you can conditionally attach either power supply (windmills or waterwheels) or load (additional gears or pumps) to a linked gear in various configurations in order to build logic gates.
+
Electronic devices and computers base on this elementary form of information, and if you want to go into computing, you’ll have to familiarize yourself with it. [http://en.wikipedia.org/wiki/Propositional_calculus propositional calculus]
 +
=== Input/Output ===
 +
Input can be any device which can be linked to another device with mechanisms, such as [[DF2010:lever|levers]] or [[DF2010:pressure plate|pressure plates]]. Pressure plates can measure water, magma, or creature weight, and can be set to react to your own dwarves if measuring creature weight. If measuring water or magma you specify the minimum and maximum levels at which it should output 'on', and at all other levels it will output an 'off' signal. Regardless of the actual amount of water, magma, or creature weight on your pressure plate, the plate can only output an 'on' or 'off' signal (1 or 0) to whatever devices it is linked to. So everything you build will have a binary base.
  
One of the weaknesses of mechanical logic is the substantial amount of materials it tends to require to construct the power and load devices, as well as the gears and axles making up the gates and connecting them to their outputs.
+
====Input elements====
 +
* manual: [[DF2010:lever|lever]] -> binary on/off signal
 +
* triggered: [[DF2010:pressure plate|pressure plate]] -> binary on/off signal
  
==Mechanical signal-input power-output gates==
+
According to input, output can be anything that is able to react to an on/off signal. This can be doors, bridges, floodgates allowing or stopping flow, gears controlling pumps and much more. In some special configurations - when [[DF2010:mechanical logic|mechanical logic]] is involved - output may not be a on/off signal but power, thus running or not running a machine component.
* These gates can be used either by adding a power -> link signal converter (also known as a "rotation sensor"), or directly used to control pumps, such as in other logic gates (the unsourced fluid logic gates use these, for instance). The conventional "rotation sensor" consists of a pump powered by the gate's OUTPUT gear, pumping an infinite supply of water onto a water-sensing pressure plate with an infinite drain.
 
* There are certain things important to all the gates:
 
* Each gate has an OUTPUT gear, which will be placed next to a pump which the gate will control.
 
* In diagrams, the OUTPUT gear is below the 'O' gear, connected to it by gears or vertical axles. The P indicates where you should hook power up, and L indicates where load (gears or pumps that don't have a water source) should be connected, and ¦ and - are horizontal axles. The Is are gears linked to INPUTs (some gates have one input, but most have two).
 
* Gates which incorporate a NOT will have the power network branch off from the 'O' gear, and have a train of power-draining stuff connected to the input gears, whereas gates which do not incorporate a NOT will have the power connected to the input gears instead. The principle behind normal gates is that when the INPUTs are ON, power is connected. The principle behind the NOT gates is that power is always connected, but when the INPUTs are ON, a large enough power requirement is connected to send the power requirements above the power supply, shutting down the system.
 
* If your windmills produce no power, you'll have to come up with some way to use water wheels for power instead.
 
* You should build only enough windmills (or water wheels) to power the system, and should not connect the network for one gate to another gate's network, since that would both gates up.
 
* The gates' instructions will explain how much load and power you need to have at each P and L in the more complicated gates.
 
  
===Legend===
+
Currently to convert from power to an on/off signal, the only way is to use a screw pump connected to that power source with an unlimited amount of water and drainage at the output, and a pressure plate to measure whether water is being pumped out by the pump.
{| class="wikitable" border="1"
+
 
 +
====Output elements====
 +
* signal: [[DF2010:pressure plate|pressure plate]] -> binary on/off signal -> linkable Object(s)
 +
* power: [[DF2010:gear assembly|gear assembly]] -> binary power on/power off -> machine
 +
 
 +
=== Binary logic ===
 +
Basic binary logic takes one or two input bits and creates an output based on them. The devices that perform these operations are commonly called '''logic gates'''.<br />
 +
* NOT - takes one input and returns the opposite of the input<br /><br />
 +
{| class="wikitable" border=1
 
|-
 
|-
! Symbol
+
! input A
! Meaning
+
! NOT
 
|-
 
|-
| {{diagram|[#ff0]O}}
+
| 0
| A gear which connects to your OUTPUT gear, which outputs power when the gate is producing an ON output.
+
| 1
 
|-
 
|-
| {{diagram|[#aaf]I}}
+
| 1
| A gear connected to an INPUT. In most gates you will have two Is, with each one connected to a different input.
+
| 0
 +
|}<br />
 +
* AND - takes two inputs and returns true if both inputs are true
 +
* OR - takes two inputs and returns true if at least one input is true
 +
* XOR - takes two inputs and returns true if exactly one input is true
 +
* NAND - takes two inputs and returns true if either input is false
 +
* NOR - takes two inputs and returns true if both inputs are false
 +
* NXOR - takes two inputs and returns true if both inputs are identical<br /><br />
 +
{| class="wikitable" border=1
 
|-
 
|-
| {{diagram|-}} and {{diagram|¦}}
+
! input A
| Horizontal axles
+
! input B
|-
+
! AND
| {{diagram|[#0f0]P}}
+
! OR
| Power goes here
+
! XOR
|-
+
! NAND
| {{diagram|[#aaf]i}}
+
! NOR
| Two more gears, each connected to the two different inputs.
+
! NXOR
|-
 
| {{diagram|[#f00]L}}
 
| a chain of gears or pumps which serve to add load to the system, generally shutting it off when connected.
 
|-
 
| {{diagram|*}}
 
| A gear which isn't linked to any inputs or outputs and just serves to connect the power or whatever.
 
|}
 
 
 
===Mechanical identity gate ===
 
{{diagram|
 
[#ff0]O[#aaf]I--[#0f0]P}}
 
 
* This takes an linked input signal and converts it to power without changing it. The unsourced fluid transfer NOT gate uses this, for instance.
 
* Connected to the input gear, such that they will only be connected to the system if the input gear is receiving an ON signal, are gears with windmills on top of them. Build only enough windmills to power the devices that the gate's OUTPUT gear are connected to (and the gears/axles).
 
* When the INPUT is ON, the INPUT gear will be active, and the network will provide power to the OUTPUT. When the INPUT is OFF, it will not provide power to the OUTPUT.
 
 
 
===Mechanical NOT gate===
 
{{diagram|
 
[#ff0]O[#aaf]I[#f00]L
 
¦
 
¦
 
[#0f0]P}}
 
 
* When the INPUT is ON, the INPUT gear will be active, and the network should need more power than is available. The devices connected to OUTPUT should shut down. When INPUT is OFF, the devices should have power since the INPUT gear will be disconnected.
 
 
 
===Mechanical NAND gate===
 
{{diagram|
 
[#ff0]O[#aaf]I[#aaf]I[#f00]L
 
¦
 
¦
 
[#0f0]P}}
 
 
* This works just like the NOT gate, except that there are two inputs and both have to be active to shut down the system instead of one. Make sure you have enough power to run the system when one of the input gears is active.
 
 
 
===Mechanical AND gate===
 
{{diagram|
 
[#ff0]O[#aaf]I[#aaf]I[#0f0]P}}
 
 
* This works like the identity gate, except that there are two inputs and both have to be active for the system to get power.
 
 
 
===Mechanical OR gate===
 
{{diagram|
 
[#ff0]O[#aaf]I
 
[#aaf]I*[#0f0]P}}
 
 
 
* This works like the identity gate, except that there are two inputs, and if either is active, the system receives power. Note that the entire power network is connected to both inputs, such that if either input is active the entire power network is powering the system.
 
 
 
===Mechanical NOR gate===
 
{{diagram|
 
[#aaf]I*[#f00]L
 
[#ff0]O[#aaf]I
 
¦
 
¦
 
[#0f0]P}}
 
 
* This works like the NOT gate, except that there are two inputs, and if either is active, the gear train or pump stack signified by the 'L' will be connected to the system. You need to have enough load to push power requirements above the amount of power produced by the power supply, shutting the system down.
 
 
 
===Mechanical XOR gate===
 
{{diagram|
 
[#ff0]O[#aaf]I
 
[#aaf]I*--*[#0f0]P
 
[#000].[#aaf]i[#000].[#000].[#aaf]i
 
[#000].[#f00]L[#000].[#000].[#f00]L}}
 
 
 
* Except for the 'i's and 'L's, this gate is identical to the OR gate. The additional components add the 'exclusive' part of the 'XOR' to the gate.
 
* This gate may be a bit difficult to construct. First, the 'i's are additional gears connected to each of your inputs, and the Ls are additional load, however, neither load by itself should be enough to shut down the system. However, you need to make the two sets of load large enough that if both inputs are active at the same time, their power requirements become large enough to shut down the system, without making them large enough to shut it down when only one of them is active. It'll just require a little math on your part.
 
 
 
===Mechanical XNOR gate===
 
{{diagram|
 
[#000].[#000].[#aaf]I*[#f00]L
 
[#000].[#000].[#ff0]O[#aaf]I
 
[#000].[#000].¦
 
[#0f0]P[#aaf]-*[#aaf]i-[#0f0]P
 
[#000].[#000].[#aaf]i
 
[#000].[#000].¦
 
[#000].[#000].[#0f0]P}}
 
 
 
{| class="wikitable" border="1"
 
|-
 
! A
 
! B
 
! Drain
 
! Power
 
! Extra Power
 
! Result
 
 
|-
 
|-
 
| 0
 
| 0
 
| 0
 
| 0
| No
+
| 0
| No
+
| 0
| No
+
| 0
 +
| 1
 +
| 1
 
| 1
 
| 1
 
|-
 
|-
 
| 0
 
| 0
 
| 1
 
| 1
| Yes
+
| 0
| Yes
+
| 1
| Half
+
| 1
 +
| 1
 +
| 0
 
| 0
 
| 0
 
|-
 
|-
 
| 1
 
| 1
 
| 0
 
| 0
| Yes
+
| 0
| Yes
+
| 1
| Half
+
| 1
 +
| 1
 +
| 0
 
| 0
 
| 0
 
|-
 
|-
 
| 1
 
| 1
 
| 1
 
| 1
| Yes
 
| Yes
 
| Full
 
 
| 1
 
| 1
|}
+
| 1
 +
| 0
 +
| 0
 +
| 0
 +
| 1
 +
|}<br />
 +
The most human-understandable logic system requires NOT, AND and OR gates, but having a design for either a NAND or a NOR gate is enough to build any of the other gates. Some gates are easier to create or need fewer components than others depending on what discipline your logic relies on. Designing each individual gate that you will need (or using designs that had each individual gate designed) rather than building a gate out of multiple NAND gates or the like will generally result in your dorfputer reacting faster and using less resources (power, water, kittens, construction materials, what-have-you).
 +
 
 +
=== Complex gates ===
 +
* [[DF2010:Latch|Latch]] - storing and reading a single binary value
 +
* [[DF2010:Repeater|Repeater]] - sending a repeating signal
 +
* [[DF2010:Counter|Counter]]/[[DF2010:Adder|Adder]] - binary calculation
 +
 
 +
== Disciplines ==
 +
Historically, prior to DF2010 there have been 3 main disciplines of dwarfputing, depending on what would drive the dwarfputer. Each of them had its assets and drawbacks. So far, DF2010 at 0.31.01 appears to be essentially the same as far as power transmission goes, barring some differences with pump vertical power transmission (they don't without the floor between being channeled, apparently). Science! will determine what, if anything, differs as far as water flow, falling, and animal pathfinding.
 +
 
 +
The three disciplines are:
 +
=== Fluid logic ===
 +
[[DF2010:Infinite flow fluid logic|Infinite flow fluid logic]] is controlling the ''flow of fluid'' over different pressure plates. Fluid logic can be easily constructed and every known logic gate in dwarf fortress has already been built with it. On the other hand this discipline depends on a somehow unlimited source of the used fluid to deal with its [[DF2010:evaporation|evaporation]] and [[DF2010:Water#Water_in_Fortress_Mode|destruction]].
 +
=== Mechanical logic ===
 +
[[DF2010:Mechanical logic|Mechanical logic]] uses systems of axles and [[DF2010:gear assemblies|gear assemblies]] to build logical gates. Mechanical logic reacts very fast and can be easily constructed, except for the need for a fluid-pump-based power->signal converter in every gate. Since every gear can itself be linked to a trigger (or multiple triggers), and automatically connect to adjacent gears for transferring either power or load, mechanical logic gates are very flexible and don't require anywhere near the number of different devices that tend to be used in fluid logic gates (except, again, for the requirement for a fluid-pump-based power->signal converter in every gate, unless you intend to use it to control a pump). On the other hand this discipline uses a LOT of mechanical power, and due to the lack of a power->signal converter, also referred to as a "rotation sensor" (a device to convert from power to on/off link signals), you need to build one using fluid logic components (the only design currently uses a pump, pressure plate, unlimited fluid, and unlimited drain) if you want to connect multiple mechanical logic gates together or connect a mechanical logic gate to any output other than a pump. So, in truth, current mechanical logic is more correctly termed mechanical-fluid hybrid logic, as you need an essentially unlimited source of water along with an unlimited drain to power the pump-based signal converters. (That said, an aquifer would work perfectly)
 +
 
 +
=== Animal logic ===
 +
[[DF2010:Animal logic|Animal logic]] places animals in an enclosed room, with a door blocking the path to where they desire to go, and a pressure plate below a hatch, with obstacles which are controlled by triggers. The animal thinks it can walk through the door, and if it has a path to the door will walk up to it and stand on the hatch. When the hatch is opened by a trigger, it falls onto the pressure plate. As long as the hatch is open, or other obstacles block its path to the door it remains on the pressure plate and the output is 'on'. Once it sees a path to the door it will leave the pressure plate. Generally this is made possibly by the fact that animals try to go to their parent while they're children, or to the meeting area. There are also be designs which use captured hostiles.
 +
 
 +
There was a fourth, theoretical, discipline, Borg Logic, but there was never any reported success inventing any functioning and useful borg logic systems.
 +
 
 +
===Examples of things you could do with logic gates===
 +
* Repeater: Repeatedly toggling hatches open and closed, or spikes up and down.
 +
* Latch: Making resettable one-use pressure plates which are reset by a lever.
 +
* NOT gate: Reversing the effect of a switch or creature-sensing pressure plate, generally linked to a latch device. You can, of course, mod the latch device to send the opposite signal instead of using a NOT gate.
 +
* AND gate: Requiring more than one condition to be true for something to occur. For instance, you could have a group of AND gates, with a system on/off switch, and and other triggers, with each trigger linked to a different AND gate with the system on/off switch linked to the the second input on all the AND gates, so that when the system on/off switch is OFF the output will be OFF on all the AND gates.
 +
* OR gate: You could link two 1-7 water sensors to an OR gate, and link that to a NOT gate, and link that to some floodgates or doors which act as emergency bulkheads, closing when water is detected in the area. Or, link the OR gate to bridges which raise instead (but you may crush things, and bridges are slower than doors).
 +
* XOR gate: You could use pressure plates hooked to latches at different points in your fort to detect enemy intrusion, and set them up to seal off the area with both an interior and exterior bulkhead when the intrusion occurs, but hook your latches up with an XOR gate and hook the output to the interior bulkhead to unseal that one if your pressure plates have detected that the enemy has gotten past it.
 +
* NOR gate: A NOR gate returns TRUE (ON) only if both inputs are FALSE. Instead of using the OR gate example with a NOT gate, you could use a NOR gate linked to two 1-7 water sensors, whose output goes to doors or floodgates. When the pressure plates are both waterless, the floodgates will be open. When one detects water, the floodgates close. (If you used 0-0 pressure plates with an OR, you would get an OFF signal if both plates detected water, or an ON signal otherwise (which is the same as 1-7 NAND 1-7))
 +
* NAND gate: A NAND gate returns TRUE (ON) whenever both inputs are not both TRUE (e.g. ON NAND ON is OFF, but every other combination is ON). Instead of the OR NOT or NOR example, you could link two 0-0 water sensors to a NAND gate, and link the NAND gate's output to raising bridges. 0-0 NAND 0-0 is the same as 1-7 OR 1-7. If there is no water on both pressure plates, the NAND gate will output an OFF signal. If, however, either has water, it will output an ON signal.
  
* The XNOR gate is an equality gate: The output is ON when both inputs are equal, and OFF when they are not equal.
+
* And here's a more complicated example, omitting the details of what gates to use: An automated swimming training room, where you pull a lever to close exit doors and open hatches to drop water into it, then pressure plates detect when there's enough water and close the hatches, and after a certain amount of time (using a very slow repeater, for instance), drains and exit doors open and the system resets until you pull the lever again. Or, the lever could be taken out entirely and the system could be made fully automatic (with dwarves set to train in the room, for instance) using the repeater.
* This gate may be '''even more complicated''' to build than the XOR gate!
 
* First, your 'i's are again gears connected to your two inputs. The two extra Ps to the right and below them are additional power sources, ideally only one windmill each.
 
* Here's where it gets complicated. The load has to be sufficient to shut down the system even when ONE of the inputs' additional power supplies are connected. However, when BOTH inputs are on, there needs to be enough power from both additional Ps to bring the system back online.
 
* Thus our gate does what it is supposed to: Produce enough power to have the OUTPUT gear be ON when both A and B are either 0 or 1, but not when they are not equal.
 

Revision as of 21:04, 11 April 2010

This article is about an older version of DF.

Template:Human Computing in dwarf fortress is the practice of setting up complex constructions to perform logical operations and calculations, ideally to control some functionality of your fortress. Even if it isn't a young concept anymore, there is still lots of room for improvement and development. One reason is that there are many ways to solve one problem. Innovation and invention is encouraged.

Binary information

Binary information can have one of two possible states: true or false, respectively 1 or 0. In dwarf fortress they can be represented by different entities:

Electronic devices and computers base on this elementary form of information, and if you want to go into computing, you’ll have to familiarize yourself with it. propositional calculus

Input/Output

Input can be any device which can be linked to another device with mechanisms, such as levers or pressure plates. Pressure plates can measure water, magma, or creature weight, and can be set to react to your own dwarves if measuring creature weight. If measuring water or magma you specify the minimum and maximum levels at which it should output 'on', and at all other levels it will output an 'off' signal. Regardless of the actual amount of water, magma, or creature weight on your pressure plate, the plate can only output an 'on' or 'off' signal (1 or 0) to whatever devices it is linked to. So everything you build will have a binary base.

Input elements

According to input, output can be anything that is able to react to an on/off signal. This can be doors, bridges, floodgates allowing or stopping flow, gears controlling pumps and much more. In some special configurations - when mechanical logic is involved - output may not be a on/off signal but power, thus running or not running a machine component.

Currently to convert from power to an on/off signal, the only way is to use a screw pump connected to that power source with an unlimited amount of water and drainage at the output, and a pressure plate to measure whether water is being pumped out by the pump.

Output elements

Binary logic

Basic binary logic takes one or two input bits and creates an output based on them. The devices that perform these operations are commonly called logic gates.

  • NOT - takes one input and returns the opposite of the input

input A NOT
0 1
1 0


  • AND - takes two inputs and returns true if both inputs are true
  • OR - takes two inputs and returns true if at least one input is true
  • XOR - takes two inputs and returns true if exactly one input is true
  • NAND - takes two inputs and returns true if either input is false
  • NOR - takes two inputs and returns true if both inputs are false
  • NXOR - takes two inputs and returns true if both inputs are identical

input A input B AND OR XOR NAND NOR NXOR
0 0 0 0 0 1 1 1
0 1 0 1 1 1 0 0
1 0 0 1 1 1 0 0
1 1 1 1 0 0 0 1


The most human-understandable logic system requires NOT, AND and OR gates, but having a design for either a NAND or a NOR gate is enough to build any of the other gates. Some gates are easier to create or need fewer components than others depending on what discipline your logic relies on. Designing each individual gate that you will need (or using designs that had each individual gate designed) rather than building a gate out of multiple NAND gates or the like will generally result in your dorfputer reacting faster and using less resources (power, water, kittens, construction materials, what-have-you).

Complex gates

Disciplines

Historically, prior to DF2010 there have been 3 main disciplines of dwarfputing, depending on what would drive the dwarfputer. Each of them had its assets and drawbacks. So far, DF2010 at 0.31.01 appears to be essentially the same as far as power transmission goes, barring some differences with pump vertical power transmission (they don't without the floor between being channeled, apparently). Science! will determine what, if anything, differs as far as water flow, falling, and animal pathfinding.

The three disciplines are:

Fluid logic

Infinite flow fluid logic is controlling the flow of fluid over different pressure plates. Fluid logic can be easily constructed and every known logic gate in dwarf fortress has already been built with it. On the other hand this discipline depends on a somehow unlimited source of the used fluid to deal with its evaporation and destruction.

Mechanical logic

Mechanical logic uses systems of axles and gear assemblies to build logical gates. Mechanical logic reacts very fast and can be easily constructed, except for the need for a fluid-pump-based power->signal converter in every gate. Since every gear can itself be linked to a trigger (or multiple triggers), and automatically connect to adjacent gears for transferring either power or load, mechanical logic gates are very flexible and don't require anywhere near the number of different devices that tend to be used in fluid logic gates (except, again, for the requirement for a fluid-pump-based power->signal converter in every gate, unless you intend to use it to control a pump). On the other hand this discipline uses a LOT of mechanical power, and due to the lack of a power->signal converter, also referred to as a "rotation sensor" (a device to convert from power to on/off link signals), you need to build one using fluid logic components (the only design currently uses a pump, pressure plate, unlimited fluid, and unlimited drain) if you want to connect multiple mechanical logic gates together or connect a mechanical logic gate to any output other than a pump. So, in truth, current mechanical logic is more correctly termed mechanical-fluid hybrid logic, as you need an essentially unlimited source of water along with an unlimited drain to power the pump-based signal converters. (That said, an aquifer would work perfectly)

Animal logic

Animal logic places animals in an enclosed room, with a door blocking the path to where they desire to go, and a pressure plate below a hatch, with obstacles which are controlled by triggers. The animal thinks it can walk through the door, and if it has a path to the door will walk up to it and stand on the hatch. When the hatch is opened by a trigger, it falls onto the pressure plate. As long as the hatch is open, or other obstacles block its path to the door it remains on the pressure plate and the output is 'on'. Once it sees a path to the door it will leave the pressure plate. Generally this is made possibly by the fact that animals try to go to their parent while they're children, or to the meeting area. There are also be designs which use captured hostiles.

There was a fourth, theoretical, discipline, Borg Logic, but there was never any reported success inventing any functioning and useful borg logic systems.

Examples of things you could do with logic gates

  • Repeater: Repeatedly toggling hatches open and closed, or spikes up and down.
  • Latch: Making resettable one-use pressure plates which are reset by a lever.
  • NOT gate: Reversing the effect of a switch or creature-sensing pressure plate, generally linked to a latch device. You can, of course, mod the latch device to send the opposite signal instead of using a NOT gate.
  • AND gate: Requiring more than one condition to be true for something to occur. For instance, you could have a group of AND gates, with a system on/off switch, and and other triggers, with each trigger linked to a different AND gate with the system on/off switch linked to the the second input on all the AND gates, so that when the system on/off switch is OFF the output will be OFF on all the AND gates.
  • OR gate: You could link two 1-7 water sensors to an OR gate, and link that to a NOT gate, and link that to some floodgates or doors which act as emergency bulkheads, closing when water is detected in the area. Or, link the OR gate to bridges which raise instead (but you may crush things, and bridges are slower than doors).
  • XOR gate: You could use pressure plates hooked to latches at different points in your fort to detect enemy intrusion, and set them up to seal off the area with both an interior and exterior bulkhead when the intrusion occurs, but hook your latches up with an XOR gate and hook the output to the interior bulkhead to unseal that one if your pressure plates have detected that the enemy has gotten past it.
  • NOR gate: A NOR gate returns TRUE (ON) only if both inputs are FALSE. Instead of using the OR gate example with a NOT gate, you could use a NOR gate linked to two 1-7 water sensors, whose output goes to doors or floodgates. When the pressure plates are both waterless, the floodgates will be open. When one detects water, the floodgates close. (If you used 0-0 pressure plates with an OR, you would get an OFF signal if both plates detected water, or an ON signal otherwise (which is the same as 1-7 NAND 1-7))
  • NAND gate: A NAND gate returns TRUE (ON) whenever both inputs are not both TRUE (e.g. ON NAND ON is OFF, but every other combination is ON). Instead of the OR NOT or NOR example, you could link two 0-0 water sensors to a NAND gate, and link the NAND gate's output to raising bridges. 0-0 NAND 0-0 is the same as 1-7 OR 1-7. If there is no water on both pressure plates, the NAND gate will output an OFF signal. If, however, either has water, it will output an ON signal.
  • And here's a more complicated example, omitting the details of what gates to use: An automated swimming training room, where you pull a lever to close exit doors and open hatches to drop water into it, then pressure plates detect when there's enough water and close the hatches, and after a certain amount of time (using a very slow repeater, for instance), drains and exit doors open and the system resets until you pull the lever again. Or, the lever could be taken out entirely and the system could be made fully automatic (with dwarves set to train in the room, for instance) using the repeater.