#define TA // This is a TA script 

#include "sfxtype.h" 
#include "exptype.h" 


piece base, turret, barrel1, firepoint1, sfxpoint1; // these are the pieces of the model 

#include "ROCKUNIT.H"

static-var gun_1, terraintype, bmoving, moving; // these are the variables 

// Signal definitions 
#define SIG_AIM 2 // this is a aim define 


SmokeUnit(healthpercent, sleeptime, smoketype) // this is a standard smoke point define 
{ 
while( get BUILD_PERCENT_LEFT ) 
{ 
sleep 400; 
} 
while( TRUE ) 
{ 
healthpercent = get HEALTH; 
if( healthpercent < 66 ) 
{ 
smoketype = 256 | 2; 
if( Rand( 1, 66 ) < healthpercent ) 
{ 
smoketype = 256 | 1; 
} 
emit-sfx 1026 from base; 
} 
sleeptime = healthpercent * 50; 
if( sleeptime < 200 ) 
{ 
sleeptime = 200; 
} 
sleep sleeptime; 
} 
} 

EmitWakes()
{
	while( TRUE )
	{
		if( bMoving )
		{
			emit-sfx 2 from base;
		}
		sleep 300;
	}
}

setSFXoccupy(setSFXoccupy_argument)
{	
terraintype = setSFXoccupy_argument;	

                if(terraintype == 2)
		{
                move base to y-axis [-0.85] speed [50]; 
                set UPRIGHT to 1;	
                }
		else
		{
                move base to y-axis [0.0] speed [50];
                set UPRIGHT to 0;	
                }
                if(terraintype == 4)
		{
                move base to y-axis [0] speed [50]; 
                set UPRIGHT to 0;	
                }
		else
		{
                move base to y-axis [-0.85] speed [50];
                set UPRIGHT to 1;	
                }
}

Thrust()
{
   while( TRUE )
   {
      if (moving)    
      {
              emit-sfx 1025 + 0 from sfxpoint1;
                }
        sleep 400;    
   }
}

StartMoving()
{
        moving=1;
}
   
StopMoving()
{   
        moving=0; 
}

Create() // tells it what to do on creation 
{
		start-script Thrust();
        start-script setSFXoccupy(); 
        start-script EmitWakes(); 
start-script SmokeUnit(); 
} 

RestoreAfterDelay() // restore function to turn the turret and so forth back to start 
{ 
sleep 3000; 
turn turret to y-axis <0> speed <60>;
turn barrel1 to x-axis <0> speed <30>;  
} 

AimWeapon1(heading, pitch) // single weapon with 2 fires this tell sit what to do while aiming 
{ 
signal SIG_AIM; 
set-signal-mask SIG_AIM; 
turn turret to y-axis heading speed <225>;
turn barrel1 to x-axis <0> - pitch speed <150>; 
wait-for-turn turret around y-axis;
wait-for-turn barrel1 around x-axis;  
start-script RestoreAfterDelay(); 
return (1); 
} 

FireWeapon1() // what do while firing, fires 1 barrel then the next , and resets 
{ 
emit-sfx 1024 + 0 from firepoint1;
} 

AimFromWeapon1(piecenum) // where it aims the weapon from 
{ 
piecenum = turret; 
} 

QueryWeapon1(piecenum) // where the shot is called from 
{ 
piecenum = firepoint1;  
} 


Killed(severity, corpsetype) // how it explodes 
{ 
	corpsetype = 1; 
	explode barrel1 type EXPLODE_ON_HIT;
	explode turret type EXPLODE_ON_HIT;
} 
