[MIRROR] Cell chargers now pull from the grid's surplus rather than their room's APC cell (#1782)

* Cell chargers now pull from the grid's surplus rather than their room's APC cell (#54989)

About The Pull Request

As the title says.

    Creates a new proc, use_power_from_net() that attempts to pull power from the grid (by adding the amount needed to the APC's powernet load), and returns the amount gathered if there was enough surplus to do so. This bypasses the APC's internal cell for power drawn this way.

    Changes cell chargers to use this new proc for charging a cell. The charger machine still uses some power from the APC, set to 1% of it's max cell charging rate, for machine-related power costs. I'm not deadset on that number, I just needed to start with something. To be clear, this 1% is to simulate running the cell charger's circuitry; all of the power for the cell it's charging is 1-to-1 coming from the powernet.

    This does not subvert the original PR's purpose; cells are still drawing as much power from the grid as they charge with.

Why It's Good For The Game

Fixes cell chargers breaking rooms after the prior cell charger fix. The load is now on the grid, and it being surplus means that it (probably) won't actually powersink anything.

Fixes #54919 by taking a different approach that entirely avoids the issue.

* Cell chargers now pull from the grid's surplus rather than their room's APC cell

Co-authored-by: zxaber <37497534+zxaber@users.noreply.github.com>
This commit is contained in:
SkyratBot
2020-11-23 13:34:33 +01:00
committed by GitHub
parent d8ee208afa
commit 3d3dfdc80a
2 changed files with 42 additions and 3 deletions
+34
View File
@@ -118,6 +118,40 @@
local_apc.cell.use(amount)
return TRUE
/**
* Attempts to draw power directly from the APC's Powernet rather than the APC's battery. For high-draw machines, like the cell charger
*
* Checks the surplus power on the APC's powernet, and compares to the requested amount. If the requested amount is available, this proc
* will add the amount to the APC's usage and return that amount. Otherwise, this proc will return FALSE.
* If the take_any var arg is set to true, this proc will use and return any surplus that is under the requested amount, assuming that
* the surplus is above zero.
* Args:
* - amount, the amount of power requested from the Powernet. In standard loosely-defined SS13 power units.
* - take_any, a bool of whether any amount of power is acceptable, instead of all or nothing. Defaults to FALSE
*/
/obj/machinery/proc/use_power_from_net(amount, take_any = FALSE)
if(amount <= 0) //just in case
return FALSE
var/area/home = get_area(src)
if(!home)
return FALSE //apparently space isn't an area
if(!home.requires_power)
return amount //Shuttles get free power, don't ask why
var/obj/machinery/power/apc/local_apc = home?.get_apc()
if(!local_apc)
return FALSE
var/surplus = local_apc.surplus()
if(surplus <= 0) //I don't know if powernet surplus can ever end up negative, but I'm just gonna failsafe it
return FALSE
if(surplus < amount)
if(!take_any)
return FALSE
amount = surplus
local_apc.add_load(amount)
return amount
/obj/machinery/proc/addStaticPower(value, powerchannel)
var/area/A = get_area(src)
if(!A)