Scripts/aj_script.js |
"use strict"
this.name = "Overdrive";
this.author = "Reval";
this.license = "CC-BY-NC-SA 4.0";
this.version = "1.5";
this.description = "FE Shipyards will re-route part of your Jump circuitry, linking it to your vehicle's velocity-controller. When full speed is set, J-drive will engage in a limited mode, similar in effect to an injector, but silent, fluid, faster, and without the attendant fuel-waste. We call it the O-drive. To disengage it, decelerate to below your normal top speed.";
this.shipWillLaunchFromStation = function() {
// start monitor if O-D installed and connected
this.$ajHasEq = (player.ship.equipmentStatus ("EQ_AUTO_J") === "EQUIPMENT_OK");
if ((this.$ajConnected) && (this.$ajHasEq)) {
if(!this.$ajTimer) this.$ajTimer=new Timer(this,this._ajMonitorSpeed.bind(this),0,0.25);
// note nominal maximum speed
this.$ajMaxSpeed = player.ship.maxSpeed;
// if E.T. present, use the Guild's enhanced speed
if (this.$ajET)
this.$ajETLast = worldScripts["Elite Trader"].$etLastSpeed;
}
}
this.shipWillDockWithStation = function(station) {
if (this.$ajHasEq) this._ajStopOverdrive();
}
this.shipDockedWithStation = function(station) {
// prepare connect/disconnect options Interface
var ps=player.ship;
if (ps.equipmentStatus ("EQ_AUTO_J") === "EQUIPMENT_OK")
this._ajPrepOptions(station);
}
this.shipWillEnterWitchspace = function(cause) {
// stop O-D before entering witchspace
if (this.$ajHasEq) this._ajStopOverdrive();
}
this.playerWillSaveGame = function() {
// save connected status
if (this.$ajConnected) var con=1; else var con=0;
missionVariables.ajConnected = con;
}
this.startUPComplete = function() {
// load connected status
if (missionVariables.ajConnected != null) {
var con=missionVariables.ajConnected;
this.$ajConnected = (con == 1);
}
}
this.startUp = function() {
// is E.T. present?
this.$ajET = false;
if (worldScripts["Elite Trader"])
this.$ajET = true;
// record etLastSpeed
this.$ajETLast = player.ship.maxSpeed;
// O-drive connection switch
this.$ajConnected = true;
this.$ajEngaged = false;
this.$ajMaxed = false;
this.$ajFactor = 10.0;
this.$ajMaxSpeed = player.ship.maxSpeed;
this.$ajHasEq = false;
// for total reset (connect/disconnect)
this.$ajNominal = player.ship.maxSpeed;
}
this.playerBoughtEquipment = function(equipment, paid) {
var pc = player.consoleMessage;
var ps = player.ship;
if (equipment == "EQ_AUTO_J") {
pc("Re-routing J-circuits for O-drive.",9);
pc("Overdrive is operative.",9);
// prepare connect/disconnect options
var sta = player.ship.dockedStation;
if (ps.equipmentStatus ("EQ_AUTO_J") === "EQUIPMENT_OK")
this._ajPrepOptions(sta);
}
}
this._ajAdjustSpeed = function() {
if (!this.$ajEngaged)
if (!this.$ajMaxed) {
player.ship.maxSpeed*=this.$ajFactor;
this.$ajMaxed = true;
this.$ajEngaged=true;
}
}
this._ajMonitorSpeed = function() {
var pss = player.ship.speed;
if (this.$ajEngaged) {
// stop the O-drive if J-Drive engaged
if (player.ship.torusEngaged)
this._ajStopOverdrive();
// stop the O-drive if decelerated to marker
if (pss < this.$ajMaxSpeed)
this._ajStopOverdrive();
} else {
// start the O-drive
if ((pss==this.$ajETLast) || (pss==this.$ajMaxSpeed)) {
this._ajAdjustSpeed();
player.consoleMessage("O-drive engaged.");
}
}
}
this._ajStopOverdrive = function() {
if (this.$ajET)
player.ship.maxSpeed = this.$ajETLast; else
player.ship.maxSpeed=this.$ajMaxSpeed;
this.$ajEngaged = false;
this.$ajMaxed = false;
player.consoleMessage("O-drive disengaged.");
}
// create Overdrive connection options
this._ajPrepOptions = function(station) {
station.setInterface("ajOpt",{
title: "Your FE Shipyards O-drive connection options",
category: "Your FE Shipyards",
summary: "FE Shipyards offers the option to connect or disconnect your Overdrive. This will also act as a 'reset' in case of unexpected behaviour." ,
callback: this._ajShowOptions.bind(this)
});
}
// show Overdrive connection options
this._ajShowOptions = function() {
var parameters = new Object();
parameters.title = "Overdrive Connection Options";
parameters.message = "Connect or disconnect your Overdrive circuits? \n\n";
parameters.choicesKey = "ajChoice";
mission.runScreen(parameters, callback);
function callback(choice) {
if (choice === "1_CONNECT") {
this.$ajConnected = true;
this.$ajEngaged = false;
this.$ajMaxed = false;
if (this.$ajET)
this.$ajETLast = worldScripts["Elite Trader"].$etLastSpeed; else
this.$ajMaxSpeed = this.$ajNominal;
player.commsMessage("Overdrive is connected.");
} else {
this.$ajConnected = false;
this.$ajEngaged = false;
this.$ajMaxed = false;
if (this.$ajET)
this.$ajETLast = worldScripts["Elite Trader"].$etLastSpeed; else
this.$ajMaxSpeed = this.$ajNominal;
player.commsMessage("Overdrive is disconnected.");
}
}
}
|