Scripts/headlights.js |
"use strict";
this.name = "headlights";
this.author = "Norby";
this.copyright = "2014 Norby";
this.description= "Tune the light level on the dark side of objects";
this.licence = "CC BY-NC-SA 4.0";
//internal properties, should not touch
this.$Level = 1; //darker than the default but not "too" dark as 0.1 in Realistic Stars
this.$Level2 = 4; //highlight objects over star-filled background
this.$Mode = 1; //current mode
//equipment events
this.activated = function() { //increase ambient level
var w = worldScripts["headlights"];
switch(w.$Mode) {
case 1: //switch between default and high level
if( system.ambientLevel == w.$Level2 )
system.ambientLevel = w.$Level;
else system.ambientLevel = w.$Level2;
player.consoleMessage("Headlights set to "
+Math.round(system.ambientLevel*100)/100, 3);
break;
case 2: //decrease ambientLevel
w.$eq(false, w);
break;
case 3: //increase ambientLevel
w.$eq(true, w);
break;
case 4: //save as high level
w.$Level2 = w.$hi();
player.consoleMessage("Headlights high level set to "+w.$Level2
+", default level set back to 1", 3);
system.ambientLevel = w.$Level = 1; //reset default to 1
w.$Mode = 1; //back to the switching mode
break;
default: //for sure
w.$Mode = 1;
break;
}
}
this.mode = function() { //decrease ambient level
var w = worldScripts["headlights"];
w.$Mode++;
if( w.$Mode > 4 ) w.$Mode = 1;
switch(w.$Mode) {
case 1: //switch between default and high level
player.consoleMessage("Headlights mode: switch between default and high level", 3);
break;
case 2: //decrease ambientLevel
player.consoleMessage("Headlights mode: decrease level", 3);
break;
case 3: //increase ambientLevel
player.consoleMessage("Headlights mode: increase level", 3);
break;
case 4: //save as high level
player.consoleMessage("Headlights mode: save "+w.$hi()+" as high level", 3);
break;
default: //for sure
w.$Mode = 1;
break;
}
}
//worldscript events
this.startUp = function() {
var l = missionVariables.$HeadlightsLevel;
if( l ) {
this.$Level = l;
if( system.ambientLevel ) system.ambientLevel = l;
}
l = missionVariables.$HeadlightsLevel2;
if( l ) this.$Level2 = l;
}
this.playerBoughtEquipment = function(equipmentKey) {
if( equipmentKey == "EQ_Headlights_REMOVE" ) {
var eq = equipmentKey.substr( 0, equipmentKey.length-7 );//the real eq
player.ship.removeEquipment( eq ); //remove it
player.ship.removeEquipment( equipmentKey ); //remove the "bought" remove eq
}
}
this.playerWillSaveGame = function(message) {
missionVariables.$HeadlightsLevel = this.$Level;
missionVariables.$HeadlightsLevel2 = this.$Level2;
}
this.shipWillExitWitchspace = function() {
system.ambientLevel = this.$Level; //force in every system
}
//headlights functions
this.$eq = function(up, w) { //decrease ambient level
if( !system.ambientLevel ) {
player.consoleMessage("You need Oolite 1.81 to use this equipment"
+" but you can change ambient_level by hand in Config/planetinfo.plist", 10);
return;
}
var step = 0.05;
if( w.$Level > 1.5 || up && w.$Level == 1.5 ) step = 0.5;
if( w.$Level < 0.05 ) w.$Level = 0;
if( up ) {
w.$Level += step;
if( w.$Level > 10 ) w.$Level = 0.01;
} else {
w.$Level -= step;
if( w.$Level < 0 ) w.$Level = 10;
}
if(w.$Level == 0) w.$Level = 0.01;
w.$Level = Math.round(w.$Level*100)/100;
system.ambientLevel = w.$Level;
player.consoleMessage("Headlights set to "+w.$Level, 3);
}
this.$hi = function() { //high ambient level
var hi = Math.round(system.ambientLevel*100)/100;
if( hi < 2 ) hi = 2; //min. 2
return hi;
} |