"use strict"; this.name = "Destination ETA"; this.version = "1.0.8"; // "Wildeblood", May 18th, 2013 //modified by laxori666 to merge Talkative Space Compass functionality (by cim) /* ==================================================================================== STAR NAMES If system.info.sun_name or system.sun.name is set, that will be displayed as the star's name. Otherwise the contents of this.$starSuffix will be affixed to the planet's name. ======================================================================================= */ // this.$starSuffix = " Stella"; this.$starSuffix = " Astrum"; /* ==================================================================================== INITIALIZATION To suppress announcing targets when cycling the ASC, set .$announceTargets = false To stop updates use .alertConditionChanged(0,1) which will stop the timer. To interrupt temporarily set .$showETA = false which will leave the timer running. ======================================================================================= */ this.$announceTargets = true; // don't print target when launching from station or after hyperspace this.$suppressAnnounce = 1; this.shipWillEnterWitchspace = function () { this.$suppressAnnounce = 1; } this.shipWillLaunchFromStation = function () { this.$suppressAnnounce = 1; } this.startUp = function() { this.$checkForIncompatibleScripts(); delete this.$checkForIncompatibleScripts; this.$destination = null; this.$showETA = true; this.$speechOn = oolite.gameSettings.speechOn; delete this.startUp; } this.$checkForIncompatibleScripts = function() { if(worldScripts["Wildefire Avionics"] || worldScripts["Talkative Space Compass"] || worldScripts["MilHUD-4000"] || worldScripts["Wide-Screen HUD"]) this.$announceTargets = false; } /* ==================================================================================== CREATING & STORING THE DESTINATION STRING ======================================================================================= */ this.$procAnnounce = function () { if (this.$suppressAnnounce) { this.$suppressAnnounce = 0; return; } player.consoleMessage("Compass: " + this.$destination); } this.compassTargetChanged = function(whom, mode) { if (mode === "COMPASS_MODE_BASIC") { if (whom && whom.isMainStation) { mode = "COMPASS_MODE_STATION"; } else { mode = "COMPASS_MODE_PLANET"; } } var procEta = true; switch(mode) { case "COMPASS_MODE_TARGET": //announce the compass but don't set it as the ETA target procEta = false; this.$destination = this.$target(); break; case "COMPASS_MODE_PLANET": this.$destination = this.$planet(); break; case "COMPASS_MODE_BEACONS": this.$destination = this.$beacon(whom); break; case "COMPASS_MODE_SUN": this.$destination = this.$star(); break; case "COMPASS_MODE_STATION": this.$destination = this.$station(); break; default: this.$destination = null; return; } if (this.$announceTargets) { this.$procAnnounce(); } if (!procEta) { this.$destination = null; return; } if (this.$destination) { this.$compassTarget = whom; } }; this.$target = function () { //from TSC 1.0.4 if (player.ship.target) { return "Current Target (" + player.ship.target.displayName + ")"; } else { return "Current Target"; } } this.$beacon = function(whom) { //adapted from TSC 1.0.4 var showname = whom.displayName; if (!showname) { showname = whom.name; } var usingBeaconCode = false; if (!showname) { showname = whom.beaconCode; usingBeaconCode = true; } if (showname == "Metal fragment" && whom.beaconCode.substr(0,1) == "E") { // Old versions of escape capsule locator OXP showname = "Escape Pod"; } else if (showname == "Navigation Buoy") { // More than one thing called Navigation Buoy, distinguish with beacon code if (whom.beaconCode.substr(0,1) == "g") { showname = "GRS Buoy Factory Nav Buoy"; usingBeaconCode = false; } else if (whom.beaconCode.substr(0,1) == "N") { showname = "Main Station Nav Buoy"; // probably usingBeaconCode = false; } else { showname = "Navigation Buoy"; } } if (usingBeaconCode) { showname = "Beacon: " + whom.beaconCode; } return showname; } this.$planet = function () { //adapted from TSC 1.0.4 if (system.mainPlanet.name) { // unofficial extension return system.mainPlanet.name + " (Planet)"; } else { return system.name; } } this.$station = function() { var altitude; var range = system.mainStation.position.distanceTo(system.mainPlanet) - system.mainPlanet.radius - system.mainStation.collisionRadius; if (range < 40000) altitude = "(low orbit)"; else altitude = "(altitude: " + (range/10).toFixed(0) + "km)"; return system.name + " space dock " + altitude; } this.$star = function() { if (system.info.sun_color) { var colour switch (system.info.sun_color) { case "magentaColor": case "redColor": colour = " (class M star)"; break; case "orangeColor": colour = " (class K star)"; break; case "yellowColor": colour = " (class G star)"; break; case "whiteColor": colour = " (class F star)"; break; case "cyanColor": colour = " (class A star)"; break; case "blueColor": colour = " (class B star)"; break; default: colour = null; } } var name; if (system.info.sun_name) { name = system.info.sun_name; } else if (system.sun.name) { //from TSC 1.0.4 name = system.sun.name; } else { name = system.name + this.$starSuffix; } if (colour) { return name + colour; } else { return name; } } /* ==================================================================================== CALCULATING & DISPLAYING THE E.T.A. In interstellar space compassTarget is undefined, will cause CTD in Oolite 1.76.1. ======================================================================================= */ this.$updateETA = function() { if (system.isInterstellarSpace || player.alertCondition != 1) return false; var self = player.ship; if (this.$showETA && this.$destination && self.status == "STATUS_IN_FLIGHT" && this.$compassTarget && this.$compassTarget.isValid) { var target = this.$compassTarget; var range = self.position.distanceTo(target.position) - target.collisionRadius; var vPtoT = target.position.subtract(self.position); // Vector player to target if (self.velocity.dot(vPtoT) > 0.1) // Then check heading... { var vVelPtoT = vPtoT.multiply(self.velocity.dot(vPtoT) / (vPtoT.dot(vPtoT))); // Velocity vector projection on player-target vector var timeToTarget = range / vVelPtoT.magnitude(); var hours = Math.floor(timeToTarget / 3600); var mins = Math.floor((timeToTarget - 3600 * hours) / 60); var secs = Math.floor(timeToTarget - hours * 3600 - mins * 60); if (hours < 10) hours = "0" + hours; if (mins < 10) mins = "0" + mins; if (secs < 10) secs = "0" + secs; player.consoleMessage("\n\n\n\n\n\n\n\n\n\n" + this.$destination); if (this.$speechOn) player.consoleMessage("E. T. A. " + hours + ":" + mins + ":" + secs); else player.consoleMessage("ETA " + hours + ":" + mins + ":" + secs); } } if (oolite.gameSettings.speechOn !== this.$speechOn) this.$restartTimer(); } /* ==================================================================================== STARTING AND STOPPING $updateTimer ======================================================================================= */ this.alertConditionChanged = function(newCondition, oldCondition) { if (this.$updateTimer) { this.$updateTimer.stop(); delete this.$updateTimer; } if (newCondition == 1 && !system.isInterstellarSpace) this.$restartTimer(); } this.$restartTimer = function() { if (!this.$updateTimer) this.$updateTimer = new Timer(this, $updateETA, 0, 10); else if (!this.$updateTimer.isRunning) this.$updateTimer.start(); if (oolite.gameSettings.speechOn) this.$updateTimer.interval = 10; else this.$updateTimer.interval = 0.5; this.$speechOn = oolite.gameSettings.speechOn; } /* ==================================================================================== OVER-RIDING $updateETA() TO SHOW EVENT MESSAGES ======================================================================================= */ this.shipTargetAcquired = this.shipTargetLost = this.shipScoopedOther = this.shipKilledOther = this.viewDirectionChanged = function() { this.$timeOutForEvent(4); } this.commsMessageReceived = function() { this.$timeOutForEvent(10); } this.$timeOutForEvent = function(timeOut) { this.$showETA = false; if (this.$eventTimer) { this.$eventTimer.stop(); this.$eventTimer.nextTime = clock.absoluteSeconds + timeOut; this.$eventTimer.start(); } else this.$eventTimer = new Timer(this, this.$eventTimeOver, timeOut); } this.$eventTimeOver = function() { this.$showETA = true; delete this.$eventTimer; } /* ==================================================================================== COPYRIGHT NOTICE (C)2012-13, 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. ======================================================================================= */