<?xml version="1.0"?>

<!-- McDonnell Douglas DC-10 Misc -->
<!-- Copyright (c) 2026 Josh Davidson (Octal450) -->

<system name="DC-10: Misc"> <!-- Everything here is after all systems -->
	
	<channel name="Misc Logic Fast" execrate="2">
		
		<fcs_function name="/systems/misc/minimums-minus-50">
			<function>
				<difference>
					<property>/controls/switches/minimums</property>
					<value>50</value>
				</difference>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/misc/minimums-plus-50">
			<function>
				<sum>
					<property>/controls/switches/minimums</property>
					<value>50</value>
				</sum>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/misc/minimums-plus-100">
			<function>
				<sum>
					<property>/controls/switches/minimums</property>
					<value>100</value>
				</sum>
			</function>
		</fcs_function>
		
		<switch name="/systems/misc/minimums-latch">
			<default value="/systems/misc/minimums-latch"/>
			<test value="0">
				position/wow eq 1
			</test>
			<test value="1">
				/position/gear-agl-ft ge /systems/misc/minimums-plus-50
			</test>
		</switch>
	
	</channel>
	
	<channel name="Exterior Lights" execrate="2">
		
		<switch name="/systems/exterior-lights/nose-landing-light-cmd">
			<default value="0"/>
			<test logic="AND" value="0.6">
				/controls/lighting/landing-light-n eq 0.5
				/systems/gear/cmd eq 1
				/gear/gear[0]/position-norm ge 0.99
				<test logic="OR">
					/systems/electrical/bus/l-emer-ac ge 112
					/systems/electrical/bus/r-emer-ac ge 112
				</test>
			</test>
			<test logic="AND" value="1">
				/controls/lighting/landing-light-n eq 1.0
				/systems/gear/cmd eq 1
				/gear/gear[0]/position-norm ge 0.99
				<test logic="OR">
					/systems/electrical/bus/l-emer-ac ge 112
					/systems/electrical/bus/r-emer-ac ge 112
				</test>
			</test>
		</switch>
		
		<lag_filter name="/systems/exterior-lights/nose-landing-light">
			<input>/systems/exterior-lights/nose-landing-light-cmd</input>
			<c1>7.5</c1>
		</lag_filter>
		
		<switch name="/systems/exterior-lights/left-landing-light-ext-cmd">
			<default value="0"/>
			<test value="1">
				/controls/lighting/landing-light-l ge 0.5
			</test>
		</switch>
		
		<switch name="/systems/exterior-lights/left-landing-light-ext-rate">
			<default value="0"/>
			<test value="0.14285714285"> <!-- 7 seconds -->
				/systems/electrical/bus/l-emer-ac ge 112
			</test>
		</switch>
		
		<actuator name="/systems/exterior-lights/left-landing-light-ext">
			<input>/systems/exterior-lights/left-landing-light-ext-cmd</input>
			<rate_limit>/systems/exterior-lights/left-landing-light-ext-rate</rate_limit>
		</actuator>
		
		<switch name="/systems/exterior-lights/left-landing-light-cmd">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/lighting/landing-light-l eq 1
				/systems/exterior-lights/left-landing-light-ext eq 1
				/systems/electrical/bus/l-emer-ac ge 112
			</test>
		</switch>
		
		<lag_filter name="/systems/exterior-lights/left-landing-light">
			<input>/systems/exterior-lights/left-landing-light-cmd</input>
			<c1>7.5</c1>
		</lag_filter>
		
		<switch name="/systems/exterior-lights/right-landing-light-ext-cmd">
			<default value="0"/>
			<test value="1">
				/controls/lighting/landing-light-r ge 0.5
			</test>
		</switch>
		
		<switch name="/systems/exterior-lights/right-landing-light-ext-rate">
			<default value="0"/>
			<test value="0.14285714285"> <!-- 7 seconds -->
				/systems/electrical/bus/r-emer-ac ge 112
			</test>
		</switch>
		
		<actuator name="/systems/exterior-lights/right-landing-light-ext">
			<input>/systems/exterior-lights/right-landing-light-ext-cmd</input>
			<rate_limit>/systems/exterior-lights/right-landing-light-ext-rate</rate_limit>
		</actuator>
		
		<switch name="/systems/exterior-lights/right-landing-light-cmd">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/lighting/landing-light-r eq 1
				/systems/exterior-lights/right-landing-light-ext eq 1
				/systems/electrical/bus/r-emer-ac ge 112
			</test>
		</switch>
		
		<lag_filter name="/systems/exterior-lights/right-landing-light">
			<input>/systems/exterior-lights/right-landing-light-cmd</input>
			<c1>7.5</c1>
		</lag_filter>
		
		<switch name="/systems/exterior-lights/left-turnoff-light-cmd">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/lighting/turnoff-light-l eq 1
				/systems/electrical/bus/l-emer-ac ge 112
			</test>
		</switch>
		
		<lag_filter name="/systems/exterior-lights/left-turnoff-light">
			<input>/systems/exterior-lights/left-turnoff-light-cmd</input>
			<c1>7.5</c1>
		</lag_filter>
		
		<switch name="/systems/exterior-lights/right-turnoff-light-cmd">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/lighting/turnoff-light-r eq 1
				/systems/electrical/bus/r-emer-ac ge 112
			</test>
		</switch>
		
		<lag_filter name="/systems/exterior-lights/right-turnoff-light">
			<input>/systems/exterior-lights/right-turnoff-light-cmd</input>
			<c1>7.5</c1>
		</lag_filter>
		
		<switch name="/systems/exterior-lights/nav-lights">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/lighting/nav-lights eq 1
				<test logic="OR">
					/systems/electrical/bus/l-emer-ac ge 112
					/systems/electrical/bus/r-emer-ac ge 112
				</test>
			</test>
		</switch>
		
		<switch name="/systems/exterior-lights/strobe-lights">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/lighting/strobe-lights eq 1
				/gear/gear[0]/wow ne 1
				<test logic="OR">
					/systems/electrical/bus/l-emer-ac ge 112
					/systems/electrical/bus/r-emer-ac ge 112
				</test>
			</test>
		</switch>
		
		<switch name="/systems/exterior-lights/beacon">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/lighting/beacon eq 1
				<test logic="OR">
					/systems/electrical/bus/l-emer-ac ge 112
					/systems/electrical/bus/r-emer-ac ge 112
				</test>
			</test>
		</switch>
		
		<switch name="/systems/exterior-lights/logo-lights-cmd">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/lighting/logo-lights eq 1
				<test logic="OR">
					/systems/electrical/bus/l-emer-ac ge 112
					/systems/electrical/bus/r-emer-ac ge 112
				</test>
			</test>
		</switch>
		
		<lag_filter name="/systems/exterior-lights/logo-lights">
			<input>/systems/exterior-lights/logo-lights-cmd</input>
			<c1>7.5</c1>
		</lag_filter>
	
	</channel>
	
	<channel name="CAWS and Warnings Logic" execrate="8">
		
		<!-- Altitude Alert -->
		<switch name="/systems/caws/logic/altitude-alert-captured">
			<default value="/systems/caws/logic/altitude-alert-captured"/>
			<test value="0">
				/it-autoflight/input/alt-diff-abs ge 800
			</test>
			<test value="1">
				/it-autoflight/input/alt-diff-abs le 250
			</test>
		</switch>
		
		<switch name="/systems/caws/logic/altitude-alert">
			<default value="/systems/caws/logic/altitude-alert"/>
			<test logic="OR" value="0"> <!-- Reset -->
				/it-autoflight/input/alt-diff-abs le 250
				fcs/flap-pos-deg ge 28
				/it-autoflight/output/vert eq 2
				/it-autoflight/output/vert eq 6
				position/wow eq 1
				<test logic="AND"> <!-- Approaching only -->
					/systems/caws/logic/altitude-alert eq 1
					/it-autoflight/input/alt-diff-abs ge 800
				</test>
			</test>
			<test logic="AND" value="1"> <!-- Approaching -->
				/systems/caws/logic/altitude-alert-captured eq 0
				/it-autoflight/input/alt-diff-abs gt 250
				/it-autoflight/input/alt-diff-abs le 750
			</test>
			<test logic="AND" value="2"> <!-- Deviating -->
				/systems/caws/logic/altitude-alert-captured eq 1
				/it-autoflight/input/alt-diff-abs gt 250
			</test>
		</switch>
		
		<switch name="/systems/caws/logic/altitude-alert-aural-1"> <!-- Prevent aural from playing if newly set altitude is inside the alert zone -->
			<default value="/systems/caws/logic/altitude-alert-aural-1"/>
			<test logic="AND" value="0">
				/systems/caws/logic/altitude-alert eq 0
				/it-autoflight/input/alt-diff-abs le 700
			</test>
			<test value="1">
				/it-autoflight/input/alt-diff-abs ge 800
			</test>
		</switch>
	
	</channel>
	
	<channel name="CAWS Sound Controller" execrate="8">
		
		<!-- Autopilot Horn -->
		<switch name="/systems/caws/apoff/trigger">
			<default value="/systems/caws/apoff/trigger"/>
			<test logic="OR" value="0">
				/systems/electrical/outputs/mk-viii lt 24
				/systems/caws/apoff/out eq 1
			</test>
			<test logic="AND" value="1">
				/systems/caws/apoff/out eq 0
				/it-autoflight/sound/apoff eq 1
			</test>
		</switch>
		
		<actuator name="/systems/caws/apoff/actuator">
			<input>/systems/caws/apoff/trigger</input>
			<rate_limit sense="incr">0.75</rate_limit>
			<rate_limit sense="decr">100</rate_limit>
			<output>/systems/caws/apoff/out</output>
		</actuator>
	
	</channel>

</system>
