Files
VMSolidusandGitHub 3b6d0f20ec Light Sensitivity Refactor (#22386)
The last time the Light Sensitivity code was changed, I remarked in a
review that "This should probably be a component so that its code isn't
being run on every mob forever". Well I've gotten around to doing that
myself, except I figured out it's even better off as an Element in this
situation rather than a Component. So this is now my first time adding
Elements to the repo. It turns out they're really awesome when paired
with signals.

This PR removes the hardcoded check for the light senstivity and dark
phobia traits from the Life() path, replacing them instead with two
Elements which hook into the pre-existing signal used to handle vision
updates for human mobs. I've mainly done this to help cut down on the
overwhelmingly high cost of the Life() codepath, which is currently one
of the most expensive paths we have.

While I was at it with refactoring these two, I noticed that there
wasn't a trait selection for either of them, so I added selections for
both traits to the disabilities tab so that players can opt-in to being
light sensitive or afraid of the dark!

<img width="318" height="336" alt="image"
src="https://github.com/user-attachments/assets/a1e60e83-d899-44df-8ea3-0cd5a87c231c"
/>
2026-05-18 19:21:19 +00:00

171 lines
6.9 KiB
Plaintext

//Character trait system. Currently geared only for disabilities but a refactor to make it trait neutral would be trivial.
/datum/character_disabilities
var/name = "Enigma"
var/desc = "This trait was not meant to be seen by mortal minds."
/datum/character_disabilities/proc/apply_self(mob/living/carbon/human/H)
return
/datum/character_disabilities/nearsighted
name = "Nearsightedness"
desc = "Without prescription glasses your vision is impaired."
/datum/character_disabilities/nearsighted/apply_self(mob/living/carbon/human/H)
H.disabilities |= NEARSIGHTED
/datum/character_disabilities/stutter
name = "Stuttering"
desc = "You have a chronic case of stuttering, repeating sounds involuntarily."
/datum/character_disabilities/stutter/apply_self(mob/living/carbon/human/H)
H.disabilities |= STUTTERING
/datum/character_disabilities/deuteranomaly
name = "Deuteranopia"
desc = "You have difficulty perceiving green."
/datum/character_disabilities/deuteranomaly/apply_self(mob/living/carbon/human/H)
H.add_client_color(/datum/client_color/deuteranopia, TRUE)
/datum/character_disabilities/protanopia
name = "Protanopia"
desc = "You have difficulty perceiving red."
/datum/character_disabilities/protanopia/apply_self(mob/living/carbon/human/H)
H.add_client_color(/datum/client_color/protanopia, TRUE)
/datum/character_disabilities/tritanopia
name = "Tritanopia"
desc = "You have difficulty perceiving green and yellow."
/datum/character_disabilities/tritanopia/apply_self(mob/living/carbon/human/H)
H.add_client_color(/datum/client_color/tritanopia, TRUE)
/datum/character_disabilities/total_colorblind
name = "Total Colorblindness"
desc = "You cannot see color, only black, white, and shades of gray."
/datum/character_disabilities/total_colorblind/apply_self(mob/living/carbon/human/H)
H.add_client_color(/datum/client_color/monochrome, TRUE)
/datum/character_disabilities/deaf
name = "Deafness"
desc = "You are unable to percieve sound."
/datum/character_disabilities/deaf/apply_self(mob/living/carbon/human/H)
H.sdisabilities |= DEAF
/datum/character_disabilities/asthma
name = "Asthma"
desc = "You are prone to inflammation in the lungs."
/datum/character_disabilities/asthma/apply_self(mob/living/carbon/human/H)
H.disabilities |= ASTHMA
if(H.max_stamina)
H.max_stamina *= 0.8
H.stamina = H.max_stamina
/datum/character_disabilities/hemophilia
name = "Hemophilia"
desc = "Your blood lacks some clotting factors, causing wounds to take twice as long to stop bleeding."
/// This takes a TRAIT_DISABILITY_* type trait, and assigns it to the character on apply_self
var/trait_type = TRAIT_DISABILITY_HEMOPHILIA
/datum/character_disabilities/hemophilia/apply_self(mob/living/carbon/human/H)
ADD_TRAIT(H, trait_type, DISABILITY_TRAIT)
/datum/character_disabilities/hemophilia/major
name = "Major Hemophilia"
desc = "Your blood lacks ALL clotting factors, causing wounds to never stop bleeding."
trait_type = TRAIT_DISABILITY_HEMOPHILIA_MAJOR
ABSTRACT_TYPE(/datum/character_disabilities/organ_scarring)
name = "Organ Scarring"
var/affected_organ
/datum/character_disabilities/organ_scarring/apply_self(mob/living/carbon/human/target)
var/obj/item/organ/internal/affecting = target.internal_organs_by_name[affected_organ]
if(affecting)
affecting.set_max_damage(initial(affecting.max_damage) * 0.5)
#define ORGAN_DISABILITY(ORGAN_PATH, ORGAN_NAME, ORGAN_TAG) \
/datum/character_disabilities/organ_scarring/##ORGAN_PATH { \
name = "Scarred Organ: " + ##ORGAN_NAME; \
affected_organ = ##ORGAN_TAG; \
}
ORGAN_DISABILITY(brain, "Brain", BP_BRAIN)
ORGAN_DISABILITY(eyes, "Eyes", BP_EYES)
ORGAN_DISABILITY(lungs, "Lungs", BP_LUNGS)
ORGAN_DISABILITY(liver, "Liver", BP_LIVER)
ORGAN_DISABILITY(kidneys, "Kidneys", BP_KIDNEYS)
ORGAN_DISABILITY(stomach, "Stomach", BP_STOMACH)
ORGAN_DISABILITY(appendix, "Appendix", BP_APPENDIX)
#undef ORGAN_DISABILITY
ABSTRACT_TYPE(/datum/character_disabilities/broken)
name = "Bruised Limb"
var/affected_limb
/datum/character_disabilities/broken/apply_self(mob/living/carbon/human/target)
var/obj/item/organ/external/affecting = target.get_organ(affected_limb)
if(affecting)
affecting.fracture(silent = TRUE)
affecting.status |= ORGAN_SPLINTED
#define BROKEN_DISABILITY(LIMB_PATH, LIMB_NAME, LIMB_TAG) \
/datum/character_disabilities/broken/##LIMB_PATH { \
name = "Broken Limb: " + ##LIMB_NAME; \
affected_limb = ##LIMB_TAG; \
}
BROKEN_DISABILITY(left_arm, "Left Arm", BP_L_ARM)
BROKEN_DISABILITY(right_arm, "Right Arm", BP_R_ARM)
BROKEN_DISABILITY(left_hand, "Left Hand", BP_L_HAND)
BROKEN_DISABILITY(right_hand, "Right Hand", BP_R_HAND)
BROKEN_DISABILITY(left_leg, "Left Leg", BP_L_LEG)
BROKEN_DISABILITY(right_leg, "Right Leg", BP_R_LEG)
BROKEN_DISABILITY(left_foot, "Left Foot", BP_L_FOOT)
BROKEN_DISABILITY(right_foot, "Right Foot", BP_R_FOOT)
#undef BROKEN_DISABILITY
// Psi related traits. Not strictly disabilities, but also not positive traits either.
/datum/character_disabilities/high_psi_sensitivity
name = "High Psi-sensitivity"
desc = "You are naturally more sensitive to psychic phenomena, roughly on par with having a psi-receiver implant." \
+ "Though this does not grant any psychic abilities, a character with this trait is counted as being psychic for a variety of effects." \
+ "For example, having the ability to distinguish the source of telepathic signals, but also taking bonus damage from anything that deals bonus damage to psychics."
/datum/character_disabilities/high_psi_sensitivity/apply_self(mob/living/carbon/human/H)
H.AddComponent(HIGH_PSI_SENSITIVITY_COMPONENT)
/datum/character_disabilities/low_psi_sensitivity
name = "Low Psi-sensitivity"
desc = "Your Zona Bovinae is naturally under-developed, resulting in a lower than normal response to psychic phenomenon." \
+ "Characters who are already psychic with this trait don't lose their powers, but they are also no longer counted as psychic for a variety of effects." \
+ "For example, losing the ability to distinguish the source of telepathic signals, or taking brain damage when having their mind read." \
+ "On the opposite end of the spectrum, anything that deals bonus damage to psychics will also deal reduced damage to you."
/datum/character_disabilities/low_psi_sensitivity/apply_self(mob/living/carbon/human/H)
H.AddComponent(LOW_PSI_SENSITIVITY_COMPONENT)
/datum/character_disabilities/photosensitivity
name = "Photosensitivity"
desc = "You are highly sensitive to bright lights. " \
+ "Characters with this trait suffer from painful sensations and degraded vision when standing in brightly lit areas without eye protection. "
/datum/character_disabilities/photosensitivity/apply_self(mob/living/carbon/human/H)
H.AddElement(/datum/element/light_sensitivity)
/datum/character_disabilities/nyctophobia
name = "Nyctophobia"
desc = "You have a fear of the dark."
/datum/character_disabilities/nyctophobia/apply_self(mob/living/carbon/human/H)
H.AddElement(/datum/element/dark_afraid)