code:
/obj/item/organ/tail/cat
	name = "cat tail"
	desc = "A severed cat tail. Who's wagging now?"
	icon_state = "tail-cat"
	tail_type = "Cat"
	mutantpart_colored = FALSE
	mutantpart_info = list(MUTANT_INDEX_NAME = "Cat", MUTANT_INDEX_COLOR = list("FFAA00"))

/obj/item/organ/tail/cat/update_overlays()
	. = ..()
	var/image/overlay = image(icon, src, "tail-cat-detail")
	if(length(mutantpart_info))
		overlay.color = mutantpart_info[MUTANT_INDEX_COLOR]
	. += overlay


code:
/obj/item/organ/tail/fluffy
	name = "fluffy tail"
	icon_state = "tail-furry"
	mutantpart_colored = FALSE

/obj/item/organ/tail/fluffy/update_overlays()
	. = ..()
	var/image/overlay = image(icon, src, "tail-furry-detail")
	if(length(mutantpart_info))
		overlay.color = mutantpart_info[MUTANT_INDEX_COLOR]
	. += overlay

/obj/item/organ/tail/fluffy/no_wag
	can_wag = FALSE

repo_name: AnalWerewolf/sundown

license: mit


code:
/obj/item/organ/tail/lizard
	name = "lizard tail"
	desc = "A severed lizard tail. Somewhere, no doubt, a lizard hater is very pleased with themselves."
	icon_state = "tail-lizard"
	tail_type = "Smooth"
	dna_block = DNA_LIZARD_TAIL_BLOCK
	mutantpart_colored = FALSE
	mutantpart_info = list(MUTANT_INDEX_NAME = "Smooth", MUTANT_INDEX_COLOR = list("DDFFDD"))
	/// The mutantpart_key of the spiens
	var/spines_key = "spines"
	/// The sprite accessory this tail gives to the human it's attached to. If null, it will inherit its value from the human's DNA once attached.
	var/list/list/spines_info = list(MUTANT_INDEX_NAME = "None", MUTANT_INDEX_COLOR = list("DDFFDD"))

/obj/item/organ/tail/lizard/update_overlays()
	. = ..()
	var/image/overlay = image(icon, src, "tail-lizard-detail")
	if(length(mutantpart_info))
		overlay.color = mutantpart_info[MUTANT_INDEX_COLOR]
	. += overlay

/obj/item/organ/tail/lizard/Insert(mob/living/carbon/human/tail_owner, special, drop_if_replaced)
	. = ..()
	if(!(tail_owner.status_flags & BUILDING_ORGANS))
		if(LAZYACCESS(spines_info, MUTANT_INDEX_NAME) && ishuman(tail_owner))
			tail_owner.dna.species.mutant_bodyparts[spines_key] = spines_info.Copy()
			tail_owner.update_body()
			update_overlays()

/obj/item/organ/tail/lizard/Remove(mob/living/carbon/human/tail_owner, special)
	. = ..()
	if(!(tail_owner.status_flags & BUILDING_ORGANS))
		if(LAZYACCESS(spines_info, MUTANT_INDEX_NAME) && ishuman(tail_owner))
			if(tail_owner.dna.species.mutant_bodyparts[spines_key])
				spines_info = tail_owner.dna.species.mutant_bodyparts[spines_key].Copy() //Update the info in case it was changed on the person
			tail_owner.dna.species.mutant_bodyparts -= spines_key
			tail_owner.update_body()
			update_overlays()

/obj/item/organ/tail/lizard/build_from_dna(datum/dna/dna_datum, associated_key)
	. = ..()
	if(!dna_datum.species.mutant_bodyparts[spines_key])
		return
	spines_info = dna_datum.species.mutant_bodyparts[spines_key].Copy()

/obj/item/organ/tail/lizard/fake
	name = "fabricated lizard tail"
	desc = "A fabricated severed lizard tail. This one's made of synthflesh. Probably not usable for lizard wine."


code:
/obj/item/organ/tail/monkey
	name = "monkey tail"
	desc = "Return to monkey."
	icon_state = "tail-monkey"
	dna_block = DNA_MONKEY_TAIL_BLOCK
	mutantpart_colored = FALSE
	mutantpart_info = list(MUTANT_INDEX_NAME = "Monkey", MUTANT_INDEX_COLOR = list("FFFFFF"))
	can_wag = FALSE


code:
/obj/item/organ/external/wings
	name = "wings"
	desc = "A pair of wings. Those may or may not allow you to fly... or at the very least flap."
	zone = BODY_ZONE_CHEST
	organ_efficiency = list(ORGAN_SLOT_EXTERNAL_WINGS = 100)
	icon_state = "wings"
	dna_block = DNA_WINGS_BLOCK
	mutantpart_key = "wings"
	mutantpart_colored = TRUE
	mutantpart_info = list(MUTANT_INDEX_NAME = "Bat", MUTANT_INDEX_COLOR = list("335533"))
	///What species get flights thanks to those wings - Important for moth wings
	var/list/flight_for_species
	///Whether the wings should grant flight on insertion.
	var/unconditional_flight = FALSE
	///Whether a wing can be opened by the *wing emote. The sprite use a "_open" suffix, before their layer
	var/can_open = FALSE
	///Whether an openable wing is currently opened
	var/is_open = FALSE
	///Whether the owner of wings has flight thanks to the wings
	var/granted_flight = FALSE

///hud action for starting and stopping flight
/datum/action/innate/flight
	name = "Toggle Flight"
	check_flags = AB_CHECK_CONSCIOUS|AB_CHECK_IMMOBILE
	icon_icon = 'icons/mob/actions/actions_items.dmi'
	button_icon_state = "flight"

/datum/action/innate/flight/Activate()


code:
/obj/item/organ/external/wings/functional
	unconditional_flight = TRUE
	can_open = TRUE


code:
/obj/item/organ/external/wings/functional/angel
	name = "angel wings"
	desc = "A pair of magnificent, feathery wings. They look strong enough to lift you up in the air."
	mutantpart_info = list(MUTANT_INDEX_NAME = "Angel", MUTANT_INDEX_COLOR = list("FFFFFF"))


code:
/obj/item/organ/external/wings/functional/dragon
	name = "dragon wings"
	desc = "A pair of intimidating, membranous wings. They look strong enough to lift you up in the air."
	mutantpart_info = list(MUTANT_INDEX_NAME = "Dragon", MUTANT_INDEX_COLOR = list("880000"))


code:
/obj/item/organ/external/wings/functional/megamoth
	name = "megamoth wings"
	desc = "A pair of horrifyingly large, fuzzy wings. They look strong enough to lift you up in the air."
	dna_block = DNA_MOTH_WINGS_BLOCK
	mutantpart_info = list(MUTANT_INDEX_NAME = "Megamoth", MUTANT_INDEX_COLOR = list("FFFFFF"))


code:
/obj/item/organ/external/wings/functional/moth
	name = "moth wings"
	desc = "A pair of fuzzy moth wings."
	dna_block = DNA_MOTH_WINGS_BLOCK
	flight_for_species = list(SPECIES_MOTH)
	unconditional_flight = FALSE


code:
/obj/item/organ/eyes
	name = "eye"
	icon_state = "eye"
	base_icon_state = "eye"
	desc = "I see you!"
	zone = BODY_ZONE_PRECISE_R_EYE
	organ_efficiency = list(ORGAN_SLOT_EYES = 100) // we actually handle each eye individually, this is fine
	w_class = WEIGHT_CLASS_SMALL
	side = RIGHT_SIDE

	maxHealth = STANDARD_ORGAN_THRESHOLD * 0.5 // weaker because we have 2
	high_threshold = STANDARD_ORGAN_THRESHOLD * 0.35
	low_threshold = STANDARD_ORGAN_THRESHOLD * 0.1

	low_threshold_passed = span_info("Distant objects become somewhat less tangible.")
	high_threshold_passed = span_info("Everything starts to look a lot less clear.")
	now_failing = span_warning("Darkness envelopes you, as your eye goes blind!")
	now_fixed = span_info("Color and shapes are once again perceivable.")
	high_threshold_cleared = span_info("Your vision functions passably once more.")
	low_threshold_cleared = span_info("Your vision is cleared of any ailment.")

	// remember that this is normally DOUBLED (2 eyes)
	organ_volume = 0.5
	max_blood_storage = 5
	current_blood = 5
	blood_req = 1
	oxygen_req = 0.5
	nutriment_req = 0.25
	hydration_req = 0.25

	var/sight_flags = 0
	var/see_in_dark = 2
	var/tint = 0
	/// Set to a hex code to override a mob's eye color
	var/eye_color = ""
	/// Used to store the owner's original eye color, before we got inserted
	var/old_eye_color = "ffffff"
	var/eye_icon_state = "eye"
	var/flash_protect = FLASH_PROTECTION_NONE
	var/see_invisible = SEE_INVISIBLE_LIVING
	var/lighting_alpha
	var/no_glasses = FALSE
	/// Changes how the eyes overlay is applied, makes it apply over the lighting layer
	var/overlay_ignore_lighting = FALSE
	/// Overlay iris when possible
	var/iris_icon_state = "eye-iris"

/obj/item/organ/eyes/left
	zone = BODY_ZONE_PRECISE_L_EYE
	side = LEFT_SIDE

/obj/item/organ/eyes/update_overlays()
	. = ..()
	if(iris_icon_state)
		var/image/iris = image(icon, src, iris_icon_state, layer+0.1)
		iris.color = eye_color || old_eye_color
		. += iris

/obj/item/organ/eyes/update_appearance()
	. = ..()
	transform = (side == RIGHT_SIDE) ? null : matrix(-1, 0, 0, 0, 1, 0)

/obj/item/organ/eyes/switch_side(new_side = RIGHT_SIDE)
	. = ..()
	if(side == RIGHT_SIDE)
		zone = BODY_ZONE_PRECISE_R_EYE
		eye_icon_state = "[initial(eye_icon_state)]-right"
	else
		zone = BODY_ZONE_PRECISE_L_EYE
		eye_icon_state = "[initial(eye_icon_state)]-left"
	if(!owner)
		current_zone = zone
	update_appearance()

/obj/item/organ/eyes/Insert(mob/living/carbon/M, special = FALSE, drop_if_replaced = FALSE, initialising)
	. = ..()
	var/mob/living/carbon/human/HMN = owner
	var/new_side = (current_zone == BODY_ZONE_PRECISE_L_EYE ? LEFT_SIDE : RIGHT_SIDE)
	switch_side(new_side)
	if(istype(HMN))
		if(current_zone == BODY_ZONE_PRECISE_L_EYE)
			old_eye_color = HMN.left_eye_color
			if(eye_color)
				HMN.left_eye_color = eye_color
				HMN.regenerate_icons()
			else
				eye_color = HMN.left_eye_color
		else
			old_eye_color = HMN.right_eye_color
			if(eye_color)
				HMN.right_eye_color = eye_color
				HMN.regenerate_icons()
			else
				eye_color = HMN.right_eye_color
		if(HAS_TRAIT(HMN, TRAIT_NIGHT_VISION) && isnull(lighting_alpha))
			lighting_alpha = LIGHTING_PLANE_ALPHA_NV_TRAIT
	owner.update_eyes()
	owner.update_sight()
	owner.update_tint()
	if(owner.has_dna() && ishuman(owner))
		owner.dna.species.handle_body(owner) //updates eye icon

/obj/item/organ/eyes/Remove(mob/living/carbon/M, special = 0)
	var/mob/living/carbon/human/HMN = M
	if(istype(HMN) && eye_color)
		if(current_zone == BODY_ZONE_PRECISE_L_EYE)
			HMN.left_eye_color = old_eye_color
		else
			HMN.right_eye_color = old_eye_color
	. = ..()
	var/new_side = (current_zone == BODY_ZONE_PRECISE_L_EYE ? LEFT_SIDE : RIGHT_SIDE)
	switch_side(new_side)
	if(istype(HMN))
		HMN.regenerate_icons()
	M.update_eyes()
	M.update_sight()
	M.update_tint()

/obj/item/organ/eyes/applyOrganDamage(amount, maximum, silent)
	. = ..()
	owner?.update_eyes()

/obj/item/organ/eyes/proc/refresh()
	if(ishuman(owner))
		var/mob/living/carbon/human/affected_human = owner
		if(zone == BODY_ZONE_PRECISE_L_EYE)
			old_eye_color = affected_human.left_eye_color
		else
			old_eye_color = affected_human.right_eye_color
		if(eye_color)
			if(zone == BODY_ZONE_PRECISE_L_EYE)
				affected_human.left_eye_color = eye_color
			else
				affected_human.right_eye_color = eye_color
			affected_human.regenerate_icons()
		else
			if(zone == BODY_ZONE_PRECISE_L_EYE)
				eye_color = affected_human.left_eye_color
			else
				eye_color = affected_human.right_eye_color
		if(HAS_TRAIT(affected_human, TRAIT_NIGHT_VISION) && isnull(lighting_alpha))
			lighting_alpha = LIGHTING_PLANE_ALPHA_NV_TRAIT
	owner.update_eyes()
	owner.update_sight()
	owner.update_tint()
	if(owner.has_dna() && ishuman(owner))
		owner.dna.species.handle_body(owner) //updates eye icon

/obj/item/organ/eyes/proc/get_eye_damage_level()
	switch(get_slot_efficiency(ORGAN_SLOT_EYES))
		if(-INFINITY to 1)
			return 3
		if(1 to 50)
			return 2
		if(50 to 80)
			return 1
		if(80 to INFINITY)
			return 0


code:
/obj/item/organ/eyes/night_vision/alien
	name = "alien eye"
	desc = "It turned out they had them after all!"
	sight_flags = SEE_MOBS

/obj/item/organ/eyes/night_vision/alien/l
	zone = BODY_ZONE_PRECISE_L_EYE


code:
/obj/item/organ/eyes/robotic
	name = "robotic eye"
	icon_state = "eye-c"
	desc = "Your vision is augmented."
	status = ORGAN_ROBOTIC
	organ_flags = ORGAN_SYNTHETIC

/obj/item/organ/eyes/robotic/l
	zone = BODY_ZONE_PRECISE_L_EYE

/obj/item/organ/eyes/emp_act(severity)
	. = ..()
	if(!owner || !CHECK_BITFIELD(organ_flags, ORGAN_SYNTHETIC) || . & EMP_PROTECT_SELF)
		return
	if(prob(10 * severity))
		return
	to_chat(owner, span_warning("Static obfuscates your vision!"))
	owner.flash_act(visual = 1)

/obj/item/organ/eyes/robotic/basic
	name = "basic robotic eye"
	desc = "A basic cybernetic eye that restores vision, but at some vulnerability to light."
	eye_color = "5500ff"
	flash_protect = FLASH_PROTECTION_SENSITIVE

/obj/item/organ/eyes/robotic/basic/l
	zone = BODY_ZONE_PRECISE_L_EYE

/obj/item/organ/eyes/robotic/basic/emp_act(severity)
	. = ..()
	if(!owner || !CHECK_BITFIELD(organ_flags, ORGAN_SYNTHETIC) || . & EMP_PROTECT_SELF)
		return
	if(prob(10 * severity))
		applyOrganDamage(10 * severity)
		to_chat(owner, span_warning("Your eyes start to fizzle in their sockets!"))
		do_sparks(2, TRUE, owner)
		owner.death_scream()


