# Segnale imperativo a tre vele quadre, seguito da qualsiasi segnale.
# Se aperto con Ctrl-click si apre con RGG invece di S se il binario
# è ingombro; da spento è apribile solo con Ctrl-click.
#
# Aspetti: R, S, G, Gx, V, GG, GV, GxVx, Gx/Vx, off (spento), fault (guasto),
#          RV, RG, RGx, RGG, RGV, RGxVx, RGx/Vx

# Main signal with 3 square heads, followed by whatever signal.
# When cleared with ctrl-click (white track) it shows RYY instead of S if
# the track is occupied; when unlit it can be cleared only with Ctrl-click.
#
# Aspects:  R, S, Y, Yx, G, YY, YG, YxGx, Yx/Gx, off, fault,
#           RG, RY, RYx, RYY, RYG, RYxGx, RYx/Gx

# P.Rosati  21/01/2021 (Versione 5.1)

Aspect: red
	IconE: NQ_rbb_E.xpm
	IconW: NQ_rbb_W.xpm
	IconN: NQ_rbb_N.xpm
	IconS: NQ_rbb_S.xpm
	Action: stop

Aspect: shunt
	IconE: NQ_rbb_E.xpm
	IconW: NQ_rbb_W.xpm
	IconN: NQ_rbb_N.xpm
	IconS: NQ_rbb_S.xpm
	Action: speedLimit 29

Aspect: green
	IconE: NQ_gbb_E.xpm
	IconW: NQ_gbb_W.xpm
	IconN: NQ_gbb_N.xpm
	IconS: NQ_gbb_S.xpm
	Action: proceed

Aspect: yellow
	IconE: NQ_ybb_E.xpm
	IconW: NQ_ybb_W.xpm
	IconN: NQ_ybb_N.xpm
	IconS: NQ_ybb_S.xpm
	Action: speedLimit 110

Aspect: short_yellow
	IconE: NQ_ybb_E.xpm
	IconW: NQ_ybb_W.xpm
	IconN: NQ_ybb_N.xpm
	IconS: NQ_ybb_S.xpm
	Action: speedLimit 110

Aspect: yellow_flashing
	IconE: NQ_ybb_E.xpm NQ_bbb_E.xpm
	IconW: NQ_ybb_W.xpm NQ_bbb_W.xpm
	IconN: NQ_ybb_N.xpm NQ_bbb_N.xpm
	IconS: NQ_ybb_S.xpm NQ_bbb_S.xpm
	Action: speedLimit 150

Aspect: yellow_yellow
	IconE: NQ_yyb_E.xpm
	IconW: NQ_yyb_W.xpm
	IconN: NQ_yyb_N.xpm
	IconS: NQ_yyb_S.xpm
	Action: speedLimit 50

Aspect: yellow_green
	IconE: NQ_ygb_E.xpm
	IconW: NQ_ygb_W.xpm
	IconN: NQ_ygb_N.xpm
	IconS: NQ_ygb_S.xpm
	Action: speedLimit 110

Aspect: short_yellow_green_30
	IconE: NQ_ygb_E.xpm
	IconW: NQ_ygb_W.xpm
	IconN: NQ_ygb_N.xpm
	IconS: NQ_ygb_S.xpm
	Action: speedLimit 110

Aspect: yellow_green_flashing
	IconE: NQ_ygb_E.xpm NQ_bbb_E.xpm
	IconW: NQ_ygb_W.xpm NQ_bbb_W.xpm
	IconN: NQ_ygb_N.xpm NQ_bbb_N.xpm
	IconS: NQ_ygb_S.xpm NQ_bbb_S.xpm
	Action: speedLimit 110

Aspect: short_yellow_green_60
	IconE: NQ_ygb_E.xpm NQ_bbb_E.xpm
	IconW: NQ_ygb_W.xpm NQ_bbb_W.xpm
	IconN: NQ_ygb_N.xpm NQ_bbb_N.xpm
	IconS: NQ_ygb_S.xpm NQ_bbb_S.xpm
	Action: speedLimit 110

