- 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.
Difference between revisions of "40d:Defense guide"
(removed confusing text) |
Strangething (talk | contribs) |
||
Line 2: | Line 2: | ||
− | + | =General Guidelines= | |
* '''Minimize fortress entrances:''' Have a strong distinction between inside and outside. This usually corresponds to underground and surface, but not always. Each point of contact needs to be hardened against attack. Don't make more entrances than necessary. If there's an useless opening, wall it off. | * '''Minimize fortress entrances:''' Have a strong distinction between inside and outside. This usually corresponds to underground and surface, but not always. Each point of contact needs to be hardened against attack. Don't make more entrances than necessary. If there's an useless opening, wall it off. | ||
Line 11: | Line 11: | ||
− | + | =Threats= | |
− | + | ==Wild animals== | |
The first, and easiest, threat you will have to deal with is the local wildlife. [[Animal]]s are easily excluded by the humble [[door]] or [[hatch]]. [[Elephant]]s are not nearly as aggressive as they were in the days of [[Boatmurdered]]. With [[cage]] [[trap]]s and an [[animal trainer]] (or [[Dungeon master]]) animals can be useful. Dwarves love [[zoo]]s, merchants will gladly take your caged animals, and they provide a [[food]] source in times of need. | The first, and easiest, threat you will have to deal with is the local wildlife. [[Animal]]s are easily excluded by the humble [[door]] or [[hatch]]. [[Elephant]]s are not nearly as aggressive as they were in the days of [[Boatmurdered]]. With [[cage]] [[trap]]s and an [[animal trainer]] (or [[Dungeon master]]) animals can be useful. Dwarves love [[zoo]]s, merchants will gladly take your caged animals, and they provide a [[food]] source in times of need. | ||
− | + | ==Thieves & snatchers== | |
Any creature with a career title of [[thief]] or master thief has a few nasty abilities. First, they are invisible until spotted by your dwarves or tame [[animal]]s. When spotted, there's an [[alert]] message, either "Protect the hoard!" or "Protect the children!" depending on the type of thief. Second, they can open [[door]]s. Not just for themselves either, the door stays open until a military dwarf "secures" the door, allowing any random creature to walk in. This can be a nasty surprise for players who aren't expecting it. Third, they bypass your [[trap]]s. Thankfully, they don't disarm them the way they neutralize doors. This trap avoidance isn't perfect, there's some element of luck involved, and kobold thieves seem to be a lot better at it than goblins. A thief caught in a cage trap will be revealed automatically, even if no dwarf is in sight of the trap. Last of all, they make dangerous prisoners. Unlike military captives, thieves will break free and attack if you attempt to transfer or [[pit]] them. | Any creature with a career title of [[thief]] or master thief has a few nasty abilities. First, they are invisible until spotted by your dwarves or tame [[animal]]s. When spotted, there's an [[alert]] message, either "Protect the hoard!" or "Protect the children!" depending on the type of thief. Second, they can open [[door]]s. Not just for themselves either, the door stays open until a military dwarf "secures" the door, allowing any random creature to walk in. This can be a nasty surprise for players who aren't expecting it. Third, they bypass your [[trap]]s. Thankfully, they don't disarm them the way they neutralize doors. This trap avoidance isn't perfect, there's some element of luck involved, and kobold thieves seem to be a lot better at it than goblins. A thief caught in a cage trap will be revealed automatically, even if no dwarf is in sight of the trap. Last of all, they make dangerous prisoners. Unlike military captives, thieves will break free and attack if you attempt to transfer or [[pit]] them. | ||
− | + | ==Ambushes== | |
An [[ambush]] is a small number of enemies (less than ten) that are invisible until spotted, like thieves, but somewhat easier to detect. The alert message is "An ambush! Curse them!" They skulk around the outside of your fortress, looking for a target of opportunity. They will often attack [[caravan]]s as they move to your depot. Ambushers have random weapons, and typically have a leader (with a career title of "guard") with a different weapon from the rest. | An [[ambush]] is a small number of enemies (less than ten) that are invisible until spotted, like thieves, but somewhat easier to detect. The alert message is "An ambush! Curse them!" They skulk around the outside of your fortress, looking for a target of opportunity. They will often attack [[caravan]]s as they move to your depot. Ambushers have random weapons, and typically have a leader (with a career title of "guard") with a different weapon from the rest. | ||
If you have [[woodcutter]]s or [[hunter]]s roaming the surface, they are likely to be the first to encounter the ambush. This can provide a kind of early alert system, but you'll loose a few of them. | If you have [[woodcutter]]s or [[hunter]]s roaming the surface, they are likely to be the first to encounter the ambush. This can provide a kind of early alert system, but you'll loose a few of them. | ||
− | + | ==Sieges== | |
A siege is a large number of attackers that are announced as soon as they appear on the map. The alert message is "A vile force of darkness has arrived!" While siegers are on the map, the word "SIEGE" appears in the top corners of the screen. Siegers are organized into a number of squads, each squad having a different weapon choice. A siege can be lead by a leader figure, often a master warrior. Goblin siegers bring along creatures such as [[troll]]s or [[beak dog]]s. Sieges tend to get progressively larger. It is unknown what factor this escalation is tied to. | A siege is a large number of attackers that are announced as soon as they appear on the map. The alert message is "A vile force of darkness has arrived!" While siegers are on the map, the word "SIEGE" appears in the top corners of the screen. Siegers are organized into a number of squads, each squad having a different weapon choice. A siege can be lead by a leader figure, often a master warrior. Goblin siegers bring along creatures such as [[troll]]s or [[beak dog]]s. Sieges tend to get progressively larger. It is unknown what factor this escalation is tied to. | ||
− | + | ==Enemy archers== | |
Attackers with [[bow]]s or [[crossbow]]s are much, much more threatening than those with melee weapons. Out shooting them with your marksdwarves is risky, and charging them with melee fighters is suicidal. Advanced techniques are needed to shield your dwarves from the deadly rain of arrows. | Attackers with [[bow]]s or [[crossbow]]s are much, much more threatening than those with melee weapons. Out shooting them with your marksdwarves is risky, and charging them with melee fighters is suicidal. Advanced techniques are needed to shield your dwarves from the deadly rain of arrows. | ||
− | + | ==Room destroyers== | |
Some creatures have the ROOM_DESTROYER tag in the raws. This gives them the fearful capacity of tearing apart your doors and bridges. | Some creatures have the ROOM_DESTROYER tag in the raws. This gives them the fearful capacity of tearing apart your doors and bridges. | ||
− | + | ==Megabeasts== | |
A [[megabeast]] appears alone, with an alert message that mentions the beast by name. These creature are incredibly powerful, a match for even a well-trained, well-equipped squad. | A [[megabeast]] appears alone, with an alert message that mentions the beast by name. These creature are incredibly powerful, a match for even a well-trained, well-equipped squad. | ||
− | + | =Elements= | |
− | + | ==Soldiers== | |
The core of any defense plan is the soldiers. A trained and equipped [[military]] is the only way to bring the fight to the enemy. Keeping them in position is the tricky part. | The core of any defense plan is the soldiers. A trained and equipped [[military]] is the only way to bring the fight to the enemy. Keeping them in position is the tricky part. | ||
− | + | ===Roughing it=== | |
Always have your soldiers carry food and water. They will each need a [[waterskin]] (or [[flask]]) and a [[backpack]]. This keeps your soldiers from wandering off to eat and drink. For around the clock defense, have them sleep on the ground when on duty. Hopefully the sounds of combat will wake them up before they get killed. | Always have your soldiers carry food and water. They will each need a [[waterskin]] (or [[flask]]) and a [[backpack]]. This keeps your soldiers from wandering off to eat and drink. For around the clock defense, have them sleep on the ground when on duty. Hopefully the sounds of combat will wake them up before they get killed. | ||
− | + | ===Daylight training room=== | |
Put a [[weapon rack]] on the surface near your entrance and make it a training room. Training dwarves will be in position if there's trouble. This also helps prevent cave adaption in your military. You can use an [[archery target]] this way, too. | Put a [[weapon rack]] on the surface near your entrance and make it a training room. Training dwarves will be in position if there's trouble. This also helps prevent cave adaption in your military. You can use an [[archery target]] this way, too. | ||
− | + | ==Doors and hatches== | |
The most obvious way to keep any enemy out is with a [[door]]. You can also forbid doors to keep your dwarves from wandering into unsafe areas. A [[floor hatch]] is just a vertical door. | The most obvious way to keep any enemy out is with a [[door]]. You can also forbid doors to keep your dwarves from wandering into unsafe areas. A [[floor hatch]] is just a vertical door. | ||
− | + | ==Walls== | |
Constructing walls around your entrance is an essential part of fortress defense. Currently, no creature can knock down a wall. Not only does it keep enemies out, your archers can stand on top of the wall and fire down. Keep in mind that this makes them vulnerable to enemy fire. To protect against that, build fortifications. | Constructing walls around your entrance is an essential part of fortress defense. Currently, no creature can knock down a wall. Not only does it keep enemies out, your archers can stand on top of the wall and fire down. Keep in mind that this makes them vulnerable to enemy fire. To protect against that, build fortifications. | ||
− | + | ==Fortifications== | |
Fortifications block movement, and allow some missiles to pass through. Projectiles have a chance of being blocked, based on the firer's skill and distance to the fortification. Keep your marksdwarves close and keep enemies away. Build fortified firing platforms above ground level and put a nice wide moat between the wall and the enemy. | Fortifications block movement, and allow some missiles to pass through. Projectiles have a chance of being blocked, based on the firer's skill and distance to the fortification. Keep your marksdwarves close and keep enemies away. Build fortified firing platforms above ground level and put a nice wide moat between the wall and the enemy. | ||
− | + | ==Moats and bridges== | |
A retractable [[bridge]] over a [[moat]] is an almost airtight defense. The moat keeps building-destroyers away from the bridge, and the raised bridge blocks arrow fire. There are two important things to remember: Always build the bridge to raise towards the ''inside''. The [[lever]] has to be pulled by a civilian, not a soldier. | A retractable [[bridge]] over a [[moat]] is an almost airtight defense. The moat keeps building-destroyers away from the bridge, and the raised bridge blocks arrow fire. There are two important things to remember: Always build the bridge to raise towards the ''inside''. The [[lever]] has to be pulled by a civilian, not a soldier. | ||
Line 67: | Line 67: | ||
A drawbridge without a moat is just a big remote control door. | A drawbridge without a moat is just a big remote control door. | ||
− | + | ==Remote control doors== | |
If you link a [[lever]] to a door, it becomes impossible for your dwarves to open and close it normally. Pulling the lever is the only way to open it. This keeps your dwarves locked in as well as keeping enemies out. It's unknown if thieves can open a door once it's linked. | If you link a [[lever]] to a door, it becomes impossible for your dwarves to open and close it normally. Pulling the lever is the only way to open it. This keeps your dwarves locked in as well as keeping enemies out. It's unknown if thieves can open a door once it's linked. | ||
Line 76: | Line 76: | ||
You can use a [[pressure plate]] instead of a lever, but there are many complications there. | You can use a [[pressure plate]] instead of a lever, but there are many complications there. | ||
− | + | ==Traps== | |
The most reliable way to stop intruders is lots of [[trap]]s. A thief's trap avoidance is subject to chance. A line of traps can wipe out an ambushes entirely, and inflict a lot of damage on a siege. | The most reliable way to stop intruders is lots of [[trap]]s. A thief's trap avoidance is subject to chance. A line of traps can wipe out an ambushes entirely, and inflict a lot of damage on a siege. | ||
− | + | ===Stone fall trap=== | |
This is the easiest trap to build, so you can easily build them in large numbers. Building lots of them is an easy way to earn experience for your [[mechanic]], and add to your fort's defenses at the same time. Surround every intersection and stairway. | This is the easiest trap to build, so you can easily build them in large numbers. Building lots of them is an easy way to earn experience for your [[mechanic]], and add to your fort's defenses at the same time. Surround every intersection and stairway. | ||
− | + | ===Cage trap=== | |
A very strong type of trap. Maybe even too strong. Currently, even a wooden or glass [[cage]] can hold indefinitely any creature, even trolls and megabeasts. Also, a cage trap never fails. A large creature can shrug off damage from a stone or weapon trap, but nothing can escape from a cage. Use cage traps as your outermost traps to catch the occasional wandering animal. A wounded [[elephant]] or [[unicorn]] in your front courtyard is not good at all. | A very strong type of trap. Maybe even too strong. Currently, even a wooden or glass [[cage]] can hold indefinitely any creature, even trolls and megabeasts. Also, a cage trap never fails. A large creature can shrug off damage from a stone or weapon trap, but nothing can escape from a cage. Use cage traps as your outermost traps to catch the occasional wandering animal. A wounded [[elephant]] or [[unicorn]] in your front courtyard is not good at all. | ||
− | + | ===Weapon trap=== | |
The gold standard of traps. This is the only simple trap that works repeatedly without reloading. They do get jammed, however. View the trap with the '''items in room''' {{key|t}} mode, and if there's a corpse inside the trap, it's jammed. None of the weapons on a jammed trap will function. It may be wiser to have several weapon traps with fewer weapons, rather than a smaller number of ten-weapon traps. | The gold standard of traps. This is the only simple trap that works repeatedly without reloading. They do get jammed, however. View the trap with the '''items in room''' {{key|t}} mode, and if there's a corpse inside the trap, it's jammed. None of the weapons on a jammed trap will function. It may be wiser to have several weapon traps with fewer weapons, rather than a smaller number of ten-weapon traps. | ||
Line 91: | Line 91: | ||
− | + | ==Guard animals== | |
[[Chain]]ed animals are sentries, not fighters. Most animals aren't strong enough to take more than one goblin warrior. Enemies with bows are even worse. The real purpose of guard animals is to spot thieves. Anything will do here, a cat is fine. Don't use something useful, like a war dog. Put animals in narrow corridors, in places where enemy archers can't see them. | [[Chain]]ed animals are sentries, not fighters. Most animals aren't strong enough to take more than one goblin warrior. Enemies with bows are even worse. The real purpose of guard animals is to spot thieves. Anything will do here, a cat is fine. Don't use something useful, like a war dog. Put animals in narrow corridors, in places where enemy archers can't see them. | ||
− | + | ==[[Siege engine]]s== | |
− | |||
− | |||
− | |||
Catapults are only useful for training and stone disposal. Ballistas are deadly, but fire expensive ammunition, and hit both friend and foe alike. | Catapults are only useful for training and stone disposal. Ballistas are deadly, but fire expensive ammunition, and hit both friend and foe alike. | ||
Line 103: | Line 100: | ||
− | + | ==Turrets== | |
[[Construct]] a tower that's sealed off, so that the only access is from the tunnels below. Carve fortifications on the second or third floor, so your dwarves can fire out. For extra usefulness, build a [[barracks]], [[archery target]], [[food]] [[stockpile]], and [[dining room]] in or near the turret. | [[Construct]] a tower that's sealed off, so that the only access is from the tunnels below. Carve fortifications on the second or third floor, so your dwarves can fire out. For extra usefulness, build a [[barracks]], [[archery target]], [[food]] [[stockpile]], and [[dining room]] in or near the turret. | ||
− | + | ===Siege engine turrets=== | |
If it's big enough, build a siege engine inside a turret. The device needs to be on ground level. Only a single tile of fortifications is needed to fire through the wall. You may want to build a moat or secondary wall to keep enemies at a distance. Build the tower in line to fire parallel your outer wall or moat, where invaders tend to congregate. | If it's big enough, build a siege engine inside a turret. The device needs to be on ground level. Only a single tile of fortifications is needed to fire through the wall. You may want to build a moat or secondary wall to keep enemies at a distance. Build the tower in line to fire parallel your outer wall or moat, where invaders tend to congregate. | ||
− | + | =Considerations= | |
− | + | ==Civilians stay underground== | |
This setting, in the [[orders and options]] menu is the easiest way to keep your non-military dwarves out of sight of the enemy. It is far from perfect, as dwarves will do the "entrance dance." They will attempt to leave the fortress, and only cancel jobs once they reach the surface. | This setting, in the [[orders and options]] menu is the easiest way to keep your non-military dwarves out of sight of the enemy. It is far from perfect, as dwarves will do the "entrance dance." They will attempt to leave the fortress, and only cancel jobs once they reach the surface. | ||
Line 125: | Line 122: | ||
− | + | ==Trade depot== | |
Factoring in access to the [[trade depot]] adds a layer of complexity. Letting merchants in while keeping enemies out requires a careful balance. The merchants do reveal ambushes, and they can arrive in the middle of a [[siege]]. | Factoring in access to the [[trade depot]] adds a layer of complexity. Letting merchants in while keeping enemies out requires a careful balance. The merchants do reveal ambushes, and they can arrive in the middle of a [[siege]]. | ||
[[Wagon]]s need a three tile wide path to the depot. You will probably want to build the depot underground, so civilian dwarves can access the depot. Wagons can't use stairs, so you need a three-tile [[ramp]], unless you can dig into the face of a cliff. | [[Wagon]]s need a three tile wide path to the depot. You will probably want to build the depot underground, so civilian dwarves can access the depot. Wagons can't use stairs, so you need a three-tile [[ramp]], unless you can dig into the face of a cliff. | ||
− | + | ==Airlock defenses/buffer zone== | |
− | Build two walls, each with a drawbridge. Build the trade depot in the buffer zone between them. Keep the outer bridge open, and the inner one closed. When the merchants appear, put crossbows on the walls to guard | + | Build two walls, each with a drawbridge. Build the trade depot in the buffer zone between them. Keep the outer bridge open, and the inner one closed. When the merchants appear, put crossbows on the walls to guard their approach. Once all the merchants are safely inside, close the outer bridge and open the inner one. Once there's no enemies left in the buffer zone, your civilians can start loading up the depot. |
The airlock pattern can be useful even without putting the depot there. Let a few siegers in at a time, and crush them with superior numbers. Reset the traps, Rest up the soldiers, and repeat. | The airlock pattern can be useful even without putting the depot there. Let a few siegers in at a time, and crush them with superior numbers. Reset the traps, Rest up the soldiers, and repeat. | ||
− | + | ==Branching corridors== | |
Enemies will take the most direct path to your fortress. You can use this to your advantage. Have two paths to the fortress: a long, twisting, three-wide road, and a shorter, one tile wide, trap-filled passage. Attackers will usually prefer the short and deadly path. This makes a good line of fire for a ballista, too. | Enemies will take the most direct path to your fortress. You can use this to your advantage. Have two paths to the fortress: a long, twisting, three-wide road, and a shorter, one tile wide, trap-filled passage. Attackers will usually prefer the short and deadly path. This makes a good line of fire for a ballista, too. | ||
This isn't a perfect method, but surprisingly effective. | This isn't a perfect method, but surprisingly effective. | ||
− | + | ==Civilians trapped outdoors== | |
− | + | ==Water sources== | |
− | + | ==Trees== | |
− | + | ==Death from below== | |
− | + | ==Lever room== | |
[[Category:Guide]] | [[Category:Guide]] |
Revision as of 18:59, 14 July 2008
Protecting your fortress from intruders is a complex task. There's a variety of threats to consider, and many ways to counter them.
General Guidelines
- Minimize fortress entrances: Have a strong distinction between inside and outside. This usually corresponds to underground and surface, but not always. Each point of contact needs to be hardened against attack. Don't make more entrances than necessary. If there's an useless opening, wall it off.
- Concentric circles: One wall may not be enough. With the existence of door-destroying and bow-wielding attackers, a double wall between the inside and the outside is essential to fend off the worst assaults. The choke points between the circles are where you build traps or station troops.
- Assume the worst: Build up your defenses before the enemy shows up. Plan on being sieged by hordes of goblin archers, trolls, kobold master thieves, giant eagles, angry elephants, and a bronze colossus all at once. Hopefully, you will never have to face that kind of threat, but being ready for anything is the best bet.
Threats
Wild animals
The first, and easiest, threat you will have to deal with is the local wildlife. Animals are easily excluded by the humble door or hatch. Elephants are not nearly as aggressive as they were in the days of Boatmurdered. With cage traps and an animal trainer (or Dungeon master) animals can be useful. Dwarves love zoos, merchants will gladly take your caged animals, and they provide a food source in times of need.
Thieves & snatchers
Any creature with a career title of thief or master thief has a few nasty abilities. First, they are invisible until spotted by your dwarves or tame animals. When spotted, there's an alert message, either "Protect the hoard!" or "Protect the children!" depending on the type of thief. Second, they can open doors. Not just for themselves either, the door stays open until a military dwarf "secures" the door, allowing any random creature to walk in. This can be a nasty surprise for players who aren't expecting it. Third, they bypass your traps. Thankfully, they don't disarm them the way they neutralize doors. This trap avoidance isn't perfect, there's some element of luck involved, and kobold thieves seem to be a lot better at it than goblins. A thief caught in a cage trap will be revealed automatically, even if no dwarf is in sight of the trap. Last of all, they make dangerous prisoners. Unlike military captives, thieves will break free and attack if you attempt to transfer or pit them.
Ambushes
An ambush is a small number of enemies (less than ten) that are invisible until spotted, like thieves, but somewhat easier to detect. The alert message is "An ambush! Curse them!" They skulk around the outside of your fortress, looking for a target of opportunity. They will often attack caravans as they move to your depot. Ambushers have random weapons, and typically have a leader (with a career title of "guard") with a different weapon from the rest.
If you have woodcutters or hunters roaming the surface, they are likely to be the first to encounter the ambush. This can provide a kind of early alert system, but you'll loose a few of them.
Sieges
A siege is a large number of attackers that are announced as soon as they appear on the map. The alert message is "A vile force of darkness has arrived!" While siegers are on the map, the word "SIEGE" appears in the top corners of the screen. Siegers are organized into a number of squads, each squad having a different weapon choice. A siege can be lead by a leader figure, often a master warrior. Goblin siegers bring along creatures such as trolls or beak dogs. Sieges tend to get progressively larger. It is unknown what factor this escalation is tied to.
Enemy archers
Attackers with bows or crossbows are much, much more threatening than those with melee weapons. Out shooting them with your marksdwarves is risky, and charging them with melee fighters is suicidal. Advanced techniques are needed to shield your dwarves from the deadly rain of arrows.
Room destroyers
Some creatures have the ROOM_DESTROYER tag in the raws. This gives them the fearful capacity of tearing apart your doors and bridges.
Megabeasts
A megabeast appears alone, with an alert message that mentions the beast by name. These creature are incredibly powerful, a match for even a well-trained, well-equipped squad.
Elements
Soldiers
The core of any defense plan is the soldiers. A trained and equipped military is the only way to bring the fight to the enemy. Keeping them in position is the tricky part.
Roughing it
Always have your soldiers carry food and water. They will each need a waterskin (or flask) and a backpack. This keeps your soldiers from wandering off to eat and drink. For around the clock defense, have them sleep on the ground when on duty. Hopefully the sounds of combat will wake them up before they get killed.
Daylight training room
Put a weapon rack on the surface near your entrance and make it a training room. Training dwarves will be in position if there's trouble. This also helps prevent cave adaption in your military. You can use an archery target this way, too.
Doors and hatches
The most obvious way to keep any enemy out is with a door. You can also forbid doors to keep your dwarves from wandering into unsafe areas. A floor hatch is just a vertical door.
Walls
Constructing walls around your entrance is an essential part of fortress defense. Currently, no creature can knock down a wall. Not only does it keep enemies out, your archers can stand on top of the wall and fire down. Keep in mind that this makes them vulnerable to enemy fire. To protect against that, build fortifications.
Fortifications
Fortifications block movement, and allow some missiles to pass through. Projectiles have a chance of being blocked, based on the firer's skill and distance to the fortification. Keep your marksdwarves close and keep enemies away. Build fortified firing platforms above ground level and put a nice wide moat between the wall and the enemy.
Moats and bridges
A retractable bridge over a moat is an almost airtight defense. The moat keeps building-destroyers away from the bridge, and the raised bridge blocks arrow fire. There are two important things to remember: Always build the bridge to raise towards the inside. The lever has to be pulled by a civilian, not a soldier.
The moat doesn't have to be filled with water or magma. Arguably, a dry moat is a better defense. If you want to build an escape rout out of your moat, make sure is leads to the outside, and is barred by a door (at least).
A moat with a non-retractable bridge is still potentially useful: It keeps enemy archers away from your fortifications, and it channels enemies into a narrow area.
A drawbridge without a moat is just a big remote control door.
Remote control doors
If you link a lever to a door, it becomes impossible for your dwarves to open and close it normally. Pulling the lever is the only way to open it. This keeps your dwarves locked in as well as keeping enemies out. It's unknown if thieves can open a door once it's linked.
A floodgate can be used just like a door, with two differences: A floodgate can be placed next to another floodgate, unlike a door, which needs to be adjacent to a wall. A floodgate is closed by default, and can only be opened with a lever. Be careful not to trap your dwarves.
A hatch cover can also be used this way.
You can use a pressure plate instead of a lever, but there are many complications there.
Traps
The most reliable way to stop intruders is lots of traps. A thief's trap avoidance is subject to chance. A line of traps can wipe out an ambushes entirely, and inflict a lot of damage on a siege.
Stone fall trap
This is the easiest trap to build, so you can easily build them in large numbers. Building lots of them is an easy way to earn experience for your mechanic, and add to your fort's defenses at the same time. Surround every intersection and stairway.
Cage trap
A very strong type of trap. Maybe even too strong. Currently, even a wooden or glass cage can hold indefinitely any creature, even trolls and megabeasts. Also, a cage trap never fails. A large creature can shrug off damage from a stone or weapon trap, but nothing can escape from a cage. Use cage traps as your outermost traps to catch the occasional wandering animal. A wounded elephant or unicorn in your front courtyard is not good at all.
Weapon trap
The gold standard of traps. This is the only simple trap that works repeatedly without reloading. They do get jammed, however. View the trap with the items in room t mode, and if there's a corpse inside the trap, it's jammed. None of the weapons on a jammed trap will function. It may be wiser to have several weapon traps with fewer weapons, rather than a smaller number of ten-weapon traps.
Using crossbows in weapon traps avoids the problem of jamming, but has to be loaded with bolts.
Guard animals
Chained animals are sentries, not fighters. Most animals aren't strong enough to take more than one goblin warrior. Enemies with bows are even worse. The real purpose of guard animals is to spot thieves. Anything will do here, a cat is fine. Don't use something useful, like a war dog. Put animals in narrow corridors, in places where enemy archers can't see them.
Siege engines
Catapults are only useful for training and stone disposal. Ballistas are deadly, but fire expensive ammunition, and hit both friend and foe alike.
Remember that siege operators are civilians. Fortunately, siege engines can fire through fortifications, just like normal projectiles.
Turrets
Construct a tower that's sealed off, so that the only access is from the tunnels below. Carve fortifications on the second or third floor, so your dwarves can fire out. For extra usefulness, build a barracks, archery target, food stockpile, and dining room in or near the turret.
Siege engine turrets
If it's big enough, build a siege engine inside a turret. The device needs to be on ground level. Only a single tile of fortifications is needed to fire through the wall. You may want to build a moat or secondary wall to keep enemies at a distance. Build the tower in line to fire parallel your outer wall or moat, where invaders tend to congregate.
Considerations
Civilians stay underground
This setting, in the orders and options menu is the easiest way to keep your non-military dwarves out of sight of the enemy. It is far from perfect, as dwarves will do the "entrance dance." They will attempt to leave the fortress, and only cancel jobs once they reach the surface.
It takes a truly airtight fortress to turn this setting off while there are still enemies outside.
- Screen the entrance Build a simple wall around your entryway. This will keep your dwarves safe from enemy fire while doing the entrance dance.
- Forbid dropped equipment and corpses Use the forbid designation to mark every item on the battlefield as forbidden. This includes any items dropped by dead merchants or scuttled wagons.
- Delete stockpiles and turn off tombs As a preemptive measure, you can delete your stockpiles. Dwarves don't haul things if there's no stockpile to place them in. Turning off or removing coffins stops burials as well.
- Keep them busy Make a bunch of busy-work for your dwarves, just to keep them underground. It's not perfect but it helps. Time to re-organize your stockpiles.
Trade depot
Factoring in access to the trade depot adds a layer of complexity. Letting merchants in while keeping enemies out requires a careful balance. The merchants do reveal ambushes, and they can arrive in the middle of a siege.
Wagons need a three tile wide path to the depot. You will probably want to build the depot underground, so civilian dwarves can access the depot. Wagons can't use stairs, so you need a three-tile ramp, unless you can dig into the face of a cliff.
Airlock defenses/buffer zone
Build two walls, each with a drawbridge. Build the trade depot in the buffer zone between them. Keep the outer bridge open, and the inner one closed. When the merchants appear, put crossbows on the walls to guard their approach. Once all the merchants are safely inside, close the outer bridge and open the inner one. Once there's no enemies left in the buffer zone, your civilians can start loading up the depot.
The airlock pattern can be useful even without putting the depot there. Let a few siegers in at a time, and crush them with superior numbers. Reset the traps, Rest up the soldiers, and repeat.
Branching corridors
Enemies will take the most direct path to your fortress. You can use this to your advantage. Have two paths to the fortress: a long, twisting, three-wide road, and a shorter, one tile wide, trap-filled passage. Attackers will usually prefer the short and deadly path. This makes a good line of fire for a ballista, too.
This isn't a perfect method, but surprisingly effective.