code:
/obj/item/organ/eyes/robotic/flashlight
	name = "flashlight eye"
	desc = "It's a flashlight rigged together with some wire. Why would you put these in someone's head?"
	eye_color ="fee5a3"
	icon = 'icons/obj/lighting.dmi'
	icon_state = "flashlight_eyes"
	flash_protect = FLASH_PROTECTION_WELDER
	tint = INFINITY
	var/obj/item/flashlight/eyelight/eye

/obj/item/organ/eyes/robotic/flashlight/emp_act(severity)
	return

/obj/item/organ/eyes/robotic/flashlight/Insert(mob/living/carbon/M, special = FALSE, drop_if_replaced = FALSE)
	. = ..()
	if(!eye)
		eye = new /obj/item/flashlight/eyelight()
	eye.on = TRUE
	eye.forceMove(M)
	eye.update_brightness(M)
	M.become_blind("flashlight_eyes")

/obj/item/organ/eyes/robotic/flashlight/Remove(mob/living/carbon/M, special = 0)
	eye.on = FALSE
	eye.update_brightness(M)
	eye.forceMove(src)
	M.cure_blind("flashlight_eyes")
	return ..()


code:
/obj/item/organ/eyes/fly
	name = "fly eye"
	desc = "This eye seem to stare back no matter the direction you look at it from."

/obj/item/organ/eyes/fly/l
	zone = BODY_ZONE_PRECISE_L_EYE

/obj/item/organ/eyes/fly/Insert(mob/living/carbon/M, special = FALSE)
	. = ..()
	ADD_TRAIT(M, TRAIT_FLASH_SENSITIVE, ORGAN_TRAIT)

/obj/item/organ/eyes/fly/Remove(mob/living/carbon/M, special = FALSE)
	REMOVE_TRAIT(M, TRAIT_FLASH_SENSITIVE, ORGAN_TRAIT)
	return ..()


code:
/obj/item/organ/eyes/night_vision/mushroom
	name = "fung-eye"
	desc = "While on the outside they look inert and dead, the eyes of mushroom people are actually very advanced."

/obj/item/organ/eyes/night_vision/mushroom/l
	zone = BODY_ZONE_PRECISE_L_EYE


code:
#define RGB2EYECOLORSTRING(definitionvar) ("[copytext_char(definitionvar, 2, 3)][copytext_char(definitionvar, 4, 5)][copytext_char(definitionvar, 6, 7)]")

/obj/item/organ/eyes/robotic/glow
	name = "High Luminosity Eye"
	desc = "Special glowing eye, used by snowflakes who want to be special."
	eye_color = "000000"
	actions_types = list(/datum/action/item_action/organ_action/use, /datum/action/item_action/organ_action/toggle)
	var/current_color_string = "#ffffff"
	var/active = FALSE
	var/max_light_beam_distance = 5
	var/light_beam_distance = 5
	var/light_object_range = 2
	var/light_object_power = 2
	var/list/obj/effect/abstract/eye_lighting/eye_lighting
	var/obj/effect/abstract/eye_lighting/on_mob
	var/image/mob_overlay
	var/datum/component/mobhook

/obj/item/organ/eyes/robotic/glow/left
	zone = BODY_ZONE_PRECISE_L_EYE
	side = LEFT_SIDE

/obj/item/organ/eyes/robotic/glow/Initialize()
	. = ..()
	if(side == RIGHT_SIDE)
		mob_overlay = image('modular_septic/icons/mob/human/sprite_accessory/human_face.dmi', "glow_gs_eye-right")
	else
		mob_overlay = image('modular_septic/icons/mob/human/sprite_accessory/human_face.dmi', "glow_gs_eye-left")

/obj/item/organ/eyes/robotic/glow/Destroy()
	terminate_effects()
	. = ..()

/obj/item/organ/eyes/robotic/glow/Remove(mob/living/carbon/M, special = FALSE)
	terminate_effects()
	. = ..()

/obj/item/organ/eyes/robotic/glow/proc/terminate_effects()
	if(owner && active)
		deactivate()
	active = FALSE
	clear_visuals(TRUE)
	STOP_PROCESSING(SSfastprocess, src)

/obj/item/organ/eyes/robotic/glow/ui_action_click(owner, action)
	if(istype(action, /datum/action/item_action/organ_action/toggle))
		toggle_active()
	else if(istype(action, /datum/action/item_action/organ_action/use))
		prompt_for_controls(owner)

/obj/item/organ/eyes/robotic/glow/proc/toggle_active()
	if(active)
		deactivate()
	else
		activate()

/obj/item/organ/eyes/robotic/glow/proc/prompt_for_controls(mob/user)
	var/C = input(owner, "Select Color", "Select color", "#ffffff") as color|null
	if(!C || QDELETED(src) || QDELETED(user) || QDELETED(owner) || owner != user)
		return
	var/range = input(user, "Enter range (0 - [max_light_beam_distance])", "Range Select", 0) as null|num
	var/old_active = active // Get old active because set_distance() -> clear_visuals()  will set it to FALSE.
	set_distance(clamp(range, 0, max_light_beam_distance))
	assume_rgb(C)
	// Reactivate if eyes were already active for real time colour swapping!
	if(old_active)
		activate(FALSE)

/obj/item/organ/eyes/robotic/glow/proc/assume_rgb(newcolor)
	current_color_string = newcolor
	eye_color = RGB2EYECOLORSTRING(current_color_string)
	if(!QDELETED(owner) && ishuman(owner)) //Other carbon mobs don't have eye color.
		owner.dna.species.handle_body(owner)

/obj/item/organ/eyes/robotic/glow/proc/cycle_mob_overlay()
	remove_mob_overlay()
	mob_overlay.color = current_color_string
	add_mob_overlay()

/obj/item/organ/eyes/robotic/glow/proc/add_mob_overlay()
	if(!QDELETED(owner))
		owner.add_overlay(mob_overlay)

/obj/item/organ/eyes/robotic/glow/proc/remove_mob_overlay()
	if(!QDELETED(owner))
		owner.cut_overlay(mob_overlay)

/obj/item/organ/eyes/robotic/glow/emp_act()
	. = ..()
	if(!active || . & EMP_PROTECT_SELF)
		return
	deactivate(silent = TRUE)

/obj/item/organ/eyes/robotic/glow/Insert(mob/living/carbon/M, special = FALSE, drop_if_replaced = FALSE)
	. = ..()
	RegisterSignal(M, COMSIG_ATOM_DIR_CHANGE, .proc/update_visuals)

/obj/item/organ/eyes/robotic/glow/Remove(mob/living/carbon/M, special = FALSE)
	. = ..()
	UnregisterSignal(M, COMSIG_ATOM_DIR_CHANGE)

/obj/item/organ/eyes/robotic/glow/Destroy()
	QDEL_NULL(mobhook) // mobhook is not our component
	return ..()

/obj/item/organ/eyes/robotic/glow/proc/activate(silent = FALSE)
	start_visuals()
	if(!silent)
		to_chat(owner, span_warning("My [src] clicks and makes a whining noise, before shooting out a beam of light!"))
	cycle_mob_overlay()

/obj/item/organ/eyes/robotic/glow/proc/deactivate(silent = FALSE)
	clear_visuals()
	if(!silent)
		to_chat(owner, span_warning("My [src] shuts off!"))
	remove_mob_overlay()

/obj/item/organ/eyes/robotic/glow/proc/update_visuals(datum/source, olddir, newdir)
	if(!active)
		return // Don't update if we're not active!
	if((LAZYLEN(eye_lighting) < light_beam_distance) || !on_mob)
		regenerate_light_effects()
	var/turf/scanfrom = get_turf(owner)
	var/scandir = owner.dir
	if (newdir && scandir != newdir) // COMSIG_ATOM_DIR_CHANGE happens before the dir change, but with a reference to the new direction.
		scandir = newdir
	if(!istype(scanfrom))
		clear_visuals()
	var/turf/scanning = scanfrom
	var/stop = FALSE
	on_mob.set_light_flags(on_mob.light_flags & ~LIGHT_ATTACHED)
	on_mob.forceMove(scanning)
	for(var/i in 1 to light_beam_distance)
		scanning = get_step(scanning, scandir)
		if(IS_OPAQUE_TURF(scanning))
			stop = TRUE
		var/obj/effect/abstract/eye_lighting/L = LAZYACCESS(eye_lighting, i)
		if(stop)
			L.forceMove(src)
		else
			L.forceMove(scanning)

/obj/item/organ/eyes/robotic/glow/proc/clear_visuals(delete_everything = FALSE)
	if(delete_everything)
		QDEL_LIST(eye_lighting)
		QDEL_NULL(on_mob)
	else
		for(var/i in eye_lighting)
			var/obj/effect/abstract/eye_lighting/L = i
			L.forceMove(src)
		if(!QDELETED(on_mob))
			on_mob.set_light_flags(on_mob.light_flags | LIGHT_ATTACHED)
			on_mob.forceMove(src)
	active = FALSE

/obj/item/organ/eyes/robotic/glow/proc/start_visuals()
	if(!islist(eye_lighting))
		regenerate_light_effects()
	if((eye_lighting.len < light_beam_distance) || !on_mob)
		regenerate_light_effects()
	sync_light_effects()
	active = TRUE
	update_visuals()

/obj/item/organ/eyes/robotic/glow/proc/set_distance(dist)
	light_beam_distance = dist
	regenerate_light_effects()

/obj/item/organ/eyes/robotic/glow/proc/regenerate_light_effects()
	clear_visuals(TRUE)
	on_mob = new (src, light_object_range, light_object_power, current_color_string, LIGHT_ATTACHED)
	for(var/i in 1 to light_beam_distance)
		LAZYADD(eye_lighting, new /obj/effect/abstract/eye_lighting(src, light_object_range, light_object_power, current_color_string))
	sync_light_effects()

/obj/item/organ/eyes/robotic/glow/proc/sync_light_effects()
	for(var/e in eye_lighting)
		var/obj/effect/abstract/eye_lighting/eye_lighting = e
		eye_lighting.set_light_color(current_color_string)
	on_mob?.set_light_color(current_color_string)

/obj/effect/abstract/eye_lighting
	light_system = MOVABLE_LIGHT
	var/obj/item/organ/eyes/robotic/glow/parent

/obj/effect/abstract/eye_lighting/Initialize(mapload, light_object_range, light_object_power, current_color_string, light_flags)
	. = ..()
	parent = loc
	if(!istype(parent))
		stack_trace("/obj/effect/abstract/eye_lighting added to improper parent ([loc]). Deleting.")
		return INITIALIZE_HINT_QDEL
	if(!isnull(light_object_range))
		set_light_range(light_object_range)
	if(!isnull(light_object_power))
		set_light_power(light_object_power)
	if(!isnull(current_color_string))
		set_light_color(current_color_string)
	if(!isnull(light_flags))
		set_light_flags(light_flags)


code:
/obj/item/organ/eyes/night_vision/maintenance_adapted
	name = "adapted eye"
	desc = "This red eye looks like a foggy marble. It gives off a particularly worrying glow in the dark."
	flash_protect = FLASH_PROTECTION_SENSITIVE
	eye_color = "f00"
	icon_state = "adapted_eyes"
	eye_icon_state = "eyes_glow"
	overlay_ignore_lighting = TRUE
	var/obj/item/flashlight/eyelight/adapted/adapt_light

/obj/item/organ/eyes/night_vision/maintenance_adapted/l
	zone = BODY_ZONE_PRECISE_L_EYE

/obj/item/organ/eyes/night_vision/maintenance_adapted/Insert(mob/living/carbon/adapted, special = FALSE)
	. = ..()
	//add lighting
	if(!adapt_light)
		adapt_light = new /obj/item/flashlight/eyelight/adapted()
	adapt_light.on = TRUE
	adapt_light.forceMove(adapted)
	adapt_light.update_brightness(adapted)
	//traits
	ADD_TRAIT(adapted, TRAIT_FLASH_SENSITIVE, ORGAN_TRAIT)
	ADD_TRAIT(adapted, TRAIT_UNNATURAL_RED_GLOWY_EYES, ORGAN_TRAIT)

/obj/item/organ/eyes/night_vision/maintenance_adapted/on_life(delta_time, times_fired)
	var/turf/T = get_turf(owner)
	var/lums = T.get_lumcount()
	if(lums > 0.5) //we allow a little more than usual so we can produce light from the adapted eyes
		to_chat(owner, span_userdanger("My eyes! They burn in the light!"))
		applyOrganDamage(10) //blind quickly
		playsound(owner, 'sound/machines/grill/grillsizzle.ogg', 50)
	else
		applyOrganDamage(-10) //heal quickly
	. = ..()

/obj/item/organ/eyes/night_vision/maintenance_adapted/Remove(mob/living/carbon/unadapted, special = FALSE)
	//remove lighting
	adapt_light.on = FALSE
	adapt_light.update_brightness(unadapted)
	adapt_light.forceMove(src)
	//traits
	REMOVE_TRAIT(unadapted, TRAIT_FLASH_SENSITIVE, ORGAN_TRAIT)
	REMOVE_TRAIT(unadapted, TRAIT_UNNATURAL_RED_GLOWY_EYES, ORGAN_TRAIT)
	return ..()


code:
/obj/item/organ/eyes/moth
	name = "moth eye"
	desc = "This eye seems to have increased sensitivity to bright light, with no improvement to low light vision."
	eye_icon_state = "moth-eye"
	icon_state = "eye-compound"
	flash_protect = FLASH_PROTECTION_SENSITIVE

/obj/item/organ/eyes/moth/l
	zone = BODY_ZONE_PRECISE_L_EYE


code:
/obj/item/organ/eyes/night_vision/nightmare
	name = "burning red eyes"
	desc = "Even without their shadowy owner, looking at these eyes gives you a sense of dread."
	icon_state = "burning_eyes"

/obj/item/organ/eyes/night_vision/nightmare/l
	zone = BODY_ZONE_PRECISE_L_EYE


code:
/obj/item/organ/eyes/night_vision
	name = "shadow eyes"
	desc = "A spooky set of eyes that can see in the dark."
	see_in_dark = 8
	lighting_alpha = LIGHTING_PLANE_ALPHA_MOSTLY_VISIBLE
	actions_types = list(/datum/action/item_action/organ_action/use)

/obj/item/organ/eyes/night_vision/l
	zone = BODY_ZONE_PRECISE_L_EYE

/obj/item/organ/eyes/night_vision/ui_action_click()
	sight_flags = initial(sight_flags)
	switch(lighting_alpha)
		if (LIGHTING_PLANE_ALPHA_VISIBLE)
			lighting_alpha = LIGHTING_PLANE_ALPHA_MOSTLY_VISIBLE
		if (LIGHTING_PLANE_ALPHA_MOSTLY_VISIBLE)
			lighting_alpha = LIGHTING_PLANE_ALPHA_MOSTLY_INVISIBLE
		if (LIGHTING_PLANE_ALPHA_MOSTLY_INVISIBLE)
			lighting_alpha = LIGHTING_PLANE_ALPHA_INVISIBLE
		else
			lighting_alpha = LIGHTING_PLANE_ALPHA_VISIBLE
			sight_flags &= ~SEE_BLACKNESS
	owner.update_sight()


code:
// Welding shield implant
/obj/item/organ/eyes/robotic/shield
	name = "shielded robotic eye"
	desc = "These reactive micro-shields will protect you from welders and flashes without obscuring your vision."
	flash_protect = FLASH_PROTECTION_WELDER

