Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Damaging Shield Boosters restores players energy

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4726
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Damaging Shield Boosters restores players energy

Post by phkb »

I'm not sure if this is by-design, but when the Shield Boosters (EQ_SHIELD_BOOSTER) are damaged and the player's energy level is less than the maximum energy level (player.ship.energy < player.ship.maxEnergy), then their energy level is returns to the maximum amount.

I tested this with no OXP's installed (via the AddOns folder or via the in-built download manager) by hitting the ECM multiple times to reduce my energy level to about half. I then executed this snippet of code:

Code: Select all

player.ship.setEquipmentStatus("EQ_SHIELD_BOOSTER", "EQUIPMENT_DAMAGED");
My tests were all performed with EQ_NAVAL_SHIELD_BOOSTER, EQ_ENERGY_UNIT and EQ_NAVAL_ENERGY_UNIT installed as well. Not sure if those are related. I'll test without them later today.

So, not sure if this is a bug or not, but if someone else can test out the scenarios that would be helpful!
User avatar
CWolf
---- E L I T E ----
---- E L I T E ----
Posts: 317
Joined: Mon Jul 03, 2006 12:33 pm
Location: Currently floating round Eninre

Re: Damaging Shield Boosters restores players energy

Post by CWolf »

It could be circuit feedback - the power is no longer going to the broken boosters so you get feedback from the dedicated capacitors back to the energy banks...
The act of talking b*ll*cks whilst waving one's arms about wildly is referred to as testiculation.

Image
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4726
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Damaging Shield Boosters restores players energy

Post by phkb »

More information: the scenario also applies to the Military Shield Enhancement (EQ_NAVAL_SHIELD_BOOSTER). If that item is damaged when your energy is down, you get a full energy recharge.

I have also tested with all shield and extra energy items removed and confirmed it still happens. So, if all you have is the shield booster, the scenario will kick in.

I have also confirmed that the scenario doesn't kick in when the extra energy unit or Naval energy unit are damaged.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6570
Joined: Wed Feb 28, 2007 7:54 am

Re: Damaging Shield Boosters restores players energy

Post by another_commander »

It's a bug (well done spotting that, by the way). The problem is here in Resources/Scripts/oolite-equipment-control.js, this.$equipmentDisable["EQ_SHIELD_BOOSTER"] = this.$equipmentDisable["EQ_NAVAL_SHIELD_BOOSTER"] function:

Code: Select all

player.ship.maxForwardShield -= parseFloat(info.scriptInfo.oolite_shield_increase);
player.ship.maxAftShield -= parseFloat(info.scriptInfo.oolite_shield_increase);
When the boosters are damaged, the script will set the maximum shield levels to what they would have been without the boosters, but it forgets to check what the actual value of the shields is at the moment of disabling the equipment. So, for a split second, the ship finds itself having forward and/or aft shields higher than what the current post-damage maximum is. This leads to negative energy drain (i.e. energy gain) in the core code, which results in the energy banks instantly filling up. To fix:

Code: Select all

player.ship.maxForwardShield -= parseFloat(info.scriptInfo.oolite_shield_increase);
if (player.ship.forwardShield > player.ship.maxForwardShield)  player.ship.forwardShield = player.ship.maxForwardShield;
player.ship.maxAftShield -= parseFloat(info.scriptInfo.oolite_shield_increase);
if (player.ship.aftShield > player.ship.maxAftShield)  player.ship.aftShield = player.ship.maxAftShield;
The heart of the problem is in the core itself, which allows for negative enrergy drains to occur. However, since the behaviour is easily fixable in the script and there could be OXPs that rely on negative energy drain behaviour in the future, for now I think I'll leave the core alone and just ensure that the maximum shield values are not exceeded via the boosters script.
User avatar
CWolf
---- E L I T E ----
---- E L I T E ----
Posts: 317
Joined: Mon Jul 03, 2006 12:33 pm
Location: Currently floating round Eninre

Re: Damaging Shield Boosters restores players energy

Post by CWolf »

another_commander wrote:
It's a bug.
Keep it in!
Seeing as it only does it with shield boosters I think my explanation fits nicely within the Ooniverse.
The act of talking b*ll*cks whilst waving one's arms about wildly is referred to as testiculation.

Image
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6570
Joined: Wed Feb 28, 2007 7:54 am

Re: Damaging Shield Boosters restores players energy

Post by another_commander »

The core is unchanged, but the fix in the script has already gone in (commit 623f9ef). If you prefer the way it was before, you can just remove the two check lines added in oolite-equipment-control.js and Shift-restart the game.
Post Reply