Page 1 of 3

Naval Grid OXP

Posted: Wed Mar 09, 2011 8:23 pm
by Thargoid
Because it was asked here and because I had a little spare time, allow me to declassify the Naval Energy Grid.

This military enhancement is designed to properly connect a naval energy unit with military boosted ship shields, giving an enhanced recharging rate. It is switchable via the equipment switch key ("n" by default) to route the energy flow to either the reserve banks or to the shields, although this is overridden in the case of full shields or critically low energy levels.

Available from tech level 14 systems for the sum of 65,000 credits. Also requires the NEU and military shield boosters.

- - = = Download Here = = - -

Re: [Release]Naval Grid OXP

Posted: Fri May 13, 2011 12:14 pm
by maik
Added it to the [wiki]OXP List[/wiki].

Re: Naval Grid OXP

Posted: Tue Jan 10, 2012 7:03 pm
by m4r35n357
I have been messing around with some, er, "aggressive" settings, and have come up with the following (with apologies to Thargoid for changing the logic a bit . . .)

It should auto-tune to most ships that it can be used on, I think. Just replace the current shieldCheck function with the following two (I could have nested the boost function but I wanted to play!)

Do with this as you will . . . .

Code: Select all

this.$boostShield = function (shield, maxShield) {
	var deficit = maxShield - shield;
	if (deficit > this.strength) {
		shield += this.strength;
		player.ship.energy -= this.strength;						
        } else {
		shield += deficit;
		player.ship.energy -= deficit;
	}
	return shield
}

this.shieldCheck = function () {
	this.strength = player.ship.maxEnergy / 16;
	
	if (player.ship.equipmentStatus("EQ_NAVAL_SHIELD_BOOSTER") !== "EQUIPMENT_OK" || player.ship.equipmentStatus("EQ_NAVAL_ENERGY_UNIT") !== "EQUIPMENT_OK") {
		player.consoleMessage("Naval Grid damaged and offline", 4);
		player.ship.setEquipmentStatus("EQ_NAVAL_GRID", "EQUIPMENT_DAMAGED");
		if (this.shieldCheckTimer) {
			this.shieldCheckTimer.stop();
		}
		return
	}
	
	if (player.ship.docked || player.ship.equipmentStatus("EQ_NAVAL_GRID") !== "EQUIPMENT_OK") {
		this.shieldCheckTimer.stop(); 
		return
	}

	if (player.ship.energy < player.ship.maxEnergy / 4) {
		return
	} else if ((player.ship.forwardShield < player.ship.maxForwardShield) || (player.ship.aftShield < player.ship.maxAftShield)) {
		if ((player.ship.maxForwardShield - player.ship.forwardShield) < (player.ship.maxAftShield - player.ship.aftShield)) {
			player.ship.aftShield = this.$boostShield(player.ship.aftShield, player.ship.maxAftShield);
		} else {
			player.ship.forwardShield = this.$boostShield(player.ship.forwardShield, player.ship.maxForwardShield);
		}
	}
}

Re: Naval Grid OXP

Posted: Tue Jun 02, 2015 2:17 pm
by Lone_Wolf
Interesting approach, m4r35n357 .
I'll look into using for next version.

One of the drawbacks of naval grid is that it needs the naval energy unit to be installed.
Getting a pilot to the point where they can buy NEU takes a lot of time.
(personally i work around that by looking in shipyards for the ship i fly, but with the NEU)

A less capable version of naval grid that requires mil Shields could solve that.
Would such a version be a good idea ?

Re: Naval Grid OXP

Posted: Thu Jun 04, 2015 4:24 am
by Cmdr Wyvern
Lone_Wolf wrote:
One of the drawbacks of naval grid is that it needs the naval energy unit to be installed.
Getting a pilot to the point where they can buy NEU takes a lot of time.
(personally i work around that by looking in shipyards for the ship i fly, but with the NEU)

A less capable version of naval grid that requires mil Shields could solve that.
Would such a version be a good idea ?
I looked into that.

In the script, I found this bit of code -

