| Scripts/gatling_laser-conditions.js | "use strict";
this.name	= "gatling_laser-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_GATLING_LASER_2" && ship.mass < 400000 ) return false;
	if( equipment == "EQ_WEAPON_GATLING_LASER_3" && ship.mass < 800000 ) return false;
	if( equipment == "EQ_WEAPON_GATLING_LASER_4" && ship.mass < 8000000 ) return false;
	if( equipment == "EQ_WEAPON_GATLING_LASER_5" && ship.mass < 200000000 ) return false;
	
//	if( equipment == "EQ_WEAPON_GATLING_LASER_COOLER" && context != "scripted" ) return false;
//	if( equipment == "EQ_WEAPON_GATLING_LASER_COOLER" ) {
//		log(this.name,  context +" "+equipment+" "+ship);
//		if( context != "scripted" ) return false;
//	}
	return true;
} | 
                
                    | Scripts/gatling_laser.js | "use strict";
this.name	= "gatling_laser";
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.$Heat = 0;
this.$LastView = null;
this.$Timer = null;
this.$WeaponKey = [];
//worldscript events
this.startUp = function() {
	if( !this.$Timer ) this.$Timer = new Timer(this, this.$Timed.bind(this), 0.25, 0.25);
}
this.startUpComplete = function() {
	var w = worldScripts.LMSS_Core;
	if( w && w._incompatible ) //for Laser Mount Switching System (LMSS)
		w._incompatible.push("EQ_WEAPON_GATLING_LASER_COOLER");
}
this.shipWillDockWithStation = function() {
	this.$DetachCooler();
}
//Internal functions
this.$DetachCooler = function() {
	var w = this.$WeaponKey["VIEW_AFT"]; if( w ) player.ship.aftWeapon = w;
	w = this.$WeaponKey["VIEW_FORWARD"]; if( w ) player.ship.forwardWeapon = w;
	w = this.$WeaponKey["VIEW_PORT"]; if( w ) player.ship.portWeapon = w;
	w = this.$WeaponKey["VIEW_STARBOARD"]; if( w ) player.ship.starboardWeapon = w;
	this.$Heat = 0;
	this.$WeaponKey = [];
}
this.$Timed = function() {
	var p = player.ship; if( !p.isValid ) return;
	var c = "EQ_WEAPON_GATLING_LASER_COOLER";
	var k = p.currentWeapon.equipmentKey;
	var v = p.viewDirection;
	if( p.laserHeatLevel > 0.75 && k != c && !this.$WeaponKey[v]
		&& k.indexOf("EQ_WEAPON_GATLING_LASER_") == 0
		&& ( v == "VIEW_FORWARD" || v == "VIEW_AFT" //do not attach in external view
			|| v == "VIEW_PORT" || v == "VIEW_STARBOARD" ) ) {
		this.$Heat = p.laserHeatLevel;
		this.$WeaponKey[v] = k;
		p.currentWeapon = c;
//		player.consoleMessage("Gatling Cooler attached");
	} else if( this.$WeaponKey[v] && k == c
		&& ( p.laserHeatLevel < 0.1 || !p.weaponsOnline ) ) {
		p.currentWeapon = this.$WeaponKey[v];
		this.$Heat = 0;
		this.$WeaponKey[v] = null;
//		player.consoleMessage("Gatling Cooler detached");
	}
	if( this.$LastView == v && k == c ) { //detect fast cooling
		if( this.$Heat > 0 && this.$Heat > p.laserHeatLevel + 0.01 ) {
			p.temperature += 0.03; //increase cabin temp
		}
		this.$Heat = p.laserHeatLevel;//save for the next timer call
	} else this.$Heat = 0;
	this.$LastView = v;
} |