Scripts/shieldtastic_crosshairs.js |
"use strict";
this.name = "Shieldtastic Crosshairs";
this.version = "1.0";
this.warningLevel_1 = 0.9;
this.warningLevel_2 = 0.6;
this.dangerLevel = 0.3;
/* ====================================================================================
START-UP
======================================================================================= */
this.startUp = function () {
"use strict";
if (worldScripts["Auto Crosshairs"]) {
this._monitorShields = this._monitorShields_v2;
}
delete this._monitorShields_v2;
delete this.startUp;
}
/* ====================================================================================
STARTING & STOPPING FRAME CALLBACK
FCB starts when player.alertCondition becomes > 1. Player is mass-locked.
======================================================================================= */
this.alertConditionChanged = function (newLevel, oldLevel) {
"use strict";
if (newLevel > 1 &&
!this.$runningFCB) {
if (player.ship.crosshairs === null) {
this.$ooliteQuirk = [
player.ship.hud,
player.ship.reticleTargetSensitive,
player.ship.scannerNonLinear,
player.ship.scannerUltraZoom
];
}
this.$runningFCB = addFrameCallback(this._monitorShields.bind(this));
}
}
this._ooliteQuirk = function () {
"use strict";
if (player.ship.hud == this.$ooliteQuirk[0]) {
player.ship.reticleTargetSensitive = this.$ooliteQuirk[1];
player.ship.scannerNonLinear = this.$ooliteQuirk[2];
player.ship.scannerUltraZoom = this.$ooliteQuirk[3];
} else {
// The HUD has changed, so preserving these settings is no longer our responsibility.
delete this.$ooliteQuirk;
}
}
this.shipWillDockWithStation = this.shipWillEnterWitchspace = this.shipDied = function () {
"use strict";
this._endFCB();
}
this._endFCB = function () {
"use strict";
if (this.$runningFCB) {
removeFrameCallback(this.$runningFCB);
delete this.$runningFCB;
// FixMe: what if player.ship.crosshairs == null was not so to begin with?
player.ship.crosshairs = null; // "crosshairs.plist";
if (this.$ooliteQuirk) {
this._ooliteQuirk();
delete this.$ooliteQuirk;
}
this.$lastForeStep = "-1";
this.$lastAftStep = "-1";
}
}
/* ====================================================================================
FRAME CALLBACK
======================================================================================= */
this._monitorShields = function (delta) {
"use strict";
var self = player.ship;
var fore = self.forwardShield / self.maxForwardShield;
var aft = self.aftShield / self.maxAftShield;
if (player.alertCondition < 2 && // Not mass-locked, and
fore == 1 && aft == 1) { // both shields fully charged...
this._endFCB();
return;
}
var foreStep = 3;
if (fore < this.dangerLevel) {
foreStep = 0;
} else if (fore < this.warningLevel_2) {
foreStep = 1;
} else if (fore < this.warningLevel_1) {
foreStep = 2;
}
var aftStep = 3;
if (aft < this.dangerLevel) {
aftStep = 0;
} else if (aft < this.warningLevel_2) {
aftStep = 1;
} else if (aft < this.warningLevel_1) {
aftStep = 2;
}
if (foreStep != this.$lastForeStep ||
aftStep != this.$lastAftStep) {
self.crosshairs = "shieldtastic_crosshairs_" + foreStep + aftStep + ".plist";
// worldScripts["Auto Crosshairs"].$offTargetCrosshairs = "shieldtastic_crosshairs_" + foreStep + aftStep + ".plist";
this.$lastForeStep = foreStep;
this.$lastAftStep = aftStep;
}
}
this._monitorShields_v2 = function (delta) {
"use strict";
var self = player.ship;
var fore = self.forwardShield / self.maxForwardShield;
var aft = self.aftShield / self.maxAftShield;
if (player.alertCondition < 2 && // Not mass-locked, and
fore == 1 && aft == 1) { // both shields fully charged...
this._endFCB();
return;
}
var foreStep = 3;
if (fore < this.dangerLevel) {
foreStep = 0;
} else if (fore < this.warningLevel_2) {
foreStep = 1;
} else if (fore < this.warningLevel_1) {
foreStep = 2;
}
var aftStep = 3;
if (aft < this.dangerLevel) {
aftStep = 0;
} else if (aft < this.warningLevel_2) {
aftStep = 1;
} else if (aft < this.warningLevel_1) {
aftStep = 2;
}
if (foreStep != this.$lastForeStep ||
aftStep != this.$lastAftStep) {
self.crosshairs = "shieldtastic_crosshairs_" + foreStep + aftStep + ".plist";
worldScripts["Auto Crosshairs"].$offTargetCrosshairs = "shieldtastic_crosshairs_" + foreStep + aftStep + ".plist";
this.$lastForeStep = foreStep;
this.$lastAftStep = aftStep;
}
}
/* ====================================================================================
COPYRIGHT NOTICE
(C) 2013,2014 Wildeblood. All rights reserved.
Free to use, but DO NOT PROMULGATE MODIFIED VERSIONS.
This was created by some fellow with the user name "Wildeblood" on the Oolite forums,
he'll tell you his real name if you bother to ask.
To use means to play with, modify or re-use in whole or in part, and to distribute freely.
To use DOES NOT imply to use for commercial gain, which would be a breach of copyright.
To promulgate means to make official announcements.
======================================================================================= */ |