moved some common code from pathfinding and lineofsight