code:
/obj/structure/punching_bag
	name = "punching bag"
	desc = "A punching bag. Can you get to speed level 4???"
	icon = 'goon/icons/obj/fitness.dmi'
	icon_state = "punchingbag"
	anchored = 1
	layer = MOB_LAYER+1 // TODO LAYER
	var/list/hit_sounds = list('sound/weapons/genhit1.ogg', 'sound/weapons/genhit2.ogg', 'sound/weapons/genhit3.ogg',\
	'sound/weapons/punch1.ogg', 'sound/weapons/punch2.ogg', 'sound/weapons/punch3.ogg', 'sound/weapons/punch4.ogg')

/obj/structure/punching_bag/attack_hand(mob/user as mob)
		flick("[icon_state]2", src)
		playsound(src.loc, pick(src.hit_sounds), 25, 1, -1)

/obj/structure/stacklifter
	name = "Weight Machine"
	desc = "Just looking at this thing makes you feel tired."
	icon = 'goon/icons/obj/fitness.dmi'
	icon_state = "fitnesslifter"
	density = 1
	anchored = 1

/obj/structure/stacklifter/attack_hand(mob/user as mob)
	if(in_use)
		user << "Its already in use - wait a bit."
		return
	else
		in_use = 1
		icon_state = "fitnesslifter2"
		user.dir = SOUTH
		user.Stun(4)
		user.loc = src.loc
		var/bragmessage = pick("pushing it to the limit","going into overdrive","burning with determination","rising up to the challenge", "getting strong now","getting ripped")
		user.visible_message("[user] is [bragmessage]!")
		var/lifts = 0
		while (lifts++ < 6)
			if (user.loc != src.loc)
				break
			sleep(3)
			animate(user, pixel_y = -2, time = 3)
			sleep(3)
			animate(user, pixel_y = -4, time = 3)
			sleep(3)
			playsound(user, 'goon/sound/effects/spring.ogg', 60, 1)

		playsound(user, 'sound/machines/click.ogg', 60, 1)
		in_use = 0
		user.pixel_y = 0
		var/finishmessage = pick("You feel stronger!","You feel like you can take on the world!","You feel robust!","You feel indestructible!")
		icon_state = "fitnesslifter"
		user << finishmessage

/obj/structure/weightlifter
	name = "Weight Machine"
	desc = "Just looking at this thing makes you feel tired."
	icon = 'goon/icons/obj/fitness.dmi'
	icon_state = "fitnessweight"
	density = 1
	anchored = 1

/obj/structure/weightlifter/attack_hand(mob/user as mob)
	if(in_use)
		user << "Its already in use - wait a bit."
		return
	else
		in_use = 1
		icon_state = "fitnessweight-c"
		user.dir = SOUTH
		user.Stun(4)
		user.loc = src.loc
		var/image/W = image('goon/icons/obj/fitness.dmi',"fitnessweight-w")
		W.layer = MOB_LAYER+1
		overlays += W
		var/bragmessage = pick("pushing it to the limit","going into overdrive","burning with determination","rising up to the challenge", "getting strong now","getting ripped")
		user.visible_message("[user] is [bragmessage]!")
		var/reps = 0
		user.pixel_y = 5
		while (reps++ < 6)
			if (user.loc != src.loc)
				break

			for (var/innerReps = max(reps, 1), innerReps > 0, innerReps--)
				sleep(3)
				animate(user, pixel_y = (user.pixel_y == 3) ? 5 : 3, time = 3)

			playsound(user, 'goon/sound/effects/spring.ogg', 60, 1)

		sleep(3)
		animate(user, pixel_y = 2, time = 3)
		sleep(3)
		playsound(user, 'sound/machines/click.ogg', 60, 1)
		in_use = 0
		animate(user, pixel_y = 0, time = 3)
		var/finishmessage = pick("You feel stronger!","You feel like you can take on the world!","You feel robust!","You feel indestructible!")
		icon_state = "fitnessweight"
		overlays -= W
		user << "[finishmessage]"


code:
#define STARTUP_STAGE 1
#define MAIN_STAGE 2
#define WIND_DOWN_STAGE 3
#define END_STAGE 4

/datum/weather
	var/name = "storm"
	var/start_up_time = 300 //30 seconds
	var/start_up_message = "The wind begins to pick up."
	var/duration = 120 //2 minutes
	var/duration_lower = 120
	var/duration_upper = 120
	var/duration_message = "A storm has started!"
	var/wind_down = 300 // 30 seconds
	var/wind_down_message = "The storm is passing."

	var/target_z = 1
	var/exclude_walls = TRUE
	var/area_type = /area/space
	var/stage = STARTUP_STAGE

	var/start_up_overlay = "lava"
	var/duration_overlay = "lava"
	var/overlay_layer = 10 //This is the default area layer, and above everything else. 2 is floors/below walls and mobs.
	var/purely_aesthetic = FALSE //If we just want gentle rain that doesn't hurt people
	var/list/impacted_areas = list()

/datum/weather/proc/weather_start_up()
	for(var/area/N in get_areas(area_type))
		if(N.z == target_z)
			impacted_areas += N
	duration = rand(duration_lower,duration_upper)
	update_areas()
	for(var/mob/M in player_list)
		if(M.z == target_z)
			M << "[start_up_message]"

	sleep(start_up_time)
	stage = MAIN_STAGE
	weather_main()

/datum/weather/proc/weather_main()
	update_areas()
	for(var/mob/M in player_list)
		if(M.z == target_z)
			M << "[duration_message]"
	if(purely_aesthetic)
		sleep(duration*10)
	else  //Storm effects
		for(var/i in 1 to duration-1)
			for(var/mob/living/L in living_mob_list)
				var/area/storm_area = get_area(L)
				if(storm_area in impacted_areas)
					storm_act(L)
			sleep(10)

	stage = WIND_DOWN_STAGE
	weather_wind_down()

/datum/weather/proc/weather_wind_down()
	update_areas()
	for(var/mob/M in player_list)
		if(M.z == target_z)
			M << "[wind_down_message]"

	sleep(wind_down)

	stage = END_STAGE
	update_areas()

/datum/weather/proc/storm_act(mob/living/L)
	if(prob(30)) //Dont want it spammed very tick
		L << "You're buffeted by the storm!"
		L.adjustBruteLoss(1)

/datum/weather/proc/update_areas()
	for(var/area/N in impacted_areas)
		N.layer = overlay_layer
		N.icon = 'icons/effects/weather_effects.dmi'
		N.invisibility = 0
		switch(stage)
			if(STARTUP_STAGE)
				N.icon_state = start_up_overlay

			if(MAIN_STAGE)
				N.icon_state = duration_overlay

			if(WIND_DOWN_STAGE)
				N.icon_state = start_up_overlay

			if(END_STAGE)
				N.icon_state = initial(N.icon_state)
				N.icon = 'icons/turf/areas.dmi'
				N.layer = 10 //Just default back to normal area stuff since I assume setting a var is faster than initial
				N.invisibility = 100
				N.opacity = 0

license: mit


code:
///The floor is lava

/datum/weather/floor_is_lava
	name = "floor is lava"
	start_up_time = 30 //3 seconds
	start_up_message = "The ground begins to bubble."
	duration_lower = 45
	duration_upper = 60 //1 minute
	duration_message = "The floor is lava!"
	wind_down = 30// 3 seconds
	wind_down_message = "The ground begins to cool."

	target_z = 1
	exclude_walls = TRUE
	area_type = /area

	start_up_overlay = "lava"
	duration_overlay = "lava"
	overlay_layer = 2 //Covers floors only

/datum/weather/floor_is_lava/storm_act(mob/living/L)
	var/turf/F = get_turf(L)
	for(var/obj/structure/O in F.contents)
		if(O.level > F.level && !istype(O, /obj/structure/window)) // Something to stand on and it isn't under the floor!
			return
	L.adjustFireLoss(3)

/datum/weather/advanced_darkness
	name = "advanced darkness"
	start_up_time = 100 //10 seconds
	start_up_message = "The lights begin to dim... is power going out?"
	duration_lower = 45
	duration_upper = 60 //1 minute
	duration_message = "This isn't average everyday darkness... this is advanced darkness!"
	wind_down = 100 // 10 seconds
	wind_down_message = "The darkness is receding. Thank god."
	purely_aesthetic = TRUE

	target_z = 1
	exclude_walls = TRUE
	area_type = /area

	start_up_overlay = ""
	duration_overlay = ""
	overlay_layer = 10

/datum/weather/advanced_darkness/update_areas()
	for(var/area/A in impacted_areas)
		if(stage == MAIN_STAGE)
			A.invisibility = 0
			A.opacity = 1
			A.layer = overlay_layer
			A.icon = 'icons/effects/weather_effects.dmi'
			A.icon_state = start_up_overlay
		else
			A.invisibility = 100
			A.opacity = 0
//Ash storms

/datum/weather/ash_storm
	name = "ash storm"
	start_up_time = 300 //30 seconds
	start_up_message = "The wind begins to pick up. Seek shelter."
	duration_lower = 60 //1 minute
	duration_upper = 150 //2.5 minutes
	duration_message = "An ash storm has started! Get inside!"
	wind_down = 300 // 30 seconds
	wind_down_message = "The storm begins to fade. Should be safe to go outside again."

	target_z = ZLEVEL_LAVALAND
	area_type = /area/lavaland/surface/outdoors

	start_up_overlay = "light_ash"
	duration_overlay = "ash_storm"
	overlay_layer = 10

/datum/weather/ash_storm/false_alarm //No storm, just light ember fall
	purely_aesthetic = TRUE
	duration_overlay = "light_ash"
	duration_message = "Looks like the storm just missed the mining area. False alarm."
	wind_down_message = "The ash fall starts to trail off."

/datum/weather/ash_storm/storm_act(mob/living/L)
	if("mining" in L.faction)
		return
	if(istype(L.loc, /obj/mecha))
		return
	if(ishuman(L))
		var/mob/living/carbon/human/H = L
		var/thermal_protection = H.get_thermal_protection()
		if(thermal_protection >= FIRE_IMMUNITY_SUIT_MAX_TEMP_PROTECT)
			return
	L.adjustFireLoss(4)


code:
/**********************Input and output plates**************************/

/obj/machinery/mineral/input
	icon = 'icons/mob/screen_gen.dmi'
	icon_state = "x2"
	name = "Input area"
	density = 0
	anchored = 1

/obj/machinery/mineral/input/New()
	icon_state = "blank"

/obj/machinery/mineral/output
	icon = 'icons/mob/screen_gen.dmi'
	icon_state = "x"
	name = "Output area"
	density = 0
	anchored = 1

/obj/machinery/mineral/output/New()
	icon_state = "blank"

/obj/machinery/mineral
	var/input_dir = NORTH
	var/output_dir = SOUTH

/obj/machinery/mineral/proc/unload_mineral(atom/movable/S)
	S.loc = loc
	var/turf/T = get_step(src,output_dir)
	if(T)
		S.loc = T


code:
/**********************Mineral processing unit console**************************/

/obj/machinery/mineral/processing_unit_console
	name = "production machine console"
	icon = 'icons/obj/machines/mining_machines.dmi'
	icon_state = "console"
	density = 1
	anchored = 1
	var/obj/machinery/mineral/processing_unit/machine = null
	var/machinedir = EAST
	speed_process = 1

/obj/machinery/mineral/processing_unit_console/New()
	..()
	spawn(7)
		src.machine = locate(/obj/machinery/mineral/processing_unit, get_step(src, machinedir))
		if (machine)
			machine.CONSOLE = src
		else
			qdel(src)

/obj/machinery/mineral/processing_unit_console/attack_hand(mob/user)

	var/dat = "Smelter control console

