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.
This commit is contained in:
Ccomp5950
2014-03-08 03:42:44 -06:00
parent e0e1bd9cfb
commit bb9a66cc3a
14 changed files with 75 additions and 67 deletions

View File

@@ -266,15 +266,16 @@ datum/controller/game_controller/proc/process_machines()
while(i<=active_areas.len) while(i<=active_areas.len)
var/area/A = active_areas[i] var/area/A = active_areas[i]
if(A.powerupdate) if(A.powerupdate)
if(A.debug)
world << "process_machines [A] powerupdate is [A.powerupdate]"
A.powerupdate -= 1 A.powerupdate -= 1
for(var/obj/machinery/M in A) for(var/obj/machinery/M in A)
if(M) if(M)
if(M.use_power) if(M.use_power)
M.auto_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() datum/controller/game_controller/proc/process_objects()

View File

@@ -33,7 +33,7 @@ NOTE: there are two lists of areas in the end of this file: centcom and station
var/eject = null var/eject = null
var/debug = 0 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/requires_power = 1
var/always_unpowered = 0 //this gets overriden to 1 for space in area/New() 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/used_environ = 0
var/has_gravity = 1 var/has_gravity = 1
var/list/apc = list()
var/no_air = null var/no_air = null
var/area/master // master area used for power calcluations var/area/master // master area used for power calcluations
// (original area before splitting due to sd_DAL) // (original area before splitting due to sd_DAL)

View File

@@ -14,6 +14,7 @@
uid = ++global_uid uid = ++global_uid
related = list(src) related = list(src)
active_areas += 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 if(type == /area) // override defaults for space. TODO: make space areas of type /area/space rather than /area
requires_power = 1 requires_power = 1
@@ -217,6 +218,7 @@
// called when power status changes // called when power status changes
/area/proc/power_change() /area/proc/power_change()
master.powerupdate = 2
for(var/area/RA in related) for(var/area/RA in related)
for(var/obj/machinery/M in RA) // for each machine in the area for(var/obj/machinery/M in RA) // for each machine in the area
M.power_change() // reverify power status (to update icons etc.) M.power_change() // reverify power status (to update icons etc.)

View File

@@ -181,10 +181,12 @@
return return
return return
/*
/obj/machinery/body_scanconsole/process() //not really used right now /obj/machinery/body_scanconsole/process() //not really used right now
if(stat & (NOPOWER|BROKEN)) if(stat & (NOPOWER|BROKEN))
return return
use_power(250) // power stuff //use_power(250) // power stuff
// var/mob/M //occupant // var/mob/M //occupant
// if (!( src.status )) //remove this // if (!( src.status )) //remove this
@@ -200,6 +202,8 @@
// src.updateDialog() // src.updateDialog()
// return // return
*/
/obj/machinery/body_scanconsole/attack_paw(user as mob) /obj/machinery/body_scanconsole/attack_paw(user as mob)
return src.attack_hand(user) return src.attack_hand(user)

View File

@@ -10,7 +10,7 @@
var/id var/id
use_power = 1 use_power = 1
idle_power_usage = 2 idle_power_usage = 2
active_power_usage = 4 active_power_usage = 5
/obj/machinery/meter/New() /obj/machinery/meter/New()
..() ..()
@@ -30,7 +30,7 @@
icon_state = "meter0" icon_state = "meter0"
return 0 return 0
use_power(5) //use_power(5)
var/datum/gas_mixture/environment = target.return_air() var/datum/gas_mixture/environment = target.return_air()
if(!environment) if(!environment)

View File

@@ -273,7 +273,7 @@
src.locked = 0 src.locked = 0
if (!src.mess) if (!src.mess)
icon_state = "pod_0" icon_state = "pod_0"
use_power(200) //use_power(200)
return return
return return

View File

@@ -75,4 +75,4 @@
..(severity) ..(severity)
return return
power_change() power_change()
..(severity) ..(severity)

View File

