# Segnale di avviso puro a una vela quadra; puņ precedere solo un segnale imperativo
# e non puņ mostrare aspetti deviati, neanche incompleti.
# Gli aspetti spenti sono due, a seconda che segua un segnale spento superabile o no.
#
# Aspetti: G, Gx, V, O (prossimo spento non superabile), D (prossimo spento superabile)

# Pure distant signal with 1 square head; it cannot show diverging aspects, not even
# incomplete, and only a main signal can follow. The off aspects are two, depending
# on the unlit signal that follows: passable or not.
#
# Aspects: Y, Yx, G, O (next unlit not passable), D (next unlit passable)

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

Aspect: green
	IconE: NQ_g_E.xpm
	IconW: NQ_g_W.xpm
	IconN: NQ_g_N.xpm
	IconS: NQ_g_S.xpm
	Action: none

Aspect: yellow
	IconE: NQ_y_E.xpm
	IconW: NQ_y_W.xpm
	IconN: NQ_y_N.xpm
	IconS: NQ_y_S.xpm
	Action: none

Aspect: short_yellow
	IconE: NQ_y_E.xpm
	IconW: NQ_y_W.xpm
	IconN: NQ_y_N.xpm
	IconS: NQ_y_S.xpm
	Action: none

Aspect: yellow_flashing
	IconE: NQ_y_E.xpm NQ_b_E.xpm
	IconW: NQ_y_W.xpm NQ_b_W.xpm
	IconN: NQ_y_N.xpm NQ_b_N.xpm
	IconS: NQ_y_S.xpm NQ_b_S.xpm
	Action: none

Aspect: off
	IconE: NQ_b_E.xpm
	IconW: NQ_b_W.xpm
	IconN: NQ_b_N.xpm
	IconS: NQ_b_S.xpm
	Action: none

Aspect: disabled
	IconE: NQ_b_E.xpm
	IconW: NQ_b_W.xpm
	IconN: NQ_b_N.xpm
	IconS: NQ_b_S.xpm
	Action: none

# initial aspect

OnInit:
	if next.aspect = off or next.aspect = fault
		.aspect = off
	else
		.aspect = yellow
	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 G: (R | S | RGG | GG) o il prossimo č deviato (segnale incompleto), anche forzato
	# Normal aspects requiring Y: (R | S | RYY | YY) or next is diverging (incomplete aspect), even forced
	if next.aspect = yellow_yellow or next.aspect = red or next.aspect = shunt or next.aspect = red_yellow_yellow or next.switchThrown = 1 or next.nextStation = K or next.nextApproach.script = "rfi_avv_dev.tds"
		if .nextLength < 1200
			.aspect = short_yellow
		else
			.aspect = yellow
		end
	else
		# 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
			.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

# a train passed the signal

OnCross:
	return
end
