Every weapon has a optimum range at which it is most effective. A mech always tries to hit the target which is closest to its optimum range of the currently equipped weapon (if two or more closest targets are equally away it chooses in alphabetical order).

The damage is reduced by 1/7th for every square out of optimum range.