optimalized targeting code

optimalized targeting code to prevent repeated code, and added check to
prevent for example: an anti air towers shooting ground enemies.