Aspect: yellow_green_switching
	IconE: NQ_ybb_E.xpm NQ_bgb_E.xpm
	IconW: NQ_ybb_W.xpm NQ_bgb_W.xpm
	IconN: NQ_ybb_N.xpm NQ_bgb_N.xpm
	IconS: NQ_ybb_S.xpm NQ_bgb_S.xpm
	Action: speedLimit 150

Aspect: short_yellow_green_100
	IconE: NQ_ybb_E.xpm NQ_bgb_E.xpm
	IconW: NQ_ybb_W.xpm NQ_bgb_W.xpm
	IconN: NQ_ybb_N.xpm NQ_bgb_N.xpm
	IconS: NQ_ybb_S.xpm NQ_bgb_S.xpm
	Action: speedLimit 150

Aspect: red_yellow_yellow
	IconE: NQ_ryy_E.xpm
	IconW: NQ_ryy_W.xpm
	IconN: NQ_ryy_N.xpm
	IconS: NQ_ryy_S.xpm
	Action: speedLimit 30

Aspect: red_green_30
	IconE: NQ_rgb_E.xpm
	IconW: NQ_rgb_W.xpm
	IconN: NQ_rgb_N.xpm
	IconS: NQ_rgb_S.xpm
	Action: speedLimit 30

Aspect: red_green_60
	IconE: NQ_rgb_E.xpm
	IconW: NQ_rgb_W.xpm
	IconN: NQ_rgb_N.xpm
	IconS: NQ_rgb_S.xpm
	Action: speedLimit 60

Aspect: red_green_100
	IconE: NQ_rgb_E.xpm
	IconW: NQ_rgb_W.xpm
	IconN: NQ_rgb_N.xpm
	IconS: NQ_rgb_S.xpm
	Action: speedLimit 100

Aspect: red_yellow_30
	IconE: NQ_ryb_E.xpm
	IconW: NQ_ryb_W.xpm
	IconN: NQ_ryb_N.xpm
	IconS: NQ_ryb_S.xpm
	Action: speedLimit 30

Aspect: red_yellow_60
	IconE: NQ_ryb_E.xpm
	IconW: NQ_ryb_W.xpm
	IconN: NQ_ryb_N.xpm
	IconS: NQ_ryb_S.xpm
	Action: speedLimit 60

Aspect: red_yellow_flashing_30
	IconE: NQ_ryb_E.xpm NQ_rbb_E.xpm
	IconW: NQ_ryb_W.xpm NQ_rbb_W.xpm
	IconN: NQ_ryb_N.xpm NQ_rbb_N.xpm
	IconS: NQ_ryb_S.xpm NQ_rbb_S.xpm
	Action: speedLimit 30

Aspect: red_yellow_flashing_60
	IconE: NQ_ryb_E.xpm NQ_rbb_E.xpm
	IconW: NQ_ryb_W.xpm NQ_rbb_W.xpm
	IconN: NQ_ryb_N.xpm NQ_rbb_N.xpm
	IconS: NQ_ryb_S.xpm NQ_rbb_S.xpm
	Action: speedLimit 60

Aspect: red_yellow_flashing_100
	IconE: NQ_ryb_E.xpm NQ_rbb_E.xpm
	IconW: NQ_ryb_W.xpm NQ_rbb_W.xpm
	IconN: NQ_ryb_N.xpm NQ_rbb_N.xpm
	IconS: NQ_ryb_S.xpm NQ_rbb_S.xpm
	Action: speedLimit 100

Aspect: red_yellow_green_30
	IconE: NQ_ryg_E.xpm
	IconW: NQ_ryg_W.xpm
	IconN: NQ_ryg_N.xpm
	IconS: NQ_ryg_S.xpm
	Action: speedLimit 30

