Powernets now tracks load added between power ticks. (#40216)

* Powernet non-machine processing changes.

* forgot an =

* Reverts floodlight changes.

* Clamps surplus() to valid values.
This commit is contained in:
skoglol
2018-09-14 13:05:21 +02:00
committed by AnturK
parent da869cb780
commit 817c9c0ffc
9 changed files with 58 additions and 14 deletions
+1 -1
View File
@@ -86,7 +86,7 @@
if(!active)
return
if(surplus() > 1500)
if(surplus() >= 1500)
add_load(1500)
if(cooldown <= world.time)
cooldown = world.time + 80
+4 -2
View File
@@ -122,8 +122,8 @@
// found a powernet, so drain up to max power from it
var/drained = min ( drain_rate, PN.avail )
PN.load += drained
var/drained = min ( drain_rate, attached.newavail() )
attached.add_delayedload(drained)
power_drained += drained
// if tried to drain more than available on powernet
@@ -137,6 +137,8 @@
power_drained += 50
if(A.charging == 2) // If the cell was full
A.charging = 1 // It's no longer full
if(drained >= drain_rate)
break
if(power_drained > max_power * 0.98)
if (!admins_warned)
+2 -2
View File
@@ -270,8 +270,8 @@
var/obj/structure/cable/C = T.get_cable_node()
if(C)
playsound(src, 'sound/magic/lightningshock.ogg', 100, 1, extrarange = 5)
tesla_zap(src, 3, C.powernet.avail * 0.01, TESLA_MOB_DAMAGE | TESLA_OBJ_DAMAGE | TESLA_MOB_STUN | TESLA_ALLOW_DUPLICATES) //Zap for 1/100 of the amount of power. At a million watts in the grid, it will be as powerful as a tesla revolver shot.
C.powernet.load += C.powernet.avail * 0.0375 // you can gain up to 3.5 via the 4x upgrades power is halved by the pole so thats 2x then 1X then .5X for 3.5x the 3 bounces shock.
tesla_zap(src, 3, C.newavail() * 0.01, TESLA_MOB_DAMAGE | TESLA_OBJ_DAMAGE | TESLA_MOB_STUN | TESLA_ALLOW_DUPLICATES) //Zap for 1/100 of the amount of power. At a million watts in the grid, it will be as powerful as a tesla revolver shot.
C.add_delayedload(C.newavail() * 0.0375) // you can gain up to 3.5 via the 4x upgrades power is halved by the pole so thats 2x then 1X then .5X for 3.5x the 3 bounces shock.
return ..()
/obj/structure/grille/get_dumping_location(datum/component/storage/source,mob/user)
+2 -2
View File
@@ -169,8 +169,8 @@ They *could* go in their appropriate files, but this is supposed to be modular
drain = (round((rand(G.mindrain, G.maxdrain))/2))
var/drained = 0
if(PN && do_after(H,10, target = src))
drained = min(drain, PN.avail)
PN.load += drained
drained = min(drain, delayed_surplus())
add_delayedload(drained)
if(drained < drain)//if no power on net, drain apcs
for(var/obj/machinery/power/terminal/T in PN.nodes)
if(istype(T.master, /obj/machinery/power/apc))
+1 -1
View File
@@ -1104,7 +1104,7 @@
/obj/machinery/power/apc/add_load(amount)
if(terminal && terminal.powernet)
terminal.powernet.load += amount
terminal.add_load(amount)
/obj/machinery/power/apc/avail()
if(terminal)
+21 -1
View File
@@ -199,6 +199,10 @@ By design, d1 is the smallest direction and d2 is the highest
// Power related
///////////////////////////////////////////
// All power generation handled in add_avail()
// Machines should use add_load(), surplus(), avail()
// Non-machines should use add_delayedload(), delayed_surplus(), newavail()
/obj/structure/cable/proc/add_avail(amount)
if(powernet)
powernet.newavail += amount
@@ -209,7 +213,7 @@ By design, d1 is the smallest direction and d2 is the highest
/obj/structure/cable/proc/surplus()
if(powernet)
return powernet.avail-powernet.load
return CLAMP(powernet.avail-powernet.load, 0, powernet.avail)
else
return 0
@@ -219,6 +223,22 @@ By design, d1 is the smallest direction and d2 is the highest
else
return 0
/obj/structure/cable/proc/add_delayedload(amount)
if(powernet)
powernet.delayedload += amount
/obj/structure/cable/proc/delayed_surplus()
if(powernet)
return CLAMP(powernet.newavail - powernet.delayedload, 0, powernet.newavail)
else
return 0
/obj/structure/cable/proc/newavail()
if(powernet)
return powernet.newavail
else
return 0
/////////////////////////////////////////////////
// Cable laying helpers
////////////////////////////////////////////////
+22 -2
View File
@@ -25,6 +25,10 @@
//////////////////////////////
// common helper procs for all power machines
// All power generation handled in add_avail()
// Machines should use add_load(), surplus(), avail()
// Non-machines should use add_delayedload(), delayed_surplus(), newavail()
/obj/machinery/power/proc/add_avail(amount)
if(powernet)
powernet.newavail += amount
@@ -38,7 +42,7 @@
/obj/machinery/power/proc/surplus()
if(powernet)
return powernet.avail - powernet.load
return CLAMP(powernet.avail-powernet.load, 0, powernet.avail)
else
return 0
@@ -48,6 +52,22 @@
else
return 0
/obj/machinery/power/proc/add_delayedload(amount)
if(powernet)
powernet.delayedload += amount
/obj/machinery/power/proc/delayed_surplus()
if(powernet)
return CLAMP(powernet.newavail - powernet.delayedload, 0, powernet.newavail)
else
return 0
/obj/machinery/power/proc/newavail()
if(powernet)
return powernet.newavail
else
return 0
/obj/machinery/power/proc/disconnect_terminal() // machines without a terminal will just return, no harm no fowl.
return
@@ -341,7 +361,7 @@
source_area.use_power(drained_energy/GLOB.CELLRATE)
else if (istype(power_source, /datum/powernet))
var/drained_power = drained_energy/GLOB.CELLRATE //convert from "joules" to "watts"
PN.load+=drained_power
PN.delayedload += (min(drained_power, max(PN.newavail - PN.delayedload, 0)))
else if (istype(power_source, /obj/item/stock_parts/cell))
cell.use(drained_energy)
return drained_energy
+3 -1
View File
@@ -13,6 +13,7 @@
var/viewavail = 0 // the available power as it appears on the power console (gradually updated)
var/viewload = 0 // the load as it appears on the power console (gradually updated)
var/netexcess = 0 // excess power on the powernet (typically avail-load)///////
var/delayedload = 0 // load applied to powernet between power ticks.
/datum/powernet/New()
SSmachines.powernets += src
@@ -88,7 +89,8 @@
viewload = round(0.8 * viewload + 0.2 * load)
// reset the powernet
load = 0
load = delayedload
delayedload = 0
avail = newavail
newavail = 0
+2 -2
View File
@@ -160,7 +160,7 @@
update_icon()
return
if(active == TRUE)
if(!active_power_usage || avail(active_power_usage))
if(!active_power_usage || surplus() >= active_power_usage)
add_load(active_power_usage)
if(!powered)
powered = TRUE
@@ -189,7 +189,7 @@
return FALSE
if(state != EMITTER_WELDED)
return FALSE
if(avail(active_power_usage))
if(surplus() >= active_power_usage)
add_load(active_power_usage)
fire_beam()