Back to Index Page generated: Dec 20, 2024, 7:22:09 AM

Expansion Auto-Prime Equipment

Content

Warnings

  1. http://wiki.alioth.net/index.php/Auto-Prime%20Equipment -> 404 Not Found
  2. Information URL mismatch between OXP Manifest and Expansion Manager string length at character position 0

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Automatic priming of equipment when current MFD changes. Automatic priming of equipment when current MFD changes.
Identifier oolite.oxp.phkb.AutoPrimeEquipment oolite.oxp.phkb.AutoPrimeEquipment
Title Auto-Prime Equipment Auto-Prime Equipment
Category Miscellaneous Miscellaneous
Author phkb phkb
Version 1.2 1.2
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL n/a
Download URL https://wiki.alioth.net/img_auth.php/2/2b/AutoPrimeEquipment.oxz n/a
License CC-BY-SA 4.0 CC-BY-SA 4.0
File Size n/a
Upload date 1610873258

Documentation

readme.txt

Auto Prime Equipment
By Nick Rogers

Overview
========
This OXP attempts to make life a bit simpler for pilots by automatically priming a specific piece of equipment whenever the MFD related to it is selected in an MFD slot. The trigger for the automatic priming is either when an MFD is cycled to a particular MFD ID (using the ";" key), or an MFD slot is selected where a particular MFD ID is already displayed (using the ":") key.

At present, the following equipment items will be activated when their MFD is selected:
    Comms Log MFD (if the Comms Log is in non-passive mode)
    Damage Report MFD (if the Damage Report MFD is in non-passive mode)
    Broadcast Comms MFD
    Range Finder MFD
    Manifest Scanner
    Market Inquirer MFD
    Waypoint Here MFD
    Escort Deck
    Telescope
    
This OXP requires Oolite 1.86/86 in order to function.

3rd Party Interface
===================
If other MFD's would like to add themselves to this control mechanism, they simply need to add this line to their startup scripts:

  worldScripts.AutoPrimeEquipment.$addConfig("MyMFDID", "EQ_MY_EQUIP_ID");

The first parameter is the ID being used for the MFD. This value is required.

The second parameter is the equipment key for the equipment item to be primed when the mfd ID is selected. Entering a value of "" (blank) will result in the MFD ID being removed from the list.

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.2
- Corrections to manifest.plist file.

1.1
- Added MFD/equipment item pairs for Telescope and Escort Deck.

1.0
- Initial public release

Equipment

This expansion declares no equipment. This may be related to warnings.

Ships

This expansion declares no ships. This may be related to warnings.

Models

This expansion declares no models. This may be related to warnings.

Scripts

Path
Config/script.js
"use strict";
this.name        = "AutoPrimeEquipment";
this.author      = "phkb";
this.copyright   = "2017 phkb";
this.description = "Automatic priming of equipment when current MFD changes.";
this.licence     = "CC BY-NC-SA 4.0";

// preloaded with some examples
this._config = {
    "CommsLogMFD":"EQ_COMMSLOGMFD",
    "DamageReportMFD":"EQ_DAMAGE_REPORT_MFD",
    "BroadcastCommsMFD":"EQ_BROADCASTCOMMSMFD",
    "RangeFinderMFD":"EQ_GCM_RANGE_FINDER_MFD",
    "ManifestScanner":"EQ_MANIF_SCANNER",
    "inquirer_mfd":"EQ_MARKET_INQUIRER_MFD",
    "Waypoint_Here_MFD":"EQ_WPH_ASC_UPGRADE",
    "escortdeck":"EQ_ESCORTDECK",
    "telescope":"EQ_TELESCOPE"
};
this._unprime = "";

//-------------------------------------------------------------------------------------------------------------
// public function to add extra config items
// mfdID = the ID of the MFD (required)
// eqKey = the equipment key for the equipment item to be primed when the MFD is selected
this.$addConfig = function(mfdID, eqKey) {
    if (mfdID === "") return;
    if (eqKey === "" && mfdID !== "") {
        delete this._config[mfdID];
    } else {
        this._config[mfdID] = eqKey;
    }
}

//-------------------------------------------------------------------------------------------------------------
this.shipWillLaunchFromStation = function() {
    // special case for escort deck, which has two different equipment items, depending on ship size
    if (player.ship.equipmentStatus("EQ_ESCORTDECKXL") === "EQUIPMENT_OK") {
        this.$addConfig("escortdeck", "EQ_ESCORTDECKXL");
    } else {
        this.$addConfig("escortdeck", "EQ_ESCORTDECK");
    }
}

//-------------------------------------------------------------------------------------------------------------
this.selectedMFDChanged = function(index) {
    var equipkey = this._config[player.ship.multiFunctionDisplayList[index]];
    if (equipkey) this.$primeEquipment(equipkey); 
    else this.$unprimeEquipment();
}

//-------------------------------------------------------------------------------------------------------------
this.mfdKeyChanged = function(index, key) {
    var equipkey = this._config[key];
    if (equipkey) this.$primeEquipment(equipkey);
    else this.$unprimeEquipment();
}

//-------------------------------------------------------------------------------------------------------------
this.playerChangedPrimedEquipment = function(equipmentKey) {
    // if the player manually changes the primed equipment, but we have an unprime value set, update it
    if (equipmentKey !== "" && this._unprime !== "" && player.ship.equipmentStatus(equipmentKey) === "EQUIPMENT_OK") this._unprime = equipmentKey;
}

//-------------------------------------------------------------------------------------------------------------
this.$primeEquipment = function(equipmentKey) {
    var p = player.ship;
    // only prime equipment if it's installed and undamaged
    if (p.equipmentStatus(equipmentKey) !== "EQUIPMENT_OK") return;
    // check the currently primed equipment item
    if (p.hasOwnProperty("primedEquipment")) {
        var check = p.primedEquipment;
        // if it's not one of the ones in our config, make a note of it so we can switch back to it later
        if (!this.$equipmentInConfig(check)) this._unprime = p.primedEquipment;
    }
    p.setPrimedEquipment(equipmentKey);
}

//-------------------------------------------------------------------------------------------------------------
this.$unprimeEquipment = function() {
    if (this._unprime !== "") {
        player.ship.setPrimedEquipment(this._unprime);
        this._unprime = "";
    }
}

//-------------------------------------------------------------------------------------------------------------
this.$equipmentInConfig = function(equipmentKey) {
    var k = Object.keys(this._config);
    for (var i = 0; i < k.length; i++) {
        if (this._config[k[i]] === equipmentKey) return true;
    }
    return false;
}