electric-energy-interface receives more power than possible

Place to get help with not working mods / modding interface.
Post Reply
Raeon
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed Jun 22, 2016 8:55 am
Contact:

electric-energy-interface receives more power than possible

Post by Raeon »

Introduction
Hi. I'm writing a mod called Induction Charging. The gist of it is that you add some induction coils to your power armor, and they tap power from whatever power network you are standing in. This is done using an invisible electric-energy-interface at the players position, which will henceforth be referred to as the shadow entity (due to it 'shadowing' the player). Using the amount and positions of coils in the players power armor, along with their forces technology level, I determine how much power they are allowed to receive and configure the shadow entity to only receive that much over the next [tickrate] ticks.

Note that throughout the data about to follow, the buffer size of the shadow entity is set to exactly twice the amount it actually needs to be. The reason for this is so we can see exactly how much power we are drawing.
The problem
Consider scrolling down to the demo first!

The issue is in principle quite simple: I'm receiving more power than the input flow rate multiplied by the amount of ticks that have passed. In my (so far fruitless) efforts to figure out what this problem is, I wrote a small CSV-generating utility to dump most of the variables I use every tick. See the following image for the data I collected:

Image

In the image above you see a recorded timeframe of 6.75 real-time seconds, or 405 ticks, or 27 updates for my mod. During this timeframe I add a single induction coil to my power armor.

The columns are as defined as follows:
  • tick is the current game tick
  • player is the name of the player being updated
  • 1_energy is the shadow.energy field (before we do anything)
  • 1_buffer is the shadow.electric_buffer_size field (before we do anything)
  • 1_flow is the shadow.electric_input_flow_limit field (before we do anything)
  • received is the same as 1_energy, but at a different place in the code
  • capacity is the total energy capacity of all batteries in the users power armor equipment grid
  • requested is how much energy we requested from the shadow entity the last time we updated.
  • receive% is (received / requested) as a percentage.
  • throughput is the total throughput that the players equipment grid allows.
  • efficiency% is the efficiency of the players current technological level (requested/received are divided and multiplied respectively by this value)
  • 2_energy is the value we assign to the shadow.energy field
  • 2_buffer is the value we assign to the shadow.electric_buffer_size field
  • 2_flow is the value we assign to the shadow.electric_input_flow_limit field
The real problem
See the following calculations:

Code: Select all

tickrate
    = (90345 - 90330)
    = 15 ticks
expected received energy over [tickrate] ticks
    = 15 * [1_flow]
    = 15 * 280,800
    = 4,212,000 J
which is identical to the [requested] column in the first several rows. This is correct and intended.

At a later time however (from tick 90465 onwards), when I add one more induction coil to the power armor which increases the requested energy, the following happens:

Code: Select all

expected received energy over [tickrate] ticks
    = 15 * [1_flow]
    = 15 * 294,400
    = 4,416,000 J
However, instead of this expected amount we suddenly get

Code: Select all

received power per [tickrate] ticks = 8,736,000 J
which is a lot more than the input flow limit that I set the shadow entity to should allow to be transferred in [tickrate] ticks.
Demo
Here is the entire problem in a nutshell:


Transcribed:
  • I load the "Testing" savefile
  • I empty one battery to make sure the coils are active
  • I walk into range of a power network
  • I highlight that the receive% is at 100% (expected levels)
  • I add one induction coil to my power armor
  • I empty the battery again to make sure the coils are active
  • I highlight the suddenly very high receive% of 197.83%
Reproducing
Attached you will find the savefile and mod. Put the "Testing.zip" in your saves directory and the mod in your "mods" directory. Enable ONLY my mod before loading the save file. Following the instructions described above you should be able to reproduce my results. Typing a message in the ingame chat will dump the CSV data to /script-output/csv/output.csv. (Note that it can not dump if the file is open in another program, e.g. Microsoft Excel).
The question
What am I dealing with here? Am I doing something severely wrong, or is this perhaps a bug? And how would I fix it? Thanks for reading :)
Attachments
Testing.zip
(3.41 MiB) Downloaded 74 times
Induction Charging_1.2.0.zip
(43 KiB) Downloaded 57 times

Post Reply

Return to “Modding help”