/obj/item/organ/eyes/robotic/shield/l
	zone = BODY_ZONE_PRECISE_L_EYE

/obj/item/organ/eyes/robotic/shield/emp_act(severity)
	return


code:
/obj/item/organ/eyes/snail
	name = "snail eye"
	desc = "This eye seem to have a large range, but might be cumbersome with glasses."
	eye_icon_state = "snail_eyes"
	icon_state = "snail_eyeballs"

/obj/item/organ/eyes/snail/l
	zone = BODY_ZONE_PRECISE_L_EYE


code:
/obj/item/organ/eyes/robotic/thermals
	name = "thermal eye"
	desc = "This cybernetic eye implants will give you thermal vision. Vertical slit pupil included."
	eye_color = "FC0"
	sight_flags = SEE_MOBS
	lighting_alpha = LIGHTING_PLANE_ALPHA_MOSTLY_VISIBLE
	flash_protect = FLASH_PROTECTION_SENSITIVE
	see_in_dark = 8

/obj/item/organ/eyes/robotic/thermals/l
	zone = BODY_ZONE_PRECISE_L_EYE


code:
/obj/item/organ/eyes/robotic/xray
	name = "\improper X-ray eye"
	desc = "This cybernetic eye will give you X-ray vision. Blinking is futile."
	eye_color = "000"
	see_in_dark = 8
	sight_flags = SEE_MOBS | SEE_OBJS | SEE_TURFS

/obj/item/organ/eyes/robotic/xray/l
	zone = BODY_ZONE_PRECISE_L_EYE


code:
/obj/item/organ/eyes/night_vision/zombie
	name = "undead eye"
	desc = "Somewhat counterintuitively, this half-rotten eye actually has superior vision to that of a living human."

/obj/item/organ/eyes/night_vision/zombie/l
	zone = BODY_ZONE_PRECISE_L_EYE


code:
/obj/item/organ/genital
	name = "genital"
	desc = "The most treasured type of organ."
	maxHealth = STANDARD_ORGAN_THRESHOLD * 0.5
	high_threshold = STANDARD_ORGAN_THRESHOLD * 0.4
	low_threshold = STANDARD_ORGAN_THRESHOLD * 0.1
	pain_multiplier = 1.5 //oof

	//should be about right most of the time
	organ_volume = 0.5

	reagent_vol = 60

	///If we produce any reagent, set it here
	var/fluid_reagent
	///The rate we produce fluids at, per second, when we have an owner
	var/fluid_production_rate = 0.2 //almost 4 minutes to fill up with cum
	///The organ slot we actually provide our fluid to - If empty, fill ourselves
	var/fluid_receiving_slot
	///Amount of fluid we expel on orgasm
	var/fluid_amount_orgasm = 15
	///The splatter we create if we don't want to create a fluid flood
	var/splatter_path

	///General genital flags
	var/genital_flags = GENITAL_CAN_CLIMAX
	///Size value of the genital, needs to be translated to proper lengths/diameters/cups
	var/genital_size = 1
	///Sprite name of the genital, it's what shows up on character creation
	var/genital_name = "Human"
	///Type of the genital - For penises tapered/horse/human etc, for breasts quadruple/sixtuple etc... Used in icon_state
	var/genital_type = "human"
	///Used for input from the user whether to show a genital through clothing or not, always or never etc.
	var/genital_visibility = GENITAL_HIDDEN_BY_CLOTHES
	///Used for determining what sprite is being used, derrives from size and type
	var/sprite_suffix = ""
	///Whether the organ is aroused, matters for sprites, use AROUSAL_CANT, AROUSAL_NONE, AROUSAL_PARTIAL or AROUSAL_FULL
	var/arousal_state = AROUSAL_NONE
	///What we change our greyscale_colors var to when skintoned
	var/skintoned_colors = "#fcccb3"

/obj/item/organ/genital/Initialize()
	. = ..()
	if(!reagents)
		create_reagents(reagent_vol, REAGENT_HOLDER_ALIVE)
	else
		reagents.flags |= REAGENT_HOLDER_ALIVE

/obj/item/organ/genital/on_life(delta_time, times_fired)
	. = ..()
	if(is_failing() || !fluid_reagent)
		return
	var/efficiency = get_slot_efficiency(organ_efficiency[1])/ORGAN_OPTIMAL_EFFICIENCY
	if(fluid_production_rate && length(organ_efficiency) && (reagents.total_volume < reagents.maximum_volume))
		reagents.add_reagent(fluid_reagent, fluid_production_rate * efficiency * delta_time, data = owner.get_blood_dna_list())
		owner.adjust_nutrition(-nutriment_req)
	if(fluid_receiving_slot)
		var/list/receiving_organs = owner.getorganslotlist(fluid_receiving_slot)
		for(var/obj/item/organ/receiver as anything in receiving_organs)
			reagents.trans_id_to(receiver, fluid_reagent, fluid_production_rate * efficiency, TRUE)

/obj/item/organ/genital/examine(mob/user)
	. = ..()
	var/peepee_exam = get_genital_examine(TRUE)
	if(peepee_exam)
		. |= peepee_exam

/obj/item/organ/genital/update_icon_state()
	. = ..()
	update_sprite_suffix()
	icon_state = "[base_icon_state][sprite_suffix ? "_[sprite_suffix]" : ""]"

/obj/item/organ/genital/build_from_dna(datum/dna/dna_datum, associated_key)
	if(!dna_datum.species.mutant_bodyparts[associated_key])
		return
	mutantpart_key = associated_key
	mutantpart_info = dna_datum.species.mutant_bodyparts[associated_key].Copy()
	var/datum/sprite_accessory/genital/SA = GLOB.sprite_accessories[associated_key][dna_datum.species.mutant_bodyparts[associated_key][MUTANT_INDEX_NAME]]
	genital_name = SA.name
	genital_type = SA.icon_state
	var/mob/living/carbon/human/human = dna_datum.holder
	if(dna_datum.features["uses_skintones"] && istype(human) && human.skin_tone)
		if(human)
			skintoned_colors = sanitize_hexcolor(skintone2hex(human.skin_tone), 6, TRUE)
		var/skin_tone_sanitized = sanitize_hexcolor(skintoned_colors, 6)
		mutantpart_info[MUTANT_INDEX_COLOR] = list(skin_tone_sanitized, skin_tone_sanitized, skin_tone_sanitized)
		set_greyscale(skintoned_colors)
	else
		set_greyscale(sanitize_hexcolor(mutantpart_info[MUTANT_INDEX_COLOR][1], 6, TRUE, "#FFFFFF"))
	update_sprite_suffix()

///Handle cooming
/obj/item/organ/genital/proc/handle_climax(atom/target, method = INGEST)
	var/efficiency = get_slot_efficiency(organ_efficiency[1])/ORGAN_OPTIMAL_EFFICIENCY
	if(!efficiency)
		return
	var/volume = fluid_amount_orgasm * efficiency
	var/datum/reagents/cum_holder = new(1000)
	reagents.trans_id_to(cum_holder, fluid_reagent, volume)
	if(isturf(target))
		if(!splatter_path)
			var/turf/cummy_turf = target
			cummy_turf.add_liquid_from_reagents(cum_holder)
		else
			var/obj/effect/decal/cleanable/cummy_decal = new splatter_path(target)
			cummy_decal.reagents.remove_all(cummy_decal.reagents.total_volume)
			cum_holder.trans_to(cummy_decal, cum_holder.total_volume, methods = method)
	else
		cum_holder.trans_to(target, cum_holder.total_volume, methods = method)
	qdel(cum_holder)

///Sets the size and updates the sprite
/obj/item/organ/genital/proc/set_size(size)
	genital_size = size
	update_sprite_suffix()

///Checks if the genital is visible
/obj/item/organ/genital/proc/is_visible()
	. = FALSE
	if(!owner)
		return TRUE
	switch(genital_visibility)
		if(GENITAL_SKIP_VISIBILITY, GENITAL_NEVER_SHOW)
			return FALSE
		if(GENITAL_HIDDEN_BY_CLOTHES)
			var/mob/living/carbon/human/human_owner = owner
			if(!istype(human_owner))
				return TRUE
			switch(current_zone)
				if(BODY_ZONE_PRECISE_GROIN)
					if(human_owner.underwear && (human_owner.underwear != "Nude"))
						return FALSE
				if(BODY_ZONE_CHEST)
					if(human_owner.undershirt && (human_owner.undershirt != "Nude"))
						return FALSE
			var/obj/item/bodypart/bp_required = owner.get_bodypart_nostump(current_zone)
			if(bp_required && !LAZYLEN(human_owner.clothingonpart(bp_required)) )
				return TRUE
		if(GENITAL_ALWAYS_SHOW)
			var/obj/item/bodypart/bp_required = owner.get_bodypart_nostump(current_zone)
			if(bp_required)
				return TRUE

///Basically the sprite suffix used for rendering
/obj/item/organ/genital/proc/update_sprite_suffix()
	return

///Translates size so it gets used in the sprite suffix
/obj/item/organ/genital/proc/translate_size_to_suffix(size = genital_size)
	return genital_size

///Translates size so it gets used in the get_genital_examine() proc
/obj/item/organ/genital/proc/translate_size_to_examine(size = genital_size)
	return genital_size

///Gets a string based on arousal for the examine
/obj/item/organ/genital/proc/get_arousal_examine()
	return

/obj/item/organ/genital/proc/get_genital_examine(direct_examine = FALSE)
	if(!is_visible())
		return
	if(direct_examine || !owner)
		return get_direct_examine()
	else
		return get_owner_examine()

/obj/item/organ/genital/proc/get_direct_examine()
	return

/obj/item/organ/genital/proc/get_owner_examine()
	return


code:
/obj/item/organ/genital/breasts
	name = "jugs"
	desc = "Does not belong on reptiles."
	organ_efficiency = list(ORGAN_SLOT_BREASTS = 100)
	icon = 'modular_septic/icons/obj/items/genitalia/jugs.dmi'
	icon_state = "breasts"
	base_icon_state = "breasts"
	zone = BODY_ZONE_CHEST
	fluid_reagent = /datum/reagent/consumable/milk
	genital_type = "pair"
	mutantpart_key = "breasts"
	mutantpart_info = list(MUTANT_INDEX_NAME = "Pair", MUTANT_INDEX_COLOR = list("FEB"))
	arousal_state = AROUSAL_CANT
	greyscale_config = /datum/greyscale_config/breasts
	skintoned_colors = "#fcccb3"

/obj/item/organ/genital/breasts/update_sprite_suffix()
	sprite_suffix = "[genital_type ? genital_type : ""]_[translate_size_to_suffix(genital_size)]"
	return sprite_suffix

/obj/item/organ/genital/breasts/translate_size_to_examine(size = genital_size)
	var/size_string = capitalize_like_old_man(translate_jug_size(size))
	if(size_string == "Flatchested")
		return "flatchested"
	else
		return "[capitalize_like_old_man(translate_jug_size(size))]-cup"

/obj/item/organ/genital/breasts/translate_size_to_suffix(size = genital_size)
	var/size_suffix = "[clamp(FLOOR(genital_size, 1), 1, 5)]"
	return size_suffix

/obj/item/organ/genital/breasts/get_arousal_examine()
	var/returned_string = ""
	if(arousal_state == AROUSAL_FULL)
		if(fluid_production_rate)
			returned_string += span_notice(" The nipples seem hard and perky, and are also leaking milk.")
		else
			returned_string += span_notice(" The nipples seem hard and perky.")
	return returned_string

/obj/item/organ/genital/breasts/get_direct_examine()
	var/parsed_name = lowertext(genital_name)
	if(parsed_name == "pair")
		parsed_name = "pair of"
	var/result = span_notice("\A [translate_size_to_examine(genital_size)] [parsed_name] [name].")
	var/arousal = get_arousal_examine()
	if(arousal)
		result += arousal
	return result

/obj/item/organ/genital/breasts/get_owner_examine()
	var/parsed_name = lowertext(genital_name)
	if(parsed_name == "pair")
		parsed_name = "pair of"
	var/result = span_notice("[owner.p_they(TRUE)] [owner.p_have()] \a [translate_size_to_examine(genital_size)] [parsed_name] [name].")
	var/arousal = get_arousal_examine()
	if(arousal)
		result += arousal
	return result

/obj/item/organ/genital/breasts/build_from_dna(datum/dna/dna_datum, associated_key)
	. = ..()
	if(!dna_datum.species.mutant_bodyparts[associated_key])
		return
	fluid_production_rate = initial(fluid_production_rate) * dna_datum.features["breasts_lactation"]
	set_size(dna_datum.features["breasts_size"])


code:
/obj/item/organ/genital/penis
	name = "knob"
	desc = "I staple tapeworms on my penis, so the flesh will drink brainjuice from your fetus."
	icon = 'modular_septic/icons/obj/items/genitalia/knob.dmi'
	icon_state = "penis"
	base_icon_state = "penis"
	organ_efficiency = list(ORGAN_SLOT_PENIS = 100)
	zone = BODY_ZONE_PRECISE_GROIN
	mutantpart_key = "penis"
	mutantpart_info = list(MUTANT_INDEX_NAME = "Human", MUTANT_INDEX_COLOR = list("FFEEBB"))
	greyscale_config = /datum/greyscale_config/penis
	skintoned_colors = "#fcccb3"
	genital_size = PENIS_DEFAULT_GIRTH
	var/genital_girth = PENIS_DEFAULT_GIRTH
	var/genital_sheath = SHEATH_NONE
	var/circumcised = FALSE

/obj/item/organ/genital/penis/update_sprite_suffix()
	if((arousal_state != AROUSAL_FULL) && genital_sheath && (genital_sheath != SHEATH_NONE))
		sprite_suffix = "[lowertext(genital_sheath)]_[arousal_state >= AROUSAL_PARTIAL ? TRUE : FALSE]"
		return sprite_suffix
	sprite_suffix = "[genital_type ? genital_type : ""]_[translate_size_to_suffix(genital_size)]_[arousal_state >= AROUSAL_FULL ? TRUE : FALSE]"
	return sprite_suffix

/obj/item/organ/genital/penis/translate_size_to_suffix(size = genital_size)
	var/size_suffix = "1"
	switch(FLOOR(genital_size, 1))
		//king
		if(-INFINITY to 12)
			size_suffix = "1"
		//acceptable human being
		if(12 to 16)
			size_suffix = "2"
		//dongoloid
		if(16 to 24)
			size_suffix = "3"
		//dumbass
		else
			size_suffix = "4"
	return size_suffix

/obj/item/organ/genital/penis/translate_size_to_examine(size = genital_size)
	return translate_knob_size(size)

/obj/item/organ/genital/penis/get_arousal_examine()
	var/returned_string = ""
	switch(arousal_state)
		if(AROUSAL_PARTIAL)
			returned_string = span_notice(" It is partially erect.")
		if(AROUSAL_FULL)
			returned_string = span_notice(" It is rock hard.")
	return returned_string

/obj/item/organ/genital/penis/get_direct_examine()
	var/parsed_name = lowertext(genital_name)
	var/result = span_notice("\A [circumcised ? "circumcised" : "intact"] [translate_size_to_examine(genital_size)] long, [translate_girth_to_examine(genital_girth)] circumference [parsed_name] [name].")
	var/arousal = get_arousal_examine()
	if(arousal)
		result += arousal
	return result

