anchor.diff:  		add_load(active_power_usage)
   		fire_beam()
   
  -/obj/machinery/power/emitter/proc/fire_beam()
  -	src.last_shot = world.time
  -	if(src.shot_number < 3)
  -		src.fire_delay = 20
  -		src.shot_number ++
  -	else
  -		src.fire_delay = rand(minimum_fire_delay,maximum_fire_delay)
  -		src.shot_number = 0
  -	var/obj/item/projectile/A = new projectile_type(src.loc)
  -	A.setDir(src.dir)
  -	playsound(src.loc, projectile_sound, 25, 1)
  +/obj/machinery/power/emitter/proc/fire_beam(atom/targeted_atom, mob/user)
  +	var/turf/targets_from = get_turf(src)
  +	var/obj/item/projectile/P = new projectile_type(targets_from)
  +	playsound(src.loc, projectile_sound, 50, 1)
   	if(prob(35))
   		var/datum/effect_system/spark_spread/s = new /datum/effect_system/spark_spread
   		s.set_up(5, 1, src)
   		s.start()
   	switch(dir)
   		if(NORTH)
  -			A.yo = 20
  -			A.xo = 0
  +			P.yo = 20
  +			P.xo = 0
   		if(EAST)
  -			A.yo = 0
  -			A.xo = 20
  +			P.yo = 0
  +			P.xo = 20
   		if(WEST)
  -			A.yo = 0
  -			A.xo = -20
  +			P.yo = 0
  +			P.xo = -20
   		else // Any other
  -			A.yo = -20
  -			A.xo = 0
  -	A.starting = loc
  -	A.fire()
  +			P.yo = -20
  +			P.xo = 0
  +	if(!manual)
  +		src.last_shot = world.time
  +		if(src.shot_number < 3)
  +			src.fire_delay = 20
  +			src.shot_number ++
  +		else
  +			src.fire_delay = rand(minimum_fire_delay,maximum_fire_delay)
  +			src.shot_number = 0
  +		if(!target)
  +			P.setDir(src.dir)
  +			P.starting = loc
  +			P.fire()
  +		else
  +			P.yo = targeted_atom.y - targets_from.y
  +			P.xo = targeted_atom.x - targets_from.x
  +			P.current = targets_from
  +			P.starting = targets_from
  +			P.firer = src
  +			P.original = target
  +			P.fire()
  +			return P
  +	else
  +		if(targeted_atom == user|| targeted_atom == targets_from)
  +			return
  +		P.yo = targeted_atom.y - targets_from.y
  +		P.xo = targeted_atom.x - targets_from.x
  +		P.current = targets_from
  +		P.starting = targets_from
  +		P.firer = src
  +		P.original = targeted_atom
  +		P.fire()
  +		return P
   
   /obj/machinery/power/emitter/can_be_unfasten_wrench(mob/user, silent)
   	if(state == EM_WELDED)
  
positive.code: 	anchored = 0
  	density = 1
  	req_access = list(access_engine_equip)
  
  	use_power = 0
  	idle_power_usage = 10
  
