From 5f67943f8e5c2355cd4a2f6fd06f6eab7f38ec46 Mon Sep 17 00:00:00 2001 From: ZomgPonies Date: Tue, 27 May 2014 21:22:53 -0400 Subject: [PATCH] Revert "APC bugfix after someone messed with mah areas!" This reverts commit ceca0ddbe876b350ee626e40e9ee9ef4623ec205. --- code/controllers/master_controller.dm | 67 ++++++++------------------- code/game/area/areas.dm | 1 + code/game/machinery/machinery.dm | 4 +- code/modules/power/apc.dm | 26 +++++------ code/modules/power/smes.dm | 4 -- 5 files changed, 35 insertions(+), 67 deletions(-) diff --git a/code/controllers/master_controller.dm b/code/controllers/master_controller.dm index 92cb296b349..b98c9ffac48 100644 --- a/code/controllers/master_controller.dm +++ b/code/controllers/master_controller.dm @@ -32,13 +32,10 @@ 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) @@ -179,14 +176,14 @@ datum/controller/game_controller/proc/process() //MACHINES timer = world.timeofday - process_machines() + processMachines() machines_cost = (world.timeofday - timer) / 10 sleep(breather_ticks) //OBJECTS timer = world.timeofday - process_objects() + processObjects() objects_cost = (world.timeofday - timer) / 10 sleep(breather_ticks) @@ -261,52 +258,26 @@ datum/controller/game_controller/proc/process() Disease.process() continue -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++ + 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() + continue - machines.Cut(i,i+1) - 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() + Machinery.removeAtProcessing() - 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) +/datum/controller/game_controller/proc/processObjects() + for (var/obj/Object in processing_objects) + if (Object && Object.loc) last_thing_processed = Object.type Object.process() continue diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index ef4f8529e24..9603638f719 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -292,6 +292,7 @@ return used /area/proc/clear_usage() + master.used_equip = 0 master.used_light = 0 master.used_environ = 0 diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index e0cc9c923e3..2fb8bb1393e 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -210,7 +210,7 @@ Class Procs: src.add_fingerprint(usr) var/area/A = get_area(src) - A.master.powerupdate = 1 + A.powerupdate = 1 return 0 @@ -256,7 +256,7 @@ Class Procs: src.add_fingerprint(user) var/area/A = get_area(src) - A.master.powerupdate = 1 + A.powerupdate = 1 return 0 diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index 58ffc3f1f42..a8accfd0048 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -1045,7 +1045,6 @@ lastused_equip = area.usage(EQUIP) lastused_environ = area.usage(ENVIRON) if(area.powerupdate) - if(debug) log_debug("power update in [area.name] / [name]") area.clear_usage() lastused_total = lastused_light + lastused_equip + lastused_environ @@ -1069,16 +1068,16 @@ if(terminal && terminal.powernet) perapc = terminal.powernet.perapc - if(debug) - log_debug( "Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light]") + //if(debug) + //world << "Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light]" if(cell && !shorted) - //var/cell_charge = cell.charge + var/cell_charge = cell.charge var/cell_maxcharge = cell.maxcharge // draw power from cell as before - var/cellused = min(cell.charge, CELLRATE * lastused_total) // clamp deduction to a max, amount left in cell + var/cellused = min(cell_charge, CELLRATE * lastused_total) // clamp deduction to a max, amount left in cell cell.use(cellused) if(excess > 0 || perapc > lastused_total) // if power excess, or enough anyway, recharge the cell @@ -1089,9 +1088,10 @@ else // no excess, and not enough per-apc - if( (cell.charge/CELLRATE+perapc) >= lastused_total) // can we draw enough from cell+grid to cover last usage? + if( (cell_charge/CELLRATE+perapc) >= lastused_total) // can we draw enough from cell+grid to cover last usage? - cell.charge = min(cell_maxcharge, cell.charge + CELLRATE * perapc) //recharge with what we can + cell_charge = min(cell_maxcharge, cell_charge + CELLRATE * perapc) //recharge with what we can + cell.charge = cell_charge add_load(perapc) // so draw what we can from the grid charging = 0 @@ -1114,30 +1114,30 @@ longtermpower -= 2 - if(cell.charge >= 1250 || longtermpower > 0) // Put most likely at the top so we don't check it last, effeciency 101 + if(cell_charge >= 1250 || longtermpower > 0) // Put most likely at the top so we don't check it last, effeciency 101 if(autoflag != 3) equipment = autoset(equipment, 1) lighting = autoset(lighting, 1) environ = autoset(environ, 1) autoflag = 3 area.poweralert(1, src) - if(cell.charge >= 4000) + if(cell_charge >= 4000) area.poweralert(1, src) - else if(cell.charge < 1250 && cell.charge > 750 && longtermpower < 0) // <30%, turn off equipment + else if(cell_charge < 1250 && cell_charge > 750 && longtermpower < 0) // <30%, turn off equipment if(autoflag != 2) equipment = autoset(equipment, 2) lighting = autoset(lighting, 1) environ = autoset(environ, 1) area.poweralert(0, src) autoflag = 2 - else if(cell.charge < 750 && cell.charge > 10 && longtermpower < 0) // <15%, turn off lighting & equipment + else if(cell_charge < 750 && cell_charge > 10 && longtermpower < 0) // <15%, turn off lighting & equipment if(autoflag != 1) equipment = autoset(equipment, 2) lighting = autoset(lighting, 2) environ = autoset(environ, 1) area.poweralert(0, src) autoflag = 1 - else if(cell.charge <= 0) // zero charge, turn all off + else if(cell_charge <= 0) // zero charge, turn all off if(autoflag != 0) equipment = autoset(equipment, 0) lighting = autoset(lighting, 0) @@ -1150,7 +1150,7 @@ if(chargemode && charging == 1 && operating) if(excess > 0) // check to make sure we have enough to charge // Max charge is perapc share, capped to cell capacity, or % per second constant (Whichever is smallest) - var/ch = min(perapc*CELLRATE, (cell_maxcharge - cell.charge), (cell_maxcharge*CHARGELEVEL)) + var/ch = min(perapc*CELLRATE, (cell_maxcharge - cell_charge), (cell_maxcharge*CHARGELEVEL)) add_load(ch/CELLRATE) // Removes the power we're taking from the grid cell.give(ch) // actually recharge the cell diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm index eb5951fa350..3f97b24dd3c 100644 --- a/code/modules/power/smes.dm +++ b/code/modules/power/smes.dm @@ -233,10 +233,6 @@ if (!istype(src.loc, /turf) && !istype(usr, /mob/living/silicon/)) return 0 // Do not update ui - for(var/area/A in active_areas) - A.master.powerupdate = 3 - - if( href_list["cmode"] ) chargemode = !chargemode if(!chargemode)