From 3a7066c6c1a18c8f3d4cdcb568eeacf948b38c6f Mon Sep 17 00:00:00 2001 From: PsiOmega Date: Wed, 15 Oct 2014 10:25:28 +0200 Subject: [PATCH] Replaces add_load with draw_power. Issue about silly battery handling remains. Fixes the build-error. --- code/game/area/areas.dm | 1 - code/modules/power/apc.dm | 30 +++++++---------------- code/modules/power/batteryrack.dm | 6 +---- code/modules/power/power.dm | 2 +- code/modules/power/powernet.dm | 2 +- code/modules/power/singularity/emitter.dm | 3 ++- code/modules/power/smes.dm | 4 +-- 7 files changed, 16 insertions(+), 32 deletions(-) diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index b3edbae7872..bc456405223 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -273,7 +273,6 @@ master.used_environ = 0 /area/proc/use_power(var/amount, var/chan) - switch(chan) if(EQUIP) master.used_equip += amount diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index bdb1345f3ee..cb9551b66dd 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -1040,9 +1040,10 @@ else return 0 -/obj/machinery/power/apc/add_load(var/amount) +/obj/machinery/power/apc/draw_power(var/amount) if(terminal && terminal.powernet) - terminal.powernet.load += amount + return terminal.powernet.draw_power(amount) + return 0 /obj/machinery/power/apc/avail() if(terminal) @@ -1057,20 +1058,10 @@ if(!area.requires_power) return - - /* - if (equipment > 1) // off=0, off auto=1, on=2, on auto=3 - use_power(src.equip_consumption, EQUIP) - if (lighting > 1) // off=0, off auto=1, on=2, on auto=3 - use_power(src.light_consumption, LIGHT) - if (environ > 1) // off=0, off auto=1, on=2, on auto=3 - use_power(src.environ_consumption, ENVIRON) - - area.calc_lighting() */ lastused_light = area.usage(LIGHT) lastused_equip = area.usage(EQUIP) lastused_environ = area.usage(ENVIRON) - area.clear_usage() + // area.clear_usage() lastused_total = lastused_light + lastused_equip + lastused_environ @@ -1100,17 +1091,14 @@ cell.use(cellused) if(excess > lastused_total) // if power excess recharge the cell - // by the same amount just used - cell.give(cellused) - add_load(cellused/CELLRATE) // add the load used to recharge the cell - - + var/actual_gain = draw_power(cellused/CELLRATE) // add the load used to recharge the cell + cell.give(actual_gain) // by the same amount just used else // no excess, and not enough per-apc if( (cell.charge/CELLRATE + excess) >= lastused_total) // can we draw enough from cell+grid to cover last usage? cell.charge = min(cell.maxcharge, cell.charge + CELLRATE * excess) //recharge with what we can - add_load(excess) // so draw what we can from the grid + draw_power(excess) // so draw what we can from the grid charging = 0 else // not enough power available to run the last tick! @@ -1159,8 +1147,8 @@ if(excess > 0) // check to make sure we have enough to charge // Max charge is capped to % per second constant var/ch = min(excess*CELLRATE, cell.maxcharge*CHARGELEVEL) - add_load(ch/CELLRATE) // Removes the power we're taking from the grid - cell.give(ch) // actually recharge the cell + var/actual_charge = draw_power(ch/CELLRATE) // Removes the power we're taking from the grid + cell.give(actual_charge) // actually recharge the cell else charging = 0 // stop charging diff --git a/code/modules/power/batteryrack.dm b/code/modules/power/batteryrack.dm index 08d1e652b46..b620f74e2d3 100644 --- a/code/modules/power/batteryrack.dm +++ b/code/modules/power/batteryrack.dm @@ -241,7 +241,7 @@ if(terminal) if(chargemode) var/target_load = min((capacity-charge)/SMESRATE, chargelevel) // charge at set rate, limited to spare capacity - var/actual_load = add_load(target_load) // add the load to the terminal side network + var/actual_load = draw_power(target_load) // add the load to the terminal side network charge += actual_load * SMESRATE // increase the charge if (actual_load >= target_load) // did the powernet have enough power available for us? @@ -249,10 +249,6 @@ else charging = 0 - else - if (chargemode && excess > 0 && excess >= chargelevel) - charging = 1 - if(online) // if outputting lastout = min( charge/SMESRATE, output) //limit output to that stored charge -= lastout*SMESRATE // reduce the storage (may be recovered in /restore() if excessive) diff --git a/code/modules/power/power.dm b/code/modules/power/power.dm index 75328dfd3d5..bde1902af1e 100644 --- a/code/modules/power/power.dm +++ b/code/modules/power/power.dm @@ -28,7 +28,7 @@ if(powernet) powernet.newavail += amount -/obj/machinery/power/proc/add_load(var/amount) +/obj/machinery/power/proc/draw_power(var/amount) if(powernet) return powernet.draw_power(amount) return 0 diff --git a/code/modules/power/powernet.dm b/code/modules/power/powernet.dm index c6e0a12e17d..ab58c76206a 100644 --- a/code/modules/power/powernet.dm +++ b/code/modules/power/powernet.dm @@ -16,7 +16,7 @@ powernets -= src /datum/powernet/proc/draw_power(var/amount) - var/draw = min(amount, avail - load, 0) + var/draw = between(0, amount, avail - load) load += draw return draw diff --git a/code/modules/power/singularity/emitter.dm b/code/modules/power/singularity/emitter.dm index 6958c63d584..4ae6e0b2543 100644 --- a/code/modules/power/singularity/emitter.dm +++ b/code/modules/power/singularity/emitter.dm @@ -105,7 +105,8 @@ return if(((src.last_shot + src.fire_delay) <= world.time) && (src.active == 1)) - if(surplus() >= active_power_usage && add_load(active_power_usage) >= active_power_usage) //does the laser have enough power to shoot? + var/actual_load = draw_power(active_power_usage) + if(actual_load >= active_power_usage) //does the laser have enough power to shoot? if(!powered) powered = 1 update_icon() diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm index 0c2b4639033..c39e922caea 100644 --- a/code/modules/power/smes.dm +++ b/code/modules/power/smes.dm @@ -92,7 +92,7 @@ //TODO: Add a meter to tell players how much charge we are actually getting, and only set charging to 0 when we are unable to get any charge at all. if(chargemode) var/target_load = min((capacity-charge)/SMESRATE, chargelevel) // charge at set rate, limited to spare capacity - var/actual_load = add_load(target_load) // add the load to the terminal side network + var/actual_load = draw_power(target_load) // add the load to the terminal side network charge += actual_load * SMESRATE // increase the charge if (actual_load >= target_load) // did the powernet have enough power available for us? @@ -174,7 +174,7 @@ return 1 -/obj/machinery/power/smes/add_load(var/amount) +/obj/machinery/power/smes/draw_power(var/amount) if(terminal && terminal.powernet) return terminal.powernet.draw_power(amount) return 0