<commit_before>/obj/machinery/door/airlock/shell
	name = "circuit airlock"
	autoclose = FALSE

/obj/machinery/door/airlock/shell/Initialize()
	. = ..()
	AddComponent( \
		/datum/component/shell, \
		unremovable_circuit_components = list(new /obj/item/circuit_component/airlock), \
		capacity = SHELL_CAPACITY_LARGE, \
		shell_flags = SHELL_FLAG_ALLOW_FAILURE_ACTION \
	)

/obj/machinery/door/airlock/shell/check_access(obj/item/I)
	return FALSE

/obj/item/circuit_component/airlock
	display_name = "Airlock"
	display_desc = "The general interface with an airlock. Includes general statuses of the airlock"

	/// Called when attack_hand is called on the shell.
	var/obj/machinery/door/airlock/attached_airlock

	/// Bolts the airlock (if possible)
	var/datum/port/input/bolt
	/// Unbolts the airlock (if possible)
	var/datum/port/input/unbolt
	/// Opens the airlock (if possible)
	var/datum/port/input/open
	/// Closes the airlock (if possible)
	var/datum/port/input/close

	/// Contains whether the airlock is open or not
	var/datum/port/output/is_open
	/// Contains whether the airlock is bolted or not
	var/datum/port/output/is_bolted

	/// Called when the airlock is opened.
	var/datum/port/output/opened
	/// Called when the airlock is closed
	var/datum/port/output/closed

	/// Called when the airlock is bolted
	var/datum/port/output/bolted
	/// Called when the airlock is unbolted
	var/datum/port/output/unbolted

/obj/item/circuit_component/airlock/Initialize()
	. = ..()
	// Input Signals
	bolt = add_input_port("Bolt", PORT_TYPE_SIGNAL)
	unbolt = add_input_port("Unbolt", PORT_TYPE_SIGNAL)
	open = add_input_port("Open", PORT_TYPE_SIGNAL)
	close = add_input_port("Close", PORT_TYPE_SIGNAL)
	// States
	is_open = add_output_port("Is Open", PORT_TYPE_NUMBER)
	is_bolted = add_output_port("Is Bolted", PORT_TYPE_NUMBER)
	// Output Signals
	opened = add_output_port("Opened", PORT_TYPE_SIGNAL)
	closed = add_output_port("Closed", PORT_TYPE_SIGNAL)
	bolted = add_output_port("Bolted", PORT_TYPE_SIGNAL)
	unbolted = add_output_port("Unbolted", PORT_TYPE_SIGNAL)

/obj/item/circuit_component/airlock/Destroy()
	bolt = null
	unbolt = null
	open = null
	close = null
	is_open = null
	is_bolted = null
	opened = null
	closed = null
	bolted = null
	unbolted = null
	attached_airlock = null
	return ..()

/obj/item/circuit_component/airlock/register_shell(atom/movable/shell)
	. = ..()
	if(istype(shell, /obj/machinery/door/airlock))
		attached_airlock = shell
		RegisterSignal(shell, COMSIG_AIRLOCK_SET_BOLT, .proc/on_airlock_set_bolted)
		RegisterSignal(shell, COMSIG_AIRLOCK_OPEN, .proc/on_airlock_open)
		RegisterSignal(shell, COMSIG_AIRLOCK_CLOSE, .proc/on_airlock_closed)

/obj/item/circuit_component/airlock/unregister_shell(atom/movable/shell)
	attached_airlock = null
	UnregisterSignal(shell, list(
		COMSIG_AIRLOCK_SET_BOLT,
		COMSIG_AIRLOCK_OPEN,
		COMSIG_AIRLOCK_CLOSE,
	))
	return ..()

/obj/item/circuit_component/airlock/proc/on_airlock_set_bolted(datum/source, should_bolt)
	SIGNAL_HANDLER
	is_bolted.set_output(should_bolt)
	if(should_bolt)
		bolted.set_output(COMPONENT_SIGNAL)
	else
		unbolted.set_output(COMPONENT_SIGNAL)

/obj/item/circuit_component/airlock/proc/on_airlock_open(datum/source, force)
	SIGNAL_HANDLER
	is_open.set_output(TRUE)
	opened.set_output(COMPONENT_SIGNAL)

/obj/item/circuit_component/airlock/proc/on_airlock_closed(datum/source, forced)
	SIGNAL_HANDLER
	is_open.set_output(FALSE)
	closed.set_output(COMPONENT_SIGNAL)

/obj/item/circuit_component/airlock/input_received(datum/port/input/port)
	. = ..()
	if(.)
		return

	if(!attached_airlock)
		return

	if(COMPONENT_TRIGGERED_BY(bolt, port))
		attached_airlock.bolt()
	if(COMPONENT_TRIGGERED_BY(unbolt, port))
		attached_airlock.unbolt()
	if(COMPONENT_TRIGGERED_BY(open, port) && attached_airlock.density)
		INVOKE_ASYNC(attached_airlock, /obj/machinery/door/airlock.proc/open)
	if(COMPONENT_TRIGGERED_BY(close, port) && !attached_airlock.density)
		INVOKE_ASYNC(attached_airlock, /obj/machinery/door/airlock.proc/close)
