//-----------------------------------------------------------------------------
// Bicycle
//
// Legend Studios S.L.
//
// Based in a resource from Lloyd [Bleeptech] Godsey
// http://www.garagegames.com/mg/forums/result.thread.php?qt=15645 
// Thank you !!
//-----------------------------------------------------------------------------

// Load dts shapes and merge animations
exec("~/data/shapes/bici/bicycle.cs");

//-----------------------------------------------------------------------------

// Information extacted from the shape.
//
// Wheel Sequences
//    spring#        Wheel spring motion: time 0 = wheel fully extended,
//                   the hub must be displaced, but not directly animated
//                   as it will be rotated in code.
// Other Sequences
//    steering       Wheel steering: time 0 = full right, 0.5 = center
//    breakLight     Break light, time 0 = off, 1 = breaking
//
// Wheel Nodes
//    hub#           Wheel hub, the hub must be in it's upper position
//                   from which the springs are mounted.
//
// The steering and animation sequences are optional.
// The center of the shape acts as the center of mass for the car.

//-----------------------------------------------------------------------------
datablock AudioProfile(BiciEngineSound)
{
   filename    = "~/data/sound/bicycle01.wav";
   description = AudioClosestLooping3d;
   preload = true;
};

datablock ParticleData(TireParticle)
{
   textureName          = "~/data/shapes/bici/dustParticle";
   dragCoefficient      = 2.0;
   gravityCoefficient   = -0.1;
   inheritedVelFactor   = 0.1;
   constantAcceleration = 0.0;
   lifetimeMS           = 1000;
   lifetimeVarianceMS   = 0;
   colors[0]     = "0.46 0.36 0.26 1.0";
   colors[1]     = "0.46 0.46 0.36 0.0";
   sizes[0]      = 0.050;
   sizes[1]      = 0.10;
};

datablock ParticleEmitterData(TireEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 1;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 5;
   thetaMax         = 20;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "TireParticle";
};

//----------------------------------------------------------------------------

// Suspension is split to allow for using existing bikes or motorcycles as a pattern
datablock WheeledVehicleTire(FrontTire)
{
   shapeFile = "~/data/shapes/bici/wheel.dts";
   staticFriction = 0;
   kineticFriction = 125;
   // Spring that generates lateral tire forces
   lateralForce = 2000;
   lateralDamping = 1500;
   lateralRelaxation = 0.1;
   // Spring that generates longitudinal tire forces
   longitudinalForce = 20000;
   longitudinalDamping = 1500;
   longitudinalRelaxation = 0.1;
};

datablock WheeledVehicleSpring(FrontSpring)
{
   // Wheel suspension properties
   length = 0.028;             // Suspension travel 0.06
   force = 41750;              // Spring force 1200 13750 21750
   damping = 0;             // Spring damping 600
   antiSwayForce = 10000;         // Lateral anti-sway force 13000
};

//----------------------------------------------------------------------------

datablock WheeledVehicleTire(BackTire)
{
   shapeFile = "~/data/shapes/bici/wheel.dts";
   staticFriction = 40;
   kineticFriction = 125;
   // Spring that generates lateral tire forces
   lateralForce = 2000;
   lateralDamping = 1500;
   lateralRelaxation = 0.1;
   // Spring that generates longitudinal tire forces
   longitudinalForce = 20000;
   longitudinalDamping = 1500;
   longitudinalRelaxation = 0.1;
};

datablock WheeledVehicleSpring(BackSpring)
{
   // Wheel suspension properties
   length = 0.038;             // Suspension travel 0.099
   force = 28000;              // Spring force 800 900
   damping = 150;             // Spring damping 600 400
   antiSwayForce = 10000;         // Lateral anti-sway force 13000
};

//----------------------------------------------------------------------------

datablock WheeledVehicleData(Bicycle)
{
   category = "Vehicles";
   shapeFile = "~/data/shapes/bici/bicycle.dts";
   
   emap = false;
   maxDamage = 1.0;
   destroyedLevel = 0.5;
   
   maxSteeringAngle = 0.796;  // Maximum steering angle, should match animation  0.7854  
   tireEmitter = TireEmitter; // All the tires use the same dust emitter
   
   cameraRoll = false;         // Roll the camera with the vehicle
   cameraMaxDist = 6;         // Far distance from vehicle
   cameraOffset = 1.5;        // Vertical offset from camera mount point
   cameraLag = 0.1;           // Velocity lag of camera
   cameraDecay = 0.75;        // Decay per sec. rate of velocity lag

   // Rigid Body
   mass = 105;  // mass * what = kilos?

   massCenter = "0 0 0";   // Center of mass for rigid body
                                // Width/Length/Height for this model
   massBox = "11 10 1";         // Size of box used for moment of inertia,
                              // if zero it defaults to object bounding box
                              
   downForce = 1.5;
   steeringSequenceWheels = 1; //number of wheels that are affected by the steering animation


   drag = 0.8;                // Drag coefficient
   bodyFriction = 1.9;
   bodyRestitution = 0.9;

//------------------------------------------------------------------------
// The following lines were yoinked from the Tribes 2 MPB script
// and appear to work after upping the values.
// Do these names actually mean anything to the Torque engine?

   gyroForce = 900;
   gyroDamping = 9;
   stabilizerForce = 100;

//------------------------------------------------------------------------

   minImpactSpeed = 5;        // Impacts over this invoke the script callback
   softImpactSpeed = 5;       // Play SoftImpact Sound
   hardImpactSpeed = 15;      // Play HardImpact Sound
   integration = 4;           // Physics integration: TickSec/Rate
   collisionTol = 0.1;        // Collision distance tolerance
   contactTol = 0.1;          // Contact velocity tolerance

   // Engine
   engineTorque = 425;       // Engine power  300
   engineBrake = 50;         // Braking when throttle is 0 900
   brakeTorque = 700;        // When brakes are applied
   maxWheelSpeed = 18;        // Engine scale by current speed / max speed

   // Energy
   maxEnergy = 10000;
   jetForce = 3000;
   minJetEnergy = 30;
   jetEnergyDrain = 2;
   
   // Mount information
   maxMountSpeed = 0.1;
   mountDelay = 2;
   dismountDelay = 1;
   stationaryThreshold = 0.5;
   maxDismountSpeed = 0.1;
   numMountPoints = 1;
   mountable = true;
   mountPose[0] = "scoutroot";
   mountPointTransform[0] = "0 0 0 0 0 1 0";
   isProtectedMountPoint[0] = false;
};

//-----------------------------------------------------------------------------

function WheeledVehicleData::create(%block)
{
   %obj = new WheeledVehicle() {
      dataBlock = %block;
   };
   return(%obj);
}

//-----------------------------------------------------------------------------

function WheeledVehicleData::onAdd(%this, %obj)
{
   %obj.setWheelTire(0,FrontTire);
   %obj.setWheelSpring(0,FrontSpring);

   %obj.setWheelTire(1,BackTire);
   %obj.setWheelSpring(1,BackSpring);

   %obj.setWheelSteering(0,1);
   %obj.setWheelSteering(1,0);

   %obj.setWheelPowered(0,false);
   %obj.setWheelPowered(1,true);
}


function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
   // Collision with other objects, including items
   //MessageBoxOk("OK");
}

    Source: geocities.com/es/chonlia

               ( geocities.com/es)