From bb9a66cc3a035bcb76989e2da3f402ad2e702ac2 Mon Sep 17 00:00:00 2001 From: Ccomp5950 Date: Sat, 8 Mar 2014 03:42:44 -0600 Subject: [PATCH] Effeciency Project: APC / Machinery power usage. We no longer run auto_use_power() on every machine every tick. We now have a global list of areas, and areas that have an APC in them (all_areas and active_areas) no more looping through world bullshit. A bunch of snowflakey as fuck machines won't use_power() in their process, you get two options, active and idle, use them! This means a lot of machines won't double dip on power as well so power usage for the station has dropped about 20% Because everything is snowflakey as fuck we're going to have some machines that don't force an update on their power usage. Fuck them. We should catch them with the root obj/machine/proc's forcing updates. --- code/controllers/master_controller.dm | 7 +- code/game/area/Space Station 13 areas.dm | 4 +- code/game/area/areas.dm | 2 + code/game/machinery/adv_med.dm | 6 +- code/game/machinery/atmoalter/meter.dm | 4 +- code/game/machinery/cloning.dm | 2 +- code/game/machinery/lightswitch.dm | 2 +- code/global.dm | 3 +- code/modules/mob/mob.dm | 7 -- code/modules/power/apc.dm | 90 +++++++++++++----------- code/modules/power/solar.dm | 2 +- code/modules/virus2/analyser.dm | 5 +- code/modules/virus2/centrifuge.dm | 4 +- code/modules/virus2/diseasesplicer.dm | 4 +- 14 files changed, 75 insertions(+), 67 deletions(-) diff --git a/code/controllers/master_controller.dm b/code/controllers/master_controller.dm index 914bad735f..a7272ee4ce 100644 --- a/code/controllers/master_controller.dm +++ b/code/controllers/master_controller.dm @@ -266,15 +266,16 @@ datum/controller/game_controller/proc/process_machines() 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++ + if(A.apc.len) + i++ + continue + active_areas.Cut(i,i+1) datum/controller/game_controller/proc/process_objects() diff --git a/code/game/area/Space Station 13 areas.dm b/code/game/area/Space Station 13 areas.dm index 7ab535b434..9507902a45 100755 --- a/code/game/area/Space Station 13 areas.dm +++ b/code/game/area/Space Station 13 areas.dm @@ -33,7 +33,7 @@ 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/powerupdate = 10 //We give everything 10 ticks to settle out it's power usage. var/requires_power = 1 var/always_unpowered = 0 //this gets overriden to 1 for space in area/New() @@ -46,7 +46,7 @@ NOTE: there are two lists of areas in the end of this file: centcom and station var/used_environ = 0 var/has_gravity = 1 - + var/list/apc = list() var/no_air = null var/area/master // master area used for power calcluations // (original area before splitting due to sd_DAL) diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 16a7059e51..7a9ac8aa37 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -14,6 +14,7 @@ uid = ++global_uid related = list(src) active_areas += src + all_areas += src if(type == /area) // override defaults for space. TODO: make space areas of type /area/space rather than /area requires_power = 1 @@ -217,6 +218,7 @@ // called when power status changes /area/proc/power_change() + master.powerupdate = 2 for(var/area/RA in related) for(var/obj/machinery/M in RA) // for each machine in the area M.power_change() // reverify power status (to update icons etc.) diff --git a/code/game/machinery/adv_med.dm b/code/game/machinery/adv_med.dm index bd44ba4e7d..b7d6ad8ef7 100644 --- a/code/game/machinery/adv_med.dm +++ b/code/game/machinery/adv_med.dm @@ -181,10 +181,12 @@ return return +/* + /obj/machinery/body_scanconsole/process() //not really used right now if(stat & (NOPOWER|BROKEN)) return - use_power(250) // power stuff + //use_power(250) // power stuff // var/mob/M //occupant // if (!( src.status )) //remove this @@ -200,6 +202,8 @@ // src.updateDialog() // return +*/ + /obj/machinery/body_scanconsole/attack_paw(user as mob) return src.attack_hand(user) diff --git a/code/game/machinery/atmoalter/meter.dm b/code/game/machinery/atmoalter/meter.dm index be38255146..b73e2cbde2 100644 --- a/code/game/machinery/atmoalter/meter.dm +++ b/code/game/machinery/atmoalter/meter.dm @@ -10,7 +10,7 @@ var/id use_power = 1 idle_power_usage = 2 - active_power_usage = 4 + active_power_usage = 5 /obj/machinery/meter/New() ..() @@ -30,7 +30,7 @@ icon_state = "meter0" return 0 - use_power(5) + //use_power(5) var/datum/gas_mixture/environment = target.return_air() if(!environment) diff --git a/code/game/machinery/cloning.dm b/code/game/machinery/cloning.dm index 6f9d50053b..6bd2fb6a6f 100644 --- a/code/game/machinery/cloning.dm +++ b/code/game/machinery/cloning.dm @@ -273,7 +273,7 @@ src.locked = 0 if (!src.mess) icon_state = "pod_0" - use_power(200) + //use_power(200) return return diff --git a/code/game/machinery/lightswitch.dm b/code/game/machinery/lightswitch.dm index 128292631f..f75ebc4171 100644 --- a/code/game/machinery/lightswitch.dm +++ b/code/game/machinery/lightswitch.dm @@ -75,4 +75,4 @@ ..(severity) return power_change() - ..(severity) \ No newline at end of file + ..(severity) diff --git a/code/global.dm b/code/global.dm index 077b9d9f85..3c6704b456 100644 --- a/code/global.dm +++ b/code/global.dm @@ -7,6 +7,7 @@ var/global/obj/effect/overlay/slmaster = null var/global/list/active_areas = list() +var/global/list/all_areas = list() var/global/list/machines = list() var/global/list/processing_objects = list() var/global/list/active_diseases = list() @@ -115,7 +116,7 @@ var/list/reg_dna = list( ) var/mouse_respawn_time = 5 //Amount of time that must pass between a player dying as a mouse and repawning as a mouse. In minutes. var/CELLRATE = 0.002 // multiplier for watts per tick <> cell storage (eg: .002 means if there is a load of 1000 watts, 20 units will be taken from a cell per second) -var/CHARGELEVEL = 0.001 // Cap for how fast cells charge, as a percentage-per-tick (.001 means cellcharge is capped to 1% per second) +var/CHARGELEVEL = 0.0005 // Cap for how fast cells charge, as a percentage-per-tick (.001 means cellcharge is capped to 1% per second) var/shuttle_z = 2 //default var/airtunnel_start = 68 // default diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 602da6dd14..6e4c7e2e18 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -32,13 +32,6 @@ usr.show_message(t, 1) -/mob/verb/check_area() - var/area/a = get_area(src) - if(a in active_areas) - src << "Yep [a] is in the active_areas list" - else - src << "Nope, FUCK." - /mob/proc/show_message(msg, type, alt, alt_type)//Message, type of message (1 or 2), alternative message, alt message type (1 or 2) if(!client) return diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index 61c782650d..40486b390e 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -78,6 +78,7 @@ 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 + var/autoflag= 0 // 0 = off, 1= eqp and lights off, 2 = eqp off, 3 = all on. // luminosity = 1 var/has_electronics = 0 // 0 - none, 1 - plugged in, 2 - secured by screwdriver var/overload = 1 //used for the Blackout malf module @@ -142,6 +143,7 @@ init() else area = src.loc.loc:master + area.apc |= src opened = 1 operating = 0 name = "[area.name] APC" @@ -168,6 +170,7 @@ cell.charge = start_charge * cell.maxcharge / 100.0 // (convert percentage to actual value) var/area/A = src.loc.loc + //if area isn't specified use current if(isarea(A) && src.areastring == null) @@ -176,6 +179,7 @@ else src.area = get_area_name(areastring) name = "\improper [area.name] APC" + area.apc |= src update_icon() make_terminal() @@ -915,6 +919,7 @@ if(user.lying) user << "\red You must stand to use this [src]!" return 0 + autoflag = 5 if (istype(user, /mob/living/silicon)) var/mob/living/silicon/ai/AI = user var/mob/living/silicon/robot/robot = user @@ -1150,16 +1155,6 @@ return - /* - if (equipment > 1) // off=0, off auto=1, on=2, on auto=3 - use_power(src.equip_consumption, EQUIP) - if (lighting > 1) // off=0, off auto=1, on=2, on auto=3 - use_power(src.light_consumption, LIGHT) - if (environ > 1) // off=0, off auto=1, on=2, on auto=3 - use_power(src.environ_consumption, ENVIRON) - - area.calc_lighting() */ - lastused_light = area.usage(LIGHT) lastused_equip = area.usage(EQUIP) lastused_environ = area.usage(ENVIRON) @@ -1191,10 +1186,12 @@ world << "Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light]" if(cell && !shorted) + 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 @@ -1205,19 +1202,21 @@ 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 - else // not enough power available to run the last tick! + else if (autoflag != 0) // not enough power available to run the last tick! charging = 0 chargecount = 0 // This turns everything off in the case that there is still a charge left on the battery, just not enough to run the room. equipment = autoset(equipment, 0) lighting = autoset(lighting, 0) environ = autoset(environ, 0) + autoflag = 0 // set channels depending on how much charge we have left @@ -1228,39 +1227,44 @@ else if(longtermpower > -10) longtermpower -= 2 - if(cell.charge <= 0) // zero charge, turn all off - equipment = autoset(equipment, 0) - lighting = autoset(lighting, 0) - environ = autoset(environ, 0) - area.poweralert(0, src) - else if(cell.percent() < 15 && longtermpower < 0) // <15%, turn off lighting & equipment - equipment = autoset(equipment, 2) - lighting = autoset(lighting, 2) - environ = autoset(environ, 1) - area.poweralert(0, src) - else if(cell.percent() < 30 && longtermpower < 0) // <30%, turn off equipment - equipment = autoset(equipment, 2) - lighting = autoset(lighting, 1) - environ = autoset(environ, 1) - area.poweralert(0, src) - else // otherwise all can be on - equipment = autoset(equipment, 1) - lighting = autoset(lighting, 1) - environ = autoset(environ, 1) - area.poweralert(1, src) - if(cell.percent() > 75) + + 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) + area.poweralert(1, src) + else if(cell_charge < 1250 && 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 && 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 + if(autoflag != 0) + equipment = autoset(equipment, 0) + lighting = autoset(lighting, 0) + environ = autoset(environ, 0) + area.poweralert(0, src) + autoflag = 0 // now trickle-charge the cell 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, (cell.maxcharge - cell.charge), (cell.maxcharge*CHARGELEVEL)) - add_load(ch) // Removes the power we're taking from the grid - cell.give(ch) // actually recharge the cell -*/ - 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 @@ -1270,12 +1274,12 @@ // show cell as fully charged if so - if(cell.charge >= cell.maxcharge) + if(cell.charge >= cell_maxcharge) charging = 2 if(chargemode) if(!charging) - if(excess > cell.maxcharge*CHARGELEVEL) + if(excess > cell_maxcharge*CHARGELEVEL) chargecount++ else chargecount = 0 @@ -1297,6 +1301,8 @@ lighting = autoset(lighting, 0) environ = autoset(environ, 0) area.poweralert(0, src) + autoflag = 0 + // update icon & area power if anything changed diff --git a/code/modules/power/solar.dm b/code/modules/power/solar.dm index af3b0d269c..5701cae3a9 100644 --- a/code/modules/power/solar.dm +++ b/code/modules/power/solar.dm @@ -370,7 +370,7 @@ var/list/solars_list = list() if(stat & (NOPOWER | BROKEN)) return - use_power(250) + //use_power(250) if(track==1 && nexttime < world.time && trackdir*trackrate) // Increments nexttime using itself and not world.time to prevent drift nexttime = nexttime + 6000/trackrate diff --git a/code/modules/virus2/analyser.dm b/code/modules/virus2/analyser.dm index 50673d403c..adec9dd186 100644 --- a/code/modules/virus2/analyser.dm +++ b/code/modules/virus2/analyser.dm @@ -28,7 +28,8 @@ /obj/machinery/disease2/diseaseanalyser/process() if(stat & (NOPOWER|BROKEN)) return - use_power(500) + + //use_power(500) if(scanning) scanning -= 1 @@ -59,4 +60,4 @@ dish = null src.state("\The [src.name] buzzes") pause = 0 - return \ No newline at end of file + return diff --git a/code/modules/virus2/centrifuge.dm b/code/modules/virus2/centrifuge.dm index 651d36ce0a..d0dc99ddf9 100644 --- a/code/modules/virus2/centrifuge.dm +++ b/code/modules/virus2/centrifuge.dm @@ -72,7 +72,7 @@ if(stat & (NOPOWER|BROKEN)) return - use_power(500) + //use_power(500) if(curing) curing -= 1 @@ -151,4 +151,4 @@ var/obj/item/weapon/virusdish/dish = new/obj/item/weapon/virusdish(src.loc) dish.virus2 = virus2 - state("\The [src.name] pings", "blue") \ No newline at end of file + state("\The [src.name] pings", "blue") diff --git a/code/modules/virus2/diseasesplicer.dm b/code/modules/virus2/diseasesplicer.dm index 7a414e388e..2c26edc358 100644 --- a/code/modules/virus2/diseasesplicer.dm +++ b/code/modules/virus2/diseasesplicer.dm @@ -7,7 +7,7 @@ var/analysed = 0 var/obj/item/weapon/virusdish/dish = null var/burning = 0 - + var/splicing = 0 var/scanning = 0 @@ -90,7 +90,7 @@ /obj/machinery/computer/diseasesplicer/process() if(stat & (NOPOWER|BROKEN)) return - use_power(500) + //use_power(500) if(scanning) scanning -= 1