Code: Select all

	if(player.ship.equipmentStatus("EQ_NAVAL_SHIELD_BOOSTER") !== "EQUIPMENT_OK" || player.ship.equipmentStatus("EQ_NAVAL_ENERGY_UNIT") !== "EQUIPMENT_OK")
		{ // as this.equipmentDamaged doesn't fire in this kind of script?
		player.consoleMessage("Naval Grid damaged and offline", 4);
		player.ship.setEquipmentStatus("EQ_NAVAL_GRID", "EQUIPMENT_DAMAGED");
		if(this.shieldCheckTimer) { this.shieldCheckTimer.stop(); }
		return;
		}
- and removed it. That code snip checks for the military shield and NEU; without it, the grid works on the Jameson's startup naked Cobra just fine.

Then I changed it's equipment.plist.

Code: Select all

(
	(
	8, 
	10000, 
	"Energy Grid", 
	"EQ_NAVAL_GRID", 
	"Smart-switching energy grid for enhanced shields and energy management. Upgraded flow supports faster shield recharging.", 
		{
		"available_to_all" = yes;
		script = "milGrid_script.js";	
		}
	)
)	
Making it competitive as a choice tween the grid and the mk1 energy unit.

Then for a test, I put it on a startup Cobra and did a little pirate fighting.

Results: Normally, A Jameson would be whupped badly if not blown out of the sky by a pack of 3 to 4 pirates. Putting the grid on a startup ship improves chances of survival a little bit, but with a hefty demand on the energy banks. IMHO, From there, odds improve along the normal upgrade path - of course.

Re: Naval Grid OXP

Posted: Sat Jun 06, 2015 12:58 pm
by Lone_Wolf
Thanks for checking that, Cmdr Wyvern .

Assuming energy is above 64 ( 1 bank), naval grid adds 1 to fwd & aft shield strength 4 times a second (and subtracts 1 from energy).
This can amount to subtracting 8 energy every second if both shields need a boost.
That's higher then the energy recharge speed of the startup cobra.

Looks like we need a more dynamic way.

How about this :

If energy is below 25% of max, grid does nothing ( for the cobra3 this equals 64) .

3 devices ( all conflict with eachother so you can only have 1 installed) :

standard grid :
TL 8 , price 1000
Never adds more then 30% of energy rechargy rate per shield
basic cobra3 has energy recharge rate of 4, so gives 1.2


advanced grid :
requires & provides EEU
TL 10, price 2500
adds max 35% of energy recharge rate per shield
Cobra3 + EEU have energy recharge of 4 * 1.8 = 7.2, so gives 2.4 max

Naval grid
Requires & provides NEU, conflicts with standard & advanced grid
TL 14 , price 65000
add 39% of ship energy recharge rate
Cobra3 + NEU have 4 * 2.6 = 10.4 , so gives max 4.056

Not sure if basic grid and standard grid are good enough, will require testing.

Re: Naval Grid OXP

Posted: Sun Jun 07, 2015 10:06 am
by Lone_Wolf
After thinking about things, i've decided it's better to make Naval Grid more dynamic, switch to a conditions script and adapt the code to my own style before adding new devices.

Re: Naval Grid OXP

Posted: Thu Aug 20, 2015 12:39 am
by Lone_Wolf
I have thought more about naval grid, and now feel it's best to use the r/w property of shield recharge rate so the core game code will handle the recharging of shields.

I'm currently thinking of 2 devices , a standard one that will require EEU and a naval version that will require NEU.

The available room to recharge shield will be calculated like this :
room = multiplier * .9 * energyRechargeRate - ( forwardShieldRechargeRate+ aftShieldRechargeRate )
The .9 will ensure there's always some energy recharge left for other purposes.

The multiplier will cycle from 0 to max probably with steps of 25% and be settable through n , with b setting it to max (useful when fleeing).

The effective room will be divided between fwd & aft shield based on the ratio of their shield recharge rates.

The standard device could have a max of 75% , while the naval version could go up to 100% .

Please voice your thoughts about this approach.

Re: Naval Grid OXP

Posted: Thu Aug 20, 2015 10:39 am
by Norby
Lone_Wolf wrote:
room = multiplier * .9 * energyRechargeRate - ( forwardShieldRechargeRate+ aftShieldRechargeRate )
You need one more parenthesis around rates.

I do not think there is a point to make this equipment adjustable due to better if all energy go into the shields to defend the internal equipments until the last bank is filled, moreover another primeable equipment is not the best in red alert.