/obj/item/organ/genital/penis/get_owner_examine()
	var/parsed_name = lowertext(genital_name)
	var/result = span_notice("[owner.p_they(TRUE)] [owner.p_have()] \a [circumcised ? "mutilated" : "intact"] [translate_size_to_examine(genital_size)] long, [translate_girth_to_examine(genital_girth)] circumference [parsed_name] [name].")
	var/arousal = get_arousal_examine()
	if(arousal)
		result += arousal
	return result

/obj/item/organ/genital/penis/build_from_dna(datum/dna/dna_datum, associated_key)
	. = ..()
	if(!dna_datum.species.mutant_bodyparts[associated_key])
		return
	genital_girth = dna_datum.features["penis_girth"]
	var/datum/sprite_accessory/genital/penis/penis_accessory = GLOB.sprite_accessories[associated_key][dna_datum.species.mutant_bodyparts[associated_key][MUTANT_INDEX_NAME]]
	if(penis_accessory.can_have_sheath)
		genital_sheath = dna_datum.features["penis_sheath"]
	set_size(dna_datum.features["penis_size"])

/obj/item/organ/genital/penis/proc/translate_girth_to_examine(girth = genital_girth)
	return "[girth]cm"


code:
/obj/item/organ/genital/penis/knotted
	mutantpart_info = list(MUTANT_INDEX_NAME = "Knotted", MUTANT_INDEX_COLOR = list("FFEEBB"))
	genital_sheath = SHEATH_NORMAL


code:
/obj/item/organ/genital/testicles
	name = "gonads"
	desc = "Some balls are held for charity, and some for fancy dress. But when they're held for pleasure, \
			they're the balls that I like best."
	icon = 'modular_septic/icons/obj/items/genitalia/gonads.dmi'
	icon_state = "testicles"
	base_icon_state = "testicles"
	organ_efficiency = list(ORGAN_SLOT_TESTICLES = 100)
	zone = BODY_ZONE_PRECISE_GROIN
	fluid_reagent = /datum/reagent/consumable/cum
	fluid_receiving_slot = ORGAN_SLOT_PENIS
	genital_flags = NONE
	genital_type = "pair"
	mutantpart_key = "testicles"
	mutantpart_info = list(MUTANT_INDEX_NAME = "Pair", MUTANT_INDEX_COLOR = list("FFEEBB"))
	arousal_state = AROUSAL_CANT
	greyscale_config = /datum/greyscale_config/testicles
	skintoned_colors = "#fcccb3"

/obj/item/organ/genital/testicles/update_sprite_suffix()
	sprite_suffix = "[genital_type ? genital_type : ""]_[translate_size_to_suffix(genital_size)]"
	return sprite_suffix

/obj/item/organ/genital/testicles/translate_size_to_examine(size = genital_size)
	return translate_gonad_size(size)

/obj/item/organ/genital/testicles/translate_size_to_suffix(size = genital_size)
	var/size_suffix = "[clamp(FLOOR(genital_size, 1), 1, 3)]"
	return size_suffix

/obj/item/organ/genital/testicles/get_direct_examine()
	var/parsed_name = lowertext(genital_name)
	var/result = span_notice("\A [translate_size_to_examine(genital_size)] [parsed_name] [name].")
	return result

/obj/item/organ/genital/testicles/get_owner_examine()
	var/parsed_name = lowertext(genital_name)
	var/result = span_notice("[owner.p_they(TRUE)] [owner.p_have()] \a [translate_size_to_examine(genital_size)] [parsed_name] [name].")
	return result

/obj/item/organ/genital/testicles/build_from_dna(datum/dna/dna_datum, associated_key)
	. = ..()
	set_size(dna_datum.features["balls_size"])


code:
/obj/item/organ/genital/vagina
	name = "cunt"
	desc = "Shut the fuck up. You're a fucking cunt. Shut the fuck up, you're a stupid cunt, suck my dick."
	icon = 'modular_septic/icons/obj/items/genitalia/cunt.dmi'
	icon_state = "vagina"
	base_icon_state = "vagina"
	organ_efficiency = list(ORGAN_SLOT_VAGINA = 100)
	zone = BODY_ZONE_PRECISE_GROIN
	fluid_reagent = /datum/reagent/consumable/femcum
	mutantpart_key = "vagina"
	mutantpart_info = list(MUTANT_INDEX_NAME = "Human", MUTANT_INDEX_COLOR = list("FFEEBB"))
	greyscale_config = /datum/greyscale_config/vagina
	skintoned_colors = "#fcccb3"

/obj/item/organ/genital/vagina/update_sprite_suffix()
	sprite_suffix = "[genital_type ? genital_type : ""]"
	return sprite_suffix

/obj/item/organ/genital/vagina/translate_size_to_suffix(size = genital_size)
	return

/obj/item/organ/genital/vagina/translate_size_to_examine(size = genital_size)
	return

/obj/item/organ/genital/vagina/get_arousal_examine()
	var/returned_string = ""
	switch(arousal_state)
		if(AROUSAL_PARTIAL)
			returned_string = span_notice(" It's glistening with arousal.")
		if(AROUSAL_FULL)
			returned_string = span_notice(" It's bright and dripping with arousal.")
	return returned_string

/obj/item/organ/genital/vagina/get_direct_examine()
	var/parsed_name = lowertext(genital_name)
	var/result = span_notice("\A [parsed_name] [name].")
	var/arousal = get_arousal_examine()
	if(arousal)
		result += arousal
	return result

/obj/item/organ/genital/vagina/get_owner_examine()
	var/parsed_name = lowertext(genital_name)
	var/result = span_notice("[owner.p_they(TRUE)] [owner.p_have()] \a [parsed_name][parsed_name == "cloaca" ? "" : " [name]"].")
	var/arousal = get_arousal_examine()
	if(arousal)
		result += arousal
	return result


code:
/obj/item/organ/genital/womb
	name = "womb"
	desc = "Acidic Vaginal Liquid Explosion Generated By Mass Amounts Of Filthy Fecal Fisting \
			And Sadistic Septic Syphilic Sodomy Inside The Infected Maggot Infested Womb Of A Molested Nun \
			Dying Under The Roof Of A Burning Church While A Priest Watches And Ejaculates In Immense Perverse \
			Pleasure Over His First Fresh Fetus."
	icon = 'modular_septic/icons/obj/items/genitalia/womb.dmi'
	icon_state = "womb"
	base_icon_state = "womb"
	organ_efficiency = list(ORGAN_SLOT_WOMB = 100)
	zone = BODY_ZONE_PRECISE_GROIN
	genital_flags = NONE
	genital_visibility = GENITAL_SKIP_VISIBILITY
	arousal_state = AROUSAL_CANT
	greyscale_config = /datum/greyscale_config/womb
	skintoned_colors = "#F99B88"

/obj/item/organ/genital/womb/Initialize()
	. = ..()
	if(skintoned_colors)
		set_greyscale(skintoned_colors)

/obj/item/organ/genital/womb/build_from_dna(datum/dna/dna_datum, associated_key)
	return


code:
/obj/item/organ/heart
	name = "heart"
	desc = "Following your HEART shall be the whole of LAW."
	icon_state = "heart"
	zone = BODY_ZONE_CHEST
	organ_efficiency = list(ORGAN_SLOT_HEART = 100)
	w_class = WEIGHT_CLASS_NORMAL

	low_threshold_passed = span_info("Prickles of pain appear then die out from within your chest...")
	high_threshold_passed = span_warning("Something inside your chest hurts, and the pain isn't subsiding. You notice yourself breathing far faster than before.")
	now_fixed = span_info("Your heart begins to beat again.")
	high_threshold_cleared = span_info("The pain in your chest has died down, and your breathing becomes more relaxed.")

	attack_verb_continuous = list("beats", "thumps")
	attack_verb_simple = list("beat", "thump")

	// the volume shouldn't worry you, the chest is full of organs - also getting shot in the heart sucks
	organ_volume = 1
	max_blood_storage = 100
	current_blood = 100
	blood_req = 10
	oxygen_req = 5
	nutriment_req = 5
	hydration_req = 5

	/// Have we been bypassed to avoid nasty blockages?
	var/open = FALSE
	/// If we're not beating that is not a good sign
	var/beating = TRUE

/obj/item/organ/heart/Initialize()
	. = ..()
	addtimer(CALLBACK(src, .proc/stop_if_unowned), 8 SECONDS)

/obj/item/organ/heart/on_life(delta_time, times_fired)
	. = ..()
	if(!failed && is_failing() && owner.needs_heart()) // heart broke, stopped beating, death imminent...
		if(owner.stat == CONSCIOUS)
			owner.visible_message(span_danger("<b>[owner]</b> clutches at [owner.p_their()] [parse_zone(BODY_ZONE_CHEST)]!"))
		failed = TRUE

/obj/item/organ/heart/is_working()
	if(owner)
		return (..() && beating)
	return ..()

/obj/item/organ/heart/is_failing()
	if(owner)
		return (..() || !beating)
	return ..()

/obj/item/organ/heart/Remove(mob/living/carbon/M, special = 0)
	. = ..()
	if(!special)
		addtimer(CALLBACK(src, .proc/stop_if_unowned), 12 SECONDS)

/obj/item/organ/heart/attack_self(mob/user)
	. = ..()
	if(!beating)
		user.visible_message(span_notice("[user] squeezes [src] to make it beat again!"), \
					span_notice("You squeeze [src] to make it beat again!"))
		Restart()
		addtimer(CALLBACK(src, .proc/stop_if_unowned), 8 SECONDS)

/obj/item/organ/heart/proc/can_stop()
	if(beating)
		return TRUE
	return FALSE

/obj/item/organ/heart/proc/stop_if_unowned()
	if(!owner)
		Stop()

/obj/item/organ/heart/proc/Stop()
	var/old_beating = beating
	beating = FALSE
	update_appearance()
	if(owner && old_beating)
		var/deathsdoor = TRUE
		for(var/thing in (owner.getorganslotlist(ORGAN_SLOT_HEART) - src))
			var/obj/item/organ/heart/heart = thing
			if(heart.beating)
				deathsdoor = FALSE
		if(deathsdoor)
			to_chat(owner, span_flashinguserdanger("I'm knocking on death's door!"))
	return TRUE

/obj/item/organ/heart/proc/Restart()
	var/old_beating = beating
	beating = TRUE
	update_appearance()
	if(owner && !old_beating)
		to_chat(owner, span_userdanger("My [name] beats again!"))
	return TRUE

/obj/item/organ/heart/on_eat_from(eater, feeder)
	. = ..()
	Stop()

/obj/item/organ/heart/get_availability(datum/species/S)
	return (!(NOBLOOD in S.species_traits) && !(TRAIT_STABLEHEART in S.inherent_traits))


code:
/obj/item/organ/heart/cursed
	name = "cursed heart"
	desc = "A heart that, when inserted, will force you to pump it manually."
	icon_state = "cursedheart-off"
	base_icon_state = "cursedheart"
	min_decay_factor = 0
	max_decay_factor = 0
	actions_types = list(/datum/action/item_action/organ_action/cursed_heart)

	var/last_pump = 0
	var/add_colour = TRUE //So we're not constantly recreating colour datums
	var/pump_delay = 30 //you can pump 1 second early, for lag, but no more (otherwise you could spam heal)
	var/blood_loss = 100 //600 blood is human default, so 5 failures (below 122 blood is where humans die because reasons?)

	//How much to heal per pump, negative numbers would HURT the player
	var/heal_brute = 0
	var/heal_burn = 0
	var/heal_oxy = 0

/obj/item/organ/heart/cursed/attack(mob/living/carbon/human/H, mob/living/carbon/human/user, obj/target)
	if(H == user && istype(H))
		playsound(user,'sound/effects/singlebeat.ogg',40,TRUE)
		user.temporarilyRemoveItemFromInventory(src, TRUE)
		Insert(user)
	else
		return ..()

/obj/item/organ/heart/cursed/on_life(delta_time, times_fired)
	. = ..()
	if(world.time > (last_pump + pump_delay))
		if(ishuman(owner) && owner.client) //While this entire item exists to make people suffer, they can't control disconnects.
			var/mob/living/carbon/human/H = owner
			if(H.dna && !(NOBLOOD in H.dna.species.species_traits))
				H.blood_volume = max(H.blood_volume - blood_loss, 0)
				to_chat(H, span_userdanger("You have to keep pumping your blood!"))
				if(add_colour)
					H.add_client_colour(/datum/client_colour/cursed_heart_blood) //bloody screen so real
					add_colour = FALSE
		else
			last_pump = world.time //lets be extra fair *sigh*

/obj/item/organ/heart/cursed/Insert(mob/living/carbon/M, special = 0)
	..()
	if(owner)
		to_chat(owner, span_userdanger("Your heart has been replaced with a cursed one, you have to pump this one manually otherwise you'll die!"))

/obj/item/organ/heart/cursed/Remove(mob/living/carbon/M, special = 0)
	..()
	M.remove_client_colour(/datum/client_colour/cursed_heart_blood)

/datum/action/item_action/organ_action/cursed_heart
	name = "Pump your blood"

//You are now brea- pumping blood manually
/datum/action/item_action/organ_action/cursed_heart/Trigger()
	. = ..()
	if(. && istype(target, /obj/item/organ/heart/cursed))
		var/obj/item/organ/heart/cursed/cursed_heart = target

		if(world.time < (cursed_heart.last_pump + (cursed_heart.pump_delay-10))) //no spam
			to_chat(owner, span_userdanger("Too soon!"))
			return

		cursed_heart.last_pump = world.time
		playsound(owner,'sound/effects/singlebeat.ogg',40,TRUE)
		to_chat(owner, span_notice("Your heart beats."))

		var/mob/living/carbon/human/H = owner
		if(istype(H))
			if(H.dna && !(NOBLOOD in H.dna.species.species_traits))
				H.blood_volume = min(H.blood_volume + cursed_heart.blood_loss*0.5, BLOOD_VOLUME_MAXIMUM)
				H.remove_client_colour(/datum/client_colour/cursed_heart_blood)
				cursed_heart.add_colour = TRUE
				H.adjustBruteLoss(-cursed_heart.heal_brute)
				H.adjustFireLoss(-cursed_heart.heal_burn)
				H.adjustOxyLoss(-cursed_heart.heal_oxy)

/datum/client_colour/cursed_heart_blood
	priority = 100 //it's an indicator you're dying, so it's very high priority
	colour = "red"


code:
/obj/item/organ/heart/cybernetic
	name = "basic cybernetic heart"
	desc = "A basic electronic device designed to mimic the functions of an organic human heart."
	icon_state = "heart-c"
	organ_flags = ORGAN_SYNTHETIC
	maxHealth = STANDARD_ORGAN_THRESHOLD*0.75 //This also hits defib timer, so a bit higher than its less important counterparts

	emp_vulnerability = 80 //Chance of permanent effects if emp-ed.
	var/dose_available = FALSE
	var/rid = /datum/reagent/medicine/epinephrine
	var/ramount = 10

/obj/item/organ/heart/cybernetic/tier2
	name = "cybernetic heart"
	desc = "An electronic device designed to mimic the functions of an organic human heart. Also holds an emergency dose of epinephrine, used automatically after facing severe trauma."
	icon_state = "heart-c-u"
	maxHealth = 1.5 * STANDARD_ORGAN_THRESHOLD
	dose_available = TRUE
	emp_vulnerability = 40

