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)
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()

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/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)

View File

@@ -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.)

View File

@@ -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)

View File

@@ -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)

View File

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

View File

@@ -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

View File

@@ -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

View File

@@ -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"
@@ -169,6 +171,7 @@
var/area/A = src.loc.loc
//if area isn't specified use current
if(isarea(A) && src.areastring == null)
src.area = A
@@ -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

View File

@@ -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

View File

@@ -28,7 +28,8 @@
/obj/machinery/disease2/diseaseanalyser/process()
if(stat & (NOPOWER|BROKEN))
return
use_power(500)
//use_power(500)
if(scanning)
scanning -= 1

View File

@@ -72,7 +72,7 @@
if(stat & (NOPOWER|BROKEN))
return
use_power(500)
//use_power(500)
if(curing)
curing -= 1

View File

@@ -90,7 +90,7 @@
/obj/machinery/computer/diseasesplicer/process()
if(stat & (NOPOWER|BROKEN))
return
use_power(500)
//use_power(500)
if(scanning)
scanning -= 1