| Config/script.js |
"use strict";
this.author = "phkb";
this.copyright = "© 2021 phkb.";
this.licence = "CC-BY-NC-SA 4.0";
this.name = "RemoveIndividualPylon";
this.description = "Script for removing an individual pylon-mounted weapon";
this._lastChoice = "";
//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function () {
if (worldScripts.EmailSystem) {
worldScripts.GalCopAdminServices._purchase_ignore_equip.push("EQ_IND_MISSILE_REMOVAL");
}
if (worldScripts.Lib_GUI) {
worldScripts.Lib_GUI.$IDRules["oolite-sellpylon-map"] = { pic: 1, snd: 1, mus: 1 };
}
}
//-------------------------------------------------------------------------------------------------------------
this.playerBoughtEquipment = function (equipmentKey) {
if (equipmentKey == "EQ_IND_MISSILE_REMOVAL") {
player.ship.removeEquipment("EQ_IND_MISSILE_REMOVAL");
this.$showMissileRemovalScreen();
}
}
//-------------------------------------------------------------------------------------------------------------
this.$showMissileRemovalScreen = function $showMissileRemovalScreen() {
var curChoices = {};
var itemcount = 0;
var p = player.ship;
var text = expandDescription("[rip_message]");
var pagesize = 17;
if (this.$isBigGuiActive() === true) pagesize = 23;
// any missiles?
if (p.missileCapacity > 0) {
var flag = false;
try {
var miss = p.missiles;
for (var i = 0; i < miss.length; i++) {
//var info = EquipmentInfo.infoForKey(miss[i].equipmentKey);
curChoices["01_MISSILE_" + (i < 10 ? "0" : "") + i + "~" + i] = { text: " -- " + EquipmentInfo.infoForKey(miss[i].equipmentKey).name + expandDescription("[rip_refund]", { price: miss[i].price }), alignment: "LEFT" };
itemcount += 1;
}
if (itemcount == 0) text += expandDescription("[rip_none_found]");
flag = true;
} catch (err) {
text += expandDescription("[rip_error]");
if (this._debug) log(this.name, "!!ERROR: " + err);
}
if (flag === true) {
}
} else {
text += expandDescription("[rip_no_pylons]");
}
for (var i = 0; i < ((pagesize + 1) - itemcount); i++) {
curChoices["90_SPACER_" + i] = "";
}
var def = "99_EXIT";
if (this._lastChoice != "") def = this._lastChoice;
curChoices["99_EXIT"] = { text: "[rip_return]" };
var opts = {
screenID: "oolite-sellpylon-map",
title: expandDescription("[rip_title]"),
exitScreen: "GUI_SCREEN_EQUIP_SHIP",
choices: curChoices,
initialChoicesKey: def,
message: text
};
mission.runScreen(opts, this.$screenHandler, this);
}
//-------------------------------------------------------------------------------------------------------------
this.$screenHandler = function $screenHandler(choice) {
if (!choice) return;
if (choice.indexOf("01_MISSILE") >= 0) {
var idx = parseInt(choice.substring(choice.indexOf("~") + 1));
var eq = player.ship.missiles[idx].equipmentKey;
var info = EquipmentInfo.infoForKey(eq);
player.ship.removeEquipment(eq);
player.credits += parseInt(info.price / 10);
player.consoleMessage(expandDescription("[rip_final_refund]", { price: info.price }));
// reset the last choice so we auto-select the next missile, if there is one to select
if (player.ship.missiles.length = idx) idx -= 1;
if (player.ship.missiles.length = 0) {
this._lastChoice = "";
} else {
this._lastChoice = "01_MISSILE_" + (idx < 10 ? "0" : "") + idx + "~" + idx;
}
}
if (choice != "99_EXIT") this.$showMissileRemovalScreen();
}
//-------------------------------------------------------------------------------------------------------------
// returns true if a HUD with allowBigGUI is enabled, otherwise false
this.$isBigGuiActive = function $isBigGuiActive() {
if (oolite.compareVersion("1.83") <= 0) {
return player.ship.hudAllowsBigGui;
} else {
var bigGuiHUD = ["XenonHUD.plist", "coluber_hud_ch01-dock.plist"]; // until there is a property we can check, I'll be listing HUD's that have the allow_big_gui property set here
if (bigGuiHUD.indexOf(player.ship.hud) >= 0) {
return true;
} else {
return false;
}
}
}
|