/obj/item/organ/heart/cybernetic/tier3
	name = "upgraded cybernetic heart"
	desc = "An electronic device designed to mimic the functions of an organic human heart. Also holds an emergency dose of epinephrine, used automatically after facing severe trauma. This upgraded model can regenerate its dose after use."
	icon_state = "heart-c-u2"
	maxHealth = 2 * STANDARD_ORGAN_THRESHOLD
	dose_available = TRUE
	emp_vulnerability = 20

/obj/item/organ/heart/emp_act(severity)
	. = ..()
	// If the owner doesn't need a heart, we don't need to do anything with it.
	if(!owner || !CHECK_BITFIELD(organ_flags, ORGAN_SYNTHETIC) || . & EMP_PROTECT_SELF)
		return
	if(!COOLDOWN_FINISHED(src, severe_cooldown)) //So we cant just spam emp to kill people.
		owner.Dizzy(10)
		owner.losebreath += 10
		COOLDOWN_START(src, severe_cooldown, 20 SECONDS)
	if(prob(emp_vulnerability/severity)) //Chance of permanent effects
		organ_flags |= ORGAN_SYNTHETIC_EMP //Starts organ faliure - gonna need replacing soon.
		Stop()
		if(owner.stat == CONSCIOUS)
			owner.visible_message(span_danger("<b>[owner]</b> clutches at [owner.p_their()] [parse_zone(BODY_ZONE_CHEST)]!"))
		failed = TRUE
		addtimer(CALLBACK(src, .proc/Restart), 10 SECONDS)

/obj/item/organ/heart/cybernetic/on_life(delta_time, times_fired)
	. = ..()
	if(dose_available && owner.health <= owner.crit_threshold && !owner.reagents.has_reagent(rid))
		used_dose()

/obj/item/organ/heart/cybernetic/proc/used_dose()
	owner.reagents.add_reagent(rid, ramount)
	dose_available = FALSE

/obj/item/organ/heart/cybernetic/tier3/used_dose()
	. = ..()
	addtimer(VARSET_CALLBACK(src, dose_available, TRUE), 5 MINUTES)


code:
/obj/item/organ/heart/ethereal
	name = "Crystal core"
	icon_state = "ethereal_heart" //Welp. At least it's more unique in functionaliy.
	desc = "A crystal-like organ that functions similarly to a heart for Ethereals. It can revive its owner."
	///Cooldown for the next time we can crystalize
	COOLDOWN_DECLARE(crystalize_cooldown)
	///Timer ID for when we will be crystalized, If not preparing this will be null.
	var/crystalize_timer_id
	///The current crystal the ethereal is in, if any
	var/obj/structure/ethereal_crystal/current_crystal
	///Damage taken during crystalization, resets after it ends
	var/crystalization_process_damage = 0
	///Color of the heart, is set by the species on gain
	var/ethereal_color = "#9c3030"

/obj/item/organ/heart/ethereal/Initialize()
	. = ..()
	add_atom_colour(ethereal_color, FIXED_COLOUR_PRIORITY)

/obj/item/organ/heart/ethereal/Insert(mob/living/carbon/M, special = 0)
	. = ..()
	RegisterSignal(M, COMSIG_MOB_STATCHANGE, .proc/on_stat_change)
	RegisterSignal(M, COMSIG_LIVING_POST_FULLY_HEAL, .proc/on_owner_fully_heal)
	RegisterSignal(M, COMSIG_PARENT_PREQDELETED, .proc/owner_deleted)

/obj/item/organ/heart/ethereal/Remove(mob/living/carbon/M, special = 0)
	UnregisterSignal(M, list(COMSIG_MOB_STATCHANGE, COMSIG_LIVING_POST_FULLY_HEAL, COMSIG_PARENT_PREQDELETED))
	REMOVE_TRAIT(M, TRAIT_CORPSELOCKED, SPECIES_TRAIT)
	stop_crystalization_process(M)
	QDEL_NULL(current_crystal)
	return ..()

/obj/item/organ/heart/ethereal/update_overlays()
	. = ..()
	var/image/shine = mutable_appearance(icon, src, icon_state = "[icon_state]_shine")
	shine.appearance_flags = RESET_COLOR //No color on this, just pure white
	. += shine

/obj/item/organ/heart/ethereal/proc/on_owner_fully_heal(mob/living/carbon/C, admin_heal)
	SIGNAL_HANDLER

	QDEL_NULL(current_crystal) //Kicks out the ethereal

///Ran when examined while crystalizing, gives info about the amount of time left
/obj/item/organ/heart/ethereal/proc/on_examine(mob/living/carbon/human/examined_human, mob/user, list/examine_list)
	SIGNAL_HANDLER

	if(!crystalize_timer_id)
		return

	switch(timeleft(crystalize_timer_id))
		if(0 to CRYSTALIZE_STAGE_ENGULFING)
			examine_list += span_warning("Crystals are almost engulfing [examined_human]!")
		if(CRYSTALIZE_STAGE_ENGULFING to CRYSTALIZE_STAGE_ENCROACHING)
			examine_list += span_notice("Crystals are starting to cover [examined_human].")
		if(CRYSTALIZE_STAGE_SMALL to INFINITY)
			examine_list += span_notice("Some crystals are coming out of [examined_human].")

///On stat changes, if the victim is no longer dead but they're crystalizing, cancel it, if they become dead, start the crystalizing process if possible
/obj/item/organ/heart/ethereal/proc/on_stat_change(mob/living/victim, new_stat)
	SIGNAL_HANDLER

	if(new_stat != DEAD)
		if(crystalize_timer_id)
			stop_crystalization_process(victim)
		return

	if(QDELETED(victim) || victim.suiciding)
		return //lol rip

	if(!COOLDOWN_FINISHED(src, crystalize_cooldown))
		return //lol double rip

	to_chat(victim, span_nicegreen("Crystals start forming around your dead body."))
	victim.visible_message(span_notice("Crystals start forming around [victim]."))
	ADD_TRAIT(victim, TRAIT_CORPSELOCKED, SPECIES_TRAIT)

	crystalize_timer_id = addtimer(CALLBACK(src, .proc/crystalize, victim), CRYSTALIZE_PRE_WAIT_TIME, TIMER_STOPPABLE)

	RegisterSignal(victim, COMSIG_HUMAN_DISARM_HIT, .proc/reset_crystalizing)
	RegisterSignal(victim, COMSIG_PARENT_EXAMINE, .proc/on_examine)
	RegisterSignal(victim, COMSIG_MOB_APPLY_DAMAGE, .proc/on_take_damage)

///Ran when disarmed, prevents the ethereal from reviving
/obj/item/organ/heart/ethereal/proc/reset_crystalizing(mob/living/defender, mob/living/attacker, zone)
	SIGNAL_HANDLER

	to_chat(defender, span_notice("The crystals on your corpse are gently broken off, and will need some time to recover."))
	defender.visible_message(span_notice("The crystals on [defender] are gently broken off."))
	deltimer(crystalize_timer_id)
	crystalize_timer_id = addtimer(CALLBACK(src, .proc/crystalize, defender), CRYSTALIZE_DISARM_WAIT_TIME, TIMER_STOPPABLE) //Lets us restart the timer on disarm

///Actually spawns the crystal which puts the ethereal in it.
/obj/item/organ/heart/ethereal/proc/crystalize(mob/living/ethereal)
	if(!COOLDOWN_FINISHED(src, crystalize_cooldown) || ethereal.stat != DEAD)
		return //Should probably not happen, but lets be safe.
	COOLDOWN_START(src, crystalize_cooldown, INFINITY) //Prevent cheeky double-healing until we get out, this is against stupid admemery
	current_crystal = new(get_turf(ethereal), src)
	stop_crystalization_process(ethereal, TRUE)

///Stop the crystalization process, unregistering any signals and resetting any variables.
/obj/item/organ/heart/ethereal/proc/stop_crystalization_process(mob/living/ethereal, succesful = FALSE)
	UnregisterSignal(ethereal, COMSIG_HUMAN_DISARM_HIT)
	UnregisterSignal(ethereal, COMSIG_PARENT_EXAMINE)
	UnregisterSignal(ethereal, COMSIG_MOB_APPLY_DAMAGE)

	crystalization_process_damage = 0 //Reset damage taken during crystalization

	if(!succesful)
		REMOVE_TRAIT(owner, TRAIT_CORPSELOCKED, SPECIES_TRAIT)
		QDEL_NULL(current_crystal)

	if(crystalize_timer_id)
		deltimer(crystalize_timer_id)
		crystalize_timer_id = null

/obj/item/organ/heart/ethereal/proc/owner_deleted(datum/source)
	SIGNAL_HANDLER

	stop_crystalization_process(owner)
	return

///Lets you stop the process with enough brute damage
/obj/item/organ/heart/ethereal/proc/on_take_damage(datum/source, damage, damagetype, def_zone)
	SIGNAL_HANDLER
	if(damagetype != BRUTE)
		return

	crystalization_process_damage += damage

	if(crystalization_process_damage < BRUTE_DAMAGE_REQUIRED_TO_STOP_CRYSTALIZATION)
		return

	var/mob/living/carbon/human/ethereal = source

	to_chat(ethereal, span_warning("The crystals on your body have completely broken"))
	ethereal.visible_message(span_notice("The crystals on [ethereal] are completely shattered and stopped growing"))

	stop_crystalization_process(ethereal)

/obj/structure/ethereal_crystal
	name = "Ethereal Resurrection Crystal"
	desc = "It seems to contain the corpse of an ethereal mending its wounds."
	icon = 'icons/obj/ethereal_crystal.dmi'
	icon_state = "ethereal_crystal"
	damage_deflection = 0
	max_integrity = 100
	resistance_flags = FIRE_PROOF
	density = TRUE
	anchored = TRUE
	///The organ this crystal belongs to
	var/obj/item/organ/heart/ethereal/ethereal_heart
	///Timer for the healing process. Stops if destroyed.
	var/crystal_heal_timer
	///Is the crystal still being built? True by default, gets changed after a timer.
	var/being_built = TRUE

/obj/structure/ethereal_crystal/Initialize(mapload, obj/item/organ/heart/ethereal/ethereal_heart)
	. = ..()
	src.ethereal_heart = ethereal_heart
	ethereal_heart.owner.visible_message(span_notice("The crystals fully encase [ethereal_heart.owner]!"))
	to_chat(ethereal_heart.owner, span_notice("You are encased in a huge crystal!"))
	playsound(get_turf(src), 'sound/effects/ethereal_crystalization.ogg', 50)
	ethereal_heart.owner.forceMove(src) //put that ethereal in
	add_atom_colour(ethereal_heart.ethereal_color, FIXED_COLOUR_PRIORITY)
	crystal_heal_timer = addtimer(CALLBACK(src, .proc/heal_ethereal), CRYSTALIZE_HEAL_TIME, TIMER_STOPPABLE)
	set_light(4, 10, ethereal_heart.ethereal_color)
	update_icon()
	flick("ethereal_crystal_forming", src)
	addtimer(CALLBACK(src, .proc/start_crystalization), 1 SECONDS)

/obj/structure/ethereal_crystal/proc/start_crystalization()
	being_built = FALSE
	update_icon()

/obj/structure/ethereal_crystal/atom_destruction(damage_flag)
	playsound(get_turf(ethereal_heart.owner), 'sound/effects/ethereal_revive_fail.ogg', 100)
	return ..()

/obj/structure/ethereal_crystal/Destroy()
	if(!ethereal_heart)
		return ..()
	ethereal_heart.current_crystal = null
	COOLDOWN_START(ethereal_heart, crystalize_cooldown, CRYSTALIZE_COOLDOWN_LENGTH)
	ethereal_heart.owner.forceMove(get_turf(src))
	REMOVE_TRAIT(ethereal_heart.owner, TRAIT_CORPSELOCKED, SPECIES_TRAIT)
	deltimer(crystal_heal_timer)
	visible_message(span_notice("The crystals shatters, causing [ethereal_heart.owner] to fall out"))
	return ..()

/obj/structure/ethereal_crystal/update_overlays()
	. = ..()
	if(!being_built)
		var/mutable_appearance/shine = mutable_appearance(icon, icon_state = "[icon_state]_shine")
		shine.appearance_flags = RESET_COLOR //No color on this, just pure white
		. += shine

/obj/structure/ethereal_crystal/proc/heal_ethereal()
	ethereal_heart.owner.revive(TRUE, FALSE)
	to_chat(ethereal_heart.owner, "[span_notice("You burst out of the crystal with vigour...")][span_userdanger("But at a cost.")]")
	var/datum/brain_trauma/picked_trauma
	if(prob(10)) //10% chance for a severe trauma
		picked_trauma = pick(subtypesof(/datum/brain_trauma/severe))
	else
		picked_trauma = pick(subtypesof(/datum/brain_trauma/mild))
	ethereal_heart.owner.gain_trauma(picked_trauma, TRAUMA_RESILIENCE_ABSOLUTE)
	playsound(get_turf(ethereal_heart.owner), 'sound/effects/ethereal_revive.ogg', 100)
	qdel(src)


code:
/obj/item/organ/heart/freedom
	name = "heart of freedom"
	desc = "This heart pumps with the passion to give... something freedom."
	organ_flags = ORGAN_SYNTHETIC //the power of freedom prevents heart attacks
	/// The cooldown until the next time this heart can give the host an adrenaline boost.
	COOLDOWN_DECLARE(adrenaline_cooldown)

/obj/item/organ/heart/freedom/on_life(delta_time, times_fired)
	. = ..()
	if(owner.health < 5 && COOLDOWN_FINISHED(src, adrenaline_cooldown))
		COOLDOWN_START(src, adrenaline_cooldown, rand(25 SECONDS, 1 MINUTES))
		to_chat(owner, span_userdanger("You feel yourself dying, but you refuse to give up!"))
		owner.heal_overall_damage(15, 15, 0, BODYPART_ORGANIC)
		if(owner.reagents.get_reagent_amount(/datum/reagent/medicine/ephedrine) < 20)
			owner.reagents.add_reagent(/datum/reagent/medicine/ephedrine, 10)


code:
/obj/item/organ/intestines
	name = "intestines"
	icon_state = "guts"
	desc = "Where food goes to die."
	w_class = WEIGHT_CLASS_NORMAL
	zone = BODY_ZONE_PRECISE_GROIN
	organ_efficiency = list(ORGAN_SLOT_INTESTINES = 100)
	attack_verb_continuous = list("gores", "defecates", "shits", "craps")
	attack_verb_simple = list("gore", "defecate", "shit", "crap")

	healing_factor = STANDARD_ORGAN_HEALING

	food_reagents = list(/datum/reagent/consumable/nutriment/organ_tissue = 5, \
					/datum/reagent/water = 5, \
					/datum/reagent/consumable/shit = 5)

	//This is a reagent user and needs more then the 10u from edible component
	reagent_vol = 115 //100u of shit will fill us up

	// Yeah, intestines are large
	organ_volume = 1.5
	max_blood_storage = 15
	current_blood = 15
	blood_req = 3
	oxygen_req = 3
	nutriment_req = 3
	hydration_req = 4

/obj/item/organ/intestines/Initialize()
	. = ..()
	//None edible organs do not get a reagent holder by default
	if(!reagents)
		create_reagents(reagent_vol, REAGENT_HOLDER_ALIVE)
	else
		reagents.flags |= REAGENT_HOLDER_ALIVE

/obj/item/organ/intestines/get_availability(datum/species/S)
	return !(NOINTESTINES in S.species_traits)


