It's really complicated and it was complicated in AOK too, but in a different way. These models were both implemented just because they look cooler when arrows sometimes miss.
In AOM, the first shot usually has bad accuracy (say 50%). The accuracy is also worse at range. This was not done to encourage you to move your units closer, but because it looks dumb when units miss each other at point blank. Each shot after the first shot on the same target also gets a huge bonus, so that by the second or third shot you have a 100% chance to hit. This means you are often better off letting your archers pick their targets than trying to pick targets for them, because you may force them to waste their more accurate shots. Also, because the bonus is so high for secondary and subsequent shots, you are better off fighting at range and not wasting time to move your units up close.
Missed shots have a chance to strike another target, but they do less damage to unintentional targets. (This was not the case in AOK, which let Trebs be much better against massed archers than we intended.)
There is also a concept of what we call tracking, or whether or not you can anticipate a moving target and fire a little ahead of him in order to hit. Generally cavalry and some fast infantry are too fast to be hit by most ranged units. Siege weapons will miss almost any moving target. Heroes tend to have very good tracking. There is also an improvement to make your buildings track better, which is key to stopping raiding cav (who are already pretty pierce resistant).
Finally, the determination of whether a shot will hit or miss is made when the shot is fired. This means that you can't just dance a unit out of the way of an incoming missile. Micromanagement has its place in our games, but it should be secondary to strategy.
BTW, there is no friendly fire for any unit in AOM (even siege), though some GPs will damage friendly units, but cause less damage than they do to enemies.