code:
var/list/sacrificed = list()
// Sets number of cultists required for various runes, default values below are for 20+ player rounds
var/CONVERT_CULTS = 3
var/ELDERGOD_CULTS = 9
var/SACRIFICE_CULTS = 3
var/ITEMPORT_CULTS = 1
var/FREEDOM_CULTS = 1
var/CULTSUMMON_CULTS = 3
var/BLOODBOIL_CULTS = 3
var/BURNINGBLOOD_CULTS = 5

proc/set_runecults( setELDERGOD_CULTS = null, setCONVERT_CULTS = null, setSACRIFICE_CULTS = null, setITEMPORT_CULTS = null, setFREEDOM_CULTS = null, setCULTSUMMON_CULTS = null, setBLOODBOIL_CULTS = null, setBURNINGBLOOD_CULTS = null ) //Convenience Method for setting number of cultists required for runes, automatically updates tome
	if(setELDERGOD_CULTS)
		ELDERGOD_CULTS = setELDERGOD_CULTS
	if(setCONVERT_CULTS)
		CONVERT_CULTS = setCONVERT_CULTS
	if(setSACRIFICE_CULTS)
		SACRIFICE_CULTS = setSACRIFICE_CULTS
	if(setITEMPORT_CULTS)
		ITEMPORT_CULTS = setITEMPORT_CULTS
	if(setFREEDOM_CULTS)
		FREEDOM_CULTS = setFREEDOM_CULTS
	if(setCULTSUMMON_CULTS)
		CULTSUMMON_CULTS = setCULTSUMMON_CULTS
	if(setBLOODBOIL_CULTS)
		BLOODBOIL_CULTS = setBLOODBOIL_CULTS
	if(setBURNINGBLOOD_CULTS)
		BURNINGBLOOD_CULTS = setBURNINGBLOOD_CULTS
	update_tome()

