Is there any fast way to determine the distance to a target that a unit is currently aiming at?
If anybody could help me out on this, I would be much obliged

Moderator: Moderators
Off course some part of it needs the rest of the bos, but pasting the whole 1300 lines here would only add confusion, and I don't remember if and where I have uploaded the lastest version of the space slug. But hopefully you're now a good enough scriptor to understand how to retrieve and adapt the part you need while leaving the rest.AimPrimary(heading, pitch)
{
if (biting_in_progress)
{
if(heading!=last_heading || ((!spring) && (pitch!=last_pitch)))//because in spring the pitch can change if terrain is dug
{
if ((can_barf) && (attack_mode==0))
{
attack_mode=1;
//var heading_minus_last_heading; // Spring don't like that being there, so this variable was made global
heading_minus_last_heading=heading - last_heading;
while (heading_minus_last_heading<0)
{heading_minus_last_heading=heading_minus_last_heading + 65536;}
while(heading_minus_last_heading>32767)
{heading_minus_last_heading=heading_minus_last_heading - 65536;}
if (heading_minus_last_heading < 0)
{
turn seg01 to y-axis last_heading - <10> speed barf_turn_speed;
}
if (heading_minus_last_heading > 0)
{
turn seg01 to y-axis last_heading + <10> speed barf_turn_speed;
}
last_heading=heading;
last_pitch=pitch;
}
}
return(FALSE);
}
if (already_aiming)
{
attack_mode=5;
return(FALSE);
}
if(heading==last_heading && (spring || pitch==last_pitch))//because in spring the pitch can change if terrain is dug
{return(FALSE);}
signal SIG_AIM1;
set-signal-mask SIG_AIM1;
already_aiming=TRUE;
// Script to determine the absolute xz position of target_finder_extremity point
// Works only for LOS weapon, and within range
// The idea is:
// - Put the turret center on a very up position
// - Wait till an aiming is done
// - Retrieve the heading and pitch
// - Turn the turret accordingly
// - Move a piece further and further folling the weapon LOS, until it goes underground
// - Use dichotomia inside the interval [turret, point underground] to find the exact limit where the piece moving along weapon LOS goes through ground
// - Use that position as xz
//don't forget that in the create there is a //move target_finder_center to y-axis [2000] now; // 200000 makes very weird things
var arm_length, arm_length_inc;
turn target_finder_center to y-axis heading now;
turn target_finder_center to x-axis (0 - pitch) now;
move target_finder_extremity to z-axis 0 now;
if(spring){sleep 1;}//override spring smoothing
arm_length=2;
while (get GROUND_HEIGHT(get PIECE_XZ(target_finder_extremity))<get PIECE_Y(target_finder_extremity))//while target_finder_extremity_point is over the ground
{
arm_length=arm_length*2;
// Lock Prevention
if (arm_length==1073741824)
{arm_length=1073741823;}
if (arm_length==2147483646)
{
while(1)
{
already_aiming=FALSE;
sleep 99999;
}
}
// Lock Prevention
move target_finder_extremity to z-axis arm_length now;move target_finder_extremity to z-axis arm_length speed 1;
if(spring){sleep 1;}//override spring smoothing
//wait-for-move target_finder_extremity along z-axis;
//explode target_finder_extremity type BITMAPONLY | BITMAP2;
}
arm_length_inc=arm_length;
while (arm_length_inc>0)
{
arm_length_inc=arm_length_inc/2;
move target_finder_extremity to z-axis (arm_length - arm_length_inc) now;
if(spring){sleep 1;}//override spring smoothing
//wait-for-move target_finder_extremity along z-axis;
//explode target_finder_extremity type BITMAPONLY | BITMAPNUKE;
if (get GROUND_HEIGHT(get PIECE_XZ(target_finder_extremity))>get PIECE_Y(target_finder_extremity))//if target_finder_extremity_point is underground
{
arm_length=arm_length - arm_length_inc;
}
}
chosen_point_xz=get PIECE_XZ(target_finder_extremity);
//explode target_finder_extremity type BITMAPONLY | BITMAP2;
letfirego=FALSE;
if (!biting_in_progress)
{
biting_in_progress=TRUE;
attack_mode=0;
last_heading=heading;
last_pitch=pitch;
call-script Bite(chosen_point_xz,get GROUND_HEIGHT(chosen_point_xz));
}//end if not already biting
while(!letfirego)
{
already_aiming=FALSE;
sleep 200;
}
return(TRUE);
}