# Segnale di avviso speciale che implementa l'indicatore di direzione (numeri 0-9) o le
# lettere A, D, P (stazioni impresenziate), ^ (prosecuzione itinerario), I (binario in-
# gombro); questa versione "guarda" due segnali in avanti, per le stazioni con doppio
# segnalamento. L'indicatore va posto adiacente al PRIMO segnale (normale o comune), e
# collegato prima di esso, ma si accende inserendo a valle del SECONDO segnale una sta-
# zione fittizia pari al numero (in lettere) o alla lettera (maiuscola) da visualizzare
# (tranne la 'I' che è automatica); Le lettere A, D, P sono sempre accese, mentre le al-
# tre indicazioni si accendono solo se il SECONDO segnale è aperto (anche in shunt); la
# lettera ^ richiede la lettera V dopo il PRIMO segnale, e che esso sia aperto in shunt.
#
# Aspetti: nothing (nessuna direzione), zero, one, two, three, four, five, six, seven, eight, nine,
#          off (spento), A, D, P, V (indicatore ^ di prosecuzione itinerario), I (binario ingombro)

# Special pure distant implementing the direction indicator (numbers 0-9) and the letters
# A, D, P (unmanned stations), ^ (route continuation), I (track is occupied); this version
# "looks" two signals ahead, for stations featuring two exit signals. The indicator should
# be placed adjoined to the FIRST exit signal (normal or shared) and linked just before it.
# Put a fake station in each branch after the SECOND signal, named after the number (in
# letters) or letter (uppercase) you want to appear (except 'I', which is automatic).
# Letters A, D, P are always lit, while the other indications are lit only when the SECOND
# signal is clear (even at shunt); the ^ letter requires the letter V after the FIRST sig-
# nal, and the latter showing shunt.
#
# Aspects: nothing (no direction), zero, one, two, three, four, five, six, seven, eight, nine, A, D,
#          P, V (for '^', the route continuation indicator), I (track is occupied), off (disabled)

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

Aspect: off
	IconE: ID_off_E.xpm
	IconW: ID_off_W.xpm
	IconN: ID_off_N.xpm
	IconS: ID_off_S.xpm
	Action: none

Aspect: nothing
	IconE: ID_off_E.xpm
	IconW: ID_off_W.xpm
	IconN: ID_off_N.xpm
	IconS: ID_off_S.xpm
	Action: none

Aspect: zero
	IconE: ID_0_E.xpm
	IconW: ID_0_W.xpm
	IconN: ID_0_N.xpm
	IconS: ID_0_S.xpm
	Action: none

Aspect: one
	IconE: ID_1_E.xpm
	IconW: ID_1_W.xpm
	IconN: ID_1_N.xpm
	IconS: ID_1_S.xpm
	Action: none

Aspect: two
	IconE: ID_2_E.xpm
	IconW: ID_2_W.xpm
	IconN: ID_2_N.xpm
	IconS: ID_2_S.xpm
	Action: none

Aspect: three
	IconE: ID_3_E.xpm
	IconW: ID_3_W.xpm
	IconN: ID_3_N.xpm
	IconS: ID_3_S.xpm
	Action: none

Aspect: four
	IconE: ID_4_E.xpm
	IconW: ID_4_W.xpm
	IconN: ID_4_N.xpm
	IconS: ID_4_S.xpm
	Action: none

Aspect: five
	IconE: ID_5_E.xpm
	IconW: ID_5_W.xpm
	IconN: ID_5_N.xpm
	IconS: ID_5_S.xpm
	Action: none

Aspect: six
	IconE: ID_6_E.xpm
	IconW: ID_6_W.xpm
	IconN: ID_6_N.xpm
	IconS: ID_6_S.xpm
	Action: none

Aspect: seven
	IconE: ID_7_E.xpm
	IconW: ID_7_W.xpm
	IconN: ID_7_N.xpm
	IconS: ID_7_S.xpm
	Action: none

