<commit_before>
#define BUGMODE_LIST	0
#define BUGMODE_MONITOR	1
#define BUGMODE_TRACK	2



/obj/item/camera_bug
	name = "camera bug"
	desc = "For illicit snooping through the camera network."
	icon = 'icons/obj/device.dmi'
	icon_state	= "camera_bug"
	w_class		= WEIGHT_CLASS_TINY
	item_state	= "camera_bug"
	throw_speed	= 4
	throw_range	= 20
	item_flags = NOBLUDGEON

	var/obj/machinery/camera/current = null

	var/last_net_update = 0
	var/list/bugged_cameras = list()

	var/track_mode = BUGMODE_LIST
	var/last_tracked = 0
	var/refresh_interval = 50

	var/tracked_name = null
	var/atom/tracking = null

	var/last_found = null
	var/last_seen = null

/obj/item/camera_bug/New()
	..()
	START_PROCESSING(SSobj, src)

/obj/item/camera_bug/Destroy()
	get_cameras()
	for(var/cam_tag in bugged_cameras)
		var/obj/machinery/camera/camera = bugged_cameras[cam_tag]
		if(camera.bug == src)
			camera.bug = null
	bugged_cameras = list()
	if(tracking)
		tracking = null
	return ..()

/obj/item/camera_bug/interact(mob/user)
	ui_interact(user)

/obj/item/camera_bug/ui_interact(mob/user = usr)
	. = ..()
	var/datum/browser/popup = new(user, "camerabug","Camera Bug",nref=src)
	popup.set_content(menu(get_cameras()))
	popup.open()

/obj/item/camera_bug/attack_self(mob/user)
	user.set_machine(src)
	interact(user)

/obj/item/camera_bug/check_eye(mob/user)
	if ( loc != user || user.incapacitated() || user.eye_blind || !current )
		user.unset_machine()
		return 0
	var/turf/T_user = get_turf(user.loc)
	var/turf/T_current = get_turf(current)
	if(T_user.z != T_current.z || !current.can_use())
		to_chat(user, "<span class='danger'>[src] has lost the signal.</span>")
		current = null
		user.unset_machine()
		return 0
	return 1
/obj/item/camera_bug/on_unset_machine(mob/user)
	user.reset_perspective(null)

/obj/item/camera_bug/proc/get_cameras()
	if( world.time > (last_net_update + 100))
		bugged_cameras = list()
		for(var/obj/machinery/camera/camera in GLOB.cameranet.cameras)
			if(camera.stat || !camera.can_use())
				continue
			if(length(list("ss13","mine", "rd", "labor", "toxins", "minisat")&camera.network))
				bugged_cameras[camera.c_tag] = camera
	return sortList(bugged_cameras)


/obj/item/camera_bug/proc/menu(list/cameras)
	if(!cameras || !cameras.len)
		return "No bugged cameras found."

	var/html
	switch(track_mode)
		if(BUGMODE_LIST)
			html = "<h3>Select a camera:</h3> <a href='?src=[REF(src)];view'>\[Cancel camera view\]</a><hr><table>"
			for(var/entry in cameras)
				var/obj/machinery/camera/C = entry
				var/functions = ""
				if(C.bug == src)<commit_msg>whoops (#6833)<commit_after>
#define BUGMODE_LIST	0
#define BUGMODE_MONITOR	1
#define BUGMODE_TRACK	2



/obj/item/camera_bug
	name = "camera bug"
	desc = "For illicit snooping through the camera network."
	icon = 'icons/obj/device.dmi'
	icon_state	= "camera_bug"
	w_class		= WEIGHT_CLASS_TINY
	item_state	= "camera_bug"
	throw_speed	= 4
	throw_range	= 20
	item_flags = NOBLUDGEON

	var/obj/machinery/camera/current = null

	var/last_net_update = 0
	var/list/bugged_cameras = list()

	var/track_mode = BUGMODE_LIST
	var/last_tracked = 0
	var/refresh_interval = 50

	var/tracked_name = null
	var/atom/tracking = null

	var/last_found = null
	var/last_seen = null

/obj/item/camera_bug/New()
	..()
	START_PROCESSING(SSobj, src)

/obj/item/camera_bug/Destroy()
	get_cameras()
	for(var/cam in bugged_cameras)
		var/obj/machinery/camera/camera = cam
		if(camera.bug == src)
			camera.bug = null
	bugged_cameras = list()
	if(tracking)
		tracking = null
	return ..()

/obj/item/camera_bug/interact(mob/user)
	ui_interact(user)

/obj/item/camera_bug/ui_interact(mob/user = usr)
	. = ..()
	var/datum/browser/popup = new(user, "camerabug","Camera Bug",nref=src)
	popup.set_content(menu(get_cameras()))
	popup.open()

/obj/item/camera_bug/attack_self(mob/user)
	user.set_machine(src)
	interact(user)

/obj/item/camera_bug/check_eye(mob/user)
	if ( loc != user || user.incapacitated() || user.eye_blind || !current )
		user.unset_machine()
		return 0
	var/turf/T_user = get_turf(user.loc)
	var/turf/T_current = get_turf(current)
	if(T_user.z != T_current.z || !current.can_use())
		to_chat(user, "<span class='danger'>[src] has lost the signal.</span>")
		current = null
		user.unset_machine()
		return 0
	return 1
/obj/item/camera_bug/on_unset_machine(mob/user)
	user.reset_perspective(null)

/obj/item/camera_bug/proc/get_cameras()
	if( world.time > (last_net_update + 100))
		bugged_cameras = list()
		for(var/obj/machinery/camera/camera in GLOB.cameranet.cameras)
			if(camera.stat || !camera.can_use())
				continue
			if(length(list("ss13","mine", "rd", "labor", "toxins", "minisat")&camera.network))
				bugged_cameras[camera.c_tag] = camera
	return sortList(bugged_cameras)


/obj/item/camera_bug/proc/menu(list/cameras)
	if(!cameras || !cameras.len)
		return "No bugged cameras found."

	var/html
	switch(track_mode)
		if(BUGMODE_LIST)
			html = "<h3>Select a camera:</h3> <a href='?src=[REF(src)];view'>\[Cancel camera view\]</a><hr><table>"
			for(var/entry in cameras)
				var/obj/machinery/camera/C = bugged_cameras[entry]
				var/functions = ""
				if(C.bug == src)
{'fraction_non_alphanumeric': 0.14880373468196847, 'fraction_numerical': 0.008558646177786422, 'mean_word_length': 4.424050632911392, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5991702', 'n_tokens_mistral': 2255, 'n_tokens_neox': 2069, 'n_words': 342}