Refactor lighting items that use fuel (#72146)

## About The Pull Request
Fixes #71826

This does the following:
- Makes candles a subtype of flare
- Fixes candles having lighting inconsistencies
- Fixes burning items (welder, candles, flares, etc.) not causing
ignition effects when held in hand
- Adds burnt flares and melted candles to maint loot and trash spawners
- Add match lighting sound when candles are lit
- Add time defines for fuel amounts and rounded them (ex. instead of
32.3333 minutes, it's now 35 minutes)
- Light sources that burn will now spawn a trash item once fuel is spent
- Light sources that burn now have a welder hitsound
- Light sources that burn can now be extinguished by a fire extinguisher
(except flares)
- Light sources that burn can now be used to ignite another object on
fire (ex. a lit candle can be used to light a cigarette)
- Light sources that burn and are lit now do `BURN` damage while
attacking

## Why It's Good For The Game
Code is more cleaner and consistent.  Also fixes some bugs.

## Changelog
🆑
soundadd: Candles will now use the match lighting sound when lit
soundadd: Light sources that burn will now have a welding hitsound
fix: Fix candle light behaving erratically
fix: Fix burning items that are held in hand will now have an ignition
effect on the turf. (ex. lit welders in hand will now ignite plasma in
the air)
balance: Light sources that burn and are lit now do `BURN` damage while
attacking
balance: Light sources fuel amounts were rounded to exact numbers (ex.
instead of 32.3333 minutes, it's now 35 minutes)
qol: Light items that burn can now be extinguished by a fire
extinguisher (except flares), used to ignite another object on fire, and
will now leave a trash item once fuel is used
qol: Add burnt flares and melted candles to trash spawners
refactor: Refactor lighting items that use fuel to be more robust
/🆑

Co-authored-by: Kylerace <kylerlumpkin1@gmail.com>
This commit is contained in:
Tim
2023-01-06 14:19:33 -06:00
committed by GitHub
parent 6769d3bc2e
commit 7d47fbef42
38 changed files with 1372 additions and 1349 deletions
-82
View File
@@ -1,82 +0,0 @@
#define CANDLE_LUMINOSITY 2
/obj/item/candle
name = "red candle"
desc = "In Greek myth, Prometheus stole fire from the Gods and gave it to \
humankind. The jewelry he kept for himself."
icon = 'icons/obj/candle.dmi'
icon_state = "candle1"
inhand_icon_state = null
w_class = WEIGHT_CLASS_TINY
light_color = LIGHT_COLOR_FIRE
heat = 1000
/// How many seconds it burns for
var/wax = 2000
var/lit = FALSE
var/infinite = FALSE
var/start_lit = FALSE
/obj/item/candle/Initialize(mapload)
. = ..()
if(start_lit)
light()
/obj/item/candle/update_icon_state()
icon_state = "candle[(wax > 800) ? ((wax > 1500) ? 1 : 2) : 3][lit ? "_lit" : ""]"
return ..()
/obj/item/candle/attackby(obj/item/W, mob/user, params)
var/msg = W.ignition_effect(src, user)
if(msg)
light(msg)
else
return ..()
/obj/item/candle/fire_act(exposed_temperature, exposed_volume)
if(!lit)
light() //honk
return ..()
/obj/item/candle/get_temperature()
return lit * heat
/obj/item/candle/proc/light(show_message)
if(!lit)
lit = TRUE
if(show_message)
usr.visible_message(show_message)
set_light(CANDLE_LUMINOSITY)
START_PROCESSING(SSobj, src)
update_appearance()
/obj/item/candle/proc/put_out_candle()
if(!lit)
return
lit = FALSE
update_appearance()
set_light(0)
return TRUE
/obj/item/candle/extinguish()
put_out_candle()
return ..()
/obj/item/candle/process(delta_time)
if(!lit)
return PROCESS_KILL
if(!infinite)
wax -= delta_time
if(wax <= 0)
new /obj/item/trash/candle(loc)
qdel(src)
update_appearance()
open_flame()
/obj/item/candle/attack_self(mob/user)
if(put_out_candle())
user.visible_message(span_notice("[user] snuffs [src]."))
/obj/item/candle/infinite
infinite = TRUE
start_lit = TRUE
#undef CANDLE_LUMINOSITY
+138 -46
View File
@@ -45,7 +45,7 @@
return NONE
/obj/item/flashlight/proc/update_brightness(mob/user)
/obj/item/flashlight/proc/update_brightness()
if(on)
icon_state = "[initial(icon_state)]-on"
else
@@ -54,14 +54,15 @@
if(light_system == STATIC_LIGHT)
update_light()
/obj/item/flashlight/proc/toggle_light(mob/user)
/obj/item/flashlight/proc/toggle_light()
on = !on
playsound(user, on ? sound_on : sound_off, 40, TRUE)
update_brightness(user)
playsound(src, on ? sound_on : sound_off, 40, TRUE)
update_brightness()
update_item_action_buttons()
return TRUE
/obj/item/flashlight/attack_self(mob/user)
toggle_light(user)
toggle_light()
/obj/item/flashlight/attack_hand_secondary(mob/user, list/modifiers)
attack_self(user)
@@ -293,62 +294,151 @@
toggle_context = FALSE
/// How many seconds of fuel we have left
var/fuel = 0
/// Do we randomize the fuel when initialized
var/randomize_fuel = TRUE
/// How much damage it does when turned on
var/on_damage = 7
var/produce_heat = 1500
/// Type of atom thats spawns after fuel is used up
var/trash_type = /obj/item/trash/flare
/// If the light source can be extinguished
var/can_be_extinguished = FALSE
/obj/item/flashlight/flare/Initialize(mapload)
. = ..()
fuel = rand(1600, 2000)
if(randomize_fuel)
fuel = rand(25 MINUTES, 35 MINUTES)
if(on)
attack_verb_continuous = string_list(list("burns", "singes"))
attack_verb_simple = string_list(list("burn", "singe"))
hitsound = 'sound/items/welder.ogg'
force = on_damage
damtype = BURN
update_brightness()
/obj/item/flashlight/flare/process(delta_time)
open_flame(heat)
fuel = max(fuel -= delta_time, 0)
if(fuel <= 0 || !on)
turn_off()
if(!fuel)
icon_state = "[initial(icon_state)]-empty"
STOP_PROCESSING(SSobj, src)
/obj/item/flashlight/flare/toggle_light()
if(on || !fuel)
return FALSE
/obj/item/flashlight/flare/ignition_effect(atom/A, mob/user)
. = fuel && on ? span_notice("[user] lights [A] with [src] like a real badass.") : ""
name = "lit [initial(name)]"
attack_verb_continuous = string_list(list("burns", "singes"))
attack_verb_simple = string_list(list("burn", "singe"))
hitsound = 'sound/items/welder.ogg'
force = on_damage
damtype = BURN
. = ..()
/obj/item/flashlight/flare/proc/turn_off()
on = FALSE
force = initial(src.force)
damtype = initial(src.damtype)
if(ismob(loc))
var/mob/U = loc
update_brightness(U)
else
update_brightness(null)
name = initial(name)
attack_verb_continuous = initial(attack_verb_continuous)
attack_verb_simple = initial(attack_verb_simple)
hitsound = initial(hitsound)
force = initial(force)
damtype = initial(damtype)
update_brightness()
/obj/item/flashlight/flare/update_brightness(mob/user = null)
/obj/item/flashlight/flare/extinguish()
if(fuel != INFINITY && can_be_extinguished)
turn_off()
return ..()
/obj/item/flashlight/flare/update_brightness()
..()
if(on)
inhand_icon_state = "[initial(inhand_icon_state)]-on"
else
inhand_icon_state = "[initial(inhand_icon_state)]"
inhand_icon_state = "[initial(inhand_icon_state)]" + (on ? "-on" : "")
update_appearance()
/obj/item/flashlight/flare/process(delta_time)
open_flame(heat)
fuel = max(fuel - delta_time * (1 SECONDS), 0)
if(!fuel || !on)
turn_off()
STOP_PROCESSING(SSobj, src)
if(!fuel && trash_type)
new trash_type(loc)
qdel(src)
/obj/item/flashlight/flare/ignition_effect(atom/A, mob/user)
if(get_temperature())
. = span_notice("[user] lights [A] with [src].")
/obj/item/flashlight/flare/proc/ignition(mob/user)
if(user && !fuel)
to_chat(user, span_warning("[src] is out of fuel!"))
return FALSE
if(user && on)
to_chat(user, span_warning("[src] is already lit!"))
return FALSE
if(!toggle_light())
return FALSE
if(fuel != INFINITY)
START_PROCESSING(SSobj, src)
return TRUE
/obj/item/flashlight/flare/fire_act(exposed_temperature, exposed_volume)
ignition()
return ..()
/obj/item/flashlight/flare/attack_self(mob/user)
// Usual checks
if(fuel <= 0)
to_chat(user, span_warning("[src] is out of fuel!"))
return
if(on)
to_chat(user, span_warning("[src] is already on!"))
return
. = ..()
// All good, turn it on.
if(.)
if(ignition(user))
user.visible_message(span_notice("[user] lights \the [src]."), span_notice("You light \the [src]!"))
force = on_damage
damtype = BURN
START_PROCESSING(SSobj, src)
/obj/item/flashlight/flare/get_temperature()
return on * heat
/obj/item/flashlight/flare/candle
name = "red candle"
desc = "In Greek myth, Prometheus stole fire from the Gods and gave it to \
humankind. The jewelry he kept for himself."
icon = 'icons/obj/candle.dmi'
icon_state = "candle1"
inhand_icon_state = null
w_class = WEIGHT_CLASS_TINY
light_color = LIGHT_COLOR_FIRE
light_range = 2
fuel = 35 MINUTES
randomize_fuel = FALSE
trash_type = /obj/item/trash/candle
can_be_extinguished = TRUE
/obj/item/flashlight/flare/candle/update_icon_state()
. = ..()
var/wax_level
switch(fuel)
if(25 MINUTES to INFINITY)
wax_level = 1
if(15 MINUTES to 25 MINUTES)
wax_level = 2
if(0 to 15 MINUTES)
wax_level = 3
icon_state = "candle[wax_level][on ? "_lit" : ""]"
/obj/item/flashlight/flare/candle/attackby(obj/item/fire_starter, mob/user, params)
var/success_msg = fire_starter.ignition_effect(src, user)
if(success_msg && ignition(user))
user.visible_message(success_msg)
else
return ..()
/obj/item/flashlight/flare/candle/attack_self(mob/user)
if(on && fuel != INFINITY && !can_be_extinguished) // can't extinguish eternal candles
turn_off()
user.visible_message(span_notice("[user] snuffs [src]."))
/obj/item/flashlight/flare/candle/process(delta_time)
. = ..()
update_appearance()
/obj/item/flashlight/flare/candle/infinite
name = "eternal candle"
fuel = INFINITY
on = TRUE
randomize_fuel = FALSE
can_be_extinguished = FALSE
/obj/item/flashlight/flare/torch
name = "torch"
desc = "A torch fashioned from some leaves and a log."
@@ -361,6 +451,8 @@
light_color = LIGHT_COLOR_ORANGE
on_damage = 10
slot_flags = null
trash_type = /obj/effect/decal/cleanable/ash
can_be_extinguished = TRUE
/obj/item/flashlight/lantern
name = "lantern"
@@ -478,7 +570,7 @@
var/fuel = 0
/obj/item/flashlight/glowstick/Initialize(mapload)
fuel = rand(3200, 4000)
fuel = rand(50 MINUTES, 60 MINUTES)
set_light_color(color)
return ..()
@@ -487,7 +579,7 @@
return ..()
/obj/item/flashlight/glowstick/process(delta_time)
fuel = max(fuel - delta_time, 0)
fuel = max(fuel - delta_time * (1 SECONDS), 0)
if(fuel <= 0)
turn_off()
STOP_PROCESSING(SSobj, src)
@@ -608,7 +700,7 @@
///Variable to preserve old lighting behavior in flashlights, to handle darkness.
var/dark_light_power = -3
/obj/item/flashlight/flashdark/update_brightness(mob/user)
/obj/item/flashlight/flashdark/update_brightness()
. = ..()
if(on)
set_light(dark_light_range, dark_light_power)
+1 -1
View File
@@ -162,7 +162,7 @@
worn_icon_state = "cigpack"
throwforce = 2
slot_flags = ITEM_SLOT_BELT
spawn_type = /obj/item/candle
spawn_type = /obj/item/flashlight/flare/candle
spawn_count = 5
is_open = TRUE
contents_tag = "candle"
+6 -1
View File
@@ -102,10 +102,15 @@
resistance_flags = NONE
/obj/item/trash/candle
name = "candle"
name = "melted candle"
icon = 'icons/obj/candle.dmi'
icon_state = "candle4"
/obj/item/trash/flare
name = "burnt flare"
icon = 'icons/obj/lighting.dmi'
icon_state = "flare-empty"
/obj/item/trash/can
name = "crushed can"
icon_state = "cola"