First, what determines what material the dwarf grabs. Say he needs metal. Will he go for the absolute closest metal bar he can grab, or will he make a choice? If a choice what determines the choice?
If it's a metalworking mood (and the primary material is a metal), then there are 3 options:
* if you have
any adamantine wafers, he will demand 1-3 adamantine wafers. If you're modded and have multiple DEEP metals, he'll demand 1-3 bars/wafers of whichever type happens to be closest.
* if he has a favorite metal and you've smelted at least one bar of that, he will demand 1-3 bars of that metal.
* otherwise, he will demand 1-3 bars of "any type of metal" and will pick whatever's closest.
If it's a clothesmaking mood (and the primary material is a type of cloth), then there are 5 options:
* if you have
any adamantine cloth, he will demand 1-3 pieces of adamantine cloth. If you're modded and have multiple DEEP cloth-metals, he'll demand 1-3 pieces of whichever type happens to be closest.
* if he has a favorite type of silk, he will demand 1-3 pieces of
any silk cloth
* if he has a favorite type of plant fiber, he will demand 1-3 pieces of
any plant fiber cloth
* if he has a favorite type of yarn, he will demand 1-3 pieces of
any yarn cloth
* otherwise, he will randomly pick one of the 3 cloth types (silk, plant fiber, or yarn) and demand 1-3 pieces of it
Glassmakers will demand their favorite type of glass
if you've made raw glass of that type; otherwise, they'll pick one randomly (but still limited by what you've made).
Bone carvers will only demand shells if they have a preference for them, otherwise they'll demand bones.
For anything else, it's random.
If you want to see how it actually works, take a look at the
source code for the "strangemood" DFHack plugin, which was pretty much written directly based on a disassembly of DF's own code. I haven't verified all of it against 0.40.24, but it should be mostly correct.