Code: Select all
#define HEADING 82 //add to headers, preferably
#define SIG_BUILD 2
StartBuilding(desired_heading)
{
set-signal-mask SIG_BUILD;
if (!isbuilding)
{
isbuilding = 1;
var speed;
speed = <90>; //spin, degrees per second, if it's too big and unit often gets stuck in eternal spins, lower the MSperChange
// radials = spring angle unit
var current_heading;
current_heading = (get HEADING);
var MSperChange;
MSperChange = 40; // milliseconds per cycle of the loop, smaller values for more cpu usage and smoother anim
var RadialsPerChange; //number of radials to increase by every cycle of the loop, calculated from speed
RadialsPerChange = (MSperChange * speed) / 1000;
desired_heading = current_heading + desired_heading; // convert local angle into global one
if (desired_heading > 65535)
{
desired_heading = desired_heading - 65536;
}
if (desired_heading < get HEADING)
{
RadialsPerChange = 0 - RadialsPerChange; // make it go the short way rather than all the way around
}
var headingdiff; //the difference between desired and current headings
var PosRadialsPerChange; //absolute value
var doneturning;
while (!doneturning)
{
sleep MSPerChange;
set HEADING to ((get HEADING) + RadialsPerChange); //spin unit
PosRadialsPerChange = RadialsPerChange; //get absolute value
if (RadialsPerChange < 0)
{
PosRadialsPerChange = 0 - RadialsPerChange;
}
headingdiff = (get HEADING) - desired_heading;
if (headingdiff < 0)
{
headingdiff = headingdiff * -1;
}
if (headingdiff < PosRadialsPerChange) // prevent overshooting, end loop
{
set HEADING to desired_heading;
doneturning = 1;
}
}
set INBUILDSTANCE to 1;
}
}
StopBuilding()
{
signal SIG_BUILD;
isbuilding = 0;
set INBUILDSTANCE to 0;
}
I haven't tried this on a unit with weapons....probably would be rather undesirable.
Go ahead and use it, giving me credit (and perhaps a sneak peek of your mod
