code:
//This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:32

/*
CONTAINS:
RCD
*/
/obj/item/weapon/rcd
	name = "rapid-construction-device (RCD)"
	desc = "A device used to rapidly build and deconstruct walls and floors."
	icon = 'icons/obj/items.dmi'
	icon_state = "rcd"
	opacity = 0
	density = 0
	anchored = 0
	flags = CONDUCT
	force = 10
	throwforce = 10
	throw_speed = 3
	throw_range = 5
	w_class = 3
	materials = list(MAT_METAL=100000)
	origin_tech = "engineering=4;materials=2"
	req_access_txt = "11"
	var/datum/effect_system/spark_spread/spark_system
	var/matter = 0
	var/max_matter = 160
	var/working = 0
	var/mode = 1
	var/canRturf = 0
	var/airlock_type = /obj/machinery/door/airlock
	var/advanced_airlock_setting = 1 //Set to 1 if you want more paintjobs available
	var/sheetmultiplier	= 4			 //Controls the amount of matter added for each glass/metal sheet, triple for plasteel
	var/plasteelmultiplier = 3 //Plasteel is worth 3 times more than glass or metal

	var/list/conf_access = null
	var/use_one_access = 0 //If the airlock should require ALL or only ONE of the listed accesses.

	/* Construction costs */

	var/wallcost = 16
	var/floorcost = 2
	var/grillecost = 4
	var/windowcost = 8
	var/airlockcost = 16
	var/deconwallcost = 26
	var/deconfloorcost = 33
	var/decongrillecost = 4
	var/deconwindowcost = 8
	var/deconairlockcost = 32

	/* Build delays (deciseconds) */

	var/walldelay = 20
	var/floordelay = null //space wind's a bitch
	var/grilledelay = 40
	var/windowdelay = 40
	var/airlockdelay = 50
	var/deconwalldelay = 40
	var/deconfloordelay = 50
	var/decongrilledelay = null //as rapid as wirecutters
	var/deconwindowdelay = 50
	var/deconairlockdelay = 50

/obj/item/weapon/rcd/suicide_act(mob/user)
	user.visible_message("[user] sets the RCD to 'Wall' and points it down \his throat! It looks like \he's trying to commit suicide..")
	return (BRUTELOSS)

/obj/item/weapon/rcd/verb/change_airlock_access()
	set name = "Change Airlock Access"
	set category = "Object"
	set src in usr

	if (!ishuman(usr) && !usr.has_unlimited_silicon_privilege)
		return ..(usr)

	var/mob/living/carbon/human/H = usr
	if(H.getBrainLoss() >= 60)
		return

	var/t1 = text("")

	if(use_one_access)
		t1 += "Restriction Type: At least one access required
"
	else
		t1 += "Restriction Type: All accesses required
"

	t1 += "Remove All
"

	var/accesses = ""
	accesses += "
Access
"
	accesses += "
"
	accesses += "
"
	for(var/i = 1; i <= 7; i++)
		accesses += "[get_region_accesses_name(i)]:	"
	accesses += "

"
	for(var/i = 1; i <= 7; i++)
		accesses += ""
		for(var/A in get_region_accesses(i))
			if(A in conf_access)
				accesses += "[replacetext(get_access_desc(A), " ", "&nbsp")] "
			else
				accesses += "[replacetext(get_access_desc(A), " ", "&nbsp")] "
			accesses += "
"
		accesses += "	"
	accesses += "

"
	t1 += "<tt>[accesses]</tt>"

	t1 += text("
Close
\n", src)

	var/datum/browser/popup = new(usr, "airlock_electronics", "Access Control", 900, 500)
	popup.set_content(t1)
	popup.set_title_image(usr.browse_rsc_icon(src.icon, src.icon_state))
	popup.open()
	onclose(usr, "airlock")

/obj/item/weapon/rcd/Topic(href, href_list)
	..()
	if (usr.stat || usr.restrained())
		return
	if (href_list["close"])
		usr << browse(null, "window=airlock")
		return

	if (href_list["access"])
		toggle_access(href_list["access"])

	change_airlock_access()

/obj/item/weapon/rcd/proc/toggle_access(acc)
	if (acc == "all")
		conf_access = null
	else if(acc == "one")
		use_one_access = !use_one_access
	else
		var/req = text2num(acc)

		if (conf_access == null)
			conf_access = list()

		if (!(req in conf_access))
			conf_access += req
		else
			conf_access -= req
			if (!conf_access.len)
				conf_access = null

/obj/item/weapon/rcd/verb/change_airlock_setting()
	set name = "Change Airlock Setting"
	set category = "Object"
	set src in usr

	var airlockcat = input(usr, "Select whether the airlock is solid or glass.") in list("Solid", "Glass")
	switch(airlockcat)
		if("Solid")
			if(advanced_airlock_setting == 1)
				var airlockpaint = input(usr, "Select the paintjob of the airlock.") in list("Default", "Engineering", "Atmospherics", "Security", "Command", "Medical", "Research", "Mining", "Maintenance", "External", "High Security")
				switch(airlockpaint)
					if("Default")
						airlock_type = /obj/machinery/door/airlock
					if("Engineering")
						airlock_type = /obj/machinery/door/airlock/engineering
					if("Atmospherics")
						airlock_type = /obj/machinery/door/airlock/atmos
					if("Security")
						airlock_type = /obj/machinery/door/airlock/security
					if("Command")
						airlock_type = /obj/machinery/door/airlock/command
					if("Medical")
						airlock_type = /obj/machinery/door/airlock/medical
					if("Research")
						airlock_type = /obj/machinery/door/airlock/research
					if("Mining")
						airlock_type = /obj/machinery/door/airlock/mining
					if("Maintenance")
						airlock_type = /obj/machinery/door/airlock/maintenance
					if("External")
						airlock_type = /obj/machinery/door/airlock/external
					if("High Security")
						airlock_type = /obj/machinery/door/airlock/highsecurity
			else
				airlock_type = /obj/machinery/door/airlock

		if("Glass")
			if(advanced_airlock_setting == 1)
				var airlockpaint = input(usr, "Select the paintjob of the airlock.") in list("Default", "Engineering", "Atmospherics", "Security", "Command", "Medical", "Research", "Mining")
				switch(airlockpaint)
					if("Default")
						airlock_type = /obj/machinery/door/airlock/glass
					if("Engineering")
						airlock_type = /obj/machinery/door/airlock/glass_engineering
					if("Atmospherics")
						airlock_type = /obj/machinery/door/airlock/glass_atmos
					if("Security")
						airlock_type = /obj/machinery/door/airlock/glass_security
					if("Command")
						airlock_type = /obj/machinery/door/airlock/glass_command
					if("Medical")
						airlock_type = /obj/machinery/door/airlock/glass_medical
					if("Research")
						airlock_type = /obj/machinery/door/airlock/glass_research
					if("Mining")
						airlock_type = /obj/machinery/door/airlock/glass_mining
			else
				airlock_type = /obj/machinery/door/airlock/glass
		else
			airlock_type = /obj/machinery/door/airlock

/obj/item/weapon/rcd/New()
	..()
	desc = "An RCD. It currently holds [matter]/[max_matter] matter-units."
	src.spark_system = new /datum/effect_system/spark_spread
	spark_system.set_up(5, 0, src)
	spark_system.attach(src)
	rcd_list += src
	return

/obj/item/weapon/rcd/Destroy()
	qdel(spark_system)
	spark_system = null
	rcd_list -= src
	return ..()

/obj/item/weapon/rcd/attackby(obj/item/weapon/W, mob/user, params)
	..()
	if(isrobot(user))	//Make sure cyborgs can't load their RCDs
		return
	var/loaded = 0
	if(istype(W, /obj/item/weapon/rcd_ammo))
		var/obj/item/weapon/rcd_ammo/R = W
		if((matter + R.ammoamt) > max_matter)
			user << "The RCD can't hold any more matter-units!"
			return
		if(!user.unEquip(W))
			return
		qdel(W)
		matter += R.ammoamt
		playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
		loaded = 1
	else if(istype(W, /obj/item/stack/sheet/metal) || istype(W, /obj/item/stack/sheet/glass))
		loaded = loadwithsheets(W, sheetmultiplier, user)
	else if(istype(W, /obj/item/stack/sheet/plasteel))
		loaded = loadwithsheets(W, plasteelmultiplier*sheetmultiplier, user) //Plasteel is worth 3 times more than glass or metal
	if(loaded)
		user << "The RCD now holds [matter]/[max_matter] matter-units."
		desc = "A RCD. It currently holds [matter]/[max_matter] matter-units."
	return

/obj/item/weapon/rcd/proc/loadwithsheets(obj/item/stack/sheet/S, value, mob/user)
    var/maxsheets = round((max_matter-matter)/value)    //calculate the max number of sheets that will fit in RCD
    if(maxsheets > 0)
        if(S.amount > maxsheets)
            //S.amount -= maxsheets
            S.use(maxsheets)
            matter += value*maxsheets
            playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
            user << "You insert [maxsheets] [S.name] sheets into the RCD. "
        else
            matter += value*(S.amount)
            user.unEquip()
            S.use(S.amount)
            playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
            user << "You insert [S.amount] [S.name] sheets into the RCD. "

        return 1
    user << "You can't insert any more [S.name] sheets into the RCD!"
    return 0

/obj/item/weapon/rcd/attack_self(mob/user)
	//Change the mode
	playsound(src.loc, 'sound/effects/pop.ogg', 50, 0)
	switch(mode)
		if(1)
			mode = 2
			user << "You change RCD's mode to 'Airlock'."
		if(2)
			mode = 3
			user << "You change RCD's mode to 'Deconstruct'."
		if(3)
			mode = 4
			user << "You change RCD's mode to 'Grilles & Windows'."
		if(4)
			mode = 1
			user << "You change RCD's mode to 'Floor & Walls'."

	if(prob(20))
		src.spark_system.start()
	return

/obj/item/weapon/rcd/proc/activate()
	playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)

