It should be relatively simple assuming you already have the pathfinding working right. Find the units within X tiles, check if any of them are melee. Check any melee that are found for enough movement. If it's within range, attempt to find a valid path. (This is all more computationally intensive because of road movement bonuses. You end up checking much further out than is possible to move in most cases.) If no matches are found move the ranged units out. Where to move them isn't simple though. Do you move them out to wait for the melee unit coming along the road ... or do you send them to another target ... where it's safe to move and where it isn't ... lots of things to consider. Of course none of that really solves the issue, since you're still left with an AI that can't take cities. In a perverse way, it's actually made it harder because now you have more surviving ranged units to get in the way of the melee units trying to make their way to the front. It just makes the pathfinding that much harder.