| Config/script.js | this.name           = "glare_filter";
this.author         = "spara";
this.copyright      = "2014 Mika Spåra";
this.description    = "Filter to diminish sun glare";
this.version        = "1.0";
this.licence    	= "CC BY-NC-SA 3.0";
//filter burns 2 * filter level in one second.
//0.6 -> 120 seconds (2 mins)
//0.4 -> 180 seconds (3 mins)
//0.2 -> 300 seconds (5 mins)
//duration in seconds at 0.5 level
this.$fullFilterDuration = 144;
this.startUpComplete = function() {
	//set up timer
	if (player.ship.equipmentStatus("EQ_GLARE_FILTER") === "EQUIPMENT_OK") {
		this.$initFilter();
		if (missionVariables.glareFilter)
			this.$filterDuration = missionVariables.glareFilter;
	}
	//three levels of filtering
	this.$filterLevels = [0.2, 0.4, 0.6];
	//current filter level
	this.$filterPointer = 1;
	//state of the equipment
	this.$filterOn = false;
}
this.playerBoughtEquipment = function(equipment) {
	if (equipment === "EQ_GLARE_FILTER") {
		this.$initFilter();
	}
	if (equipment === "EQ_GLARE_FILTER_REPLACE") {
		player.ship.awardEquipment("EQ_GLARE_FILTER");
		player.ship.removeEquipment("EQ_GLARE_FILTER_REPLACE");
		this.$initFilter();
	}
}
this.playerBoughtNewShip = function() {
	player.ship.removeEquipment("EQ_GLARE_FILTER");
}
this.playerWillSaveGame = function() {
	if (player.ship.equipmentStatus("EQ_GLARE_FILTER") === "EQUIPMENT_OK")
		missionVariables.glareFilter = this.$filterDuration;
}
//turn the filter off when docking or witchspacing
this.shipWillDockWithStation = this.shipWillEnterWitchSpace = function() {
	if (this.$filterOn) this.$toggleOnOff();
}
this.$toggleOnOff = function() {
	if (this.$filterOn) {
		this.$filterTimer.stop();
		this.$filterOn = false;
		player.ship.sunGlareFilter = 0;
		player.consoleMessage("Glare Filter: Off.");
	}
	else {
		player.consoleMessage("Glare Filter: On.");
		this.$filterOn = true;
		player.ship.sunGlareFilter = this.$filterLevels[this.$filterPointer];
		this.$filterTimer.start();
	}
}
this.$adjustFilter = function() {
	//change filter level first locally
	var filterPointer = this.$filterPointer + 1;
	//over the top
	if (filterPointer > 2) filterPointer = 0;
	
	//for console
	var filterLevels = ["Low", "Medium", "High"];
	
	//set the filter
	if (this.$filterOn)
		player.ship.sunGlareFilter = this.$filterLevels[filterPointer];
	//print out the message
	player.consoleMessage("Glare Filter: " + filterLevels[filterPointer]+".");
	//update the global filter level pointer
	this.$filterPointer = filterPointer;	
}
//start the timer and reset the duration counter
this.$initFilter = function() {
	if (!this.$filterTimer)
		this.$filterTimer = new Timer(this, this.$burnFilter, 1, 1);
	this.$filterTimer.stop();
	this.$filterDuration = this.$fullFilterDuration;
}
//the actual burning function
this.$burnFilter = function() {
	//there's filter left and filter is active.
	if (this.$filterDuration > 0 && this.$filterOn) {
		//burn filter.
		this.$filterDuration = this.$filterDuration - player.ship.sunGlareFilter * 2;
		var percentageLeft = Math.round((this.$filterDuration / this.$fullFilterDuration) * 100);
		//print messages at 10, 20, ..., 90 %
		if (percentageLeft % 10 === 0 && percentageLeft !== 100 && percentageLeft !== 0)
			player.consoleMessage("Glare Filter: " + percentageLeft + " % left.");
		return;
	}
	//filter burned out
	if (this.$filterDuration <= 0){
		player.ship.removeEquipment("EQ_GLARE_FILTER");
		player.consoleMessage("Glare Filter: Burned out.");
		player.ship.sunGlareFilter = 0;
		this.$filterOn = false;
		this.$filterTimer.stop();
	}
}
 | 
                
                    | Scripts/glare_filter.js | this.name           = "glare_filter_equipment";
this.author         = "spara";
this.copyright      = "2014 Mika Spåra";
this.description    = "Filter equipment";
this.version        = "1.0";
this.licence    	= "CC BY-NC-SA 3.0";
//equipment activation n
this.activated = function() {
	worldScripts.glare_filter.$toggleOnOff();
};
//equipment activation b
this.mode = function() {
	worldScripts.glare_filter.$adjustFilter();
};
//equipment can only be added by script
this.allowAwardEquipment = function(eqKey, ship, context) {
	if (worldScripts.glare_filter.$filterDuration === worldScripts.glare_filter.$fullFilterDuration) return false;
	return true;
};
 |