The target choice is defined by weapon type
Empty hand focuses on the frontline
If no target in the frontline, switch to the backline
Melee weapons focus on the frontline
If no target in the frontline, switch to the backline
Range weapons focus on the backline
If no target in the backline, switch to the frontline