mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-09 16:12:17 +00:00
172 lines
4.7 KiB
Plaintext
172 lines
4.7 KiB
Plaintext
var/list/floor_light_cache = list()
|
|
|
|
/obj/item/floor_light
|
|
name = "floor light kit"
|
|
desc = "A backlit floor panel, ready for installation!"
|
|
icon = 'icons/obj/machines/floor_light.dmi'
|
|
icon_state = "item"
|
|
matter = list(MAT_STEEL = 2500, MAT_GLASS = 2750)
|
|
|
|
/obj/item/floor_light/attack_self(mob/user)
|
|
var/turf/T = get_turf(user)
|
|
if(!T)
|
|
to_chat(user, span_warning("You need to be on a floor to install this."))
|
|
return
|
|
new /obj/machinery/floor_light(T)
|
|
qdel(src)
|
|
|
|
/obj/machinery/floor_light
|
|
name = "floor light"
|
|
icon = 'icons/obj/machines/floor_light.dmi'
|
|
icon_state = "base"
|
|
desc = "A backlit floor panel."
|
|
layer = TURF_LAYER+0.001
|
|
anchored = FALSE
|
|
use_power = USE_POWER_ACTIVE
|
|
idle_power_usage = 2
|
|
active_power_usage = 20
|
|
power_channel = LIGHT
|
|
|
|
var/on
|
|
var/damaged
|
|
var/default_light_range = 4
|
|
var/default_light_power = 0.75
|
|
var/default_light_colour = LIGHT_COLOR_INCANDESCENT_BULB
|
|
|
|
/obj/machinery/floor_light/prebuilt
|
|
anchored = TRUE
|
|
|
|
/obj/machinery/floor_light/attackby(var/obj/item/W, var/mob/user)
|
|
if(W.has_tool_quality(TOOL_SCREWDRIVER))
|
|
anchored = !anchored
|
|
visible_message(span_notice("\The [user] has [anchored ? "attached" : "detached"] \the [src]."))
|
|
else if(W.has_tool_quality(TOOL_WELDER) && (damaged || (stat & BROKEN)))
|
|
var/obj/item/weldingtool/WT = W.get_welder()
|
|
if(!WT.remove_fuel(0, user))
|
|
to_chat(user, span_warning("\The [src] must be on to complete this task."))
|
|
return
|
|
playsound(src, WT.usesound, 50, 1)
|
|
if(!do_after(user, 2 SECONDS * WT.toolspeed, target = src))
|
|
return
|
|
if(!src || !WT.isOn())
|
|
return
|
|
visible_message(span_notice("\The [user] has repaired \the [src]."))
|
|
stat &= ~BROKEN
|
|
damaged = null
|
|
update_brightness()
|
|
else if(W.force && user.a_intent == "hurt")
|
|
attack_hand(user)
|
|
return
|
|
|
|
/obj/machinery/floor_light/attack_hand(var/mob/user)
|
|
|
|
if(user.a_intent == I_HURT && !issmall(user))
|
|
if(!isnull(damaged) && !(stat & BROKEN))
|
|
visible_message(span_danger("\The [user] smashes \the [src]!"))
|
|
playsound(src, "shatter", 70, 1)
|
|
stat |= BROKEN
|
|
else
|
|
visible_message(span_danger("\The [user] attacks \the [src]!"))
|
|
playsound(src, 'sound/effects/Glasshit.ogg', 75, 1)
|
|
if(isnull(damaged)) damaged = 0
|
|
update_brightness()
|
|
return
|
|
else
|
|
|
|
if(!anchored)
|
|
to_chat(user, span_warning("\The [src] must be screwed down first."))
|
|
return
|
|
|
|
if(stat & BROKEN)
|
|
to_chat(user, span_warning("\The [src] is too damaged to be functional."))
|
|
return
|
|
|
|
if(stat & NOPOWER)
|
|
to_chat(user, span_warning("\The [src] is unpowered."))
|
|
return
|
|
|
|
on = !on
|
|
if(on) update_use_power(USE_POWER_ACTIVE)
|
|
//visible_message(span_notice("\The [user] turns \the [src] [on ? "on" : "off"].")) //VOREStation Edit - No thankouuuu. Too spammy.
|
|
update_brightness()
|
|
return
|
|
|
|
/obj/machinery/floor_light/process()
|
|
..()
|
|
var/need_update
|
|
if((!anchored || broken()) && on)
|
|
update_use_power(USE_POWER_OFF)
|
|
on = 0
|
|
need_update = 1
|
|
else if(use_power && !on)
|
|
update_use_power(USE_POWER_OFF)
|
|
need_update = 1
|
|
if(need_update)
|
|
update_brightness()
|
|
|
|
/obj/machinery/floor_light/proc/update_brightness()
|
|
if(on && use_power == USE_POWER_ACTIVE)
|
|
if(light_range != default_light_range || light_power != default_light_power || light_color != default_light_colour)
|
|
set_light(default_light_range, default_light_power, default_light_colour)
|
|
else
|
|
update_use_power(USE_POWER_OFF)
|
|
if(light_range || light_power)
|
|
set_light(0)
|
|
|
|
update_active_power_usage((light_range + light_power) * 10)
|
|
update_icon()
|
|
|
|
/obj/machinery/floor_light/update_icon()
|
|
cut_overlays()
|
|
if(use_power && !broken())
|
|
if(isnull(damaged))
|
|
var/cache_key = "floorlight-[default_light_colour]"
|
|
if(!floor_light_cache[cache_key])
|
|
var/image/I = image("on")
|
|
I.color = default_light_colour
|
|
I.layer = layer+0.001
|
|
floor_light_cache[cache_key] = I
|
|
add_overlay(floor_light_cache[cache_key])
|
|
else
|
|
if(damaged == 0) //Needs init.
|
|
damaged = rand(1,4)
|
|
var/cache_key = "floorlight-broken[damaged]-[default_light_colour]"
|
|
if(!floor_light_cache[cache_key])
|
|
var/image/I = image("flicker[damaged]")
|
|
I.color = default_light_colour
|
|
I.layer = layer+0.001
|
|
floor_light_cache[cache_key] = I
|
|
add_overlay(floor_light_cache[cache_key])
|
|
|
|
/obj/machinery/floor_light/proc/broken()
|
|
return (stat & (BROKEN|NOPOWER))
|
|
|
|
/obj/machinery/floor_light/ex_act(severity)
|
|
switch(severity)
|
|
if(1)
|
|
qdel(src)
|
|
if(2)
|
|
if(prob(50))
|
|
qdel(src)
|
|
else if(prob(20))
|
|
stat |= BROKEN
|
|
else
|
|
if(isnull(damaged))
|
|
damaged = 0
|
|
if(3)
|
|
if(prob(5))
|
|
qdel(src)
|
|
else if(isnull(damaged))
|
|
damaged = 0
|
|
return
|
|
|
|
/obj/machinery/floor_light/Destroy()
|
|
var/area/A = get_area(src)
|
|
if(A)
|
|
on = 0
|
|
. = ..()
|
|
|
|
/obj/machinery/floor_light/cultify()
|
|
default_light_colour = "#FF0000"
|
|
update_brightness()
|