A single device is enough if the formula contain energyRechargeRate, this is already higher with NEU than EEU. So imho:

Code: Select all

room = .9 * ( energyRechargeRate - ( forwardShieldRechargeRate + aftShieldRechargeRate ) )

Re: Naval Grid OXP

Posted: Thu Aug 20, 2015 12:24 pm
by Lone_Wolf
The formulae was indeed missing those parenthesis.

Currently Naval Grid is already primable (n basically shows a status message) , although i doubt many people use it.

I do agree technically it's possible to have 1 device, but Thargoid set naval grid to a very high price and require NEU on purpose.

I would like to keep as much as possible of those intentions in the oxp.

How about removing the primable part, but give the standard device a lower multiplier then the naval version ?
The Naval grid would then become an upgrade to the standard version (which conflicts with NEU).


Handwavium : The standard version is dimensioned to work with the EEU and would just burn out when having to deal with the massive amount of available recharge enegy supplied by the NEU.

Re: Naval Grid OXP

Posted: Thu Aug 20, 2015 3:21 pm
by Norby
Lone_Wolf wrote:
How about removing the primable part, but give the standard device a lower multiplier then the naval version ?
Ok, your handwavium is very reasonable.

Re: Naval Grid OXP

Posted: Fri Aug 21, 2015 12:04 pm
by Lone_Wolf
I've looked deeper and found several potential problems .

- Core game has 2 devices that influence shield recharge : Shield Boosters & Mil Shields
Both use a multiplier while my devices are intended to use an additive change.
My changes are intend to be applied AFTER shield booster / mil shield changes have been applied.
This means that if shield booster / mil shield get added or removed, i will have to :
revert the additive change
apply the change from shield booster/ mil shiels
calculate a new additive value

- The value used by my devices will also need to be recalculated if EEU or NEU get added/removed

- devices from other oxps could also change shield recharge and/or energy recharge. again I will have to recalculate energy grid values for these.

Basically i will have to atleast replace core equipmentAdded , equipmentDamaged , equipmentRepaired & equipementRemoved handlers by my own handler for every device that changes shield recharge and/or energy recharge.

Ofcourse there's an easy alternative : my devices could also use a multiplier instead of an additive.

Thargoid did his best to only apply naval grid boost if there was enough energy.

My personal feeling is that an additive shield recharge change that makes sure there's energy left for other things is much closer to his approach then using a mulitplicative change.

Re: Naval Grid OXP

Posted: Sat Aug 22, 2015 12:43 am
by Lone_Wolf
The problems were easier to solve then i had expected, i now have a 1.10 WIP version that needs playtesting.

Some numbers :
Cobra3 + EEU + Shield Boosters + energy grid gives .8 extra shield charge PER shield , or 2.8 total
Cobra3 + NEU + Shield Boosters + Naval grid gives 3.3 extra per shield or 5.3 total
Cobra3 + NEU + Mil Shields + Naval grid gives 2.07 extra per shield or 5.07 total
FDL 3G +t , NEU, Mil shields, Naval Grid gives 3.2085 , total 6.2085
Caduceus alpha, NEU, Mil Shields, Naval Grid : 4.086 , total 7.086

For most ships this number is lower then the potential increase ( 4 + 4 ) of the old naval grid, but that potential value was rarely achieved due to the huge drain on the energy banks.

Re: Naval Grid OXP

Posted: Sat Aug 22, 2015 2:58 pm
by Lone_Wolf
Previous upload had several typos, also i simplified the code.

New download : https://app.box.com/s/mkozkxrr3cfypf6n7nhgdra0fw4ur00j


Main script :

Code: Select all

"use strict";
this.name        = "Naval Grid";
this.author	 = "Lone_Wolf";
this.copyright	 = "2015 Lone_Wolf";
this.licence     = "CC-by-SA 4.0";
this.description = "Enhanced shield recharging unit";
this.version	 = "1.10";

this._ng_charging_devices = 
  [
    "EQ_SHIELD_BOOSTER",
    "EQ_NAVAL_SHIELD_BOOSTER",
    "EQ_ENERGY_UNIT",
    "EQ_NAVAL_ENERGY_UNIT"
  ];

