datablock AudioProfile(HandheldArtilleryFireSound)
{
   filename    = "./artyshot.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock AudioProfile(HandheldArtilleryExplosionSound)
{
   filename    = "./kaboomer.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock AudioProfile(HandheldArtilleryReload1Sound)
{
   filename    = "./clickPlant.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock AudioProfile(HandheldArtilleryReload2Sound)
{
   filename    = "./clickRotate.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock ParticleData(HandheldArtilleryFlashParticle)
{
	dragCoefficient		= 3.0;
	windCoefficient		= 0.0;
	gravityCoefficient	= 0.0;
	inheritedVelFactor	= 0.0;
	constantAcceleration	= 0.0;
	lifetimeMS		= 500;
	lifetimeVarianceMS	= 100;
	spinSpeed		= 10.0;
	spinRandomMin		= -50.0;
	spinRandomMax		= 50.0;
	useInvAlpha		= false;
	animateTexture		= false;
	textureName		= "base/data/particles/cloud";
	// Interpolation variables
	colors[0]	= "1 0.875 0.75 0.75";
	colors[1]	= "1.0 0.5 0.0 0.5";
	sizes[0]	= 0.6;
	sizes[1]	= 0.5;
};
datablock ParticleEmitterData(HandheldArtilleryFlashEmitter)
{
   ejectionPeriodMS = 5;
   periodVarianceMS = 0;
   ejectionVelocity = 0; //0.25;
   velocityVariance = 0; //0.10;
   ejectionOffset = 0;
   thetaMin         = 0.0;
   thetaMax         = 90.0;  
   particles = HandheldArtilleryFlashParticle;
   useEmitterColors = true;
};
datablock DebrisData(HandheldArtilleryShellDebris)
{
	shapeFile = "./shell.dts";
	lifetime = 4.0;
	minSpinSpeed = -400.0;
	maxSpinSpeed = 200.0;
	elasticity = 0.5;
	friction = 0.2;
	numBounces = 3;
	staticOnMaxBounce = true;
	snapOnMaxBounce = false;
	fade = true;
	gravModifier = 1;
};
datablock ParticleData(HandheldArtilleryExplosionParticle)
{
	dragCoefficient      = 5;
	gravityCoefficient   = 0;
	inheritedVelFactor   = 0;
	constantAcceleration = 0.0;
	lifetimeMS           = 100;
	lifetimeVarianceMS   = 10;
	textureName          = "base/data/particles/star1";
	spinSpeed		= 500.0;
	spinRandomMin		= -500.0;
	spinRandomMax		= 500.0;
	colors[0]     = "1 1 1 0";
	colors[1]     = "1 0.25 0 0.9";
	sizes[0]      = 6;
	sizes[1]      = 12;
	times[0] = 0.0;
	times[1] = 0.025;
	useInvAlpha = false;
};
datablock ParticleEmitterData(HandheldArtilleryExplosionEmitter)
{
   ejectionPeriodMS = 5;
   periodVarianceMS = 0;
   ejectionVelocity = 2;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 89;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "HandheldArtilleryExplosionParticle";
};
datablock ParticleData(HandheldArtillerySmokeParticle)
{
	dragCoefficient      = 3;
	gravityCoefficient   = -1.25;
	inheritedVelFactor   = 0.2;
	constantAcceleration = 0.0;
	lifetimeMS           = 700;
	lifetimeVarianceMS   = 300;
	textureName          = "base/data/particles/cloud";
	spinSpeed		= 10.0;
	spinRandomMin		= -20.0;
	spinRandomMax		= 20.0;
   	colors[0]     = "1 0.5 0.0 1.0";
	colors[1]     = "0.6 0.4 0.4 0.25";
	colors[2]     = "0.25 0.25 0.25 0.0";
	sizes[0]      = 20;
   	sizes[1]      = 22.5;
	sizes[2]      = 25;
   times[0] = 0.0;
   times[1] = 0.25;
   times[2] = 1.0;
	useInvAlpha = true;
};
datablock ParticleEmitterData(HandheldArtillerySmokeEmitter)
{
   ejectionPeriodMS = 25;
   periodVarianceMS = 0;
   ejectionVelocity = 2.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 25;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "HandheldArtillerySmokeParticle";
};
datablock ExplosionData(HandheldArtilleryExplosion)
{
   //explosionShape = "";
   explosionShape = "add-ons/weapon_rocket_launcher/explosionSphere1.dts";
	soundProfile = HandheldArtilleryExplosionSound;
   lifeTimeMS = 200;
   particleEmitter = HandheldArtilleryExplosionEmitter;
   particleDensity = 65;
   particleRadius = 0.3;
   emitter[0] = HandheldArtillerySmokeEmitter;
   emitter[1] = HandheldArtilleryExplosionEmitter;
   faceViewer     = true;
   explosionScale = "1 1 1";
   shakeCamera = true;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "3.0 10.0 3.0";
   camShakeDuration = 1;
   camShakeRadius = 40.0;
   // Dynamic light
   lightStartRadius = 5;
   lightEndRadius = 30;
   lightStartColor = "1 0.85 0.8 1";
   lightEndColor = "0 0 0 0";
   damageRadius = 15;
   radiusDamage = 100;
   impulseRadius = 20;
   impulseForce = 1000;
};
datablock ParticleData(HandheldArtilleryTrailParticle)
{
	dragCoefficient      = 3;
	gravityCoefficient   = -0.0;
	inheritedVelFactor   = 0.15;
	constantAcceleration = 0.0;
	lifetimeMS           = 1000;
	lifetimeVarianceMS   = 805;
	textureName          = "base/data/particles/cloud";
	spinSpeed		= 10.0;
	spinRandomMin		= -150.0;
	spinRandomMax		= 150.0;
	colors[0]     = "1.0 1.0 0.0 0.4";
	colors[1]     = "1.0 0.2 0.0 0.5";
	sizes[0]      = 0.3;
	sizes[1]      = 0.9;
	useInvAlpha = false;
};
datablock ParticleEmitterData(HandheldArtilleryTrailEmitter)
{
   ejectionPeriodMS = 8;
   periodVarianceMS = 1;
   ejectionVelocity = 0.25;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "HandheldArtilleryTrailParticle";
   uiName = "";
};
AddDamageType("HandheldArtillery",   '<bitmap:add-ons/Weapon_HandheldArtillery/CI_HandheldArtillery> %1',    '%2 <bitmap:add-ons/Weapon_HandheldArtillery/CI_HandheldArtillery> %1',0.75,1);
datablock ProjectileData(HandheldArtilleryProjectile)
{
   projectileShapeName = "add-ons/Vehicle_Tank/tankbullet.dts";
   directDamage        = 250;
   directDamageType    = $DamageType::HandheldArtillery;
   radiusDamageType    = $DamageType::HandheldArtillery;
   brickExplosionRadius = 5;
   brickExplosionImpact = false;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 35;             
   brickExplosionMaxVolume = 45;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 60;  //max volume of bricks that we can destroy if they aren't connected to the ground (should always be >= brickExplosionMaxVolume)
   impactImpulse	= 1000;
   verticalImpulse	= 1000;
   explosion           = HandheldArtilleryExplosion;
   particleEmitter     = HandheldArtilleryTrailEmitter;
   muzzleVelocity      = 200;
   velInheritFactor    = 0;
   armingDelay         = 0;
   lifetime            = 4000;
   fadeDelay           = 3500;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;
   isBallistic         = true;
   gravityMod = 1.0;
   hasLight    = true;
   lightRadius = 5.0;
   lightColor  = "1 0.5 0";
   
   uiName = "Handheld Artillery Shell";
};
//////////
// item //
//////////
datablock ItemData(HandheldArtilleryItem)
{
	category = "Weapon";  // Mission editor category
	className = "Weapon"; // For inventory system
	 // Basic Item Properties
	shapeFile = "./handheldartillery.dts";
	rotate = false;
	mass = 1;
	density = 0.2;
	elasticity = 0.2;
	friction = 0.6;
	emap = true;
	//gui stuff
	uiName = "Handheld Artillery";
	iconName = "./icon";
	doColorShift = true;
	colorShiftColor = "0.25 0.25 0.25 1.000";
	 // Dynamic properties defined by the scripts
	image = HandheldArtilleryImage;
	canDrop = true;
};
////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(HandheldArtilleryImage)
{
   // Basic Item properties
   shapeFile = "./handheldartillery.dts";
   emap = true;
   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
   eyeOffset = 0; //"0.7 1.2 -0.5";
   rotation = eulerToMatrix( "0 0 0" );
   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off.  
   correctMuzzleVector = true;
   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";
   // Projectile && Ammo.
   item = HandheldArtilleryItem;
   ammo = " ";
   projectile = HandheldArtilleryProjectile;
   projectileType = Projectile;
	casing = HandheldArtilleryShellDebris;
	shellExitDir        = "1.0 -1.3 1.0";
	shellExitOffset     = "0 0 0";
	shellExitVariance   = 15.0;	
	shellVelocity       = 7.0;
   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = true;
   minShotTime = 1000; 
   doColorShift = false;
   colorShiftColor = HandheldArtilleryItem.colorShiftColor;
   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.
   // Initial start up state
	stateName[0]                     = "Activate";
	stateTimeoutValue[0]             = 0.15;
	stateTransitionOnTimeout[0]      = "Ready";
	stateSound[0]			= weaponSwitchSound;
	stateName[1]                     = "Ready";
	stateTransitionOnTriggerDown[1]  = "Fire";
	stateAllowImageChange[1]         = true;
	stateSequence[1]		= "Ready";
	stateName[2]                    = "Fire";
	stateTransitionOnTimeout[2]     = "Wait";
	stateTimeoutValue[2]            = 0.14;
	stateFire[2]                    = true;
	stateAllowImageChange[2]        = false;
	stateSequence[2]                = "Fire";
	stateScript[2]                  = "onFire";
	stateWaitForTimeout[2]		= true;
	stateEmitter[2]			= HandheldArtilleryFlashEmitter;
	stateEmitterTime[2]		= 0.05;
	stateEmitterNode[2]		= "muzzleNode";
	stateSound[2]			= HandheldArtilleryFireSound;
	stateEjectShell[2]       	= true;
	stateName[3] 			= "Wait";
	stateTimeoutValue[3]            = 1;
	stateScript[3]			= "onWait";
	stateTransitionOnTimeout[3]     = "Load";
	stateSound[3]			= HandheldArtilleryReload1Sound;
	stateSequence[3]		= "Wait";
	stateName[4]			= "Load";
	stateTimeoutValue[4]		= 2;
	stateScript[4]			= "onLoad";
	stateTransitionOnTimeout[4]     = "Reload";
	stateSound[4]			= HandheldArtilleryReload2Sound;
	stateSequence[4]		= "Load";
	stateName[5]			= "Reload";
	stateSequence[5]                = "Reload";
	stateScript[5]			= "onReady";
	stateTransitionOnTriggerUp[5]    = "Ready";
	stateSound[5]			= HandheldArtilleryReload1Sound;
	stateSequence[5]		= "Ready";
};
function HandheldArtilleryImage::onFire(%this,%obj,%slot)
{
	if(%obj.getDamagePercent() < 1.0)
		%obj.playThread(2, shiftAway);
	%obj.spawnExplosion(HandheldArtilleryRecoilProjectile,"1 1 1");
	Parent::onFire(%this,%obj,%slot);	
}
function HandheldArtilleryImage::onWait(%this,%obj,%slot)
{
		%obj.playThread(2, plantBrick);
}
function HandheldArtilleryImage::onLoad(%this,%obj,%slot)
{
		%obj.playThread(4, shiftLeft);
}
function HandheldArtilleryImage::onReady(%this,%obj,%slot)
{
		%obj.playThread(2, plantBrick);
}