@@ -7,6 +7,7 @@ var/global/obj/effect/overlay/slmaster = null
var/global/list/active_areas = list() var/global/list/active_areas = list()
var/global/list/all_areas = list()
var/global/list/machines = list() var/global/list/machines = list()
var/global/list/processing_objects = list() var/global/list/processing_objects = list()
var/global/list/active_diseases = 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/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/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/shuttle_z = 2 //default
var/airtunnel_start = 68 // default var/airtunnel_start = 68 // default

View File

@@ -32,13 +32,6 @@
usr.show_message(t, 1) 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) /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 if(!client) return

View File

@@ -78,6 +78,7 @@
var/malfhack = 0 //New var for my changes to AI malf. --NeoFite var/malfhack = 0 //New var for my changes to AI malf. --NeoFite
var/mob/living/silicon/ai/malfai = null //See above --NeoFite var/mob/living/silicon/ai/malfai = null //See above --NeoFite
var/debug= 0 var/debug= 0
var/autoflag= 0 // 0 = off, 1= eqp and lights off, 2 = eqp off, 3 = all on.
// luminosity = 1 // luminosity = 1
var/has_electronics = 0 // 0 - none, 1 - plugged in, 2 - secured by screwdriver var/has_electronics = 0 // 0 - none, 1 - plugged in, 2 - secured by screwdriver
var/overload = 1 //used for the Blackout malf module var/overload = 1 //used for the Blackout malf module
@@ -142,6 +143,7 @@
init() init()
else else
area = src.loc.loc:master area = src.loc.loc:master
area.apc |= src
opened = 1 opened = 1
operating = 0 operating = 0
name = "[area.name] APC" name = "[area.name] APC"
@@ -168,6 +170,7 @@
cell.charge = start_charge * cell.maxcharge / 100.0 // (convert percentage to actual value) cell.charge = start_charge * cell.maxcharge / 100.0 // (convert percentage to actual value)
var/area/A = src.loc.loc var/area/A = src.loc.loc
//if area isn't specified use current //if area isn't specified use current
if(isarea(A) && src.areastring == null) if(isarea(A) && src.areastring == null)
@@ -176,6 +179,7 @@
else else
src.area = get_area_name(areastring) src.area = get_area_name(areastring)
name = "\improper [area.name] APC" name = "\improper [area.name] APC"
area.apc |= src
update_icon() update_icon()
make_terminal() make_terminal()
@@ -915,6 +919,7 @@
if(user.lying) if(user.lying)
user << "\red You must stand to use this [src]!" user << "\red You must stand to use this [src]!"
return 0 return 0
autoflag = 5
if (istype(user, /mob/living/silicon)) if (istype(user, /mob/living/silicon))
var/mob/living/silicon/ai/AI = user var/mob/living/silicon/ai/AI = user
var/mob/living/silicon/robot/robot = user var/mob/living/silicon/robot/robot = user
@@ -1150,16 +1155,6 @@
return 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_light = area.usage(LIGHT)
lastused_equip = area.usage(EQUIP) lastused_equip = area.usage(EQUIP)
lastused_environ = area.usage(ENVIRON) lastused_environ = area.usage(ENVIRON)
@@ -1191,10 +1186,12 @@
world << "Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light]" world << "Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light]"
if(cell && !shorted) if(cell && !shorted)
var/cell_charge = cell.charge
var/cell_maxcharge = cell.maxcharge
// draw power from cell as before // 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) cell.use(cellused)
if(excess > 0 || perapc > lastused_total) // if power excess, or enough anyway, recharge the cell 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 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 add_load(perapc) // so draw what we can from the grid
charging = 0 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 charging = 0
chargecount = 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. // 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) equipment = autoset(equipment, 0)
lighting = autoset(lighting, 0) lighting = autoset(lighting, 0)
environ = autoset(environ, 0) environ = autoset(environ, 0)
autoflag = 0
// set channels depending on how much charge we have left // set channels depending on how much charge we have left
@@ -1228,39 +1227,44 @@
else if(longtermpower > -10) else if(longtermpower > -10)
longtermpower -= 2 longtermpower -= 2
if(cell.charge <= 0) // zero charge, turn all off
equipment = autoset(equipment, 0) if(cell_charge >= 1250 || longtermpower > 0) // Put most likely at the top so we don't check it last, effeciency 101
lighting = autoset(lighting, 0) if(autoflag != 3)
environ = autoset(environ, 0) equipment = autoset(equipment, 1)
area.poweralert(0, src) lighting = autoset(lighting, 1)
else if(cell.percent() < 15 && longtermpower < 0) // <15%, turn off lighting & equipment environ = autoset(environ, 1)
equipment = autoset(equipment, 2) autoflag = 3
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)
area.poweralert(1, src) 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 // now trickle-charge the cell
if(chargemode && charging == 1 && operating) if(chargemode && charging == 1 && operating)
if(excess > 0) // check to make sure we have enough to charge 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) // 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)) var/ch = min(perapc*CELLRATE, (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))
add_load(ch/CELLRATE) // Removes the power we're taking from the grid add_load(ch/CELLRATE) // Removes the power we're taking from the grid
cell.give(ch) // actually recharge the cell cell.give(ch) // actually recharge the cell
@@ -1270,12 +1274,12 @@
// show cell as fully charged if so // show cell as fully charged if so
if(cell.charge >= cell.maxcharge) if(cell.charge >= cell_maxcharge)
charging = 2 charging = 2
if(chargemode) if(chargemode)
if(!charging) if(!charging)
if(excess > cell.maxcharge*CHARGELEVEL) if(excess > cell_maxcharge*CHARGELEVEL)
chargecount++ chargecount++
else else
chargecount = 0 chargecount = 0
@@ -1297,6 +1301,8 @@
lighting = autoset(lighting, 0) lighting = autoset(lighting, 0)
environ = autoset(environ, 0) environ = autoset(environ, 0)
area.poweralert(0, src) area.poweralert(0, src)
autoflag = 0
// update icon & area power if anything changed // update icon & area power if anything changed

