I was considering making a guide to making a fortress survive just about any kind of tragedy or incursion. But then I realized I don't know everything and everyone has their own way of doing things and aren't willing to sacrifice some of the things I am to keep a fortress going. So I'm opening this up to everyone to post some tips on how they keep their fortresses from succumbing to the every day perils of dwarven life. I'll start with some of the tricks I've picked up over the past months.
1: Seal yourself in. This is the most reliable method of protecting your dwarves' collective assets from the outside world but comes at a cost. You will need to make sure anything you need from the surface or the caves is already in good supply. Most notably wood. With some engineering you can create a tree farm underground or wall off an area above ground for green trees.
The most notable sacrifice is your lack of access to trade. You will need to rely on your own resources for all of your needs. Raising your own animals for meat and leather can help.
The real trick is handling migrants. If you wall in too early you may be stuck with just a handful of dwarves. Fortunately bad things don't usually start happening until several months into the game so you can risk holding off until you feel your population is sufficient. This can work in your favor if you are trying to keep your population low.
This doesn't have to be a permanent solution. Walling in while you get your military and other industries under way can save you a lot of headache early on but once you get up and running you should consider opening up again. I highly recommend this strategy for newer players.
2: Use a bridge or a gate. A good and commonly used alternative to keeping yourself walled in all the time is to use a gate or a bridge to allow passage only during certain events such as migrant waves or caravans. These gates are best combined with other defenses such as military or traps.
Care must be taken when designing these gateways as ranged hostiles can fire bolts and arrows directly into your fortress without fearing reprisal. You should arrange passage through the gateway so that the bulk of your fortress interior does not have a direct line of sight to the outside. Combined with a properly positioned squad near the entrance, ranged attacks can be rendered almost completely useless.
Make sure the gateway is only open when you need it. This can be difficult to keep up with for new players. Keeping an eye on announcements will tell you when you should open or close the gate.
3: Military > Traps. Don't get me wrong. I love traps. I've used them in almost every fortress I've made. But they come with a price.
There's no doubt that properly designed traps can slice up most of your ambushers and kidnappers without any trouble. The problems occur when they are being maintained. Inevitably your traps will become jammed. If you leave them alone they will unjam on their own. Unfortunately there is no option to force your dwarves to leave them alone short of using burrows and I'm not even going to go into all the trouble burrows have given me. And unless you have an excessively large array of traps you will need to have them cleaned regularly.
So what eventually happens is you get a dwarf that decides to clean a trap and it just happens to be at the worst possible time. A goblin ambush pops up right at your door step and the dwarf cleaning the trap faces almost certain doom. This is compounded by the fact that more often than not your dwarves will tend to run out of your fortress instead of back in. However his chances increase significantly if you have a squad nearby.
I don't have any magic numbers for your military. I've successfully defended a fortress in the past with only 4 axedwarves but I've needed more in others. For the inexperienced, stick with axes and/or swords and use bronze or higher for materials.
If at all possible, dig all the way down to the magma to find adamantine and dig out the top layer(perfectly safe) to get some adamantine weapons started.
In any case you'll want to make your weapons out of the best materials you have available. Trading for steel is a viable option as you won't require much for weapons or you can trade for the weapons directly. For armor you can get away with using lesser materials. But try to use plate instead of chain to avoid stray bolts and arrows.
4: Make sure you have a little bit of everything. Probably the most irritating way for a dwarf to die is to go into a mood, claim a workshop, and sit there, slowly going insane because there's no silk thread or raw glass lying around. This is where trade becomes more important. The materials are usually cheap and it only takes a little of each to insure your moody dwarves have what they need. If there's any industry you don't plan on having, go ahead and trade for some of the materials for them. Also consider embarking with it if you can.
5: Keep your dwarves happy. This should go without saying and since there are so many methods to this I won't go into too much detail. But I do think I should emphasize the importance of keeping your dwarves happy. Megaprojects are all well and good but you shouldn't neglect the feelings of your dwarves in the process, especially since it doesn't take too much work. Otherwise the first dwarf that bites the dust is going to set your other dwarves down the path of mood death and nobody wants that......Okay, a lot of people want that but it's not a good way to keep a fortress going.
Quick tip to keep dwarves happy: Big dining room and a variety of booze. Remember, the more happy thoughts, the better.