Back to Index Page generated: Dec 20, 2024, 7:22:09 AM

Expansion Engine Sound

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description The tone of engine sound follow the speed of your ship. The tone of engine sound follow the speed of your ship.
Identifier oolite.oxp.Norby.Engine_Sound oolite.oxp.Norby.Engine_Sound
Title Engine Sound Engine Sound
Category Ambience Ambience
Author Norby Norby
Version 1.2 1.2
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL http://wiki.alioth.net/index.php/Engine_Sound n/a
Download URL https://wiki.alioth.net/img_auth.php/3/3c/Engine_Sound_1.2.oxz n/a
License CC BY-NC-SA 4 CC BY-NC-SA 4
File Size n/a
Upload date 1610873279

Documentation

Also read http://wiki.alioth.net/index.php/Engine%20Sound

Equipment

This expansion declares no equipment.

Ships

This expansion declares no ships.

Models

This expansion declares no models.

Scripts

Path
Scripts/engine_sound.js
"use strict";
this.name	= "engine_sound";
this.author	= "Norby";
this.copyright	= "2015 Norby";
this.description= "The tone of engine sound follow the speed of your ship.";
this.licence	= "CC BY-NC-SA 4.0";

//internal properties, should not touch
this.$Last = 1; //last played sound
this.$Pause = false; //no sound in pause
this.$S = []; //sound objects storing sound files
this.$SS = null; //soundsource

//worldscript events
this.startUp = function() {
	for(var i=1; i<26; i++) {
		this.$S[i] = Sound.load("bgs-m_ambi_engine1-"+i+".ogg");
	}
	
	this.$SS = new SoundSource;
	this.$SS.sound = this.$S[1];
	this.$SS.loop = true;

	this.$T =  new Timer(this, this.$Play, 0, 0.25);
	this.$T2 =  new Timer(this, this.$Play, 0.125, 0.25);
}


this.startUpComplete = function() {
	var b = worldScripts["BGS-M"];
//	if( b ) b.ambientSounds = false; //turn off BGS engine sound but chatter too
}

this.gamePaused = this.shipDockedWithStation = this.shipDied = this.shipWillEnterWitchspace = function() {
	this.$SS.volume = 0;
	this.$Pause = true;
}

this.gameResumed = this.shipWillLaunchFromStation  = this.shipExitedWitchspace = function() {
	this.$Pause = false; 
}

//engine sound methods
this.$Play = function() {
	var p = player.ship;
	if( !p || !p.isValid || p.docked || p.speed < 1 || p.torusEngaged
		|| p.speed > 8 * p.maxSpeed + 1
		|| !this.$SS || this.$Pause ) {
		this.$SS.volume = 0;
		return;
	}

	var s = p.speed;
	if( !p.injectorsEngaged && s > p.maxSpeed ) s = p.maxSpeed;
	var l = Math.ceil( s/20 );
	if( !this.$S[ l ] ) l = 25; //speed over 500
	this.$SS.volume = 0.2 + l / 250; //from 0.2 to 0.3

	if( this.$Last != l ) {
		this.$Last = l;
		this.$SS.sound = this.$S[ l ];
		this.$SS.play();
	}
}