<commit_before>// Disposal bin
// Holds items for disposal into pipe system
// Draws air from turf, gradually charges internal reservoir
// Once full (~1 atm), uses air resv to flush items into the pipes
// Automatically recharges air (unless off), will flush when ready if pre-set
// Can hold items and human size things, no other draggables
// Toilets are a type of disposal bin for small objects only and work on magic. By magic, I mean torque rotation
#define SEND_PRESSURE 0.05*ONE_ATMOSPHERE

/obj/machinery/disposal
	name = "disposal unit"
	desc = "A pneumatic waste disposal unit."
	icon = 'disposal.dmi'
	icon_state = "disposal"
	anchored = 1
	density = 1
	var/datum/gas_mixture/air_contents	// internal reservoir
	var/mode = 1	// item mode 0=off 1=charging 2=charged
	var/flush = 0	// true if flush handle is pulled
	var/obj/structure/disposalpipe/trunk/trunk = null // the attached pipe trunk
	var/flushing = 0	// true if flushing in progress
	var/timeleft = 0	//used to give a delay after the last item was put in before flushing
	var/islarge = 0		//If there is a crate, lets not add a second.

	// create a new disposal
	// find the attached trunk (if present) and init gas resvr.
	New()
		..()
		spawn(5)
			trunk = locate() in src.loc
			if(!trunk)
				mode = 0
				flush = 0
			else
				trunk.linked = src	// link the pipe trunk to self

			air_contents = new/datum/gas_mixture()
			//gas.volume = 1.05 * CELLSTANDARD
			update()


	// attack by item places it in to disposal
	attackby(var/obj/item/I, var/mob/user)
		if(stat & BROKEN)
			return

		if(istype(I, /obj/item/weapon/melee/energy/blade))
			user << "You can't place that item inside the disposal unit."
			return

		if(istype(I, /obj/item/weapon/trashbag))
			user << "\blue You empty the bag."
			for(var/obj/item/O in I.contents)
				I.contents -= O
				O.loc = src
			I.update_icon()
			update()
			return

		if(istype(I, /obj/item/weapon/weldingtool) && I:welding)
			var/obj/item/weapon/weldingtool/W = I
			playsound(src.loc, 'Welder.ogg', 100, 1)
			var/turf/T = get_turf(user)
			user.visible_message("[user] welds apart the disposal.", "You start to weld apart the disposal.")
			sleep(40)
			if(get_turf(user) == T && W.remove_fuel(2,user))
				var/obj/machinery/constructable_frame/machine_frame/M = new /obj/machinery/constructable_frame/machine_frame(loc)
				M.state = 2
				M.icon_state = "box_1"
				for(var/obj/O in component_parts)
					if(O.reliability != 100 && crit_fail)
						O.crit_fail = 1
					O.loc = src.loc
				// the stuff still in the disposal
				for(var/obj/O in src)
					O.loc = src.loc
				del(src)
			return

		var/obj/item/weapon/grab/G = I
		if(istype(G))	// handle grabbed mob
			if(ismob(G.affecting))
				var/mob/GM = G.affecting
				for (var/mob/V in viewers(usr))
					V.show_message("[usr] starts putting [GM.name] into the disposal.", 3)
				if(do_after(usr, 20))
					if (GM.client)
						GM.client.perspective = EYE_PERSPECTIVE
						GM.client.eye = src
					GM.loc = src
					for (var/mob/C in viewers(src))
						C.show_message("\red [GM.name] has been placed in the [src] by [user].", 3)
					del(G)

		if(isrobot(user))
			return

		else
			if(!I || isnull(I))
				//CRASH("disposal/attackby() was called, but I was nulled before calling user.drop_item()")
				return // No idea why, but somehow I gets nulled before it goes into the else, and that leads to a lot of spam with runtime errors.

			user.drop_item()

			I.loc = src
			user << "You place \the [I] into the [src]."
			for(var/mob/M in viewers(src))
				if(M == user)
					continue
				M.show_message("[user.name] places \the [I] into the [src].", 3)
		timeleft = 5
		update()

	// mouse drop another mob or self<commit_msg>fixed error from using a grab on a disposal chute<commit_after>// Disposal bin
