[2.0.47] Shield Regen Wrong Upon Taking damage from Max Shield

Bugs that are actually features.
Loup&Snoop
Inserter
Inserter
Posts: 30
Joined: Wed Dec 04, 2024 4:33 am
Contact:

[2.0.47] Shield Regen Wrong Upon Taking damage from Max Shield

Post by Loup&Snoop »

TL;DR Shields regenerate a large fixed amount for 1 tick if you took damage while at max shields
This may be obnoxious to fix. I have had my suspicions that it is slightly off for a while, and this code confirmed it. It looks like the bug where shields get a very large regen boost for exactly 1 tick if you are at max shield. This boost seems to be roughly 30 ticks worth of regeneration in one tick.

The main experiment does the following: 1) Record the player's current shield total, 2) damage player, 3) report shield values after X ticks.
05-31-2025, 14-45-54.png
05-31-2025, 14-45-54.png (187.44 KiB) Viewed 184 times
This uses 8 normal shield Mk2. The first test call was done at max HP. The second was called while the player was still healing. The main difference is: the 1 tick after the player takes damage, if they were at max shield, they get about +53 shield.
----
05-31-2025, 14-49-25.png
05-31-2025, 14-49-25.png (108.09 KiB) Viewed 184 times
This uses 31 legendary shield Mk2. The first test call was done at max HP. The second was called while the player was still healing. Player seems to gain 170 extra shield on the very next tick, if they were at max shield.

----
Extra note: Charge your shields to the max, then remove all your batteries/electricity from your grid, then take damage. Your shields still get this 1 frame bonus regeneration.

----
Some other measurements, included for completeness, but the above pics are all you need.
Measurements (after 120 ticks of regen):
  • 8 Shield Mk2. Theoretical = 96/s. Actual = 96/s (perfect, measured mid-heal), Actual = 119.2/s (25% higher)
  • 1 Shield Mk1. Theoretical = 12/s. Actual = 12.00/s (perfect measured mid-heal), Actual = 13.64/s (13% higher, measured from max shield)
  • 2 Shield Mk2. Theoretical = 24/s. Actual = 24.0/s (perfect, measured while damage was taken mid-heal), Actual = 29.8/s (24% higher, damage taken from max HP).
  • 20 rare Shield Mk1. Theoretical = 384/s. Actual = 383.99/s (perfect, measured when taking damage mid-heal), Actual = 440.8/s (15% higher, measured from max shield).
  • 1 Legendary shield Mk2. Theoretical = 30/s. actual (measure while healing)= 31.08/s. Actual = 32.75/s (9% higher, from max HP),
  • 31 Legendary shield Mk2. Theoretical = 930/s. Actual = 1015/s (9% higher)
Measurements after 5 ticks of regen:
  • 8 Shield Mk2. Theoretical = 96/s. Actual = 95.9 (measured mid-heal), 652.8/s (measured from being topped off)
  • 31 Legendary shield Mk2. Theoretical = 930/s. Actual = 930/s (mid-heal), 2976/s (measured from being topped off
--------

This sucks to test, so I am providing some of my test code for this. shield-bug.lua is the main test code. I tore the main pieces out from my mod, so these files may not compile, but recycling some code should save you some time.
rubia.timing_manager's one job is to invoke a function X ticks in the future, and my event_lib manages events. I recommend using the raiguardian FLIB if you are more comfortable with that.

Also, this might be more of a modding interface request, but read access to the actual regen of a LuaEquipment would help test these things more accurately.


------
EDIT: If you want to just have the whole mod with the test code active, go get v0.69.47 of https://mods.factorio.com/mod/rubia . The test code is on landing-cutscene.lua at line 660. You should be able to just run the tests by calling this with my mod installed:
/c __rubia__ rubia.testing.test_shield_regen()
I understand if you would rather test in isolation. For that, shield_bug.lua attached with the post would have the main code from which to recycle.
Attachments
timing-manager.lua
(4.34 KiB) Downloaded 10 times
event-lib.lua
(11.31 KiB) Downloaded 8 times
shield_bug.lua
(2.37 KiB) Downloaded 9 times
eugenekay
Filter Inserter
Filter Inserter
Posts: 503
Joined: Tue May 15, 2018 2:14 am
Contact:

Re: [2.0.47] Shield Regen Wrong Upon Taking damage from Max Shield

Post by eugenekay »

According to the Lua Prototype Data the Energy Shield (and Mk2) have an electric “Buffer Capacity” equal to 6 times the “energy per shield”. In your examples, 6hp is healed in the first Tick(per Equipment); so that sure seems like Intended Behaviour? The internal Buffer is exhausted after the first tick of Regeneration, so it then proceeds slower at a speed governed by the input_flow_limit parameter.

The regeneration rate is plainly given in the Prototype as well: you just have to do the Division yourself. ;-)
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5403
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [2.0.47] Shield Regen Wrong Upon Taking damage from Max Shield

Post by Klonan »

eugenekay wrote: Sun Jun 01, 2025 10:40 pm The internal Buffer is exhausted after the first tick of Regeneration, so it then proceeds slower at a speed governed by the input_flow_limit parameter.
From looking at the code, it seems to be the case, and intentional, and configurable in prototype, so all in all I consider this not a bug.

The shield takes as much energy as it can, and converts it into shield points,
In the first tick, the buffer is full so it can take the whole buffer and convert it,
In the subsequent ticks, the buffer is limited by the input flow limit, so converts less per tick
Post Reply

Return to “Not a bug”