View File

@@ -370,7 +370,7 @@ var/list/solars_list = list()
if(stat & (NOPOWER | BROKEN)) if(stat & (NOPOWER | BROKEN))
return return
use_power(250) //use_power(250)
if(track==1 && nexttime < world.time && trackdir*trackrate) if(track==1 && nexttime < world.time && trackdir*trackrate)
// Increments nexttime using itself and not world.time to prevent drift // Increments nexttime using itself and not world.time to prevent drift
nexttime = nexttime + 6000/trackrate nexttime = nexttime + 6000/trackrate

View File

@@ -28,7 +28,8 @@
/obj/machinery/disease2/diseaseanalyser/process() /obj/machinery/disease2/diseaseanalyser/process()
if(stat & (NOPOWER|BROKEN)) if(stat & (NOPOWER|BROKEN))
return return
use_power(500)
//use_power(500)
if(scanning) if(scanning)
scanning -= 1 scanning -= 1
@@ -59,4 +60,4 @@
dish = null dish = null
src.state("\The [src.name] buzzes") src.state("\The [src.name] buzzes")
pause = 0 pause = 0
return return

View File

@@ -72,7 +72,7 @@
if(stat & (NOPOWER|BROKEN)) if(stat & (NOPOWER|BROKEN))
return return
use_power(500) //use_power(500)
if(curing) if(curing)
curing -= 1 curing -= 1
@@ -151,4 +151,4 @@
var/obj/item/weapon/virusdish/dish = new/obj/item/weapon/virusdish(src.loc) var/obj/item/weapon/virusdish/dish = new/obj/item/weapon/virusdish(src.loc)
dish.virus2 = virus2 dish.virus2 = virus2
state("\The [src.name] pings", "blue") state("\The [src.name] pings", "blue")

View File

@@ -7,7 +7,7 @@
var/analysed = 0 var/analysed = 0
var/obj/item/weapon/virusdish/dish = null var/obj/item/weapon/virusdish/dish = null
var/burning = 0 var/burning = 0
var/splicing = 0 var/splicing = 0
var/scanning = 0 var/scanning = 0
@@ -90,7 +90,7 @@
/obj/machinery/computer/diseasesplicer/process() /obj/machinery/computer/diseasesplicer/process()
if(stat & (NOPOWER|BROKEN)) if(stat & (NOPOWER|BROKEN))
return return
use_power(500) //use_power(500)
if(scanning) if(scanning)
scanning -= 1 scanning -= 1