// Holds items for disposal into pipe system
// Draws air from turf, gradually charges internal reservoir
// Once full (~1 atm), uses air resv to flush items into the pipes
// Automatically recharges air (unless off), will flush when ready if pre-set
// Can hold items and human size things, no other draggables
// Toilets are a type of disposal bin for small objects only and work on magic. By magic, I mean torque rotation
#define SEND_PRESSURE 0.05*ONE_ATMOSPHERE

/obj/machinery/disposal
	name = "disposal unit"
	desc = "A pneumatic waste disposal unit."
	icon = 'disposal.dmi'
	icon_state = "disposal"
	anchored = 1
	density = 1
	var/datum/gas_mixture/air_contents	// internal reservoir
	var/mode = 1	// item mode 0=off 1=charging 2=charged
	var/flush = 0	// true if flush handle is pulled
	var/obj/structure/disposalpipe/trunk/trunk = null // the attached pipe trunk
	var/flushing = 0	// true if flushing in progress
	var/timeleft = 0	//used to give a delay after the last item was put in before flushing
	var/islarge = 0		//If there is a crate, lets not add a second.

	// create a new disposal
	// find the attached trunk (if present) and init gas resvr.
	New()
		..()
		spawn(5)
			trunk = locate() in src.loc
			if(!trunk)
				mode = 0
				flush = 0
			else
				trunk.linked = src	// link the pipe trunk to self

			air_contents = new/datum/gas_mixture()
			//gas.volume = 1.05 * CELLSTANDARD
			update()


	// attack by item places it in to disposal
	attackby(var/obj/item/I, var/mob/user)
		if(stat & BROKEN)
			return

		//robots shouldn't be able to grab/carry stuff anyway
		if(isrobot(user))
			return

		if(istype(I, /obj/item/weapon/melee/energy/blade))
			user << "You can't place that item inside the disposal unit."
			return

		if(istype(I, /obj/item/weapon/trashbag))
			user << "\blue You empty the bag."
			for(var/obj/item/O in I.contents)
				I.contents -= O
				O.loc = src
			I.update_icon()
			update()
			return

		if(istype(I, /obj/item/weapon/weldingtool) && I:welding)
			var/obj/item/weapon/weldingtool/W = I
			playsound(src.loc, 'Welder.ogg', 100, 1)
			var/turf/T = get_turf(user)
			user.visible_message("[user] welds apart the disposal.", "You start to weld apart the disposal.")
			sleep(40)
			if(get_turf(user) == T && W.remove_fuel(2,user))
				var/obj/machinery/constructable_frame/machine_frame/M = new /obj/machinery/constructable_frame/machine_frame(loc)
				M.state = 2
				M.icon_state = "box_1"
				for(var/obj/O in component_parts)
					if(O.reliability != 100 && crit_fail)
						O.crit_fail = 1
					O.loc = src.loc
				// the stuff still in the disposal
				for(var/obj/O in src)
					O.loc = src.loc
				del(src)
			return

		var/obj/item/weapon/grab/G = I
		if(istype(G))	// handle grabbed mob
			if(ismob(G.affecting))
				var/mob/GM = G.affecting
				for (var/mob/V in viewers(usr))
					V.show_message("[usr] starts putting [GM.name] into the disposal.", 3)
				if(do_after(usr, 20))
					if (GM.client)
						GM.client.perspective = EYE_PERSPECTIVE
						GM.client.eye = src
					GM.loc = src
					for (var/mob/C in viewers(src))
						C.show_message("\red [GM.name] has been placed in the [src] by [user].", 3)
					del(G)
		else
			if(!I || isnull(I))
				//CRASH("disposal/attackby() was called, but I was nulled before calling user.drop_item()")
				return // No idea why, but somehow I gets nulled before it goes into the else, and that leads to a lot of spam with runtime errors.

			user.drop_item()

			I.loc = src
			user << "You place \the [I] into the [src]."
			for(var/mob/M in viewers(src))
				if(M == user)
					continue
				M.show_message("[user.name] places \the [I] into the [src].", 3)
		timeleft = 5
		update()

	// mouse drop another mob or self
{'fraction_non_alphanumeric': 0.11910142230493154, 'fraction_numerical': 0.010368204173866809, 'mean_word_length': 2.9106029106029108, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '800593', 'n_tokens_mistral': 3139, 'n_tokens_neox': 2630, 'n_words': 848}