code:
/obj/item/organ/kidneys
	name = "kidney"
	icon_state = "kidneys"
	base_icon_state = "kidney"
	desc = "The organ that hates stoners the most."
	zone = BODY_ZONE_CHEST
	organ_efficiency = list(ORGAN_SLOT_KIDNEYS = 100)
	w_class = WEIGHT_CLASS_SMALL
	side = RIGHT_SIDE

	organ_volume = 0.5
	max_blood_storage = 7.5
	current_blood = 7.5
	blood_req = 1.5
	oxygen_req = 1.5
	nutriment_req = 1.5
	hydration_req = 2

	/// Toxin damage holding
	var/toxins = 0
	/// How much toxin damage we can hold
	var/max_toxins = KIDNEY_MAX_TOXIN
	/// How much shock a point of toxins causes
	var/toxin_pain_factor = KIDNEY_TOXIN_PAIN_FACTOR

	/// The maximum volume of toxins the kidney will quickly purge
	var/tox_tolerance = KIDNEY_DEFAULT_TOX_TOLERANCE
	/// Scaling factor for how much damage toxins deal to the kidney
	var/tox_lethality = KIDNEY_DEFAULT_TOX_LETHALITY
	/// Whether to filter toxins
	var/filter_toxins = TRUE

/obj/item/organ/kidneys/left
	side = LEFT_SIDE

/obj/item/organ/kidneys/get_availability(datum/species/S)
	return (!(TRAIT_NOMETABOLISM in S.inherent_traits))

/obj/item/organ/kidneys/update_icon_state()
	. = ..()
	if(side == RIGHT_SIDE)
		icon_state = "[base_icon_state]-r"
	else
		icon_state = "[base_icon_state]-l"

/obj/item/organ/kidneys/add_toxins(amount)
	var/last_tox = toxins
	toxins = min(max_toxins, max(0, toxins + amount))
	return (toxins - last_tox)

/obj/item/organ/kidneys/remove_toxins(amount)
	var/last_tox = toxins
	toxins = min(max_toxins, max(0, toxins - amount))
	return (toxins - last_tox)

/obj/item/organ/kidneys/get_toxins()
	if(is_failing())
		return max_toxins
	return toxins

/obj/item/organ/kidneys/can_add_toxins()
	return (toxins < max_toxins)

/obj/item/organ/kidneys/can_remove_toxins()
	return (toxins > 0)

/obj/item/organ/kidneys/get_availability(datum/species/S)
	return !(NOKIDNEYS in S.species_traits)


code:
#define LIVER_FAILURE_STAGE_SECONDS 60 //amount of seconds before liver failure reaches a new stage
/obj/item/organ/liver
	name = "liver"
	icon_state = "liver"
	desc = "It's called liver, because it'd be weird for it to be called deader."
	zone = BODY_ZONE_CHEST
	organ_efficiency = list(ORGAN_SLOT_LIVER = 100)
	w_class = WEIGHT_CLASS_NORMAL

	food_reagents = list(/datum/reagent/consumable/nutriment = 5, /datum/reagent/iron = 5)
	grind_results = list(/datum/reagent/consumable/nutriment/peptides = 5)

	// the liver is large as fuck
	organ_volume = 2
	max_blood_storage = 25
	current_blood = 25
	blood_req = 4
	oxygen_req = 4
	nutriment_req = 4
	hydration_req = 4

	/// Toxin damage holding
	var/toxins = 0
	/// How much toxin damage we can hold
	var/max_toxins = LIVER_MAX_TOXIN
	/// How much shock a point of toxins causes
	var/toxin_pain_factor = LIVER_TOXIN_PAIN_FACTOR
	/// Affects how much damage the liver takes from alcohol
	var/alcohol_tolerance = ALCOHOL_RATE

/obj/item/organ/liver/get_availability(datum/species/S)
	return (!(TRAIT_NOMETABOLISM in S.inherent_traits))

/obj/item/organ/liver/Initialize()
	. = ..()
	// If the liver handles foods like a clown, it honks like a bike horn
	// Don't think about it too much.
	RegisterSignal(src, SIGNAL_ADDTRAIT(TRAIT_COMEDY_METABOLISM), .proc/on_add_comedy_metabolism)

/* Signal handler for the liver gaining the TRAIT_COMEDY_METABOLISM trait
 *
 * Adds the "squeak" component, so clown livers will act just like their
 * bike horns, and honk when you hit them with things, or throw them
 * against things, or step on them.
 *
 * The removal of the component, if this liver loses that trait, is handled
 * by the component itself.
 */
/obj/item/organ/liver/proc/on_add_comedy_metabolism()
	SIGNAL_HANDLER
	// Are clown "bike" horns made from the livers of ex-clowns?
	// Would that make the clown more or less likely to honk it
	AddComponent(/datum/component/squeak, list('sound/items/bikehorn.ogg'=1), 50, falloff_exponent = 20)

/obj/item/organ/liver/surgical_examine(mob/user)
	. = ..()
	if(HAS_TRAIT(user, TRAIT_ENTRAILS_READER) || (user.mind && HAS_TRAIT(user.mind, TRAIT_ENTRAILS_READER)) || isobserver(user))
		if(HAS_TRAIT(src, TRAIT_LAW_ENFORCEMENT_METABOLISM))
			. += "Fatty deposits and sprinkle residue, imply that this is the liver of someone in security."
		if(HAS_TRAIT(src, TRAIT_CULINARY_METABOLISM))
			. += "The high iron content and slight smell of garlic, implies that this is the liver of a cook."
		if(HAS_TRAIT(src, TRAIT_COMEDY_METABOLISM))
			. += "A smell of bananas, a slippery sheen and honking when depressed, implies that this is the liver of a clown."
		if(HAS_TRAIT(src, TRAIT_MEDICAL_METABOLISM))
			. += "Marks of stress and a faint whiff of medicinal alcohol, imply that this is the liver of a medical worker."
		if(HAS_TRAIT(src, TRAIT_GREYTIDE_METABOLISM))
			. += "Greyer than most with electrical burn marks, this is the liver of an assistant."
		if(HAS_TRAIT(src, TRAIT_ENGINEER_METABOLISM))
			. += "Signs of radiation exposure and space adaption, implies that this is the liver of an engineer."

		// royal trumps pretender royal
		if(HAS_TRAIT(src, TRAIT_ROYAL_METABOLISM))
			. += "A rich diet of luxury food, suppleness from soft beds, implies that this is the liver of a head of staff."
		else if(HAS_TRAIT(src, TRAIT_PRETENDER_ROYAL_METABOLISM))
			. += "A diet of imitation caviar, and signs of insomnia, implies that this is the liver of someone who wants to be a head of staff."

/obj/item/organ/liver/add_toxins(amount)
	var/last_tox = toxins
	toxins = min(max_toxins, max(0, toxins + amount))
	return (toxins - last_tox)

/obj/item/organ/liver/remove_toxins(amount)
	var/last_tox = toxins
	toxins = min(max_toxins, max(0, toxins - amount))
	return (toxins - last_tox)

/obj/item/organ/liver/get_toxins()
	if(is_failing())
		return max_toxins
	return toxins

/obj/item/organ/liver/can_add_toxins()
	return (toxins < max_toxins)

/obj/item/organ/liver/can_remove_toxins()
	return (toxins > 0)

/obj/item/organ/liver/handle_failing_organ(delta_time)
	if(HAS_TRAIT(src, TRAIT_STABLELIVER) || HAS_TRAIT(src, TRAIT_NOMETABOLISM))
		return
	return ..()

/obj/item/organ/liver/organ_failure(delta_time)
	if(failure_time == 2)
		to_chat(owner,span_danger("I feel a gut-wrenching pain in my abdomen!"))
	switch(failure_time/LIVER_FAILURE_STAGE_SECONDS)
		if(1)
			to_chat(owner,span_danger("I feel a stabbing pain in my abdomen!"))
		if(2)
			to_chat(owner,span_danger("I feel a burning sensation in my gut!"))
			owner.vomit()
		if(3)
			to_chat(owner,span_danger("I feel painful acid in my throat!"))
			owner.vomit(blood = TRUE)
		if(4)
			to_chat(owner,span_danger("Overwhelming pain knocks me out!"))
			owner.vomit(blood = TRUE, distance = rand(1,2))
			owner.agony_scream()
			owner.AdjustUnconscious(2.5 SECONDS)
		if(5)
			to_chat(owner,span_danger("I feel as if my guts are about to melt!"))
			owner.vomit(blood = TRUE,distance = rand(1,3))
			owner.agony_scream()
			owner.AdjustUnconscious(5 SECONDS)
	switch(failure_time)
		// After 60 seconds we begin to feel the effects
		if(1 * LIVER_FAILURE_STAGE_SECONDS to 2 * LIVER_FAILURE_STAGE_SECONDS - 1)
			owner.adjustToxLoss(0.2 * delta_time,forced = TRUE)
			owner.adjust_disgust(0.1 * delta_time)

		if(2 * LIVER_FAILURE_STAGE_SECONDS to 3 * LIVER_FAILURE_STAGE_SECONDS - 1)
			owner.adjustToxLoss(0.4 * delta_time,forced = TRUE)
			owner.drowsyness += 0.25 * delta_time
			owner.adjust_disgust(0.3 * delta_time)

		if(3 * LIVER_FAILURE_STAGE_SECONDS to 4 * LIVER_FAILURE_STAGE_SECONDS - 1)
			owner.adjustToxLoss(0.6 * delta_time,forced = TRUE)
			owner.adjustOrganLoss(pick(ORGAN_SLOT_HEART,ORGAN_SLOT_LUNGS,ORGAN_SLOT_STOMACH,ORGAN_SLOT_KIDNEYS,ORGAN_SLOT_INTESTINES,ORGAN_SLOT_BLADDER,ORGAN_SLOT_EYES,ORGAN_SLOT_EARS), 0.2 * delta_time)
			owner.drowsyness += 0.5 * delta_time
			owner.adjust_disgust(0.6 * delta_time)
			if(DT_PROB(1.5, delta_time))
				owner.emote("drool")

		if(4 * LIVER_FAILURE_STAGE_SECONDS to INFINITY)
			owner.adjustToxLoss(0.8 * delta_time,forced = TRUE)
			owner.adjustOrganLoss(pick(ORGAN_SLOT_HEART,ORGAN_SLOT_LUNGS,ORGAN_SLOT_STOMACH,ORGAN_SLOT_KIDNEYS,ORGAN_SLOT_INTESTINES,ORGAN_SLOT_BLADDER,ORGAN_SLOT_EYES,ORGAN_SLOT_EARS), 0.5 * delta_time)
			owner.drowsyness += 0.8 * delta_time
			owner.adjust_disgust(1.2 * delta_time)
			if(DT_PROB(3, delta_time))
				owner.emote("drool")

/obj/item/organ/liver/on_owner_examine(datum/source, mob/user, list/examine_list)
	if(!ishuman(owner) || !is_failing())
		return

	var/mob/living/carbon/human/humie_owner = owner
	if(!humie_owner.getorganslot(ORGAN_SLOT_EYES) || humie_owner.is_eyes_covered())
		return
	switch(failure_time)
		if(0 to 3 * LIVER_FAILURE_STAGE_SECONDS - 1)
			examine_list += span_notice("[owner]'s eyes are slightly yellow.")
		if(3 * LIVER_FAILURE_STAGE_SECONDS to 4 * LIVER_FAILURE_STAGE_SECONDS - 1)
			examine_list += span_notice("[owner]'s eyes are completely yellow, and [humie_owner.p_they()] [humie_owner.p_are()] visibly suffering.")
		if(4 * LIVER_FAILURE_STAGE_SECONDS to INFINITY)
			examine_list += span_danger("[owner]'s eyes are completely yellow and swelling with pus. [owner.p_they(TRUE)] don't look like [owner.p_they()] will be alive for much longer.")


code:
/obj/item/organ/liver/alien
	name = "alien liver" // doesnt matter for actual aliens because they dont take toxin damage
	icon_state = "liver-x" // Same sprite as fly-person liver.
	desc = "A liver that used to belong to a killer alien, who knows what it used to eat."


code:
/obj/item/organ/liver/cybernetic
	name = "basic cybernetic liver"
	icon_state = "liver-c"
	desc = "A very basic device designed to mimic the functions of a human liver. Handles toxins slightly worse than an organic liver."
	organ_flags = ORGAN_SYNTHETIC
	maxHealth = STANDARD_ORGAN_THRESHOLD*0.5
	emp_vulnerability = 80 //Chance of permanent effects if emp-ed.

/obj/item/organ/liver/cybernetic/tier2
	name = "cybernetic liver"
	icon_state = "liver-c-u"
	desc = "An electronic device designed to mimic the functions of a human liver. Handles toxins slightly better than an organic liver."
	maxHealth = 1.5 * STANDARD_ORGAN_THRESHOLD
	emp_vulnerability = 40

/obj/item/organ/liver/cybernetic/tier3
	name = "upgraded cybernetic liver"
	icon_state = "liver-c-u2"
	desc = "An upgraded version of the cybernetic liver, designed to improve further upon organic livers. It is resistant to alcohol poisoning and is very robust at filtering toxins."
	alcohol_tolerance = 0.001
	maxHealth = 2 * STANDARD_ORGAN_THRESHOLD
	emp_vulnerability = 20

/obj/item/organ/liver/emp_act(severity)
	. = ..()
	if(!owner || !CHECK_BITFIELD(organ_flags, ORGAN_SYNTHETIC) || . & EMP_PROTECT_SELF)
		return
	if(COOLDOWN_FINISHED(src, severe_cooldown)) //So we cant just spam emp to kill people.
		owner.adjustToxLoss(10)
		COOLDOWN_START(src, severe_cooldown, 10 SECONDS)
	if(prob(emp_vulnerability/severity)) //Chance of permanent effects
		organ_flags |= ORGAN_SYNTHETIC_EMP //Starts organ faliure - gonna need replacing soon.


code:
/obj/item/organ/liver/plasmaman
	name = "reagent processing crystal"
	icon_state = "liver-p"
	desc = "A large crystal that is somehow capable of metabolizing chemicals, these are found in plasmamen."