this._ng_shield_charge_modifiers = 
  {
    fwd:0,
    aft:0
  };

this._ng_switch_max = 0;

this.startUpComplete = function()
  {
    if ( !player.ship.script ) { player.ship.setScript("oolite-default-ship-script.js"); }; // just in case
    if ( player.ship.equipmentStatus("EQ_ENERGY_GRID") == "EQUIPMENT_OK") 
      { 
        this._ng_switch_max = 0.5;
        this._ng_setup_handlers();
      };
    if ( player.ship.equipmentStatus("EQ_NAVAL_GRID") == "EQUIPMENT_OK")
      { 
        this._ng_switch_max = 0.9;
        this._ng_setup_handlers();
      };
    delete this.startup;
  };

  
this._ng_setup_handlers = function()
  {
    // store existing handlers
    if ( player.ship.script.equipmentAdded ) { player.ship.script._ng_player_equipmentAdded_original = player.ship.script.equipmentAdded; };
    if ( player.ship.script.equipmentRemoved ) { player.ship.script._ng_player_equipmentRemoved_original = player.ship.script.equipmentRemoved; };
    // set new handlers
    var new_player_equipmentAdded = function(eqkey)
      {
        worldScripts["Naval Grid"]._ng_equipment(eqkey, player.ship.script._ng_player_equipmentAdded_original ); 
      };
    var new_player_equipmentRemoved = function(eqkey)
      {
        worldScripts["Naval Grid"]._ng_equipment(eqkey, player.ship.script._ng_player_equipmentRemoved_original ); 
      };
    player.ship.script.equipmentAdded = new_player_equipmentAdded;
    player.ship.script.equipmentRemoved = new_player_equipmentRemoved;
  };

this._ng_player_equipment = function (eqkey, original_handler)
  {
    // avoiding "this.xxx" cause function will be called as a method of player.ship.script
    // only act if STATUS_IN_FLIGHT
    if ( player.ship.status != STATUS_IN_FLIGHT ) { original_handler(eqkey); return };
    // verify if added/removed device influences NG modifiers
    if ( worldScripts["Naval Grid"]._ng_charging_devices.indexOf(eqkey) == -1 ) { original_handler(eqkey); return };
    // revert ng modifiers
    worldScripts["Naval Grid"]._ng_player_modifiers("revert");
    // apply original handler for device
    original_handler(eqkey);
    worldScripts["Naval Grid"]._ng_player_modifiers( "apply");
  };

this._ng_player_modifiers = function(type)
  {
    // type = string
    //   apply = add values
    //   revert = subtract values
    // verify if energy grid or naval grid are present and undamaged
    if ( this._ng_switch_max == 0 ) return;
    var rates =
      { 
        fwd: player.ship.forwardShieldRechargeRate,
        aft: player.ship.aftShieldRechargeRate,
        energy: player.ship.energyRechargeRate,
        switch_max: this._ng_switch_max
      };
    var modifiers = { fwd: 0,aft: 0 };
    modifiers = this._ng_calc_modifiers(rates);
    switch ( type )
      {
        case "apply":
          player.ship.forwardShieldRechargeRate += modifiers.fwd;
          player.ship.aftShieldRechargeRate += modifiers.fwd;
          break;
        case "revert":
          player.ship.forwardShieldRechargeRate -= modifiers.fwd;
          player.ship.aftShieldRechargeRate -= modifiers.fwd;
          break;
        default:
          break;
      };
  };
  
this._ng_calc_modifiers = function(charge_rates)
  {
    /* Input
      object charge_rates = { fwd_charge, aft_charge, energy_charge, switch_max }
    Output
      object = { fwd_modifier, aft_modifier }
    */
    var modifiers = { fwd: 0, aft: 0 };
    var shield_charge = fwd_charge + aft_charge;
    charge_room = switch_max * ( energy_charge - shield_charge );
    modifiers.fwd = (fwd_charge / shield_charge) * charge_room;
    modifiers.aft = (aft_charge / shield_charge) * charge_room;
    return modifiers;
  };

Re: Naval Grid OXP

Posted: Sat Aug 22, 2015 4:24 pm
by Norby
Nice work. The normal Energy Grid for 2500cr is a good help in the early-midgame imho.