RimWorld

RimWorld

Power Tab 2
ọzkriff 30 May, 2023 @ 1:02pm
Sun lamps at night
JFYI that the mod doesn't seem to take sunlamp's night mode period into account:

https://i.imgur.com/hAhWt3f.png
< >
Showing 1-2 of 2 comments
Hedgehog1024 30 May, 2023 @ 1:56pm 
Or, to be more precise, Power Tab 2 shows nominal power comsumption of items, even if it currently consumes no power (like a sun lamp at night).

I am not competent enough to propose a fix, however reading source code reveals a suspicious method GetPowerPlantPotential of class PowerTabUtility (https://github.com/Owlchemist/power-tab-2/blob/0e47dea5f7e0d9754df883e166b88e9440c3277d/Source/PowerTabUtility.cs#L96). If I understand the source code correctly, it temporarily turns sky fully bright, fetches the DesiredPowerOutput of thing in question and restores sky brightness. The return value of GetPowerPlantPotential is later used in DesiredPowerOutput method, which returns the maximum of potential and PowerConsumption od thing in question.

Given that power consumption of sun lamp is dependent on time of day, it likely depends on current sky brightness in order to evaluate it's power conumption. Thus I strongly suspect that GetPowerPlantPotential is a culprit here.

Honestly I don't understand the point of calling Mathf.Max (https://github.com/Owlchemist/power-tab-2/blob/0e47dea5f7e0d9754df883e166b88e9440c3277d/Source/PowerTabUtility.cs#L87). I mean, `.Props.PowerConsumption` is probably an accurate value of current power consumption, so why not just return it directly? However I have no experience of modding Rimworld, so this question might be just due to my incompetence.
Gensando 10 May, 2024 @ 4:56pm 
After some debugging about the possible issue mentioned by @Hedgehog1024 figured out that GetPowerPlantPotential is just used to get max value for solar panels and such for progress bar display purposes.

The problem is that CompPowerTrader.PowerOutput always returns power consumption for sun lamp even if it is night time. Issue was solved by checking PowerOn property of CompPowerTrader
(https://github.com/Owlchemist/power-tab-2/blob/0e47dea5f7e0d9754df883e166b88e9440c3277d/Source/PowerTabUtility.cs#L56)
like this:

if (!(building.GetComp<CompFlickable>()?.SwitchIsOn ?? true)) result = 0; else if (!(building.GetComp<CompPowerTrader>()?.PowerOn ?? true)) result = 0; else { result = building.GetComp<CompPowerTrader>()?.PowerOutput ?? 0; }
Not sure if it is correct way of doing it, but it works for me at least.
Also would be cool if repo was updated with the actual state of the mod.
Last edited by Gensando; 11 May, 2024 @ 2:30am
< >
Showing 1-2 of 2 comments
Per page: 1530 50