/obj/item/weapon/rcd/afterattack(atom/A, mob/user, proximity)
	if(!proximity) return 0
	if(istype(A,/area/shuttle)||istype(A,/turf/open/space/transit))
		return 0
	if(!(istype(A, /turf) || istype(A, /obj/machinery/door/airlock) || istype(A, /obj/structure/grille) || istype(A, /obj/structure/window)))
		return 0

	switch(mode)
		if(1)
			if(istype(A, /turf/open/space))
				var/turf/open/space/S = A
				if(useResource(floorcost, user))
					user << "You start building floor..."
					activate()
					S.ChangeTurf(/turf/open/floor/plating)
					return 1
				return 0

			if(istype(A, /turf/open/floor))
				var/turf/open/floor/F = A
				if(checkResource(wallcost, user))
					user << "You start building wall..."
					playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
					if(do_after(user, walldelay, target = A))
						if(!useResource(wallcost, user)) return 0
						activate()
						F.ChangeTurf(/turf/closed/wall)
						return 1
				return 0

		if(2)
			if(istype(A, /turf/open/floor))
				if(checkResource(airlockcost, user))
					var/door_check = 1
					for(var/obj/machinery/door/D in A)
						if(!D.sub_door)
							door_check = 0
							break

					if(door_check)
						user << "You start building airlock..."
						playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
						if(do_after(user, airlockdelay, target = A))
							if(!useResource(airlockcost, user)) return 0
							activate()
							var/obj/machinery/door/airlock/T = new airlock_type( A )

							T.electronics = new/obj/item/weapon/electronics/airlock( src.loc )

							if(conf_access)
								T.electronics.accesses = conf_access.Copy()
							T.electronics.one_access = use_one_access

							if(T.electronics.one_access)
								T.req_one_access = T.electronics.accesses
							else
								T.req_access = T.electronics.accesses

							if(!T.checkForMultipleDoors())
								qdel(T)
								useResource(-airlockcost, user)
								return 0
							T.autoclose = 1
							return 1
						return 0
					else
						user << "There is another door here!"
						return 0
				return 0

		if(3)
			if(istype(A, /turf/closed/wall))
				var/turf/closed/wall/W = A
				if(istype(W, /turf/closed/wall/r_wall) && !canRturf)
					return 0
				if(checkResource(deconwallcost, user))
					user << "You start deconstructing wall..."
					playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
					if(do_after(user, deconwalldelay, target = A))
						if(!useResource(deconwallcost, user)) return 0
						activate()
						W.ChangeTurf(/turf/open/floor/plating)
						return 1
				return 0

			if(istype(A, /turf/open/floor))
				var/turf/open/floor/F = A
				if(istype(F, /turf/open/floor/engine) && !canRturf)
					return 0
				if(istype(F, F.baseturf))
					user << "You can't dig any deeper!"
					return 0
				else if(checkResource(deconfloorcost, user))
					user << "You start deconstructing floor..."
					playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
					if(do_after(user, deconfloordelay, target = A))
						if(!useResource(deconfloorcost, user)) return 0
						activate()
						F.ChangeTurf(F.baseturf)
						return 1
				return 0

			if(istype(A, /obj/machinery/door/airlock))
				if(checkResource(deconairlockcost, user))
					user << "You start deconstructing airlock..."
					playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
					if(do_after(user, deconairlockdelay, target = A))
						if(!useResource(deconairlockcost, user)) return 0
						activate()
						qdel(A)
						return 1
				return	0

			if(istype(A, /obj/structure/window))
				if(checkResource(deconwindowcost, user))
					user << "You start deconstructing the window..."
					playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
					if(do_after(user, deconwindowdelay, target = A))
						if(!useResource(deconwindowcost, user)) return 0
						activate()
						qdel(A)
						return 1
				return	0

			if(istype(A, /obj/structure/grille))
				var/obj/structure/grille/G = A
				if(!G.shock(user, 90)) //if it's shocked, try to shock them
					if(useResource(decongrillecost, user))
						user << "You start deconstructing the grille..."
						activate()
						playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
						qdel(A)
						return 1
					return 0

		if (4)
			if(istype(A, /turf/open/floor))
				if(checkResource(grillecost, user))
					for(var/obj/structure/grille/GRILLE in A)
						user << "There is already a grille there!"
						return 0
					user << "You start building a grille..."
					playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
					if(do_after(user, grilledelay, target = A))
						if(!useResource(grillecost, user)) return 0
						activate()
						var/obj/structure/grille/G = new/obj/structure/grille(A)
						G.anchored = 1
						return 1
					return 0
				return 0
			if(istype(A, /obj/structure/grille))
				if(checkResource(windowcost, user))
					user << "You start building a window..."
					playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
					if(do_after(user, windowdelay, target = A))
						if(locate(/obj/structure/window) in A.loc) return 0
						if(!useResource(windowcost, user)) return 0
						activate()
						var/obj/structure/window/WD = new/obj/structure/window/fulltile(A.loc)
						WD.anchored = 1
						return 1
					return 0
				return 0

		else
			user << "ERROR: RCD in MODE: [mode] attempted use by [user]. Send this text #coderbus or an admin."
			return 0

/obj/item/weapon/rcd/proc/useResource(amount, mob/user)
	if(matter < amount)
		return 0
	matter -= amount
	desc = "An RCD. It currently holds [matter]/[max_matter] matter-units."
	return 1

/obj/item/weapon/rcd/proc/checkResource(amount, mob/user)
	return matter >= amount
/obj/item/weapon/rcd/borg/useResource(amount, mob/user)
	if(!isrobot(user))
		return 0
	return user:cell:use(amount * 72) //borgs get 1.3x the use of their RCDs

/obj/item/weapon/rcd/borg/checkResource(amount, mob/user)
	if(!isrobot(user))
		return 0
	return user:cell:charge >= (amount * 72)

/obj/item/weapon/rcd/borg/New()
	..()
	desc = "A device used to rapidly build walls and floors."
	canRturf = 1

/obj/item/weapon/rcd/loaded
	matter = 160

/obj/item/weapon/rcd/combat
	name = "industrial RCD"
	max_matter = 500
	matter = 500
	canRturf = 1

/obj/item/weapon/rcd_ammo
	name = "compressed matter cartridge"
	desc = "Highly compressed matter for the RCD."
	icon = 'icons/obj/ammo.dmi'
	icon_state = "rcd"
	item_state = "rcdammo"
	origin_tech = "materials=3"
	materials = list(MAT_METAL=3000, MAT_GLASS=2000)
	var/ammoamt = 40

/obj/item/weapon/rcd_ammo/large
	origin_tech = "materials=4"
	materials = list(MAT_METAL=12000, MAT_GLASS=8000)
	ammoamt = 160


code:
//This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:32

/*
CONTAINS:
RPD
*/
#define PIPE_BINARY		0
#define PIPE_BENDABLE	1
#define PIPE_TRINARY	2
#define PIPE_TRIN_M		3
#define PIPE_UNARY		4
#define PIPE_QUAD		5

#define PAINT_MODE -2
#define EATING_MODE -1
#define ATMOS_MODE 0
#define METER_MODE 1
#define DISPOSALS_MODE 2

#define CATEGORY_ATMOS 0
#define CATEGORY_DISPOSALS 1

/datum/pipe_info
	var/id=-1
	var/categoryId = CATEGORY_ATMOS
	var/dir=SOUTH
	var/dirtype = PIPE_BENDABLE
	var/icon = 'icons/obj/atmospherics/pipes/pipe_item.dmi'
	var/icon_state=""
	var/selected=0

/datum/pipe_info/New(pid,direction,dt)
	src.id=pid
	src.icon_state=pipeID2State["[pid]"]
	src.dir=direction
	src.dirtype=dt

/datum/pipe_info/proc/Render(dispenser,label)
	return "
[label]
"

/datum/pipe_info/meter
	icon = 'icons/obj/atmospherics/pipes/simple.dmi'
	icon_state = "meterX"

/datum/pipe_info/meter/New()
	return

/datum/pipe_info/meter/Render(dispenser,label)
	return "
[label]
" //hardcoding is no

var/global/list/disposalpipeID2State=list(
	"pipe-s",
	"pipe-c",
	"pipe-j1",
	"pipe-j2",
	"pipe-y",
	"pipe-t",
	"disposal",
	"outlet",
	"intake",
	"pipe-j1s",
	"pipe-j2s"
)

/datum/pipe_info/disposal
	categoryId = CATEGORY_DISPOSALS
	icon = 'icons/obj/atmospherics/pipes/disposal.dmi'
	icon_state = "meterX"

/datum/pipe_info/disposal/New(var/pid,var/dt)
	src.id=pid
	src.icon_state=disposalpipeID2State[pid+1]
	src.dir=2
	src.dirtype=dt
	if(pid<DISP_END_BIN || pid>DISP_END_CHUTE)
		icon_state = "con[icon_state]"

/datum/pipe_info/disposal/Render(dispenser,label)
	return "
[label]
" //avoid hardcoding.

//find these defines in code\game\machinery\pipe\consruction.dm
var/global/list/RPD_recipes=list(
	"Regular Pipes" = list(
		"Pipe"           = new /datum/pipe_info(PIPE_SIMPLE,			1, PIPE_BENDABLE),
		//"Bent Pipe"      = new /datum/pipe_info(PIPE_SIMPLE,	 		5, PIPE_BENT),
		"Manifold"       = new /datum/pipe_info(PIPE_MANIFOLD, 			1, PIPE_TRINARY),
		"Manual Valve"   = new /datum/pipe_info(PIPE_MVALVE, 			1, PIPE_BINARY),
		"Digital Valve"  = new /datum/pipe_info(PIPE_DVALVE,			1, PIPE_BINARY),
		"4-Way Manifold" = new /datum/pipe_info(PIPE_4WAYMANIFOLD,		1, PIPE_QUAD),
	),
	"Devices"=list(
		"Connector"      = new /datum/pipe_info(PIPE_CONNECTOR,			1, PIPE_UNARY),
		"Unary Vent"     = new /datum/pipe_info(PIPE_UVENT,				1, PIPE_UNARY),
		"Gas Pump"       = new /datum/pipe_info(PIPE_PUMP,				1, PIPE_UNARY),
		"Passive Gate"   = new /datum/pipe_info(PIPE_PASSIVE_GATE,		1, PIPE_UNARY),
		"Volume Pump"    = new /datum/pipe_info(PIPE_VOLUME_PUMP,		1, PIPE_UNARY),
		"Scrubber"       = new /datum/pipe_info(PIPE_SCRUBBER,			1, PIPE_UNARY),
		"Meter"          = new /datum/pipe_info/meter(),
		"Gas Filter"     = new /datum/pipe_info(PIPE_GAS_FILTER,		1, PIPE_TRIN_M),
		"Gas Mixer"      = new /datum/pipe_info(PIPE_GAS_MIXER,			1, PIPE_TRIN_M),
//		"Injector"       = new /datum/pipe_info(PIPE_INJECTOR,     		1, PIPE_UNARY),
	),
	"Heat Exchange" = list(
		"Pipe"           = new /datum/pipe_info(PIPE_HE,				1, PIPE_BENDABLE),
		//"Bent Pipe"      = new /datum/pipe_info(PIPE_HE,				5, PIPE_BENT),
		"Manifold"       = new /datum/pipe_info(PIPE_HE_MANIFOLD, 		1, PIPE_TRINARY),
		"4-Way Manifold" = new /datum/pipe_info(PIPE_HE_4WAYMANIFOLD,	1, PIPE_QUAD),
		"Junction"       = new /datum/pipe_info(PIPE_JUNCTION,			1, PIPE_UNARY),
		"Heat Exchanger" = new /datum/pipe_info(PIPE_HEAT_EXCHANGE,		1, PIPE_UNARY),
	),
	"Disposal Pipes" = list(
		"Pipe"          = new /datum/pipe_info/disposal(DISP_PIPE_STRAIGHT,	PIPE_BINARY),
		"Bent Pipe"     = new /datum/pipe_info/disposal(DISP_PIPE_BENT,		PIPE_TRINARY),
		"Junction"      = new /datum/pipe_info/disposal(DISP_JUNCTION,		PIPE_TRINARY),
		"Y-Junction"    = new /datum/pipe_info/disposal(DISP_YJUNCTION,		PIPE_TRINARY),
		"Trunk"         = new /datum/pipe_info/disposal(DISP_END_TRUNK,		PIPE_TRINARY),
		"Bin"           = new /datum/pipe_info/disposal(DISP_END_BIN,		PIPE_QUAD),
		"Outlet"        = new /datum/pipe_info/disposal(DISP_END_OUTLET,	PIPE_UNARY),
		"Chute"         = new /datum/pipe_info/disposal(DISP_END_CHUTE,		PIPE_UNARY),
		"Sort Junction" = new /datum/pipe_info/disposal(DISP_SORTJUNCTION,	PIPE_TRINARY),
	)
)
/obj/item/weapon/pipe_dispenser
	name = "Rapid Piping Device (RPD)"
	desc = "A device used to rapidly pipe things."
	icon = 'icons/obj/items.dmi'
	icon_state = "rpd"
	flags = CONDUCT
	force = 10
	throwforce = 10
	throw_speed = 1
	throw_range = 5
	w_class = 3
	materials = list(MAT_METAL=75000, MAT_GLASS=37500)
	origin_tech = "engineering=4;materials=2"
	var/datum/effect_system/spark_spread/spark_system
	var/working = 0
	var/p_type = PIPE_SIMPLE
	var/p_conntype = PIPE_BENDABLE
	var/p_dir = 1
	var/p_flipped = 0
	var/p_class = ATMOS_MODE
	var/list/paint_colors = list(
		"grey"		= rgb(255,255,255),
		"red"		= rgb(255,0,0),
		"blue"		= rgb(0,0,255),
		"cyan"		= rgb(0,256,249),
		"green"		= rgb(30,255,0),
		"yellow"	= rgb(255,198,0),
		"purple"	= rgb(130,43,255)
	)
	var/paint_color="grey"
	var/screen = CATEGORY_ATMOS //Starts on the atmos tab.

/obj/item/weapon/pipe_dispenser/New()
	. = ..()
	spark_system = new /datum/effect_system/spark_spread
	spark_system.set_up(5, 0, src)
	spark_system.attach(src)

/obj/item/weapon/pipe_dispenser/Destroy()
	qdel(spark_system)
	spark_system = null
	return ..()

/obj/item/weapon/pipe_dispenser/attack_self(mob/user)
	show_menu(user)

