Files
kiwistation/code/modules/power/singularity/collector.dm
T
MrPerson ff3f84ab81 Replaces /image with /mutable_appearance, where appropriate (#26518)
In cases where you're creating an image to use as an overlay, it makes more sense to use a mutable_appearance if you can. The image will create a static appearance for not just the image but also each intermediate step if you change vars along the way. The mutable appearance avoids this unnecessary and expensive process. The only situation that requires an image instead of a mutable_appearance is if the overlay is supposed to be directional. MA's ignore direction while images don't. I dunno why, probably another BYOND-ism.

I added a convenience function, mutable_appearance(), designed to emulate image(). Also went ahead and set the default plane of /mutable_appearance to FLOAT_PLANE because it's fucking 0 by default.

Several overlays that were image() calls were changed to just text strings when I could. overlays += "string" has the same result as overlays += image(icon, "string") and saves a proc call.
2017-04-25 12:15:16 +02:00

161 lines
4.7 KiB
Plaintext

GLOBAL_LIST_EMPTY(rad_collectors)
/obj/machinery/power/rad_collector
name = "Radiation Collector Array"
desc = "A device which uses Hawking Radiation and plasma to produce power."
icon = 'icons/obj/singularity.dmi'
icon_state = "ca"
anchored = 0
density = 1
req_access = list(GLOB.access_engine_equip)
// use_power = 0
obj_integrity = 350
max_integrity = 350
integrity_failure = 80
var/obj/item/weapon/tank/internals/plasma/loaded_tank = null
var/last_power = 0
var/active = 0
var/locked = 0
var/drainratio = 1
/obj/machinery/power/rad_collector/New()
..()
GLOB.rad_collectors += src
/obj/machinery/power/rad_collector/Destroy()
GLOB.rad_collectors -= src
return ..()
/obj/machinery/power/rad_collector/process()
if(loaded_tank)
if(!loaded_tank.air_contents.gases["plasma"])
investigate_log("<font color='red'>out of fuel</font>.","singulo")
eject()
else
loaded_tank.air_contents.gases["plasma"][MOLES] -= 0.001*drainratio
loaded_tank.air_contents.garbage_collect()
return
/obj/machinery/power/rad_collector/attack_hand(mob/user)
if(..())
return
if(anchored)
if(!src.locked)
toggle_power()
user.visible_message("[user.name] turns the [src.name] [active? "on":"off"].", \
"<span class='notice'>You turn the [src.name] [active? "on":"off"].</span>")
var/fuel = loaded_tank.air_contents.gases["plasma"]
fuel = fuel ? fuel[MOLES] : 0
investigate_log("turned [active?"<font color='green'>on</font>":"<font color='red'>off</font>"] by [user.key]. [loaded_tank?"Fuel: [round(fuel/0.29)]%":"<font color='red'>It is empty</font>"].","singulo")
return
else
to_chat(user, "<span class='warning'>The controls are locked!</span>")
return
..()
/obj/machinery/power/rad_collector/can_be_unfasten_wrench(mob/user, silent)
if(loaded_tank)
if(!silent)
to_chat(user, "<span class='warning'>Remove the plasma tank first!</span>")
return FAILED_UNFASTEN
return ..()
/obj/machinery/power/rad_collector/default_unfasten_wrench(mob/user, obj/item/weapon/wrench/W, time = 20)
. = ..()
if(. == SUCCESSFUL_UNFASTEN)
if(anchored)
connect_to_network()
else
disconnect_from_network()
/obj/machinery/power/rad_collector/attackby(obj/item/W, mob/user, params)
if(istype(W, /obj/item/device/multitool))
to_chat(user, "<span class='notice'>The [W.name] detects that [last_power]W were recently produced.</span>")
return 1
else if(istype(W, /obj/item/device/analyzer) && loaded_tank)
atmosanalyzer_scan(loaded_tank.air_contents, user)
else if(istype(W, /obj/item/weapon/tank/internals/plasma))
if(!anchored)
to_chat(user, "<span class='warning'>The [src] needs to be secured to the floor first!</span>")
return 1
if(loaded_tank)
to_chat(user, "<span class='warning'>There's already a plasma tank loaded!</span>")
return 1
if(!user.drop_item())
return 1
loaded_tank = W
W.forceMove(src)
update_icons()
else if(istype(W, /obj/item/weapon/crowbar))
if(loaded_tank && !locked)
eject()
return 1
else if(istype(W, /obj/item/weapon/wrench))
default_unfasten_wrench(user, W, 0)
return 1
else if(W.GetID())
if(allowed(user))
if(active)
locked = !locked
to_chat(user, "<span class='notice'>You [locked ? "lock" : "unlock"] the controls.</span>")
else
to_chat(user, "<span class='warning'>The controls can only be locked when \the [src] is active!</span>")
else
to_chat(user, "<span class='danger'>Access denied.</span>")
return 1
else
return ..()
/obj/machinery/power/rad_collector/obj_break(damage_flag)
if(!(stat & BROKEN) && !(flags & NODECONSTRUCT))
eject()
stat |= BROKEN
/obj/machinery/power/rad_collector/proc/eject()
locked = 0
var/obj/item/weapon/tank/internals/plasma/Z = src.loaded_tank
if (!Z)
return
Z.loc = get_turf(src)
Z.layer = initial(Z.layer)
Z.plane = initial(Z.plane)
src.loaded_tank = null
if(active)
toggle_power()
else
update_icons()
/obj/machinery/power/rad_collector/proc/receive_pulse(pulse_strength)
if(loaded_tank && active)
var/power_produced = loaded_tank.air_contents.gases["plasma"] ? loaded_tank.air_contents.gases["plasma"][MOLES] : 0
power_produced *= pulse_strength*10
add_avail(power_produced)
last_power = power_produced
return
return
/obj/machinery/power/rad_collector/proc/update_icons()
cut_overlays()
if(loaded_tank)
add_overlay("ptank")
if(stat & (NOPOWER|BROKEN))
return
if(active)
add_overlay("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