Optimize flashlight processing

This commit is contained in:
Aronai Sieyes
2020-05-13 11:44:56 -04:00
parent 19f165f0cf
commit 94e085740e

View File

@@ -20,23 +20,19 @@
/obj/item/device/flashlight/Initialize()
. = ..()
update_icon()
/obj/item/device/flashlight/New()
if(power_use)
START_PROCESSING(SSobj, src)
if(cell_type)
cell = new cell_type(src)
brightness_levels = list("low" = 0.25, "medium" = 0.5, "high" = 1)
power_usage = brightness_levels[brightness_level]
if(power_use && cell_type)
cell = new cell_type(src)
brightness_levels = list("low" = 0.25, "medium" = 0.5, "high" = 1)
power_usage = brightness_levels[brightness_level]
else
verbs -= /obj/item/device/flashlight/verb/toggle
..()
update_icon()
/obj/item/device/flashlight/Destroy()
if(power_use)
STOP_PROCESSING(SSobj, src)
STOP_PROCESSING(SSobj, src)
qdel_null(cell)
return ..()
/obj/item/device/flashlight/get_cell()
@@ -57,18 +53,17 @@
update_icon()
/obj/item/device/flashlight/process()
if(on)
if(cell)
if(brightness_level && power_usage)
if(power_usage < cell.charge)
cell.charge -= power_usage
else
cell.charge = 0
visible_message("<span class='warning'>\The [src] flickers before going dull.</span>")
set_light(0)
playsound(src.loc, 'sound/effects/sparks3.ogg', 10, 1, -3) //Small cue that your light went dull in your pocket.
on = 0
update_icon()
if(!on || !cell)
return PROCESS_KILL
if(brightness_level && power_usage)
if(cell.use(power_usage) != power_usage) // we weren't able to use our full power_usage amount!
visible_message("<span class='warning'>\The [src] flickers before going dull.</span>")
set_light(0)
playsound(src.loc, 'sound/effects/sparks3.ogg', 10, 1, -3) //Small cue that your light went dull in your pocket.
on = 0
update_icon()
return PROCESS_KILL
/obj/item/device/flashlight/update_icon()
if(on)
@@ -110,6 +105,10 @@
to_chat(user, "You flick the switch on [src], but nothing happens.")
return 0
on = !on
if(on && power_use)
START_PROCESSING(SSobj, src)
else if(power_use)
STOP_PROCESSING(SSobj, src)
playsound(src.loc, 'sound/weapons/empty.ogg', 15, 1, -3)
update_icon()
user.update_action_buttons()