Files
Yogstation/code/modules/lighting/lighting_atom.dm
John Willard 892cee1705 Adds grep for mapload and var in Args (#19203)
* Adds grep for mapload and var in Args

* vars in args

* some more

* stuff

* Update shuttle_creator.dm

* Update __techweb_helpers.dm

* fix

* Update discoball.dm

* Update check_grep.sh

* Update check_grep.sh

* Update check_grep.sh

* Update check_grep.sh

* I'll finish this later

* datum and lateinit maploads

* componentinit stuff

* mapload fixes

* why isnt CI catching these major issues

* MERGE CONFLICT FUCKED MY PR OVER

* Update check_grep.sh

* Update food.dm
2023-06-15 12:04:36 -05:00

191 lines
5.9 KiB
Plaintext

/atom
///Light systems, both shouldn't be active at the same time.
var/light_system = STATIC_LIGHT
///Range of the light in tiles. Zero means no light.
var/light_range = 0
///Intensity of the light. The stronger, the less shadows you will see on the lit area.
var/light_power = 1
///Hexadecimal RGB string representing the colour of the light. White by default.
var/light_color = COLOR_WHITE
///Boolean variable for toggleable lights. Has no effect without the proper light_system, light_range and light_power values.
var/light_on = TRUE
///Bitflags to determine lighting-related atom properties.
var/light_flags = NONE
///Our light source. Don't fuck with this directly unless you have a good reason!
var/tmp/datum/light_source/light
///Any light sources that are "inside" of us, for example, if src here was a mob that's carrying a flashlight, that flashlight's light source would be part of this list.
var/tmp/list/light_sources
// The proc you should always use to set the light of this atom.
// Nonesensical value for l_color default, so we can detect if it gets set to null.
#define NONSENSICAL_VALUE -99999
/atom/proc/set_light(l_range, l_power, l_color = NONSENSICAL_VALUE)
if(l_range > 0 && l_range < MINIMUM_USEFUL_LIGHT_RANGE)
l_range = MINIMUM_USEFUL_LIGHT_RANGE //Brings the range up to 1.4, which is just barely brighter than the soft lighting that surrounds players.
if (l_power != null)
light_power = l_power
if (l_range != null)
light_range = l_range
if (l_color != NONSENSICAL_VALUE)
light_color = l_color
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT, l_range, l_power, l_color)
update_light()
#undef NONSENSICAL_VALUE
// Will update the light (duh).
// Creates or destroys it if needed, makes it update values, makes sure it's got the correct source turf...
/atom/proc/update_light()
set waitfor = FALSE
if (QDELETED(src))
return
if(light_system != STATIC_LIGHT)
CRASH("update_light() for [src] with following light_system value: [light_system]")
if (!light_power || !light_range) // We won't emit light anyways, destroy the light source.
QDEL_NULL(light)
else
if (!ismovable(loc)) // We choose what atom should be the top atom of the light here.
. = src
else
. = loc
if (light) // Update the light or create it if it does not exist.
light.update(.)
else
light = new/datum/light_source(src, .)
// If we have opacity, make sure to tell (potentially) affected light sources.
/atom/movable/Destroy()
var/turf/T = loc
. = ..()
if (opacity && istype(T))
var/old_has_opaque_atom = T.has_opaque_atom
T.recalc_atom_opacity()
if (old_has_opaque_atom != T.has_opaque_atom)
T.reconsider_lights()
// Should always be used to change the opacity of an atom.
// It notifies (potentially) affected light sources so they can update (if needed).
/atom/proc/set_opacity(new_opacity)
if (new_opacity == opacity)
return
opacity = new_opacity
var/turf/T = loc
if (!isturf(T))
return
if (new_opacity == TRUE)
T.has_opaque_atom = TRUE
T.reconsider_lights()
else
var/old_has_opaque_atom = T.has_opaque_atom
T.recalc_atom_opacity()
if (old_has_opaque_atom != T.has_opaque_atom)
T.reconsider_lights()
/atom/movable/Moved(atom/OldLoc, Dir)
. = ..()
for (var/datum/light_source/light as anything in light_sources) // Cycle through the light sources on this atom and tell them to update.
light.source_atom.update_light()
/atom/vv_edit_var(var_name, var_value)
switch (var_name)
if ("light_range")
if(light_system == STATIC_LIGHT)
set_light(l_range = var_value)
else
set_light_range(var_value)
datum_flags |= DF_VAR_EDITED
return TRUE
if ("light_power")
if(light_system == STATIC_LIGHT)
set_light(l_power = var_value)
else
set_light_power(var_value)
datum_flags |= DF_VAR_EDITED
return TRUE
if ("light_color")
if(light_system == STATIC_LIGHT)
set_light(l_color = var_value)
else
set_light_color(var_value)
datum_flags |= DF_VAR_EDITED
return TRUE
return ..()
/atom/proc/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION)
return
/turf/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION)
if(!_duration)
stack_trace("Lighting FX obj created on a turf without a duration")
new /obj/effect/dummy/lighting_obj (src, _range, _power, _color, _duration)
/obj/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION)
if(!_duration)
stack_trace("Lighting FX obj created on a obj without a duration")
new /obj/effect/dummy/lighting_obj (get_turf(src), _range, _power, _color, _duration)
/mob/living/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION)
mob_light(_range, _power, _color, _duration)
/mob/living/proc/mob_light(_range, _power, _color, _duration)
var/obj/effect/dummy/lighting_obj/moblight/mob_light_obj = new (src, _range, _power, _color, _duration)
return mob_light_obj
/atom/proc/set_light_range(new_range)
if(new_range == light_range)
return
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT_RANGE, new_range)
. = light_range
light_range = new_range
/atom/proc/set_light_power(new_power)
if(new_power == light_power)
return
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT_POWER, new_power)
. = light_power
light_power = new_power
/atom/proc/set_light_color(new_color)
if(new_color == light_color)
return
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT_COLOR, new_color)
. = light_color
light_color = new_color
/atom/proc/set_light_on(new_value)
if(new_value == light_on)
return
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT_ON, new_value)
. = light_on
light_on = new_value
/atom/proc/set_light_flags(new_value)
if(new_value == light_flags)
return
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT_FLAGS, new_value)
. = light_flags
light_flags = new_value