Pathfinding.
Or Poor Mans Obstacle Avoidance.
Whats this?
Well, Poor Mans Obstacle Avoidance can be found in some of the AUMS. It basicly works like that:
You constantly check the front of the enemy by using c_trace.
If the trace hits a wall in a certain distance, you add some pan to the enemies angle.
Thats how it basicly works, check the AUMS for details.
Or get yourself into pathfinding, but thats much more difficult.