function car_noise(ENTITY* car,SOUND* sndEngine,SOUND* sndTire,SOUND* sndCrash)
{
// use skills for the sound handles, to handle them individually per car
if(!car.car_hEngine)
car.car_hEngine = ent_playloop(car,sndEngine,100);
// tune engine sound according to speed and acceleration
if(car.car_hEngine) {
var freq = 80
+ 200*abs(car.car_speed/car.car_maxSpeed)
+ 100*abs(car.car_torque/car.car_maxTorque);
snd_tune(car.car_hEngine,100,freq,0); //80% of real frequency
}
// play tire sound when tires are slipping
if(!snd_playing(car.car_hTire)) {
if(car_wheelslip(car))
car.car_hTire = ent_playloop(car,sndTire,100);
} else {
if(!car_wheelslip(car)) {
snd_stop(car.car_hTire);
car.car_hTire = 0;
}
}
// play crash sound on abrupt speed changes or when car topples
static var last_speed = 0;
static var last_roll = 0;
if((abs(last_speed) > tcar_crashSpeed &&
abs(last_speed-car.car_speed) > tcar_crashSpeed)
|| (abs(last_roll) < 90 && abs(car.roll) > 90))
{
ent_playsound(car,sndCrash,200);
}
last_speed = car.car_speed;
last_roll = car.roll;
}