Aspect: eight
	IconE: ID_8_E.xpm
	IconW: ID_8_W.xpm
	IconN: ID_8_N.xpm
	IconS: ID_8_S.xpm
	Action: none

Aspect: nine
	IconE: ID_9_E.xpm
	IconW: ID_9_W.xpm
	IconN: ID_9_N.xpm
	IconS: ID_9_S.xpm
	Action: none

Aspect: i
	IconE: ID_I_E.xpm
	IconW: ID_I_W.xpm
	IconN: ID_I_N.xpm
	IconS: ID_I_S.xpm
	Action: none

Aspect: a
	IconE: ID_A_E.xpm
	IconW: ID_A_W.xpm
	IconN: ID_A_N.xpm
	IconS: ID_A_S.xpm
	Action: none

Aspect: d
	IconE: ID_D_E.xpm
	IconW: ID_D_W.xpm
	IconN: ID_D_N.xpm
	IconS: ID_D_S.xpm
	Action: none

Aspect: p
	IconE: ID_P_E.xpm
	IconW: ID_P_W.xpm
	IconN: ID_P_N.xpm
	IconS: ID_P_S.xpm
	Action: none

Aspect: v
	IconE: ID_V_E.xpm ID_off_E.xpm
	IconW: ID_V_W.xpm ID_off_W.xpm
	IconN: ID_V_N.xpm ID_off_N.xpm
	IconS: ID_V_S.xpm ID_off_S.xpm
	Action: none

# initial aspect

OnInit:
	if .nextApproach.script > "rfi_com" and .nextApproach.script < "rfi_con"
		# Se il primo segnale (comune) è spento, sta spento - If the first signal (shared) is unlit, stay off
		if nextApproach.aspect = off or nextApproach.aspect = disabled or nextApproach.aspect = fault
			.aspect = off
			return
		end
		# Le lettere si accendono sempre - Letters are always shown
		if nextApproach.nextStation = A or .nextStation = A
			.aspect = a
			return
		end
		if nextApproach.nextStation = D or .nextStation = D
			.aspect = d
			return
		end
		if nextApproach.nextStation = P or .nextStation = P
			.aspect = p
			return
		end
		.aspect = nothing
	else
		# Se il primo segnale (normale) è spento, sta spento - If the first signal (normal) is unlit, stay off
		if next.aspect = off or next.aspect = disabled or next.aspect = fault
			.aspect = off
			return
		end
		# Le lettere si accendono sempre - Letters are always shown
		if next.nextStation = A or .nextStation = A
			.aspect = a
			return
		end
		if next.nextStation = D or .nextStation = D
			.aspect = d
			return
		end
		if next.nextStation = P or .nextStation = P
			.aspect = p
			return
		end
		.aspect = nothing
	end
end

# the player or a script cleared the signal

OnCleared:
	return
end

# this or another signal changed its aspect