/obj/item/weapon/pipe_dispenser/suicide_act(mob/user)
	user.visible_message("[user] points the end of the RPD down \his throat and presses a button! It looks like \he's trying to commit suicide...")
	playsound(get_turf(user), 'sound/machines/click.ogg', 50, 1)
	playsound(get_turf(user), 'sound/items/Deconstruct.ogg', 50, 1)
	return(BRUTELOSS)

/obj/item/weapon/pipe_dispenser/proc/render_dir_img(_dir,pic,title,flipped=0)
	var/selected=" class=\"imglink\""
	if(_dir == p_dir)
		selected=" class=\"imglink selected\""
	return ""

/obj/item/weapon/pipe_dispenser/proc/show_menu(mob/user)
	if(!user || !src)
		return 0
	var/dat = {"
Type

Utilities:

"}
	if(p_class != EATING_MODE)
		dat += "
Eat Pipes
"
	else
		dat += "
Eat Pipes
"
	if(p_class != PAINT_MODE)
		dat += "
Paint Pipes
"
	else
		dat += "
Paint Pipes
"
	dat += "
"

	dat += "Category:
"
	if(screen == CATEGORY_ATMOS)
		dat += "Atmospherics Disposals
"
	else if(screen == CATEGORY_DISPOSALS)
		dat += "Atmospherics Disposals
"
	dat += "
"

	var/icon/preview=null
	var/datbuild = ""
	for(var/category in RPD_recipes)
		var/list/cat=RPD_recipes[category]
		for(var/label in cat)
			var/datum/pipe_info/I = cat[label]
			var/found=0
			if(I.id == p_type)
				if((p_class == ATMOS_MODE || p_class == METER_MODE) && (I.type == /datum/pipe_info || I.type == /datum/pipe_info/meter))
					found=1
				else if(p_class == DISPOSALS_MODE && I.type==/datum/pipe_info/disposal)
					found=1
			if(found)
				preview=new /icon(I.icon,I.icon_state)
			if(screen == I.categoryId)
				if(I.id == p_type && p_class >= 0)
					datbuild += "[label]"
				else
					datbuild += I.Render(src,label)

		if(length(datbuild) > 0)
			dat += "[category]:
"
			dat += datbuild
			datbuild = ""
		dat += "
"

	var/color_css=""
	var/color_picker=""
	for(var/color_name in paint_colors)
		var/color=paint_colors[color_name]
		color_css += {"
			a.color.[color_name] {
				color: [color];
			}
			a.color.[color_name]:hover {
				border:1px solid [color];
			}
			a.color.[color_name].selected {
				background-color: [color];
			}
		"}
		var/selected=""
		if(color_name==paint_color)
			selected = " selected"
		color_picker += {"•"}

	var/dirsel="
Direction
"
	switch(p_conntype)
		if(-1)
			if(p_class==PAINT_MODE)
				dirsel = "
Color
[color_picker]"
			else
				dirsel = ""

		if(PIPE_BINARY) // Straight, N-S, W-E
			if(preview)
				user << browse_rsc(new /icon(preview, dir=NORTH), "vertical.png")
				user << browse_rsc(new /icon(preview, dir=EAST), "horizontal.png")

				dirsel += "
"
				dirsel += render_dir_img(1,"vertical.png","Vertical")
				dirsel += render_dir_img(4,"horizontal.png","Horizontal")
				dirsel += "
"
			else
				dirsel+={"

			↕
			↔

				"}

		if(PIPE_BENDABLE) // Bent, N-W, N-E etc
			if(preview)
				user << browse_rsc(new /icon(preview, dir=NORTH), "vertical.png")
				user << browse_rsc(new /icon(preview, dir=EAST), "horizontal.png")
				user << browse_rsc(new /icon(preview, dir=NORTHWEST),  "nw.png")
				user << browse_rsc(new /icon(preview, dir=NORTHEAST),  "ne.png")
				user << browse_rsc(new /icon(preview, dir=SOUTHWEST),  "sw.png")
				user << browse_rsc(new /icon(preview, dir=SOUTHEAST),  "se.png")

				dirsel += "
"
				dirsel += render_dir_img(1,"vertical.png","Vertical")
				dirsel += render_dir_img(4,"horizontal.png","Horizontal")
				dirsel += "
"
				dirsel += render_dir_img(9,"nw.png","West to North")
				dirsel += render_dir_img(5,"ne.png","North to East")
				dirsel += "
"
				dirsel += render_dir_img(10,"sw.png","South to West")
				dirsel += render_dir_img(6,"se.png","East to South")
				dirsel += "
"
			else
				dirsel+={"

			↕
			↔

			╝
			╚

			╗
			╔

				"}
		if(PIPE_TRINARY) // Manifold
			if(preview)
				user << browse_rsc(new /icon(preview, dir=NORTH), "s.png")
				user << browse_rsc(new /icon(preview, dir=EAST),  "w.png")
				user << browse_rsc(new /icon(preview, dir=SOUTH), "n.png")
				user << browse_rsc(new /icon(preview, dir=WEST),  "e.png")

				dirsel += "
"
				dirsel += render_dir_img(1,"s.png","West South East")
				dirsel += render_dir_img(4,"w.png","North West South")
				dirsel += "
"
				dirsel += render_dir_img(2,"n.png","East North West")
				dirsel += render_dir_img(8,"e.png","South East North")
				dirsel += "
"
			else
				dirsel+={"

			╦
			╣

			╩
			╠

				"}
		if(PIPE_TRIN_M) // Mirrored ones
			if(preview)
				user << browse_rsc(new /icon(preview, dir=NORTH), "s.png")
				user << browse_rsc(new /icon(preview, dir=EAST),  "w.png")
				user << browse_rsc(new /icon(preview, dir=SOUTH), "n.png")
				user << browse_rsc(new /icon(preview, dir=WEST),  "e.png")
				user << browse_rsc(new /icon(preview, dir=SOUTHEAST), "sm.png") //each mirror icon is 45 anticlockwise from it's real direction
				user << browse_rsc(new /icon(preview, dir=NORTHEAST),  "wm.png")
				user << browse_rsc(new /icon(preview, dir=NORTHWEST), "nm.png")
				user << browse_rsc(new /icon(preview, dir=SOUTHWEST),  "em.png")

				dirsel += "
"
				dirsel += render_dir_img(1,"s.png","West South East")
				dirsel += render_dir_img(4,"w.png","North West South")
				dirsel += "
"
				dirsel += render_dir_img(2,"n.png","East North West")
				dirsel += render_dir_img(8,"e.png","South East North")
				dirsel += "
"
				dirsel += render_dir_img(6,"sm.png","West South East", 1)
				dirsel += render_dir_img(5,"wm.png","North West South", 1)
				dirsel += "
"
				dirsel += render_dir_img(9,"nm.png","East North West", 1)
				dirsel += render_dir_img(10,"em.png","South East North", 1)
				dirsel += "
"
			else
				dirsel+={"

			╦
			╣

			╩
			╠

			╦
			╣

			╩
			╠

				"}
		if(PIPE_UNARY) // Stuff with four directions - includes pumps etc.
			if(preview)
				user << browse_rsc(new /icon(preview, dir=NORTH), "n.png")
				user << browse_rsc(new /icon(preview, dir=EAST),  "e.png")
				user << browse_rsc(new /icon(preview, dir=SOUTH), "s.png")
				user << browse_rsc(new /icon(preview, dir=WEST),  "w.png")

				dirsel += "
"
				dirsel += render_dir_img(NORTH,"n.png","North")
				dirsel += render_dir_img(EAST, "e.png","East")
				dirsel += render_dir_img(SOUTH,"s.png","South")
				dirsel += render_dir_img(WEST, "w.png","West")
				dirsel += "
"
			else
				dirsel+={"

			↑
			→
			↓
			←

					"}
		if(PIPE_QUAD) // Single icon_state (eg 4-way manifolds)
			if(preview)
				user << browse_rsc(new /icon(preview), "pipe.png")

				dirsel += "
"
				dirsel += render_dir_img(1,"pipe.png","Pipe")
				dirsel += "
"
			else
				dirsel+={"

			↕

				"}

	var/datsytle = {"
"}

	dat = datsytle + dirsel + dat

	var/datum/browser/popup = new(user, "pipedispenser", name, 300, 550)
	popup.set_content(dat)
	popup.open()
	return

/obj/item/weapon/pipe_dispenser/Topic(href, href_list)
	if(!usr.canUseTopic(src))
		usr << browse(null, "window=pipedispenser")
		return
	usr.set_machine(src)
	src.add_fingerprint(usr)
	if(href_list["screen"])
		screen = text2num(href_list["screen"])
		show_menu(usr)

	if(href_list["setdir"])
		p_dir= text2num(href_list["setdir"])
		p_flipped = text2num(href_list["flipped"])
		show_menu(usr)

	if(href_list["eatpipes"])
		p_class = EATING_MODE
		p_conntype=-1
		p_dir=1
		src.spark_system.start()
		playsound(get_turf(src), 'sound/effects/pop.ogg', 50, 0)
		show_menu(usr)

	if(href_list["paintpipes"])
		p_class = PAINT_MODE
		p_conntype = -1
		p_dir = 1
		src.spark_system.start()
		playsound(get_turf(src), 'sound/effects/pop.ogg', 50, 0)
		show_menu(usr)

	if(href_list["set_color"])
		paint_color = href_list["set_color"]
		src.spark_system.start()
		playsound(get_turf(src), 'sound/effects/pop.ogg', 50, 0)
		show_menu(usr)

	if(href_list["makepipe"])
		p_type = text2path(href_list["makepipe"])
		p_dir = text2num(href_list["dir"])
		p_conntype = text2num(href_list["type"])
		p_class = ATMOS_MODE
		src.spark_system.start()
		playsound(get_turf(src), 'sound/effects/pop.ogg', 50, 0)
		show_menu(usr)

	if(href_list["makemeter"])
		p_class = METER_MODE
		p_conntype = -1
		p_dir = 1
		src.spark_system.start()
		playsound(get_turf(src), 'sound/effects/pop.ogg', 50, 0)
		show_menu(usr)

	if(href_list["dmake"])
		p_type = text2num(href_list["dmake"])
		p_conntype = text2num(href_list["type"])
		p_dir = 1
		p_class = DISPOSALS_MODE
		src.spark_system.start()
		playsound(get_turf(src), 'sound/effects/pop.ogg', 50, 0)
		show_menu(usr)

/obj/item/weapon/pipe_dispenser/afterattack(atom/A, mob/user)
	if(!in_range(A,user) || loc != user)
		return 0

	if(!user.IsAdvancedToolUser())
		user << "You don't have the dexterity to do this!"
		return 0

	if(istype(A,/area/shuttle)||istype(A,/turf/open/space/transit))
		return 0

	//So that changing the menu settings doesn't affect the pipes already being built.
	var/queued_p_type = p_type
	var/queued_p_dir = p_dir
	var/queued_p_flipped = p_flipped

	switch(p_class)
		if(PAINT_MODE) // Paint pipes
			if(!istype(A,/obj/machinery/atmospherics/pipe))
				// Avoid spewing errors about invalid mode -2 when clicking on stuff that aren't pipes.
				user << "\The [src]'s error light flickers!  Perhaps you need to only use it on pipes and pipe meters?"
				return 0
			var/obj/machinery/atmospherics/pipe/P = A
			playsound(get_turf(src), 'sound/machines/click.ogg', 50, 1)
			P.color = paint_colors[paint_color]
			P.pipe_color = paint_colors[paint_color]
			P.stored.color = paint_colors[paint_color]
			user.visible_message("[user] paints \the [P] [paint_color].","You paint \the [P] [paint_color].")
			//P.update_icon()
			P.update_node_icon()
			return 1
		if(EATING_MODE) // Eating pipes
			// Must click on an actual pipe or meter.
			if(istype(A,/obj/item/pipe) || istype(A,/obj/item/pipe_meter) || istype(A,/obj/structure/disposalconstruct))
				user << "You start destroying pipe..."
				playsound(get_turf(src), 'sound/machines/click.ogg', 50, 1)
				if(do_after(user, 2, target = A))
					activate()
					qdel(A)
					return 1
				return 0

			// Avoid spewing errors about invalid mode -1 when clicking on stuff that aren't pipes.
			user << "The [src]'s error light flickers!  Perhaps you need to only use it on pipes and pipe meters?"
			return 0
		if(ATMOS_MODE)
			if(!(istype(A, /turf)))
				user << "The [src]'s error light flickers!"
				return 0
			user << "You start building pipes..."
			playsound(get_turf(src), 'sound/machines/click.ogg', 50, 1)
			if(do_after(user, 2, target = A))
				activate()
				var/obj/item/pipe/P = new (A, pipe_type=queued_p_type, dir=queued_p_dir)
				P.flipped = queued_p_flipped
				P.update()
				P.add_fingerprint(usr)
				return 1
			return 0

		if(METER_MODE)
			if(!(istype(A, /turf)))
				user << "The [src]'s error light flickers!"
				return 0
			user << "You start building meter..."
			playsound(get_turf(src), 'sound/machines/click.ogg', 50, 1)
			if(do_after(user, 2, target = A))
				activate()
				new /obj/item/pipe_meter(A)
				return 1
			return 0

		if(DISPOSALS_MODE)
			if(!isturf(A) || is_anchored_dense_turf(A))
				user << "The [src]'s error light flickers!"
				return 0
			user << "You start building pipes..."
			playsound(get_turf(src), 'sound/machines/click.ogg', 50, 1)
			if(do_after(user, 20, target = A))
				var/obj/structure/disposalconstruct/C = new (A, queued_p_type ,queued_p_dir)

				if(!C.can_place())
					user << "There's not enough room to build that here!"
					qdel(C)
					return 0

				activate()

				C.add_fingerprint(usr)
				C.update()
				return 1
			return 0
		else
			..()
			return 0

/obj/item/weapon/pipe_dispenser/proc/activate()
	playsound(get_turf(src), 'sound/items/Deconstruct.ogg', 50, 1)

#undef PIPE_BINARY
#undef PIPE_BENT
#undef PIPE_TRINARY
#undef PIPE_TRIN_M
#undef PIPE_UNARY
#undef PIPE_QUAD
#undef PAINT_MODE
#undef EATING_MODE
#undef ATMOS_MODE
#undef METER_MODE
#undef DISPOSALS_MODE
#undef CATEGORY_ATMOS
#undef CATEGORY_DISPOSALS

license: mit


code:
/*
CONTAINS:
RSF

*/
/obj/item/weapon/rsf
	name = "\improper Rapid-Service-Fabricator"
	desc = "A device used to rapidly deploy service items."
	icon = 'icons/obj/items.dmi'
	icon_state = "rcd"
	opacity = 0
	density = 0
	anchored = 0
	var/matter = 0
	var/mode = 1
	w_class = 3

/obj/item/weapon/rsf/New()
	desc = "A RSF. It currently holds [matter]/30 fabrication-units."
	return

/obj/item/weapon/rsf/attackby(obj/item/weapon/W, mob/user, params)
	..()
	if (istype(W, /obj/item/weapon/rcd_ammo))
		if ((matter + 10) > 30)
			user << "The RSF can't hold any more matter."
			return
		qdel(W)
		matter += 10
		playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
		user << "The RSF now holds [matter]/30 fabrication-units."
		desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

/obj/item/weapon/rsf/attack_self(mob/user)
	playsound(src.loc, 'sound/effects/pop.ogg', 50, 0)
	if (mode == 1)
		mode = 2
		user << "Changed dispensing mode to 'Drinking Glass'"
		return
	if (mode == 2)
		mode = 3
		user << "Changed dispensing mode to 'Paper'"
		return
	if (mode == 3)
		mode = 4
		user << "Changed dispensing mode to 'Pen'"
		return
	if (mode == 4)
		mode = 5
		user << "Changed dispensing mode to 'Dice Pack'"
		return
	if (mode == 5)
		mode = 6
		user << "Changed dispensing mode to 'Cigarette'"
		return
	if (mode == 6)
		mode = 1
		user << "Changed dispensing mode to 'Dosh'"
		return
	// Change mode

/obj/item/weapon/rsf/afterattack(atom/A, mob/user, proximity)
	if(!proximity) return
	if (!(istype(A, /obj/structure/table) || istype(A, /turf/open/floor)))
		return

	if (istype(A, /obj/structure/table) && mode == 1)
		if (istype(A, /obj/structure/table) && matter >= 1)
			user << "Dispensing Dosh..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/stack/spacecash/c10( A.loc )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 200 //once money becomes useful, I guess changing this to a high ammount, like 500 units a kick, till then, enjoy dosh!
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /turf/open/floor) && mode == 1)
		if (istype(A, /turf/open/floor) && matter >= 1)
			user << "Dispensing Dosh..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/stack/spacecash/c10( A )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 200 //once money becomes useful, I guess changing this to a high ammount, like 500 units a kick, till then, enjoy dosh!
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /obj/structure/table) && mode == 2)
		if (istype(A, /obj/structure/table) && matter >= 1)
			user << "Dispensing Drinking Glass..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/weapon/reagent_containers/food/drinks/drinkingglass( A.loc )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 50
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /turf/open/floor) && mode == 2)
		if (istype(A, /turf/open/floor) && matter >= 1)
			user << "Dispensing Drinking Glass..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/weapon/reagent_containers/food/drinks/drinkingglass( A )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 50
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /obj/structure/table) && mode == 3)
		if (istype(A, /obj/structure/table) && matter >= 1)
			user << "Dispensing Paper Sheet..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/weapon/paper( A.loc )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 10
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /turf/open/floor) && mode == 3)
		if (istype(A, /turf/open/floor) && matter >= 1)
			user << "Dispensing Paper Sheet..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/weapon/paper( A )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 10
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /obj/structure/table) && mode == 4)
		if (istype(A, /obj/structure/table) && matter >= 1)
			user << "Dispensing Pen..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/weapon/pen( A.loc )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 50
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /turf/open/floor) && mode == 4)
		if (istype(A, /turf/open/floor) && matter >= 1)
			user << "Dispensing Pen..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/weapon/pen( A )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 50
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /obj/structure/table) && mode == 5)
		if (istype(A, /obj/structure/table) && matter >= 1)
			user << "Dispensing Dice Pack..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/weapon/storage/pill_bottle/dice( A.loc )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 200
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /turf/open/floor) && mode == 5)
		if (istype(A, /turf/open/floor) && matter >= 1)
			user << "Dispensing Dice Pack..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/weapon/storage/pill_bottle/dice( A )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 200
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /obj/structure/table) && mode == 6)
		if (istype(A, /obj/structure/table) && matter >= 1)
			user << "Dispensing Cigarette..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/clothing/mask/cigarette( A.loc )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 10
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return

	else if (istype(A, /turf/open/floor) && mode == 6)
		if (istype(A, /turf/open/floor) && matter >= 1)
			user << "Dispensing Cigarette..."
			playsound(src.loc, 'sound/machines/click.ogg', 10, 1)
			new /obj/item/clothing/mask/cigarette( A )
			if (isrobot(user))
				var/mob/living/silicon/robot/engy = user
				engy.cell.charge -= 10
			else
				matter--
				user << "The RSF now holds [matter]/30 fabrication-units."
				desc = "A RSF. It currently holds [matter]/30 fabrication-units."
		return


