APC bugfix after someone messed with mah areas!

This was probably bound to happen either way the previous version was based upon a faulty understanding of how the areas worked this is much more robust and only messes with the master areas
and master areas needing power updates call power updates for the each of it's child areas.  Also added where messing with SMESes called for an update on all areas power consumption, probably
not required but doing so either way.

We also rebuild the active_areas list every 5 minutes, if you get a engineer that wants to build a new area off of the station with APC's set rebuild_all_areas in the master controller and it will
update instantly, otherwise wait 5 minutes.  The only downside to this 5 minutes is you might get free energy until that area becomes active.

Conflicts:
	code/controllers/master_controller.dm
	code/modules/power/apc.dm
This commit is contained in:
Ccomp5950
2014-04-01 03:06:58 -05:00
committed by ZomgPonies
parent 9d45361f9b
commit ceca0ddbe8
5 changed files with 67 additions and 35 deletions

View File

@@ -32,10 +32,13 @@ datum/controller/game_controller
var/total_cost = 0
var/last_thing_processed
var/mob/list/expensive_mobs = list()
var/rebuild_active_areas = 0
datum/controller/game_controller/New()
//There can be only one master_controller. Out with the old and in with the new.
if(master_controller != src)
log_debug("Rebuilding Master Controller")
if(istype(master_controller))
Recover()
del(master_controller)
@@ -176,14 +179,14 @@ datum/controller/game_controller/proc/process()
//MACHINES
timer = world.timeofday
processMachines()
process_machines()
machines_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
//OBJECTS
timer = world.timeofday
processObjects()
process_objects()
objects_cost = (world.timeofday - timer) / 10
sleep(breather_ticks)
@@ -258,26 +261,52 @@ datum/controller/game_controller/proc/process()
Disease.process()
continue
active_diseases -= Disease
/datum/controller/game_controller/proc/processMachines()
for (var/obj/machinery/Machinery in machines)
if (Machinery && Machinery.loc)
last_thing_processed = Machinery.type
if(Machinery.process() != PROCESS_KILL)
if (Machinery) // Why another check?
if (Machinery.use_power)
Machinery.auto_use_power()
datum/controller/game_controller/proc/process_machines()
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)
Machinery.removeAtProcessing()
i=1
while(i<=active_areas.len)
var/area/A = active_areas[i]
if(A.powerupdate && A.master == A)
A.powerupdate -= 1
for(var/area/SubArea in A.related)
for(var/obj/machinery/M in SubArea)
if(M)
if(M.use_power)
M.auto_use_power()
/datum/controller/game_controller/proc/processObjects()
for (var/obj/Object in processing_objects)
if (Object && Object.loc)
if(A.apc.len && A.master == A)
i++
continue
A.powerupdate = 0
active_areas.Cut(i,i+1)
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
datum/controller/game_controller/proc/process_objects()
var/i = 1
while(i<=processing_objects.len)
var/obj/Object = processing_objects[i]
if(Object)
last_thing_processed = Object.type
Object.process()
continue