OnUpdate:
	if .nextApproach.script > "rfi_com" and .nextApproach.script < "rfi_con"
		# Se il primo segnale (comune) è spento, sta spento - If the first signal (shared) is unlit, stay off
		if nextApproach.aspect = off or nextApproach.aspect = disabled or nextApproach.aspect = fault
			.aspect = off
			return
		end
		# Binario ingombro: fusione - Track is occupied: joining
		if nextApproach.aspect ! red and nextApproach.color = white and nextApproach.occupied = 1
			.aspect = i
			return
		end
		# La lettera lambda ^ si accende solo se il primo segnale è aperto in shunt
		# The lambda letter ^ is lit only if the first signal shows shunt
		if nextApproach.aspect = shunt and nextApproach.nextStation = V or .nextStation = V
			.aspect = v
			return
		end
		# Le lettere si accendono sempre - Letters are always shown
		if nextApproach.next.nextStation = A or nextApproach.nextStation = A
			.aspect = a
			return
		end
		if nextApproach.next.nextStation = D or nextApproach.nextStation = D
			.aspect = d
			return
		end
		if nextApproach.next.nextStation = P or nextApproach.nextStation = P
			.aspect = p
			return
		end
		# I numeri si accendono solo se entrambi i segnali sono aperti (anche in shunt)
		# Numbers are lit only when both signals are clear (also at shunt)
		if nextApproach.aspect ! red and nextApproach.aspect ! shunt and nextApproach.next.aspect ! red and nextApproach.next.aspect ! off and nextApproach.next.aspect ! disabled and nextApproach.next.aspect ! fault
			if nextApproach.next.nextStation = zero
				.aspect = zero
				return
			end
			if nextApproach.next.nextStation = uno or nextApproach.next.nextStation = one
				.aspect = one
				return
			end
			if nextApproach.next.nextStation = due or nextApproach.next.nextStation = two
				.aspect = two
				return
			end
			if nextApproach.next.nextStation = tre or nextApproach.next.nextStation = three
				.aspect = three
				return
			end
			if nextApproach.next.nextStation = quattro or nextApproach.next.nextStation = four
				.aspect = four
				return
			end
			if nextApproach.next.nextStation = cinque or nextApproach.next.nextStation = five
				.aspect = five
				return
			end
			if nextApproach.next.nextStation = sei or nextApproach.next.nextStation = six
				.aspect = six
				return
			end
			if nextApproach.next.nextStation = sette or nextApproach.next.nextStation = seven
				.aspect = seven
				return
			end
			if nextApproach.next.nextStation = otto or nextApproach.next.nextStation = eight
				.aspect = eight
				return
			end
			if nextApproach.next.nextStation = nove or nextApproach.next.nextStation = nine
				.aspect = nine
				return
			end
		end
		.aspect = nothing		# Se non ho trovato niente... - If no fake station found...
	else
		# Se il primo segnale (normale) è spento, sta spento - If the first signal (normal) is unlit, stay off
		if next.aspect = off or next.aspect = disabled or next.aspect = fault
			.aspect = off
			return
		end
		# Binario ingombro: fusione - Track is occupied: joining
		if next.aspect ! red and next.color = white and next.occupied = 1
			.aspect = i
			return
		end
		# La lettera lambda ^ si accende solo se il primo segnale è aperto in shunt
		# The lambda letter ^ is lit only if the first signal shows shunt
		if next.aspect = shunt and next.nextStation = V or .nextStation = V
			.aspect = v
			return
		end
		# Le lettere si accendono sempre - Letters are always shown
		if next.next.nextStation = A or next.nextStation = A
			.aspect = a
			return
		end
		if next.next.nextStation = D or next.nextStation = D
			.aspect = d
			return
		end
		if next.next.nextStation = P or next.nextStation = P
			.aspect = p
			return
		end
		# I numeri si accendono solo se entrambi i segnali sono aperti (anche in shunt)
		# Numbers are lit only when both signals are clear (also at shunt)
		if next.aspect ! red and next.aspect ! shunt and next.next.aspect ! red and next.next.aspect ! off and next.next.aspect ! disabled and next.next.aspect ! fault
			if next.next.nextStation = zero
				.aspect = zero
				return
			end
			if next.next.nextStation = uno or next.next.nextStation = one
				.aspect = one
				return
			end
			if next.next.nextStation = due or next.next.nextStation = two
				.aspect = two
				return
			end
			if next.next.nextStation = tre or next.next.nextStation = three
				.aspect = three
				return
			end
			if next.next.nextStation = quattro or next.next.nextStation = four
				.aspect = four
				return
			end
			if next.next.nextStation = cinque or next.next.nextStation = five
				.aspect = five
				return
			end
			if next.next.nextStation = sei or next.next.nextStation = six
				.aspect = six
				return
			end
			if next.next.nextStation = sette or next.next.nextStation = seven
				.aspect = seven
				return
			end
			if next.next.nextStation = otto or next.next.nextStation = eight
				.aspect = eight
				return
			end
			if next.next.nextStation = nove or next.next.nextStation = nine
				.aspect = nine
				return
			end
		end
		.aspect = nothing		# Se non ho trovato niente... - If no fake station found...
	end
end

# a train passed the signal

OnCross:
	return
end