code:
/obj/item/weapon/airlock_painter
	name = "airlock painter"
	desc = "An advanced autopainter preprogrammed with several paintjobs for airlocks. Use it on an airlock during or after construction to change the paintjob."
	icon = 'icons/obj/objects.dmi'
	icon_state = "paint sprayer"
	item_state = "paint sprayer"

	w_class = 2

	materials = list(MAT_METAL=50, MAT_GLASS=50)
	origin_tech = "engineering=1"

	flags = CONDUCT
	slot_flags = SLOT_BELT

	var/obj/item/device/toner/ink = null

/obj/item/weapon/airlock_painter/New()
	ink = new /obj/item/device/toner(src)

//This proc doesn't just check if the painter can be used, but also uses it.
//Only call this if you are certain that the painter will be used right after this check!
/obj/item/weapon/airlock_painter/proc/use(mob/user)
	if(can_use(user))
		ink.charges--
		playsound(src.loc, 'sound/effects/spray2.ogg', 50, 1)
		return 1
	else
		return 0

//This proc only checks if the painter can be used.
//Call this if you don't want the painter to be used right after this check, for example
//because you're expecting user input.
/obj/item/weapon/airlock_painter/proc/can_use(mob/user)
	if(!ink)
		user << "There is no toner cardridge installed installed in \the [name]!"
		return 0
	else if(ink.charges < 1)
		user << "\The [name] is out of ink!"
		return 0
	else
		return 1

/obj/item/weapon/airlock_painter/examine(mob/user)
	..()
	if(!ink)
		user << "It doesn't have a toner cardridge installed."
		return
	var/ink_level = "high"
	if(ink.charges < 1)
		ink_level = "empty"
	else if((ink.charges/ink.max_charges) <= 0.25) //25%
		ink_level = "low"
	else if((ink.charges/ink.max_charges) > 1) //Over 100% (admin var edit)
		ink_level = "dangerously high"
	user << "Its ink levels look [ink_level]."

/obj/item/weapon/airlock_painter/attackby(obj/item/weapon/W, mob/user, params)
	..()
	if(istype(W, /obj/item/device/toner))
		if(ink)
			user << "\the [name] already contains \a [ink]."
			return
		if(!user.unEquip(W))
			return
		W.loc = src
		user << "You install \the [W] into \the [name]."
		ink = W
		playsound(src.loc, 'sound/machines/click.ogg', 50, 1)

/obj/item/weapon/airlock_painter/attack_self(mob/user)
	if(ink)
		playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
		ink.loc = user.loc
		user.put_in_hands(ink)
		user << "You remove \the [ink] from \the [name]."
		ink = null


code:
/* Cards
 * Contains:
 *		DATA CARD
 *		ID CARD
 *		FINGERPRINT CARD HOLDER
 *		FINGERPRINT CARD
 */

/*
 * DATA CARDS - Used for the teleporter
 */
/obj/item/weapon/card
	name = "card"
	desc = "Does card things."
	icon = 'icons/obj/card.dmi'
	w_class = 1

	var/list/files = list(  )

/obj/item/weapon/card/data
	name = "data disk"
	desc = "A disk of data."
	icon_state = "data"
	var/function = "storage"
	var/data = "null"
	var/special = null
	item_state = "card-id"

/obj/item/weapon/card/data/verb/label(t as text)
	set name = "Label Disk"
	set category = "Object"
	set src in usr

	if(usr.stat || !usr.canmove || usr.restrained())
		return

	if (t)
		src.name = "data disk- '[t]'"
	else
		src.name = "data disk"
	src.add_fingerprint(usr)
	return

/obj/item/weapon/card/data/clown
	name = "\proper the coordinates to clown planet"
	icon_state = "data"
	item_state = "card-id"
	layer = 3
	level = 2
	desc = "This card contains coordinates to the fabled Clown Planet. Handle with care."
	function = "teleporter"
	data = "Clown Land"

/*
 * ID CARDS
 */
/obj/item/weapon/card/emag
	desc = "It's a card with a magnetic strip attached to some circuitry."
	name = "cryptographic sequencer"
	icon_state = "emag"
	item_state = "card-id"
	origin_tech = "magnets=2;syndicate=2"
	flags = NOBLUDGEON

/obj/item/weapon/card/emag/attack()
	return

/obj/item/weapon/card/emag/afterattack(atom/target, mob/user, proximity)
	var/atom/A = target
	if(!proximity)
		return
	A.emag_act(user)

/obj/item/weapon/card/id
	name = "identification card"
	desc = "A card used to provide ID and determine access across the station."
	icon_state = "id"
	item_state = "card-id"
	var/mining_points = 0 //For redeeming at mining equipment vendors
	var/list/access = list()
	var/registered_name = null // The name registered_name on the card
	slot_flags = SLOT_ID

	var/assignment = null
	var/dorm = 0		// determines if this ID has claimed a dorm already

/obj/item/weapon/card/id/attack_self(mob/user)
	user.visible_message("[user] shows you: \icon[src] [src.name].", \
					"You show \the [src.name].")
	src.add_fingerprint(user)
	return