negative.code: 		emagged = 1
  		if(user)
  			user.visible_message("[user.name] emags the [src.name].","<span class='notice'>You short out the lock.</span>")
  
  
  /obj/machinery/power/emitter/prototype
  	name = "Prototype Emitter"
  	icon = 'icons/obj/turrets.dmi'
  	icon_state = "protoemitter"
  	can_buckle = TRUE
  	buckle_lying = 0
  	var/view_range = 12
  	var/datum/riding/riding_datum = null
  
  //BUCKLE HOOKS
  
  /obj/machinery/power/emitter/prototype/unbuckle_mob(mob/living/buckled_mob,force = 0)
  	playsound(src,'sound/mecha/mechmove01.ogg', 50, 1)
  	for(var/obj/item/I in buckled_mob.held_items)
  		if(istype(I, /obj/item/weapon/turret_control))
  			qdel(I)
  	if(istype(buckled_mob))
  		buckled_mob.pixel_x = 0
  		buckled_mob.pixel_y = 0
  		if(buckled_mob.client)
  			buckled_mob.client.change_view(world.view)
  	for(var/datum/action/innate/protoemitter/H in buckled_mob.actions)
  		qdel(H)
  	. = ..()
  
  /obj/machinery/power/emitter/prototype/user_buckle_mob(mob/living/M, mob/living/carbon/user)
  	if(user.incapacitated() || !istype(user))
  		return
  	for(var/atom/movable/A in get_turf(src))
  		if(A.density)
  			if(A != src && A != M)
  				return
  	M.loc = get_turf(src)
  	..()
  	playsound(src,'sound/mecha/mechmove01.ogg', 50, 1)
  	if(user.client)
  		user.client.change_view(view_range)
  	var/datum/action/innate/protoemitter/firing/auto = new()
  	auto.Grant(M, src)
  
  /datum/action/innate/protoemitter
  	check_flags = AB_CHECK_RESTRAINED | AB_CHECK_STUNNED | AB_CHECK_CONSCIOUS
  	var/obj/machinery/power/emitter/prototype/PE
  	var/mob/living/carbon/U
  
  
  /datum/action/innate/protoemitter/Grant(mob/living/L, obj/machinery/power/emitter/prototype/proto)
  	PE = proto
  	U = L
  	..()
  
  /datum/action/innate/protoemitter/firing
  	name = "Switch to Manual Firing"
  	desc = "The emitter will only fire on your command and at your designated target"
  	button_icon_state = "mech_zoom_off"
  
  /datum/action/innate/protoemitter/firing/Activate()
  	if(PE.manual == TRUE)
  		playsound(PE,'sound/mecha/mechmove01.ogg', 50, 1)
  		PE.manual = FALSE
  		name = "Switch to Manual Firing"
  		desc = "The emitter will only fire on your command and at your designated target"
  		button_icon_state = "mech_zoom_off"
  		for(var/obj/item/I in U.held_items)
  			if(istype(I, /obj/item/weapon/turret_control))
  				qdel(I)
  		UpdateButtonIcon()
  		return
  	if(PE.manual == FALSE)
  		playsound(PE,'sound/mecha/mechmove01.ogg', 50, 1)
  		name = "Switch to Automatic Firing"
  		desc = "Emitters will switch to periodic firing at your last target"
  		button_icon_state = "mech_zoom_on"
  		PE.manual = TRUE
  		for(var/V in U.held_items)
  			var/obj/item/I = V
  			if(istype(I))
  				if(U.dropItemToGround(I))
  					var/obj/item/weapon/turret_control/TC = new /obj/item/weapon/turret_control()
  					U.put_in_hands(TC)
  			else	//Entries in the list should only ever be items or null, so if it's not an item, we can assume it's an empty hand
  				var/obj/item/weapon/turret_control/TC = new /obj/item/weapon/turret_control()
  				U.put_in_hands(TC)
  		UpdateButtonIcon()
  
  
  /obj/item/weapon/turret_control
  	name = "turret controls"
  	icon_state = "offhand"
  	w_class = WEIGHT_CLASS_HUGE
  	flags = ABSTRACT | NODROP
  	resistance_flags = FIRE_PROOF | UNACIDABLE | ACID_PROOF | NOBLUDGEON
  	var/delay = 0
  
  /obj/item/weapon/turret_control/afterattack(atom/targeted_atom, mob/user)
  	..()
  	var/obj/machinery/power/emitter/E = user.buckled
  	user.dir = get_dir(user,targeted_atom)
  	E.dir = get_dir(E,targeted_atom)
  	switch(E.dir)
  		if(NORTH)
  			E.layer = 3.9
  			user.pixel_x = 0
  			user.pixel_y = -14
  		if(EAST)
  			E.layer = 4.1
  			user.pixel_x = -14
  			user.pixel_y = 0
  		if(SOUTH)
  			E.layer = 4.1
  			user.pixel_x = 0
  			user.pixel_y = 14
  		if(WEST)
  			E.layer = 4.1
  			user.pixel_x = 14
  			user.pixel_y = 0
  	if(E.charge >= 10 && world.time > delay)
  		E.charge -= 10
  		E.target = targeted_atom
  		E.fire_beam(targeted_atom, user)
  		delay = world.time + 10
  	else if (E.charge < 10)
  		playsound(get_turf(user),'sound/machines/buzz-sigh.ogg', 50, 1)
  