| Scripts/laser_cooler.js | "use strict";
this.name	= "laser_cooler";
this.author	= "Norby";
this.copyright	= "2015 Norby";
this.description= "laser cooler";
this.licence	= "CC BY-NC-SA 4.0";
//Internal variables, should not touch
this.$FuelPart = 0;
this.$Heat = 0;
this.$Timer = null;
this.$View = null;
this.$WeaponKey = null;
this.$WeaponsOff = false;
this.$WeaponsOn = false;
//worldscript events
this.startUp = function() {
	if( !this.$Timer ) this.$Timer = new Timer(this, this.$Timed.bind(this), 0.25, 0.25);
}
this.shipWillDockWithStation = function() {
	this.$DetachCooler();
}
//Internal functions
this.$DetachCooler = function() {
	var lmss = worldScripts.LMSS_Core; // ** added
	if (lmss) lmss._switching = true;
	if( this.$WeaponKey ) player.ship.currentWeapon = this.$WeaponKey;
	var x = worldScripts.XenonHUD;
	if (x) x.weaponsSystemsToggled(true);
	if (lmss) lmss._switching = false;
	this.$Fuelpart = 0;
	this.$Heat = 0;
	this.$View = null;
	this.$WeaponKey = null;
	this.$WeaponsOff = false;
	this.$WeaponsOn = false;
}
this.$Timed = function() {
	var c = "EQ_WEAPON_LASER_COOLER";
	var p = player.ship;
	if( !p.isValid ) return;
	var k = p.currentWeapon.equipmentKey;
	if( !p.weaponsOnline ) {
		if( p.equipmentStatus("EQ_LASER_COOLER") == "EQUIPMENT_OK" && !this.$WeaponKey
			&& p.laserHeatLevel > 0.6 && k != c ) {
				if( p.fuel <= 1.0 ) {
					player.consoleMessage("Not enough fuel for Laser Cooler");
				} else {
					this.$Fuelpart = 0;
					this.$Heat = p.laserHeatLevel;
					this.$View = p.viewDirection;
					this.$WeaponKey = k;
					this.$WeaponsOff = false;
					this.$WeaponsOn = false;
					log(this.name, "setting " + this.$WeaponKey);
					p.currentWeapon = c;
					player.consoleMessage("Laser Cooler attached, press fire for cooling",5);
				}
		} else if( this.$WeaponKey && this.$WeaponsOn ) this.$WeaponsOff = true;
	} else {
		this.$WeaponsOn = true;
		if( this.$WeaponKey && k == c
			&& ( p.laserHeatLevel < 0.1 || this.$WeaponsOff || p.fuel <= 1.0 )
			&& this.$View == p.viewDirection ) {
				this.$DetachCooler();
				var f = "";
				if( p.fuel <= 1.0 ) f = " due to low fuel"
				player.consoleMessage("Laser Cooler detached"+f, 5);
		}
	}
	if( this.$View == p.viewDirection && k == c ) {
		if( this.$Heat > 0 && this.$Heat > p.laserHeatLevel + 0.01 ) { //detect fast cooling
			p.temperature += 0.035; //increase cabin temp
			this.$FuelPart++;
			if( this.$FuelPart >= 2 ) { //1 mean 0.4 ly/s, 2 mean 0.2 ly/s, 4 mean 0.1 ly/s
				this.$FuelPart = 0;
				p.fuel -= 0.1; //must be at least 0.1 and divisible by 0.1
			}
		}
		this.$Heat = p.laserHeatLevel;//save for the next timer call
	} else this.$Heat = 0;
} | 
                
                    | Scripts/lasercooler-conditions.js | "use strict";
this.name	= "lasercooler-conditions";
this.author	= "Norby";
this.copyright   = "2013 Norbert Nagy";
this.licence     = "CC BY-NC-SA 4.0";
this.description = "This equipment is usable only for ships over 130t like the Cobra Mark III.";
this.allowAwardEquipment = function(equipment, ship, context)
{
	// OXP hook to allow stations to forbid specific equipment
	if (context == "purchase" && player.ship.dockedStation && player.ship.dockedStation.scriptInfo["oolite-barred-equipment"])
	{
		if (player.ship.dockedStation.scriptInfo["oolite-barred-equipment"].indexOf(equipment) != -1)
		{
			return false;
		}
	}
	// OXP hook to allow ships to forbid specific "available to all" equipment
	if (ship.scriptInfo && ship.scriptInfo["oolite-barred-equipment"] && ship.scriptInfo["oolite-barred-equipment"].indexOf(equipment) != -1)
	{
		return false;
	}
//	player.consoleMessage( eqKey+" "+ship+" "+context );//debug
	//for large ships only like Cobra Mark III
	if( ship.mass < 130000 ) {
		return false;
	}
	
//	if( equipment == "EQ_WEAPON_LASER_COOLER" && context != "scripted" ) return false;
//	if( equipment == "EQ_WEAPON_LASER_COOLER" ) {
//		log(this.name,  context +" "+equipment+" "+ship);
//		if( context != "scripted" ) return false;
//	}
	return true;
} |