OCB7D2D / OcbElectricityOverhaul

OCB Electricity Overhaul - 7 Days to Die (V1.0) Addon
https://www.nexusmods.com/7daystodie/mods/1713
15 stars 3 forks source link

Phantom charging. #2

Closed Shadow-Genesis closed 2 years ago

Shadow-Genesis commented 2 years ago

If you connect a battery bank to a parent power source such as a generator, and set the batter bank to not charge from the generator, the bank will still charge. This can be repeated with the solar panel as well, but the solar ONLY does it during the day.

My wiring setup used in my test. Only using one panel, generator, and battery bank. (Top Level) Solar Panel, six level six cells -> (Second Level) Generator Bank, six engines -> (Third Level) Battery Bank, six level six batteries -> (Fourth Level) Array of Auto Turrets(16 total), for load.

After placing all the blocks down and filling them with their required items, I wired the battery bank to the auto turrets first, in series, turning on each gun as I do. Then from the solar panel to the generator, and from there to the battery bank, note at this time neither of the solar or generator was turned on, but filled with their items to run. Once wiring was done, I turned on the battery bank to supply power to the load, Auto Turrets(16 total), and drain the batteries down. Battery state of charge can be read as a number by the sell price of the battery, my case a full level six battery was 1000 Dukes. Once the battery was drained a bit, I then made sure to turn off charging from both solar and generator inside the battery bank. When the sell price of the battery reached a low enough value, 900-950 Dukes, I turned on either the solar panel or generator bank. The parent power source, solar/generator, showed taking over the load(s) with no charging load(s). The battery bank showed the load being passed through and not charging. Now looking at the battery's sell price again, it showed that a rising sell price, as it does when charging.

Please note the phantom charging does not happen with the solar panel at night, I think this is due to the panel only having power during the day.

I'm not an expert in software code, but after looking over the code in the Harmony/ocbElectricityManager.cs file I believe the cause is in there under the function "public ushort BorrowPower" line 364, 381, 385. The if statement used "if (battery != null && !battery.ChargeFromSolar)" , using line 364, askes if the battery exist and if NOT to ChargeFromSolar, If ChargeFromSolar is FALSE as it askes for to continue and charge. This doesn't make sense to me.

while (enumerator.MoveNext()) { PowerSource lender = enumerator.Current; if (!lender.isOn) continue; if (!(lender is PowerSolarPanel)) continue; if (battery != null && !battery.ChargeFromSolar) continue; ushort distributing = distribute; BorrowPowerFromSource(lender, ref distribute, battery); AccountPowerUse(lender, (ushort)(distributing - distribute), battery); if (distribute == 0) break; i++; }

mgreter commented 2 years ago

Thanks for the detailed report (actually the first after many "doesn't work" reports). First glad you got it working and since I added the options to charge from specific sources pretty recently there is a chance I missed some things when testing it. Not sure when I'll have time to investigate further, but at least you gave me a good reproduction case. Will report here when there is news.

Edit: Was able to reproduce it, which is always a good first step regarding a fix...

mgreter commented 2 years ago

Could you retry with latest master? https://github.com/OCB7D2D/ElectricityOverhaul/archive/master.zip Make sure to only load one mod (the directory from github download is different) You may also just replace the dll (as it's the only relevant file)...

mgreter commented 2 years ago

I believe this is fixed, re-open if you disagree.

Shadow-Genesis commented 2 years ago

I retry with the github version, and it works great now. Everything charges when it is set to. Also great response time. Felt like I posted yesterday about it, and its fixed.