code:
/obj/item/organ/lungs
	name = "lung"
	icon_state = "lung"
	base_icon_state = "lung"
	desc = "I can't breathe - Words that precede unfortunate events."
	zone = BODY_ZONE_CHEST
	organ_efficiency = list(ORGAN_SLOT_LUNGS = 50) // Most people have two lungs you dolt
	w_class = WEIGHT_CLASS_NORMAL
	side = RIGHT_SIDE

	low_threshold_passed = span_warning("You feel short of breath.")
	high_threshold_passed = span_warning("You feel some sort of constriction around your chest as your breathing becomes shallow and rapid.")
	now_fixed = span_warning("Your lungs seem to once again be able to hold air.")
	low_threshold_cleared = span_info("You can breathe normally again.")
	high_threshold_cleared = span_info("The constriction around your chest loosens as your breathing calms down.")

	food_reagents = list(/datum/reagent/consumable/nutriment = 5, /datum/reagent/medicine/salbutamol = 5)

	// i am here to remind you once again that humans have TWO lungs
	maxHealth = STANDARD_ORGAN_THRESHOLD * 0.8
	high_threshold = STANDARD_ORGAN_THRESHOLD * 0.4
	low_threshold = STANDARD_ORGAN_THRESHOLD * 0.2

	organ_volume = 1
	max_blood_storage = 25
	current_blood = 25
	blood_req = 4
	oxygen_req = 4
	nutriment_req = 4
	hydration_req = 4

	//Breath damage
	//These thresholds are checked against what amounts to total_mix_pressure * (gas_type_mols/total_mols)
	var/safe_oxygen_min = 8 // Minimum safe partial pressure of O2, in kPa
	var/safe_oxygen_max = 0
	var/safe_nitro_min = 0
	var/safe_nitro_max = 0
	var/safe_co2_min = 0
	var/safe_co2_max = 5 // Yes it's an arbitrary value who cares?
	var/safe_plas_min = 0
	///How much breath partial pressure is a safe amount of toxins. 0 means that we are immune to toxins.
	var/safe_plas_max = 0.025
	var/SA_para_min = 0.5 //Sleeping agent
	var/SA_sleep_min = 2.5 //Sleeping agent
	var/BZ_trip_balls_min = 0.5 //BZ gas
	var/BZ_brain_damage_min = 5 //Give people some room to play around without killing the station
	var/gas_stimulation_min = 0.001 //Nitryl, Stimulum and Freon
	///Minimum amount of healium to make you unconscious for 4 seconds
	var/healium_para_min = 1.5
	///Minimum amount of healium to knock you down for good
	var/healium_sleep_min = 3
	///Whether these lungs react negatively to miasma
	var/suffers_miasma = TRUE

	var/oxy_breath_dam_min = MIN_TOXIC_GAS_DAMAGE
	var/oxy_breath_dam_max = MAX_TOXIC_GAS_DAMAGE
	var/oxy_damage_type = OXY
	var/nitro_breath_dam_min = MIN_TOXIC_GAS_DAMAGE
	var/nitro_breath_dam_max = MAX_TOXIC_GAS_DAMAGE
	var/nitro_damage_type = OXY
	var/co2_breath_dam_min = MIN_TOXIC_GAS_DAMAGE
	var/co2_breath_dam_max = MAX_TOXIC_GAS_DAMAGE
	var/co2_damage_type = OXY
	var/plas_breath_dam_min = MIN_TOXIC_GAS_DAMAGE
	var/plas_breath_dam_max = MAX_TOXIC_GAS_DAMAGE
	var/plas_damage_type = TOX

	var/cold_message = "my face freezing and an icicle forming"
	var/cold_level_1_threshold = 260
	var/cold_level_2_threshold = 200
	var/cold_level_3_threshold = 120
	var/cold_level_1_damage = COLD_GAS_DAMAGE_LEVEL_1 //Keep in mind with gas damage levels, you can set these to be negative, if you want someone to heal, instead.
	var/cold_level_2_damage = COLD_GAS_DAMAGE_LEVEL_2
	var/cold_level_3_damage = COLD_GAS_DAMAGE_LEVEL_3
	var/cold_damage_type = BURN

	var/hot_message = "my face burning and a searing heat"
	var/heat_level_1_threshold = 360
	var/heat_level_2_threshold = 400
	var/heat_level_3_threshold = 1000
	var/heat_level_1_damage = HEAT_GAS_DAMAGE_LEVEL_1
	var/heat_level_2_damage = HEAT_GAS_DAMAGE_LEVEL_2
	var/heat_level_3_damage = HEAT_GAS_DAMAGE_LEVEL_3
	var/heat_damage_type = BURN

	var/breath_modulo = 2

	var/crit_stabilizing_reagent = /datum/reagent/medicine/epinephrine

	// oxyloss
	var/oxygen_deprivation = 0
	var/max_oxygen_deprivation = 50

/obj/item/organ/lungs/left
	side = LEFT_SIDE

/obj/item/organ/lungs/update_icon_state()
	. = ..()
	if(side == RIGHT_SIDE)
		icon_state = "[base_icon_state]-r"
	else
		icon_state = "[base_icon_state]-l"

/obj/item/organ/lungs/on_life(delta_time, times_fired)
	. = ..()
	if(failed)
		if(!is_failing())
			failed = FALSE
			return
	else if(is_failing())
		if(owner.stat == CONSCIOUS)
			owner.visible_message(span_danger("<b>[owner]</b> grabs [owner.p_their()] throat, struggling for breath!"), \
						span_userdanger("I CAN'T BREATHE!"))
		failed = TRUE
	if(damage >= low_threshold)
		var/do_i_cough = DT_PROB((damage < high_threshold) ? 2.5 : 5, delta_time) // between : past high
		if(do_i_cough)
			owner.emote("cough")

/obj/item/organ/lungs/get_availability(datum/species/S)
	return !(TRAIT_NOBREATH in S.inherent_traits)

/obj/item/organ/lungs/proc/add_oxygen_deprivation(amount)
	var/last_deprive = oxygen_deprivation
	oxygen_deprivation = min(max_oxygen_deprivation, max(0, oxygen_deprivation + amount))
	return (oxygen_deprivation - last_deprive)

/obj/item/organ/lungs/proc/remove_oxygen_deprivation(amount)
	var/last_deprive = oxygen_deprivation
	oxygen_deprivation = min(max_oxygen_deprivation, max(0, oxygen_deprivation - amount))
	return (oxygen_deprivation - last_deprive)

// Returns a percentage value for use by GetOxyloss().
/obj/item/organ/lungs/proc/get_oxygen_deprivation()
	if(is_failing())
		return max_oxygen_deprivation
	return FLOOR(oxygen_deprivation, 1)

/obj/item/organ/lungs/proc/can_oxy_deprive()
	if(oxygen_deprivation < max_oxygen_deprivation)
		return TRUE
	return FALSE

/obj/item/organ/lungs/proc/can_oxy_heal()
	if(oxygen_deprivation)
		return TRUE
	return FALSE

/obj/item/organ/lungs/proc/get_breath_modulo()
	if(is_dead())
		return 0
	var/final_breath_modulo = breath_modulo
	if(is_failing())
		final_breath_modulo -= 2
	else if(is_bruised())
		final_breath_modulo -= 1
	return final_breath_modulo

/obj/item/organ/lungs/proc/handle_gas_override(mob/living/carbon/human/breather, list/breath_gases, gas_breathed)


code:
/obj/item/organ/lungs/ashwalker
	name = "blackened frilled lungs" // blackened from necropolis exposure
	desc = "Exposure to the necropolis has mutated these lungs to breathe the air of Indecipheres, the lava-covered moon."
	icon_state = "lungs-ashwalker"

// Normal oxygen is 21 kPa partial pressure, but SS13 humans can tolerate down
// to 16 kPa. So it follows that ashwalkers, as humanoids, follow the same rules.
#define GAS_TOLERANCE 2.5

/obj/item/organ/lungs/ashwalker/Initialize(mapload)
	. = ..()

	var/datum/gas_mixture/immutable/planetary/mix = SSair.planetary[LAVALAND_DEFAULT_ATMOS]
	// Take a "breath" of the air
	var/datum/gas_mixture/breath = mix.remove(mix.total_moles() * BREATH_PERCENTAGE)

	var/list/breath_gases = breath.gases

	breath.assert_gases(
		/datum/gas/oxygen,
		/datum/gas/plasma,
		/datum/gas/carbon_dioxide,
		/datum/gas/nitrogen,
		/datum/gas/bz,
		/datum/gas/miasma,
	)

	var/oxygen_pp = breath.get_breath_partial_pressure(breath_gases[/datum/gas/oxygen][MOLES])
	var/nitrogen_pp = breath.get_breath_partial_pressure(breath_gases[/datum/gas/nitrogen][MOLES])
	var/plasma_pp = breath.get_breath_partial_pressure(breath_gases[/datum/gas/plasma][MOLES])
	var/carbon_dioxide_pp = breath.get_breath_partial_pressure(breath_gases[/datum/gas/carbon_dioxide][MOLES])
	var/bz_pp = breath.get_breath_partial_pressure(breath_gases[/datum/gas/bz][MOLES])
	var/miasma_pp = breath.get_breath_partial_pressure(breath_gases[/datum/gas/miasma][MOLES])

	safe_oxygen_min = max(0, oxygen_pp - GAS_TOLERANCE)
	safe_nitro_min = max(0, nitrogen_pp - GAS_TOLERANCE)
	safe_plas_min = max(0, plasma_pp - GAS_TOLERANCE)

	// Increase plasma tolerance based on amount in base air
	safe_plas_max += plasma_pp

	// CO2 is always a waste gas, so none is required, but ashwalkers
	// tolerate the base amount plus tolerance*2 (humans tolerate only 10 pp)

	safe_co2_max = carbon_dioxide_pp + GAS_TOLERANCE * 2

	// The lung tolerance against BZ is also increased the amount of BZ in the base air
	BZ_trip_balls_min += bz_pp
	BZ_brain_damage_min += bz_pp

	// Lungs adapted to a high miasma atmosphere do not process it, and breathe it back out
	if(miasma_pp)
		suffers_miasma = FALSE

#undef GAS_TOLERANCE


code:
/obj/item/organ/lungs/cybernetic
	name = "basic cybernetic lungs"
	desc = "A basic cybernetic version of the lungs found in traditional humanoid entities."
	icon_state = "lungs-c"
	base_icon_state = "lung-c"
	organ_flags = ORGAN_SYNTHETIC
	maxHealth = STANDARD_ORGAN_THRESHOLD * 0.5
	emp_vulnerability = 80 //Chance of permanent effects if emp-ed.

/obj/item/organ/lungs/cybernetic/tier2
	name = "cybernetic lung"
	desc = "A cybernetic version of the lung found in traditional humanoid entities. Allows for greater intakes of oxygen than organic lungs, requiring slightly less pressure."
	icon_state = "lungs-c-u"
	base_icon_state = "lung-c-u"
	maxHealth = 1.5 * STANDARD_ORGAN_THRESHOLD
	safe_oxygen_min = 13
	emp_vulnerability = 40

/obj/item/organ/lungs/cybernetic/tier3
	name = "upgraded cybernetic lung"
	desc = "A more advanced version of the stock cybernetic lung. Features the ability to filter out lower levels of toxins and carbon dioxide."
	icon_state = "lung-c-u2"
	base_icon_state = "lungs-c-u2"
	safe_plas_max = 20
	safe_co2_max = 20
	maxHealth = 2 * STANDARD_ORGAN_THRESHOLD
	safe_oxygen_min = 13
	emp_vulnerability = 20

	cold_level_1_threshold = 200
	cold_level_2_threshold = 140
	cold_level_3_threshold = 100

/obj/item/organ/lungs/emp_act(severity)
	. = ..()
	if(!owner || !CHECK_BITFIELD(organ_flags, ORGAN_SYNTHETIC) || . & EMP_PROTECT_SELF)
		return
	if(COOLDOWN_FINISHED(src, severe_cooldown)) //So we cant just spam emp to kill people.
		owner.losebreath += 16
		COOLDOWN_START(src, severe_cooldown, 30 SECONDS)
	if(prob(emp_vulnerability/severity)) // Chance of permanent effects
		organ_flags |= ORGAN_SYNTHETIC_EMP // Starts organ faliure - gonna need replacing soon.


code:
/obj/item/organ/lungs/ethereal
	name = "aeration reticulum"
	desc = "These exotic lungs seem crunchier than most."
	icon_state = "lungs_ethereal"
	heat_level_1_threshold = FIRE_MINIMUM_TEMPERATURE_TO_SPREAD // 150C or 433k, in line with ethereal max safe body temperature
	heat_level_2_threshold = 473
	heat_level_3_threshold = 1073

/obj/item/organ/lungs/ethereal/handle_gas_override(mob/living/carbon/human/breather, list/breath_gases, gas_breathed)
	// H2O electrolysis
	gas_breathed = breath_gases[/datum/gas/water_vapor][MOLES]
	breath_gases[/datum/gas/oxygen][MOLES] += gas_breathed/2
	breath_gases[/datum/gas/hydrogen][MOLES] += gas_breathed
	breath_gases[/datum/gas/water_vapor][MOLES] -= gas_breathed


code:
/obj/item/organ/lungs/plasmaman
	name = "plasma filter"
	desc = "A spongy rib-shaped mass for filtering plasma from the air."
	icon_state = "lungs-plasma"

	safe_oxygen_min = 0 //We don't breath this
	safe_plas_min = 8 //We breath THIS!
	safe_plas_max = 0


code:
/obj/item/organ/lungs/slime
	name = "vacuole"
	desc = "A large organelle designed to store oxygen and other important gasses."

	safe_plas_max = 0 //We breathe this to gain POWER.

/* implement this later...
/obj/item/organ/lungs/slime/check_breath(datum/gas_mixture/breath, mob/living/carbon/human/H)
	. = ..()
	if (breath?.gases[/datum/gas/plasma])
		var/plasma_pp = breath.get_breath_partial_pressure(breath.gases[/datum/gas/plasma][MOLES])
		owner.blood_volume += (0.2 * plasma_pp) // 10/s when breathing literally nothing but plasma, which will suffocate you.
*/


code:
/obj/item/organ/regenerative_core
	icon_state = "roro_core"
	base_icon_state = "roro_core"

/obj/item/organ/regenerative_core/update_icon_state()
	. = ..()
	icon_state = (inert ? "[base_icon_state]-inert" : base_icon_state)

/obj/item/organ/regenerative_core/update_overlays()
	. = ..()
	if(!inert && !preserved)
		. += image(icon, src, "[base_icon_state]-crackle")

/obj/item/organ/regenerative_core/legion
	icon_state = "legion_core"
	base_icon_state = "legion_core"


code:
//Spleen: Regenerates blood over time
//Without it, you cannot generate blood without transfusions.
/obj/item/organ/spleen
	name = "spleen"
	desc = "The most underrated organ of the human body."
	icon = 'modular_septic/icons/obj/surgery.dmi'
	icon_state = "spleen"
	zone = BODY_ZONE_CHEST
	organ_efficiency = list(ORGAN_SLOT_SPLEEN = 100)

	maxHealth = STANDARD_ORGAN_THRESHOLD * 0.7
	high_threshold = STANDARD_ORGAN_THRESHOLD * 0.6
	low_threshold = STANDARD_ORGAN_THRESHOLD * 0.2
	w_class = WEIGHT_CLASS_SMALL

	organ_volume = 0.5
	max_blood_storage = 20
	current_blood = 20
	blood_req = 2
	oxygen_req = 2
	nutriment_req = 2
	hydration_req = 3

	var/blood_regen_factor = 0.005 // how much blood the spleen regenerates per efficiency point, per 2 seconds

/obj/item/organ/spleen/get_availability(datum/species/S)
	return (!(NOBLOOD in S.species_traits))


