Back to Index Page generated: Nov 12, 2024, 11:02:04 PM

Expansion Remove Individual Pylon

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Allows an individual pylon-mounted weapon to be removed. Allows an individual pylon-mounted weapon to be removed.
Identifier oolite.oxp.phkb.RemoveIndividualPylon oolite.oxp.phkb.RemoveIndividualPylon
Title Remove Individual Pylon Remove Individual Pylon
Category Equipment Equipment
Author phkb phkb
Version 1.0 1.0
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL http://wiki.alioth.net/index.php/Remove_Individual_Pylon_OXP n/a
Download URL https://wiki.alioth.net/img_auth.php/7/7e/RemoveIndividualPylon.oxz n/a
License CC BY-NC-SA 4.0 CC BY-NC-SA 4.0
File Size n/a
Upload date 1627014844

Documentation

Also read http://wiki.alioth.net/index.php/Remove%20Individual%20Pylon

readme.txt

Remove Individual Pylon
By Nick Rogers

Overview
========
This OXP allows individual pylon mounted weapons to be removed and sold.

Operations
==========
From the F3 Equip Ship screen, select the "Unmount and sell single pylon mounted weapon" item. This will display a screen where each of the currently mounted pylon weapons will be listed. Select the item you wish to remove and press enter. The item will be removed, and the full cost of the item will be refunded to you.

License
=======
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 4.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/

Version History
===============
1.0
- Initial release.

Equipment

Name Visible Cost [deci-credits] Tech-Level
Unmount and sell single pylon mounted weapon yes 0 2+

Ships

This expansion declares no ships.

Models

This expansion declares no models.

Scripts

Path
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");
    }
}

//-------------------------------------------------------------------------------------------------------------
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 = "Select the pylon mounted weapon you want to sell and remove:";
	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++) {
                curChoices["01_MISSILE_" + (i < 10 ? "0" : "") + i + "~" + i] = {text:" -- " + EquipmentInfo.infoForKey(miss[i].equipmentKey).name, alignment:"LEFT"};
                itemcount += 1;
            }
            if (itemcount == 0) text += "\n\nNo pylon mounted weapons found.";
            flag = true;
        } catch (err) {
            text += "\n\nComputer system malfunction - unable to access pylons!";
            if (this._debug) log(this.name, "!!ERROR: " + err);
        }
        if (flag === true) {

        }
    } else {
        text += "\n\nShip has 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: "Return"};
    
    var opts = {
        screenID: "oolite-sellpylon-map",
        title: "Sell Pylon Mounted Weapon",
        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("You have been refunded " + formatCredits(parseInt(info.price / 10), false, true));

        // 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;
		}
	}
}