Config/script.js |
"use strict";
this.name = "useful_MFDs";
this.author = "Zireael";
this.copyright = "2013 Zireael";
this.description = "Makes MFDs more useful by displaying some info";
this.version = "0.6";
this.licence = "CC BY-NC-SA 3.0";
this.$updateTimer;
this.$count = 0;
//-----------------------------------------------------------------------------------
this.startUpComplete = function() {
this.$player = player;
this.$ship = this.$player.ship;
this.$sun = system.sun;
this.$systemMarket = system.mainStation.market;
this.$station = this.$ship.dockedStation;
this.$stationName = this.$station.displayName;
this.$registerHUDSelector();
this.$updateMFDs();
}
//-----------------------------------------------------------------------------------
this.shipDockedWithStation = function(station) {
this.$station = station;
this.$stationName = this.$station.displayName;
}
//-----------------------------------------------------------------------------------
this.shipLaunchedFromStation = this.shipExitedWitchspace = function() {
var _player = this.$player;
this.$sun = system.sun;
this.$count = 0;
this.$station = null;
this.$stationName = null;
this.$showGeneralInfo.sun = this.$sun;
this.$systemMarket = (system.mainStation ? system.mainStation.market : null);
this.$showStationMarket();
if (this.$updateTimer)
this.$updateTimer.start();
else
this.$updateTimer = new Timer(this, this.$updateMFDs.bind(this), 0, 1);
}
//-----------------------------------------------------------------------------------
this.shipWillDockWithStation = this.shipWillEnterWitchspace = function() {
if (this.$updateTimer && this.$updateTimer.isRunning)
this.$updateTimer.stop();
}
//-----------------------------------------------------------------------------------
this.playerBoughtNewShip = this.playerReplacedShip = function() {
this.$ship = player.ship;
}
//-----------------------------------------------------------------------------------
this.$registerHUDSelector = function() {
var ws = worldScripts.hudselector;
if (!ws) return;
ws.$HUDSelectorAddMFD("useful_MFDs", "useful_MFD_general_info");
ws.$HUDSelectorAddMFD("useful_MFDs", "useful_MFD_market");
}
//-----------------------------------------------------------------------------------
this.$updateMFDs = function _usefulMFDs_updateMFDs() {
this.$count += 1;
this.$showGeneralInfo();
if (this.$count % 5 === 0) {
this.$showStationMarket();
}
}
//-----------------------------------------------------------------------------------
this.$showGeneralInfo = function _usefulMFDs_showGeneralInfo() {
var that = _usefulMFDs_showGeneralInfo;
var wsAstroLib = (that.wsAstroLib = that.wsAtroLib || worldScripts.AstroLibrary);
var _player = (that._player = that._player || player);
var ship = (that._ship = that._ship || this.$ship);
var sun = (that.sun = that.sun || this.$sun);
var solarwind = (wsAstroLib ? wsAstroLib.$astroLib_SolarWind(ship.position.distanceTo(sun)) : null);
var txt = ship.displayName;
txt += "\nService Level: " + ship.serviceLevel + "%";
txt += ", Mass: "+(ship.mass/1000).toFixed(1)+"t";
txt += "\nRe-sale Price: " + ship.price*0.75 + " Cr";
txt += "\nNext Revision: " + ship.renovationMultiplier*ship.renovationCost/10 + " Cr";
txt += "\nFuel: "+ship.fuel.toFixed(1)+" LY";
if (solarwind != null) txt += ", Solar Wind: "+solarwind.toFixed(3)+" LY/min";
txt += "\nCredits: " + _player.credits.toFixed(1) + "₢";
txt += "\nLegal Status : " + _player.legalStatus + " (" + _player.bounty + ")";
txt += "\nRating: " + _player.rank + " (" + _player.score + ")";
txt += "\nParcel Rep.: "+_player.parcelReputationPrecise.toFixed(2);
txt += "\nCurrent date: " + this.$setDateSince(3142, 2, 21);
ship.setMultiFunctionText("useful_MFD_general_info", txt, true);
}
//-----------------------------------------------------------------------------------
this.$showStationMarket = function _usefulMFDs_showStationMarket() {
var ship = this.$ship;
var sysMarket = this.$systemMarket;
var _manifest = ship.manifest.list;
var z = _manifest.length;
var msg = ((z > 0) ? "Market for the ship's cargo" : "No cargo");
var m, c, qtt, price;
while (z--) {
m = _manifest[z];
c = m.commodity;
if (sysMarket) {
qtt = sysMarket[c].quantity;
price = sysMarket[c].price / 10;
}
if ( m.quantity > 0) {
msg += "\n"+m.quantity+m.unit+" "+m.displayName+" -> "+(sysMarket ? qtt+m.unit+" at "+formatCredits(price,true,true) : "No Main Station in range");
}
}
ship.setMultiFunctionText("useful_MFD_market", msg, true);
}
//-----------------------------------------------------------------------------------
this.$setStartDate = function(year, month, day) {
var startDate = new Date();
startDate.setFullYear(year, month, day);
return startDate.toLocaleString();
}
//-----------------------------------------------------------------------------------
this.$setDateSince = function(year, month, day) {
var testDate = new Date();
testDate.setFullYear(year, month, day);
var secondsPassedTotal = clock.seconds - 2084004 * 86400.0;
var hoursPassed = Math.floor(secondsPassedTotal / 3600);
var minutesPassed = Math.floor((secondsPassedTotal % 3600) / 60);
var secondsPassed = Math.floor(secondsPassedTotal % 60);
testDate.setHours(hoursPassed);
testDate.setMinutes(minutesPassed);
testDate.setSeconds(secondsPassed);
return testDate.toLocaleString();
}
//-----------------------------------------------------------------------------------
this.$killRate = function() {
var days = clock.days - 2084004;
var kills = player.score;
return kills / days;
}
/*this.$showDamagedEquipment = function() {
for (i = start; i < eqptCount; i++)
{
info = [eqptList oo_arrayAtIndex:i];
name = [info oo_stringAtIndex:0];
if([name length] > 42) name = [[name substringToIndex:40] stringByAppendingString:@"..."];
damaged = ![info oo_boolAtIndex:1];
if (damaged) glColor4f (1.0f, 0.5f, 0.0f, 1.0f); // Damaged items show up orange.
// else glColor4f (1.0f, 1.0f, 0.0f, 1.0f);
}*/
|