
//**************************************************************
// JERICHO FORWARD BASE (Mobile Point Base)
//**************************************************************
//**************************************************************
// SOUNDS
//**************************************************************

datablock AudioProfile(MPBEngineSound)
{
   filename    = "fx/vehicles/mpb_thrust.wav";
   description = AudioDefaultLooping3d;
   preload = true;
};

datablock AudioProfile(MPBThrustSound)
{
   filename    = "fx/vehicles/mpb_boost.wav";
   description = AudioDefaultLooping3d;
   preload = true;
};

datablock AudioProfile(MobileBaseDeploySound)
{
   filename    = "fx/vehicles/MPB_deploy.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(MobileBaseUndeploySound)
{
   filename    = "fx/vehicles/MPB_undeploy_turret.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(MobileBaseTurretDeploySound)
{
   filename    = "fx/vehicles/MPB_deploy_turret.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(MobileBaseTurretUndeploySound)
{
   filename    = "fx/vehicles/MPB_undeploy_turret.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(MobileBaseStationDeploySound)
{
   filename    = "fx/vehicles/MPB_deploy_station.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(MobileBaseStationUndeploySound)
{
   filename    = "fx/vehicles/MPB_close_lid.wav";
   description = AudioClose3d;
   preload = true;
};


//**************************************************************
// LIGHTS
//**************************************************************
datablock RunningLightData(MPBLight1)
{
   pointSize = 3.0;
   pointColor = "1.0 1.0 1.0 0.3";
   pointNodeName = "Headlight_node01";
   texture = "special/expFlare";
};

datablock RunningLightData(MPBLight2)
{
   pointSize = 3.0;
   pointColor = "1.0 1.0 1.0 0.3";
   pointNodeName = "Headlight_node02";
   texture = "special/expFlare";
};


//**************************************************************
// VEHICLE CHARACTERISTICS
//**************************************************************
datablock SensorData(MPBDeployedSensor) : VehiclePulseSensor
{
   jams = true;
   jamsOnlyGroup = true;
   jamsUsingLOS = false;
   jamRadius = 50;
};

datablock WheeledVehicleData(MobileBaseVehicle) : MPBDamageProfile
{
   spawnOffset = "0 0 1.0";
   renderWhenDestroyed = false;

   catagory = "Vehicles";
   shapeFile = "vehicle_land_mpbase.dts";
   multipassenger = false;
   computeCRC = true;

   debrisBase = 14;
   debrisVariance = 6;
   debrisShapeName = "vehicle_land_mpbase_debris.dts";
//   debris = ShapeDebris;
   debrisEjectionScale = 2.0;

   drag = 0.0;
   density = 20.0;

   mountPose[0] = sitting;
   numMountPoints = 1;
   isProtectedMountPoint[0] = true;

   ELFDrain  = 3.5;

   cantAbandon = 1;
   cantTeamSwitch = 1;
   
   cameraMaxDist = 20;
   cameraOffset = 6;
   cameraLag = 1.5;
   explosion = LargeGroundVehicleExplosion;
   explosionDamage = 0.5;
   explosionRadius = 5.0;

   maxSteeringAngle = 0.3;  // 20 deg.

   // Used to test if the station can deploy
   stationPoints[1] = "-2.3 -7.38703 -0.65";
   stationPoints[2] = "-2.3 -11.8 -0.65";
   stationPoints[3] = "0 -7.38703 -0.65";
   stationPoints[4] = "0 -11.8 -0.65";
   stationPoints[5] = "2.3 -7.38703 -0.65";
   stationPoints[6] = "2.3 -11.8 -0.65";

   // Rigid Body
   mass = 2000;
   bodyFriction = 0.8;
   bodyRestitution = 0.5;
   minRollSpeed = 3;
   gyroForce = 400;
   gyroDamping = 0.3;
   stabilizerForce = 10;
   minDrag = 10;
   softImpactSpeed = 15;       // Play SoftImpact Sound
   hardImpactSpeed = 25;      // Play HardImpact Sound

   // Ground Impact Damage (uses DamageType::Ground)
   minImpactSpeed = 12;
   speedDamageScale = 0.060;

   // Object Impact Damage (uses DamageType::Impact)
   collDamageThresholdVel = 18;
   collDamageMultiplier   = 0.070;

   // Engine
   engineTorque = 7.0 * 745;
   breakTorque = 7.0 * 745;
   maxWheelSpeed = 20;

   // Springs
   springForce = 8000;
   springDamping = 1300;
   antiSwayForce = 6000;
   staticLoadScale = 2;

   // Tires
   tireRadius = 1.6;
   tireFriction = 10.0;
   tireRestitution = 0.5;
   tireLateralForce = 3000;
   tireLateralDamping = 400;
   tireLateralRelaxation = 1;
   tireLongitudinalForce = 12000;
   tireLongitudinalDamping = 600;
   tireLongitudinalRelaxation = 1;
   tireEmitter = TireEmitter;

   //   
   maxDamage = 3.85;
   destroyedLevel = 3.85;

   isShielded = true;
   energyPerDamagePoint = 105;
   maxEnergy = 400;
   jetForce = 2000;
   minJetEnergy = 60;
   jetEnergyDrain = 1.4;
   rechargeRate = 0.85;

   jetSound = MPBThrustSound;
   engineSound = MPBEngineSound;
   squeelSound = AssaultVehicleSkid;
   softImpactSound = GravSoftImpactSound;
   hardImpactSound = HardImpactSound;
   wheelImpactSound = WheelImpactSound;

   //
   softSplashSoundVelocity = 5.0; 
   mediumSplashSoundVelocity = 8.0;   
   hardSplashSoundVelocity = 12.0;   
   exitSplashSoundVelocity = 8.0;
   
   exitingWater      = VehicleExitWaterSoftSound;
   impactWaterEasy   = VehicleImpactWaterSoftSound;
   impactWaterMedium = VehicleImpactWaterMediumSound;
   impactWaterHard   = VehicleImpactWaterHardSound;
   waterWakeSound    = VehicleWakeMediumSplashSound; 

   minMountDist = 3;

   damageEmitter[0] = LightDamageSmoke;
   damageEmitter[1] = HeavyDamageSmoke;
   damageEmitter[2] = DamageBubbles;
   damageEmitterOffset[0] = "3.0 0.5 0.0 ";
   damageEmitterOffset[1] = "-3.0 0.5 0.0 ";
   damageLevelTolerance[0] = 0.3;
   damageLevelTolerance[1] = 0.7;
   numDmgEmitterAreas = 2;

   splashEmitter[0] = VehicleFoamDropletsEmitter;
   splashEmitter[1] = VehicleFoamEmitter;

   shieldImpact = VehicleShieldImpact;

   cmdCategory = "Tactical";
   cmdIcon = CMDGroundMPBIcon;
   cmdMiniIconName = "commander/MiniIcons/com_mpb_grey";
   targetNameTag = 'Jericho';
   targetTypeTag = 'MPB';
   sensorData = VehiclePulseSensor;

   checkRadius = 7.5225;
   
   observeParameters = "1 12 12";

   runningLight[0] = MPBLight1;
   runningLight[1] = MPBLight2;

   shieldEffectScale = "0.85 1.2 0.7";
};

//**************************************************************
// WEAPONS
//**************************************************************

datablock SensorData(MPBTurretMissileSensor)
{
   detects = true;
   detectsUsingLOS = true;
   detectsPassiveJammed = false;
   detectsActiveJammed = false;
   detectsCloaked = false;
   detectionPings = true;
   detectRadius = 200;
};

datablock TurretData(MobileTurretBase)
{
   className      = VehicleTurret;
   catagory       = "Turrets";
   shapeFile      = "turret_base_mpb.dts";

   preload        = true;

   mass           = 1.0;

   Name = "MPB Turret Base";

   maxDamage      = MobileBaseVehicle.maxDamage;
   destroyedLevel = MobileBaseVehicle.destroyedLevel;
   
   thetaMin      = 15;
   thetaMax      = 140;

   energyPerDamagePoint = 33;
   inheritEnergyFromMount = true;
   firstPersonOnly = true;

   sensorColor = "0 212 45";
   sensorData = MPBTurretMissileSensor;
   sensorRadius = MPBTurretMissileSensor.detectRadius;

   cmdCategory = "Tactical";

   cmdMiniIconName = "commander/MiniIcons/com_turret_grey";
   targetNameTag = 'Jericho';
   targetTypeTag = 'Turret';

   canControl = true;

   TurretBase = true;
};

function MobileBaseVehicle::onAdd(%this, %Vehicle)
{
   Parent::onAdd(%this, %Vehicle);
   %Vehicle.station = "";
   %Vehicle.turret = "";
   %Vehicle.Barrel = MissileBarrelLarge;
   
   %Vehicle.schedule(5000, "playThread", $AmbientThread, "ambient");
}

function MobileBaseVehicle::playerMounted(%Data, %Vehicle, %Player, %node)
{
   commandToClient(%Player.client, 'setHudMode', 'Pilot', "MPB", %node);

   if(%Vehicle.deploySchedule !$= "")
   {
      %Vehicle.deploySchedule.clear();
      %Vehicle.deploySchedule = "";
   }

   // If it is deployed, then undeploy everything   
   if(%Vehicle.deployed !$= "" && %Vehicle.deployed == true)
   {
      %Vehicle.setThreadDir($DeployThread, false);
      %Vehicle.playThread($DeployThread,"deploy");  
      %Vehicle.playAudio($DeploySound, MobileBaseUndeploySound);

      // Retract the Inventory Station
      %Vehicle.station.setThreadDir($DeployThread, false);
      %Vehicle.station.getDataBlock().onLosePowerDisabled(%Vehicle.station);
      %Vehicle.station.clearSelfPowered();
      %Vehicle.station.goingOut = false;
      %Vehicle.station.notDeployed = true;
      %Vehicle.station.playAudio($DeploySound, MobileBaseStationUndeploySound);

      // Retract the Turret
      %Vehicle.turret.setThreadDir($DeployThread, false);
      %Vehicle.turret.playAudio($DeploySound, MobileBaseTurretUndeploySound);
      %Vehicle.turret.clearSelfPowered();

      // Remove the Beacon to it.
      if (%Vehicle.Beacon !$= "")
      {
         %Vehicle.Beacon.delete();
         %Vehicle.Beacon = "";
      }

      // Clear the Drivers force field
      %Vehicle.shield.open();  
      %Vehicle.shield.schedule(1000,"delete"); 

      %Vehicle.deploySchedule = "";
      %Vehicle.fullyDeployed = false;
      %Vehicle.noEnemyControl = false;
   }
   %Vehicle.deployed = false;
}

//**************************************************************
//* JERICHO DEPLOYMENT and UNDEPLOYMENT
//**************************************************************

function MobileBaseVehicle::vehicleDeploy(%Data, %Vehicle, %Player, %ForceDeploy)
{ 
   if(VectorLen(%Vehicle.getVelocity()) <= 0.1 || %ForceDeploy)
   {
      %deployMessage = "";
      if( (%deployMessage = %Data.checkTurretDistance(%Vehicle)) $= "" || %ForceDeploy)
      {
         if(%Vehicle.station $= "")
         {
            if( (%deployMessage = %Data.checkDeploy(%Vehicle)) $= "" || %ForceDeploy)
            {
               // Station behind the MPB
               %Vehicle.station = new StaticShape()
               {
                  scale = "1 1 1";
                  dataBlock = "MobileInvStation";
                  lockCount = "0";
                  homingCount = "0";
                  team = %Vehicle.team;
                  vehicle = %Vehicle;
               };                
               %Vehicle.station.startFade(0,0,true);
               %Vehicle.mountObject(%Vehicle.station, 2);
               %Vehicle.station.getDataBlock().createTrigger(%Vehicle.station);
               %Vehicle.station.setSelfPowered();
               %Vehicle.station.playThread($PowerThread,"Power");
               %Vehicle.station.playAudio($HumSound,StationHumSound);
               %Vehicle.station.vehicle = %Vehicle;

               if (%Vehicle.turret $= "")
               {
                  // Turret on top of the MPB
                  %Turret = new turret()
                  {
                     scale = "1 1 1";
                     dataBlock = "MobileTurretBase";
                     lockCount = "0";
                     homingCount = "0";
                     team = %Vehicle.team;
                   };
                   %Vehicle.turret = %Turret;
                   %Turret.Vehicle = %Vehicle;
                   %Turret.setDamageLevel(%Vehicle.getDamageLevel());
                   %Vehicle.mountObject(%Turret, 1);
                   %Turret.setSelfPowered();
                   %Turret.playThread($PowerThread,"Power");
                   %Turret.mountImage(%Vehicle.Barrel, 0 ,false);
               }
               
               checkSpawnPos(%Vehicle, 20);
            }
         }
         else
         {
            %Vehicle.station.setSelfPowered();
            %Vehicle.station.playThread($PowerThread,"Power");

            %Vehicle.turret.setSelfPowered();
            %Vehicle.turret.playThread($PowerThread,"Power");
         }

         if(%deployMessage $= "" || %ForceDeploy)
         {
            if(%Vehicle.turret.getTarget() == -1)
               %Vehicle.turret.setTarget(%Vehicle.turret.target);
               
            %Vehicle.turret.setThreadDir($DeployThread, true);
            %Vehicle.turret.playThread($DeployThread,"deploy");
            %Vehicle.turret.playAudio($DeploySound, MobileBaseTurretDeploySound);
         
            %Vehicle.station.notDeployed = true;
            %Vehicle.setThreadDir($DeployThread, true);
            %Vehicle.playThread($DeployThread,"deploy");  
            %Vehicle.playAudio($DeploySound, MobileBaseDeploySound);

            // Activate the Parking Brake
            %Vehicle.deployed = true;
            %Vehicle.deploySchedule = "";
            %Vehicle.disableMove = true;
            %Vehicle.setFrozenState(true);

            // If there is a previous shield, delete it
            if(isObject(%Vehicle.shield))
               %Vehicle.shield.delete();

            // Make new shield over the drivers seat
            %Vehicle.shield = new forceFieldBare()
            {
               scale = "1.22 1.8 1.1";
               dataBlock = "defaultTeamSlowFieldBare";
               team = %Vehicle.team;
            };
            %Vehicle.shield.open();

            // Setup the Sensor Jammer
            setTargetSensorData(%Vehicle.getTarget(), MPBDeployedSensor);

            //Place a Marker beacon
            %Vehicle.Beacon = new BeaconObject()
            {
               dataBlock = "DeployedBeacon";
               position = %Vehicle.getWorldBoxCenter();
               team = %Vehicle.team;
            };
            MissionCleanup.add(%Vehicle.Beacon);

            %Vehicle.Beacon.setTarget(%Vehicle.team);
            %Vehicle.Beacon.setBeaconType(friend);
         }
      }
      if(%deployMessage !$= "")
         messageClient(%Player.client, '', %deployMessage); 

      return true;
   }
   else
   {
      return false;
   }
}