Replaces add_load with draw_power. Issue about silly battery handling remains. Fixes the build-error.

This commit is contained in:
PsiOmega
2014-10-15 10:25:28 +02:00
parent 1cabbbf5a6
commit 3a7066c6c1
7 changed files with 16 additions and 32 deletions

View File

@@ -273,7 +273,6 @@
master.used_environ = 0 master.used_environ = 0
/area/proc/use_power(var/amount, var/chan) /area/proc/use_power(var/amount, var/chan)
switch(chan) switch(chan)
if(EQUIP) if(EQUIP)
master.used_equip += amount master.used_equip += amount

View File

@@ -1040,9 +1040,10 @@
else else
return 0 return 0
/obj/machinery/power/apc/add_load(var/amount) /obj/machinery/power/apc/draw_power(var/amount)
if(terminal && terminal.powernet) if(terminal && terminal.powernet)
terminal.powernet.load += amount return terminal.powernet.draw_power(amount)
return 0
/obj/machinery/power/apc/avail() /obj/machinery/power/apc/avail()
if(terminal) if(terminal)
@@ -1057,20 +1058,10 @@
if(!area.requires_power) if(!area.requires_power)
return 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_light = area.usage(LIGHT)
lastused_equip = area.usage(EQUIP) lastused_equip = area.usage(EQUIP)
lastused_environ = area.usage(ENVIRON) lastused_environ = area.usage(ENVIRON)
area.clear_usage() // area.clear_usage()
lastused_total = lastused_light + lastused_equip + lastused_environ lastused_total = lastused_light + lastused_equip + lastused_environ
@@ -1100,17 +1091,14 @@
cell.use(cellused) cell.use(cellused)
if(excess > lastused_total) // if power excess recharge the cell if(excess > lastused_total) // if power excess recharge the cell
// by the same amount just used var/actual_gain = draw_power(cellused/CELLRATE) // add the load used to recharge the cell
cell.give(cellused) cell.give(actual_gain) // by the same amount just used
add_load(cellused/CELLRATE) // add the load used to recharge the cell
else // no excess, and not enough per-apc 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? 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 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 charging = 0
else // not enough power available to run the last tick! 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 if(excess > 0) // check to make sure we have enough to charge
// Max charge is capped to % per second constant // Max charge is capped to % per second constant
var/ch = min(excess*CELLRATE, cell.maxcharge*CHARGELEVEL) var/ch = min(excess*CELLRATE, cell.maxcharge*CHARGELEVEL)
add_load(ch/CELLRATE) // Removes the power we're taking from the grid var/actual_charge = draw_power(ch/CELLRATE) // Removes the power we're taking from the grid
cell.give(ch) // actually recharge the cell cell.give(actual_charge) // actually recharge the cell
else else
charging = 0 // stop charging charging = 0 // stop charging

View File

@@ -241,7 +241,7 @@
if(terminal) if(terminal)
if(chargemode) if(chargemode)
var/target_load = min((capacity-charge)/SMESRATE, chargelevel) // charge at set rate, limited to spare capacity 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 charge += actual_load * SMESRATE // increase the charge
if (actual_load >= target_load) // did the powernet have enough power available for us? if (actual_load >= target_load) // did the powernet have enough power available for us?
@@ -249,10 +249,6 @@
else else
charging = 0 charging = 0
else
if (chargemode && excess > 0 && excess >= chargelevel)
charging = 1
if(online) // if outputting if(online) // if outputting
lastout = min( charge/SMESRATE, output) //limit output to that stored lastout = min( charge/SMESRATE, output) //limit output to that stored
charge -= lastout*SMESRATE // reduce the storage (may be recovered in /restore() if excessive) charge -= lastout*SMESRATE // reduce the storage (may be recovered in /restore() if excessive)

View File

@@ -28,7 +28,7 @@
if(powernet) if(powernet)
powernet.newavail += amount powernet.newavail += amount
/obj/machinery/power/proc/add_load(var/amount) /obj/machinery/power/proc/draw_power(var/amount)
if(powernet) if(powernet)
return powernet.draw_power(amount) return powernet.draw_power(amount)
return 0 return 0

View File

@@ -16,7 +16,7 @@
powernets -= src powernets -= src
/datum/powernet/proc/draw_power(var/amount) /datum/powernet/proc/draw_power(var/amount)
var/draw = min(amount, avail - load, 0) var/draw = between(0, amount, avail - load)
load += draw load += draw
return draw return draw

View File

@@ -105,7 +105,8 @@
return return
if(((src.last_shot + src.fire_delay) <= world.time) && (src.active == 1)) 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) if(!powered)
powered = 1 powered = 1
update_icon() update_icon()

View File

@@ -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. //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) if(chargemode)
var/target_load = min((capacity-charge)/SMESRATE, chargelevel) // charge at set rate, limited to spare capacity 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 charge += actual_load * SMESRATE // increase the charge
if (actual_load >= target_load) // did the powernet have enough power available for us? if (actual_load >= target_load) // did the powernet have enough power available for us?
@@ -174,7 +174,7 @@
return 1 return 1
/obj/machinery/power/smes/add_load(var/amount) /obj/machinery/power/smes/draw_power(var/amount)
if(terminal && terminal.powernet) if(terminal && terminal.powernet)
return terminal.powernet.draw_power(amount) return terminal.powernet.draw_power(amount)
return 0 return 0