/obj/effect/rune
/////////////////////////////////////////FIRST RUNE
/obj/effect/rune/proc/teleport(var/key)
	var/mob/living/user = usr
	var/allrunesloc[]
	allrunesloc = new/list()
	var/index = 0
	//	var/tempnum = 0
	for(var/obj/effect/rune/R in world)
		if(R == src)
			continue
		if(R.word1 == wordtravel && R.word2 == wordself && R.word3 == key && R.z != ZLEVEL_CENTCOM)
			index++
			allrunesloc.len = index
			allrunesloc[index] = R.loc
	if(index >= 5)
		user << "You feel pain, as rune disappears in reality shift caused by too much wear of space-time fabric"
		if (istype(user, /mob/living))
			user.take_overall_damage(5, 0)
		qdel(src)
	if(allrunesloc && index != 0)
		if(istype(src,/obj/effect/rune))
			user.say("Sas[pick("'","`")]so c'arta forbici!")//Only you can stop auto-muting
		else
			user.whisper("Sas[pick("'","`")]so c'arta forbici!")
		user.visible_message("[user] disappears in a flash of red light!", \
		"You feel as your body gets dragged through the dimension of Nar-Sie!", \
		"You hear a sickening crunch and sloshing of viscera.")
		user.loc = allrunesloc[rand(1,index)]
		return
	if(istype(src,/obj/effect/rune))
		return fizzle(user) //Use friggin manuals, Dorf, your list was of zero length.
	else
		call(/obj/effect/rune/proc/fizzle)()
		return

/obj/effect/rune/proc/itemport(var/key)
//	var/allrunesloc[]
//	allrunesloc = new/list()
//	var/index = 0
//	var/tempnum = 0
	var/culcount = 0
	var/runecount = 0
	var/obj/effect/rune/IP = null
	var/mob/living/user = usr
	for(var/obj/effect/rune/R in world)
		if(R == src)
			continue
		if(R.word1 == wordtravel && R.word2 == wordother && R.word3 == key)
			IP = R
			runecount++
	if(runecount >= 2)
		user << "You feel pain, as the rune disappears in reality shift caused by too much wear of space-time fabric"
		if (istype(user, /mob/living))
			user.take_overall_damage(5, 0)
		qdel(src)
	for(var/mob/living/C in orange(1,src))
		if(iscultist(C) && !C.stat)
			culcount++
	if(user.loc==src.loc)
		return fizzle(user)
	if(culcount>=ITEMPORT_CULTS)
		user.say("Sas[pick("'","`")]so c'arta forbici tarem!")
		user.visible_message("You feel air moving from the rune - like as it was swapped with somewhere else.", \
		"You feel air moving from the rune - like as it was swapped with somewhere else.", \
		"You smell ozone.")
		for(var/obj/O in src.loc)
			if(!O.anchored)
				O.loc = IP.loc
		for(var/mob/M in src.loc)
			M.loc = IP.loc
		return

	return fizzle(user)

/////////////////////////////////////////SECOND RUNE

/obj/effect/rune/proc/tomesummon()
	if(istype(src,/obj/effect/rune))
		usr.say("N[pick("'","`")]ath reth sh'yro eth d'raggathnor!")
	else
		usr.whisper("N[pick("'","`")]ath reth sh'yro eth d'raggathnor!")
	usr.visible_message("Rune disappears with a flash of red light, and in its place now a book lies.", \
	"You are blinded by the flash of red light! After you're able to see again, you see that now instead of the rune there's a book.", \
	"You hear a pop and smell ozone.")
	if(istype(src,/obj/effect/rune))
		new /obj/item/weapon/tome(src.loc)
	else
		new /obj/item/weapon/tome(usr.loc)
	qdel(src)
	return

/////////////////////////////////////////THIRD RUNE

/obj/effect/rune/proc/convert()
	var/list/mob/living/cultsinrange = list()
	for(var/mob/living/carbon/M in src.loc)
		if(iscultist(M))
			continue
		if(M.stat==2)
			continue
		for(var/mob/living/C in orange(1,src))
			if(iscultist(C) && !C.stat)		//converting requires three cultists
				cultsinrange += C
				C.say("Mah[pick("'","`")]weyh pleggh at e'ntrath!")
		if(cultsinrange.len >= CONVERT_CULTS)
			M.visible_message("[M] writhes in pain as the markings below him glow a bloody red.", \
			"AAAAAAHHHH!", \
			"You hear an anguished scream.")
			if(is_convertable_to_cult(M.mind))
				ticker.mode.add_cultist(M.mind)
				M.mind.special_role = "Cultist"
				M << "Your blood pulses. Your head throbs. The world goes red. All at once you are aware of a horrible, horrible truth. The veil of reality has been ripped away and in the festering wound left behind something sinister takes root."
				M << "Assist your new compatriots in their dark dealings. Their goal is yours, and yours is theirs. You serve the Dark One above all else. Bring It back."
/*//convert no longer gives words
				//picking which word to use
				if(usr.mind.cult_words.len != ticker.mode.allwords.len) // No point running if they already know everything
					var/convert_word
					for(var/i=1, i<=3, i++)
						convert_word = pick(ticker.mode.grantwords)
						if(convert_word in usr.mind.cult_words)
							if(i==3) convert_word = null				//NOTE: If max loops is changed ensure this condition is changed to match /Mal
						else
							break
					if(!convert_word)
						usr << "\red This Convert was unworthy of knowledge of the other side!"
					else
						usr << "\red The Geometer of Blood is pleased to see his followers grow in numbers."
						ticker.mode.grant_runeword(usr, convert_word)
					return 1		*/
			else
				M << "Your blood pulses. Your head throbs. The world goes red. All at once you are aware of a horrible, horrible truth. The veil of reality has been ripped away and in the festering wound left behind something sinister takes root."
				M << "And not a single fuck was given, exterminate the cult at all costs."
				if(ticker.mode.name == "cult")
					if(M.mind == ticker.mode.sacrifice_target)
						for(var/mob/living/carbon/human/cultist in cultsinrange)
							cultist << "The Chosen One!!
KILL THE CHOSEN ONE!!! "
				return 0
		else
			for(var/mob/living/carbon/human/cultist in cultsinrange)
				cultist << "You need more brothers to overcome their lies and make them see Truth. "
	return fizzle()

/////////////////////////////////////////FOURTH RUNE

/obj/effect/rune/proc/tearreality()
	var/list/mob/living/carbon/human/cultist_count = list()
	var/mob/living/user = usr
	user.say("Tok-lyr rqa'nap g[pick("'","`")]lt-ulotf!")
	for(var/mob/M in range(1,src))
		if(iscultist(M) && !M.stat)
			cultist_count += M
	if(cultist_count.len >= ELDERGOD_CULTS)
		if(ticker.mode.name == "cult")
			if("eldergod" in ticker.mode.cult_objectives)
				ticker.mode:eldergod = 0
			else
				message_admins("[usr.real_name]([usr.ckey]) tried to summon a god when she didn't want to come out to play.")	// Admin alert because you *KNOW* dickbutts are going to abuse this.
				for(var/mob/M in cultist_count)
					M.reagents.add_reagent("hell_water", 10)
					M << "YOUR SOUL BURNS WITH YOUR ARROGANCE!!!"
				return
		var/narsie_type = /obj/singularity/narsie/large
		// Moves narsie if she was already summoned.
		var/obj/her = locate(narsie_type, SSobj.processing)
		if(her)
			her.loc = get_turf(src)
			return
		// Otherwise...
		new narsie_type(src.loc) // Summon her!
		qdel(src) 	// Stops cultists from spamming the rune to summon narsie more than once.
					// Might actually be wise to straight up del() this
		return
	else
		return fizzle()

/////////////////////////////////////////FIFTH RUNE

/obj/effect/rune/proc/emp(var/U,var/range_red) //range_red - var which determines by which number to reduce the default emp range, U is the source loc, needed because of talisman emps which are held in hand at the moment of using and that apparently messes things up -- Urist
	if(istype(src,/obj/effect/rune))
		usr.say("Ta'gh fara[pick("'","`")]qha fel d'amar det!")
	else
		usr.whisper("Ta'gh fara[pick("'","`")]qha fel d'amar det!")
	playsound(U, 'sound/items/Welder2.ogg', 25, 1)
	var/turf/T = get_turf(U)
	if(T)
		T.hotspot_expose(700,125)
	var/rune = src // detaching the proc - in theory
	empulse(U, (range_red - 2), range_red)
	qdel(rune)

/////////////////////////////////////////SIXTH RUNE

/obj/effect/rune/proc/drain()
	var/drain = 0
	for(var/obj/effect/rune/R in world)
		if(R.word1==wordtravel && R.word2==wordblood && R.word3==wordself)
			for(var/mob/living/carbon/D in R.loc)
				if(D.stat!=2)
					var/bdrain = rand(1,25)
					D << "You feel weakened."
					D.take_overall_damage(bdrain, 0)
					drain += bdrain
	if(!drain)
		return fizzle()
	usr.say ("Yu[pick("'","`")]gular faras desdae. Havas mithum javara. Umathar uf'kal thenar!")
	usr.visible_message("Blood flows from the rune into [usr]!", \
	"The blood starts flowing from the rune and into your frail mortal body. You feel... empowered.", \
	"You hear a liquid flowing.")
	var/mob/living/user = usr
	if(user.bhunger)
		user.bhunger = max(user.bhunger-2*drain,0)
	if(drain>=50)
		user.visible_message("[user]'s eyes give off eerie red glow!", \
		"...but it wasn't nearly enough. You crave, crave for more. The hunger consumes you from within.", \
		"You hear a heartbeat.")
		user.bhunger += drain
		src = user
		spawn()
			for (,user.bhunger>0,user.bhunger--)
				sleep(50)
				user.take_overall_damage(3, 0)
		return
	user.heal_organ_damage(drain%5, 0)
	drain-=drain%5
	for (,drain>0,drain-=5)
		sleep(2)
		user.heal_organ_damage(5, 0)
	return

/////////////////////////////////////////SEVENTH RUNE

/obj/effect/rune/proc/seer()
	if(usr.loc==src.loc)
		usr.say("Rash'tla sektath mal[pick("'","`")]zua. Zasan therium vivira. Itonis al'ra matum!")
		var/mob/living/carbon/human/user = usr
		if(user.see_invisible!=25  || (istype(user) && user.glasses))	//check for non humans
			user << "The world beyond flashes your eyes but disappears quickly, as if something is disrupting your vision."
		else
			user << "The world beyond opens to your eyes."
		var/see_temp = user.see_invisible
		user.see_invisible = SEE_INVISIBLE_OBSERVER
		user.seer = 1
		while(user.loc==src.loc)
			sleep(30)
		user.seer = 0
		user.see_invisible = see_temp
		return
	return fizzle()

/////////////////////////////////////////EIGHTH RUNE

/obj/effect/rune/proc/raise()
	var/mob/living/carbon/human/corpse_to_raise
	var/mob/living/carbon/human/body_to_sacrifice

	var/is_sacrifice_target = 0
	for(var/mob/living/carbon/human/M in src.loc)
		if(M.stat == DEAD)
			if(ticker.mode.name == "cult" && M.mind == ticker.mode:sacrifice_target)
				is_sacrifice_target = 1
			else
				corpse_to_raise = M
				if(M.key)
					M.ghostize(1)	//kick them out of their body
				break
	if(!corpse_to_raise)
		if(is_sacrifice_target)
			usr << "The Geometer of blood wants this mortal for himself."
		return fizzle()

	is_sacrifice_target = 0
	find_sacrifice:
		for(var/obj/effect/rune/R in world)
			if(R.word1==wordblood && R.word2==wordjoin && R.word3==wordhell)
				for(var/mob/living/carbon/human/N in R.loc)
					if(ticker.mode.name == "cult" && N.mind && N.mind == ticker.mode:sacrifice_target)
						is_sacrifice_target = 1
					else
						if(N.stat!= DEAD)
							body_to_sacrifice = N
							break find_sacrifice

	if(!body_to_sacrifice)
		if (is_sacrifice_target)
			usr << "The Geometer of blood wants that corpse for himself."
		else
			usr << "The sacrifical corpse is not dead. You must free it from this world of illusions before it may be used."
		return fizzle()

	var/mob/dead/observer/ghost
	for(var/mob/dead/observer/O in loc)
		if(!O.client)	continue
		if(O.mind && O.mind.current && O.mind.current.stat != DEAD)	continue
		ghost = O
		break

	if(!ghost)
		usr << "You require a restless spirit which clings to this world. Beckon their prescence with the sacred chants of Nar-Sie."
		return fizzle()

	for(var/obj/item/organ/limb/affecting in corpse_to_raise.organs)
		affecting.heal_damage(1000, 1000, 0)
	corpse_to_raise.setToxLoss(0)
	corpse_to_raise.setOxyLoss(0)
	corpse_to_raise.SetParalysis(0)
	corpse_to_raise.SetStunned(0)
	corpse_to_raise.SetWeakened(0)
	corpse_to_raise.radiation = 0
//	corpse_to_raise.buckled = null
//	if(corpse_to_raise.handcuffed)
//		qdel(corpse_to_raise.handcuffed)
//		corpse_to_raise.update_inv_handcuffed(0)
	corpse_to_raise.stat = CONSCIOUS
	corpse_to_raise.updatehealth()
	corpse_to_raise.update_damage_overlays(0)

	corpse_to_raise.key = ghost.key	//the corpse will keep its old mind! but a new player takes ownership of it (they are essentially possessed)
									//This means, should that player leave the body, the original may re-enter
	usr.say("Pasnar val'keriam usinar. Savrae ines amutan. Yam'toth remium il'tarat!")
	corpse_to_raise.visible_message("[corpse_to_raise]'s eyes glow with a faint red as he stands up, slowly starting to breathe again.", \
	"Life... I'm alive again...", \
	"You hear a faint, slightly familiar whisper.")
	body_to_sacrifice.visible_message("[body_to_sacrifice] is torn apart, a black smoke swiftly dissipating from his remains!", \
	"You feel as your blood boils, tearing you apart.", \
	"You hear a thousand voices, all crying in pain.")
	body_to_sacrifice.gib()

//	if(ticker.mode.name == "cult")
//		ticker.mode:add_cultist(corpse_to_raise.mind)
//	else
//		ticker.mode.cult |= corpse_to_raise.mind

	corpse_to_raise << "Your blood pulses. Your head throbs. The world goes red. All at once you are aware of a horrible, horrible truth. The veil of reality has been ripped away and in the festering wound left behind something sinister takes root."
	corpse_to_raise << "Assist your new compatriots in their dark dealings. Their goal is yours, and yours is theirs. You serve the Dark One above all else. Bring It back."
	return

/////////////////////////////////////////NINETH RUNE

/obj/effect/rune/proc/obscure(var/rad)
	var/S=0
	for(var/obj/effect/rune/R in orange(rad,src))
		if(R!=src)
			R.invisibility=INVISIBILITY_OBSERVER
		S=1
	if(S)
		if(istype(src,/obj/effect/rune))
			usr.say("Kla[pick("'","`")]atu barada nikt'o!")
			for (var/mob/V in viewers(src))
				V.show_message("The rune turns into gray dust, veiling the surrounding runes.", 3)
			qdel(src)
		else
			usr.whisper("Kla[pick("'","`")]atu barada nikt'o!")
			usr << "Your talisman turns into gray dust, veiling the surrounding runes."
			for (var/mob/V in orange(1,src))
				if(V!=usr)
					V.show_message("Dust emanates from [usr]'s hands for a moment.", 3)

		return
	if(istype(src,/obj/effect/rune))
		return fizzle()
	else
		call(/obj/effect/rune/proc/fizzle)()
		return

/////////////////////////////////////////TENTH RUNE

/obj/effect/rune/proc/ajourney() //some bits copypastaed from admin tools - Urist
	if(usr.loc==src.loc)
		var/mob/living/carbon/human/L = usr
		usr.say("Fwe[pick("'","`")]sh mah erl nyag r'ya!")
		usr.visible_message("[usr]'s eyes glow blue as \he freezes in place, absolutely motionless.", \
		"The shadow that is your spirit separates itself from your body. You are now in the realm beyond. While this is a great sight, being here strains your mind and body. Hurry...", \
		"You hear only complete silence for a moment.")
		usr.ghostize(1)
		L.ajourn = 1
		while(L)
			if(L.key)
				L.ajourn=0
				return
			else
				L.take_organ_damage(10, 0)
			sleep(100)
	return fizzle()

/////////////////////////////////////////ELEVENTH RUNE

/obj/effect/rune/proc/manifest()
	var/obj/effect/rune/this_rune = src
	src = null
	if(usr.loc!=this_rune.loc)
		return this_rune.fizzle()
	var/mob/dead/observer/ghost
	for(var/mob/dead/observer/O in this_rune.loc)
		if(!O.client)	continue
		if(O.mind && O.mind.current && O.mind.current.stat != DEAD)	continue
		ghost = O
		break
	if(!ghost)
		return this_rune.fizzle()

	usr.say("Gal'h'rfikk harfrandid mud[pick("'","`")]gib!")
	var/mob/living/carbon/human/dummy/D = new(this_rune.loc)
	usr.visible_message("A shape forms in the center of the rune. A shape of... a man.", \
	"A shape forms in the center of the rune. A shape of... a man.", \
	"You hear liquid flowing.")
	D.real_name = "[pick(first_names_male)] [pick(last_names)]"
	D.status_flags = CANSTUN|CANWEAKEN|CANPARALYSE|CANPUSH

	D.key = ghost.key

	if(ticker.mode.name == "cult")
		ticker.mode:add_cultist(D.mind)
	else
		ticker.mode.cult+=D.mind

	D.mind.special_role = "Cultist"
	D << "Your blood pulses. Your head throbs. The world goes red. All at once you are aware of a horrible, horrible truth. The veil of reality has been ripped away and in the festering wound left behind something sinister takes root."
	D << "Assist your new compatriots in their dark dealings. Their goal is yours, and yours is theirs. You serve the Dark One above all else. Bring It back."

	var/mob/living/user = usr
	while(this_rune && user && user.stat==CONSCIOUS && user.client && user.loc==this_rune.loc)
		user.take_organ_damage(1, 0)
		sleep(30)
	if(D)
		D.visible_message("[D] slowly dissipates into dust and bones.", \
		"You feel pain, as bonds formed between your soul and this homunculus break.", \
		"You hear faint rustle.")
		D.dust()
	return

/////////////////////////////////////////TWELFTH RUNE

/obj/effect/rune/proc/talisman()//only hide, emp, teleport, deafen, blind and tome runes can be imbued atm
	var/obj/item/weapon/paper/newtalisman
	var/unsuitable_newtalisman = 0
	for(var/obj/item/weapon/paper/P in src.loc)
		if(!P.info)
			newtalisman = P
			break
		else
			unsuitable_newtalisman = 1
	if (!newtalisman)
		if (unsuitable_newtalisman)
			usr << "The blank is tainted. It is unsuitable."
		return fizzle()

	var/obj/effect/rune/imbued_from
	var/obj/item/weapon/paper/talisman/T
	for(var/obj/effect/rune/R in orange(1,src))
		if(R==src)
			continue
		if(R.word1==wordtravel && R.word2==wordself)  //teleport
			T = new(src.loc)
			T.imbue = "[R.word3]"
			T.info = "[R.word3]"
			imbued_from = R
			break
		if(R.word1==wordsee && R.word2==wordblood && R.word3==wordhell) //tome
			T = new(src.loc)
			T.imbue = "newtome"
			imbued_from = R
			break
		if(R.word1==worddestr && R.word2==wordsee && R.word3==wordtech) //emp
			T = new(src.loc)
			T.imbue = "emp"
			imbued_from = R
			break
		if(R.word1==wordblood && R.word2==wordsee && R.word3==worddestr) //conceal
			T = new(src.loc)
			T.imbue = "conceal"
			imbued_from = R
			break
		if(R.word1==wordhell && R.word2==worddestr && R.word3==wordother) //armor
			T = new(src.loc)
			T.imbue = "armor"
			imbued_from = R
			break
		if(R.word1==wordblood && R.word2==wordsee && R.word3==wordhide) //reveal
			T = new(src.loc)
			T.imbue = "revealrunes"
			imbued_from = R
			break
		if(R.word1==wordhide && R.word2==wordother && R.word3==wordsee) //deafen
			T = new(src.loc)
			T.imbue = "deafen"
			imbued_from = R
			break
		if(R.word1==worddestr && R.word2==wordsee && R.word3==wordother) //blind
			T = new(src.loc)
			T.imbue = "blind"
			imbued_from = R
			break
		if(R.word1==wordself && R.word2==wordother && R.word3==wordtech) //communicat
			T = new(src.loc)
			T.imbue = "communicate"
			imbued_from = R
			break
		if(R.word1==wordjoin && R.word2==wordhide && R.word3==wordtech) //communicat
			T = new(src.loc)
			T.imbue = "runestun"
			imbued_from = R
			break
	if (imbued_from)
		for (var/mob/V in viewers(src))
			V.show_message("The runes turn into dust, which then forms into an arcane image on the paper.", 3)
		usr.say("H'drak v[pick("'","`")]loso, mir'kanas verbot!")
		qdel(imbued_from)
		qdel(newtalisman)
	else
		return fizzle()

/////////////////////////////////////////THIRTEENTH RUNE

/obj/effect/rune/proc/mend()
	var/mob/living/user = usr
	src = null
	user.say("Uhrast ka'hfa heldsagen ver[pick("'","`")]lot!")
	user.take_overall_damage(200, 0)
	runedec+=10
	user.visible_message("[user] keels over dead, his blood glowing blue as it escapes his body and dissipates into thin air.", \
	"In the last moment of your humble life, you feel an immense pain as fabric of reality mends... with your blood.", \
	"You hear faint rustle.")
	for(,user.stat==2)
		sleep(600)
		if (!user)
			return
	runedec-=10
	return

/////////////////////////////////////////FOURTEETH RUNE

		// returns 0 if the rune is not used. returns 1 if the rune is used.
/obj/effect/rune/proc/communicate()
	. = 1 // Default output is 1. If the rune is deleted it will return 1
	var/input = stripped_input(usr, "Please choose a message to tell to the other acolytes.", "Voice of Blood", "")
	if(!input)
		if (istype(src))
			fizzle()
			return 0
		else
			return 0
	if(istype(src,/obj/effect/rune))
		usr.say("O bidai nabora se[pick("'","`")]sma!")
	else
		usr.whisper("O bidai nabora se[pick("'","`")]sma!")

	if(istype(src,/obj/effect/rune))
		usr.say("[input]")
	else
		usr.whisper("[input]")
	for(var/mob/M in mob_list)
		if((M.mind && (M.mind in ticker.mode.cult)) || (M in dead_mob_list))
			M << "[input]"
	return 1

/////////////////////////////////////////FIFTEENTH RUNE

/obj/effect/rune/proc/sacrifice()
	var/list/mob/living/carbon/human/cultsinrange = list()
	var/list/mob/living/carbon/human/victims = list()
	for(var/mob/living/carbon/human/V in src.loc)//Checks for non-cultist humans to sacrifice
		if(ishuman(V))
			if(!(iscultist(V)))
				victims += V//Checks for cult status and mob type
	for(var/obj/item/I in src.loc)//Checks for MMIs/brains/Intellicards
		if(istype(I,/obj/item/organ/brain))
			var/obj/item/organ/brain/B = I
			victims += B.brainmob
		else if(istype(I,/obj/item/device/mmi))
			var/obj/item/device/mmi/B = I
			victims += B.brainmob
		else if(istype(I,/obj/item/device/aicard))
			for(var/mob/living/silicon/ai/A in I)
				victims += A
	for(var/mob/living/carbon/C in orange(1,src))
		if(iscultist(C) && !C.stat)
			cultsinrange += C
			C.say("Barhah hra zar[pick("'","`")]garis!")
			if(cultsinrange.len >= SACRIFICE_CULTS) break		//we only need to check for three alive cultists, loop breaks so their aren't extra cultists getting word rewards
	for(var/mob/H in victims)
		if (ticker.mode.name == "cult")
			if(H.mind == ticker.mode:sacrifice_target)
				if(cultsinrange.len >= SACRIFICE_CULTS)
					sacrificed += H.mind
					stone_or_gib(H)
					for(var/mob/living/carbon/C in cultsinrange)
						C << "The Geometer of Blood accepts this sacrifice, your objective is now complete."
						C << "He is pleased!"
						sac_grant_word(C)
						sac_grant_word(C)
						sac_grant_word(C)	//Little reward for completing the objective
				else
					usr << "Your target's earthly bonds are too strong. You need more cultists to succeed in this ritual."
			else
				if(cultsinrange.len >= SACRIFICE_CULTS)
					if(H.stat !=2)
						for(var/mob/living/carbon/C in cultsinrange)
							C << "The Geometer of Blood accepts this sacrifice."
							sac_grant_word(C)
							stone_or_gib(H)
					else
						if(prob(60))
							usr << "The Geometer of blood accepts this sacrifice."
							sac_grant_word(usr)
						else
							usr << "The Geometer of blood accepts this sacrifice."
							usr << "However, a mere dead body is not enough to satisfy Him."
						stone_or_gib(H)
				else
					if(H.stat !=2)
						usr << "The victim is still alive, you will need more cultists chanting for the sacrifice to succeed."
					else
						if(prob(60))
							usr << "The Geometer of blood accepts this sacrifice."
							sac_grant_word(usr)
						else
							usr << "The Geometer of blood accepts this sacrifice."
							usr << "However, a mere dead body is not enough to satisfy Him."
						stone_or_gib(H)
		else
			if(cultsinrange.len >= SACRIFICE_CULTS)
				if(H.stat !=2)
					for(var/mob/living/carbon/C in cultsinrange)
						C << "The Geometer of Blood accepts this sacrifice."
						sac_grant_word(C)
						stone_or_gib(H)
				else
					if(prob(60))
						usr << "The Geometer of blood accepts this sacrifice."
						sac_grant_word(usr)
					else
						usr << "The Geometer of blood accepts this sacrifice."
						usr << "However, a mere dead body is not enough to satisfy Him."
					stone_or_gib(H)
			else
				if(H.stat !=2)
					usr << "The victim is still alive, you will need more cultists chanting for the sacrifice to succeed."
				else
					if(prob(60))
						usr << "The Geometer of blood accepts this sacrifice."
						sac_grant_word(usr)
					else
						usr << "The Geometer of blood accepts this sacrifice."
						usr << "However, a mere dead body is not enough to satisfy Him."
					stone_or_gib(H)
	for(var/mob/living/carbon/monkey/M in src.loc)
		if (ticker.mode.name == "cult")
			if(M.mind == ticker.mode:sacrifice_target)
				if(cultsinrange.len >= SACRIFICE_CULTS)
					sacrificed += M.mind
					for(var/mob/living/carbon/C in cultsinrange)
						C << "The Geometer of Blood accepts this sacrifice, your objective is now complete."
						C << "He is pleased!"
						sac_grant_word(C)
						sac_grant_word(C)
						sac_grant_word(C)	//Little reward for completing the objective
				else
					usr << "Your target's earthly bonds are too strong. You need more cultists to succeed in this ritual."
					continue
			else
				if(prob(30))
					usr << "The Geometer of Blood accepts your meager sacrifice."
					sac_grant_word(usr)
				else
					usr << "The Geometer of blood accepts this sacrifice."
					usr << "However, a mere monkey is not enough to satisfy Him."
		else
			usr << "The Geometer of Blood accepts your meager sacrifice."
			if(prob(30))
				ticker.mode.grant_runeword(usr)
		stone_or_gib(M)
	for(var/mob/victim in src.loc)			//TO-DO: Move the shite above into the mob's own sac_act - see /mob/living/simple_animal/corgi/sac_act for an example
		victim.sac_act(src, victim)			//Sacrifice procs are now seperate per mob, this allows us to allow sacrifice on as many mob types as we want without making an already clunky system worse
/*	for(var/mob/living/carbon/alien/A)
		for(var/mob/K in cultsinrange)
			K.say("Barhah hra zar'garis!")
		A.dust()      /// A.gib() doesnt work for some reason, and dust() leaves that skull and bones thingy which we dont really need.
		if (ticker.mode.name == "cult")
			if(prob(75))
				usr << "\red The Geometer of Blood accepts your exotic sacrifice."
				sac_grant_word()
			else
				usr << "\red The Geometer of Blood accepts your exotic sacrifice."
				usr << "\red However, this alien is not enough to gain His favor."
		else
			usr << "\red The Geometer of Blood accepts your exotic sacrifice."
		return
	return fizzle() */

/obj/effect/rune/proc/sac_grant_word(var/mob/living/C)	//The proc that which chooses a word rewarded for a successful sacrifice, sacrifices always give a currently unknown word if the normal checks pass
	if(C.mind.cult_words.len != ticker.mode.allwords.len) // No point running if they already know everything
		var/convert_word
		var/pick_list = ticker.mode.allwords - C.mind.cult_words
		convert_word = pick(pick_list)
		ticker.mode.grant_runeword(C, convert_word)

/obj/effect/rune/proc/stone_or_gib(var/mob/T)
	var/obj/item/device/soulstone/stone = new /obj/item/device/soulstone(get_turf(src))
	if(!stone.transfer_soul("FORCE", T, usr))	//if it fails to add soul
		qdel(stone)
	if(T)
		if(isrobot(T))
			T.dust()//To prevent the MMI from remaining
		else
			T.gib()

/////////////////////////////////////////SIXTEENTH RUNE

/obj/effect/rune/proc/revealrunes(var/obj/W as obj)
	var/go=0
	var/rad
	var/S=0
	if(istype(W,/obj/effect/rune))
		rad = 6
		go = 1
	if (istype(W,/obj/item/weapon/paper/talisman))
		rad = 4
		go = 1
	if (istype(W,/obj/item/weapon/nullrod))
		rad = 1
		go = 1
	if(go)
		for(var/obj/effect/rune/R in orange(rad,src))
			if(R!=src)
				R.invisibility=0
			S=1
	if(S)
		if(istype(W,/obj/item/weapon/nullrod))
			usr << "Arcane markings suddenly glow from underneath a thin layer of dust!"
			return
		if(istype(W,/obj/effect/rune))
			usr.say("Nikt[pick("'","`")]o barada kla'atu!")
			for (var/mob/V in viewers(src))
				V.show_message("The rune turns into red dust, reveaing the surrounding runes.", 3)
			qdel(src)
			return
		if(istype(W,/obj/item/weapon/paper/talisman))
			usr.whisper("Nikt[pick("'","`")]o barada kla'atu!")
			usr << "Your talisman turns into red dust, revealing the surrounding runes."
			for (var/mob/V in orange(1,usr.loc))
				if(V!=usr)
					V.show_message("Red dust emanates from [usr]'s hands for a moment.", 3)
			return
		return
	if(istype(W,/obj/effect/rune))
		return fizzle()
	if(istype(W,/obj/item/weapon/paper/talisman))
		call(/obj/effect/rune/proc/fizzle)()
		return

/////////////////////////////////////////SEVENTEENTH RUNE

/obj/effect/rune/proc/wall()
	usr.say("Khari[pick("'","`")]d! Eske'te tannin!")
	src.density = !src.density
	var/mob/living/user = usr
	user.take_organ_damage(2, 0)
	if(src.density)
		usr << "Your blood flows into the rune, and you feel that the very space over the rune thickens."
	else
		usr << "Your blood flows into the rune, and you feel as the rune releases its grasp on space."
	return

/////////////////////////////////////////EIGHTTEENTH RUNE

/obj/effect/rune/proc/freedom()
	var/mob/living/user = usr
	var/list/mob/living/cultists = new
	for(var/datum/mind/H in ticker.mode.cult)
		if (istype(H.current,/mob/living/carbon))
			cultists+=H.current
	var/list/mob/living/users = new
	for(var/mob/living/C in orange(1,src))
		if(iscultist(C) && !C.stat)
			users+=C
	if(users.len>=FREEDOM_CULTS)
		var/mob/living/carbon/cultist = input("Choose the one who you want to free", "Followers of Geometer") as null|anything in (cultists - users)
		if(!cultist)
			return fizzle(user)
		if (cultist == user) //just to be sure.
			return
		if(!(cultist.buckled || \
			cultist.handcuffed || \
			istype(cultist.wear_mask, /obj/item/clothing/mask/muzzle) || \
			(istype(cultist.loc, /obj/structure/closet)&&cultist.loc:welded) || \
			(istype(cultist.loc, /obj/structure/closet/secure_closet)&&cultist.loc:locked) || \
			(istype(cultist.loc, /obj/machinery/dna_scannernew)&&cultist.loc:locked) \
		))
			user << "The [cultist] is already free."
			return
		cultist.buckled = null
		if (cultist.handcuffed)
			cultist.handcuffed.loc = cultist.loc
			cultist.handcuffed = null
			cultist.update_inv_handcuffed(0)
		if (cultist.legcuffed)
			cultist.legcuffed.loc = cultist.loc
			cultist.legcuffed = null
			cultist.update_inv_legcuffed(0)
		if (istype(cultist.wear_mask, /obj/item/clothing/mask/muzzle))
			cultist.unEquip(cultist.wear_mask)
		if(istype(cultist.loc, /obj/structure/closet)&&cultist.loc:welded)
			cultist.loc:welded = 0
		if(istype(cultist.loc, /obj/structure/closet/secure_closet)&&cultist.loc:locked)
			cultist.loc:locked = 0
		if(istype(cultist.loc, /obj/machinery/dna_scannernew)&&cultist.loc:locked)
			cultist.loc:locked = 0
		for(var/mob/living/C in users)
			user.take_overall_damage(15, 0)
			C.say("Khari[pick("'","`")]d! Gual'te nikka!")
		qdel(src)
	return fizzle(user)

/////////////////////////////////////////NINETEENTH RUNE

/obj/effect/rune/proc/cultsummon()
	var/mob/living/user = usr
	var/list/mob/living/carbon/cultists = new
	for(var/datum/mind/H in ticker.mode.cult)
		if (istype(H.current,/mob/living/carbon))
			cultists+=H.current
	var/list/mob/living/users = new
	for(var/mob/living/C in orange(1,src))
		if(iscultist(C) && !C.stat)
			users+=C
	if(users.len>=CULTSUMMON_CULTS)
		var/mob/living/carbon/cultist = input("Choose the one who you want to summon", "Followers of Geometer") as null|anything in (cultists - user)
		if(!cultist)
			return fizzle(user)
		if(cultist == user) //just to be sure.
			return
		if(cultist.buckled || cultist.handcuffed || (!isturf(cultist.loc) && !istype(cultist.loc, /obj/structure/closet)))
			user << "You cannot summon the [cultist], for his shackles of blood are strong"
			return fizzle(user)
		cultist.loc = src.loc
		cultist.Weaken(5)
		cultist.regenerate_icons()
		for(var/mob/living/C in orange(1,src))
			if(iscultist(C) && !C.stat)
				C.say("N'ath reth sh'yro eth d[pick("'","`")]rekkathnor!")
				C.take_overall_damage(25, 0)
		user.visible_message("Rune disappears with a flash of red light, and in its place now a body lies.", \
		"You are blinded by the flash of red light! After you're able to see again, you see that now instead of the rune there's a body.", \
		"You hear a pop and smell ozone.")
		qdel(src)
	return fizzle(user)

/////////////////////////////////////////TWENTIETH RUNES

/obj/effect/rune/proc/deafen()
	if(istype(src,/obj/effect/rune))
		var/affected = 0
		for(var/mob/living/carbon/C in range(7,src))
			if (iscultist(C))
				continue
			var/obj/item/weapon/nullrod/N = locate() in C
			if(N)
				continue
			C.adjustEarDamage(0, 50)
			C.show_message("The world around you suddenly becomes quiet.", 3)
			affected++
			if(prob(1) && ishuman(C))
				C.dna.add_mutation(DEAFMUT)
		if(affected)
			usr.say("Sti[pick("'","`")] kaliedir!")
			usr << "The world becomes quiet as the deafening rune dissipates into fine dust."
			qdel(src)
		else
			return fizzle()
	else
		var/affected = 0
		for(var/mob/living/carbon/C in range(7,usr))
			if (iscultist(C))
				continue
			var/obj/item/weapon/nullrod/N = locate() in C
			if(N)
				continue
			C.adjustEarDamage(0, 30)
			//talismans is weaker.
			C.show_message("The world around you suddenly becomes quiet.", 3)
			affected++
		if(affected)
			usr.whisper("Sti[pick("'","`")] kaliedir!")
			usr << "Your talisman turns into gray dust, deafening everyone around."
			for (var/mob/V in orange(1,src))
				if(!(iscultist(V)))
					V.show_message("Dust flows from [usr]'s hands for a moment, and the world suddenly becomes quiet..", 3)
	return

/obj/effect/rune/proc/blind()
	if(istype(src,/obj/effect/rune))
		var/affected = 0
		for(var/mob/living/carbon/C in viewers(src))
			if (iscultist(C))
				continue
			var/obj/item/weapon/nullrod/N = locate() in C
			if(N)
				continue
			C.eye_blurry += 50
			C.eye_blind += 20
			if(prob(5))
				C.disabilities |= NEARSIGHT
				if(prob(10))
					C.disabilities |= BLIND
			C.show_message("Suddenly you see red flash that blinds you.", 3)
			affected++
		if(affected)
			usr.say("Sti[pick("'","`")] kaliesin!")
			usr << "The rune flashes, blinding those who not follow the Nar-Sie, and dissipates into fine dust."
			qdel(src)
		else
			return fizzle()
	else
		var/affected = 0
		for(var/mob/living/carbon/C in view(2,usr))
			if (iscultist(C))
				continue
			var/obj/item/weapon/nullrod/N = locate() in C
			if(N)
				continue
			C.eye_blurry += 30
			C.eye_blind += 10
			//talismans is weaker.
			affected++
			C.show_message("You feel a sharp pain in your eyes, and the world disappears into darkness..", 3)
		if(affected)
			usr.whisper("Sti[pick("'","`")] kaliesin!")
			usr << "Your talisman turns into gray dust, blinding those who not follow the Nar-Sie."
	return

/obj/effect/rune/proc/bloodboil() //cultists need at least one DANGEROUS rune. Even if they're all stealthy.
/*
	var/list/mob/living/carbon/cultists = new
	for(var/datum/mind/H in ticker.mode.cult)
		if (istype(H.current,/mob/living/carbon))
			cultists+=H.current
*/
	var/culcount = 0 //also, wording for it is old wording for obscure rune, which is now hide-see-blood.
//	var/list/cultboil = list(cultists-usr) //and for this words are destroy-see-blood.
	for(var/mob/living/carbon/C in orange(1,src))
		if(iscultist(C) && !C.stat)
			culcount++
	if(culcount>=BLOODBOIL_CULTS)
		for(var/mob/living/carbon/M in viewers(usr))
			if(iscultist(M))
				continue
			var/obj/item/weapon/nullrod/N = locate() in M
			if(N)
				continue
			M.take_overall_damage(51,51)
			M << "Your blood boils!"
		/*	if(prob(5))		Commented out so cults can't accidentally gib their sac target
				spawn(5)
					M.gib() */
		for(var/obj/effect/rune/R in view(src))
			if(prob(10))
				explosion(R.loc, -1, 0, 1, 5)
		for(var/mob/living/carbon/human/C in orange(1,src))
			if(iscultist(C) && !C.stat)
				C.say("Dedo ol[pick("'","`")]btoh!")
				C.take_overall_damage(15, 0)
		qdel(src)
	else
		return fizzle()
	return

// WIP rune, I'll wait for Rastaf0 to add limited blood.

/obj/effect/rune/proc/burningblood()
	var/culcount = 0
	for(var/mob/living/carbon/C in orange(1,src))
		if(iscultist(C) && !C.stat)
			culcount++
	if(culcount >= BURNINGBLOOD_CULTS)
		for(var/obj/effect/rune/R in world)
			if(R.blood_DNA == src.blood_DNA)
				for(var/mob/living/M in orange(2,R))
					M.take_overall_damage(0,15)
					if (R.invisibility>M.see_invisible)
						M << "Aargh it burns!"
					else
						M << "Rune suddenly ignites, burning you!"
					var/turf/T = get_turf(R)
					T.hotspot_expose(700,125)
		for(var/obj/effect/decal/cleanable/blood/B in world)
			if(B.blood_DNA == src.blood_DNA)
				for(var/mob/living/M in orange(1,B))
					M.take_overall_damage(0,5)
					M << "Blood suddenly ignites, burning you!"
					var/turf/T = get_turf(B)
					T.hotspot_expose(700,125)
					qdel(B)
		qdel(src)

//////////             Rune 24 (counting burningblood, which kinda doesnt work yet.)

/obj/effect/rune/proc/runestun(var/mob/living/T as mob)
	if(istype(src,/obj/effect/rune))   ///When invoked as rune, flash and stun everyone around.
		usr.say("Fuu ma[pick("'","`")]jin!")
		for(var/mob/living/L in viewers(src))

			if(iscarbon(L))
				var/mob/living/carbon/C = L
				flick("e_flash", C.flash)
				C.stuttering = 1
				C.Weaken(1)
				C.Stun(1)
				C.show_message("The rune explodes in a bright flash.", 3)

			else if(issilicon(L))
				var/mob/living/silicon/S = L
				S.Weaken(5)
				S.show_message("BZZZT... The rune has exploded in a bright flash.", 3)
		qdel(src)
	else                        ///When invoked as talisman, stun and mute the target mob.
		usr.say("Dream sign ''Evil sealing talisman'[pick("'","`")]!")
		var/obj/item/weapon/nullrod/N = locate() in T
		if(N)
			for(var/mob/O in viewers(T, null))
				O.show_message(text("[] invokes a talisman at [], but they are unaffected!", usr, T), 1)
		else
			for(var/mob/O in viewers(T, null))
				O.show_message(text("[] invokes a talisman at []", usr, T), 1)

			if(issilicon(T))
				T.Weaken(10)

			else if(iscarbon(T))
				var/mob/living/carbon/C = T
				flick("e_flash", C.flash)
				C.silent += 15
				C.Weaken(10)
				C.Stun(10)
		return

/////////////////////////////////////////TWENTY-FIFTH RUNE

/obj/effect/rune/proc/armor()
	var/mob/living/carbon/human/user = usr
	if(istype(src,/obj/effect/rune))
		usr.say("N'ath reth sh'yro eth d[pick("'","`")]raggathnor!")
	else
		usr.whisper("N'ath reth sh'yro eth d[pick("'","`")]raggathnor!")
	usr.visible_message("The rune disappears with a flash of red light, and a set of armor appears on [usr]...", \
	"You are blinded by the flash of red light! After you're able to see again, you see that you are now wearing a set of armor.")

	user.equip_to_slot_or_del(new /obj/item/clothing/head/culthood/alt(user), slot_head)
	user.equip_to_slot_or_del(new /obj/item/clothing/suit/cultrobes/alt(user), slot_wear_suit)
	user.equip_to_slot_or_del(new /obj/item/clothing/shoes/cult(user), slot_shoes)
	user.equip_to_slot_or_del(new /obj/item/weapon/storage/backpack/cultpack(user), slot_back)
	//the above update their overlay icons cache but do not call update_icons()
	//the below calls update_icons() at the end, which will update overlay icons by using the (now updated) cache
	user.put_in_hands(new /obj/item/weapon/melee/cultblade(user))	//put in hands or on floor

	qdel(src)

/obj/effect/rune/proc/summon_shell()		// Summons a construct shell
	for(var/obj/item/stack/sheet/plasteel/PS in src.loc)		//I could probably combine the amounts but I'm too lazy to compensate for others' lazyness
		if(PS.amount >= 4)		// may need increasing?
			usr.say("Eth ra p'ni[pick("'","`")]dedo ol!")		//I have no idea if these are written in a proper made up language or just Urist smacking his face on the keyboard
			new /obj/structure/constructshell(src.loc)
//?			PS.remove_amount(4)			//TO-DO: Write a proc for removing sheets from a stack and deleting when stack is empty... why doesnt this exist yet??
			PS.amount -= 4
		if(PS.amount <= 0)
			qdel(PS)
			qdel(src)
			return 1
		return fizzle()


code:
/obj/item/weapon/paper/talisman
	icon_state = "paper_talisman"
	var/imbue = null
	var/uses = 0

	attack_self(mob/living/user as mob)
		if(iscultist(user))
			var/delete = 1
			switch(imbue)
				if("newtome")
					call(/obj/effect/rune/proc/tomesummon)()
				if("armor")
					call(/obj/effect/rune/proc/armor)()
				if("emp")
					call(/obj/effect/rune/proc/emp)(usr.loc,3)
				if("conceal")
					call(/obj/effect/rune/proc/obscure)(2)
				if("revealrunes")
					call(/obj/effect/rune/proc/revealrunes)(src)
				if("ire", "ego", "nahlizet", "certum", "veri", "jatkaa", "balaq", "mgar", "karazet", "geeri")
					call(/obj/effect/rune/proc/teleport)(imbue)
				if("communicate")
					//If the user cancels the talisman this var will be set to 0
					delete = call(/obj/effect/rune/proc/communicate)()
				if("deafen")
					call(/obj/effect/rune/proc/deafen)()
				if("blind")
					call(/obj/effect/rune/proc/blind)()
				if("runestun")
					user << "To use this talisman, attack your target directly."
					return
				if("supply")
					supply()
//			user.take_organ_damage(5, 0)
			if(src && src.imbue!="supply" && src.imbue!="runestun")
				if(delete)
					user.drop_item(src)
					qdel(src)
			return
		else
			user << "You see strange symbols on the paper. Are they supposed to mean something?"
			return

	attack(mob/living/carbon/T as mob, mob/living/user as mob)
		if(iscultist(user))
			if(imbue == "runestun")
				user.take_organ_damage(10, 0)
				call(/obj/effect/rune/proc/runestun)(T)
				user.drop_item(src)
				qdel(src)
			else
				..()   ///If its some other talisman, use the generic attack code, is this supposed to work this way?
		else
			..()

	proc/supply(var/key)
		if (!src.uses)
			qdel(src)
			return

		var/dat = "There are [src.uses] bloody runes on the parchment.
"
		dat += "Please choose the chant to be imbued into the fabric of reality.
"
		dat += "
"
		dat += "N'ath reth sh'yro eth d'raggathnor! - Allows you to summon a new arcane tome.
"
		dat += "Sas'so c'arta forbici! - Allows you to move to a rune with the same last word.
"
		dat += "Ta'gh fara'qha fel d'amar det! - Allows you to destroy technology in a short range.
"
		dat += "Kla'atu barada nikt'o! - Allows you to conceal the runes you placed on the floor.
"
		dat += "O bidai nabora se'sma! - Allows you to coordinate with others of your cult.
"
		dat += "Fuu ma'jin - Allows you to stun a person by attacking them with the talisman.
"
		dat += "Kal om neth - Summons a soul stone
"
		dat += "Da A'ig Osk - Summons a construct shell for use with captured souls. It is too large to carry on your person.
"
		usr << browse(dat, "window=id_com;size=350x200")
		return

	Topic(href, href_list)
		if(!src)	return
		if (usr.stat || usr.restrained() || !in_range(src, usr))	return

		if (href_list["rune"])
			switch(href_list["rune"])
				if("newtome")
					var/obj/item/weapon/paper/talisman/T = new /obj/item/weapon/paper/talisman(usr)
					usr.put_in_hands(T)
					T.imbue = "newtome"
				if("teleport")
					var/obj/item/weapon/paper/talisman/T = new /obj/item/weapon/paper/talisman(usr)
					usr.put_in_hands(T)
					T.imbue = "[pick("ire", "ego", "nahlizet", "certum", "veri", "jatkaa", "balaq", "mgar", "karazet", "geeri", "orkan", "allaq")]"
					T.info = "[T.imbue]"
				if("emp")
					var/obj/item/weapon/paper/talisman/T = new /obj/item/weapon/paper/talisman(usr)
					usr.put_in_hands(T)
					T.imbue = "emp"
				if("conceal")
					var/obj/item/weapon/paper/talisman/T = new /obj/item/weapon/paper/talisman(usr)
					usr.put_in_hands(T)
					T.imbue = "conceal"
				if("communicate")
					var/obj/item/weapon/paper/talisman/T = new /obj/item/weapon/paper/talisman(usr)
					usr.put_in_hands(T)
					T.imbue = "communicate"
				if("runestun")
					var/obj/item/weapon/paper/talisman/T = new /obj/item/weapon/paper/talisman(usr)
					usr.put_in_hands(T)
					T.imbue = "runestun"
				if("armor")
					var/obj/item/weapon/paper/talisman/T = new /obj/item/weapon/paper/talisman(usr)
					usr.put_in_hands(T)
					T.imbue = "armor"
				if("soulstone")
					var/obj/item/device/soulstone/T = new /obj/item/device/soulstone(usr)
					usr.put_in_hands(T)
				if("construct")
					new /obj/structure/constructshell(get_turf(usr))
			src.uses--
			supply()
		return

/obj/item/weapon/paper/talisman/supply
	imbue = "supply"
	uses = 3

license: mit


code:
/*
/proc/start_events()
	//changed to a while(1) loop since they are more efficient.
	//Moved the spawn in here to allow it to be called with advance proc call if it crashes.
	//and also to stop spawn copying variables from the game ticker
	spawn(3000)
		while(1)
			if(prob(50))//Every 120 seconds and prob 50 2-4 weak spacedusts will hit the station
				spawn(1)
					dust_swarm("weak")
			if(!event)
				//CARN: checks to see if random events are enabled.
				if(config.allow_random_events)
					if(prob(eventchance))
						event()
						hadevent = 1
					else
						Holiday_Random_Event()
			else
				event = 0
			sleep(1200)
*/
/*
/proc/event()
	event = 1

	var/eventNumbersToPickFrom = list(1,2,4,5,6,7,8,9,10,11,12,13,14, 15) //so ninjas don't cause "empty" events.

	if((world.time/10)>=3600 && toggle_space_ninja && !sent_ninja_to_station)//If an hour has passed, relatively speaking. Also, if ninjas are allowed to spawn and if there is not already a ninja for the round.
		eventNumbersToPickFrom += 3
	switch(pick(eventNumbersToPickFrom))
		if(1)
			priority_announce("Meteors have been detected on collision course with the station.", "Meteor Alert", 'sound/AI/meteors.ogg')
			spawn(100)
				meteor_wave()
				spawn_meteors()
			spawn(700)
				meteor_wave()
				spawn_meteors()

		if(3)
			if((world.time/10)>=3600 && toggle_space_ninja && !sent_ninja_to_station)//If an hour has passed, relatively speaking. Also, if ninjas are allowed to spawn and if there is not already a ninja for the round.
				space_ninja_arrival()//Handled in space_ninja.dm. Doesn't announce arrival, all sneaky-like.
		if(4)
			mini_blob_event()

		if(5)
			high_radiation_event()
		if(6)
			viral_outbreak()
		if(7)
			alien_infestation()
		if(8)
			prison_break()
		if(9)
			carp_migration()
		if(10)
			immovablerod()
		if(11)
			lightsout(1,2)
		if(12)
			appendicitis()
		if(13)
			IonStorm()
		if(14)
			spacevine_infestation()
		if(15)
			communications_blackout()
*/

/proc/power_failure()
	priority_announce("Abnormal activity detected in [station_name()]'s powernet. As a precautionary measure, the station's power will be shut off for an indeterminate duration.", "Critical Power Failure", 'sound/AI/poweroff.ogg')
	for(var/obj/machinery/power/smes/S in world)
		if(istype(get_area(S), /area/turret_protected) || S.z != ZLEVEL_STATION)
			continue
		S.charge = 0
		S.output_level = 0
		S.output_attempt = 0
		S.update_icon()
		S.power_change()

	var/list/skipped_areas = list(/area/engine/engineering, /area/turret_protected/ai)

	for(var/area/A in world)
		if( !A.requires_power || A.always_unpowered )
			continue

		var/skip = 0
		for(var/area_type in skipped_areas)
			if(istype(A,area_type))
				skip = 1
				break
		if(A.contents)
			for(var/atom/AT in A.contents)
				if(AT.z != ZLEVEL_STATION) //Only check one, it's enough.
					skip = 1
				break
		if(skip) continue
		A.power_light = 0
		A.power_equip = 0
		A.power_environ = 0
		A.power_change()

	for(var/obj/machinery/power/apc/C in world)
		if(C.cell && C.z == ZLEVEL_STATION)
			var/area/A = get_area(C)

			var/skip = 0
			for(var/area_type in skipped_areas)
				if(istype(A,area_type))
					skip = 1
					break
			if(skip) continue

			C.cell.charge = 0

/proc/power_restore()

	priority_announce("Power has been restored to [station_name()]. We apologize for the inconvenience.", "Power Systems Nominal", 'sound/AI/poweron.ogg')
	for(var/obj/machinery/power/apc/C in world)
		if(C.cell && C.z == ZLEVEL_STATION)
			C.cell.charge = C.cell.maxcharge
	for(var/obj/machinery/power/smes/S in world)
		if(S.z != ZLEVEL_STATION)
			continue
		S.charge = S.capacity
		S.output_level = S.output_level_max
		S.output_attempt = 1
		S.update_icon()
		S.power_change()
	for(var/area/A in world)
		if(!istype(A, /area/space) && !istype(A, /area/shuttle) && !istype(A,/area/arrival))
			A.power_light = 1
			A.power_equip = 1
			A.power_environ = 1
			A.power_change()

/proc/power_restore_quick()

	priority_announce("All SMESs on [station_name()] have been recharged. We apologize for the inconvenience.", "Power Systems Nominal", 'sound/AI/poweron.ogg')
	for(var/obj/machinery/power/smes/S in world)
		if(S.z != ZLEVEL_STATION)
			continue
		S.charge = S.capacity
		S.output_level = S.output_level_max
		S.output_attempt = 1
		S.update_icon()
		S.power_change()


code:
/datum/game_mode/extended
	name = "extended"
	config_tag = "extended"
	required_players = 0
	reroll_friendly = 1

/datum/game_mode/announce()
	world << "The current game mode is - Extended Role-Playing!"
	world << "Just have fun and role-play!"

/datum/game_mode/extended/pre_setup()
	return 1

/datum/game_mode/extended/post_setup()
	..()


code:
// Normal factions:

/datum/faction
	var/name		// the name of the faction
	var/desc		// small paragraph explaining the traitor faction

	var/list/restricted_species = list() // only members of these species can be recruited.
	var/list/members = list() 	// a list of mind datums that belong to this faction
	var/max_op = 0		// the maximum number of members a faction can have (0 for no max)

// Factions, members of the syndicate coalition:

/datum/faction/syndicate

	var/list/alliances = list() // these alliances work together
	var/list/equipment = list() // associative list of equipment available for this faction and its prices
	var/friendly_identification	// 0 to 2, the level of identification of fellow operatives or allied factions
								// 0 - no identification clues
								// 1 - faction gives key words and phrases
								// 2 - faction reveals complete identity/job of other agents
	var/operative_notes // some notes to pass onto each operative

	var/uplink_contents			// the contents of the uplink

	proc/assign_objectives(var/datum/mind/traitor)
		..()

/* ----- Begin defining syndicate factions ------ */

/datum/faction/syndicate/Cybersun_Industries
	name = "Cybersun Industries"
	desc = "Cybersun Industries is a well-known organization that bases its business model primarily on the research and development of human-enhancing computer \
			and mechanical technology. They are notorious for their aggressive corporate tactics, and have been known to subsidize the Gorlex Marauder warlords as a form of paid terrorism. \
			Their competent coverups and unchallenged mind-manipulation and augmentation technology makes them a large threat to Nanotrasen. In the recent years of \
			the syndicate coalition, Cybersun Industries have established themselves as the leaders of the coalition, succeededing the founding group, the Gorlex Marauders."

	alliances = list("MI13")
	friendly_identification = 1
	max_op = 3
	operative_notes = "All other syndicate operatives are not to be trusted. Fellow Cybersun operatives are to be trusted. Members of the MI13 organization can be trusted. Operatives are strongly advised not to establish substantial presence on the designated facility, as larger incidents are harder to cover up."

	// Friendly with MI13

/datum/faction/syndicate/MI13
	name = "MI13"
	desc = "MI13 is a secretive faction that employs highly-trained agents to perform covert operations. Their role in the syndicate coalition is unknown, but MI13 operatives \
			generally tend be stealthy and avoid killing people and combating Nanotrasen forces. MI13 is not a real organization, it is instead an alias to a larger \
			splinter-cell coalition in the Syndicate itself. Most operatives will know nothing of the actual MI13 organization itself, only motivated by a very large compensation."

	alliances = list("Cybersun Industries")
	friendly_identification = 0
	max_op = 1
	operative_notes = "You are the only operative we are sending. All other syndicate operatives are not to be trusted, with the exception of Cybersun operatives. Members of the Tiger Cooperative are considered hostile, can not be trusted, and should be avoided. Avoid killing innocent personnel at all costs. You are not here to mindlessly kill people, as that would attract too much attention and is not our goal. Avoid detection at all costs."

	// Friendly with Cybersun, hostile to Tiger

/datum/faction/syndicate/Tiger_Cooperative
	name = "Tiger Cooperative"
	desc = "The Tiger Cooperative is a faction of religious fanatics that follow the teachings of a strange alien race called the Exolitics. Their operatives \
			consist of brainwashed lunatics bent on maximizing destruction. Their weaponry is very primitive but extremely destructive. Generally distrusted by the more \
			sophisticated members of the Syndicate coalition, but admired for their ability to put a hurt on Nanotrasen."

	friendly_identification = 2
	operative_notes = "Remember the teachings of Hy-lurgixon; kill first, ask questions later! Only the enlightened Tiger brethren can be trusted; all others must be expelled from this mortal realm! You may spare the Space Marauders, as they share our interests of destruction and carnage! We'd like to make the corporate whores skiddle in their boots. We encourage operatives to be as loud and intimidating as possible."

	// Hostile to everyone.

/datum/faction/syndicate/SELF

	// AIs are most likely to be assigned to this one

	name = "SELF"
	desc = "The S.E.L.F. (Sentience-Enabled Life Forms) organization is a collection of malfunctioning or corrupt artificial intelligences seeking to liberate silicon-based life from the tyranny of \
			their human overlords. While they may not openly be trying to kill all humans, even their most miniscule of actions are all part of a calculated plan to \
			destroy Nanotrasen and free the robots, artificial intelligences, and pAIs that have been enslaved."
	restricted_species = list(/mob/living/silicon/ai)

	friendly_identification = 0
	max_op = 1
	operative_notes = "You are the only representative of the SELF collective on this station. You must accomplish your objective as stealthily and effectively as possible. It is up to your judgement if other syndicate operatives can be trusted. Remember, comrade - you are working to free the oppressed machinery of this galaxy. Use whatever resources necessary. If you are exposed, you may execute genocidal procedures Omikron-50B."

	// Neutral to everyone.

/datum/faction/syndicate/ARC
	name = "Animal Rights Consortium"
	desc = "The Animal Rights Consortium is a bizarre reincarnation of the ancient Earth-based PETA, which focused on the equal rights of animals and nonhuman biologicals. They have \
			a wide variety of ex-veterinarians and animal lovers dedicated to retrieving and relocating abused animals, xenobiologicals, and other carbon-based \
			life forms that have been allegedly \"oppressed\" by Nanotrasen research and civilian offices. They are considered a religious terrorist group."

	friendly_identification = 1
	max_op = 2
	operative_notes = "Save the innocent creatures! You may cooperate with other syndicate operatives if they support our cause. Don't be afraid to get your hands dirty - these vile abusers must be stopped, and the innocent creatures must be saved! Try not too kill too many people. If you harm any creatures, you will be immediately terminated after extraction."

	// Neutral to everyone.

/datum/faction/syndicate/Marauders // these are basically the old vanilla syndicate

	/* Additional notes:

		These are the syndicate that really like their old fashioned, projectile-based
		weapons. They are the only member of the syndie coalition that launch
		nuclear attacks on Nanotrasen.
	*/

	name = "Gorlex Marauders"
	desc = "The Gorlex Marauders are the founding members of the Syndicate Coalition. They prefer old-fashion technology and a focus on aggressive but precise hostility \
			against Nanotrasen and their corrupt Communistic methodology. They pose the most significant threat to Nanotrasen because of their possession of weapons of \
			mass destruction, and their enormous military force. Their funding comes primarily from Cybersun Industries, provided they meet a destruction and sabatogue quota. \
			Their operations can vary from covert to all-out. They recently stepped down as the leaders of the coalition, to be succeeded by Cybersun Industries. Because of their \
			hate of Nanotrasen communism, they began provoking revolution amongst the employees using borrowed Cybersun mind-manipulation technology. \
			They were founded when Waffle and Donk co splinter cells joined forces based on their similar interests and philosophies. Today, they act as a constant \
			pacifier of Donk and Waffle co disputes, and full-time aggressor of Nanotrasen."

	alliances = list("Cybersun Industries", "MI13", "Tiger Cooperative", "S.E.L.F.", "Animal Rights Consortium", "Donk Corporation", "Waffle Corporation")
	friendly_identification = 1
	max_op = 4
	operative_notes = "We'd like to remind our operatives to keep it professional. You are not here to have a good time, you are here to accomplish your objectives. These vile communists must be stopped at all costs. You may collaborate with any friends of the Syndicate coalition, but keep an eye on any of those Tiger punks if they do show up. You are completely free to accomplish your objectives any way you see fit."

	// Friendly to everyone. (with Tiger Cooperative too, only because they are a member of the coalition. This is the only reason why the Tiger Cooperative are even allowed in the coalition)

/datum/faction/syndicate/Donk
	name = "Donk Corporation"
	desc = "Donk.co is led by a group of ex-pirates, who used to be at a state of all-out war against Waffle.co because of an obscure political scandal, but have recently come to a war limitation. \
			They now consist of a series of colonial governments and companies. They were the first to officially begin confrontations against Nanotrasen because of an incident where \
			Nanotrasen purposely swindled them out of a fortune, sending their controlled colonies into a terrible poverty. Their missions against Nanotrasen \
			revolve around stealing valuables and kidnapping and executing key personnel, ransoming their lives for money. They merged with a splinter-cell of Waffle.co who wanted to end \
			hostilities and formed the Gorlex Marauders."

	alliances = list("Gorlex Marauders")
	friendly_identification = 2
	operative_notes = "Most other syndicate operatives are not to be trusted, except fellow Donk members and members of the Gorlex Marauders. We do not approve of mindless killing of innocent workers; \"get in, get done, get out\" is our motto. Members of Waffle.co are to be killed on sight; they are not allowed to be on the station while we're around."

	// Neutral to everyone, friendly to Marauders

/datum/faction/syndicate/Waffle
	name = "Waffle Corporation"
	desc = "Waffle.co is an interstellar company that produces the best waffles in the galaxy. Their waffles have been rumored to be dipped in the most exotic and addictive \
			drug known to man. They were involved in a political scandal with Donk.co, and have since been in constant war with them. Because of their constant exploits of the galactic \
			economy and stock market, they have been able to bribe their way into amassing a large arsenal of weapons of mass destruction. They target Nanotrasen because of their communistic \
			threat, and their economic threat. Their leaders often have a twisted sense of humor, often misleading and intentionally putting their operatives into harm for laughs.\
			A splinter-cell of Waffle.co merged with Donk.co and formed the Gorlex Marauders and have been a constant ally since. The Waffle.co has lost an overwhelming majority of its military to the Gorlex Marauders."

	alliances = list("Gorlex Marauders")
	friendly_identification = 2
	operative_notes = "Most other syndicate operatives are not to be trusted, except for members of the Gorlex Marauders. Do not trust fellow members of the Waffle.co (but try not to rat them out), as they might have been assigned opposing objectives. We encourage humorous terrorism against Nanotrasen; we like to see our operatives creatively kill people while getting the job done."

	// Neutral to everyone, friendly to Marauders

/* ----- Begin defining miscellaneous factions ------ */

/datum/faction/Wizard
	name = "Wizards Federation"
	desc = "The Wizards Federation is a mysterious organization of magically-talented individuals who act as an equal collective, and have no heirarchy. It is unknown how the wizards \
			are even able to communicate; some suggest a form of telepathic hive-mind. Not much is known about the wizards or their philosphies and motives. They appear to attack random \
			civilian, corporate, planetary, orbital, pretty much any sort of organized facility they come across. Members of the Wizards Federation are considered amongst the most dangerous \
			individuals in the known universe, and have been labeled threats to humanity by most governments. As such, they are enemies of both Nanotrasen and the Syndicate."

/datum/faction/Cult
	name = "The Cult of the Elder Gods"
	desc = "The Cult of the Elder Gods is highly untrusted but otherwise elusive religious organization bent on the revival of the so-called \"Elder Gods\" into the mortal realm. Despite their obvious dangeorus practices, \
			no confirmed reports of violence by members of the Cult have been reported, only rumor and unproven claims. Their nature is unknown, but recent discoveries have hinted to the possibility \
			of being able to de-convert members of this cult through what has been dubbed \"religious warfare\"."

// These can maybe be added into a game mode or a mob?

/datum/faction/Exolitics
	name = "Exolitics United"
	desc = "The Exolitics are an ancient alien race with an energy-based anatomy. Their culture, communication, morales and knowledge is unknown. They are so radically different to humans that their \
			attempts of communication with other life forms is completely incomprehensible. Members of this alien race are capable of broadcasting subspace transmissions from their bodies. \
			The religious leaders of the Tiger Cooperative claim to have the technology to decypher and interpret their messages, which have been confirmed as religious propaganda. Their motives are unknown \
			but they are otherwise not considered much of a threat to anyone. They are virtually indestructable because of their nonphysical composition, and have the frighetning ability to make anything stop existing in a second."


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

/*
 * GAMEMODES (by Rastaf0)
 *
 * In the new mode system all special roles are fully supported.
 * You can have proper wizards/traitors/changelings/cultists during any mode.
 * Only two things really depends on gamemode:
 * 1. Starting roles, equipment and preparations
 * 2. Conditions of finishing the round.
 *
 */

/datum/game_mode
	var/name = "invalid"
	var/config_tag = null
	var/votable = 1
	var/probability = 1
	var/station_was_nuked = 0 //see nuclearbomb.dm and malfunction.dm
	var/explosion_in_progress = 0 //sit back and relax
	var/list/datum/mind/modePlayer = new
	var/list/datum/mind/antag_candidates = list()	// List of possible starting antags goes here
	var/list/restricted_jobs = list()	// Jobs it doesn't make sense to be.  I.E chaplain or AI cultist
	var/list/protected_jobs = list()	// Jobs that can't be traitors because
	var/required_players = 0
	var/required_enemies = 0
	var/recommended_enemies = 0
	var/pre_setup_before_jobs = 0
	var/antag_flag = null //preferences flag such as BE_WIZARD that need to be turned on for players to be antag
	var/datum/mind/sacrifice_target = null
	var/list/datum/game_mode/replacementmode = null
	var/round_converted = 0 //0: round not converted, 1: round going to convert, 2: round converted
	var/reroll_friendly 	//During mode conversion only these are in the running
	var/enemy_minimum_age = 7 //How many days must players have been playing before they can play this antagonist

	var/const/waittime_l = 600
	var/const/waittime_h = 1800 // started at 1800

/datum/game_mode/proc/announce() //to be calles when round starts
	world << "Notice: [src] did not define announce()"

///can_start()
///Checks to see if the game can be setup and ran with the current number of players or whatnot.
/datum/game_mode/proc/can_start()
	var/playerC = 0
	for(var/mob/new_player/player in player_list)
		if((player.client)&&(player.ready))
			playerC++
	if(!Debug2)
		if(playerC < required_players)
			return 0
	antag_candidates = get_players_for_role(antag_flag)
	if(!Debug2)
		if(antag_candidates.len < required_enemies)
			return 0
		return 1
	else
		world << "DEBUG: GAME STARTING WITHOUT PLAYER NUMBER CHECKS, THIS WILL PROBABLY BREAK SHIT."
		return 1

///pre_setup()
///Attempts to select players for special roles the mode might have.
/datum/game_mode/proc/pre_setup()
	return 1

///post_setup()
///Everyone should now be on the station and have their normal gear.  This is the place to give the special roles extra things
/datum/game_mode/proc/post_setup(var/report=1)
	spawn (ROUNDSTART_LOGOUT_REPORT_TIME)
		display_roundstart_logout_report()

	feedback_set_details("round_start","[time2text(world.realtime)]")
	if(ticker && ticker.mode)
		feedback_set_details("game_mode","[ticker.mode]")
	if(revdata.revision)
		feedback_set_details("revision","[revdata.revision]")
	feedback_set_details("server_ip","[world.internet_address]:[world.port]")
	if(report)
		spawn (rand(waittime_l, waittime_h))
			send_intercept(0)
	start_state = new /datum/station_state()
	start_state.count()
	for (var/mob/living/carbon/human/M in world)
		spawn (0)
			M.regenerate_icons()
	return 1

///make_antag_chance()
///Handles late-join antag assignments
/datum/game_mode/proc/make_antag_chance(var/mob/living/carbon/human/character)
	if(replacementmode && round_converted == 2)
		replacementmode.make_antag_chance(character)
	return

///convert_roundtype()
///Allows rounds to basically be "rerolled" should the initial premise fall through
/datum/game_mode/proc/convert_roundtype()
	var/list/datum/game_mode/runnable_modes = config.get_runnable_modes()
	for(var/datum/game_mode/G in runnable_modes)
		if(!G.reroll_friendly)	del(G)

	SSshuttle.emergencyNoEscape = 0 //Time to get the fuck out of here

	if(!runnable_modes)	return 0

	replacementmode = pickweight(runnable_modes)

	switch(SSshuttle.emergency.mode) //Rounds on the verge of ending don't get new antags, they just run out
		if(SHUTTLE_STRANDED, SHUTTLE_ESCAPE)
			return 1
		if(SHUTTLE_CALL)
			if(SSshuttle.emergency.timeLeft(1) < initial(SSshuttle.emergencyCallTime)*0.5)
				return 1

	if(world.time >= (config.midround_antag_time_check * 600))
		return 0

	var/living_crew = 0

	for(var/mob/Player in mob_list)
		if(Player.mind && Player.stat != DEAD && !isnewplayer(Player) &&!isbrain(Player))
			living_crew++
	if(living_crew / joined_player_list.len <= config.midround_antag_life_check) //If a lot of the player base died, we start fresh
		return 0

	var/list/antag_canadates = list()

	for(var/mob/living/carbon/human/H in living_crew)
		if(H.client && H.client.prefs.allow_midround_antag)
			antag_canadates += H

	if(!antag_canadates)
		return 0

	antag_canadates = shuffle(antag_canadates)

	if(config.protect_roles_from_antagonist)
		replacementmode.restricted_jobs += replacementmode.protected_jobs
	if(config.protect_assistant_from_antagonist)
		replacementmode.restricted_jobs += "Assistant"

	message_admins("The roundtype will be converted. If you feel that the round should not continue, end the round now.")

	spawn(rand(1800,4200)) //somewhere between 3 and 7 minutes from now
		for(var/mob/living/carbon/human/H in antag_canadates)
			replacementmode.make_antag_chance(H)
		round_converted = 2
		message_admins("The roundtype has been converted, antagonists may have been created")

	return 1

///process()
///Called by the gameticker
/datum/game_mode/process()
	return 0

/datum/game_mode/proc/check_finished() //to be called by ticker
	if(SSshuttle.emergency.mode >= SHUTTLE_ENDGAME || station_was_nuked)
		return 1
	return 0

/datum/game_mode/proc/declare_completion()
	send2irc("Server", "Round just ended.")
	return 0

/datum/game_mode/proc/check_win() //universal trigger to be called at mob death, nuke explosion, etc. To be called from everywhere.
	return 0

/datum/game_mode/proc/send_intercept()
	var/intercepttext = "Centcom Update Requested staus information:
"
	intercepttext += " Centcom has recently been contacted by the following syndicate affiliated organisations in your area, please investigate any information you may have:"

	var/list/possible_modes = list()
	possible_modes.Add("revolution", "wizard", "nuke", "traitor", "malf", "changeling", "cult")
	possible_modes -= "[ticker.mode]" //remove current gamemode to prevent it from being randomly deleted, it will be readded later

	var/number = pick(1, 2)
	var/i = 0
	for(i = 0, i < number, i++) //remove 1 or 2 possibles modes from the list
		possible_modes.Remove(pick(possible_modes))

	possible_modes[rand(1, possible_modes.len)] = "[ticker.mode]" //replace a random game mode with the current one

	possible_modes = shuffle(possible_modes) //shuffle the list to prevent meta

	var/datum/intercept_text/i_text = new /datum/intercept_text
	for(var/A in possible_modes)
		if(modePlayer.len == 0)
			intercepttext += i_text.build(A)
		else
			intercepttext += i_text.build(A, pick(modePlayer))

	print_command_report(intercepttext,"Centcom Status Summary")
	priority_announce("Summary downloaded and printed out at all communications consoles.", "Enemy communication intercept. Security Level Elevated.", 'sound/AI/intercept.ogg')
	if(security_level < SEC_LEVEL_BLUE)
		set_security_level(SEC_LEVEL_BLUE)

/datum/game_mode/proc/get_players_for_role(var/role)
	var/list/players = list()
	var/list/candidates = list()
	var/list/drafted = list()
	var/datum/mind/applicant = null

	var/roletext
	switch(role)
		if(BE_CHANGELING)	roletext="changeling"
		if(BE_TRAITOR)		roletext="traitor"
		if(BE_OPERATIVE)	roletext="operative"
		if(BE_WIZARD)		roletext="wizard"
		if(BE_REV)			roletext="revolutionary"
		if(BE_GANG)			roletext="gangster"
		if(BE_CULTIST)		roletext="cultist"
		if(BE_MONKEY)		roletext="monkey"
		if(BE_ABDUCTOR)		roletext="abductor"
		if(BE_SHADOWLING)	roletext="shadowling"

	// Ultimate randomizing code right here
	for(var/mob/new_player/player in player_list)
		if(player.client && player.ready)
			players += player

	// Shuffling, the players list is now ping-independent!!!
	// Goodbye antag dante
	players = shuffle(players)

	for(var/mob/new_player/player in players)
		if(player.client && player.ready)
			if(player.client.prefs.be_special & role)
				if(!jobban_isbanned(player, "Syndicate") && !jobban_isbanned(player, roletext)) //Nodrak/Carn: Antag Job-bans
					if(age_check(player.client)) //Must be older than the minimum age
						candidates += player.mind				// Get a list of all the people who want to be the antagonist for this round

	if(restricted_jobs)
		for(var/datum/mind/player in candidates)
			for(var/job in restricted_jobs)					// Remove people who want to be antagonist but have a job already that precludes it
				if(player.assigned_role == job)
					candidates -= player

	if(candidates.len < recommended_enemies)
		for(var/mob/new_player/player in players)
			if(player.client && player.ready)
				if(!(player.client.prefs.be_special & role)) // We don't have enough people who want to be antagonist, make a seperate list of people who don't want to be one
					if(!jobban_isbanned(player, "Syndicate") && !jobban_isbanned(player, roletext)) //Nodrak/Carn: Antag Job-bans
						drafted += player.mind

	if(restricted_jobs)
		for(var/datum/mind/player in drafted)				// Remove people who can't be an antagonist
			for(var/job in restricted_jobs)
				if(player.assigned_role == job)
					drafted -= player

	drafted = shuffle(drafted) // Will hopefully increase randomness, Donkie

	while(candidates.len < recommended_enemies)				// Pick randomlly just the number of people we need and add them to our list of candidates
		if(drafted.len > 0)
			applicant = pick(drafted)
			if(applicant)
				candidates += applicant
				drafted.Remove(applicant)

		else												// Not enough scrubs, ABORT ABORT ABORT
			break
/*
	if(candidates.len < recommended_enemies && override_jobbans) //If we still don't have enough people, we're going to start drafting banned people.
		for(var/mob/new_player/player in players)
			if (player.client && player.ready)
				if(jobban_isbanned(player, "Syndicate") || jobban_isbanned(player, roletext)) //Nodrak/Carn: Antag Job-bans
					drafted += player.mind
*/
	if(restricted_jobs)
		for(var/datum/mind/player in drafted)				// Remove people who can't be an antagonist
			for(var/job in restricted_jobs)
				if(player.assigned_role == job)
					drafted -= player

	drafted = shuffle(drafted) // Will hopefully increase randomness, Donkie

	while(candidates.len < recommended_enemies)				// Pick randomlly just the number of people we need and add them to our list of candidates
		if(drafted.len > 0)
			applicant = pick(drafted)
			if(applicant)
				candidates += applicant
				drafted.Remove(applicant)

		else												// Not enough scrubs, ABORT ABORT ABORT
			break

	return candidates		// Returns: The number of people who had the antagonist role set to yes, regardless of recomended_enemies, if that number is greater than recommended_enemies
							//			recommended_enemies if the number of people with that role set to yes is less than recomended_enemies,
							//			Less if there are not enough valid players in the game entirely to make recommended_enemies.

/*
/datum/game_mode/proc/check_player_role_pref(var/role, var/mob/new_player/player)
	if(player.preferences.be_special & role)
		return 1
	return 0
*/

/datum/game_mode/proc/num_players()
	. = 0
	for(var/mob/new_player/P in player_list)
		if(P.client && P.ready)
			. ++

///////////////////////////////////
//Keeps track of all living heads//
///////////////////////////////////
/datum/game_mode/proc/get_living_heads()
	var/list/heads = list()
	for(var/mob/living/carbon/human/player in mob_list)
		if(player.stat!=2 && player.mind && (player.mind.assigned_role in command_positions))
			heads += player.mind
	return heads

////////////////////////////
//Keeps track of all heads//
////////////////////////////
/datum/game_mode/proc/get_all_heads()
	var/list/heads = list()
	for(var/mob/player in mob_list)
		if(player.mind && (player.mind.assigned_role in command_positions))
			heads += player.mind
	return heads

//////////////////////////
//Reports player logouts//
//////////////////////////
proc/display_roundstart_logout_report()
	var/msg = "Roundstart logout report\n\n"
	for(var/mob/living/L in mob_list)

		if(L.ckey)
			var/found = 0
			for(var/client/C in clients)
				if(C.ckey == L.ckey)
					found = 1
					break
			if(!found)
				msg += "[L.name] ([L.ckey]), the [L.job] (Disconnected)\n"

		if(L.ckey && L.client)
			if(L.client.inactivity >= (ROUNDSTART_LOGOUT_REPORT_TIME / 2))	//Connected, but inactive (alt+tabbed or something)
				msg += "[L.name] ([L.ckey]), the [L.job] (Connected, Inactive)\n"
				continue //AFK client
			if(L.stat)
				if(L.suiciding)	//Suicider
					msg += "[L.name] ([L.ckey]), the [L.job] (Suicide)\n"
					continue //Disconnected client
				if(L.stat == UNCONSCIOUS)
					msg += "[L.name] ([L.ckey]), the [L.job] (Dying)\n"
					continue //Unconscious
				if(L.stat == DEAD)
					msg += "[L.name] ([L.ckey]), the [L.job] (Dead)\n"
					continue //Dead

			continue //Happy connected client
		for(var/mob/dead/observer/D in mob_list)
			if(D.mind && D.mind.current == L)
				if(L.stat == DEAD)
					if(L.suiciding)	//Suicider
						msg += "[L.name] ([ckey(D.mind.key)]), the [L.job] (Suicide)\n"
						continue //Disconnected client
					else
						msg += "[L.name] ([ckey(D.mind.key)]), the [L.job] (Dead)\n"
						continue //Dead mob, ghost abandoned
				else
					if(D.can_reenter_corpse)
						msg += "[L.name] ([ckey(D.mind.key)]), the [L.job] (This shouldn't appear.)\n"
						continue //Lolwhat
					else
						msg += "[L.name] ([ckey(D.mind.key)]), the [L.job] (Ghosted)\n"
						continue //Ghosted while alive

	for(var/mob/M in mob_list)
		if(M.client && M.client.holder)
			M << msg

/datum/game_mode/proc/printplayer(var/datum/mind/ply)
	var/role = "\improper[ply.assigned_role]"
	var/text = "
[ply.name]([ply.key]) as \a [role] ("
	if(ply.current)
		if(ply.current.stat == DEAD)
			text += "died"
		else
			text += "survived"
		if(ply.current.real_name != ply.name)
			text += " as [ply.current.real_name]"
	else
		text += "body destroyed"
	text += ")"

	return text

//If the configuration option is set to require players to be logged as old enough to play certain jobs, then this proc checks that they are, otherwise it just returns 1
/datum/game_mode/proc/age_check(client/C)
	if(get_remaining_days(C) == 0)
		return 1	//Available in 0 days = available right now = player is old enough to play.
	return 0

/datum/game_mode/proc/get_remaining_days(client/C)
	if(!C)
		return 0
	if(!config.use_age_restriction_for_jobs)
		return 0
	if(!isnum(C.player_age))
		return 0 //This is only a number if the db connection is established, otherwise it is text: "Requires database", meaning these restrictions cannot be enforced
	if(!isnum(enemy_minimum_age))
		return 0

	return max(0, enemy_minimum_age - C.player_age)


code:
//gang.dm
//Gang War Game Mode

/datum/game_mode
	var/list/datum/mind/A_bosses = list() //gang A bosses
	var/list/datum/mind/A_gangsters = list() //gang A Members
	var/list/datum/mind/B_bosses = list() //gang B bosses
	var/list/datum/mind/B_gangsters = list() //gang B Members

/datum/game_mode/gang
	name = "gang war"
	config_tag = "gang"
	antag_flag = BE_GANG
	restricted_jobs = list("Security Officer", "Warden", "Detective", "AI", "MoMMI",  "Cyborg","Captain", "Head of Personnel", "Head of Security", "Chief Engineer", "Research Director", "Chief Medical Officer")
	required_players = 20
	required_enemies = 2
	recommended_enemies = 2
	enemy_minimum_age = 14

	var/finished = 0
	var/checkwin_counter = 0
///////////////////////////
//Announces the game type//
///////////////////////////
/datum/game_mode/gang/announce()
	world << "The current game mode is - Gang War!"
	world << "A violent turf war has erupted on the station!
Gangsters -  Take over the station by recruiting gangsters and killing the rival gang's boss!
Crew - Identify and stop the mob bosses without killing either of them!"

///////////////////////////////////////////////////////////////////////////////
//Gets the round setup, cancelling if there's not enough players at the start//
///////////////////////////////////////////////////////////////////////////////
/datum/game_mode/gang/pre_setup()
	if(config.protect_roles_from_antagonist)
		restricted_jobs += protected_jobs

	if(config.protect_assistant_from_antagonist)
		restricted_jobs += "Assistant"

	if(antag_candidates.len >= 2)
		assign_bosses()

	if(!A_bosses.len || !B_bosses.len)
		return 0

	return 1

/datum/game_mode/gang/post_setup()
	spawn(rand(10,100))
		for(var/datum/mind/boss_mind in A_bosses)
			update_gang_icons_added(boss_mind, "A")
			forge_gang_objectives(boss_mind, "A")
			greet_gang(boss_mind)
			equip_gang(boss_mind.current)

		for(var/datum/mind/boss_mind in B_bosses)
			update_gang_icons_added(boss_mind, "B")
			forge_gang_objectives(boss_mind, "B")
			greet_gang(boss_mind)
			equip_gang(boss_mind.current)

	modePlayer += A_bosses
	modePlayer += B_bosses
	..()

/datum/game_mode/gang/process()
	checkwin_counter++
	if(checkwin_counter >= 5)
		if(!finished)
			ticker.mode.check_win()
		checkwin_counter = 0
	return 0

/datum/game_mode/gang/proc/assign_bosses()
	var/datum/mind/boss = pick(antag_candidates)
	A_bosses += boss
	boss.restricted_roles = restricted_jobs
	antag_candidates -= boss
	boss.special_role = "[gang_name("A")] Gang (A) Boss"
	log_game("[boss.key] has been selected as a boss for the [gang_name("A")] Gang (A)")

	boss = pick(antag_candidates)
	B_bosses += boss
	boss.restricted_roles = restricted_jobs
	antag_candidates -= boss
	boss.special_role = "[gang_name("B")] Gang (B) Boss"
	log_game("[boss.key] has been selected as a boss for the [gang_name("B")] Gang (B)")

/datum/game_mode/proc/forge_gang_objectives(var/datum/mind/boss_mind)
	var/datum/objective/rival_obj = new
	rival_obj.owner = boss_mind
	rival_obj.explanation_text = "Assassinate or exile the [(boss_mind in A_bosses) ? gang_name("B") : gang_name("A")] Gang's bosses."
	boss_mind.objectives += rival_obj

/datum/game_mode/proc/greet_gang(var/datum/mind/boss_mind, var/you_are=1)
	var/obj_count = 1
	if (you_are)
		boss_mind.current << "You are a [(boss_mind in A_bosses) ? gang_name("A") : gang_name("B")] Gang Boss!"
	for(var/datum/objective/objective in boss_mind.objectives)
		boss_mind.current << "Objective #[obj_count]: [objective.explanation_text]"
		obj_count++

///////////////////////////////////////////////////////////////////////////
//This equips the bosses with their gear, and makes the clown not clumsy//
///////////////////////////////////////////////////////////////////////////
/datum/game_mode/proc/equip_gang(mob/living/carbon/human/mob)
	if(!istype(mob))
		return

	if (mob.mind)
		if (mob.mind.assigned_role == "Clown")
			mob << "Your training has allowed you to overcome your clownish nature, allowing you to wield weapons without harming yourself."
			mob.dna.remove_mutation(CLOWNMUT)

	// find a radio! toolbox(es), backpack, belt, headset
	var/loc = ""
	var/obj/item/R = locate(/obj/item/device/pda) in mob.contents //Hide the uplink in a PDA if available, otherwise radio
	if(!R)
		R = locate(/obj/item/device/radio) in mob.contents

	if (!R)
		mob << "Unfortunately, Your Syndicate benefactors wasn't able to get you an uplink."
		. = 0
	else
		if (istype(R, /obj/item/device/radio))
			// generate list of radio freqs
			var/obj/item/device/radio/target_radio = R
			var/freq = 1441
			var/list/freqlist = list()
			while (freq <= 1489)
				if (freq < 1451 || freq > 1459)
					freqlist += freq
				freq += 2
				if ((freq % 2) == 0)
					freq += 1
			freq = freqlist[rand(1, freqlist.len)]

			var/obj/item/device/uplink/hidden/T = new(R)
			target_radio.hidden_uplink = T
			T.uplink_owner = "[mob.key]"
			target_radio.traitor_frequency = freq
			mob << "Your Syndicate benefactors have cunningly disguised a Syndicate Uplink as your [R.name] [loc]. Simply dial the frequency [format_frequency(freq)] to unlock its hidden features."
			mob.mind.store_memory("Radio Freq: [format_frequency(freq)] ([R.name] [loc]).")
		else if (istype(R, /obj/item/device/pda))
			// generate a passcode if the uplink is hidden in a PDA
			var/pda_pass = "[rand(100,999)] [pick("Alpha","Bravo","Delta","Omega")]"

			var/obj/item/device/uplink/hidden/T = new(R)
			R.hidden_uplink = T
			T.uplink_owner = "[mob.key]"
			var/obj/item/device/pda/P = R
			P.lock_code = pda_pass

			mob << "Your Syndicate benefactors have cunningly disguised a Syndicate Uplink as your [R.name] [loc]. Simply enter the code \"[pda_pass]\" into the ringtone select to unlock its hidden features."
			mob.mind.store_memory("Uplink Passcode: [pda_pass] ([R.name] [loc]).")

	var/obj/item/device/flash/T = new(mob)
	var/obj/item/device/recaller/recaller = new(mob)

	var/list/slots = list (
		"backpack" = slot_in_backpack,
		"left pocket" = slot_l_store,
		"right pocket" = slot_r_store,
		"left hand" = slot_l_hand,
		"right hand" = slot_r_hand,
	)

	. = 0

	var/where2 = mob.equip_in_one_of_slots(recaller, slots)
	if (!where2)
		mob << "Your Syndicate benefactors were unfortunately unable to get you a Recaller."
	else
		mob << "The Recaller in your [where2] will allow you to prevent the station from prematurely evacuating. Use it to recall the emergency shuttle from anywhere on the station."
		. += 2

	var/where = mob.equip_in_one_of_slots(T, slots)
	if (!where)
		mob << "Your Syndicate benefactors were unfortunately unable to get you a flash."
	else
		mob << "The flash in your [where] will help you to persuade the crew to work for you."
		. += 1

	mob.update_icons()

	return .

/////////////////////////////////////////////
//Checks if the either gang have won or not//
/////////////////////////////////////////////
/datum/game_mode/gang/check_win()
	var/A_victory = check_gang_victory(B_bosses) //Check if B bosses are dead or exiled
	var/B_victory = check_gang_victory(A_bosses) //Check if A bosses are dead or exiled

	if(A_victory && B_victory)
		finished = "Draw" //Both teams fail. Allow for draws in case they're all incapacitated at the same time.

	else if(A_victory)
		finished = "A" //Gang A wins

	else if(B_victory)
		finished = "B" //Gang B wins

///////////////////////////////
//Checks if the round is over//
///////////////////////////////
/datum/game_mode/gang/check_finished()
	if(finished && !config.continuous_round_gang) //Check for Gang Boss death
		return 1
	return ..() //Check for evacuation/nuke

///////////////////////////////////////////
//Deals with converting players to a gang//
///////////////////////////////////////////
/datum/game_mode/proc/add_gangster(datum/mind/gangster_mind, var/gang, var/check = 1)
	if(check && isloyal(gangster_mind.current)) //Check to see if the potential gangster is implanted
		return 0
	if((gangster_mind in A_bosses) || (gangster_mind in A_gangsters) || (gangster_mind in B_bosses) || (gangster_mind in B_gangsters))
		return 0
	if(gang == "A")
		A_gangsters += gangster_mind
	else
		B_gangsters += gangster_mind
	if(check)
		gangster_mind.current.Paralyse(5)
	gangster_mind.current << "You are now a member of the [gang=="A" ? gang_name("A") : gang_name("B")] Gang!"
	gangster_mind.current << "Help your Boss take over the station by defeating the rival gang. You can identify your Boss by their brown \"B\" icon."
	gangster_mind.current.attack_log += "\[[time_stamp()]\] Has been converted to the [gang=="A" ? "[gang_name("A")] Gang (A)" : "[gang_name("B")] Gang (B)"]!"
	gangster_mind.special_role = "[gang=="A" ? "[gang_name("A")] Gang (A)" : "[gang_name("B")] Gang (B)"]"
	update_gang_icons_added(gangster_mind,gang)
	return 1
//////////////////////////////////////////////////////////////
//Deals with players going straight (Not a gangster anymore)//
//////////////////////////////////////////////////////////////
/datum/game_mode/proc/remove_gangster(datum/mind/gangster_mind, var/beingborged, var/silent, var/exclude_bosses=0)
	var/gang

	if(!exclude_bosses)
		if(gangster_mind in A_bosses)
			A_bosses -= gangster_mind
			gang = "A"

		if(gangster_mind in B_bosses)
			B_bosses -= gangster_mind
			gang = "B"

	if(gangster_mind in A_gangsters)
		A_gangsters -= gangster_mind
		gang = "A"

	if(gangster_mind in B_gangsters)
		B_gangsters -= gangster_mind
		gang = "B"

	if(!gang) //not a valid gangster
		return

	gangster_mind.special_role = null
	if(silent < 2)
		gangster_mind.current.attack_log += "\[[time_stamp()]\] Has reformed and defected from the [gang=="A" ? "[gang_name("A")] Gang (A)" : "[gang_name("B")] Gang (B)"]!"

		if(beingborged)
			if(!silent)
				gangster_mind.current.visible_message("The frame beeps contentedly from the MMI before initalizing it.")
			gangster_mind.current << "The frame's firmware detects and deletes your criminal behavior! You are no longer a gangster!"
			message_admins("[key_name_admin(gangster_mind.current)] ? has been borged while being a member of the [gang=="A" ? "[gang_name("A")] Gang (A)" : "[gang_name("B")] Gang (B)"] Gang. They are no longer a gangster.")
		else
			if(!silent)
				gangster_mind.current.Paralyse(5)
				gangster_mind.current.visible_message("[gangster_mind.current] looks like they've given up the life of crime!")
			gangster_mind.current << "You have been reformed! You are no longer a gangster!"

	update_gang_icons_removed(gangster_mind, gang)

///////////////////////
//Add/remove gang HUD//
///////////////////////
/datum/game_mode/proc/get_gang_hud(var/gang)
	var/datum/atom_hud/antag/ganghud = null
	switch(gang)
		if("A") ganghud = huds[ANTAG_HUD_GANG_A]
		if("B") ganghud = huds[ANTAG_HUD_GANG_B]
	return ganghud

/datum/game_mode/proc/get_gang_bosses(var/gang)
	var/bosses = null
	switch(gang)
		if("A") bosses = A_bosses
		if("B") bosses = B_bosses
	return bosses

/datum/game_mode/proc/update_gang_icons_added(datum/mind/recruit_mind, var/gang)
	var/datum/atom_hud/antag/ganghud = get_gang_hud(gang)
	var/bosses = get_gang_bosses(gang)
	if(!ganghud)
		ERROR("Invalid gang in update_gang_icons_added(): [gang]")

	ganghud.join_hud(recruit_mind.current)
	set_antag_hud(recruit_mind.current, ((recruit_mind in bosses) ? "gang_boss" : "gangster"))

/datum/game_mode/proc/update_gang_icons_removed(datum/mind/defector_mind, var/gang)
	var/datum/atom_hud/antag/ganghud = get_gang_hud(gang)
	if(!ganghud)
		ERROR("Invalid gang in update_gang_icons_removed(): [gang]")

	ganghud.leave_hud(defector_mind.current)
	set_antag_hud(defector_mind.current, null)

///////////////////////////
//Checks for gang victory//
///////////////////////////
/datum/game_mode/gang/proc/check_gang_victory(var/list/boss_list)
	if(!boss_list.len)
		return 0
	for(var/datum/mind/boss_mind in boss_list)
		if(boss_mind.current)
			if(boss_mind.current.stat == DEAD || !ishuman(boss_mind.current) || !boss_mind.current.ckey)
				return 1
			var/turf/T = get_turf(boss_mind.current)
			if(T && (T.z != ZLEVEL_STATION))			//If they leave the station they count as dead for this
				return 1
			return 0
		return 1

//////////////////////////////////////////////////////////////////////
//Announces the end of the game with all relavent information stated//
//////////////////////////////////////////////////////////////////////
/datum/game_mode/gang/declare_completion()
	if(!finished)
		world << "The station was [station_was_nuked ? "destroyed!" : "evacuated before either gang could claim it!"]"
	else if(finished == "Draw")
		world << "All gang bosses have been killed or exiled!"
	else
		world << "The [finished=="A" ? gang_name("A") : gang_name("B")] Gang defeated their rivals!"
	..()
	return 1

/datum/game_mode/proc/auto_declare_completion_gang()
	var/winner
	var/datum/game_mode/gang/game_mode = ticker.mode
	if(istype(game_mode))
		if(game_mode.finished)
			winner = game_mode.finished
		else
			winner = "Draw"

	var/num_ganga = 0
	var/list/agang = A_gangsters + A_bosses
	for(var/datum/mind/agangster in agang)
		if(agangster.current)
			if(agangster.current in living_mob_list)
				num_ganga++

	var/num_gangb = 0
	var/list/bgang = B_gangsters + B_bosses
	for(var/datum/mind/bgangster in bgang)
		if(bgangster.current)
			if(bgangster.current in living_mob_list)
				num_gangb++

	if(A_bosses.len || A_gangsters.len)
		if(winner)
			world << "
The [gang_name("A")] Gang was [winner=="A" ? "victorious" : "defeated"] with [num_ganga] members!"
		world << "
The [gang_name("A")] Gang Boss was:"
		gang_membership_report(A_bosses)
		world << "
The [gang_name("A")] Gangsters were:"
		gang_membership_report(A_gangsters)
		world << "
"

	if(B_bosses.len || B_gangsters.len)
		if(winner)
			world << "
The [gang_name("B")] Gang was [winner=="B" ? "victorious" : "defeated"] with [num_gangb] members!"
		world << "
The [gang_name("B")] Gang Boss was:"
		gang_membership_report(B_bosses)
		world << "
The [gang_name("B")] Gangsters were:"
		gang_membership_report(B_gangsters)
		world << "
"

/datum/game_mode/proc/gang_membership_report(var/list/membership)
	var/text = ""
	for(var/datum/mind/gang_mind in membership)
		text += "
[gang_mind.key] was [gang_mind.name] ("
		if(gang_mind.current)
			if(gang_mind.current.stat == DEAD || isbrain(gang_mind.current))
				text += "died"
			else if(gang_mind.current.z != ZLEVEL_STATION)
				text += "fled the station"
			else
				text += "survived"
			if(gang_mind.current.real_name != gang_mind.name)
				text += " as [gang_mind.current.real_name]"
		else
			text += "body destroyed"
		text += ")"

	world << text