From b97434054fec00bc0df5329f7336425f9bfa76bd Mon Sep 17 00:00:00 2001 From: Ccomp5950 Date: Fri, 7 Mar 2014 23:42:28 -0600 Subject: [PATCH] APC Area update initial commit. Conflicts: code/modules/mob/mob.dm code/modules/power/power.dm --- code/controllers/master_controller.dm | 20 ++++++++++++++++++-- code/game/area/Space Station 13 areas.dm | 3 +++ code/game/area/areas.dm | 1 + code/game/machinery/machinery.dm | 16 +++++++++++++--- code/global.dm | 3 ++- code/modules/power/apc.dm | 10 ++++++---- code/modules/power/lighting.dm | 2 ++ code/modules/power/power.dm | 8 ++++++-- code/modules/recycling/disposal.dm | 9 ++++++--- 9 files changed, 57 insertions(+), 15 deletions(-) diff --git a/code/controllers/master_controller.dm b/code/controllers/master_controller.dm index 40f10f48d3b..1551bf82c0e 100644 --- a/code/controllers/master_controller.dm +++ b/code/controllers/master_controller.dm @@ -267,11 +267,27 @@ datum/controller/game_controller/proc/process_machines() last_thing_processed = Machine.type if(Machine.process() != PROCESS_KILL) if(Machine) - if(Machine.use_power) - Machine.auto_use_power() + +// if(Machine.use_power) +// Machine.auto_use_power() + i++ continue machines.Cut(i,i+1) + i=1 + while(i<=active_areas.len) + var/area/A = active_areas[i] + if(A.powerupdate) + if(A.debug) + world << "process_machines [A] powerupdate is [A.powerupdate]" + A.powerupdate -= 1 + for(var/obj/machinery/M in A) + if(M) + if(M.use_power) + M.auto_use_power() + + i++ + datum/controller/game_controller/proc/process_objects() var/i = 1 diff --git a/code/game/area/Space Station 13 areas.dm b/code/game/area/Space Station 13 areas.dm index 5bc9dea2fcb..87c8ee8abc2 100644 --- a/code/game/area/Space Station 13 areas.dm +++ b/code/game/area/Space Station 13 areas.dm @@ -14,6 +14,7 @@ NOTE: there are two lists of areas in the end of this file: centcom and station */ + /area var/fire = null var/atmos = 1 @@ -32,6 +33,8 @@ NOTE: there are two lists of areas in the end of this file: centcom and station var/eject = null + var/debug = 0 + var/powerupdate = 0 var/requires_power = 1 var/always_unpowered = 0 //this gets overriden to 1 for space in area/New() diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 45f71b02385..8bab8ab6b42 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -13,6 +13,7 @@ master = src //moved outside the spawn(1) to avoid runtimes in lighting.dm when it references loc.loc.master ~Carn uid = ++global_uid related = list(src) + active_areas += src if(type == /area) // override defaults for space. TODO: make space areas of type /area/space rather than /area requires_power = 1 diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index cb266209f45..38e96fe7b94 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -67,8 +67,10 @@ Class Procs: Checks to see if area that contains the object has power available for power channel given in 'chan'. - use_power(amount, chan=EQUIP) 'modules/power/power.dm' + use_power(amount, chan=EQUIP, autocalled) 'modules/power/power.dm' Deducts 'amount' from the power channel 'chan' of the area that contains the object. + If it's autocalled then everything is normal, if something else calls use_power we are going to + need to recalculate the power two ticks in a row. power_change() 'modules/power/power.dm' Called by the area that contains the object when ever that area under goes a @@ -161,9 +163,9 @@ Class Procs: if(!powered(power_channel)) return 0 if(src.use_power == 1) - use_power(idle_power_usage,power_channel) + use_power(idle_power_usage,power_channel, 1) else if(src.use_power >= 2) - use_power(active_power_usage,power_channel) + use_power(active_power_usage,power_channel, 1) return 1 /obj/machinery/Topic(href, href_list) @@ -191,6 +193,10 @@ Class Procs: return 1 src.add_fingerprint(usr) + + var/area/A = get_area(src) + A.powerupdate = 1 + return 0 /obj/machinery/attack_ai(var/mob/user as mob) @@ -233,6 +239,10 @@ Class Procs: return 1 src.add_fingerprint(user) + + var/area/A = get_area(src) + A.powerupdate = 1 + return 0 /obj/machinery/CheckParts() diff --git a/code/global.dm b/code/global.dm index 55084b0048d..fa61015cd05 100644 --- a/code/global.dm +++ b/code/global.dm @@ -6,6 +6,7 @@ var/global/obj/effect/overlay/plmaster = null var/global/obj/effect/overlay/slmaster = null +var/global/list/active_areas = list() var/global/list/machines = list() var/global/list/processing_objects = list() var/global/list/active_diseases = list() @@ -300,4 +301,4 @@ var/score_dmgestkey = null // Recall time limit: 2 hours -var/recall_time_limit=72000 \ No newline at end of file +var/recall_time_limit=72000 diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index 9c308a2600d..944690c4d2e 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -78,6 +78,7 @@ powernet = 0 // set so that APCs aren't found as powernet nodes //Hackish, Horrible, was like this before I changed it :( var/malfhack = 0 //New var for my changes to AI malf. --NeoFite var/mob/living/silicon/ai/malfai = null //See above --NeoFite + var/debug= 0 // luminosity = 1 var/has_electronics = 0 // 0 - none, 1 - plugged in, 2 - secured by screwdriver var/overload = 1 //used for the Blackout malf module @@ -1049,7 +1050,8 @@ lastused_light = area.usage(LIGHT) lastused_equip = area.usage(EQUIP) lastused_environ = area.usage(ENVIRON) - area.clear_usage() + if(area.powerupdate) + area.clear_usage() lastused_total = lastused_light + lastused_equip + lastused_environ @@ -1072,8 +1074,8 @@ if(terminal && terminal.powernet) perapc = terminal.powernet.perapc - //if(debug) - // world.log << "Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light] - Longterm: [longtermpower]" + if(debug) + world << "Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light]" if(cell && !shorted) @@ -1318,4 +1320,4 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on) else return 0 -#undef APC_UPDATE_ICON_COOLDOWN \ No newline at end of file +#undef APC_UPDATE_ICON_COOLDOWN diff --git a/code/modules/power/lighting.dm b/code/modules/power/lighting.dm index 6176d4d026a..7ff2be8c2a2 100644 --- a/code/modules/power/lighting.dm +++ b/code/modules/power/lighting.dm @@ -602,9 +602,11 @@ #define LIGHTING_POWER_FACTOR 20 //20W per unit luminosity +/* /obj/machinery/light/process()//TODO: remove/add this from machines to save on processing as needed ~Carn PRIORITY if(on) use_power(luminosity * LIGHTING_POWER_FACTOR, LIGHT) +*/ // called when area power state changes /obj/machinery/light/power_change() diff --git a/code/modules/power/power.dm b/code/modules/power/power.dm index 7527b70993e..c010771b308 100644 --- a/code/modules/power/power.dm +++ b/code/modules/power/power.dm @@ -54,13 +54,17 @@ // increment the power usage stats for an area -/obj/machinery/proc/use_power(var/amount, var/chan = -1) // defaults to power_channel - var/area/A = get_area(src) // make sure it's in an area +/obj/machinery/proc/use_power(var/amount, var/chan = -1, var/autocalled = 0) // defaults to power_channel + var/area/A = src.loc.loc // make sure it's in an area if(!A || !isarea(A) || !A.master) return if(chan == -1) chan = power_channel A.master.use_power(amount, chan) + if(!autocalled) + if(A.master.debug) + world << "Yeah we're setting this to 2 source: [src] / [src.type]" + A.master.powerupdate = 2 // Decremented by 2 each GC tick, since it's not auto power change we're going to update power twice. /obj/machinery/proc/power_change() // called whenever the power settings of the containing area change // by default, check equipment channel & set flag diff --git a/code/modules/recycling/disposal.dm b/code/modules/recycling/disposal.dm index 8f7f5f0b52a..4b1ad0470e4 100644 --- a/code/modules/recycling/disposal.dm +++ b/code/modules/recycling/disposal.dm @@ -22,6 +22,8 @@ var/flush_every_ticks = 30 //Every 30 ticks it will look whether it is ready to flush var/flush_count = 0 //this var adds 1 once per tick. When it reaches flush_every_ticks it resets and tries to flush. var/last_sound = 0 + active_power_usage = 600 + idle_power_usage = 100 // create a new disposal // find the attached trunk (if present) and init gas resvr. @@ -340,6 +342,7 @@ // timed process // charge the gas reservoir and perform flush if ready process() + use_power = 0 if(stat & BROKEN) // nothing can happen if broken return @@ -363,13 +366,13 @@ if(stat & NOPOWER) // won't charge if no power return - use_power(100) // base power usage - + use_power = 1 + if(mode != 1) // if off or ready, no need to charge return // otherwise charge - use_power(500) // charging power usage + use_power = 2 var/atom/L = loc // recharging from loc turf