From 304d88a4d4d70154a0b140dbbf7acc8a8cf4f786 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Thu, 21 Aug 2014 19:27:12 -0400 Subject: [PATCH] Adds simple load balancing --- code/modules/power/power.dm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/code/modules/power/power.dm b/code/modules/power/power.dm index a1c0a57529e..6c8e6e479d2 100644 --- a/code/modules/power/power.dm +++ b/code/modules/power/power.dm @@ -81,9 +81,7 @@ if(has_power) stat &= ~NOPOWER else - stat |= NOPOWER - return // the powernet datum // each contiguous network of cables & nodes @@ -387,10 +385,13 @@ if( istype( term.master, /obj/machinery/power/apc ) ) numapc++ - if(numapc) - perapc = avail/numapc - netexcess = avail - load + + if(numapc) + //very simple load balancing. If there was a net excess this tick then it must have been that some APCs used less than perapc, since perapc*numapc = avail + //Therefore we can raise the amount of power rationed out to APCs on the assumption that those APCs that used less than perapc will continue to do so. + //If that assumption fails, then some APCs will miss out on power next tick, however it will be rebalanced for the tick after. + perapc = (avail + netexcess)/numapc if( netexcess > 100) // if there was excess power last cycle if(nodes && nodes.len)