/obj/item/weapon/card/id/examine(mob/user)
	..()
	if(mining_points)
		user << "There's [mining_points] mining equipment redemption point\s loaded onto this card."

/obj/item/weapon/card/id/GetAccess()
	return access

/obj/item/weapon/card/id/GetID()
	return src

/*
Usage:
update_label()
	Sets the id name to whatever registered_name and assignment is

update_label("John Doe", "Clowny")
	Properly formats the name and occupation and sets the id name to the arguments
*/
/obj/item/weapon/card/id/proc/update_label(newname, newjob)
	if(newname || newjob)
		name = "[(!newname)	? "identification card"	: "[newname]'s ID Card"][(!newjob) ? "" : " ([newjob])"]"
		return

	name = "[(!registered_name)	? "identification card"	: "[registered_name]'s ID Card"][(!assignment) ? "" : " ([assignment])"]"

/obj/item/weapon/card/id/silver
	name = "silver identification card"
	desc = "A silver card which shows honour and dedication."
	icon_state = "silver"
	item_state = "silver_id"

/obj/item/weapon/card/id/gold
	name = "gold identification card"
	desc = "A golden card which shows power and might."
	icon_state = "gold"
	item_state = "gold_id"

/obj/item/weapon/card/id/syndicate
	name = "agent card"
	access = list(access_maint_tunnels, access_syndicate)
	origin_tech = "syndicate=3"

/obj/item/weapon/card/id/syndicate/New()
	..()
	var/datum/action/item_action/chameleon/change/chameleon_action = new(src)
	chameleon_action.chameleon_type = /obj/item/weapon/card/id
	chameleon_action.chameleon_name = "ID Card"
	chameleon_action.initialize_disguises()

/obj/item/weapon/card/id/syndicate/afterattack(obj/item/weapon/O, mob/user, proximity)
	if(!proximity)
		return
	if(istype(O, /obj/item/weapon/card/id))
		var/obj/item/weapon/card/id/I = O
		src.access |= I.access
		if(istype(user, /mob/living) && user.mind)
			if(user.mind.special_role)
				usr << "The card's microscanners activate as you pass it over the ID, copying its access."

/obj/item/weapon/card/id/syndicate/attack_self(mob/user)
	if(istype(user, /mob/living) && user.mind)
		if(user.mind.special_role)
			if(alert(user, "Action", "Agent ID", "Show", "Forge") == "Forge")
				var t = copytext(sanitize(input(user, "What name would you like to put on this card?", "Agent card name", registered_name ? registered_name : (ishuman(user) ? user.real_name : user.name))as text | null),1,26)
				if(!t || t == "Unknown" || t == "floor" || t == "wall" || t == "r-wall") //Same as mob/new_player/prefrences.dm
					if (t)
						alert("Invalid name.")
					return
				registered_name = t

				var u = copytext(sanitize(input(user, "What occupation would you like to put on this card?\nNote: This will not grant any access levels other than Maintenance.", "Agent card job assignment", "Assistant")as text | null),1,MAX_MESSAGE_LEN)
				if(!u)
					registered_name = ""
					return
				assignment = u
				update_label()
				user << "You successfully forge the ID card."
				return
	..()

/obj/item/weapon/card/id/syndicate_command
	name = "syndicate ID card"
	desc = "An ID straight from the Syndicate."
	registered_name = "Syndicate"
	assignment = "Syndicate Overlord"
	access = list(access_syndicate)

/obj/item/weapon/card/id/captains_spare
	name = "captain's spare ID"
	desc = "The spare ID of the High Lord himself."
	icon_state = "gold"
	item_state = "gold_id"
	registered_name = "Captain"
	assignment = "Captain"

/obj/item/weapon/card/id/captains_spare/New()
	var/datum/job/captain/J = new/datum/job/captain
	access = J.get_access()
	..()

/obj/item/weapon/card/id/centcom
	name = "\improper Centcom ID"
	desc = "An ID straight from Cent. Com."
	icon_state = "centcom"
	registered_name = "Central Command"
	assignment = "General"

/obj/item/weapon/card/id/centcom/New()
	access = get_all_centcom_access()
	..()

/obj/item/weapon/card/id/ert
	name = "\improper Centcom ID"
	desc = "A ERT ID card"
	icon_state = "centcom"
	registered_name = "Emergency Response Team Commander"
	assignment = "Emergency Response Team Commander"

/obj/item/weapon/card/id/ert/New()
	access = get_all_accesses()+get_ert_access("commander")-access_change_ids

/obj/item/weapon/card/id/ert/Security
	registered_name = "Security Response Officer"
	assignment = "Security Response Officer"

/obj/item/weapon/card/id/ert/Security/New()
	access = get_all_accesses()+get_ert_access("sec")-access_change_ids

/obj/item/weapon/card/id/ert/Engineer
	registered_name = "Engineer Response Officer"
	assignment = "Engineer Response Officer"

/obj/item/weapon/card/id/ert/Engineer/New()
	access = get_all_accesses()+get_ert_access("eng")-access_change_ids

/obj/item/weapon/card/id/ert/Medical
	registered_name = "Medical Response Officer"
	assignment = "Medical Response Officer"

/obj/item/weapon/card/id/ert/Medical/New()
	access = get_all_accesses()+get_ert_access("med")-access_change_ids

/obj/item/weapon/card/id/prisoner
	name = "prisoner ID card"
	desc = "You are a number, you are not a free man."
	icon_state = "orange"
	item_state = "orange-id"
	assignment = "Prisoner"
	registered_name = "Scum"
	var/goal = 0 //How far from freedom?
	var/points = 0

/obj/item/weapon/card/id/prisoner/attack_self(mob/user)
	usr << "You have accumulated [points] out of the [goal] points you need for freedom."

/obj/item/weapon/card/id/prisoner/one
	name = "Prisoner #13-001"
	registered_name = "Prisoner #13-001"

/obj/item/weapon/card/id/prisoner/two
	name = "Prisoner #13-002"
	registered_name = "Prisoner #13-002"

/obj/item/weapon/card/id/prisoner/three
	name = "Prisoner #13-003"
	registered_name = "Prisoner #13-003"

/obj/item/weapon/card/id/prisoner/four
	name = "Prisoner #13-004"
	registered_name = "Prisoner #13-004"

/obj/item/weapon/card/id/prisoner/five
	name = "Prisoner #13-005"
	registered_name = "Prisoner #13-005"

/obj/item/weapon/card/id/prisoner/six
	name = "Prisoner #13-006"
	registered_name = "Prisoner #13-006"

/obj/item/weapon/card/id/prisoner/seven
	name = "Prisoner #13-007"
	registered_name = "Prisoner #13-007"

/obj/item/weapon/card/id/mining
	name = "mining ID"
	access = list(access_mining, access_mining_station, access_mineral_storeroom)


code:
#define CHRONO_BEAM_RANGE 3
#define CHRONO_FRAME_COUNT 22
/obj/item/weapon/chrono_eraser
	name = "Timestream Eradication Device"
	desc = "The result of outlawed time-bluespace research, this device is capable of wiping a being from the timestream. They never are, they never were, they never will be."
	icon = 'icons/obj/chronos.dmi'
	icon_state = "chronobackpack"
	item_state = "backpack"
	w_class = 4
	slot_flags = SLOT_BACK
	slowdown = 1
	actions_types = list(/datum/action/item_action/equip_unequip_TED_Gun)
	var/obj/item/weapon/gun/energy/chrono_gun/PA = null
	var/list/erased_minds = list() //a collection of minds from the dead

/obj/item/weapon/chrono_eraser/proc/pass_mind(datum/mind/M)
	erased_minds += M

/obj/item/weapon/chrono_eraser/dropped()
	..()
	if(PA)
		qdel(PA)

/obj/item/weapon/chrono_eraser/Destroy()
	dropped()
	return ..()

/obj/item/weapon/chrono_eraser/ui_action_click(mob/user)
	if(iscarbon(user))
		var/mob/living/carbon/C = user
		if(C.back == src)
			if(PA)
				qdel(PA)
			else
				PA = new(src)
				user.put_in_hands(PA)

/obj/item/weapon/chrono_eraser/item_action_slot_check(slot, mob/user)
	if(slot == slot_back)
		return 1

/obj/item/weapon/gun/energy/chrono_gun
	name = "T.E.D. Projection Apparatus"
	desc = "It's as if they never existed in the first place."
	icon = 'icons/obj/chronos.dmi'
	icon_state = "chronogun"
	item_state = "chronogun"
	w_class = 3
	flags = NODROP
	ammo_type = list(/obj/item/ammo_casing/energy/chrono_beam)
	can_charge = 0
	fire_delay = 50
	var/obj/item/weapon/chrono_eraser/TED = null
	var/obj/effect/chrono_field/field = null
	var/turf/startpos = null

/obj/item/weapon/gun/energy/chrono_gun/New(var/obj/item/weapon/chrono_eraser/T)
	. = ..()
	if(istype(T))
		TED = T
	else //admin must have spawned it
		TED = new(src.loc)
		qdel(src)

/obj/item/weapon/gun/energy/chrono_gun/dropped()
	..()
	qdel(src)

/obj/item/weapon/gun/energy/chrono_gun/update_icon()
	return

/obj/item/weapon/gun/energy/chrono_gun/process_fire()
	if(field)
		field_disconnect(field)
	..()

/obj/item/weapon/gun/energy/chrono_gun/Destroy()
	if(TED)
		TED.PA = null
		TED = null
	if(field)
		field_disconnect(field)
	return ..()

/obj/item/weapon/gun/energy/chrono_gun/proc/field_connect(obj/effect/chrono_field/F)
	var/mob/living/user = src.loc
	if(F.gun)
		if(isliving(user) && F.captured)
			user << "FAIL: [F.captured] already has an existing connection."
		src.field_disconnect(F)
	else
		startpos = get_turf(src)
		field = F
		F.gun = src
		if(isliving(user) && F.captured)
			user << "Connection established with target: [F.captured]"

/obj/item/weapon/gun/energy/chrono_gun/proc/field_disconnect(obj/effect/chrono_field/F)
	if(F && field == F)
		var/mob/living/user = src.loc
		if(F.gun == src)
			F.gun = null
		if(isliving(user) && F.captured)
			user << "Disconnected from target: [F.captured]"
	field = null
	startpos = null

/obj/item/weapon/gun/energy/chrono_gun/proc/field_check(obj/effect/chrono_field/F)
	if(F)
		if(field == F)
			var/turf/currentpos = get_turf(src)
			var/mob/living/user = src.loc
			if((currentpos == startpos) && (field in view(CHRONO_BEAM_RANGE, currentpos)) && !user.lying && (user.stat == CONSCIOUS))
				return 1
		field_disconnect(F)
		return 0

/obj/item/weapon/gun/energy/chrono_gun/proc/pass_mind(datum/mind/M)
	if(TED)
		TED.pass_mind(M)

/obj/item/projectile/energy/chrono_beam
	name = "eradication beam"
	icon_state = "chronobolt"
	range = CHRONO_BEAM_RANGE
	color = null
	nodamage = 1
	var/obj/item/weapon/gun/energy/chrono_gun/gun = null

/obj/item/projectile/energy/chrono_beam/fire()
	gun = firer.get_active_hand()
	if(istype(gun))
		return ..()
	else
		return 0

/obj/item/projectile/energy/chrono_beam/on_hit(atom/target)
	if(target && gun && isliving(target))
		var/obj/effect/chrono_field/F = new(target.loc, target, gun)
		gun.field_connect(F)

/obj/item/ammo_casing/energy/chrono_beam
	name = "eradication beam"
	projectile_type = /obj/item/projectile/energy/chrono_beam
	icon_state = "chronobolt"
	e_cost = 0

/obj/effect/chrono_field
	name = "eradication field"
	desc = "An aura of time-bluespace energy."
	icon = 'icons/effects/effects.dmi'
	icon_state = "chronofield"
	density = 0
	anchored = 1
	unacidable = 1
	blend_mode = BLEND_MULTIPLY
	var/mob/living/captured = null
	var/obj/item/weapon/gun/energy/chrono_gun/gun = null
	var/tickstokill = 15
	var/image/mob_underlay = null
	var/preloaded = 0
	var/RPpos = null

