Ports more of /tg/'s powernet code.

Among other things this fixes a a bug where SMES would draw excess power from the powergrid they were outputting to, rather than drawing from.
This commit is contained in:
PsiOmega
2014-10-29 14:00:11 +01:00
parent c8e27555b9
commit a1c19b78be
14 changed files with 204 additions and 278 deletions

View File

@@ -274,8 +274,6 @@ datum/controller/game_controller/proc/process_diseases()
datum/controller/game_controller/proc/process_machines()
process_machines_sort()
process_machines_process()
process_machines_power()
process_machines_rebuild()
/var/global/machinery_sort_required = 0
datum/controller/game_controller/proc/process_machines_sort()
@@ -284,49 +282,14 @@ datum/controller/game_controller/proc/process_machines_sort()
machines = dd_sortedObjectList(machines)
datum/controller/game_controller/proc/process_machines_process()
var/i = 1
while(i<=machines.len)
var/obj/machinery/Machine = machines[i]
if(Machine)
last_thing_processed = Machine.type
if(Machine.process() != PROCESS_KILL)
if(Machine)
i++
continue
machines.Cut(i,i+1)
datum/controller/game_controller/proc/process_machines_power()
var/i=1
while(i<=active_areas.len)
var/area/A = active_areas[i]
if(A.powerupdate && A.master == A)
A.powerupdate -= 1
A.clear_usage()
for(var/j = 1; j <= A.related.len; j++)
var/area/SubArea = A.related[j]
for(var/obj/machinery/M in SubArea)
if(M)
//check if the area has power for M's channel
//this will keep stat updated in case the machine is moved from one area to another.
M.power_change(A) //we've already made sure A is a master area, above.
if(!(M.stat & NOPOWER) && M.use_power)
M.auto_use_power()
if(A.apc.len && A.master == A)
i++
continue
A.powerupdate = 0
active_areas.Cut(i,i+1)
datum/controller/game_controller/proc/process_machines_rebuild()
if(controller_iteration % 150 == 0 || rebuild_active_areas) //Every 300 seconds we retest every area/machine
for(var/area/A in all_areas)
if(A == A.master)
A.powerupdate += 1
active_areas |= A
rebuild_active_areas = 0
for(var/obj/machinery/Machine in machines)
last_thing_processed = Machine.type
if(Machine.process() != PROCESS_KILL)
if(Machine)
if(Machine.use_power)
Machine.auto_use_power()
continue
machines -= Machine
datum/controller/game_controller/proc/process_objects()