"
	//iron
	if(machine.ore_iron || machine.ore_glass || machine.ore_plasma || machine.ore_uranium || machine.ore_gold || machine.ore_silver || machine.ore_diamond || machine.ore_clown || machine.ore_adamantine)
		if(machine.ore_iron)
			if (machine.selected_iron==1)
				dat += text("Smelting ")
			else
				dat += text("Not smelting ")
			dat += text("Iron: [machine.ore_iron]
")
		else
			machine.selected_iron = 0

		//sand - glass
		if(machine.ore_glass)
			if (machine.selected_glass==1)
				dat += text("Smelting ")
			else
				dat += text("Not smelting ")
			dat += text("Sand: [machine.ore_glass]
")
		else
			machine.selected_glass = 0

		//plasma
		if(machine.ore_plasma)
			if (machine.selected_plasma==1)
				dat += text("Smelting ")
			else
				dat += text("Not smelting ")
			dat += text("Plasma: [machine.ore_plasma]
")
		else
			machine.selected_plasma = 0

		//uranium
		if(machine.ore_uranium)
			if (machine.selected_uranium==1)
				dat += text("Smelting ")
			else
				dat += text("Not smelting ")
			dat += text("Uranium: [machine.ore_uranium]
")
		else
			machine.selected_uranium = 0

		//gold
		if(machine.ore_gold)
			if (machine.selected_gold==1)
				dat += text("Smelting ")
			else
				dat += text("Not smelting ")
			dat += text("Gold: [machine.ore_gold]
")
		else
			machine.selected_gold = 0

		//silver
		if(machine.ore_silver)
			if (machine.selected_silver==1)
				dat += text("Smelting ")
			else
				dat += text("Not smelting ")
			dat += text("Silver: [machine.ore_silver]
")
		else
			machine.selected_silver = 0

		//diamond
		if(machine.ore_diamond)
			if (machine.selected_diamond==1)
				dat += text("Smelting ")
			else
				dat += text("Not smelting ")
			dat += text("Diamond: [machine.ore_diamond]
")
		else
			machine.selected_diamond = 0

		//bananium
		if(machine.ore_clown)
			if (machine.selected_clown==1)
				dat += text("Smelting ")
			else
				dat += text("Not smelting ")
			dat += text("Bananium: [machine.ore_clown]
")
		else
			machine.selected_clown = 0

		//On or off
		dat += text("Machine is currently ")
		if (machine.on==1)
			dat += text("On ")
		else
			dat += text("Off ")
	else
		dat+="---No Materials Loaded---"

	user << browse("[dat]", "window=console_processing_unit")

/obj/machinery/mineral/processing_unit_console/Topic(href, href_list)
	if(..())
		return
	usr.set_machine(src)
	src.add_fingerprint(usr)
	if(href_list["sel_iron"])
		if (href_list["sel_iron"] == "yes")
			machine.selected_iron = 1
		else
			machine.selected_iron = 0
	if(href_list["sel_glass"])
		if (href_list["sel_glass"] == "yes")
			machine.selected_glass = 1
		else
			machine.selected_glass = 0
	if(href_list["sel_plasma"])
		if (href_list["sel_plasma"] == "yes")
			machine.selected_plasma = 1
		else
			machine.selected_plasma = 0
	if(href_list["sel_uranium"])
		if (href_list["sel_uranium"] == "yes")
			machine.selected_uranium = 1
		else
			machine.selected_uranium = 0
	if(href_list["sel_gold"])
		if (href_list["sel_gold"] == "yes")
			machine.selected_gold = 1
		else
			machine.selected_gold = 0
	if(href_list["sel_silver"])
		if (href_list["sel_silver"] == "yes")
			machine.selected_silver = 1
		else
			machine.selected_silver = 0
	if(href_list["sel_diamond"])
		if (href_list["sel_diamond"] == "yes")
			machine.selected_diamond = 1
		else
			machine.selected_diamond = 0
	if(href_list["sel_clown"])
		if (href_list["sel_clown"] == "yes")
			machine.selected_clown = 1
		else
			machine.selected_clown = 0
	if(href_list["set_on"])
		if (href_list["set_on"] == "on")
			machine.on = 1
		else
			machine.on = 0
	src.updateUsrDialog()
	return

/**********************Mineral processing unit**************************/

/obj/machinery/mineral/processing_unit
	name = "furnace"
	icon = 'icons/obj/machines/mining_machines.dmi'
	icon_state = "furnace"
	density = 1
	anchored = 1
	var/obj/machinery/mineral/CONSOLE = null
	var/ore_gold = 0;
	var/ore_silver = 0;
	var/ore_diamond = 0;
	var/ore_glass = 0;
	var/ore_plasma = 0;
	var/ore_uranium = 0;
	var/ore_iron = 0;
	var/ore_clown = 0;
	var/ore_adamantine = 0;
	var/selected_gold = 0
	var/selected_silver = 0
	var/selected_diamond = 0
	var/selected_glass = 0
	var/selected_plasma = 0
	var/selected_uranium = 0
	var/selected_iron = 0
	var/selected_clown = 0
	var/on = 0 //0 = off, 1 =... oh you know!

/obj/machinery/mineral/processing_unit/process()
	var/i
	for (i = 0; i < 10; i++)
		if (on)
			if (selected_glass == 1 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0)
				if (ore_glass > 0)
					ore_glass--;
					generate_mineral(/obj/item/stack/sheet/glass)
				else
					on = 0
				continue
			if (selected_glass == 1 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 1 && selected_clown == 0)
				if (ore_glass > 0 && ore_iron > 0)
					ore_glass--;
					ore_iron--;
					generate_mineral(/obj/item/stack/sheet/rglass)
				else
					on = 0
				continue
			if (selected_glass == 0 && selected_gold == 1 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0)
				if (ore_gold > 0)
					ore_gold--;
					generate_mineral(/obj/item/stack/sheet/mineral/gold)
				else
					on = 0
				continue
			if (selected_glass == 0 && selected_gold == 0 && selected_silver == 1 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0)
				if (ore_silver > 0)
					ore_silver--;
					generate_mineral(/obj/item/stack/sheet/mineral/silver)
				else
					on = 0
				continue
			if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 1 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0)
				if (ore_diamond > 0)
					ore_diamond--;
					generate_mineral(/obj/item/stack/sheet/mineral/diamond)
				else
					on = 0
				continue
			if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 1 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0)
				if (ore_plasma > 0)
					ore_plasma--;
					generate_mineral(/obj/item/stack/sheet/mineral/plasma)
				else
					on = 0
				continue
			if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 1 && selected_iron == 0 && selected_clown == 0)
				if (ore_uranium > 0)
					ore_uranium--;
					generate_mineral(/obj/item/stack/sheet/mineral/uranium)
				else
					on = 0
				continue
			if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 1 && selected_clown == 0)
				if (ore_iron > 0)
					ore_iron--;
					generate_mineral(/obj/item/stack/sheet/metal)
				else
					on = 0
				continue
			if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 1 && selected_uranium == 0 && selected_iron == 1 && selected_clown == 0)
				if (ore_iron > 0 && ore_plasma > 0)
					ore_iron--;
					ore_plasma--;
					generate_mineral(/obj/item/stack/sheet/plasteel)
				else
					on = 0
				continue
			if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 1)
				if (ore_clown > 0)
					ore_clown--;
					generate_mineral(/obj/item/stack/sheet/mineral/bananium)
				else
					on = 0
				continue
			//THESE TWO ARE CODED FOR URIST TO USE WHEN HE GETS AROUND TO IT.
			//They were coded on 18 Feb 2012. If you're reading this in 2015, then firstly congratulations on the world not ending on 21 Dec 2012 and secondly, Urist is apparently VERY lazy. ~Errorage
			/*if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 1 && selected_plasma == 0 && selected_uranium == 1 && selected_iron == 0 && selected_clown == 0)
				if (ore_uranium >= 2 && ore_diamond >= 1)
					ore_uranium -= 2
					ore_diamond -= 1
					generate_mineral(/obj/item/stack/sheet/mineral/adamantine)
				else
					on = 0
				continue
			if (selected_glass == 0 && selected_gold == 0 && selected_silver == 1 && selected_diamond == 0 && selected_plasma == 1 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0)
				if (ore_silver >= 1 && ore_plasma >= 3)
					ore_silver -= 1
					ore_plasma -= 3
					generate_mineral(/obj/item/stack/sheet/mineral/mythril)
				else
					on = 0
				continue*/

			//if a non valid combination is selected

			var/b = 1 //this part checks if all required ores are available

			if (!(selected_gold || selected_silver ||selected_diamond || selected_uranium | selected_plasma || selected_iron || selected_iron))
				b = 0

			if (selected_gold == 1)
				if (ore_gold <= 0)
					b = 0
			if (selected_silver == 1)
				if (ore_silver <= 0)
					b = 0
			if (selected_diamond == 1)
				if (ore_diamond <= 0)
					b = 0
			if (selected_uranium == 1)
				if (ore_uranium <= 0)
					b = 0
			if (selected_plasma == 1)
				if (ore_plasma <= 0)
					b = 0
			if (selected_iron == 1)
				if (ore_iron <= 0)
					b = 0
			if (selected_glass == 1)
				if (ore_glass <= 0)
					b = 0
			if (selected_clown == 1)
				if (ore_clown <= 0)
					b = 0

			if (b) //if they are, deduct one from each, produce slag and shut the machine off
				if (selected_gold == 1)
					ore_gold--
				if (selected_silver == 1)
					ore_silver--
				if (selected_diamond == 1)
					ore_diamond--
				if (selected_uranium == 1)
					ore_uranium--
				if (selected_plasma == 1)
					ore_plasma--
				if (selected_iron == 1)
					ore_iron--
				if (selected_clown == 1)
					ore_clown--
				generate_mineral(/obj/item/weapon/ore/slag)
				on = 0
			else
				on = 0
				break
			break
		else
			break
	var/turf/T = get_step(src,input_dir)
	if(T)
		var/n = 0
		for(var/obj/item/O in T)
			n++
			if(n>10)
				break
			if (istype(O,/obj/item/weapon/ore/iron))
				ore_iron++;
				O.loc = null
				continue
			if (istype(O,/obj/item/weapon/ore/glass))
				ore_glass++;
				O.loc = null
				continue
			if (istype(O,/obj/item/weapon/ore/diamond))
				ore_diamond++;
				O.loc = null
				continue
			if (istype(O,/obj/item/weapon/ore/plasma))
				ore_plasma++
				O.loc = null
				continue
			if (istype(O,/obj/item/weapon/ore/gold))
				ore_gold++
				O.loc = null
				continue
			if (istype(O,/obj/item/weapon/ore/silver))
				ore_silver++
				O.loc = null
				continue
			if (istype(O,/obj/item/weapon/ore/uranium))
				ore_uranium++
				O.loc = null
				continue
			if (istype(O,/obj/item/weapon/ore/bananium))
				ore_clown++
				O.loc = null
				continue
			unload_mineral(O)

/obj/machinery/mineral/processing_unit/proc/generate_mineral(P)
	var/O = new P(src)
	unload_mineral(O)


code:
/**********************Mineral stacking unit console**************************/

/obj/machinery/mineral/stacking_unit_console
	name = "stacking machine console"
	icon = 'icons/obj/machines/mining_machines.dmi'
	icon_state = "console"
	density = 0
	anchored = 1
	var/obj/machinery/mineral/stacking_machine/machine = null
	var/machinedir = SOUTHEAST
	speed_process = 1

/obj/machinery/mineral/stacking_unit_console/New()
	..()
	spawn(7)
		src.machine = locate(/obj/machinery/mineral/stacking_machine, get_step(src, machinedir))
		if (machine)
			machine.CONSOLE = src
		else
			qdel(src)

/obj/machinery/mineral/stacking_unit_console/attack_hand(mob/user)

	var/obj/item/stack/sheet/s
	var/dat

	dat += text("Stacking unit console

")

	for(var/O in machine.stack_list)
		s = machine.stack_list[O]
		if(s.amount > 0)
			dat += text("[capitalize(s.name)]: [s.amount] Release
")

	dat += text("
Stacking: [machine.stack_amt]

")

	user << browse("[dat]", "window=console_stacking_machine")

	return

/obj/machinery/mineral/stacking_unit_console/Topic(href, href_list)
	if(..())
		return
	usr.set_machine(src)
	src.add_fingerprint(usr)
	if(href_list["release"])
		if(!(text2path(href_list["release"]) in machine.stack_list)) return //someone tried to spawn materials by spoofing hrefs
		var/obj/item/stack/sheet/inp = machine.stack_list[text2path(href_list["release"])]
		var/obj/item/stack/sheet/out = new inp.type()
		out.amount = inp.amount
		inp.amount = 0
		machine.unload_mineral(out)

	src.updateUsrDialog()
	return

/**********************Mineral stacking unit**************************/

/obj/machinery/mineral/stacking_machine
	name = "stacking machine"
	icon = 'icons/obj/machines/mining_machines.dmi'
	icon_state = "stacker"
	density = 1
	anchored = 1
	var/obj/machinery/mineral/stacking_unit_console/CONSOLE
	var/stk_types = list()
	var/stk_amt   = list()
	var/stack_list[0] //Key: Type.  Value: Instance of type.
	var/stack_amt = 50; //ammount to stack before releassing
	input_dir = EAST
	output_dir = WEST

/obj/machinery/mineral/stacking_machine/proc/process_sheet(obj/item/stack/sheet/inp)
	if(!(inp.type in stack_list)) //It's the first of this sheet added
		var/obj/item/stack/sheet/s = new inp.type(src,0)
		s.amount = 0
		stack_list[inp.type] = s
	var/obj/item/stack/sheet/storage = stack_list[inp.type]
	storage.amount += inp.amount //Stack the sheets
	inp.loc = null //Let the old sheet garbage collect
	while(storage.amount > stack_amt) //Get rid of excessive stackage
		var/obj/item/stack/sheet/out = new inp.type()
		out.amount = stack_amt
		unload_mineral(out)
		storage.amount -= stack_amt

/obj/machinery/mineral/stacking_machine/process()
	var/turf/T = get_step(src, input_dir)
	if(T)
		for(var/obj/item/stack/sheet/S in T)
			process_sheet(S)


code:
/**********************Unloading unit**************************/

/obj/machinery/mineral/unloading_machine
	name = "unloading machine"
	icon = 'icons/obj/machines/mining_machines.dmi'
	icon_state = "unloader"
	density = 1
	anchored = 1
	input_dir = WEST
	output_dir = EAST
	speed_process = 1

/obj/machinery/mineral/unloading_machine/process()
	var/turf/T = get_step(src,input_dir)
	if(T)
		var/limit
		for(var/obj/structure/ore_box/B in T)
			for (var/obj/item/weapon/ore/O in B)
				B.contents -= O
				unload_mineral(O)
				limit++
				if (limit>=10)
					return
				CHECK_TICK
			CHECK_TICK
		for(var/obj/item/I in T)
			unload_mineral(I)
			limit++
			if (limit>=10)
				return
			CHECK_TICK


code:
/**********************Mine areas**************************/

/area/mine
	icon_state = "mining"
	has_gravity = 1

/area/mine/explored
	name = "Mine"
	icon_state = "explored"
	music = null
	always_unpowered = 1
	requires_power = 1
	poweralm = 0
	power_environ = 0
	power_equip = 0
	power_light = 0
	outdoors = 1
	ambientsounds = list('sound/ambience/ambimine.ogg')

/area/mine/unexplored
	name = "Mine"
	icon_state = "unexplored"
	music = null
	always_unpowered = 1
	requires_power = 1
	poweralm = 0
	power_environ = 0
	power_equip = 0
	power_light = 0
	outdoors = 1
	ambientsounds = list('sound/ambience/ambimine.ogg')

/area/mine/lobby
	name = "Mining station"

/area/mine/storage
	name = "Mining station Storage"

/area/mine/production
	name = "Mining Station Starboard Wing"
	icon_state = "mining_production"

/area/mine/abandoned
	name = "Abandoned Mining Station"

/area/mine/living_quarters
	name = "Mining Station Port Wing"
	icon_state = "mining_living"

/area/mine/eva
	name = "Mining Station EVA"
	icon_state = "mining_eva"

/area/mine/maintenance
	name = "Mining Station Communications"

/area/mine/cafeteria
	name = "Mining station Cafeteria"

/area/mine/hydroponics
	name = "Mining station Hydroponics"

/area/mine/sleeper
	name = "Mining station Emergency Sleeper"

/area/mine/north_outpost
	name = "North Mining Outpost"

/area/mine/west_outpost
	name = "West Mining Outpost"

/area/mine/laborcamp
	name = "Labor Camp"

/area/mine/laborcamp/security
	name = "Labor Camp Security"
	icon_state = "security"


code:
/**********************Light************************/

//this item is intended to give the effect of entering the mine, so that light gradually fades
/obj/effect/light_emitter
	name = "Light-emtter"
	anchored = 1
	unacidable = 1
	luminosity = 8

/**********************Miner Lockers**************************/

/obj/structure/closet/wardrobe/miner
	name = "mining wardrobe"
	icon_door = "mixed"

/obj/structure/closet/wardrobe/miner/New()
	..()
	contents = list()
	new /obj/item/weapon/storage/backpack/dufflebag/engineering(src)
	new /obj/item/weapon/storage/backpack/industrial(src)
	new /obj/item/weapon/storage/backpack/satchel_eng(src)
	new /obj/item/clothing/under/rank/miner(src)
	new /obj/item/clothing/under/rank/miner(src)
	new /obj/item/clothing/under/rank/miner(src)
	new /obj/item/clothing/shoes/sneakers/black(src)
	new /obj/item/clothing/shoes/sneakers/black(src)
	new /obj/item/clothing/shoes/sneakers/black(src)
	new /obj/item/clothing/gloves/fingerless(src)
	new /obj/item/clothing/gloves/fingerless(src)
	new /obj/item/clothing/gloves/fingerless(src)

/obj/structure/closet/secure_closet/miner
	name = "miner's equipment"
	icon_state = "mining"
	req_access = list(access_mining)

/obj/structure/closet/secure_closet/miner/New()
	..()
	new /obj/item/device/radio/headset/headset_cargo(src)
	new /obj/item/device/t_scanner/adv_mining_scanner/lesser(src)
	new /obj/item/weapon/storage/bag/ore(src)
	new /obj/item/weapon/shovel(src)
	new /obj/item/weapon/pickaxe(src)
	new /obj/item/weapon/gun/energy/kinetic_accelerator(src)
	new /obj/item/clothing/glasses/meson(src)
	new /obj/item/weapon/survivalcapsule(src)

/**********************Shuttle Computer**************************/

/obj/machinery/computer/shuttle/mining
	name = "Mining Shuttle Console"
	desc = "Used to call and send the mining shuttle."
	circuit = /obj/item/weapon/circuitboard/mining_shuttle
	shuttleId = "mining"
	possible_destinations = "mining_home;mining_away"
	no_destination_swap = 1

/*********************Pickaxe & Drills**************************/

/obj/item/weapon/pickaxe
	name = "pickaxe"
	icon = 'icons/obj/mining.dmi'
	icon_state = "pickaxe"
	flags = CONDUCT
	slot_flags = SLOT_BELT
	force = 15
	throwforce = 10
	item_state = "pickaxe"
	w_class = 4
	materials = list(MAT_METAL=2000) //one sheet, but where can you make them?
	var/digspeed = 40
	var/list/digsound = list('sound/effects/picaxe1.ogg','sound/effects/picaxe2.ogg','sound/effects/picaxe3.ogg')
	origin_tech = "materials=1;engineering=1"
	attack_verb = list("hit", "pierced", "sliced", "attacked")

/obj/item/weapon/pickaxe/proc/playDigSound()
	playsound(src, pick(digsound),50,1)

/obj/item/weapon/pickaxe/silver
	name = "silver-plated pickaxe"
	icon_state = "spickaxe"
	item_state = "spickaxe"
	digspeed = 20 //mines faster than a normal pickaxe, bought from mining vendor
	origin_tech = "materials=3;engineering=2"
	desc = "A silver-plated pickaxe that mines slightly faster than standard-issue."
	force = 17

/obj/item/weapon/pickaxe/diamond
	name = "diamond-tipped pickaxe"
	icon_state = "dpickaxe"
	item_state = "dpickaxe"
	digspeed = 14
	origin_tech = "materials=4;engineering=3"
	desc = "A pickaxe with a diamond pick head. Extremely robust at cracking rock walls and digging up dirt."
	force = 19

/obj/item/weapon/pickaxe/drill
	name = "mining drill"
	icon_state = "handdrill"
	item_state = "jackhammer"
	digspeed = 25 //available from roundstart, faster than a pickaxe.
	digsound = list('sound/weapons/drill.ogg')
	hitsound = 'sound/weapons/drill.ogg'
	origin_tech = "materials=2;powerstorage=3;engineering=2"
	desc = "An electric mining drill for the especially scrawny."

/obj/item/weapon/pickaxe/drill/cyborg
	name = "cyborg mining drill"
	desc = "An integrated electric mining drill."
	flags = NODROP

/obj/item/weapon/pickaxe/drill/diamonddrill
	name = "diamond-tipped mining drill"
	icon_state = "diamonddrill"
	digspeed = 7
	origin_tech = "materials=6;powerstorage=4;engineering=5"
	desc = "Yours is the drill that will pierce the heavens!"

/obj/item/weapon/pickaxe/drill/cyborg/diamond //This is the BORG version!
	name = "diamond-tipped cyborg mining drill" //To inherit the NODROP flag, and easier to change borg specific drill mechanics.
	icon_state = "diamonddrill"
	digspeed = 7

/obj/item/weapon/pickaxe/drill/jackhammer
	name = "sonic jackhammer"
	icon_state = "jackhammer"
	item_state = "jackhammer"
	digspeed = 5 //the epitome of powertools. extremely fast mining, laughs at puny walls
	origin_tech = "materials=3;powerstorage=2;engineering=2"
	digsound = list('sound/weapons/sonic_jackhammer.ogg')
	hitsound = 'sound/weapons/sonic_jackhammer.ogg'
	desc = "Cracks rocks with sonic blasts, and doubles as a demolition power tool for smashing walls."

/*****************************Shovel********************************/

/obj/item/weapon/shovel
	name = "shovel"
	desc = "A large tool for digging and moving dirt."
	icon = 'icons/obj/mining.dmi'
	icon_state = "shovel"
	flags = CONDUCT
	slot_flags = SLOT_BELT
	force = 8
	var/digspeed = 20
	throwforce = 4
	item_state = "shovel"
	w_class = 3
	materials = list(MAT_METAL=50)
	origin_tech = "materials=1;engineering=1"
	attack_verb = list("bashed", "bludgeoned", "thrashed", "whacked")
	sharpness = IS_SHARP

/obj/item/weapon/shovel/spade
	name = "spade"
	desc = "A small tool for digging and moving dirt."
	icon_state = "spade"
	item_state = "spade"
	force = 5
	throwforce = 7
	w_class = 2

/**********************Mining car (Crate like thing, not the rail car)**************************/

/obj/structure/closet/crate/miningcar
	desc = "A mining car. This one doesn't work on rails, but has to be dragged."
	name = "Mining car (not for rails)"
	icon_state = "miningcar"

/*****************************Survival Pod********************************/

/area/survivalpod
	name = "\improper Emergency Shelter"
	icon_state = "away"
	requires_power = 0
	has_gravity = 1

/obj/item/weapon/survivalcapsule
	name = "bluespace shelter capsule"
	desc = "An emergency shelter stored within a pocket of bluespace."
	icon_state = "capsule"
	icon = 'icons/obj/mining.dmi'
	w_class = 1
	var/used = FALSE

/obj/item/weapon/survivalcapsule/attack_self()
	if(used == FALSE)
		src.loc.visible_message("\The [src] begins to shake. Stand back!")
		used = TRUE
		sleep(50)
		var/turf/T = get_turf(src)
		var/clear = TRUE
		for(var/turf/turf in range(2,T))
			if(istype(turf, /turf/closed) && !istype(turf, /turf/closed/mineral))
				clear = FALSE
				break
			for(var/obj/obj in turf)
				if(obj.density)
					clear = FALSE
					break
		if(!clear)
			src.loc.visible_message("\The [src] doesn't have room to deploy! You need to clear a 5x5 area!")
			used = FALSE
			return
		playsound(get_turf(src), 'sound/effects/phasein.ogg', 100, 1)
		PoolOrNew(/obj/effect/particle_effect/smoke, src.loc)
		if(T.z != ZLEVEL_MINING && T.z != ZLEVEL_LAVALAND)//only report capsules away from the mining/lavaland level
			message_admins("[key_name_admin(usr)] (?) (FLW) activated a bluespace capsule away from the mining level! (JMP)")
			log_admin("[key_name(usr)] activated a bluespace capsule away from the mining level at [T.x], [T.y], [T.z]")
		load()
		qdel(src)

/obj/item/weapon/survivalcapsule/proc/load()
	var/list/blacklist = list(/area/shuttle) //Shuttles move based on area, and we'd like not to break them
	var/turf/start_turf = get_turf(src.loc)
	var/turf/cur_turf
	var/x_size = 5
	var/y_size = 5
	var/list/walltypes = list(/turf/closed/wall/shuttle/survival_pod)
	var/floor_type = /turf/open/floor/pod
	var/room

	//Center the room/spawn it
	start_turf = locate(start_turf.x -2, start_turf.y - 2, start_turf.z)

	room = spawn_room(start_turf, x_size, y_size, walltypes, floor_type, "Emergency Shelter")

	start_turf = get_turf(src.loc)

	//Fill it

	//The door
	cur_turf = locate(start_turf.x, start_turf.y-2, start_turf.z)
	new /obj/machinery/door/airlock/survival_pod(cur_turf)

	//Bed middle right
	cur_turf = locate(start_turf.x+1, start_turf.y, start_turf.z)
	new /obj/structure/bed/pod(cur_turf)
	new /obj/item/weapon/bedsheet/black(cur_turf)

	//Chair bottom right
	cur_turf = locate(start_turf.x+1, start_turf.y-1, start_turf.z)
	new /obj/structure/tubes(cur_turf)
	var/obj/structure/chair/comfy/black/C = new (cur_turf)
	C.dir = 8

	//GPS computer top right
	cur_turf = locate(start_turf.x+1, start_turf.y+1, start_turf.z)
	new /obj/item/device/gps/computer(cur_turf)

	//Donk Pocket Storage Top/middle
	cur_turf = locate(start_turf.x, start_turf.y+1, start_turf.z)
	new /obj/machinery/smartfridge/survival_pod(cur_turf)

	//Table in Bottom Left
	cur_turf = locate(start_turf.x-1, start_turf.y-1, start_turf.z)
	new /obj/structure/table/survival_pod(cur_turf)

	//Sleeper Middle Left
	cur_turf = locate(start_turf.x-1, start_turf.y, start_turf.z)
	new /obj/machinery/sleeper/survival_pod(cur_turf)

	//Fans Top Left
	cur_turf = locate(start_turf.x-1, start_turf.y+1, start_turf.z)
	new /obj/structure/fans(cur_turf)

	//Signs
	cur_turf = locate(start_turf.x-2, start_turf.y, start_turf.z)
	var/obj/structure/sign/mining/survival/S1 = new(cur_turf)
	S1.dir = WEST

	cur_turf = locate(start_turf.x+2, start_turf.y, start_turf.z)
	var/obj/structure/sign/mining/survival/S2 = new(cur_turf)
	S2.dir = EAST

	cur_turf = locate(start_turf.x, start_turf.y+2, start_turf.z)
	var/obj/structure/sign/mining/survival/S3 = new(cur_turf)
	S3.dir = NORTH

	cur_turf = locate(start_turf.x-1, start_turf.y-2, start_turf.z)
	var/obj/structure/sign/mining/survival/S4 = new(cur_turf)
	S4.dir = SOUTH

	cur_turf = locate(start_turf.x+1, start_turf.y-2, start_turf.z)
	new /obj/structure/sign/mining(cur_turf)

	var/area/survivalpod/L = new /area/survivalpod

	var/turf/threshhold = locate(start_turf.x, start_turf.y-2, start_turf.z)
	threshhold.ChangeTurf(/turf/open/floor/pod)
	var/turf/open/floor/pod/doorturf = threshhold
	doorturf.blocks_air = 1 //So the air doesn't leak out
	doorturf.air.parse_gas_string("o2=21;n2=82;TEMP=293.15")
	var/area/ZZ = get_area(threshhold)
	if(!is_type_in_list(ZZ, blacklist))
		L.contents += threshhold
	threshhold.overlays.Cut()

	var/list/turfs = room["floors"]
	for(var/turf/open/floor/A in turfs)
		A.air.parse_gas_string("o2=21;n2=82;TEMP=293.15")
		A.overlays.Cut()
		var/area/Z = get_area(A)
		if(!is_type_in_list(Z, blacklist))
			L.contents += A

//Pod turfs and objects

//Floor
/turf/open/floor/pod
	name = "pod floor"
	icon_state = "podfloor"
	icon_regular_floor = "podfloor"

//Table
/obj/structure/table/survival_pod
	icon = 'icons/obj/lavaland/survival_pod.dmi'
	icon_state = "table"
	smooth = SMOOTH_FALSE

/obj/structure/fans
	icon = 'icons/obj/lavaland/survival_pod.dmi'
	icon_state = "fans"
	name = "environmental regulation system"
	anchored = 1
	density = 1

//Sleeper
/obj/machinery/sleeper/survival_pod
	icon = 'icons/obj/lavaland/survival_pod.dmi'
	icon_state = "sleeper"

/obj/machinery/sleeper/survival_pod/update_icon()
	if(state_open)
		overlays.Cut()
	else
		overlays += "sleeper_cover"

//Computer
/obj/item/device/gps/computer
	name = "pod computer"
	icon_state = "pod_computer"
	icon = 'icons/obj/lavaland/pod_computer.dmi'
	anchored = 1
	density = 1
	pixel_y = -32

/obj/item/device/gps/computer/attack_hand(mob/user)
	attack_self(user)

//Bed
/obj/structure/bed/pod
	icon = 'icons/obj/lavaland/survival_pod.dmi'
	icon_state = "bed"

//Survival Storage Unit
/obj/machinery/smartfridge/survival_pod
	name = "survival pod storage"
	desc = "A heated storage unit."
	icon_state = "bedcomputer"
	icon = 'icons/obj/lavaland/donkvendor.dmi'
	icon_on = "donkvendor"
	icon_off = "donkvendor"
	luminosity = 8
	max_n_of_items = 10
	pixel_y = -4

/obj/machinery/smartfridge/survival_pod/accept_check(obj/item/O)
	if(istype(O, /obj/item))
		return 1
	return 0

/obj/machinery/smartfridge/survival_pod/New()
	..()
	for(var/i in 1 to 5)
		var/obj/item/weapon/reagent_containers/food/snacks/donkpocket/warm/W = new(src)
		load(W)
	if(prob(50))
		var/obj/item/weapon/storage/pill_bottle/dice/D = new(src)
		load(D)
	else
		var/obj/item/device/instrument/guitar/G = new(src)
		load(G)

//Walls

/turf/closed/wall/shuttle/survival_pod
	name = "wall"
	desc = "An easily-compressable wall used for temporary shelter."
	icon = 'icons/turf/walls/survival_pod_walls.dmi'
	icon_state = "smooth"
	walltype = "shuttle"
	smooth = SMOOTH_MORE|SMOOTH_DIAGONAL
	canSmoothWith = list(/turf/closed/wall/shuttle/survival_pod, /obj/machinery/door/airlock, /obj/structure/window/fulltile, /obj/structure/window/reinforced/fulltile, /obj/structure/window/reinforced/tinted/fulltile, /obj/structure/window/shuttle)

//Signs

/obj/structure/sign/mining
	name = "nanotrasen mining corps sign"
	desc = "A sign of relief for weary miners, and a warning for would be competitors to Nanotrasen's mining claims."
	icon = 'icons/turf/walls/survival_pod_walls.dmi'
	icon_state = "ntpod"

/obj/structure/sign/mining/survival
	name = "shelter sign"
	desc = "A high visibility sign designating a safe shelter."
	icon = 'icons/turf/walls/survival_pod_walls.dmi'
	icon_state = "survival"

//Door

/obj/machinery/door/airlock/survival_pod
	name = "airlock"
	icon = 'icons/obj/doors/airlocks/survival/survival.dmi'
	overlays_file = 'icons/obj/doors/airlocks/survival/survival_overlays.dmi'
	opacity = 0
	glass = 1

/obj/structure/tubes
	icon_state = "tubes"
	icon = 'icons/obj/lavaland/survival_pod.dmi'
	name = "tubes"
	anchored = 1
	layer = MOB_LAYER - 0.2
	density = 0


code:
/**********************Mineral deposits**************************/

/turf/closed/mineral //wall piece
	name = "rock"
	icon = 'icons/turf/mining.dmi'
	icon_state = "rock"
	smooth = SMOOTH_MORE|SMOOTH_BORDER
	canSmoothWith = list (/turf/closed/mineral, /turf/closed/wall)
	baseturf = /turf/open/floor/plating/asteroid/airless
	initial_gas_mix = "o2=0;n2=0;TEMP=2.7"
	opacity = 1
	density = 1
	blocks_air = 1
	layer = MOB_LAYER + 0.05
	temperature = TCMB
	var/environment_type = "asteroid"
	var/turf/open/floor/plating/asteroid/turf_type = /turf/open/floor/plating/asteroid/airless
	var/mineralType = null
	var/mineralAmt = 3
	var/spread = 0 //will the seam spread?
	var/spreadChance = 0 //the percentual chance of an ore spreading to the neighbouring tiles
	var/last_act = 0
	var/scan_state = null //Holder for the image we display when we're pinged by a mining scanner

/turf/closed/mineral/New()
	pixel_y = -4
	pixel_x = -4
	icon = 'icons/turf/smoothrocks.dmi'
	..()
	if (mineralType && mineralAmt && spread && spreadChance)
		for(var/dir in cardinal)
			if(prob(spreadChance))
				var/turf/T = get_step(src, dir)
				if(istype(T, /turf/closed/mineral/random))
					Spread(T)

/turf/closed/mineral/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt
	baseturf = /turf/open/floor/plating/asteroid/basalt
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

/turf/closed/mineral/ex_act(severity, target)
	..()
	switch(severity)
		if(3)
			if (prob(75))
				src.gets_drilled(null, 1)
		if(2)
			if (prob(90))
				src.gets_drilled(null, 1)
		if(1)
			src.gets_drilled(null, 1)
	return

/turf/closed/mineral/Spread(turf/T)
	new src.type(T)

/turf/closed/mineral/random
	var/mineralSpawnChanceList = list(
		/turf/closed/mineral/uranium = 5, /turf/closed/mineral/diamond = 1, /turf/closed/mineral/gold = 10,
		/turf/closed/mineral/silver = 12, /turf/closed/mineral/plasma = 20, /turf/closed/mineral/iron = 40,
		/turf/closed/mineral/gibtonite = 4, /turf/open/floor/plating/asteroid/airless/cave = 2, /turf/closed/mineral/bscrystal = 1)
		//Currently, Adamantine won't spawn as it has no uses. -Durandan
	var/mineralChance = 13

/turf/closed/mineral/random/New()
	..()

	if (prob(mineralChance))
		var/path = pickweight(mineralSpawnChanceList)
		var/turf/T = new path(src)

		if(T && istype(T, /turf/closed/mineral))
			var/turf/closed/mineral/M = T
			M.mineralAmt = rand(1, 5)
			M.environment_type = src.environment_type
			M.turf_type = src.turf_type
			M.baseturf = src.baseturf
			src = M
			M.levelupdate()

/turf/closed/mineral/random/high_chance
	icon_state = "rock_highchance"
	mineralChance = 25
	mineralSpawnChanceList = list(
		/turf/closed/mineral/uranium = 35, /turf/closed/mineral/diamond = 30, /turf/closed/mineral/gold = 45,
		/turf/closed/mineral/silver = 50, /turf/closed/mineral/plasma = 50, /turf/closed/mineral/bscrystal = 20)

/turf/closed/mineral/random/high_chance/New()
	icon_state = "rock"
	..()

/turf/closed/mineral/random/low_chance
	icon_state = "rock_lowchance"
	mineralChance = 6
	mineralSpawnChanceList = list(
		/turf/closed/mineral/uranium = 2, /turf/closed/mineral/diamond = 1, /turf/closed/mineral/gold = 4,
		/turf/closed/mineral/silver = 6, /turf/closed/mineral/plasma = 15, /turf/closed/mineral/iron = 40,
		/turf/closed/mineral/gibtonite = 2, /turf/closed/mineral/bscrystal = 1)

/turf/closed/mineral/random/low_chance/New()
	icon_state = "rock"
	..()

/turf/closed/mineral/iron
	mineralType = /obj/item/weapon/ore/iron
	spreadChance = 20
	spread = 1
	scan_state = "rock_Iron"

/turf/closed/mineral/uranium
	mineralType = /obj/item/weapon/ore/uranium
	spreadChance = 5
	spread = 1
	scan_state = "rock_Uranium"

/turf/closed/mineral/diamond
	mineralType = /obj/item/weapon/ore/diamond
	spreadChance = 0
	spread = 1
	scan_state = "rock_Diamond"

/turf/closed/mineral/gold
	mineralType = /obj/item/weapon/ore/gold
	spreadChance = 5
	spread = 1
	scan_state = "rock_Gold"

/turf/closed/mineral/silver
	mineralType = /obj/item/weapon/ore/silver
	spreadChance = 5
	spread = 1
	scan_state = "rock_Silver"

/turf/closed/mineral/plasma
	mineralType = /obj/item/weapon/ore/plasma
	spreadChance = 8
	spread = 1
	scan_state = "rock_Plasma"

/turf/closed/mineral/clown
	mineralType = /obj/item/weapon/ore/bananium
	mineralAmt = 3
	spreadChance = 0
	spread = 0
	scan_state = "rock_Clown"

/turf/closed/mineral/bscrystal
	mineralType = /obj/item/weapon/ore/bluespace_crystal
	mineralAmt = 1
	spreadChance = 0
	spread = 0
	scan_state = "rock_BScrystal"

////////////////////////////////Gibtonite
/turf/closed/mineral/gibtonite
	mineralAmt = 1
	spreadChance = 0
	spread = 0
	scan_state = "rock_Gibtonite"
	var/det_time = 8 //Countdown till explosion, but also rewards the player for how close you were to detonation when you defuse it
	var/stage = 0 //How far into the lifecycle of gibtonite we are, 0 is untouched, 1 is active and attempting to detonate, 2 is benign and ready for extraction
	var/activated_ckey = null //These are to track who triggered the gibtonite deposit for logging purposes
	var/activated_name = null
	var/activated_image = null

/turf/closed/mineral/gibtonite/New()
	det_time = rand(8,10) //So you don't know exactly when the hot potato will explode
	..()

/turf/closed/mineral/gibtonite/attackby(obj/item/I, mob/user, params)
	if(istype(I, /obj/item/device/mining_scanner) || istype(I, /obj/item/device/t_scanner/adv_mining_scanner) && stage == 1)
		user.visible_message("[user] holds [I] to [src]...", "You use [I] to locate where to cut off the chain reaction and attempt to stop it...")
		defuse()
	..()

/turf/closed/mineral/gibtonite/proc/explosive_reaction(mob/user = null, triggered_by_explosion = 0)
	if(stage == 0)
		var/image/I = image('icons/turf/smoothrocks.dmi', loc = src, icon_state = "rock_Gibtonite_active", layer = 4.06)
		overlays += I
		activated_image = I
		name = "gibtonite deposit"
		desc = "An active gibtonite reserve. Run!"
		stage = 1
		visible_message("There was gibtonite inside! It's going to explode!")
		var/turf/bombturf = get_turf(src)
		var/area/A = get_area(bombturf)

		var/notify_admins = 0
		if(z != 5)
			notify_admins = 1
			if(!triggered_by_explosion)
				message_admins("[key_name_admin(user)]? (FLW) has triggered a gibtonite deposit reaction at [A.name] (JMP).")
			else
				message_admins("An explosion has triggered a gibtonite deposit reaction at [A.name] (JMP).")

		if(!triggered_by_explosion)
			log_game("[key_name(user)] has triggered a gibtonite deposit reaction at [A.name] ([A.x], [A.y], [A.z]).")
		else
			log_game("An explosion has triggered a gibtonite deposit reaction at [A.name]([bombturf.x],[bombturf.y],[bombturf.z])")

		countdown(notify_admins)

/turf/closed/mineral/gibtonite/proc/countdown(notify_admins = 0)
	set waitfor = 0
	while(stage == 1 && det_time > 0 && mineralAmt >= 1)
		det_time--
		sleep(5)
	if(stage == 1 && det_time <= 0 && mineralAmt >= 1)
		var/turf/bombturf = get_turf(src)
		mineralAmt = 0
		explosion(bombturf,1,3,5, adminlog = notify_admins)

/turf/closed/mineral/gibtonite/proc/defuse()
	if(stage == 1)
		overlays -= activated_image
		var/image/I = image('icons/turf/smoothrocks.dmi', loc = src, icon_state = "rock_Gibtonite_inactive", layer = 4.06)
		overlays += I
		desc = "An inactive gibtonite reserve. The ore can be extracted."
		stage = 2
		if(det_time < 0)
			det_time = 0
		visible_message("The chain reaction was stopped! The gibtonite had [src.det_time] reactions left till the explosion!")

/turf/closed/mineral/gibtonite/gets_drilled(mob/user, triggered_by_explosion = 0)
	if(stage == 0 && mineralAmt >= 1) //Gibtonite deposit is activated
		playsound(src,'sound/effects/hit_on_shattered_glass.ogg',50,1)
		explosive_reaction(user, triggered_by_explosion)
		return
	if(stage == 1 && mineralAmt >= 1) //Gibtonite deposit goes kaboom
		var/turf/bombturf = get_turf(src)
		mineralAmt = 0
		explosion(bombturf,1,2,5, adminlog = 0)
	if(stage == 2) //Gibtonite deposit is now benign and extractable. Depending on how close you were to it blowing up before defusing, you get better quality ore.
		var/obj/item/weapon/twohanded/required/gibtonite/G = new /obj/item/weapon/twohanded/required/gibtonite/(src)
		if(det_time <= 0)
			G.quality = 3
			G.icon_state = "Gibtonite ore 3"
		if(det_time >= 1 && det_time <= 2)
			G.quality = 2
			G.icon_state = "Gibtonite ore 2"
	ChangeTurf(turf_type)

/turf/closed/mineral/gibtonite/volcanic
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

////////////////////////////////End Gibtonite

/turf/open/floor/plating/asteroid/airless/cave
	var/length = 100
	var/mob_spawn_list = list(/mob/living/simple_animal/hostile/asteroid/goldgrub = 1, /mob/living/simple_animal/hostile/asteroid/goliath = 5, /mob/living/simple_animal/hostile/asteroid/basilisk = 4, /mob/living/simple_animal/hostile/asteroid/hivelord = 3)
	var/sanity = 1
	turf_type = /turf/open/floor/plating/asteroid/airless

/turf/open/floor/plating/asteroid/airless/cave/volcanic
	mob_spawn_list = list(/mob/living/simple_animal/hostile/asteroid/goldgrub = 10, /mob/living/simple_animal/hostile/asteroid/goliath/beast = 50, /mob/living/simple_animal/hostile/asteroid/basilisk/watcher = 40, /mob/living/simple_animal/hostile/asteroid/hivelord/legion = 30,
		/mob/living/simple_animal/hostile/spawner/lavaland = 2, /mob/living/simple_animal/hostile/spawner/lavaland/goliath = 3, /mob/living/simple_animal/hostile/spawner/lavaland/legion = 3)

	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

/turf/open/floor/plating/asteroid/airless/cave/New(loc, length, go_backwards = 1, exclude_dir = -1)
	// If length (arg2) isn't defined, get a random length; otherwise assign our length to the length arg.
	if(!length)
		src.length = rand(25, 50)
	else
		src.length = length

	// Get our directiosn
	var/forward_cave_dir = pick(alldirs - exclude_dir)
	// Get the opposite direction of our facing direction
	var/backward_cave_dir = angle2dir(dir2angle(forward_cave_dir) + 180)

	// Make our tunnels
	make_tunnel(forward_cave_dir)
	if(go_backwards)
		make_tunnel(backward_cave_dir)
	// Kill ourselves by replacing ourselves with a normal floor.
	SpawnFloor(src)
	..()

/turf/open/floor/plating/asteroid/airless/cave/proc/make_tunnel(dir)

	var/turf/closed/mineral/tunnel = src
	var/next_angle = pick(45, -45)

	for(var/i = 0; i < length; i++)
		if(!sanity)
			break

		var/list/L = list(45)
		if(IsOdd(dir2angle(dir))) // We're going at an angle and we want thick angled tunnels.
			L += -45

		// Expand the edges of our tunnel
		for(var/edge_angle in L)
			var/turf/closed/mineral/edge = get_step(tunnel, angle2dir(dir2angle(dir) + edge_angle))
			if(istype(edge))
				SpawnFloor(edge)

		// Move our tunnel forward
		tunnel = get_step(tunnel, dir)

		if(istype(tunnel))
			// Small chance to have forks in our tunnel; otherwise dig our tunnel.
			if(i > 3 && prob(20))
				new src.type(tunnel, rand(10, 15), 0, dir)
			else
				SpawnFloor(tunnel)
		else //if(!istype(tunnel, src.parent)) // We hit space/normal/wall, stop our tunnel.
			break

		// Chance to change our direction left or right.
		if(i > 2 && prob(33))
			// We can't go a full loop though
			next_angle = -next_angle
			dir = angle2dir(dir2angle(dir) + next_angle)

/turf/open/floor/plating/asteroid/airless/cave/proc/SpawnFloor(turf/T)
	for(var/turf/S in range(2,T))
		if(istype(S, /turf/open/space) || istype(S.loc, /area/mine/explored))
			sanity = 0
			break
	if(!sanity)
		return

	SpawnMonster(T)
	new turf_type(T)
/turf/open/floor/plating/asteroid/airless/cave/proc/SpawnMonster(turf/T)
	if(prob(30))
		if(istype(loc, /area/mine/explored))
			return
		for(var/atom/A in urange(12,T))//Lowers chance of mob clumps
			if(istype(A, /mob/living/simple_animal/hostile/asteroid))
				return
		var/randumb = pickweight(mob_spawn_list)
		new randumb(T)
	return

/turf/closed/mineral/attackby(obj/item/weapon/pickaxe/P, mob/user, params)

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

	if (istype(P, /obj/item/weapon/pickaxe))
		var/turf/T = user.loc
		if (!( istype(T, /turf) ))
			return

		if(last_act+P.digspeed > world.time)//prevents message spam
			return
		last_act = world.time
		user << "You start picking..."
		P.playDigSound()

		if(do_after(user,P.digspeed, target = src))
			if(istype(src, /turf/closed/mineral))
				user << "You finish cutting into the rock."
				gets_drilled(user)
				feedback_add_details("pick_used_mining","[P.type]")
	else
		return attack_hand(user)
	return

/turf/closed/mineral/proc/gets_drilled()
	if (mineralType && (src.mineralAmt > 0) && (src.mineralAmt < 11))
		var/i
		for (i=0;i<mineralAmt;i++)
			new mineralType(src)
		feedback_add_details("ore_mined","[mineralType]|[mineralAmt]")
	ChangeTurf(turf_type)
	playsound(src, 'sound/effects/break_stone.ogg', 50, 1) //beautiful destruction
	return

/turf/closed/mineral/attack_animal(mob/living/simple_animal/user)
	if(user.environment_smash >= 2)
		gets_drilled()
	..()

/turf/closed/mineral/attack_alien(mob/living/carbon/alien/M)
	M << "You start digging into the rock..."
	playsound(src, 'sound/effects/break_stone.ogg', 50, 1)
	if(do_after(M,40, target = src))
		M << "You tunnel into the rock."
		gets_drilled(M)

/turf/closed/mineral/Bumped(AM as mob|obj)
	..()
	if(istype(AM,/mob/living/carbon/human))
		var/mob/living/carbon/human/H = AM
		if((istype(H.l_hand,/obj/item/weapon/pickaxe)) && (!H.hand))
			src.attackby(H.l_hand,H)
		else if((istype(H.r_hand,/obj/item/weapon/pickaxe)) && H.hand)
			src.attackby(H.r_hand,H)
		return
	else if(istype(AM,/mob/living/silicon/robot))
		var/mob/living/silicon/robot/R = AM
		if(istype(R.module_active,/obj/item/weapon/pickaxe))
			src.attackby(R.module_active,R)
			return
/*	else if(istype(AM,/obj/mecha))
		var/obj/mecha/M = AM
		if(istype(M.selected,/obj/item/mecha_parts/mecha_equipment/drill))
			src.attackby(M.selected,M)
			return*/
//Aparantly mechs are just TOO COOL to call Bump(), so fuck em (for now)
	else
		return

/**********************Asteroid**************************/

/turf/open/floor/plating/asteroid //floor piece
	name = "asteroid sand"
	baseturf = /turf/open/floor/plating/asteroid
	icon = 'icons/turf/floors.dmi'
	icon_state = "asteroid"
	icon_plating = "asteroid"
	var/environment_type = "asteroid"
	var/turf_type = /turf/open/floor/plating/asteroid //Because caves do whacky shit to revert to normal
	var/dug = 0       //0 = has not yet been dug, 1 = has already been dug
	var/sand_type = /obj/item/weapon/ore/glass

/turf/open/floor/plating/asteroid/airless
	initial_gas_mix = "o2=0.01;n2=0.01;TEMP=2.7"
	turf_type = /turf/open/floor/plating/asteroid/airless

/turf/open/floor/plating/asteroid/basalt
	name = "volcanic floor"
	baseturf = /turf/open/floor/plating/asteroid/basalt
	icon = 'icons/turf/floors.dmi'
	icon_state = "basalt"
	icon_plating = "basalt"
	environment_type = "basalt"
	sand_type = /obj/item/weapon/ore/glass/basalt

/turf/open/floor/plating/asteroid/basalt/lava //lava underneath
	baseturf = /turf/open/floor/plating/lava/smooth

/turf/open/floor/plating/asteroid/basalt/airless
	initial_gas_mix = "o2=0.01;n2=0.01;TEMP=2.7"

/turf/open/floor/plating/asteroid/snow
	name = "snow"
	desc = "Looks cold."
	icon = 'icons/turf/snow.dmi'
	baseturf = /turf/open/floor/plating/asteroid/snow
	icon_state = "snow"
	icon_plating = "snow"
	temperature = 180
	slowdown = 2
	environment_type = "snow"
	sand_type = /obj/item/stack/sheet/mineral/snow

/turf/open/floor/plating/asteroid/snow/airless
	initial_gas_mix = "o2=0.01;n2=0.01;TEMP=2.7"

/turf/open/floor/plating/asteroid/snow/temperatre
	temperature = 255.37

/turf/open/floor/plating/asteroid/New()
	var/proper_name = name
	..()
	name = proper_name
	if(prob(20))
		icon_state = "[environment_type][rand(0,12)]"

/turf/open/floor/plating/asteroid/burn_tile()
	return

/turf/open/floor/plating/asteroid/ex_act(severity, target)
	contents_explosion(severity, target)
	switch(severity)
		if(3)
			return
		if(2)
			if (prob(20))
				src.gets_dug()
		if(1)
			src.gets_dug()
	return

/turf/open/floor/plating/asteroid/attackby(obj/item/weapon/W, mob/user, params)
	//note that this proc does not call ..()
	if(!W || !user)
		return 0
	var/digging_speed = 0
	if (istype(W, /obj/item/weapon/shovel))
		var/obj/item/weapon/shovel/S = W
		digging_speed = S.digspeed
	else if (istype(W, /obj/item/weapon/pickaxe))
		var/obj/item/weapon/pickaxe/P = W
		digging_speed = P.digspeed
	if (digging_speed)
		var/turf/T = user.loc
		if (!( istype(T, /turf) ))
			return

		if (dug)
			user << "This area has already been dug!"
			return

		user << "You start digging..."
		playsound(src, 'sound/effects/shovel_dig.ogg', 50, 1)

		if(do_after(user, digging_speed, target = src))
			if(istype(src, /turf/open/floor/plating/asteroid))
				user << "You dig a hole."
				gets_dug()
				feedback_add_details("pick_used_mining","[W.type]")

	if(istype(W,/obj/item/weapon/storage/bag/ore))
		var/obj/item/weapon/storage/bag/ore/S = W
		if(S.collection_mode == 1)
			for(var/obj/item/weapon/ore/O in src.contents)
				O.attackby(W,user)
				return

	if(istype(W, /obj/item/stack/tile))
		var/obj/item/stack/tile/Z = W
		if(!Z.use(1))
			return
		var/turf/open/floor/T = ChangeTurf(Z.turf_type)
		if(istype(Z,/obj/item/stack/tile/light)) //TODO: get rid of this ugly check somehow
			var/obj/item/stack/tile/light/L = Z
			var/turf/open/floor/light/F = T
			F.state = L.state
		playsound(src, 'sound/weapons/Genhit.ogg', 50, 1)

/turf/open/floor/plating/asteroid/proc/gets_dug()
	if(dug)
		return
	for(var/i in 1 to 5)
		new sand_type(src)
	dug = 1
	icon_plating = "[environment_type]_dug"
	icon_state = "[environment_type]_dug"
	slowdown = 0
	return

/turf/open/floor/plating/asteroid/singularity_act()
	return

/turf/open/floor/plating/asteroid/singularity_pull(S, current_size)
	return

//////////////CHASM//////////////////

/turf/open/chasm
	name = "chasm"
	desc = "Watch your step."
	baseturf = /turf/open/chasm
	smooth = SMOOTH_TRUE | SMOOTH_BORDER
	icon = 'icons/turf/floors/Chasms.dmi'
	icon_state = "smooth"
	var/drop_x = 1
	var/drop_y = 1
	var/drop_z = 1

/turf/open/chasm/Entered(atom/movable/AM)
	if(istype(AM, /obj/singularity) || istype(AM, /obj/item/projectile))
		return
	drop(AM)

/turf/open/chasm/proc/drop(atom/movable/AM)
	/*visible_message("[AM] falls into [src]!")
	qdel(AM)*/
	AM.forceMove(locate(drop_x, drop_y, drop_z))
	AM.visible_message("[AM] falls from above!")
	if(istype(AM, /mob/living))
		var/mob/living/L = AM
		L.adjustBruteLoss(30)

/turf/open/chasm/straight_down/New()
	..()
	drop_x = x
	drop_y = y
	if(z+1 <= world.maxz)
		drop_z = z+1

/**********************Lavaland Turfs**************************/

///////Surface. The surface is warm, but survivable without a suit. Internals are required. The floors break to chasms, which drop you into the underground.

/turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"
	baseturf = /turf/open/floor/plating/lava/smooth/lava_land_surface

/turf/open/chasm/straight_down/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"
	baseturf = /turf/open/chasm/straight_down/lava_land_surface

/turf/open/chasm/straight_down/lava_land_surface/drop(atom/movable/AM)
	if(!AM.invisibility)
		visible_message("[AM] falls into [src]!")
		qdel(AM)

/turf/closed/mineral/volcanic/lava_land_surface
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/lava/smooth/lava_land_surface

/turf/closed/mineral/random/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/lava/smooth/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

	mineralChance = 10
	mineralSpawnChanceList = list(
		/turf/closed/mineral/uranium/volcanic = 5, /turf/closed/mineral/diamond/volcanic = 1, /turf/closed/mineral/gold/volcanic = 10,
		/turf/closed/mineral/silver/volcanic = 12, /turf/closed/mineral/plasma/volcanic = 20, /turf/closed/mineral/iron/volcanic = 40,
		/turf/closed/mineral/gibtonite/volcanic = 4, /turf/open/floor/plating/asteroid/airless/cave/volcanic = 1, /turf/closed/mineral/bscrystal/volcanic = 1)

/turf/open/floor/plating/lava/smooth/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"
	baseturf = /turf/open/chasm/straight_down/lava_land_surface

/turf/closed/mineral/gibtonite/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

/turf/closed/mineral/uranium/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

/turf/closed/mineral/diamond/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

/turf/closed/mineral/gold/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

/turf/closed/mineral/silver/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

/turf/closed/mineral/plasma/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

/turf/closed/mineral/iron/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"

/turf/closed/mineral/bscrystal/volcanic
	environment_type = "basalt"
	turf_type = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	baseturf = /turf/open/floor/plating/asteroid/basalt/lava_land_surface
	initial_gas_mix = "o2=14;n2=23;TEMP=300"


code:
/**********************Mint**************************/

/obj/machinery/mineral/mint
	name = "Coin press"
	icon = 'icons/obj/economy.dmi'
	icon_state = "coinpress0"
	density = 1
	anchored = 1
	var/amt_silver = 0 //amount of silver
	var/amt_gold = 0   //amount of gold
	var/amt_diamond = 0
	var/amt_iron = 0
	var/amt_plasma = 0
	var/amt_uranium = 0
	var/amt_clown = 0
	var/amt_adamantine = 0
	var/amt_mythril = 0
	var/newCoins = 0   //how many coins the machine made in it's last load
	var/processing = 0
	var/chosen = "metal" //which material will be used to make coins
	var/coinsToProduce = 10
	speed_process = 1

/obj/machinery/mineral/mint/process()
	var/turf/T = get_step(src,input_dir)
	if(T)
		for(var/obj/item/stack/sheet/O in T)
			if (istype(O, /obj/item/stack/sheet/mineral/gold))
				amt_gold += 100 * O.amount
				O.loc = null
			if (istype(O, /obj/item/stack/sheet/mineral/silver))
				amt_silver += 100 * O.amount
				O.loc = null
			if (istype(O, /obj/item/stack/sheet/mineral/diamond))
				amt_diamond += 100 * O.amount
				O.loc = null
			if (istype(O, /obj/item/stack/sheet/mineral/plasma))
				amt_plasma += 100 * O.amount
				O.loc = null
			if (istype(O, /obj/item/stack/sheet/mineral/uranium))
				amt_uranium += 100 * O.amount
				O.loc = null
			if (istype(O, /obj/item/stack/sheet/metal))
				amt_iron += 100 * O.amount
				O.loc = null
			if (istype(O, /obj/item/stack/sheet/mineral/bananium))
				amt_clown += 100 * O.amount
				O.loc = null
			if (istype(O, /obj/item/stack/sheet/mineral/adamantine))
				amt_adamantine += 100 * O.amount
				O.loc = null //Commented out for now. -Durandan
			return

/obj/machinery/mineral/mint/attack_hand(mob/user) //TODO: Adamantine coins! -Durandan

	var/dat = "Coin Press
"

	dat += text("
Gold inserted: [amt_gold] ")
	if (chosen == "gold")
		dat += text("chosen")
	else
		dat += text("Choose")
	dat += text("
Silver inserted: [amt_silver] ")
	if (chosen == "silver")
		dat += text("chosen")
	else
		dat += text("Choose")
	dat += text("
Iron inserted: [amt_iron] ")
	if (chosen == "metal")
		dat += text("chosen")
	else
		dat += text("Choose")
	dat += text("
Diamond inserted: [amt_diamond] ")
	if (chosen == "diamond")
		dat += text("chosen")
	else
		dat += text("Choose")
	dat += text("
Plasma inserted: [amt_plasma] ")
	if (chosen == "plasma")
		dat += text("chosen")
	else
		dat += text("Choose")
	dat += text("
uranium inserted: [amt_uranium] ")
	if (chosen == "uranium")
		dat += text("chosen")
	else
		dat += text("Choose")
	if(amt_clown > 0)
		dat += text("
Bananium inserted: [amt_clown] ")
		if (chosen == "clown")
			dat += text("chosen")
		else
			dat += text("Choose")
	dat += text("
Adamantine inserted: [amt_adamantine] ")//I don't even know these color codes, so fuck it.
	if (chosen == "adamantine")
		dat += text("chosen")
	else
		dat += text("Choose")

	dat += text("

Will produce [coinsToProduce] [chosen] coins if enough materials are available.
")
	//dat += text("The dial which controls the number of conins to produce seems to be stuck. A technician has already been dispatched to fix this.")
	dat += text("-10 ")
	dat += text("-5 ")
	dat += text("-1 ")
	dat += text("+1 ")
	dat += text("+5 ")
	dat += text("+10 ")

	dat += text("

In total this machine produced [newCoins] coins.")
	dat += text("
Make coins")
	user << browse("[dat]", "window=mint")

/obj/machinery/mineral/mint/Topic(href, href_list)
	if(..())
		return
	usr.set_machine(src)
	src.add_fingerprint(usr)
	if(processing==1)
		usr << "The machine is processing."
		return
	if(href_list["choose"])
		chosen = href_list["choose"]
	if(href_list["chooseAmt"])
		coinsToProduce = Clamp(coinsToProduce + text2num(href_list["chooseAmt"]), 0, 1000)
	if(href_list["makeCoins"])
		var/temp_coins = coinsToProduce
		processing = 1;
		icon_state = "coinpress1"
		switch(chosen)
			if("metal")
				while(amt_iron > 0 && coinsToProduce > 0)
					create_coins(/obj/item/weapon/coin/iron)
					amt_iron -= 20
					coinsToProduce--
					newCoins++
					src.updateUsrDialog()
					sleep(5);
			if("gold")
				while(amt_gold > 0 && coinsToProduce > 0)
					create_coins(/obj/item/weapon/coin/gold)
					amt_gold -= 20
					coinsToProduce--
					newCoins++
					src.updateUsrDialog()
					sleep(5);
			if("silver")
				while(amt_silver > 0 && coinsToProduce > 0)
					create_coins(/obj/item/weapon/coin/silver)
					amt_silver -= 20
					coinsToProduce--
					newCoins++
					src.updateUsrDialog()
					sleep(5);
			if("diamond")
				while(amt_diamond > 0 && coinsToProduce > 0)
					create_coins(/obj/item/weapon/coin/diamond)
					amt_diamond -= 20
					coinsToProduce--
					newCoins++
					src.updateUsrDialog()
					sleep(5);
			if("plasma")
				while(amt_plasma > 0 && coinsToProduce > 0)
					create_coins(/obj/item/weapon/coin/plasma)
					amt_plasma -= 20
					coinsToProduce--
					newCoins++
					src.updateUsrDialog()
					sleep(5);
			if("uranium")
				while(amt_uranium > 0 && coinsToProduce > 0)
					create_coins(/obj/item/weapon/coin/uranium)
					amt_uranium -= 20
					coinsToProduce--
					newCoins++
					src.updateUsrDialog()
					sleep(5)
			if("clown")
				while(amt_clown > 0 && coinsToProduce > 0)
					create_coins(/obj/item/weapon/coin/clown)
					amt_clown -= 20
					coinsToProduce--
					newCoins++
					src.updateUsrDialog()
					sleep(5);
			if("adamantine")
				while(amt_adamantine > 0 && coinsToProduce > 0)
					create_coins(/obj/item/weapon/coin/adamantine)
					amt_adamantine -= 20
					coinsToProduce--
					newCoins++
					src.updateUsrDialog()
					sleep(5);
			if("mythril")
				while(amt_adamantine > 0 && coinsToProduce > 0)
					create_coins(/obj/item/weapon/coin/mythril)
					amt_mythril -= 20
					coinsToProduce--
					newCoins++
					src.updateUsrDialog()
					sleep(5);
		icon_state = "coinpress0"
		processing = 0;
		coinsToProduce = temp_coins
	src.updateUsrDialog()
	return

/obj/machinery/mineral/mint/proc/create_coins(P)
	var/turf/T = get_step(src,output_dir)
	if(T)
		var/obj/item/O = new P(src)
		var/obj/item/weapon/moneybag/M = locate(/obj/item/weapon/moneybag/, T)
		if(!M)
			M = new /obj/item/weapon/moneybag(src)
			unload_mineral(M)
		O.loc = M


code:
/*****************************Money bag********************************/

/obj/item/weapon/moneybag
	icon = 'icons/obj/storage.dmi'
	name = "Money bag"
	icon_state = "moneybag"
	flags = CONDUCT
	force = 10
	throwforce = 0
	w_class = 4
	burn_state = FLAMMABLE
	burntime = 20

/obj/item/weapon/moneybag/attack_hand(mob/user)
	var/amt_gold = 0
	var/amt_silver = 0
	var/amt_diamond = 0
	var/amt_iron = 0
	var/amt_plasma = 0
	var/amt_uranium = 0
	var/amt_clown = 0
	var/amt_adamantine = 0

	for (var/obj/item/weapon/coin/C in contents)
		if (istype(C,/obj/item/weapon/coin/diamond))
			amt_diamond++;
		if (istype(C,/obj/item/weapon/coin/plasma))
			amt_plasma++;
		if (istype(C,/obj/item/weapon/coin/iron))
			amt_iron++;
		if (istype(C,/obj/item/weapon/coin/silver))
			amt_silver++;
		if (istype(C,/obj/item/weapon/coin/gold))
			amt_gold++;
		if (istype(C,/obj/item/weapon/coin/uranium))
			amt_uranium++;
		if (istype(C,/obj/item/weapon/coin/clown))
			amt_clown++;
		if (istype(C,/obj/item/weapon/coin/adamantine))
			amt_adamantine++;

	var/dat = text("The contents of the moneybag reveal...
")
	if (amt_gold)
		dat += text("Gold coins: [amt_gold] Remove one
")
	if (amt_silver)
		dat += text("Silver coins: [amt_silver] Remove one
")
	if (amt_iron)
		dat += text("Metal coins: [amt_iron] Remove one
")
	if (amt_diamond)
		dat += text("Diamond coins: [amt_diamond] Remove one
")
	if (amt_plasma)
		dat += text("Plasma coins: [amt_plasma] Remove one
")
	if (amt_uranium)
		dat += text("Uranium coins: [amt_uranium] Remove one
")
	if (amt_clown)
		dat += text("Bananium coins: [amt_clown] Remove one
")
	if (amt_adamantine)
		dat += text("Adamantine coins: [amt_adamantine] Remove one
")
	user << browse("[dat]", "window=moneybag")

/obj/item/weapon/moneybag/attackby(obj/item/weapon/W, mob/user, params)
	..()
	if (istype(W, /obj/item/weapon/coin))
		var/obj/item/weapon/coin/C = W
		if(!user.drop_item())
			return
		user << "You add the [C.name] into the bag."
		contents += C
	if (istype(W, /obj/item/weapon/moneybag))
		var/obj/item/weapon/moneybag/C = W
		for (var/obj/O in C.contents)
			contents += O;
		user << "You empty the [C.name] into the bag."
	return

/obj/item/weapon/moneybag/Topic(href, href_list)
	if(..())
		return
	usr.set_machine(src)
	src.add_fingerprint(usr)
	if(href_list["remove"])
		var/obj/item/weapon/coin/COIN
		switch(href_list["remove"])
			if("gold")
				COIN = locate(/obj/item/weapon/coin/gold,src.contents)
			if("silver")
				COIN = locate(/obj/item/weapon/coin/silver,src.contents)
			if("iron")
				COIN = locate(/obj/item/weapon/coin/iron,src.contents)
			if("diamond")
				COIN = locate(/obj/item/weapon/coin/diamond,src.contents)
			if("plasma")
				COIN = locate(/obj/item/weapon/coin/plasma,src.contents)
			if("uranium")
				COIN = locate(/obj/item/weapon/coin/uranium,src.contents)
			if("clown")
				COIN = locate(/obj/item/weapon/coin/clown,src.contents)
			if("adamantine")
				COIN = locate(/obj/item/weapon/coin/adamantine,src.contents)
		if(!COIN)
			return
		COIN.loc = src.loc
	return

/obj/item/weapon/moneybag/vault

/obj/item/weapon/moneybag/vault/New()
	..()
	new /obj/item/weapon/coin/silver(src)
	new /obj/item/weapon/coin/silver(src)
	new /obj/item/weapon/coin/silver(src)
	new /obj/item/weapon/coin/silver(src)
	new /obj/item/weapon/coin/gold(src)
	new /obj/item/weapon/coin/gold(src)
	new /obj/item/weapon/coin/adamantine(src)


code:
/**********************Mineral ores**************************/

/obj/item/weapon/ore
	name = "rock"
	icon = 'icons/obj/mining.dmi'
	icon_state = "ore"
	var/points = 0 //How many points this ore gets you from the ore redemption machine
	var/refined_type = null //What this ore defaults to being refined into

/obj/item/weapon/ore/attackby(obj/item/I, mob/user, params)
	if(istype(I, /obj/item/weapon/weldingtool))
		var/obj/item/weapon/weldingtool/W = I
		if(W.remove_fuel(15) && refined_type)
			new refined_type(get_turf(src.loc))
			qdel(src)
		else if(W.isOn())
			user << "Not enough fuel to smelt [src]."
	..()

/obj/item/weapon/ore/uranium
	name = "uranium ore"
	icon_state = "Uranium ore"
	origin_tech = "materials=5"
	points = 30
	materials = list(MAT_URANIUM=MINERAL_MATERIAL_AMOUNT)
	refined_type = /obj/item/stack/sheet/mineral/uranium

/obj/item/weapon/ore/iron
	name = "iron ore"
	icon_state = "Iron ore"
	origin_tech = "materials=1"
	points = 1
	materials = list(MAT_METAL=MINERAL_MATERIAL_AMOUNT)
	refined_type = /obj/item/stack/sheet/metal

/obj/item/weapon/ore/glass
	name = "sand pile"
	icon_state = "Glass ore"
	origin_tech = "materials=1"
	points = 1
	materials = list(MAT_GLASS=MINERAL_MATERIAL_AMOUNT)
	refined_type = /obj/item/stack/sheet/glass
	w_class = 1

/obj/item/weapon/ore/glass/attack_self(mob/living/user)
	user << "You use the sand to make sandstone."
	var/sandAmt = 1
	for(var/obj/item/weapon/ore/glass/G in user.loc) // The sand on the floor
		sandAmt += 1
		qdel(G)
	while(sandAmt > 0)
		var/obj/item/stack/sheet/mineral/sandstone/SS = new /obj/item/stack/sheet/mineral/sandstone(user.loc)
		if(sandAmt >= SS.max_amount)
			SS.amount = SS.max_amount
		else
			SS.amount = sandAmt
			for(var/obj/item/stack/sheet/mineral/sandstone/SA in user.loc)
				if(SA != SS && SA.amount < SA.max_amount)
					SA.attackby(SS, user) //we try to transfer all old unfinished stacks to the new stack we created.
		sandAmt -= SS.max_amount
	qdel(src)
	return

/obj/item/weapon/ore/glass/throw_impact(atom/hit_atom)
	if(..() || !ishuman(hit_atom))
		return
	var/mob/living/carbon/human/C = hit_atom
	if(C.head && C.head.flags_cover & HEADCOVERSEYES)
		visible_message("[C]'s headgear blocks the sand!")
		return
	if(C.wear_mask && C.wear_mask.flags_cover & MASKCOVERSEYES)
		visible_message("[C]'s mask blocks the sand!")
		return
	if(C.glasses && C.glasses.flags_cover & GLASSESCOVERSEYES)
		visible_message("[C]'s glasses block the sand!")
		return
	C.adjust_blurriness(6)
	C.adjustStaminaLoss(15)//the pain from your eyes burning does stamina damage
	C.confused += 5
	C << "\The [src] gets into your eyes! The pain, it burns!"
	qdel(src)

/obj/item/weapon/ore/glass/basalt
	name = "volcanic ash"
	icon_state = "volcanic_sand"

/obj/item/weapon/ore/plasma
	name = "plasma ore"
	icon_state = "Plasma ore"
	origin_tech = "plasmatech=2;materials=2"
	points = 15
	materials = list(MAT_PLASMA=MINERAL_MATERIAL_AMOUNT)
	refined_type = /obj/item/stack/sheet/mineral/plasma

/obj/item/weapon/ore/plasma/attackby(obj/item/I, mob/user, params)
	if(istype(I, /obj/item/weapon/weldingtool))
		var/obj/item/weapon/weldingtool/W = I
		if(W.welding)
			user << "You can't hit a high enough temperature to smelt [src] properly!"
	else
		..()

/obj/item/weapon/ore/silver
	name = "silver ore"
	icon_state = "Silver ore"
	origin_tech = "materials=3"
	points = 16
	materials = list(MAT_SILVER=MINERAL_MATERIAL_AMOUNT)
	refined_type = /obj/item/stack/sheet/mineral/silver

/obj/item/weapon/ore/gold
	name = "gold ore"
	icon_state = "Gold ore"
	origin_tech = "materials=4"
	points = 18
	materials = list(MAT_GOLD=MINERAL_MATERIAL_AMOUNT)
	refined_type = /obj/item/stack/sheet/mineral/gold

/obj/item/weapon/ore/diamond
	name = "diamond ore"
	icon_state = "Diamond ore"
	origin_tech = "materials=6"
	points = 50
	materials = list(MAT_DIAMOND=MINERAL_MATERIAL_AMOUNT)
	refined_type = /obj/item/stack/sheet/mineral/diamond

/obj/item/weapon/ore/bananium
	name = "bananium ore"
	icon_state = "Clown ore"
	origin_tech = "materials=4"
	points = 60
	materials = list(MAT_BANANIUM=MINERAL_MATERIAL_AMOUNT)
	refined_type = /obj/item/stack/sheet/mineral/bananium

/obj/item/weapon/ore/slag
	name = "slag"
	desc = "Completely useless"
	icon_state = "slag"

/obj/item/weapon/twohanded/required/gibtonite
	name = "gibtonite ore"
	desc = "Extremely explosive if struck with mining equipment, Gibtonite is often used by miners to speed up their work by using it as a mining charge. This material is illegal to possess by unauthorized personnel under space law."
	icon = 'icons/obj/mining.dmi'
	icon_state = "Gibtonite ore"
	item_state = "Gibtonite ore"
	w_class = 4
	throw_range = 0
	var/primed = 0
	var/det_time = 100
	var/quality = 1 //How pure this gibtonite is, determines the explosion produced by it and is derived from the det_time of the rock wall it was taken from, higher value = better
	var/attacher = "UNKNOWN"

/obj/item/weapon/twohanded/required/gibtonite/Destroy()
	qdel(wires)
	wires = null
	return ..()

/obj/item/weapon/twohanded/required/gibtonite/attackby(obj/item/I, mob/user, params)
	if(!wires && istype(I, /obj/item/device/assembly/igniter))
		user.visible_message("[user] attaches [I] to [src].", "You attach [I] to [src].")
		wires = new /datum/wires/explosive/gibtonite(src)
		attacher = key_name(user)
		qdel(I)
		overlays += "Gibtonite_igniter"
		return

	if(wires && !primed)
		if(is_wire_tool(I))
			wires.interact(user)
			return

	if(istype(I, /obj/item/weapon/pickaxe) || istype(I, /obj/item/weapon/resonator) || I.force >= 10)
		GibtoniteReaction(user)
		return
	if(primed)
		if(istype(I, /obj/item/device/mining_scanner) || istype(I, /obj/item/device/t_scanner/adv_mining_scanner) || istype(I, /obj/item/device/multitool))
			primed = 0
			user.visible_message("The chain reaction was stopped! ...The ore's quality looks diminished.", "You stopped the chain reaction. ...The ore's quality looks diminished.")
			icon_state = "Gibtonite ore"
			quality = 1
			return
	..()

/obj/item/weapon/twohanded/required/gibtonite/attack_self(user)
	if(wires)
		wires.interact(user)
	else
		..()

/obj/item/weapon/twohanded/required/gibtonite/bullet_act(obj/item/projectile/P)
	GibtoniteReaction(P.firer)
	..()

/obj/item/weapon/twohanded/required/gibtonite/ex_act()
	GibtoniteReaction(null, 1)

/obj/item/weapon/twohanded/required/gibtonite/proc/GibtoniteReaction(mob/user, triggered_by = 0)
	if(!primed)
		playsound(src,'sound/effects/hit_on_shattered_glass.ogg',50,1)
		primed = 1
		icon_state = "Gibtonite active"
		var/turf/bombturf = get_turf(src)
		var/area/A = get_area(bombturf)
		var/notify_admins = 0
		if(z != 5)//Only annoy the admins ingame if we're triggered off the mining zlevel
			notify_admins = 1

		if(notify_admins)
			if(triggered_by == 1)
				message_admins("An explosion has triggered a [name] to detonate at [A.name] (JMP).")
			else if(triggered_by == 2)
				message_admins("A signal has triggered a [name] to detonate at [A.name] (JMP). Igniter attacher: [key_name_admin(attacher)]? (FLW)")
			else
				message_admins("[key_name_admin(user)]? (FLW) has triggered a [name] to detonate at [A.name] (JMP).")
		if(triggered_by == 1)
			log_game("An explosion has primed a [name] for detonation at [A.name]([bombturf.x],[bombturf.y],[bombturf.z])")
		else if(triggered_by == 2)
			log_game("A signal has primed a [name] for detonation at [A.name]([bombturf.x],[bombturf.y],[bombturf.z]). Igniter attacher: [key_name(attacher)].")
		else
			user.visible_message("[user] strikes \the [src], causing a chain reaction!", "You strike \the [src], causing a chain reaction.")
			log_game("[key_name(user)] has primed a [name] for detonation at [A.name]([bombturf.x],[bombturf.y],[bombturf.z])")
		spawn(det_time)
		if(primed)
			if(quality == 3)
				explosion(src.loc,2,4,9,adminlog = notify_admins)
			if(quality == 2)
				explosion(src.loc,1,2,5,adminlog = notify_admins)
			if(quality == 1)
				explosion(src.loc,-1,1,3,adminlog = notify_admins)
			qdel(src)

/obj/item/weapon/ore/New()
	pixel_x = rand(0,16)-8
	pixel_y = rand(0,8)-8

/obj/item/weapon/ore/ex_act()
	return

/*****************************Coin********************************/

/obj/item/weapon/coin
	icon = 'icons/obj/economy.dmi'
	name = "coin"
	icon_state = "coin__heads"
	flags = CONDUCT
	force = 1
	throwforce = 2
	w_class = 1
	var/string_attached
	var/list/sideslist = list("heads","tails")
	var/cmineral = null
	var/cooldown = 0
	var/value = 10

/obj/item/weapon/coin/New()
	pixel_x = rand(0,16)-8
	pixel_y = rand(0,8)-8

	icon_state = "coin_[cmineral]_heads"
	if(cmineral)
		name = "[cmineral] coin"

/obj/item/weapon/coin/gold
	cmineral = "gold"
	icon_state = "coin_gold_heads"
	value = 160
	materials = list(MAT_GOLD = 400)

/obj/item/weapon/coin/silver
	cmineral = "silver"
	icon_state = "coin_silver_heads"
	value = 40
	materials = list(MAT_SILVER = 400)

/obj/item/weapon/coin/diamond
	cmineral = "diamond"
	icon_state = "coin_diamond_heads"
	value = 120
	materials = list(MAT_DIAMOND = 400)

/obj/item/weapon/coin/iron
	cmineral = "iron"
	icon_state = "coin_iron_heads"
	value = 20
	materials = list(MAT_METAL = 400)

/obj/item/weapon/coin/plasma
	cmineral = "plasma"
	icon_state = "coin_plasma_heads"
	value = 80
	materials = list(MAT_PLASMA = 400)

/obj/item/weapon/coin/uranium
	cmineral = "uranium"
	icon_state = "coin_uranium_heads"
	value = 160
	materials = list(MAT_URANIUM = 400)

/obj/item/weapon/coin/clown
	cmineral = "bananium"
	icon_state = "coin_bananium_heads"
	value = 600 //makes the clown cri
	materials = list(MAT_BANANIUM = 400)

/obj/item/weapon/coin/adamantine
	cmineral = "adamantine"
	icon_state = "coin_adamantine_heads"
	value = 400

/obj/item/weapon/coin/mythril
	cmineral = "mythril"
	icon_state = "coin_mythril_heads"
	value = 400

/obj/item/weapon/coin/twoheaded
	cmineral = "iron"
	icon_state = "coin_iron_heads"
	desc = "Hey, this coin's the same on both sides!"
	sideslist = list("heads")
	value = 20

/obj/item/weapon/coin/antagtoken
	name = "antag token"
	icon_state = "coin_valid_valid"
	cmineral = "valid"
	desc = "A novelty coin that helps the heart know what hard evidence cannot prove."
	sideslist = list("valid", "salad")
	value = 20

/obj/item/weapon/coin/antagtoken/New()
	return

/obj/item/weapon/coin/attackby(obj/item/weapon/W, mob/user, params)
	if(istype(W, /obj/item/stack/cable_coil))
		var/obj/item/stack/cable_coil/CC = W
		if(string_attached)
			user << "There already is a string attached to this coin!"
			return

		if (CC.use(1))
			overlays += image('icons/obj/economy.dmi',"coin_string_overlay")
			string_attached = 1
			user << "You attach a string to the coin."
		else
			user << "You need one length of cable to attach a string to the coin!"
			return

	else if(istype(W,/obj/item/weapon/wirecutters))
		if(!string_attached)
			..()
			return

		var/obj/item/stack/cable_coil/CC = new/obj/item/stack/cable_coil(user.loc)
		CC.amount = 1
		CC.update_icon()
		overlays = list()
		string_attached = null
		user << "You detach the string from the coin."
	else ..()

/obj/item/weapon/coin/attack_self(mob/user)
	if(cooldown < world.time - 15)
		if(string_attached) //does the coin have a wire attached
			user << "The coin won't flip very well with something attached!" //Tell user it will not flip
			return //do not flip the coin
		var/coinflip = pick(sideslist)
		cooldown = world.time
		flick("coin_[cmineral]_flip", src)
		icon_state = "coin_[cmineral]_[coinflip]"
		playsound(user.loc, 'sound/items/coinflip.ogg', 50, 1)
		var/oldloc = loc
		sleep(15)
		if(loc == oldloc && user && !user.incapacitated())
			user.visible_message("[user] has flipped [src]. It lands on [coinflip].", \
 							 "You flip [src]. It lands on [coinflip].", \
							 "You hear the clattering of loose change.")


code:
/**********************Ore box**************************/

/obj/structure/ore_box
	icon = 'icons/obj/mining.dmi'
	icon_state = "orebox"
	name = "ore box"
	desc = "A heavy wooden box, which can be filled with a lot of ores."
	density = 1
	pressure_resistance = 5*ONE_ATMOSPHERE

/obj/structure/ore_box/attackby(obj/item/weapon/W as obj, mob/user as mob, params)
	if (istype(W, /obj/item/weapon/ore))
		if(!user.drop_item())
			return
		W.loc = src
	if (istype(W, /obj/item/weapon/storage))
		var/obj/item/weapon/storage/S = W
		S.hide_from(usr)
		for(var/obj/item/weapon/ore/O in S.contents)
			S.remove_from_storage(O, src) //This will move the item to this item's contents
		user << "You empty the satchel into the box."
	return

/obj/structure/ore_box/attack_hand(mob/user)
	var/amt_gold = 0
	var/amt_silver = 0
	var/amt_diamond = 0
	var/amt_glass = 0
	var/amt_iron = 0
	var/amt_plasma = 0
	var/amt_uranium = 0
	var/amt_clown = 0
	var/amt_bluespace = 0

	for (var/obj/item/weapon/ore/C in contents)
		if (istype(C,/obj/item/weapon/ore/diamond))
			amt_diamond++;
		if (istype(C,/obj/item/weapon/ore/glass))
			amt_glass++;
		if (istype(C,/obj/item/weapon/ore/plasma))
			amt_plasma++;
		if (istype(C,/obj/item/weapon/ore/iron))
			amt_iron++;
		if (istype(C,/obj/item/weapon/ore/silver))
			amt_silver++;
		if (istype(C,/obj/item/weapon/ore/gold))
			amt_gold++;
		if (istype(C,/obj/item/weapon/ore/uranium))
			amt_uranium++;
		if (istype(C,/obj/item/weapon/ore/bananium))
			amt_clown++;
		if (istype(C,/obj/item/weapon/ore/bluespace_crystal))
			amt_bluespace++

	var/dat = text("The contents of the ore box reveal...
")
	if (amt_gold)
		dat += text("Gold ore: [amt_gold]
")
	if (amt_silver)
		dat += text("Silver ore: [amt_silver]
")
	if (amt_iron)
		dat += text("Metal ore: [amt_iron]
")
	if (amt_glass)
		dat += text("Sand: [amt_glass]
")
	if (amt_diamond)
		dat += text("Diamond ore: [amt_diamond]
")
	if (amt_plasma)
		dat += text("Plasma ore: [amt_plasma]
")
	if (amt_uranium)
		dat += text("Uranium ore: [amt_uranium]
")
	if (amt_clown)
		dat += text("Bananium ore: [amt_clown]
")
	if (amt_bluespace)
		dat += text("Bluespace crystals: [amt_bluespace]
")

	dat += text("

Empty box")
	user << browse("[dat]", "window=orebox")
	return

/obj/structure/ore_box/Topic(href, href_list)
	if(..())
		return
	usr.set_machine(src)
	src.add_fingerprint(usr)
	if(href_list["removeall"])
		for (var/obj/item/weapon/ore/O in contents)
			contents -= O
			O.loc = src.loc
		usr << "You empty the box."
	src.updateUsrDialog()
	return

obj/structure/ore_box/ex_act(severity, target)
	if(prob(100 / severity) && severity < 3)
		qdel(src) //nothing but ores can get inside unless its a bug and ores just return nothing on ex_act, not point in calling it on them


code:
// Camera mob, used by AI camera and blob.

/mob/camera
	name = "camera mob"
	density = 0
	anchored = 1
	status_flags = GODMODE  // You can't damage it.
	mouse_opacity = 0
	see_in_dark = 7
	invisibility = 101 // No one can see us
	sight = SEE_SELF
	move_on_shuttle = 0

/mob/camera/experience_pressure_difference()
	return


code:
/mob/dead/dust()	//ghosts can't be vaporised.
	return

/mob/dead/gib(animation = 1)		//ghosts can't be gibbed.
	return


code:
/mob/dead/observer/Login()
	..()

	ghost_accs = client.prefs.ghost_accs
	ghost_others = client.prefs.ghost_others
	var/preferred_form = null

	if(check_rights(R_ADMIN, 0))
		has_unlimited_silicon_privilege = 1

	if(client.prefs.unlock_content)
		preferred_form = client.prefs.ghost_form
		ghost_orbit = client.prefs.ghost_orbit

	update_icon(preferred_form)
	updateghostimages()


code:
/mob/dead/observer/Logout()
	if (client)
		client.images -= ghost_darkness_images
	..()
	spawn(0)
		if(src && !key)	//we've transferred to another mob. This ghost should be deleted.
			qdel(src)