Files
CHOMPStation2/code/modules/power/singularity/collector.dm
Leshana 34c73dab69 Optimization/Rewrite of Radiation Controller
* The performance of the radiation controller as-is was not fast enough for inclusion in production servers, but it has some nice featuers, so rewrote it to be more performant.
* Instead of storing the radiation strength for every turf, we only store the sources of radiation, and calculate the strength only for mobs who might be in range.
   * Old method was ray-tracing to every turf in range whether anything was there to be irradiated or not.  Could be hundreds of turfs.  New method only lazily calcualtes strength at a turf if we actually need to know it.   Often times this is zero turfs if nobody is standing in engineering.
  * Removed the automatic processing of objects with "rad_power" set.  Objects are responsible for calling the repository to create/update their radiation sources.   Saves some extra overhead that in practice was redundant with other process controllers.
  * Also tweaked to be more respectful of qdel'd objects and added some comments.
2017-05-25 18:43:56 -04:00

162 lines
4.4 KiB
Plaintext

//This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:33
var/global/list/rad_collectors = list()
/obj/machinery/power/rad_collector
name = "Radiation Collector Array"
desc = "A device which uses Hawking Radiation and phoron to produce power."
icon = 'icons/obj/singularity.dmi'
icon_state = "ca"
anchored = 0
density = 1
req_access = list(access_engine_equip)
// use_power = 0
var/obj/item/weapon/tank/phoron/P = null
var/last_power = 0
var/last_power_new = 0
var/active = 0
var/locked = 0
var/drainratio = 1
/obj/machinery/power/rad_collector/New()
..()
rad_collectors += src
/obj/machinery/power/rad_collector/Destroy()
rad_collectors -= src
..()
/obj/machinery/power/rad_collector/process()
//so that we don't zero out the meter if the SM is processed first.
last_power = last_power_new
last_power_new = 0
if(P && active)
var/rads = radiation_repository.get_rads_at_turf(get_turf(src))
if(rads)
receive_pulse(rads * 5) //Maths is hard
if(P)
if(P.air_contents.gas["phoron"] == 0)
investigate_log("<font color='red'>out of fuel</font>.","singulo")
eject()
else
P.air_contents.adjust_gas("phoron", -0.001*drainratio)
return
/obj/machinery/power/rad_collector/attack_hand(mob/user as mob)
if(anchored)
if(!src.locked)
toggle_power()
user.visible_message("[user.name] turns the [src.name] [active? "on":"off"].", \
"You turn the [src.name] [active? "on":"off"].")
investigate_log("turned [active?"<font color='green'>on</font>":"<font color='red'>off</font>"] by [user.key]. [P?"Fuel: [round(P.air_contents.gas["phoron"]/0.29)]%":"<font color='red'>It is empty</font>"].","singulo")
return
else
user << "\red The controls are locked!"
return
..()
/obj/machinery/power/rad_collector/attackby(obj/item/W, mob/user)
if(istype(W, /obj/item/weapon/tank/phoron))
if(!src.anchored)
user << "\red The [src] needs to be secured to the floor first."
return 1
if(src.P)
user << "\red There's already a phoron tank loaded."
return 1
user.drop_item()
src.P = W
W.loc = src
update_icons()
return 1
else if(istype(W, /obj/item/weapon/crowbar))
if(P && !src.locked)
eject()
return 1
else if(istype(W, /obj/item/weapon/wrench))
if(P)
user << "\blue Remove the phoron tank first."
return 1
playsound(src.loc, 'sound/items/Ratchet.ogg', 75, 1)
src.anchored = !src.anchored
user.visible_message("[user.name] [anchored? "secures":"unsecures"] the [src.name].", \
"You [anchored? "secure":"undo"] the external bolts.", \
"You hear a ratchet")
if(anchored)
connect_to_network()
else
disconnect_from_network()
return 1
else if(istype(W, /obj/item/weapon/card/id)||istype(W, /obj/item/device/pda))
if (src.allowed(user))
if(active)
src.locked = !src.locked
user << "The controls are now [src.locked ? "locked." : "unlocked."]"
else
src.locked = 0 //just in case it somehow gets locked
user << "\red The controls can only be locked when the [src] is active"
else
user << "\red Access denied!"
return 1
return ..()
/obj/machinery/power/rad_collector/examine(mob/user)
if (..(user, 3))
user << "The meter indicates that \the [src] is collecting [last_power] W."
return 1
/obj/machinery/power/rad_collector/ex_act(severity)
switch(severity)
if(2, 3)
eject()
return ..()
/obj/machinery/power/rad_collector/proc/eject()
locked = 0
var/obj/item/weapon/tank/phoron/Z = src.P
if (!Z)
return
Z.loc = get_turf(src)
Z.layer = initial(Z.layer)
src.P = null
if(active)
toggle_power()
else
update_icons()
/obj/machinery/power/rad_collector/proc/receive_pulse(var/pulse_strength)
if(P && active)
var/power_produced = 0
power_produced = P.air_contents.gas["phoron"]*pulse_strength*20
add_avail(power_produced)
last_power_new = power_produced
return
return
/obj/machinery/power/rad_collector/proc/update_icons()
overlays.Cut()
if(P)
overlays += image('icons/obj/singularity.dmi', "ptank")
if(stat & (NOPOWER|BROKEN))
return
if(active)
overlays += image('icons/obj/singularity.dmi', "on")
/obj/machinery/power/rad_collector/proc/toggle_power()
active = !active
if(active)
icon_state = "ca_on"
flick("ca_active", src)
else
icon_state = "ca"
flick("ca_deactive", src)
update_icons()
return