/obj/effect/chrono_field/New(loc, var/mob/living/target, var/obj/item/weapon/gun/energy/chrono_gun/G)
	if(target && isliving(target) && G)
		target.loc = src
		src.captured = target
		var/icon/mob_snapshot = getFlatIcon(target)
		var/icon/cached_icon = new()

		for(var/i=1, i<=CHRONO_FRAME_COUNT, i++)
			var/icon/removing_frame = icon('icons/obj/chronos.dmi', "erasing", SOUTH, i)
			var/icon/mob_icon = icon(mob_snapshot)
			mob_icon.Blend(removing_frame, ICON_MULTIPLY)
			cached_icon.Insert(mob_icon, "frame[i]")

		mob_underlay = new(cached_icon, "frame1")
		update_icon()

		desc = initial(desc) + "
It appears to contain [target.name]."
	SSobj.processing |= src

/obj/effect/chrono_field/Destroy()
	if(gun && gun.field_check(src))
		gun.field_disconnect(src)
	return ..()

/obj/effect/chrono_field/update_icon()
	var/ttk_frame = 1 - (tickstokill / initial(tickstokill))
	ttk_frame = Clamp(Ceiling(ttk_frame * CHRONO_FRAME_COUNT), 1, CHRONO_FRAME_COUNT)
	if(ttk_frame != RPpos)
		RPpos = ttk_frame
		mob_underlay.icon_state = "frame[RPpos]"
		underlays = list() //hack: BYOND refuses to update the underlay to match the icon_state otherwise
		underlays += mob_underlay

/obj/effect/chrono_field/process()
	if(captured)
		if(tickstokill > initial(tickstokill))
			for(var/atom/movable/AM in contents)
				AM.loc = loc
			qdel(src)
		else if(tickstokill <= 0)
			captured << "As the last essence of your being is erased from time, you begin to re-experience your most enjoyable memory. You feel happy..."
			var/mob/dead/observer/ghost = captured.ghostize(1)
			if(captured.mind)
				if(ghost)
					ghost.mind = null
				if(gun)
					gun.pass_mind(captured.mind)
			qdel(captured)
			qdel(src)
		else
			captured.Paralyse(4)
			if(captured.loc != src)
				captured.loc = src
			update_icon()
			if(gun)
				if(gun.field_check(src))
					tickstokill--
				else
					gun = null
					return .()
			else
				tickstokill++
	else
		qdel(src)

/obj/effect/chrono_field/bullet_act(obj/item/projectile/P)
	if(istype(P, /obj/item/projectile/energy/chrono_beam))
		var/obj/item/projectile/energy/chrono_beam/beam = P
		var/obj/item/weapon/gun/energy/chrono_gun/Pgun = beam.gun
		if(Pgun && istype(Pgun))
			Pgun.field_connect(src)
	else
		return 0

/obj/effect/chrono_field/assume_air()
	return 0

/obj/effect/chrono_field/return_air() //we always have nominal air and temperature
	var/datum/gas_mixture/GM = new
	GM.assert_gases("o2","n2")
	GM.gases["o2"][MOLES] = MOLES_O2STANDARD
	GM.gases["n2"][MOLES] = MOLES_N2STANDARD
	GM.temperature = T20C
	return GM

/obj/effect/chrono_field/Move()
	return

/obj/effect/chrono_field/singularity_act()
	return

/obj/effect/chrono_field/ex_act()
	return

/obj/effect/chrono_field/blob_act()
	return

#undef CHRONO_BEAM_RANGE
#undef CHRONO_FRAME_COUNT


code:
//cleansed 9/15/2012 17:48

/*
CONTAINS:
MATCHES
CIGARETTES
CIGARS
SMOKING PIPES
CHEAP LIGHTERS
ZIPPO

CIGARETTE PACKETS ARE IN FANCY.DM
*/

///////////
//MATCHES//
///////////
/obj/item/weapon/match
	name = "match"
	desc = "A simple match stick, used for lighting fine smokables."
	icon = 'icons/obj/cigarettes.dmi'
	icon_state = "match_unlit"
	var/lit = 0
	var/smoketime = 5
	w_class = 1
	origin_tech = "materials=1"
	heat = 1000

/obj/item/weapon/match/process()
	var/turf/location = get_turf(src)
	smoketime--
	if(smoketime < 1)
		matchburnout()
		return
	if(location)
		location.hotspot_expose(700, 5)
		return

/obj/item/weapon/match/fire_act()
	matchignite()

/obj/item/weapon/match/proc/matchignite()
	if(lit == 0)
		lit = 1
		icon_state = "match_lit"
		damtype = "fire"
		force = 3
		hitsound = 'sound/items/welder.ogg'
		item_state = "cigon"
		name = "lit match"
		desc = "A match. This one is lit."
		attack_verb = list("burnt","singed")
		SSobj.processing |= src
		update_icon()
	return

/obj/item/weapon/match/proc/matchburnout()
	if(lit == 1)
		lit = -1
		damtype = "brute"
		force = initial(force)
		icon_state = "match_burnt"
		item_state = "cigoff"
		name = "burnt match"
		desc = "A match. This one has seen better days."
		attack_verb = null
		SSobj.processing.Remove(src)

/obj/item/weapon/match/dropped(mob/user)
	matchburnout()
	return ..()

/obj/item/weapon/match/attack(mob/living/carbon/M, mob/living/carbon/user)
	if(!isliving(M))
		return
	M.IgniteMob()
	var/obj/item/clothing/mask/cigarette/cig = help_light_cig(M,user)
	if(lit && cig && user.a_intent == "help")
		if(cig.lit)
			user << "The [cig.name] is already lit."
		if(M == user)
			cig.attackby(src, user)
		else
			cig.light("[user] holds the [name] out for [M], and lights the [cig.name].")
	else
		..()

/obj/item/proc/help_light_cig(mob/living/carbon/M, mob/living/carbon/user)
	if(!iscarbon(M))
		return
	if(istype(M.wear_mask, /obj/item/clothing/mask/cigarette))
		var/obj/item/clothing/mask/cigarette/cig = M.wear_mask
		return cig

/obj/item/weapon/match/is_hot()
	return lit * heat

//////////////////
//FINE SMOKABLES//
//////////////////
/obj/item/clothing/mask/cigarette
	name = "cigarette"
	desc = "A roll of tobacco and nicotine."
	icon_state = "cigoff"
	throw_speed = 0.5
	item_state = "cigoff"
	w_class = 1
	body_parts_covered = null
	var/lit = 0
	var/icon_on = "cigon"  //Note - these are in masks.dmi not in cigarette.dmi
	var/icon_off = "cigoff"
	var/type_butt = /obj/item/weapon/cigbutt
	var/lastHolder = null
	var/smoketime = 300
	var/chem_volume = 30
	heat = 1000

/obj/item/clothing/mask/cigarette/suicide_act(mob/user)
	user.visible_message("[user] is huffing the [src.name] as quickly as they can! It looks like \he's trying to give \himself cancer.")
	return (TOXLOSS|OXYLOSS)

/obj/item/clothing/mask/cigarette/New()
	..()
	flags |= NOREACT // so it doesn't react until you light it
	create_reagents(chem_volume) // making the cigarette a chemical holder with a maximum volume of 15
	reagents.add_reagent("nicotine", 15)

/obj/item/clothing/mask/cigarette/attackby(obj/item/weapon/W, mob/user, params)
	..()
	if(!lit && smoketime > 0 && W.is_hot())
		var/lighting_text = is_lighter(W,user)
		if(lighting_text)
			light(lighting_text)
			return
	return

/obj/item/clothing/mask/cigarette/afterattack(obj/item/weapon/reagent_containers/glass/glass, mob/user, proximity)
	if(!proximity || lit) //can't dip if cigarette is lit (it will heat the reagents in the glass instead)
		return
	if(istype(glass))	//you can dip cigarettes into beakers
		var/transfered = glass.reagents.trans_to(src, chem_volume)
		if(transfered)	//if reagents were transfered, show the message
			user << "You dip \the [src] into \the [glass]."
		else			//if not, either the beaker was empty, or the cigarette was full
			if(!glass.reagents.total_volume)
				user << "[glass] is empty."
			else
				user << "[src] is full."

/obj/item/clothing/mask/cigarette/proc/is_lighter(obj/item/O, mob/user)
	var/lighting_text = null
	if(istype(O, /obj/item/weapon/weldingtool))
		lighting_text = "[user] casually lights the [name] with [O], what a badass."
	else if(istype(O, /obj/item/weapon/lighter/greyscale)) // we have to check for this first -- zippo lighters are default
		lighting_text = "After some fiddling, [user] manages to light their [name] with [O]."
	else if(istype(O, /obj/item/weapon/lighter))
		lighting_text = "With a single flick of their wrist, [user] smoothly lights their [name] with [O]. Damn they're cool."
	else if(istype(O, /obj/item/weapon/melee/energy))
		lighting_text = "[user] swings their [O], barely missing their nose. They light their [name] in the process."
	else if(istype(O, /obj/item/device/assembly/igniter))
		lighting_text = "[user] fiddles with [O], and manages to light their [name]."
	else if(istype(O, /obj/item/device/flashlight/flare))
		lighting_text = "[user] lights their [name] with [O] like a real badass."
	else if(O.is_hot())
		lighting_text = "[user] lights their [name] with [O]."
	return lighting_text

/obj/item/clothing/mask/cigarette/proc/light(flavor_text = null)
	if(!src.lit)
		src.lit = 1
		name = "lit [name]"
		attack_verb = list("burnt", "singed")
		hitsound = 'sound/items/welder.ogg'
		damtype = "fire"
		force = 4
		if(reagents.get_reagent_amount("plasma")) // the plasma explodes when exposed to fire
			var/datum/effect_system/reagents_explosion/e = new()
			e.set_up(round(reagents.get_reagent_amount("plasma") / 2.5, 1), get_turf(src), 0, 0)
			e.start()
			if(ismob(loc))
				var/mob/M = loc
				M.unEquip(src, 1)
			qdel(src)
			return
		if(reagents.get_reagent_amount("welding_fuel")) // the fuel explodes, too, but much less violently
			var/datum/effect_system/reagents_explosion/e = new()
			e.set_up(round(reagents.get_reagent_amount("welding_fuel") / 5, 1), get_turf(src), 0, 0)
			e.start()
			if(ismob(loc))
				var/mob/M = loc
				M.unEquip(src, 1)
			qdel(src)
			return
		flags &= ~NOREACT // allowing reagents to react after being lit
		reagents.handle_reactions()
		icon_state = icon_on
		item_state = icon_on
		if(flavor_text)
			var/turf/T = get_turf(src)
			T.visible_message(flavor_text)
		SSobj.processing |= src

		//can't think of any other way to update the overlays :<
		if(ismob(loc))
			var/mob/M = loc
			M.update_inv_wear_mask()
			M.update_inv_l_hand()
			M.update_inv_r_hand()

/obj/item/clothing/mask/cigarette/proc/handle_reagents()
	if(reagents.total_volume)
		if(iscarbon(loc))
			var/mob/living/carbon/C = loc
			if (src == C.wear_mask) // if it's in the human/monkey mouth, transfer reagents to the mob
				if(prob(15)) // so it's not an instarape in case of acid
					var/fraction = min(REAGENTS_METABOLISM/reagents.total_volume, 1)
					reagents.reaction(C, INGEST, fraction)
				reagents.trans_to(C, REAGENTS_METABOLISM)
				return
		reagents.remove_any(REAGENTS_METABOLISM)

/obj/item/clothing/mask/cigarette/process()
	var/turf/location = get_turf(src)
	var/mob/living/M = loc
	if(isliving(loc))
		M.IgniteMob()
	smoketime--
	if(smoketime < 1)
		new type_butt(location)
		SSobj.processing.Remove(src)
		if(ismob(loc))
			M << "Your [name] goes out."
			M.unEquip(src, 1)	//un-equip it so the overlays can update //Force the un-equip so the overlays update
		qdel(src)
		return
	if(location)
		location.hotspot_expose(700, 5)
	if(reagents && reagents.total_volume)	//	check if it has any reagents at all
		handle_reagents()
	return