Aspect: red_yellow_green_60
	IconE: NQ_ryg_E.xpm
	IconW: NQ_ryg_W.xpm
	IconN: NQ_ryg_N.xpm
	IconS: NQ_ryg_S.xpm
	Action: speedLimit 60

Aspect: red_yellow_green_100
	IconE: NQ_ryg_E.xpm
	IconW: NQ_ryg_W.xpm
	IconN: NQ_ryg_N.xpm
	IconS: NQ_ryg_S.xpm
	Action: speedLimit 100

Aspect: red_yellow_green_flashing_30
	IconE: NQ_ryg_E.xpm NQ_rbb_E.xpm
	IconW: NQ_ryg_W.xpm NQ_rbb_W.xpm
	IconN: NQ_ryg_N.xpm NQ_rbb_N.xpm
	IconS: NQ_ryg_S.xpm NQ_rbb_S.xpm
	Action: speedLimit 30

Aspect: red_yellow_green_flashing_60
	IconE: NQ_ryg_E.xpm NQ_rbb_E.xpm
	IconW: NQ_ryg_W.xpm NQ_rbb_W.xpm
	IconN: NQ_ryg_N.xpm NQ_rbb_N.xpm
	IconS: NQ_ryg_S.xpm NQ_rbb_S.xpm
	Action: speedLimit 60

Aspect: red_yellow_green_flashing_100
	IconE: NQ_ryg_E.xpm NQ_rbb_E.xpm
	IconW: NQ_ryg_W.xpm NQ_rbb_W.xpm
	IconN: NQ_ryg_N.xpm NQ_rbb_N.xpm
	IconS: NQ_ryg_S.xpm NQ_rbb_S.xpm
	Action: speedLimit 100

Aspect: red_yellow_green_switching_30
	IconE: NQ_ryb_E.xpm NQ_rbg_E.xpm
	IconW: NQ_ryb_W.xpm NQ_rbg_W.xpm
	IconN: NQ_ryb_N.xpm NQ_rbg_N.xpm
	IconS: NQ_ryb_S.xpm NQ_rbg_S.xpm
	Action: speedLimit 30

Aspect: red_yellow_green_switching_60
	IconE: NQ_ryb_E.xpm NQ_rbg_E.xpm
	IconW: NQ_ryb_W.xpm NQ_rbg_W.xpm
	IconN: NQ_ryb_N.xpm NQ_rbg_N.xpm
	IconS: NQ_ryb_S.xpm NQ_rbg_S.xpm
	Action: speedLimit 60

Aspect: red_yellow_green_switching_100
	IconE: NQ_ryb_E.xpm NQ_rbg_E.xpm
	IconW: NQ_ryb_W.xpm NQ_rbg_W.xpm
	IconN: NQ_ryb_N.xpm NQ_rbg_N.xpm
	IconS: NQ_ryb_S.xpm NQ_rbg_S.xpm
	Action: speedLimit 100

Aspect: off
	IconE: NQ_bbb_E.xpm
	IconW: NQ_bbb_W.xpm
	IconN: NQ_bbb_N.xpm
	IconS: NQ_bbb_S.xpm
	Action: stop

Aspect: fault
	IconE: NQ_bbb_E.xpm
	IconW: NQ_bbb_W.xpm
	IconN: NQ_bbb_N.xpm
	IconS: NQ_bbb_S.xpm
	Action: speedLimit 30

# initial aspect

OnInit:
	.aspect = red
end

# the player or a script cleared the signal

