well, it would be rather time consuming to do a gps scan of every space in between you and the detonation point, but you can use scan forward to atleast make sure the first 5 spaces are clear. ofcourse there are still problems with this, you may be only 2 spaces away, but the barrier is 4 spaces away, so your bug doesnt shoot coz it scanned a barrier.
the solution that seems to work for me requires you to do 2 things, 1st calculate whether the enemy is (a)facing parallel to your heading, or (b)perpindicular to your heading.
then you work out the maximum distance for (a) and (b) that you can fire a gren and reliable hit the enemy, even if they try to escape. for (a) its likely to be around 7 spaces i think, for (b) its probably only 3 spaces.
2nd have 2 gren attack routines one for (a) and another for (b). check the distance, and if the distance is within the "maximum sure-hit distance" for each case then scan relative 1, if the space is empty, fire! and then set your fuse to the distance from the enemy (or 1 less if you want to be tricky).
this will reduce those long distance gren firing which hardly ever hit, and also save you from firing a gren point blank into a barrier.