/obj/item/clothing/mask/cigarette/attack_self(mob/user)
	if(lit == 1)
		user.visible_message("[user] calmly drops and treads on \the [src], putting it out instantly.")
		new type_butt(user.loc)
		new /obj/effect/decal/cleanable/ash(user.loc)
		SSobj.processing.Remove(src)
		qdel(src)
	return ..()

/obj/item/clothing/mask/cigarette/attack(mob/living/carbon/M, mob/living/carbon/user)
	if(!istype(M))
		return ..()
	var/obj/item/clothing/mask/cigarette/cig = help_light_cig(M,user)
	if(lit && cig && user.a_intent == "help")
		if(cig.lit)
			user << "The [cig.name] is already lit."
		if(M == user)
			cig.attackby(src, user)
		else
			cig.light("[user] holds the [name] out for [M], and lights the [cig.name].")
	else
		return ..()

/obj/item/clothing/mask/cigarette/fire_act()
	light()

/obj/item/clothing/mask/cigarette/is_hot()
	return lit * heat

/obj/item/clothing/mask/cigarette/rollie
	name = "rollie"
	desc = "A roll of dried plant matter wrapped in thin paper."
	icon_state = "spliffoff"
	icon_on = "spliffon"
	icon_off = "spliffoff"
	type_butt = /obj/item/weapon/cigbutt/roach
	throw_speed = 0.5
	item_state = "spliffoff"
	smoketime = 180
	chem_volume = 50

/obj/item/clothing/mask/cigarette/rollie/New()
	..()
	src.pixel_x = rand(-5, 5)
	src.pixel_y = rand(-5, 5)

/obj/item/clothing/mask/cigarette/rollie/trippy/New()
	..()
	reagents.add_reagent("mushroomhallucinogen", 50)
	light()
	//for(var/mob/M in player_list)	M << 'sound/misc/Smoke_Weed_Everyday.ogg'

/obj/item/weapon/cigbutt/roach
	name = "roach"
	desc = "A manky old roach, or for non-stoners, a used rollup."
	icon_state = "roach"

/obj/item/weapon/cigbutt/roach/New()
	..()
	src.pixel_x = rand(-5, 5)
	src.pixel_y = rand(-5, 5)

////////////
// CIGARS //
////////////
/obj/item/clothing/mask/cigarette/cigar
	name = "premium cigar"
	desc = "A brown roll of tobacco and... well, you're not quite sure. This thing's huge!"
	icon_state = "cigaroff"
	icon_on = "cigaron"
	icon_off = "cigaroff"
	type_butt = /obj/item/weapon/cigbutt/cigarbutt
	throw_speed = 0.5
	item_state = "cigaroff"
	smoketime = 1500
	chem_volume = 40

/obj/item/clothing/mask/cigarette/cigar/cohiba
	name = "\improper Cohiba Robusto cigar"
	desc = "There's little more you could want from a cigar."
	icon_state = "cigar2off"
	icon_on = "cigar2on"
	icon_off = "cigar2off"
	smoketime = 2000
	chem_volume = 80

/obj/item/clothing/mask/cigarette/cigar/havana
	name = "premium Havanian cigar"
	desc = "A cigar fit for only the best of the best."
	icon_state = "cigar2off"
	icon_on = "cigar2on"
	icon_off = "cigar2off"
	smoketime = 7200
	chem_volume = 50

/obj/item/weapon/cigbutt
	name = "cigarette butt"
	desc = "A manky old cigarette butt."
	icon = 'icons/obj/clothing/masks.dmi'
	icon_state = "cigbutt"
	w_class = 1
	throwforce = 0

/obj/item/weapon/cigbutt/cigarbutt
	name = "cigar butt"
	desc = "A manky old cigar butt."
	icon_state = "cigarbutt"

/////////////////
//SMOKING PIPES//
/////////////////
/obj/item/clothing/mask/cigarette/pipe
	name = "smoking pipe"
	desc = "A pipe, for smoking. Probably made of meershaum or something."
	icon_state = "pipeoff"
	item_state = "pipeoff"
	icon_on = "pipeon"  //Note - these are in masks.dmi
	icon_off = "pipeoff"
	smoketime = 0
	chem_volume = 100
	var/packeditem = 0

/obj/item/clothing/mask/cigarette/pipe/New()
	..()
	name = "empty [initial(name)]"

/obj/item/clothing/mask/cigarette/pipe/process()
	var/turf/location = get_turf(src)
	smoketime--
	if(smoketime < 1)
		new /obj/effect/decal/cleanable/ash(location)
		if(ismob(loc))
			var/mob/living/M = loc
			M << "Your [name] goes out."
			lit = 0
			icon_state = icon_off
			item_state = icon_off
			M.update_inv_wear_mask()
			packeditem = 0
			name = "empty [initial(name)]"
		SSobj.processing.Remove(src)
		return
	if(location)
		location.hotspot_expose(700, 5)
	if(reagents && reagents.total_volume)	//	check if it has any reagents at all
		handle_reagents()
	return

/obj/item/clothing/mask/cigarette/pipe/attackby(obj/item/O, mob/user, params)
	if(istype(O, /obj/item/weapon/reagent_containers/food/snacks/grown))
		var/obj/item/weapon/reagent_containers/food/snacks/grown/G = O
		if(!packeditem)
			if(G.dry == 1)
				user << "You stuff [O] into [src]."
				smoketime = 400
				packeditem = 1
				name = "[O.name]-packed [initial(name)]"
				if(O.reagents)
					O.reagents.trans_to(src, O.reagents.total_volume)
				qdel(O)
			else
				user << "It has to be dried first!"
		else
			user << "It is already packed!"
	else
		var/lighting_text = is_lighter(O,user)
		if(lighting_text)
			if(smoketime > 0)
				light(lighting_text)
			else
				user << "There is nothing to smoke!"
		else
			user << "You can't put that in the pipe!"
	..()

/obj/item/clothing/mask/cigarette/pipe/attack_self(mob/user)
	var/turf/location = get_turf(user)
	if(lit)
		user.visible_message("[user] puts out [src].", "You put out [src].")
		lit = 0
		icon_state = icon_off
		item_state = icon_off
		SSobj.processing.Remove(src)
		return
	if(!lit && smoketime > 0)
		user << "You empty [src] onto [location]."
		new /obj/effect/decal/cleanable/ash(location)
		packeditem = 0
		smoketime = 0
		reagents.clear_reagents()
		name = "empty [initial(name)]"
	return

/obj/item/clothing/mask/cigarette/pipe/cobpipe
	name = "corn cob pipe"
	desc = "A nicotine delivery system popularized by folksy backwoodsmen and kept popular in the modern age and beyond by space hipsters. Can be loaded with objects."
	icon_state = "cobpipeoff"
	item_state = "cobpipeoff"
	icon_on = "cobpipeon"  //Note - these are in masks.dmi
	icon_off = "cobpipeoff"
	smoketime = 0

/////////
//ZIPPO//
/////////
/obj/item/weapon/lighter
	name = "\improper Zippo lighter"
	desc = "The zippo."
	icon = 'icons/obj/cigarettes.dmi'
	icon_state = "zippo"
	item_state = "zippo"
	w_class = 1
	flags = CONDUCT
	slot_flags = SLOT_BELT
	var/lit = 0
	heat = 1500

/obj/item/weapon/lighter/greyscale
	name = "cheap lighter"
	desc = "A cheap-as-free lighter."
	icon_state = "lighter"

/obj/item/weapon/lighter/greyscale/New()
	var/image/I = image(icon,"lighter-overlay")
	I.color = color2hex(randomColor(1))
	overlays += I

/obj/item/weapon/lighter/update_icon()
	icon_state = lit ? "[icon_state]_on" : "[initial(icon_state)]"

/obj/item/weapon/lighter/attack_self(mob/living/user)
	if(user.r_hand == src || user.l_hand == src)
		if(!lit)
			lit = 1
			update_icon()
			force = 5
			damtype = "fire"
			hitsound = 'sound/items/welder.ogg'
			attack_verb = list("burnt", "singed")
			if(!istype(src, /obj/item/weapon/lighter/greyscale))
				user.visible_message("Without even breaking stride, [user] flips open and lights [src] in one smooth movement.", "Without even breaking stride, you flip open and lights [src] in one smooth movement.")
			else
				if(prob(75))
					user.visible_message("After a few attempts, [user] manages to light [src].", "After a few attempts, you manage to light [src].")
				else
					var/hitzone = user.r_hand == src ? "r_hand" : "l_hand"
					user.apply_damage(5, BURN, hitzone)
					user.visible_message("After a few attempts, [user] manages to light [src] - they however burn their finger in the process.", "You burn yourself while lighting the lighter!")

			user.AddLuminosity(1)
			SSobj.processing |= src
		else
			lit = 0
			update_icon()
			hitsound = "swing_hit"
			force = 0
			attack_verb = null //human_defense.dm takes care of it
			if(!istype(src, /obj/item/weapon/lighter/greyscale))
				user.visible_message("You hear a quiet click, as [user] shuts off [src] without even looking at what they're doing. Wow.", "You quietly shut off [src] without even looking at what you're doing. Wow.")
			else
				user.visible_message("[user] quietly shuts off [src].", "You quietly shut off [src].")
			user.AddLuminosity(-1)
			SSobj.processing.Remove(src)
	else
		return ..()
	return

/obj/item/weapon/lighter/attack(mob/living/carbon/M, mob/living/carbon/user)
	if(!isliving(M))
		return
	if(lit)
		M.IgniteMob()
	var/obj/item/clothing/mask/cigarette/cig = help_light_cig(M,user)
	if(lit && cig && user.a_intent == "help")
		if(cig.lit)
			user << "The [cig.name] is already lit."
		if(M == user)
			cig.attackby(src, user)
		else
			if(!istype(src, /obj/item/weapon/lighter/greyscale))
				cig.light("[user] whips the [name] out and holds it for [M]. Their arm is as steady as the unflickering flame they light \the [cig] with.")
			else
				cig.light("[user] holds the [name] out for [M], and lights the [cig.name].")
	else
		..()

/obj/item/weapon/lighter/process()
	var/turf/location = get_turf(src)
	if(location)
		location.hotspot_expose(700, 5)
	return

/obj/item/weapon/lighter/pickup(mob/user)
	..()
	if(lit)
		SetLuminosity(0)
		user.AddLuminosity(1)
	return

/obj/item/weapon/lighter/dropped(mob/user)
	..()
	if(lit)
		if(user)
			user.AddLuminosity(-1)
		SetLuminosity(1)
	return

/obj/item/weapon/lighter/is_hot()
	return lit * heat

///////////
//ROLLING//
///////////
/obj/item/weapon/rollingpaper
	name = "rolling paper"
	desc = "A thin piece of paper used to make fine smokeables."
	icon = 'icons/obj/cigarettes.dmi'
	icon_state = "cig_paper"
	w_class = 1

/obj/item/weapon/rollingpaper/afterattack(atom/target, mob/user, proximity)
	if(!proximity)
		return
	if(istype(target, /obj/item/weapon/reagent_containers/food/snacks/grown))
		var/obj/item/weapon/reagent_containers/food/snacks/grown/O = target
		if(O.dry)
			user.unEquip(target, 1)
			user.unEquip(src, 1)
			var/obj/item/clothing/mask/cigarette/rollie/R = new /obj/item/clothing/mask/cigarette/rollie(user.loc)
			R.chem_volume = target.reagents.total_volume
			target.reagents.trans_to(R, R.chem_volume)
			user.put_in_active_hand(R)
			user << "You roll the [target.name] into a rolling paper."
			R.desc = "Dried [target.name] rolled up in a thin piece of paper."
			qdel(target)
			qdel(src)
		else
			user << "You need to dry this first!"
	else
		..()


code:
/* Clown Items
 * Contains:
 *		Soap
 *		Bike Horns
 *		Air Horns
 */

/*
 * Soap
 */

/obj/item/weapon/soap
	name = "soap"
	desc = "A cheap bar of soap. Doesn't smell."
	gender = PLURAL
	icon = 'icons/obj/items.dmi'
	icon_state = "soap"
	w_class = 1
	throwforce = 0
	throw_speed = 3
	throw_range = 7
	var/cleanspeed = 50 //slower than mop