OnCleared:
	# Se bloccato, spento o seguito da un segnale guasto superabile, si apre solo con Ctrl-click
	# If blocked, unlit or followed by a passable faulty signal, clears only with Ctrl-click
	if .aspect = off or next.aspect = fault or next.aspect = block
		return
	end
	# Se seguito da un segnale di partenza aperto, si apre solo con Ctrl-click
	# If followed by a clear exit signal, clears only with Ctrl-click
	if nextApproach.aspect = block or next.script > "rfi_part" and next.script < "rfi_paru" and next.aspect ! red and next.aspect ! off
		return
	end
	# Se seguito da un segnale di partenza (chiuso), lo blocca
	# If followed by an (unclear) exit signal, lock it
	if nextApproach.script = "rfi_avv_part.tds" or next.script > "rfi_part" and next.script < "rfi_paru"
		next.fixedred = 1
	end
	# Aspetto temporaneo: la OnUpdate imposterà quello giusto
	# Temporary aspect: the OnUpdate will set the right one
	.aspect = green
end

# this or another signal changed its aspect

OnUpdate:
	# Se chiuso, guasto o RGG con binario bianco, non cambia
	# If unclear, faulty or RYY with a white track, no change
	if .aspect = red or .aspect = off or .aspect = fault or .aspect = red_yellow_yellow and .color = white
		return
	end
	# Qui è aperto; se segue un segnale guasto superabile, si chiude
	# Here it's clear; if a passable faulty signal follows, unclears
	if next.aspect = fault
		.click = 1
		return
	end
	# Prosecuzione itinerario: shunt se il segnale dopo è R o S
	# Route continuation: shunt if next signal is R or S
	if .nextStation = V and next.aspect = red or next.aspect = shunt
		.aspect = shunt
		return
	end

	# Deviata vera o avviso nascosto che la forza - prima controllo gli avvisi
	# Diverging route, true or forced by the hidden distant - check distants first
	if .switchThrown = 1 or .nextStation = K or nextApproach.script = "rfi_avv_dev.tds"
		# Avvisi che richiedono RGG: deviate forzate verso (R | S | RGG) corto
		# Distants requiring RYY: forced diversions towards a short (R | S | RYY)
		if nextApproach.aspect = red_short_thrown
			.aspect = red_yellow_yellow
			return
		end
		# Avvisi che richiedono RG: GG o deviata forzata verso GG
		# Distants requiring RY: YY or forced diversions towards YY
		if nextApproach.aspect = yellow_yellow or nextApproach.aspect = yellow_thrown and Signal(143,40).aspect='shunt'
			if .nextLimit < 60
				.aspect = red_yellow_30				# Deviata a 30 - Diverging route requiring 30 km/h
			else
				.aspect = red_yellow_60				# Deviata a 60 - Diverging route requiring 60 km/h
			end
			return
		end
		# Avvisi che richiedono RGx: (G | GV | GxVx | Gx/Vx) vicini al successivo, anche forzati
		# Distants requiring RYx: (Y | YG | YxGx | Yx/Gx) near the next signal, even forced
		if nextApproach.aspect = flashing_thrown or nextApproach.aspect > short and nextApproach.aspect < shoru and Signal(143,40).aspect='shunt'
			if .nextLimit < 60 						# Deviata a 30 - Diverging route requiring 30 km/h
				.aspect = red_yellow_flashing_30
			else
				if .nextLimit < 100					# Deviata a 60 - Diverging route requiring 60 km/h
					.aspect = red_yellow_flashing_60
				else 								# Deviata a 100 - Diverging route requiring 100 km/h
					.aspect = red_yellow_flashing_100
				end
			end
			return
		end
		# Avvisi che richiedono RV: (G | GV | GxVx | Gx/Vx) a distanza normale o (Gx | V), anche forzati
		# Distants requiring RG: (Y | YG | YxGx | Yx/Gx) at normal distance or (Yx | V), even forced
		if nextApproach.aspect = yellow_green or nextApproach.aspect = yellow_green_flashing or nextApproach.aspect = yellow_green_switching and Signal(143,40).aspect='shunt'
			if .nextLimit < 60
				.aspect = red_green_30
			else
				if .nextLimit < 100
					.aspect = red_green_60
				else
					.aspect = red_green_100
				end
			end
			return
		end
		if nextApproach.aspect = yellow or nextApproach.aspect = yellow_flashing or nextApproach.aspect = green or nextApproach.aspect = green_thrown and Signal(143,40).aspect='shunt'
			if .nextLimit < 60
				.aspect = red_green_30
			else
				if .nextLimit < 100
					.aspect = red_green_60
				else
					.aspect = red_green_100
				end
			end
			return
		end

		# Aspetti che richiedono RGG (R | S | RGG se corti o forzati tali) o RG (idem se normali, o GG):
		# Aspects requiring RYY (R | S | RYY when short or forced so) or RY (the same when normal, or YY):
		if next.aspect = yellow_yellow or next.aspect = red or next.aspect = shunt or next.aspect = red_yellow_yellow and Signal(143,40).aspect='shunt'
			if next.aspect ! yellow_yellow and .nextLength < 600 or nextApproach.aspect = red_short
				.aspect = red_yellow_yellow			# Blocco corto - Short block
			else
				if .nextLimit < 60
					.aspect = red_yellow_30
				else
					.aspect = red_yellow_60
				end
			end
			return
		end
		# Se anche il prossimo è deviato (non è R | S | RGG | GG)
		# If next is also diverging (not showing R | S | RYY | YY)
		if next.switchThrown = 1 or next.nextStation = K or next.nextApproach.script = "rfi_avv_dev.tds"
			# Se il prossimo è (G | Gx | V) è deviato ma incompleto: RG invece di (RGV | RGxVx | RGx/Vx)
			# If next shows (Y | Yx | G) it's diverging but incomplete: show RY instead of RYG | RYxGx | RYx/Gx
			if next.aspect = short_yellow or next.aspect = yellow or next.aspect = yellow_flashing or next.aspect = green and Signal(143,40).aspect='shunt'
				if .nextLimit < 60
					.aspect = red_yellow_30
				else
					.aspect = red_yellow_60
				end
				return
			end
			# Prossimo deviato e completo - Next is diverging and complete

			if .nextLimit < 60		# Prima deviata a 30 - First diversion at 30 km/h
				# Seconda deviata a 30 o forzata tale - Second diversion at 30 km/h or forced so
				if next.nextLimit < 60 or next.aspect = red_yellow_30 and Signal(143,40).aspect='shunt'
					.aspect = red_yellow_green_30
				else
					# Seconda deviata a 60 o forzata tale - Second diversion at 60 km/h or forced so
					if next.nextLimit < 100 or next.aspect = red_yellow_60 or next.aspect = red_yellow_green_60 and Signal(143,40).aspect='shunt'
						.aspect = red_yellow_green_flashing_30
					else
						# Seconda deviata a 100, non forzata - Second diversion at 100 km/h, no forcing
						.aspect = red_yellow_green_switching_30
					end
				end
				return
			end
			if .nextLimit < 100		# Prima deviata a 60 - First diversion at 60 km/h
				# Seconda deviata a 30 o forzata tale - Second diversion at 30 km/h or forced so
				if next.nextLimit < 60 or next.aspect = red_yellow_30 and Signal(143,40).aspect='shunt'
					.aspect = red_yellow_green_60
				else
					# Seconda deviata a 60 o forzata tale - Second diversion at 60 km/h or forced so
					if next.nextLimit < 100 or next.aspect = red_yellow_60 or next.aspect = red_yellow_green_60 and Signal(143,40).aspect='shunt'
						.aspect = red_yellow_green_flashing_60
					else
						# Seconda deviata a 100, non forzata - Second diversion at 100 km/h, no forcing
						.aspect = red_yellow_green_switching_60
					end
				end
			else 		# Prima deviata a 100, non forzabile - First diversion at 100 km/h, no forcing
				# Seconda deviata a 30 o forzata tale: abbasso la prima a 60
				# Second diversion at 30 km/h or forced so: slow down the first to 60 km/h
				if next.nextLimit < 60 or next.aspect = red_yellow_30 and Signal(143,40).aspect='shunt'
					.aspect = red_yellow_green_60
				else
					# Seconda deviata a 60 o forzata tale - Second diversion at 60 km/h or forced so
					if next.nextLimit < 100 or next.aspect = red_yellow_60 or next.aspect = red_yellow_green_60 and Signal(143,40).aspect='shunt'
						.aspect = red_yellow_green_flashing_100
					else
						# Seconda deviata a 100, non forzata - Second diversion at 100 km/h, no forcing
						.aspect = red_yellow_green_switching_100
					end
				end
			end
			return
		end
		# Prossimo non deviato e non (R | S | RGG | GG) - Next is not diverging and not showing (R | S | RYY | GG)

		# Aspetti che richiedono RGx: (G | GV | GxVx | Gx/Vx) se vicini al successivo
		# Aspects requiring RYx: (Y | YG | YxGx | Yx/Gx) if near the next signal
		if next.aspect > short and next.aspect < shoru and Signal(143,40).aspect='shunt'
			if .nextLimit < 60
				.aspect = red_yellow_flashing_30
			else
				if .nextLimit < 100
					.aspect = red_yellow_flashing_60
				else
					.aspect = red_yellow_flashing_100
				end
			end
			return
		end
		# Ogni altro caso richiede RV (V | Gx | G | GV | GxVx | Gx/Vx), compreso nessun altro segnale (uscita)
		# Any other case requires RG (G | Yx | Y | YG | YxGx | Yx/Gx), including no signal follows (exit point)
		if .nextLimit < 60
			.aspect = red_green_30
		else
			if .nextLimit < 100
				.aspect = red_green_60
			else
				.aspect = red_green_100
			end
		end
	else
	# Corretto tracciato (.switchThrown = 0 e deviata non forzata da avvisi speciali) - prima controllo gli avvisi
	# Straight route (.switchThrown = 0 and no diversion forced by special distants) - check distants first

		# Avvisi che richiedono G: GG - Distants aspects requiring Y: YY
		if nextApproach.aspect = yellow_yellow and Signal(143,40).aspect='shunt'
			.aspect = yellow
			return
		end
		# Avvisi che richiedono Gx: (G | GV | GxVx | Gx/Vx) se vicini al successivo
		# Distants requiring Yx: (Y | YG | YxGx | Yx/Gx) if near the next signal
		if nextApproach.aspect > short and nextApproach.aspect < shoru and Signal(143,40).aspect='shunt'
			.aspect = yellow_flashing
			return
		end
		# Avvisi che richiedono V: (G | GV | GxVx | Gx/Vx) a distanza normale o (Gx | V)
		# Distant aspects requiring G: (Y | YG | YxGx | Yx/Gx) at normal distance or (Yx | V)
		if nextApproach.aspect = yellow_green or nextApproach.aspect = yellow_green_flashing or nextApproach.aspect = yellow_green_switching and Signal(143,40).aspect='shunt'
			.aspect = green
			return
		end
		if nextApproach.aspect = yellow or nextApproach.aspect = yellow_flashing or nextApproach.aspect = green and Signal(143,40).aspect='shunt'
			.aspect = green
			return
		end

		# Aspetti che richiedono GG (R | S | RGG se corti o forzati tali) o G (idem se normali, o GG):
		# Aspects requiring YY (R | S | RYY when short or forced so) or Y (the same when normal, or YY):
		if next.aspect = yellow_yellow or next.aspect = red or next.aspect = shunt or next.aspect = red_yellow_yellow and Signal(143,40).aspect='shunt'
			if next.aspect ! yellow_yellow and .nextLength < 900 or nextApproach.aspect = red_short
				.aspect = yellow_yellow		# Blocco corto - Short block
			else
				if .nextLength < 1350
					.aspect = short_yellow
				else
					.aspect = yellow
				end
			end
			return
		end
		# Se il prossimo è deviato (non è R | S | RGG | GG) - If next is diverging (not showing R | S | RYY | YY)
		if next.switchThrown = 1 or next.nextStation = K or next.nextApproach.script = "rfi_avv_dev.tds"
			# Se il prossimo è (G | Gx | V) è deviato ma incompleto: G invece di (GV | GxVx | Gx/Vx)
			# If next shows (Y | Yx | G) it's diverging but incomplete: show Y instead of (YG | YxGx | Yx/Gx)
			if next.aspect = short_yellow or next.aspect = yellow or next.aspect = yellow_flashing or next.aspect = green and Signal(143,40).aspect='shunt'
				if .nextLength < 1350
					.aspect = short_yellow
				else
					.aspect = yellow
				end
				return
			end
			# Prossimo deviato e completo - Next is diverging and complete

			# Se deviata a 30 o forzata tale, abbassa anche l'avviso
			# If next is diverging at 30, or forced so, slow down also the distant
			if next.nextLimit < 60 or next.aspect = red_yellow_30 and Signal(143,40).aspect='shunt'
				if .nextLength < 1350
					.aspect = short_yellow_green_30
				else
					.aspect = yellow_green
				end
			else
				# Se deviata a 60 o forzata tale, abbassa anche l'avviso
				# If next is diverging at 60, or forced so, slow down also the distant
				if next.nextLimit < 100 or next.aspect = red_yellow_60 or next.aspect = red_yellow_green_60 and Signal(143,40).aspect='shunt'
					if .nextLength < 1350
						.aspect = short_yellow_green_60
					else
						.aspect = yellow_green_flashing
					end
				else
					# Deviata a 100, non forzabile - Next is diverging at 100, no forcing
					if .nextLength < 1350
						.aspect = short_yellow_green_100
					else
						.aspect = yellow_green_switching
					end
				end
			end
			return
		end		# Prossimo non deviato e non (R | S | RGG | GG) - Next is not diverging and not showing (R | S | RYY | YY)

		# Aspetti che richiedono Gx: (G | GV | GxVx | Gx/Vx) se vicini al successivo
		# Aspects requiring Yx: (Y | YG | YxGx | Yx/Gx) if near the next signal
		if next.aspect > short and next.aspect < shoru and Signal(143,40).aspect='shunt'
			.aspect = yellow_flashing
			return
		end
		# Ogni altro caso richiede V (V | Gx | G | GV | GxVx | Gx/Vx o nessun altro segnale: uscita)
		# Any other case requires G (G | Yx | Y | YG | YxGx | Yx/Gx or no signal follows: exit point)
		.aspect = green
	end
end

# the player or a script cleared the signal for shunting

OnShunt:
	if .aspect = off
		.aspect = fault
	else
		# Se il binario è occupato: RGG, altrimenti S
		# If the track is occupied: RYY, otherwise S
		if .occupied = 1
			.aspect = red_yellow_yellow
		else
			.aspect = shunt
		end
	end
end

# a train passed the signal

OnCross:
	# Se seguito da un segnale di partenza (bloccato), lo sblocca
	# If followed by a (locked) exit signal, unlock it
	if nextApproach.script = "rfi_avv_part.tds" or next.script > "rfi_part" and next.script < "rfi_paru"
		next.fixedred = 0
	end
	if .aspect = fault
		.aspect = off
	else
		.aspect = red
	end
end

# the player or a script uncleared the signal

OnUncleared:
	# Se seguito da un segnale di partenza (bloccato), lo sblocca
	# If followed by a (locked) exit signal, unlock it
	if nextApproach.script = "rfi_avv_part.tds" or next.script > "rfi_part" and next.script < "rfi_paru"
		next.fixedred = 0
	end
	if .aspect = fault
		.aspect = off
	else
		.aspect = red
	end
end