<commit_msg>Fixes oversights and disables AI interaction with door shell (#59809)<commit_after>/datum/wires/airlock/shell
	holder_type = /obj/machinery/door/airlock/shell
	proper_name = "Circuit Airlock"

/datum/wires/airlock/shell/on_cut(wire, mend)
	// Don't allow them to re-enable autoclose.
	if(wire == WIRE_TIMING)
		return
	return ..()

/obj/machinery/door/airlock/shell
	name = "circuit airlock"
	autoclose = FALSE

/obj/machinery/door/airlock/shell/Initialize()
	. = ..()
	AddComponent( \
		/datum/component/shell, \
		unremovable_circuit_components = list(new /obj/item/circuit_component/airlock), \
		capacity = SHELL_CAPACITY_LARGE, \
		shell_flags = SHELL_FLAG_ALLOW_FAILURE_ACTION \
	)

/obj/machinery/door/airlock/shell/check_access(obj/item/I)
	return FALSE

/obj/machinery/door/airlock/shell/canAIControl(mob/user)
	return FALSE

/obj/machinery/door/airlock/shell/canAIHack(mob/user)
	return FALSE

/obj/machinery/door/airlock/shell/set_wires()
	return new /datum/wires/airlock/shell(src)

/obj/item/circuit_component/airlock
	display_name = "Airlock"
	display_desc = "The general interface with an airlock. Includes general statuses of the airlock"

	/// Called when attack_hand is called on the shell.
	var/obj/machinery/door/airlock/attached_airlock

	/// Bolts the airlock (if possible)
	var/datum/port/input/bolt
	/// Unbolts the airlock (if possible)
	var/datum/port/input/unbolt
	/// Opens the airlock (if possible)
	var/datum/port/input/open
	/// Closes the airlock (if possible)
	var/datum/port/input/close

	/// Contains whether the airlock is open or not
	var/datum/port/output/is_open
	/// Contains whether the airlock is bolted or not
	var/datum/port/output/is_bolted

	/// Called when the airlock is opened.
	var/datum/port/output/opened
	/// Called when the airlock is closed
	var/datum/port/output/closed

	/// Called when the airlock is bolted
	var/datum/port/output/bolted
	/// Called when the airlock is unbolted
	var/datum/port/output/unbolted

/obj/item/circuit_component/airlock/Initialize()
	. = ..()
	// Input Signals
	bolt = add_input_port("Bolt", PORT_TYPE_SIGNAL)
	unbolt = add_input_port("Unbolt", PORT_TYPE_SIGNAL)
	open = add_input_port("Open", PORT_TYPE_SIGNAL)
	close = add_input_port("Close", PORT_TYPE_SIGNAL)
	// States
	is_open = add_output_port("Is Open", PORT_TYPE_NUMBER)
	is_bolted = add_output_port("Is Bolted", PORT_TYPE_NUMBER)
	// Output Signals
	opened = add_output_port("Opened", PORT_TYPE_SIGNAL)
	closed = add_output_port("Closed", PORT_TYPE_SIGNAL)
	bolted = add_output_port("Bolted", PORT_TYPE_SIGNAL)
	unbolted = add_output_port("Unbolted", PORT_TYPE_SIGNAL)

/obj/item/circuit_component/airlock/Destroy()
	bolt = null
	unbolt = null
	open = null
	close = null
	is_open = null
	is_bolted = null
	opened = null
	closed = null
	bolted = null
	unbolted = null
	attached_airlock = null
	return ..()

/obj/item/circuit_component/airlock/register_shell(atom/movable/shell)
	. = ..()
	if(istype(shell, /obj/machinery/door/airlock))
		attached_airlock = shell
		RegisterSignal(shell, COMSIG_AIRLOCK_SET_BOLT, .proc/on_airlock_set_bolted)
		RegisterSignal(shell, COMSIG_AIRLOCK_OPEN, .proc/on_airlock_open)
		RegisterSignal(shell, COMSIG_AIRLOCK_CLOSE, .proc/on_airlock_closed)

/obj/item/circuit_component/airlock/unregister_shell(atom/movable/shell)
	attached_airlock = null
	UnregisterSignal(shell, list(
		COMSIG_AIRLOCK_SET_BOLT,
		COMSIG_AIRLOCK_OPEN,
		COMSIG_AIRLOCK_CLOSE,
	))
	return ..()

/obj/item/circuit_component/airlock/proc/on_airlock_set_bolted(datum/source, should_bolt)
	SIGNAL_HANDLER
	is_bolted.set_output(should_bolt)
	if(should_bolt)
		bolted.set_output(COMPONENT_SIGNAL)
	else
		unbolted.set_output(COMPONENT_SIGNAL)

/obj/item/circuit_component/airlock/proc/on_airlock_open(datum/source, force)
	SIGNAL_HANDLER
	is_open.set_output(TRUE)
	opened.set_output(COMPONENT_SIGNAL)

/obj/item/circuit_component/airlock/proc/on_airlock_closed(datum/source, forced)
	SIGNAL_HANDLER
	is_open.set_output(FALSE)
	closed.set_output(COMPONENT_SIGNAL)

/obj/item/circuit_component/airlock/input_received(datum/port/input/port)
	. = ..()
	if(.)
		return

	if(!attached_airlock)
		return

	if(COMPONENT_TRIGGERED_BY(bolt, port))
		attached_airlock.bolt()
	if(COMPONENT_TRIGGERED_BY(unbolt, port))
		attached_airlock.unbolt()
	if(COMPONENT_TRIGGERED_BY(open, port) && attached_airlock.density)
		INVOKE_ASYNC(attached_airlock, /obj/machinery/door/airlock.proc/open)
	if(COMPONENT_TRIGGERED_BY(close, port) && !attached_airlock.density)
		INVOKE_ASYNC(attached_airlock, /obj/machinery/door/airlock.proc/close)

{'fraction_non_alphanumeric': 0.11258586564210037, 'fraction_numerical': 0.0005821399464431249, 'mean_word_length': 4.998603351955308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4538091', 'n_tokens_mistral': 3450, 'n_tokens_neox': 3306, 'n_words': 513}