code:
/obj/item/organ/stomach
	name = "stomach"
	icon_state = "stomach"
	desc = "When bariatric goes too far."
	w_class = WEIGHT_CLASS_SMALL
	zone = BODY_ZONE_CHEST
	organ_efficiency = list(ORGAN_SLOT_STOMACH = 100)
	attack_verb_continuous = list("gores", "squishes", "slaps", "digests")
	attack_verb_simple = list("gore", "squish", "slap", "digest")

	healing_factor = STANDARD_ORGAN_HEALING

	low_threshold_passed = span_info("Your stomach flashes with pain before subsiding. Food doesn't seem like a good idea right now.")
	high_threshold_passed = span_warning("Your stomach flares up with constant pain- you can hardly stomach the idea of food right now!")
	high_threshold_cleared = span_info("The pain in your stomach dies down for now, but food still seems unappealing.")
	low_threshold_cleared = span_info("The last bouts of pain in your stomach have died out.")

	food_reagents = list(/datum/reagent/consumable/nutriment/organ_tissue = 5,
					/datum/reagent/consumable/nutriment/protein = 5,
					/datum/reagent/toxin/acid = 5)
	// This is a reagent user and needs more then the 15u from edible component
	reagent_vol = 140 //125u of stuff max

	// This volume may seem misleading, but the human stomach is about the size of a fist most of the time
	organ_volume = 1
	max_blood_storage = 20
	current_blood = 20
	blood_req = 4
	oxygen_req = 4
	nutriment_req = 3
	hydration_req = 4

	/// The rate that disgust decays
	var/disgust_metabolism = 1

	/// The rate that the stomach will transfer reagents to the body
	var/metabolism_efficiency = 0.05 // the lowest we should go is 0.05

/obj/item/organ/stomach/Initialize()
	. = ..()
	//None edible organs do not get a reagent holder by default
	if(!reagents)
		create_reagents(reagent_vol, REAGENT_HOLDER_ALIVE)
	else
		reagents.flags |= REAGENT_HOLDER_ALIVE

/obj/item/organ/stomach/get_availability(datum/species/S)
	return !(NOSTOMACH in S.species_traits)


code:
/obj/item/organ/stomach/bone
	desc = "You have no idea what this strange ball of bones does."
	metabolism_efficiency = 0.025 //very bad
	/// How much [BRUTE] damage milk heals every second
	var/milk_brute_healing = 2.5
	/// How much [BURN] damage milk heals every second
	var/milk_burn_healing = 2.5

/obj/item/organ/stomach/bone/on_life(delta_time, times_fired)
	var/datum/reagent/consumable/milk/milk = locate(/datum/reagent/consumable/milk) in reagents.reagent_list
	if(milk)
		var/mob/living/carbon/body = owner
		if(milk.volume > 50)
			reagents.remove_reagent(milk.type, milk.volume - 5)
			to_chat(owner, span_warning("The excess milk is dripping off your bones!"))
		body.heal_bodypart_damage(milk_brute_healing * REAGENTS_EFFECT_MULTIPLIER * delta_time, milk_burn_healing * REAGENTS_EFFECT_MULTIPLIER * delta_time)

		for(var/i in body.all_wounds)
			var/datum/wound/iter_wound = i
			iter_wound.on_xadone(1 * REAGENTS_EFFECT_MULTIPLIER * delta_time)
		reagents.remove_reagent(milk.type, milk.metabolization_rate * delta_time)
	return ..()


code:
/obj/item/organ/stomach/cybernetic
	name = "basic cybernetic stomach"
	icon_state = "stomach-c"
	desc = "A basic device designed to mimic the functions of a human stomach"
	organ_flags = ORGAN_SYNTHETIC
	maxHealth = STANDARD_ORGAN_THRESHOLD * 0.5
	emp_vulnerability = 80 //Chance of permanent effects if emp-ed.
	metabolism_efficiency = 0.35 // not as good at digestion

/obj/item/organ/stomach/cybernetic/tier2
	name = "cybernetic stomach"
	icon_state = "stomach-c-u"
	desc = "An electronic device designed to mimic the functions of a human stomach. Handles disgusting food a bit better."
	maxHealth = 1.5 * STANDARD_ORGAN_THRESHOLD
	disgust_metabolism = 2
	emp_vulnerability = 40
	metabolism_efficiency = 0.07

/obj/item/organ/stomach/cybernetic/tier3
	name = "upgraded cybernetic stomach"
	icon_state = "stomach-c-u2"
	desc = "An upgraded version of the cybernetic stomach, designed to improve further upon organic stomachs. Handles disgusting food very well."
	maxHealth = 2 * STANDARD_ORGAN_THRESHOLD
	disgust_metabolism = 3
	emp_vulnerability = 20
	metabolism_efficiency = 0.1

/obj/item/organ/stomach/emp_act(severity)
	. = ..()
	if(!owner || !CHECK_BITFIELD(organ_flags, ORGAN_SYNTHETIC) || . & EMP_PROTECT_SELF)
		return
	if(!COOLDOWN_FINISHED(src, severe_cooldown)) //So we cant just spam emp to kill people.
		owner.vomit(stun = FALSE)
		COOLDOWN_START(src, severe_cooldown, 10 SECONDS)
	if(prob(emp_vulnerability/severity)) //Chance of permanent effects
		organ_flags |= ORGAN_SYNTHETIC_EMP //Starts organ faliure - gonna need replacing soon.


code:
/obj/item/organ/stomach/ethereal
	name = "biological battery"
	icon_state = "stomach-p" //Welp. At least it's more unique in functionaliy.
	desc = "A crystal-like organ that stores the electric charge of ethereals."
	var/drain_time = 0
	var/crystal_charge = ETHEREAL_CHARGE_FULL

/obj/item/organ/stomach/ethereal/on_life(delta_time, times_fired)
	. = ..()
	adjust_charge(-ETHEREAL_CHARGE_FACTOR * delta_time)

/obj/item/organ/stomach/ethereal/Insert(mob/living/carbon/M, special = 0)
	. = ..()
	RegisterSignal(owner, COMSIG_PROCESS_BORGCHARGER_OCCUPANT, .proc/charge)
	RegisterSignal(owner, COMSIG_LIVING_ELECTROCUTE_ACT, .proc/on_electrocute)

/obj/item/organ/stomach/ethereal/Remove(mob/living/carbon/M, special = 0)
	UnregisterSignal(owner, COMSIG_PROCESS_BORGCHARGER_OCCUPANT)
	UnregisterSignal(owner, COMSIG_LIVING_ELECTROCUTE_ACT)
	return ..()

/obj/item/organ/stomach/ethereal/proc/charge(datum/source, amount, repairs)
	adjust_charge(amount / 3.5)

/obj/item/organ/stomach/ethereal/proc/on_electrocute(datum/source, shock_damage, siemens_coeff = 1, flags = NONE)
	if(flags & SHOCK_ILLUSION)
		return
	adjust_charge(shock_damage * siemens_coeff * 2)
	to_chat(owner, span_notice("You absorb some of the shock into your body!"))

/obj/item/organ/stomach/ethereal/proc/adjust_charge(amount)
	crystal_charge = clamp(crystal_charge + amount, ETHEREAL_CHARGE_NONE, ETHEREAL_CHARGE_DANGEROUS)


code:
/obj/item/organ/stomach/bone/plasmaman
	name = "digestive crystal"
	icon_state = "stomach-p"
	desc = "A strange crystal that is responsible for metabolizing the unseen energy force that feeds plasmamen."
	metabolism_efficiency = 0.06
	milk_burn_healing = 0


code:
/obj/item/organ/artery
	name = "artery"
	desc = "An artery is torn! I mean, literally."
	icon_state = "artery"
	organ_flags = ORGAN_EDIBLE|ORGAN_LIMB_SUPPORTER|ORGAN_INDESTRUCTIBLE|ORGAN_NO_VIOLENT_DAMAGE
	organ_efficiency = list(ORGAN_SLOT_ARTERY = 100)

	maxHealth = ARTERY_MAX_HEALTH
	high_threshold = ARTERY_MAX_HEALTH * 0.8
	low_threshold = ARTERY_MAX_HEALTH * 0.2
	pain_multiplier = 0.05

	organ_volume = 0.5
	max_blood_storage = 100
	current_blood = 100
	oxygen_req = 0.25
	nutriment_req = 0.15
	hydration_req = 0.15

	/// How much blood we gush when torn
	var/blood_flow = ARTERIAL_BLOOD_FLOW
	/// If torn, this is basically the time until we gush again
	COOLDOWN_DECLARE(next_squirt)
	/// Minimum time until we squirt again
	var/squirt_delay_min_seconds = 4
	/// Maximum time until we squirt again
	var/squirt_delay_max_seconds = 10

/obj/item/organ/artery/Insert(mob/living/carbon/M, special, drop_if_replaced, new_zone)
	. = ..()
	M.update_artery_overlays()

/obj/item/organ/artery/Remove(mob/living/carbon/M, special)
	. = ..()
	M.update_artery_overlays()

/obj/item/organ/artery/can_heal(delta_time, times_fired)
	return FALSE

/obj/item/organ/artery/on_life(delta_time, times_fired)
	. = ..()
	// Dead, pulseless or cryosleep people do not pump blood
	if(!(is_bruised() || is_failing()) || !owner.pulse || (owner.bodytemperature <= TCRYO))
		return
	var/bleed_mod = 1 * (damage/maxHealth)
	var/obj/item/bodypart/limb = owner.get_bodypart(current_zone)
	if(LAZYLEN(limb.grasped_by))
		bleed_mod *= 0.5
	if(limb.current_gauze)
		bleed_mod *= 0.5
	switch(owner.pulse)
		if(PULSE_NONE)
			bleed_mod *= 0
		if(PULSE_SLOW)
			bleed_mod *= 0.8
		if(PULSE_FAST)
			bleed_mod *= 1.25
		if(PULSE_FASTER, PULSE_THREADY)
			bleed_mod *= 1.5
	if(ishuman(owner))
		var/mob/living/carbon/human/human_owner = owner
		if(human_owner.physiology)
			bleed_mod *= human_owner.physiology.bleed_mod
	var/final_bleed_rate = CEILING(blood_flow * bleed_mod, 0.1)
	if(!final_bleed_rate)
		return
	if(COOLDOWN_FINISHED(src, next_squirt))
		squirt(final_bleed_rate)
	else
		squirt_less(final_bleed_rate)

/obj/item/organ/artery/applyOrganDamage(amount, maximum, silent)
	. = ..()
	owner?.update_artery_overlays()

/obj/item/organ/artery/proc/squirt(amount = 1, force = FALSE)
	var/obj/item/bodypart/limb = owner.get_bodypart(current_zone)
	var/open_wound = FALSE
	for(var/datum/wound/wound as anything in limb.wounds)
		if(wound.blood_flow)
			open_wound = TRUE
			break
	for(var/datum/injury/injury as anything in limb.injuries)
		if(injury.is_bleeding())
			open_wound = TRUE
			break
	var/unrestricted_flow = TRUE
	if(LAZYLEN(limb.grasped_by) || limb.current_gauze)
		unrestricted_flow = FALSE
	if(unrestricted_flow || force)
		if(open_wound && (owner.get_blood_circulation() >= amount) || force)
			playsound(owner, 'modular_septic/sound/gore/artery.ogg', 75, 0)
			owner.bleed(amount)
			if(limb.current_gauze)
				limb.seep_gauze(amount * limb.current_gauze.absorption_rate)
			owner.visible_message(span_danger("<b>[owner]</b>'s [limb.name]'s [name] squirts blood!"), \
							span_userdanger("Blood squirts from my [limb.name]'s [name]!"))
			if(CHECK_BITFIELD(owner.mob_biotypes, MOB_ORGANIC|MOB_HUMANOID) && owner.needs_heart() && !(NOBLOOD in owner.dna?.species?.species_traits))
				var/obj/effect/decal/cleanable/blood/hitsplatter/B = new (get_turf(owner), owner.get_blood_dna_list())
				B.do_squirt(range = rand(1,3))
			COOLDOWN_START(src, next_squirt, rand(squirt_delay_min_seconds, squirt_delay_max_seconds) SECONDS)
		else
			COOLDOWN_START(src, next_squirt, rand(squirt_delay_min_seconds, squirt_delay_max_seconds) SECONDS)
			return squirt_less(amount, open_wound)
	else
		return squirt_less(amount, open_wound)

/obj/item/organ/artery/proc/squirt_less(amount = 1, open_wound = TRUE)
	// Just bleed without being *too* dramatic
	if(open_wound)
		owner.bleed(amount)
		var/obj/item/bodypart/limb = owner.get_bodypart(current_zone)
		if(limb.current_gauze)
			limb.seep_gauze(amount * limb.current_gauze.absorption_rate)
	// No open wound, even less drama
	else
		owner.adjust_bloodvolume(-amount)

/obj/item/organ/artery/proc/tear()
	if(!owner)
		return
	if(owner.stat < UNCONSCIOUS)
		owner.death_scream()
	owner.bleed(blood_flow)
	current_blood = 0
	applyOrganDamage(maxHealth * 0.5)
	var/cd_time = rand(squirt_delay_min_seconds, squirt_delay_max_seconds) SECONDS
	COOLDOWN_START(src, next_squirt, cd_time)

/obj/item/organ/artery/proc/mend()
	if(!owner)
		return
	setOrganDamage(0)


code:
/obj/item/organ/artery/chest
	name = "aorta"
	desc = "Shot through the heart, and you're to blame - Darlin', you give love a bad name."
	zone = BODY_ZONE_CHEST


code:
/obj/item/organ/artery/groin
	name = "iliac artery"
	desc = "My anus is bleeding!"
	zone = BODY_ZONE_PRECISE_GROIN


code:
/obj/item/organ/artery/head
	name = "temporal artery"
	desc = "Well, this one was certainly temporal."
	zone = BODY_ZONE_HEAD


code:
/obj/item/organ/artery/l_arm
	name = "basilic vein"
	zone = BODY_ZONE_L_ARM
	blood_flow = ARTERIAL_BLOOD_FLOW * 0.75


code:
/obj/item/organ/artery/l_eye
	name = "central retinal artery"
	zone = BODY_ZONE_PRECISE_L_EYE
	blood_flow = ARTERIAL_BLOOD_FLOW * 0.35


code:
/obj/item/organ/artery/l_foot
	name = "dorsalis pedis artery"
	zone = BODY_ZONE_PRECISE_L_FOOT
	blood_flow = ARTERIAL_BLOOD_FLOW * 0.5


code:
/obj/item/organ/artery/l_hand
	name = "deep palmar arch"
	zone = BODY_ZONE_PRECISE_L_HAND
	blood_flow = ARTERIAL_BLOOD_FLOW * 0.5


code:
/obj/item/organ/artery/l_leg
	name = "femoral artery"
	zone = BODY_ZONE_L_LEG


code:
/obj/item/organ/artery/mouth
	name = "facial artery"
	zone = BODY_ZONE_PRECISE_MOUTH


code:
/obj/item/organ/artery/neck
	name = "carotid artery"
	zone = BODY_ZONE_PRECISE_NECK
	blood_flow = ARTERIAL_BLOOD_FLOW * 2


code:
/obj/item/organ/artery/r_arm
	name = "basilic vein"
	zone = BODY_ZONE_R_ARM
	blood_flow = ARTERIAL_BLOOD_FLOW * 0.75


code:
/obj/item/organ/artery/r_eye
	name = "central retinal artery"
	zone = BODY_ZONE_PRECISE_R_EYE
	blood_flow = ARTERIAL_BLOOD_FLOW * 0.35


code:
/obj/item/organ/artery/r_foot
	name = "dorsalis pedis artery"
	zone = BODY_ZONE_PRECISE_R_FOOT
	blood_flow = ARTERIAL_BLOOD_FLOW * 0.5


code:
/obj/item/organ/artery/r_hand
	name = "deep palmar arch"
	zone = BODY_ZONE_PRECISE_R_HAND
	blood_flow = ARTERIAL_BLOOD_FLOW * 0.5


code:
/obj/item/organ/artery/r_leg
	name = "femoral artery"
	zone = BODY_ZONE_R_LEG