Config/script.js |
this.name = "tws_satnav_main";
this.author = "Wyn Sleeman";
this.copyright = "(C) 2014 Wyn Sleeman";
this.licence = "CC-NC-by-SA 3.0";
this.description = "Navigation aid for long journeys";
this.version = "0.01";
this.equipmentName = "EQ_TWS_GALACTICSATNAV";
"use strict";
//WorldSpace Handlers
this.startUp = function()
{
this._finalDestination = -1;
if(missionVariables.tws_satnav_finalDestination === null) return;
this._finalDestination = missionVariables.tws_satnav_finalDestination;
}
this.playerWillSaveGame = function(message)
{
if(this._okToContinue() == true)
{
missionVariables.tws_satnav_finalDestination = this._finalDestination;
}
else
{
missionVariables.tws_satnav_finalDestination = null;
}
}
this.guiScreenChanged = function(to, from)
{
if(guiScreen != "GUI_SCREEN_SHORT_RANGE_CHART") return;
if(this._okToContinue() == false) return;
if(this._finalDestination == system.ID)
{
this._finalDestination = -1;
return;
}
player.consoleMessage("Routes to " + System.systemNameForID(this._finalDestination), 10);
this._destinationInfo = System.infoForSystem(system.info.galaxyID, this._finalDestination);
this._route = system.info.routeToSystem(this._destinationInfo,"OPTIMIZED_BY_JUMPS");
if(! this._route) return;
this._showRouteDescription("Shortest");
this._route = system.info.routeToSystem(this._destinationInfo,"OPTIMIZED_BY_TIME");
if(! this._route) return;
this._showRouteDescription("Quickest");
}
this.playerEnteredNewGalaxy = function(galaxyNumber)
{
this._finalDestination = -1;
}
this.shipExitedWitchspace = function()
{
if(this._okToContinue()==false) return;
if(this._finalDestination == system.ID)
{
player.consoleMessage("SatNav OFF: You have arrived at " + System.systemNameForID(this._finalDestination) , 6);
this._finalDestination = -1;
return;
}
}
//Internal Functions
this._setDestination = function()
{
if(player.ship.targetSystem >= 0)
{
this._finalDestination = player.ship.targetSystem;
player.consoleMessage("SatNav ON. Destination: " + System.systemNameForID(player.ship.targetSystem), 6);
}
}
this._okToContinue = function()
{
if(player.ship.equipmentStatus("EQ_ADVANCED_NAVIGATIONAL_ARRAY") != "EQUIPMENT_OK") return false;
if(player.ship.equipmentStatus(this.equipmentName) != "EQUIPMENT_OK") return false;
if(this._finalDestination == -1) return false;
return true;
}
this._showRouteDescription = function(routeType)
{
let _result = routeType;
if(this._route.route.length <= 2)
{
_result += ": Direct to " + System.systemNameForID(this._finalDestination) + " (";
}
else
{
_result += ": via " + System.systemNameForID(this._route.route[1]) + " ("+ formatInteger(this._route.route.length -1) + " J, ";
}
_result += formatCredits(this._route.distance, true, false) + " LY, " + formatCredits(this._route.time, true, false) +" hrs)";
player.consoleMessage( _result, 10);
delete _result;
} |