anchor.diff:  		if (!beaker || (beaker && beaker.reagents.total_volume >= beaker.reagents.maximum_volume))
   				return
   		playsound(src.loc, 'sound/machines/juicer.ogg', 20, 1)
  -		var/offset = prob(50) ? -2 : 2
  -		animate(src, pixel_x = pixel_x + offset, time = 0.2, loop = 250) //start shaking
   		operating = 1
   		updateUsrDialog()
   		spawn(50)
  -				pixel_x = initial(pixel_x) //return to its spot after shaking
   				operating = 0
   				updateUsrDialog()
   
  
positive.code: 		if (!beaker || (beaker && beaker.reagents.total_volume >= beaker.reagents.maximum_volume))
  				return
  		playsound(src.loc, 'sound/machines/blender.ogg', 50, 1)
  		var/offset = prob(50) ? -2 : 2
  		animate(src, pixel_x = pixel_x + offset, time = 0.2, loop = 250) //start shaking
  		operating = 1
  		updateUsrDialog()
  		spawn(60)
  				pixel_x = initial(pixel_x) //return to its spot after shaking
  				operating = 0
  				updateUsrDialog()
  
  
negative.code: 			default_deconstruction_crowbar(I)
  			return 1
  
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  /obj/machinery/adv_chem
  	name = "Advanced chemical machine"
  	desc = "Something is wrong if this is the machine you are using!"
  	density = 1
  	anchored = 1
  	icon = 'icons/obj/machines/chem.dmi'
  	icon_state = "distill"
  	use_power = 1
  	idle_power_usage = 10
  	var/obj/item/weapon/reagent_containers/glass/beaker = null
  
  /obj/machinery/adv_chem/ex_act(severity, target)
  	if(severity < 3)
  		..()
  
  /obj/machinery/adv_chem/blob_act()
  	if (prob(50))
  		qdel(src)
  
  /obj/machinery/adv_chem/power_change()
  	if(powered())
  		stat &= ~NOPOWER
  	else
  		spawn(rand(0, 15))
  			stat |= NOPOWER
  /obj/machinery/adv_chem/attackby(var/obj/item/weapon/B as obj, var/mob/user as mob)
  	if(istype(B,/obj/item/weapon/reagent_containers/glass))
  		if(src.beaker)
  			user<<"A beaker is already loaded into the machine"
  			return
  		else
  			user.drop_item()
  			B.loc = src
  			user << "You add the beaker to the machine!"
  			src.beaker = B
  			src.updateUsrDialog()
  /obj/machinery/adv_chem/attack_ai(mob/user as mob)
  	return src.attack_hand(user)
  
  /obj/machinery/adv_chem/attack_paw(mob/user as mob)
  	return src.attack_hand(user)
  
  /obj/machinery/adv_chem/attack_hand(mob/user as mob)
  	return
  /obj/machinery/adv_chem/process()
  	return
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  /obj/machinery/adv_chem/pressure
  	name = "Pressurized reaction chamber"
  	desc = "Creates immensly high pressures to suit certain reaction conditions"
  	density = 1
  	anchored = 1
  	icon_state = "press"
  	use_power = 1
  	idle_power_usage = 10
  	var/pressure = 1
  	var/target_pressure = 1
  
  /obj/machinery/adv_chem/pressure/attack_hand(mob/user as mob)
  	if(stat & BROKEN)
  		return
  	user.set_machine(src)
  	var/dat = ""
  	if(!src.beaker)
  		dat += "No beaker loaded"
  	else
  		dat += "Target pressure: [src.pressure] Atmospheres <BR><BR>"
  
  
  		dat += "<A href='?src=\ref[src];lower=1'>Pressure (- 1) </A> "
  		dat += "<A href='?src=\ref[src];higher=1'>Pressure (+ 1)</A> "
  		dat += "<A href='?src=\ref[src];lower_=1'>Pressure (- 10) </A> "
  		dat += "<A href='?src=\ref[src];higher_=1'>Pressure (+ 10)</A> "
  		dat += "<A href='?src=\ref[src];pressure=1'>Pressurize chamber</A><BR><BR> "
  		dat += "<A href='?src=\ref[src];eject=1'>Eject beaker</A><BR><BR> "
  		dat += "Contained reagents<BR>"
  		var/datum/reagents/R = src.beaker:reagents
  		for(var/datum/reagent/I in R.reagent_list)
  			dat += "Reagent : [I.name] , [I.volume] Units <BR>"
  	user << browse("<TITLE>Pressurized reaction chamber</TITLE>Reactor menu:<BR><BR>[dat]", "window=preactor;size=575x400")
  	onclose(user, "preactor")
  
  /obj/machinery/adv_chem/pressure/Topic(href, href_list)
  	usr.set_machine(src)
  	if(href_list["lower"])
  		if(src.pressure - 1 >= 0)
  			src.pressure -= 1
  	else if(href_list["higher"])
  		if(src.pressure + 1 <= 200)
  			src.pressure += 1
  	if(href_list["lower_"])
  		if(src.pressure - 10 >= 0)
  			src.pressure -= 10
  		else
  			src.pressure = 0
  	else if(href_list["higher_"])
  		if(src.pressure + 10 <= 100)
  			src.pressure += 10
  		else
  			src.pressure = 100
  	else if(href_list["pressure"])
  		var/datum/reagents/R = src.beaker:reagents
  		R.present_machines[3] = src.pressure
  		R.handle_reactions()
  		R.present_machines[3] = -1 //reset it so we don't have magic infinite reactions or reactions that dont happen.
  	else if(href_list["eject"])
  		src.beaker.loc = src.loc
  		src.beaker = null
  	src.updateUsrDialog()
  	return
  
  
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  /obj/machinery/adv_chem/radioactive//break up in action dust I walk my brow and I strut my
  	name = "Radioactive molecular reassembler"
  	desc = "A mystical machine that changes molecules directly on the level of bonding."
  	density = 1
  	anchored = 1
  	icon_state = "radio"
  	use_power = 1
  	idle_power_usage = 10
  	var/material_amt = 0 //requires uranium in order to function
  	var/active = 0
  	var/curr_time = 0
  	var/target_time = 10
  
  /obj/machinery/adv_chem/radioactive/attackby(var/obj/item/B as obj, var/mob/user as mob)
  	if(istype(B,/obj/item/weapon/reagent_containers/glass))
  		if(src.beaker)
  			user<<"A beaker is already loaded into the machine"
  			return
  		else
  			user.drop_item()
  			B.loc = src
  			user << "You add the beaker to the machine!"
  			src.beaker = B
  			src.updateUsrDialog()
  	if(istype(B,/obj/item/stack/sheet/mineral/uranium))
  		user<<"You add the uranium to the machine"
  		var/obj/item/stack/sheet/mineral/uranium/I = B
  		material_amt += I.amount * 500
  		user.drop_item()
  		qdel(I)//it's a var now
  
  /obj/machinery/adv_chem/radioactive/attack_hand(mob/user as mob)
  	if(stat & BROKEN)
  		return
  	if(!beaker || material_amt == 0)
  		user.visible_message("<span class='danger'>The [src.name] pings angrilly!</span>")
  	else if(!active)
  		user<<"<span class='notice'>You turn on the [src.name].</span>"
  		active = 1
  /obj/machinery/adv_chem/radioactive/process()
  	if(stat & BROKEN || !active || !beaker)
  		return
  	if(curr_time == target_time)
  		active = 0
  		curr_time = 0
  		var/datum/reagents/R = src.beaker:reagents
  		R.present_machines[4] = -1//reset the value so we don't have outside reactions
  		beaker.loc = src.loc
  		beaker = null
  		return
  	curr_time ++
  	if(prob(25))
  		src.visible_message("<span class='notice'>The [src.name] humms loudly.</span>")
  		var/datum/reagents/R = src.beaker:reagents
  		R.present_machines[4] = rand(0,30)//much more out of chance much more dangerous
  		R.handle_reactions()//always called
  		material_amt -= 10 //50 charges per sheet of uranium
  		for(var/mob/living/l in range(4,src))//boy is this thing nasty!
  			if(l in view())
  				l.show_message("<span class=\"warning\">You become covered in radiation burns from the [src.name].</span>")
  			else
  				l.show_message("<span class=\"warning\">Your clothes feel warm and you notice your arms a burnt!</span>", 2)
  			var/rads = 100 * sqrt( 1 / (get_dist(l, src) + 1) )
  			l.apply_effect(rads, IRRADIATE)
  //do_teleport(L, get_turf(L), blink_range, asoundin = 'sound/effects/phasein.ogg')
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  /obj/machinery/adv_chem/bluespace
  	name = "Bluespace recombobulator"
  	desc = "Forget changing molecules , this thing changes the laws of physics itself in order to produce chemicals."
  	density = 1
  	anchored = 1
  	icon_state = "blue"
  	use_power = 1
  	idle_power_usage = 10
  	//var/material_amt = 0 // I might add something I don't know
  	var/curr_time = 0
  	var/target_time = 10
  	var/active = 0
  	var/crystal_amt = 0
  	var/target_activity = 0
  
  
  /obj/machinery/adv_chem/bluespace/attackby(var/obj/item/B as obj, var/mob/user as mob)
  	if(istype(B,/obj/item/weapon/reagent_containers/glass))
  		if(src.beaker)
  			user<<"A beaker is already loaded into the machine"
  			return
  		else
  			user.drop_item()
  			B.loc = src
  			user << "You add the beaker to the machine!"
  			src.beaker = B
  			src.updateUsrDialog()
  	if(istype(B,/obj/item/bluespace_crystal))
  		crystal_amt += 1
  		user<<"<span class='notice'>You add the bluespace crystal to the machine!</span>"
  		user.drop_item()
  		qdel(B)
  
  /obj/machinery/adv_chem/bluespace/attack_hand(mob/user as mob)
  	if(stat & BROKEN)
  		return
  	if(!beaker)
  		user<<"<span class='notice'>There is no beaker loaded in the [src.name]"
  		if(prob(10))
  			user.visible_message("<span class='danger'>The [src.name] sparks!</span>")
  			var/datum/effect/effect/system/spark_spread/sparks = new /datum/effect/effect/system/spark_spread
  			sparks.set_up(1, 1, src)
  			sparks.start()
  	else
  		var/dat = ""
  		dat += "Active : [(active)? "Yes" : "No"] <BR><BR>"
  		dat += "Target bluespace activity : [src.target_activity] <BR><BR>"
  		dat += "<A href='?src=\ref[src];lower=1'>Activity (-1) </A> "
  		dat += "<A href='?src=\ref[src];higher=1'>Activity (+1)</A> "
  		dat += "<A href='?src=\ref[src];heat=1'>Recombobulate</A><BR><BR> "
  		dat += "<A href='?src=\ref[src];eject=1'>Eject beaker</A><BR><BR> "
  		dat += "Contained reagents<BR>"
  		var/datum/reagents/R = src.beaker:reagents
  		for(var/datum/reagent/I in R.reagent_list)
  			dat += "[I.name] , [I.volume] Units <BR>"
  		user << browse("<TITLE>Bluespace recombobulator</TITLE>Bluespace recombobulator menu:<BR><BR>[dat]", "window=bluespace;size=575x400")
  		onclose(user, "bluespace")
  /obj/machinery/adv_chem/bluespace/Topic(href, href_list)
  	usr.set_machine(src)
  	if(href_list["lower"])
  		if(src.target_activity - 1 >= 0)
  			src.target_activity -= 1
  	else if(href_list["higher"])
  		if(src.target_activity + 1 <= 30)
  			src.target_activity += 1
  	else if(href_list["heat"])
  		active = !active
  	else if(href_list["eject"])
  		if(!active)
  			src.beaker.loc = src.loc
  			src.beaker = null
  	src.updateUsrDialog()
  	return
  
  /obj/machinery/adv_chem/bluespace/process()
  	if(stat & BROKEN || !active || !beaker)
  		return
  	if(curr_time == target_time)
  		active = 0
  		curr_time = 0
  		var/datum/reagents/R = src.beaker:reagents
  		R.present_machines[5] = 0//reset the value so we don't have outside reactions
  		beaker.loc = src.loc
  		beaker = null
  		return
  	curr_time ++
  	if(prob(30))
  		src.visible_message("<span class='danger'>The [src.name] sparks crazily!.</span>")
  		var/datum/reagents/R = src.beaker:reagents
  		if(!(crystal_amt > 0))
  			R.present_machines[5] = rand(0,30)//much more out of chance much more dangerous
  		else
  			var/value = rand(target_activity , target_activity + 3)
  			if(value > 30)
  				value = 30
  			else if(value < 0)
  				value = 0
  			crystal_amt -= 1
  			R.present_machines[5] = value
  		R.handle_reactions()//always called
  	if(prob(20))//low chance but could still happen
  		var/datum/effect/effect/system/spark_spread/sparks = new /datum/effect/effect/system/spark_spread//give it some sparks for drama ofc!
  		sparks.set_up(1, 1, src)
  		sparks.start()
  		for(var/mob/living/l in range(2,src))//boy is this thing nasty!
  			l.show_message("<span class=\"warning\">You feel disorientated!</span>")
  			do_teleport(l, get_turf(l), 5, asoundin = 'sound/effects/phasein.ogg')
  
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  /obj/machinery/adv_chem/distiller
  	name = "Chemical Distillery"
  	desc = "Used in the manufacturing of highly complicated chemicals"
  	density = 1
  	anchored = 1
  	icon_state = "distill"
  	use_power = 1
  	idle_power_usage = 10
  	var/temperature = 270
  	var/target_temp = 270
  	var/heating = 0
  
  /obj/machinery/adv_chem/distiller/attackby(var/obj/item/weapon/B as obj, var/mob/user as mob)
  	if(istype(B,/obj/item/weapon/reagent_containers/glass))
  		if(src.beaker)
  			user<<"A beaker is already loaded into the machine"
  			return
  		else
  			heating = 0
  			user.drop_item()
  			B.loc = src
  			user << "You add the beaker to the machine!"
  			src.beaker = B
  			temperature = src.beaker:reagents.present_machines[1]//this makes it unique
  			src.updateUsrDialog()
  /obj/machinery/adv_chem/distiller/attack_hand(mob/user as mob)
  	if(stat & BROKEN)
  		return
  	user.set_machine(src)
  	var/dat = ""
  	if(!src.beaker)
  		dat += "No beaker loaded"
  	else if(src.temperature != -1)
  		dat += "Temperature : [src.temperature]K <BR><BR>"
  		dat += "Target temperature : [src.target_temp]K <BR><BR>"
  		dat += "<A href='?src=\ref[src];lower=1'>Temp (- 10) </A> "
  		dat += "<A href='?src=\ref[src];higher=1'>Temp (+ 10)</A> "
  		dat += "<A href='?src=\ref[src];lower_=1'>Temp (- 100) </A> "
  		dat += "<A href='?src=\ref[src];higher_=1'>Temp (+ 100)</A> "
  		dat += "<A href='?src=\ref[src];heat=1'>Heat beaker</A><BR><BR> "
  		dat += "<A href='?src=\ref[src];eject=1'>Eject beaker</A><BR><BR> "
  		dat += "Contained reagents<BR>"
  		var/datum/reagents/R = src.beaker:reagents
  		for(var/datum/reagent/I in R.reagent_list)
  			dat += "[I.name] , [I.volume] Units <BR>"
  	else
  		dat += "No reagents within the container"
  	user << browse("<TITLE>Chemical Distillery</TITLE>Chemical Distillery menu:<BR><BR>[dat]", "window=dist;size=575x400")
  	onclose(user, "dist")
  
  /obj/machinery/adv_chem/distiller/Topic(href, href_list)
  	usr.set_machine(src)
  	if(href_list["lower"])
  		if(src.target_temp - 10 >= 0)
  			src.target_temp -= 10
  	else if(href_list["higher"])
  		if(src.target_temp + 10 <= 500)
  			src.target_temp += 10
  	if(href_list["lower_"])
  		if(src.target_temp - 100 >= 0)
  			src.target_temp -= 100
  		else
  			src.target_temp = 0
  	else if(href_list["higher_"])
  		if(src.target_temp + 100 <= 500)
  			src.target_temp += 100
  		else
  			src.target_temp = 500
  	else if(href_list["heat"])
  		heating = !heating
  	else if(href_list["eject"])
  		heating = 0
  		src.beaker.loc = src.loc
  		src.beaker = null
  	src.updateUsrDialog()
  	return
  /obj/machinery/adv_chem/distiller/process()
  	if((stat & (BROKEN|NOPOWER)) || !beaker)
  		return
  	if(heating)
  		var/datum/reagents/R = src.beaker:reagents
  		if(R.present_machines[1] == -1)
  			return
  
  		R.present_machines[1] = src.temperature
  		R.handle_reactions()//always called
  		if(temperature == target_temp)
  			heating = 0
  			return
  		var/increase_amt = 30 //temp to increase by , because it's this value chemials can and will overheat_react
  		if(target_temp > temperature)
  			if(temperature + increase_amt > target_temp)
  				increase_amt -= ((temperature + increase_amt) - target_temp) //get it to the exact temperature
  		else
  			increase_amt = -30
  			if(temperature + increase_amt < target_temp)
  				increase_amt -= ((temperature + increase_amt) - target_temp)
  		if(increase_amt + temperature > 500)
  			increase_amt -= (temperature + increase_amt) - 500
  		else if(increase_amt + temperature < 0)
  			increase_amt -= (temperature + increase_amt)
  		temperature += increase_amt
  	src.updateUsrDialog()
  
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  /obj/machinery/adv_chem/centrifuge
  	name = "Centrifuge"
  	desc = "Spins chemicals at high speeds to seperate them"
  	density = 1
  	anchored = 1
  	icon_state = "cent_off"
  	use_power = 1
  	idle_power_usage = 30
  	var/time_required = 30
  	var/current_time = 0
  	var/working = 0
  
  /obj/machinery/adv_chem/centrifuge/attack_hand(mob/user as mob)
  	if(stat & BROKEN || working)
  		return
  	if(src.beaker)
  		user<<"<span class='notice'>You activate the centrifuge."
  		//play sound here
  		working = 1
  
  
  	else
  		user<<"<span class='notice'>No beaker is in the machine!"
  
  /obj/machinery/adv_chem/centrifuge/process()
  	if((stat & (BROKEN|NOPOWER)) || !working)
  		return
  	else
  		icon_state = "cent_on"
  		current_time ++
  		if(current_time == time_required)
  			icon_state = "cent_off"
  			var/datum/reagents/Reagent = src.beaker:reagents
  			Reagent.present_machines[2] = 1
  			Reagent.handle_reactions()
  			Reagent.present_machines[2] = -1
  			working = 0
  			current_time = 0
  			src.beaker.loc = src.loc
  			src.beaker = null
  			return
  
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  