//
//
//
//	Filename : Vehicles.cs

datablock ParticleData(VehicleFoamParticle)
{
   dragCoefficient      = 2.0;
   gravityCoefficient   = -0.05;
   inheritedVelFactor   = 0.0;
   constantAcceleration = 0.0;
   lifetimeMS           = 1200;	
   lifetimeVarianceMS   = 400;
   useInvAlpha          = false;
   spinRandomMin        = -90.0;
   spinRandomMax        = 500.0;
   textureName          = "~/data/shapes/rifle/smokeParticle";
   colors[0]     = "0.7 0.8 1.0 1.0";
   colors[1]     = "0.7 0.8 1.0 0.5";
   colors[2]     = "0.7 0.8 1.0 0.0";
   sizes[0]      = 2;
   sizes[1]      = 4;
   sizes[2]      = 6;
   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(VehicleFoamEmitter)
{
   ejectionPeriodMS = 40;
   periodVarianceMS = 0;
   ejectionVelocity = 10.0;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 85;
   thetaMax         = 85;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   particles = "VehicleFoamParticle";
};


datablock ParticleData( VehicleFoamDropletsParticle )
{
   dragCoefficient      = 1;
   gravityCoefficient   = 0.2;
   inheritedVelFactor   = 0.2;
   constantAcceleration = -0.0;
   lifetimeMS           = 800;
   lifetimeVarianceMS   = 300;
   textureName          = "~/data/shapes/rifle/smokeParticle";
   colors[0]     = "0.7 0.8 1.0 1.0";
   colors[1]     = "0.7 0.8 1.0 0.5";
   colors[2]     = "0.7 0.8 1.0 0.0";
   sizes[0]      = 8;
   sizes[1]      = 3;
   sizes[2]      = 0;
   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData( VehicleFoamDropletsEmitter )
{
   ejectionPeriodMS = 34;
   periodVarianceMS = 0;
   ejectionVelocity = 10;
   velocityVariance = 5.0;
   ejectionOffset   = 0.0;
   thetaMin         = 60;
   thetaMax         = 80;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   orientParticles  = true;
   particles = "VehicleFoamDropletsParticle";
};

function VehicleData::onAdd(%data, %obj)
{
	%obj.setRechargeRate(%data.rechargeRate);

//	%obj.mountImage(MissileLauncherImage, 0); // Optional Weapon Mounting

	if(%obj.disableMove)
		%obj.immobilized = true;
}

function VehicleData::onRemove(%this, %obj)
{
	// if there are passengers/driver, kick them out
	for(%i = 0; %i < %obj.getDatablock().numMountPoints; %i++)
	{
		if (%obj.getMountNodeObject(%i)) 
		{
			%passenger = %obj.getMountNodeObject(%i);
			%passenger.unmount();
		}
	}
	if(%obj.lastPilot.lastVehicle == %obj)
		%obj.lastPilot.lastVehicle = "";      
}

function VehicleData::playerDismounted(%data, %obj, %player)
{
	if( %player.client.observeCount > 0 )
		resetObserveFollow( %player.client, true );
}

function VehicleData::hasDismountOverrides(%data, %obj)
{
   return false;
}

function FlyingVehicleData::create(%data, %team, %oldObj)
{
   if(%oldObj $= "")
   {
      %obj = new FlyingVehicle() 
      {
         dataBlock  = %data;
         respawn    = "0";
         teamBought = %team;
         team = %team;
      };
   }
   else
   {
      %obj = new FlyingVehicle() 
      {
         dataBlock  = %data;
         respawn    = "0";
         teamBought = %team;
         team = %team;
         mountable = %oldObj.mountable;
         disableMove = %oldObj.disableMove;
         resetPos = %oldObj.resetPos;
         deployed = %oldObj.deployed;
         respawnTime = %oldObj.respawnTime;
         marker = %oldObj;
      };   
   }
   %obj.mountable = true;
   
   return(%obj);
}