/obj/item/weapon/soap/nanotrasen
	desc = "A Nanotrasen brand bar of soap. Smells of plasma."
	icon_state = "soapnt"

/obj/item/weapon/soap/homemade
	desc = "A homemade bar of soap. Smells of... well...."
	icon_state = "soapgibs"
	cleanspeed = 45 // a little faster to reward chemists for going to the effort

/obj/item/weapon/soap/deluxe
	desc = "A deluxe Waffle Co. brand bar of soap. Smells of high-class luxury."
	icon_state = "soapdeluxe"
	cleanspeed = 40 //same speed as mop because deluxe -- captain gets one of these

/obj/item/weapon/soap/syndie
	desc = "An untrustworthy bar of soap made of strong chemical agents that dissolve blood faster."
	icon_state = "soapsyndie"
	cleanspeed = 10 //much faster than mop so it is useful for traitors who want to clean crime scenes

/obj/item/weapon/soap/suicide_act(mob/user)
	user.say(";FFFFFFFFFFFFFFFFUUUUUUUDGE!!")
	user.visible_message("[user] lifts the [src.name] to their mouth and gnaws on it furiously, producing a thick froth! They'll never get that BB gun now!")
	PoolOrNew(/obj/effect/particle_effect/foam, loc)
	return (TOXLOSS)

/obj/item/weapon/soap/Crossed(AM as mob|obj)
	if (istype(AM, /mob/living/carbon))
		var/mob/living/carbon/M = AM
		M.slip(4, 2, src)

/obj/item/weapon/soap/afterattack(atom/target, mob/user, proximity)
	if(!proximity || !check_allowed_items(target))
		return
	//I couldn't feasibly  fix the overlay bugs caused by cleaning items we are wearing.
	//So this is a workaround. This also makes more sense from an IC standpoint. ~Carn
	if(user.client && (target in user.client.screen))
		user << "You need to take that [target.name] off before cleaning it!"
	else if(istype(target,/obj/effect/decal/cleanable))
		user.visible_message("[user] begins to scrub \the [target.name] out with [src].", "You begin to scrub \the [target.name] out with [src]...")
		if(do_after(user, src.cleanspeed, target = target))
			user << "You scrub \the [target.name] out."
			qdel(target)
	else if(ishuman(target) && user.zone_selected == "mouth")
		user.visible_message("\the [user] washes \the [target]'s mouth out with [src.name]!", "You wash \the [target]'s mouth out with [src.name]!") //washes mouth out with soap sounds better than 'the soap' here
		return
	else if(istype(target, /obj/structure/window))
		user.visible_message("[user] begins to clean \the [target.name] with [src]...", "You begin to clean \the [target.name] with [src]...")
		if(do_after(user, src.cleanspeed, target = target))
			user << "You clean \the [target.name]."
			target.color = initial(target.color)
			target.SetOpacity(initial(target.opacity))
	else
		user.visible_message("[user] begins to clean \the [target.name] with [src]...", "You begin to clean \the [target.name] with [src]...")
		if(do_after(user, src.cleanspeed, target = target))
			user << "You clean \the [target.name]."
			var/obj/effect/decal/cleanable/C = locate() in target
			qdel(C)
			target.clean_blood()
	return

/*
 * Bike Horns
 */

/obj/item/weapon/bikehorn
	name = "bike horn"
	desc = "A horn off of a bicycle."
	icon = 'icons/obj/items.dmi'
	icon_state = "bike_horn"
	item_state = "bike_horn"
	throwforce = 0
	hitsound = null //To prevent tap.ogg playing, as the item lacks of force
	w_class = 1
	throw_speed = 3
	throw_range = 7
	attack_verb = list("HONKED")
	var/spam_flag = 0
	var/honksound = 'sound/items/bikehorn.ogg'
	var/cooldowntime = 20

/obj/item/weapon/bikehorn/suicide_act(mob/user)
	user.visible_message("[user] solemnly points the horn at \his temple! It looks like \he's trying to commit suicide..")
	playsound(src.loc, honksound, 50, 1)
	return (BRUTELOSS)

/obj/item/weapon/bikehorn/attack(mob/living/carbon/M, mob/living/carbon/user)
	if(!spam_flag)
		playsound(loc, honksound, 50, 1, -1) //plays instead of tap.ogg!
	return ..()

/obj/item/weapon/bikehorn/attack_self(mob/user)
	if(!spam_flag)
		spam_flag = 1
		playsound(src.loc, honksound, 50, 1)
		src.add_fingerprint(user)
		spawn(cooldowntime)
			spam_flag = 0
	return

/obj/item/weapon/bikehorn/Crossed(mob/living/L)
	if(isliving(L))
		playsound(loc, honksound, 50, 1, -1)
	..()

/obj/item/weapon/bikehorn/airhorn
	name = "air horn"
	desc = "Damn son, where'd you find this?"
	icon_state = "air_horn"
	honksound = 'sound/items/AirHorn2.ogg'
	cooldowntime = 50


code:
/obj/item/weapon/lipstick
	gender = PLURAL
	name = "red lipstick"
	desc = "A generic brand of lipstick."
	icon = 'icons/obj/items.dmi'
	icon_state = "lipstick"
	w_class = 1
	var/colour = "red"
	var/open = 0

/obj/item/weapon/lipstick/purple
	name = "purple lipstick"
	colour = "purple"

/obj/item/weapon/lipstick/jade
	//It's still called Jade, but theres no HTML color for jade, so we use lime.
	name = "jade lipstick"
	colour = "lime"

/obj/item/weapon/lipstick/black
	name = "black lipstick"
	colour = "black"

/obj/item/weapon/lipstick/random
	name = "lipstick"

/obj/item/weapon/lipstick/random/New()
	colour = pick("red","purple","lime","black","green","blue","white")
	name = "[colour] lipstick"

/obj/item/weapon/lipstick/attack_self(mob/user)
	overlays.Cut()
	user << "You twist \the [src] [open ? "closed" : "open"]."
	open = !open
	if(open)
		var/image/colored = image("icon"='icons/obj/items.dmi', "icon_state"="lipstick_uncap_color")
		colored.color = colour
		icon_state = "lipstick_uncap"
		overlays += colored
	else
		icon_state = "lipstick"

/obj/item/weapon/lipstick/attack(mob/M, mob/user)
	if(!open)
		return

	if(!istype(M, /mob))
		return

	if(ishuman(M))
		var/mob/living/carbon/human/H = M
		if(H.is_mouth_covered())
			user << "Remove [ H == user ? "your" : "their" ] mask!"
			return
		if(H.lip_style)	//if they already have lipstick on
			user << "You need to wipe off the old lipstick first!"
			return
		if(H == user)
			user.visible_message("[user] does their lips with \the [src].", \
								 "You take a moment to apply \the [src]. Perfect!")
			H.lip_style = "lipstick"
			H.lip_color = colour
			H.update_body()
		else
			user.visible_message("[user] begins to do [H]'s lips with \the [src].", \
								 "You begin to apply \the [src] on [H]'s lips...")
			if(do_after(user, 20, target = H))
				user.visible_message("[user] does [H]'s lips with \the [src].", \
									 "You apply \the [src] on [H]'s lips.")
				H.lip_style = "lipstick"
				H.lip_color = colour
				H.update_body()
	else
		user << "Where are the lips on that?"

//you can wipe off lipstick with paper!
/obj/item/weapon/paper/attack(mob/M, mob/user)
	if(user.zone_selected == "mouth")
		if(!ismob(M))
			return

		if(ishuman(M))
			var/mob/living/carbon/human/H = M
			if(H == user)
				user << "You wipe off the lipstick with [src]."
				H.lip_style = null
				H.update_body()
			else
				user.visible_message("[user] begins to wipe [H]'s lipstick off with \the [src].", \
								 	 "You begin to wipe off [H]'s lipstick...")
				if(do_after(user, 10, target = H))
					user.visible_message("[user] wipes [H]'s lipstick off with \the [src].", \
										 "You wipe off [H]'s lipstick.")
					H.lip_style = null
					H.update_body()
	else
		..()

/obj/item/weapon/razor
	name = "electric razor"
	desc = "The latest and greatest power razor born from the science of shaving."
	icon = 'icons/obj/items.dmi'
	icon_state = "razor"
	flags = CONDUCT
	w_class = 1

/obj/item/weapon/razor/proc/shave(mob/living/carbon/human/H, location = "mouth")
	if(location == "mouth")
		H.facial_hair_style = "Shaved"
	else
		H.hair_style = "Skinhead"

	H.update_hair()
	playsound(loc, 'sound/items/Welder2.ogg', 20, 1)

/obj/item/weapon/razor/attack(mob/M, mob/user)
	if(ishuman(M))
		var/mob/living/carbon/human/H = M
		var/location = user.zone_selected
		if(location == "mouth")
			if(!(H.dna.species.specflags & FACEHAIR))
				user << "There is no facial hair to shave!"
				return
			if(!get_location_accessible(H, location))
				user << "The mask is in the way!"
				return
			if(H.facial_hair_style == "Shaved")
				user << "Already clean-shaven!"
				return

			if(H == user) //shaving yourself
				user.visible_message("[user] starts to shave their facial hair with [src].", \
									 "You take a moment to shave your facial hair with [src]...")
				if(do_after(user, 50, target = H))
					user.visible_message("[user] shaves his facial hair clean with [src].", \
										 "You finish shaving with [src]. Fast and clean!")
					shave(H, location)
			else
				var/turf/H_loc = H.loc
				user.visible_message("[user] tries to shave [H]'s facial hair with [src].", \
									 "You start shaving [H]'s facial hair...")
				if(do_after(user, 50, target = H))
					if(H_loc == H.loc)
						user.visible_message("[user] shaves off [H]'s facial hair with [src].", \
											 "You shave [H]'s facial hair clean off.")
						shave(H, location)

		else if(location == "head")
			if(!(H.dna.species.specflags & HAIR))
				user << "There is no hair to shave!"
				return
			if(!get_location_accessible(H, location))
				user << "The headgear is in the way!"
				return
			if(H.hair_style == "Bald" || H.hair_style == "Balding Hair" || H.hair_style == "Skinhead")
				user << "There is not enough hair left to shave!"
				return

			if(H == user) //shaving yourself
				user.visible_message("[user] starts to shave their head with [src].", \
									 "You start to shave your head with [src]...")
				if(do_after(user, 5, target = H))
					user.visible_message("[user] shaves his head with [src].", \
										 "You finish shaving with [src].")
					shave(H, location)
			else
				var/turf/H_loc = H.loc
				user.visible_message("[user] tries to shave [H]'s head with [src]!", \
									 "You start shaving [H]'s head...")
				if(do_after(user, 50, target = H))
					if(H_loc == H.loc)
						user.visible_message("[user] shaves [H]'s head bald with [src]!", \
											 "You shave [H]'s head bald.")
						shave(H, location)
		else
			..()
	else
		..()


code:
// Contains:
// Gavel Hammer
// Gavel Block

/obj/item/weapon/gavelhammer
	name = "gavel hammer"
	desc = "Order, order! No bombs in my courthouse."
	icon = 'icons/obj/items.dmi'
	icon_state = "gavelhammer"
	force = 5
	throwforce = 6
	w_class = 2
	attack_verb = list("bashed", "battered", "judged", "whacked")
	burn_state = FLAMMABLE

/obj/item/weapon/gavelhammer/suicide_act(mob/user)
	user.visible_message("[user] has sentenced \himself to death with the [src.name]! It looks like \he's trying to commit suicide.")
	playsound(loc, 'sound/items/gavel.ogg', 50, 1, -1)
	return (BRUTELOSS)

/obj/item/weapon/gavelblock
	name = "gavel block"
	desc = "Smack it with a gavel hammer when the assistants get rowdy."
	icon = 'icons/obj/items.dmi'
	icon_state = "gavelblock"
	force = 2
	throwforce = 2
	w_class = 1
	burn_state = FLAMMABLE

/obj/item/weapon/gavelblock/attackby(obj/item/I, mob/user, params)
	if(istype(I, /obj/item/weapon/gavelhammer))
		playsound(loc, 'sound/items/gavel.ogg', 100, 1)
		user.visible_message("[user] strikes \the [src] with \the [I].")
		user.changeNext_move(CLICK_CD_MELEE)
	else
		return