Scripts/laserific_crosshairs.js |
"use strict";
this.name = "Laserific Crosshairs"; // "Wildeblood", 2014.
this.version = "1.3";
this.$maxSteps = 16;
this.$cutOffHeat = 0.85;
/* ====================================================================================
AVOID STUTTERING THE FIRST TIME THE ANIMATION RUNS?
======================================================================================= */
this.$autoCrosshairs = {
default: {
off: "wildeblood_combat_crosshairs_0.plist",
on: "wildeblood_combat_crosshairs_on.plist"
}
}
this.startUp = function () {
"use strict";
for (var i = 0; i <= this.$maxSteps; i++) {
player.ship.crosshairs = "wildeblood_combat_crosshairs_" + i + ".plist";
}
player.ship.crosshairs = null;
if (worldScripts["Auto Crosshairs"]) {
this._showDisplay = this._showDisplay_v2;
}
delete this._showDisplay_v2;
}
/* ====================================================================================
STARTING & STOPPING FRAME CALLBACK
FCB starts when player.alertCondition becomes 3 or a target is acquired.
FCB ends when !player.ship.target && player.ship.laserHeatLevel === 0 && player.alertCondition < 3
Display is shown while player.ship.target or player.ship.laserHeatLevel > 0 or player.alertHostiles
======================================================================================= */
this.alertConditionChanged = function (newState, oldState) {
"use strict";
if (newState ==3 && !this.$runningFCB) {
this.$runningFCB = addFrameCallback(this._monitorLaser.bind(this));
}
}
this.shipTargetAcquired = function (target) {
"use strict";
if (!this.$runningFCB) {
this.$runningFCB = addFrameCallback(this._monitorLaser.bind(this));
}
}
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;
this._hideDisplay();
}
}
this._monitorLaser = function (delta) {
"use strict";
if (player.alertHostiles ||
player.ship.target ||
player.ship.laserHeatLevel) {
this._showDisplay();
} else if (player.alertCondition < 3) {
this._endFCB();
} else {
this._hideDisplay();
}
}
this._showDisplay = function () {
"use strict";
var level = (player.ship.laserHeatLevel / this.$cutOffHeat * this.$maxSteps);
var step = level.toFixed();
if (step != this.$lastStep) {
if (step > this.$maxSteps) {
step = this.$maxSteps; // Thank you, javascript automatic variable typing.
}
player.ship.crosshairs = "wildeblood_combat_crosshairs_" + step + ".plist";
this.$lastStep = step;
}
}
this._showDisplay_v2 = function () {
"use strict";
var level = (player.ship.laserHeatLevel / this.$cutOffHeat * this.$maxSteps);
var step = level.toFixed();
if (step != this.$lastStep) {
if (step > this.$maxSteps) {
step = this.$maxSteps;
}
player.ship.crosshairs = "wildeblood_combat_crosshairs_" + step + ".plist";
worldScripts["Auto Crosshairs"].$offTargetCrosshairs = "wildeblood_combat_crosshairs_" + step + ".plist";
this.$lastStep = step;
}
}
this._hideDisplay = function () {
"use strict";
// FixMe: player.ship.crosshairs = null causes a HUD reset;
// similar fix to that used in Auto Crosshairs OXP required.
if (this.$lastStep != "-1") {
player.ship.crosshairs = null; // "crosshairs.plist";
this.$lastStep = "-1";
}
}
/* ====================================================================================
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.
======================================================================================= */ |