Scripts/waypoint_here_eq.js |
"use strict";
this.author = "Neelix";
this.copyright = "© 2014 Neelix.";
this.licence = "CC-BY-NC-SA 4.0";
this.name = "tlxn_waypointHere_eq";
this.description = "Waypoint Here Equipment Script";
// setup internal waypoint identifiers
this.$wph_waypoints = [
{key: "wph_alpha", wname: "Waypoint Alpha", code: "A", wpset: false},
{key: "wph_bravo", wname: "Waypoint Bravo", code: "B", wpset: false},
{key: "wph_charlie", wname: "Waypoint Charlie", code: "C", wpset: false},
{key: "wph_delta", wname: "Waypoint Delta", code: "D", wpset: false},
{key: "wph_echo", wname: "Waypoint Echo", code: "E", wpset: false},
{key: "wph_foxtrot", wname: "Waypoint Foxtrot", code: "F", wpset: false},
{key: "wph_golf", wname: "Waypoint Golf", code: "G", wpset: false},
{key: "wph_hotel", wname: "Waypoint Hotel", code: "H", wpset: false},
];
// Add waypoint at current location
this.activated = function() {
var wph = worldScripts["tlxn_waypointHere_eq"];
// look for an unused waypoint identifier
for (var i = 0; i < wph.$wph_waypoints.length; i++) {
if (!wph.$wph_waypoints[i].wpset) {
//unused identifier found - use it and exit function
system.setWaypoint(
wph.$wph_waypoints[i].key, player.ship.position, player.ship.orientation,
{size: 100, beaconCode: wph.$wph_waypoints[i].code, beaconLabel: wph.$wph_waypoints[i].wname}
);
wph.$wph_waypoints[i].wpset = true;
player.consoleMessage(wph.$wph_waypoints[i].wname + " set.", 5);
worldScripts.Waypoint_Here_MFD.$updateWaypointMFD();
return;
}
}
//if we get this far then all waypoint identifiers are in use.
player.consoleMessage("Waypoint Here Memory Full. Please clear a waypoint before attempting to set another",5);
}
// Clear waypoint currently selected on ASC
this.mode = function() {
var $ct = player.ship.compassTarget;
var $sw = system.waypoints;
var wph = worldScripts["tlxn_waypointHere_eq"];
// check position of each waypoint against the postion of the compass target
for (var i = 0; i < wph.$wph_waypoints.length; i ++) {
if ($ct && $sw && $sw[wph.$wph_waypoints[i].key] && $ct.position.distanceTo($sw[wph.$wph_waypoints[i].key].position) == 0) {
//match found - clear the waypoint and exit function
system.setWaypoint(wph.$wph_waypoints[i].key);
wph.$wph_waypoints[i].wpset = false;
player.consoleMessage(wph.$wph_waypoints[i].wname + " cleared",5);
worldScripts.Waypoint_Here_MFD.$updateWaypointMFD();
return;
}
}
//if we get this far the compass target did not match one of our waypoints
player.consoleMessage("No waypoint selected");
}
// reset waypoints on entering a new system
this.shipWillExitWitchspace = function() {
var wph = worldScripts["tlxn_waypointHere_eq"];
for (var i = 0; i < wph.$wph_waypoints.length; i ++) {
if (wph.$wph_waypoints[i].wpset === true) {
wph.$wph_waypoints[i].wpset = false;
}
}
}
this.shipExitedWitchspace = function() {
if (system.isInterstellarSpace === true && player.ship.equipmentStatus("EQ_WPH_ASC_UPGRADE") === "EQUIPMENT_OK") {
// auto-deploy a waypoint at 0, 0, 0
var wph = worldScripts["tlxn_waypointHere_eq"];
// always use the "Alpha" waypoint - it should always be free whenever we first arrive in a system
system.setWaypoint(
wph.$wph_waypoints[0].key, [0, 0, 0], player.ship.orientation,
{size: 100, beaconCode: wph.$wph_waypoints[0].code, beaconLabel: wph.$wph_waypoints[0].wname}
);
wph.$wph_waypoints[0].wpset = true;
worldScripts.Waypoint_Here_MFD.$updateWaypointMFD();
player.consoleMessage("Auto-deploying waypoint for witchspace exit point", 5);
}
} |
Scripts/waypoint_here_mfd.js |
"use strict";
this.author = "phkb";
this.copyright = "© 2017 phkb";
this.licence = "CC-BY-NC-SA 4.0";
this.name = "Waypoint_Here_MFD";
this.description = "Waypoint Here MFD Script";
//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function() {
// add interface to HUD selector
var h = worldScripts.hudselector;
if (h) h.$HUDSelectorAddMFD(this.name, this.name);
h = null;
}
//-------------------------------------------------------------------------------------------------------------
this.shipWillLaunchFromStation = function(station) {
// only start the waypoint timer if we have the equipment installed
if (player.ship.equipmentStatus("EQ_WPH_ASC_UPGRADE") === "EQUIPMENT_OK")
this._updateWaypointMFD = new Timer(this, this.$updateWaypointMFD, 5, 0.5);
}
//-------------------------------------------------------------------------------------------------------------
this.shipDied = function(whom, why) {
this.$stopTimer();
}
//-------------------------------------------------------------------------------------------------------------
this.shipWillDockWithStation = function(station) {
this.$stopTimer();
}
//-------------------------------------------------------------------------------------------------------------
this.$stopTimer = function() {
if (this._updateWaypointMFD && this._updateWaypointMFD.isRunning) this._updateWaypointMFD.stop();
}
//-------------------------------------------------------------------------------------------------------------
// updates the text of the damage report MFD
this.$updateWaypointMFD = function $updateWaypointMFD() {
var p = player.ship;
var output = "SYSTEM WAYPOINTS:\n";
var keys = [];
if (system.waypoints) keys = Object.keys(system.waypoints);
if (keys.length === 0) {
output += "\n No waypoints set";
} else {
for (var i = 0; i < keys.length; i++) {
if (i > 8) break;
var wp = system.waypoints[keys[i]];
output += this.$padTextRight(
(p.compassTarget && p.compassTarget == wp ? "•" : "") +
(wp.beaconLabel !== "" ? wp.beaconLabel : "(Unlabelled)"),
(system.isInterstellarSpace === true ? 7.5 : 8.5)
) + (wp.position.distanceTo(p) / 1000).toFixed(1) + "kms";
// give the player some waypoint direction information in interstellar space
// because the space compass doesn't work
if (system.isInterstellarSpace === true && p && p.vectorForward) {
var f_dev = p.vectorForward.angleTo(wp.position.subtract(p));
var r_dev = p.vectorRight.angleTo(wp.position.subtract(p));
var u_dev = p.vectorUp.angleTo(wp.position.subtract(p));
var s = "";
// > 1.56 means oppposite side (3.12 exact opposite)
// so, f_dev < 0.01, r_dev = 1.57, u_dev = 1.57 -- aligned
if (f_dev < 0.25) {
if (f_dev < 0.25) s = "O";
if (f_dev < 0.12) s = "o";
if (f_dev < 0.05) s = "X";
}
if (f_dev >= 0.25) {
if (r_dev > 1.69) {
s += "<";
}
if (u_dev < 1.45) {
s += "^";
} else if(u_dev > 1.69) {
s += "v";
}
if (r_dev < 1.45) {
s += ">";
}
if (f_dev > 1.57) s+= "A";
}
output += " " + s;
}
output += "\n";
}
}
// set the text in the MFD
p.setMultiFunctionText(this.name, output, false);
}
//-------------------------------------------------------------------------------------------------------------
// appends space to currentText to the specified length in 'em'
this.$padTextRight = function(currentText, desiredLength, leftSwitch) {
if (currentText == null) currentText = "";
var hairSpace = String.fromCharCode(31);
var ellip = "…";
var currentLength = defaultFont.measureString(currentText.toString().replace(/%%/g, "%"));
var hairSpaceLength = defaultFont.measureString(hairSpace);
// calculate number needed to fill remaining length
var padsNeeded = Math.floor((desiredLength - currentLength) / hairSpaceLength);
if (padsNeeded < 1) {
// text is too long for column, so start pulling characters off
var tmp = currentText;
do {
tmp = tmp.substring(0, tmp.length - 2) + ellip;
if (tmp == ellip) break;
} while (defaultFont.measureString(tmp.replace(/%%/g, "%")) > desiredLength);
currentLength = defaultFont.measureString(tmp);
padsNeeded = Math.floor((desiredLength - currentLength) / hairSpaceLength);
currentText = tmp;
}
// quick way of generating a repeated string of that number
if (!leftSwitch || leftSwitch == false) {
return currentText + new Array(padsNeeded).join(hairSpace);
} else {
return new Array(padsNeeded).join(hairSpace) + currentText;
}
}
|