# Segnale di avviso puro a due vele quadre; può essere seguito solo da un segnale
# imperativo o dall'avviso che forza il blocco corto e non può mostrare aspetti
# deviati, neanche incompleti. Gli aspetti spenti sono due, a seconda che segua
# un segnale spento superabile o no. Per retrocompatibilità mostra ancora il GG,
# ma se appare il posizionamento del segnale è sbagliato.
#
# Aspetti: V, G, Gx, GV, GxVx, Gx/Vx,
#          O (prossimo spento non superabile), D (prossimo spento superabile)

# Pure distant signal with 2 square heads; can be followed only by a main signal
# or by the distant that forces a short block, and cennot show diverging aspects,
# not even incomplete. The off aspects are two, depending on the unlit signal
# that follows: passable or not. For backword compatibility it still shows YY,
# but if this happens the signal placement is wrong.
#
# Aspects: G, Y, Yx, YG, YxGx, Yx/Gx, O (next unlit not passable), D (next unlit passable)

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

Aspect: green
	IconE: NQ_gb_E.xpm
	IconW: NQ_gb_W.xpm
	IconN: NQ_gb_N.xpm
	IconS: NQ_gb_S.xpm
	Action: none

Aspect: yellow
	IconE: NQ_yb_E.xpm
	IconW: NQ_yb_W.xpm
	IconN: NQ_yb_N.xpm
	IconS: NQ_yb_S.xpm
	Action: none

Aspect: short_yellow
	IconE: NQ_yb_E.xpm
	IconW: NQ_yb_W.xpm
	IconN: NQ_yb_N.xpm
	IconS: NQ_yb_S.xpm
	Action: none

Aspect: yellow_flashing
	IconE: NQ_yb_E.xpm NQ_bb_E.xpm
	IconW: NQ_yb_W.xpm NQ_bb_W.xpm
	IconN: NQ_yb_N.xpm NQ_bb_N.xpm
	IconS: NQ_yb_S.xpm NQ_bb_S.xpm
	Action: none

Aspect: yellow_yellow
	IconE: NQ_yy_E.xpm
	IconW: NQ_yy_W.xpm
	IconN: NQ_yy_N.xpm
	IconS: NQ_yy_S.xpm
	Action: none

Aspect: yellow_green
	IconE: NQ_yg_E.xpm
	IconW: NQ_yg_W.xpm
	IconN: NQ_yg_N.xpm
	IconS: NQ_yg_S.xpm
	Action: none

Aspect: short_yellow_green_30
	IconE: NQ_yg_E.xpm
	IconW: NQ_yg_W.xpm
	IconN: NQ_yg_N.xpm
	IconS: NQ_yg_S.xpm
	Action: none

Aspect: yellow_green_flashing
	IconE: NQ_yg_E.xpm NQ_bb_E.xpm
	IconW: NQ_yg_W.xpm NQ_bb_W.xpm
	IconN: NQ_yg_N.xpm NQ_bb_N.xpm
	IconS: NQ_yg_S.xpm NQ_bb_S.xpm
	Action: none

Aspect: short_yellow_green_60
	IconE: NQ_yg_E.xpm NQ_bb_E.xpm
	IconW: NQ_yg_W.xpm NQ_bb_W.xpm
	IconN: NQ_yg_N.xpm NQ_bb_N.xpm
	IconS: NQ_yg_S.xpm NQ_bb_S.xpm
	Action: none

Aspect: yellow_green_switching
	IconE: NQ_yb_E.xpm NQ_bg_E.xpm
	IconW: NQ_yb_W.xpm NQ_bg_W.xpm
	IconN: NQ_yb_N.xpm NQ_bg_N.xpm
	IconS: NQ_yb_S.xpm NQ_bg_S.xpm
	Action: none

Aspect: short_yellow_green_100
	IconE: NQ_yb_E.xpm NQ_bg_E.xpm
	IconW: NQ_yb_W.xpm NQ_bg_W.xpm
	IconN: NQ_yb_N.xpm NQ_bg_N.xpm
	IconS: NQ_yb_S.xpm NQ_bg_S.xpm
	Action: none

Aspect: off
	IconE: NQ_bb_E.xpm
	IconW: NQ_bb_W.xpm
	IconN: NQ_bb_N.xpm
	IconS: NQ_bb_S.xpm
	Action: none

Aspect: disabled
	IconE: NQ_bb_E.xpm
	IconW: NQ_bb_W.xpm
	IconN: NQ_bb_N.xpm
	IconS: NQ_bb_S.xpm
	Action: none

# initial aspect

OnInit:
	if next.aspect = off or next.aspect = fault
		.aspect = off
	else
		if .nextLength < 600 or nextApproach.aspect = red_short
			.aspect = yellow_yellow		# Blocco corto - Short block
		else
			.aspect = yellow
		end
	end
end

# the player or a script cleared the signal

OnCleared:
	return
end

# this or another signal changed its aspect

OnUpdate:
	# Se il prossimo è spento, si spegne - If next is disabled, go disabled
	if next.aspect = disabled
		.aspect = disabled
		return
	end
	if next.aspect = off or next.aspect = fault
		.aspect = off
		return
	end
	# Niente deviate o avvisi dopo questo segnale
	# No diversions or normal distants after this signal

	# 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
		if next.aspect ! yellow_yellow and .nextLength < 600 or nextApproach.aspect = red_short
			.aspect = yellow_yellow		# Blocco corto - Short block
		else
			if .nextLength < 1200
				.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 G | Gx | V 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
			if .nextLength < 1200
				.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
			if .nextLength < 1200
				.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
				if .nextLength < 1200
					.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 < 1200
					.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
	# Normal aspects requiring Yx: (Y | YG | YxGx | Yx/Gx) if near the next signal
	if next.aspect > short and next.aspect < shoru
		.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

# a train passed the signal

OnCross:
	return
end
