Back to Index Page generated: May 8, 2024, 6:16:03 AM

Expansion Naval Grid Next

Content

Warnings

  1. Unresolved dependency reference to oolite.oxp.Thargoid.NavalGrid:0
  2. No version in dependency reference to oolite.oxp.Thargoid.NavalGrid:null
  3. Conflict Expansions mismatch between OXP Manifest and Expansion Manager at character position 0063 (DIGIT ZERO vs LATIN SMALL LETTER N)
  4. Unknown key 'upload_date' at https://wiki.alioth.net/img_auth.php/b/ba/NavalGridNext-2.0.oxz!manifest.plist

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Enhanced energy grid to link the energy units to the shields, enhancing recharging rates. There is a civilian and a naval version, requiring an Extra or Naval Energy Unit. Enhanced energy grid to link the energy units to the shields, enhancing recharging rates. There is a civilian and a naval version, requiring an Extra or Naval Energy Unit.
Identifier oolite.oxp.Lone_Wolf.NavalGridNext oolite.oxp.Lone_Wolf.NavalGridNext
Title Naval Grid Next Naval Grid Next
Category Equipment Equipment
Author Lone_Wolf Lone_Wolf
Version 2.0 2.0
Tags Equipment, Shields Equipment, Shields
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
  • oolite.oxp.Thargoid.NavalGrid:0
  • oolite.oxp.Thargoid.NavalGrid:
  • Information URL http://wiki.alioth.net/index.php/NavalGrid_OXP n/a
    Download URL https://wiki.alioth.net/img_auth.php/b/ba/NavalGridNext-2.0.oxz n/a
    License CC-BY-SA 4.0 CC-BY-SA 4.0
    File Size n/a
    Upload date 1610873454

    Documentation

    Also read http://wiki.alioth.net/index.php/Naval%20Grid%20Next

    Readme.txt

    Naval Grid Next
    ---------------
    by Lone_Wolf
    
    This OXP allows the the increased energy recharge rate from Extra Energy Unit (EEU) or Naval Energy Unit (NEU) to improve shield recharging.
    
    The ship's factory energy grid will not transfer more than 4 energy units each second into the shields (2 to the forward and 2 to the aft shields) even if the energy is available, i. e., the ship's energy recharge rate exceeds 4 units/s. The Military Shield Enhancement include an upgrade of the fatcory energy grid to handle a recharge of 6 energy units each second (3 for each shield), but the same limitations apply : if the ship's energy recharge rate exceeds the 6 unit/s, that energy can't be used to recharge the shields.
    
    This OXP creates two new energy grids allowing higher energy transfers to the shields if there is enough energy generation capability:
    
    Enery grid
    
    This is a civilian version built with standard components. It can only handle limited amounts of recharge energy, but is compatible with the EEU, routing up to 50% of the available recharge energy to the shields, and with the NEU, when it's capable of routing up to 30% of available recharge energy to the shields (which is still 20% higher than what would be transferred had the ship only an EEU).
    Cost : 2,500 , techlevel 10
    
    Naval Energy Grid
    
    The military version meant for use with the Naval Energy Unit - it works with the EEU, but with the NEU it can accomplish its full potential. It's price is steep, but it can handle the huge amount of available recharge energy provided by the Naval Energy Unit: it will route up to 90% of the available energy recharge to the shields.
    Cost : 65,000 , Techlevel 14 .
    
    
    Notes for OXP developers
    ------------------------
    
    This OXP makes available two helper functions:
    
    * worldScripts.NavalGrid.$ng_calc_booster_recharge(ship)
        Parameters:
            ship: ship object
    
        Calculates the shield recharge rate taking into account the ship's scriptInfo (if any) and the ship's Shield Booster equipments. Does not update the ship's shield recharge rate properties.
        Output: object with properties 'aft' and 'fwd'
    
    
    * worldScripts.NavalGrid.$ng_calc_shield_recharge_update(ship, shield_recharge_rates, context)
        Parameters:
            ship: ship object;
            shield_recharge_rates: object whith two properties ('fwd' and 'aft') with the ship's shield recharge rates (the ship's factory rates plus any Shield Booster);
            context: string describing the circunstances of the call, for logging purposes;
    
        Calculates the updated shield recharge rates given any Energy Grid (civillian or naval) installed in the ship. Does not update the ship's shield recharge rate properties.
        Output: object with properties 'aft' and 'fwd'
    
    
    License 
    -------
    
    CC-BY-NC-SA 4.0 - Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
    (https://creativecommons.org/licenses/by-nc-sa/4.0/)
    
    
    OXP History
    -----------
    
    The OXP was started by Thargoid, taken over by Lone_Wolf when Thargoid announced on forum he lacked time to keep maintaining his many oxps, then taken up by Dybal some years later (v2.x).
    
    Up to v1.13, the energy grids were player ship only - they could be awarded to a NPC ship, but the NPC would get no additional shield recharge from them, even if the player were running an OXP do handle shields for the NPCs.
    
    Version 2.0 is a re-write that aims to enable the OXP functionality for NPCs too, by making available functions that any OXP supplying a shield implementation for NPCs (like N-Shields) can use to discover the updated shield recharge rates.
    
    
    Change Log
    ----------
    
    v2.0
    - made the Naval Energy Grid compatible with the EEU - if it can handle the NEU output, it sure can handle EEU's.
    - NEU or EEU can be sold for a 40% refund.
    - made the civilian energy grid transfer a lower fraction of the available energy when NEU (instead of EEU) was installed (lower fraction of a larger amount of energy is still a higher energy transfer).
    - re-write to expose functions to calculate the shield recharge rates taking into account the Shield Boosters and taking into account the Energy Grids for other OXPs (N-Shields) to use enabling the Energy Grids for NPC ships.
    
    v1.13 
    - correcting Extra Energy Unit string identifier in equipment.plist thhat prevented the civilian Energy Grid from being available for purchase
    
    v1.12 
    - replacing handlers gave problems, switched to a different method of combining additive(NG next) and multiplicative modifiers.
    
    v1.11.1
    - replacement add/remove equipment handlers used wrong function name
    
    v1.11
    - it was impossible to install Naval Energy Unit or Naval Grid if you had civilian energy grid installed, added sell option for energy grid to solve this
    - fixed errors in the functions that handle apply/revert the modificationss to the shield charge values
    
    v1.10
    - rewrite to make use of 1.82 feautures, especially the now writable shield recharge value.
    - no longer uses a timer, core game now handles the actual shield recharging
    - removed primable part as it's no longer relevant/needed with the new design
    - added a lower spec civilian version that depends on EEU instead of NEU, so players can now get extra shield recharge if they have an EEU installed.
    This should help survival in early/mid-game . (the energy is available, why not use it ? )
    
    
    Older versions 
    
    v1.00 initial release by Thargoid.
    
    --------------------------------------------------------------
    
    Acknowledgements:
    
    With thanks to Zireael for the original inspiration and request.
    Thargoid for creating this excellent oxp.
    Lone_Wolf for a great re-write that simplified the equipments operation fot the player.
    

    Equipment

    Name Visible Cost [deci-credits] Tech-Level
    Energy Grid yes 25000 10+
    Naval Energy Grid yes 650000 14+
    Sell Energy Grid yes 0 10+
    Sell Naval Energy Grid yes 0 14+

    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
    Scripts/NavalGrid.js
    "use strict";
    this.name        = "NavalGrid";
    this.author      = "Dybal";
    this.copyright   = "2020 Dybal";
    this.licence     = "CC-BY-NC-SA 4.0";
    this.description = "Naval Grid worldscript event handlers and functions";
    this.version     = "2.0";
    
    this.$relatedEquipment = [  
                                "EQ_ENERGY_GRID",
                                "EQ_NAVAL_GRID",
                                "EQ_ENERGY_UNIT",
                                "EQ_NAVAL_ENERGY_UNIT",
                                "EQ_SHIELD_BOOSTER",
                                "EQ_NAVAL_SHIELD_BOOSTER"
                            ];
    this.$directEquipment = [
                                "EQ_ENERGY_GRID",
                                "EQ_NAVAL_GRID",
                            ];
    this.$equipmentRemoval = {
                                EQ_SELL_ENERGY_GRID: "EQ_ENERGY_GRID",
                                EQ_SELL_NAVAL_GRID: "EQ_NAVAL_GRID"
                             };
    this.$debug = true;
    this.$started = false;
    
    //
    // Event Handlers
    //
    
    //---------------------------------------------------------------------------------//
    this.startUpComplete = function _startUpComplete() {
        this.$started = true;
        this._ng_player_update("startup");
    }
    
    //---------------------------------------------------------------------------------//
    this.playerBoughtEquipment = function _playerBoughtEquipment(eqKey) {
        var _equipmentRemoval = this.$equipmentRemoval;
        if (eqKey in _equipmentRemoval) {
            var eq_to_remove = _equipmentRemoval[eqKey];
            player.ship.removeEquipment(eqKey);
            player.ship.removeEquipment(eq_to_remove);
            player.credits += 0.4 * EquipmentInfo.infoForKey(eq_to_remove).price;
        }
    }  
    
    //---------------------------------------------------------------------------------//
    this.equipmentAdded = function _equipmentAdded(eqKey) {
        // don't alter the player ship's shieldRechargeRate until Oolite Equipment Control has 
        // initialized its baseline structure at startUp
        if (!this.$started) return;
    
        if (this.$relatedEquipment.indexOf(eqKey) >= 0) {
            if (this.$directEquipment.indexOf(eqKey) >= 0)
                this._ng_player_update(eqKey+" added");
            else if (!this.$playerUpdateTimer) {
                // delay setup to allow Oolite Equipment Control's equipmentAdded to run first
                if (this.$debug) log(this.name, "Delaying action on adding "+eqKey);
                this.$playerUpdateTimer = new Timer(this, this._ng_player_update.bind(this, eqKey+" added"), 0);
            } else 
                if (this.$debug) log(this.name, "equipmentAdded "+eqKey+", there is already a timer running");
        }
    }
     
    //---------------------------------------------------------------------------------//
    this.equipmentRemoved = function _equipmentRemoved(eqKey) {
        // don't alter the player ship's shieldRechargeRate until Oolite Equipment Control has 
        // initialized its baseline structure at startUp
        if (!this.$started) return;
    
        if (this.$relatedEquipment.indexOf(eqKey) >= 0) {
            if (this.$directEquipment.indexOf(eqKey) >= 0)
                this._ng_player_update(eqKey+" removed");
            else if (!this.$playerUpdateTimer) {
                // delay setup to allow Oolite Equipment Control's equipmentRemoved to run first
                log(this.name, "Delaying action on removing "+eqKey);
                if (this.$debug) this.$playerUpdateTimer = new Timer(this, this._ng_player_update.bind(this, eqKey+" removed"), 0);
            } else
                if (this.$debug) log(this.name, "equipmentRemoved "+eqKey+", there is already a timer running");
        }
    };  
    
    
    //
    //  Functions for OXPs to use
    //
    
    //-----------------------------------------------------------------------------------//
    // Calculates Shield Recharge Rates based on the ship's original shield recharge rate and the
    // shield booster devices installed on the ship.
    // Does NOT alter the ship's properties.
    this.$ng_calc_booster_recharge = function _ng_calc_booster_recharge(ship) {
        var that = _ng_calc_booster_recharge;
        var shieldBoosterEqs = (that.shieldBoosterEqs = shieldBoosterEqs || [ "EQ_SHIELD_BOOSTER",
                                                                              "EQ_NAVAL_SHIELD_BOOSTER",
                                                                              "EQ_NSHIELDS_NPC_SHIELD_BOOSTER",
                                                                              "EQ_NSHIELDS_NPC_NAVAL_SHIELD_BOOSTER"
                                                                            ]);
        var shieldRecharge = { fwd: 2, aft: 2 };
    
        if (ship.scriptInfo) {
            if (ship.scriptInfo.shield_recharge_forward) shield_recharge.fwd = parseInt(ship.scriptInfo.shield_recharge_forward);
            if (ship.scriptInfo.shield_recharge_aft) shield_recharge.aft = parseInt(ship.scriptInfo.shield_recharge_aft);
        }
    
        var eq, scriptInfo, i = shieldBoosterEqs.length;
        while (i--) {
            eq = shieldBoosterEqs[i];
            if (ship.equipmentStatus(eq) === "EQUIPMENT_OK") {
                scriptInfo = EquipmentInfo.infoForKey(eq).scriptInfo;
                if (this.$debug) log("NavalGrid", eq+", scriptInfo:"+ JSON.stringify(scriptInfo));
                let recharge_boost = parseFloat(scriptInfo.oolite_shield_recharge_multiplier);
                shieldRecharge.fwd *= recharge_boost;
                shieldRecharge.aft *= recharge_boost;
            }
        }
        if (this.$debug) log("NavalGrid", ship.displayName+", shieldRechargeRate after Boosters: "+shieldRecharge.fwd.toFixed(2)+"/"+shieldRecharge.aft.toFixed(2)+", shields: "+ship.maxForwardShield+"/"+ship.maxAftShield);
        return shieldRecharge;
    }
    
    //-----------------------------------------------------------------------------------//
    // Caculates the updated values for the Shield Recharge Rates based on the Grid equipment installed and functional on the ship.
    // Deals only with the Grid effects, all other effects must already be incorporated into the base recharge rates input into this.
    // NPC enabled, might be called by N-Shields when setting up NPC's shields.
    // Does NOT alter the ship's properties.
    // Input:
    //      ship: reference to the ship object (player or NPC);
    //      shRechargeRates: object with properties 'fwd' and 'aft', containing the base shield recharge rate (the ship's original 
    //                       shield recharge rates plus improvements from shield boosters) ;
    //      context: string describing the circunstances of the call, for logging purposes;
    // Output:
    //      Object with properties 'fwd' and 'aft' with the updated (original + grid improvements) shield 
    //      recharge rates;
    this.$ng_calc_shield_recharge_update = function _ng_update(ship, shRechargeRates, context) { 
        var ng_switch_max = 0;
        var result = {
                        fwd: shRechargeRates.fwd,
                        aft: shRechargeRates.aft
        };
        
        // find the fraction of the energy "production" that should be earmarked for shields
        // based on the type of grid; this doesn't take into account at all the other energy
        // consuming equipments installed in the ship (shields have priority!), which could lead
        // to energy bank depletion (and ship destruction) if the shields keep being drained faster
        // than the improved recharge
        if (ship.equipmentStatus("EQ_ENERGY_GRID") === "EQUIPMENT_OK") {
            if (ship.equipmentStatus("EQ_ENERGY_UNIT") === "EQUIPMENT_OK")
                ng_switch_max = 0.5;
            else if (ship.equipmentStatus("EQ_NAVAL_ENERGY_UNIT") === "EQUIPMENT_OK")
                // civillian grid shouldn't be able to carry full NEU load to the shields... 
                // this adds around 20% energy transfer compared to EEU
                ng_switch_max = 0.3;
        } else if (ship.equipmentStatus("EQ_NAVAL_GRID") === "EQUIPMENT_OK") {
            if (ship.equipmentStatus("EQ_ENERGY_UNIT") === "EQUIPMENT_OK" ||
                ship.equipmentStatus("EQ_NAVAL_ENERGY_UNIT") === "EQUIPMENT_OK")
                ng_switch_max = 0.9;
        }
    
        var total_shield_recharge_rate = shRechargeRates.fwd + shRechargeRates.aft;
        var available_energy = ship.energyRechargeRate - total_shield_recharge_rate;
        if (available_energy > 0) {
            // only a part of the available energy "production" can be redirected to shields
            available_energy *= ng_switch_max;
            // distribute the available energy between the shields proportional to their recharge rates
            // shtRechRat = shRechRat + availEnerg*(shRechRat/totalRechRate)
            result.fwd *= 1 + (available_energy / total_shield_recharge_rate);
            result.aft *= 1 + (available_energy / total_shield_recharge_rate);
        }
        if (this.$debug) log("NavalGrid", ship.displayName+", shieldRechargeRate, from "+shRechargeRates.fwd.toFixed(2)+"/"+shRechargeRates.aft.toFixed(2)+" to "+result.fwd.toFixed(2)+"/"+result.aft.toFixed(2)+", energyRechargeRate:"+ship.energyRechargeRate.toFixed(2)+", available:"+available_energy.toFixed(2));
        return result;
    }
    
    
    //
    // Internal functions
    //
    
    //-----------------------------------------------------------------------------------//
    this._ng_player_update = function _ng_player_update(context) {
        if (this.$debug) log(this.name, "Updating player ship for "+context);
        var ship = player.ship;
    
        var shieldRechargeRates = this.$ng_calc_booster_recharge(ship);
        var result = this.$ng_calc_shield_recharge_update(ship, shieldRechargeRates, context);
    
        ship.forwardShieldRechargeRate = result.fwd;
        ship.aftShieldRechargeRate = result.aft;
        delete this.$playerUpdateTimer;
    }