# Segnale ripetitore di partenza a una vela tonda, seguito da qualsiasi segnale.
# Ha l'aspetto di un segnale di partenza con triangolo a una vela, pertanto i se-
# gnali precedenti non si aprono se questo è aperto, e viceversa questo si richiude
# se il segnale precedente è aperto verso di esso. Dovrebbe essere seguito da un
# altro segnale di partenza (con o senza triangolo), ed è l'unico caso in cui que-
# sti due segnali possono essere aperti contemporaneamente. Non porta l'avviso del
# successivo, ma indica solo se è aperto con o senza limitazioni; da spento è apri-
# bile solo con Ctrl-click.
#
# Aspetti:             off, fault, R, S (se segue R, S, off o fault),
#                      V (se segue V o RV), G (altrimenti)
# da considerare come: spento, guasto, R, S, RV, RG

# Repeater of an exit signal, with 1 round head and a triangle below, followed by
# whatever signal. It looks like a 1 head departure signal, so previous signals
# cannot be cleared if this is clear, and this will unclear if the previuos signal
# is clear towards it. It should be followed by another departure signal (with or
# without the triangle) and this is the only case when both signals can be clear to-
# gether. It doesn't act as a distant of the next, but it just tells if next is clear
# with or without limitations. When unlit it can be cleared only with Ctrl-click.
#
# Aspects:                       off, fault, R, S (if R, S, off or fault follows),
#                                G (if G or RG follows), Y (otherwise)
# to be "seen" by the driver as: off, fault, R, S, RG, RY

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

Aspect: red
	IconE: TN_r_E.xpm
	IconW: TN_r_W.xpm
	IconN: TN_r_N.xpm
	IconS: TN_r_S.xpm
	Action: stop

Aspect: shunt
	IconE: TN_r_E.xpm
	IconW: TN_r_W.xpm
	IconN: TN_r_N.xpm
	IconS: TN_r_S.xpm
	Action: speedLimit 29

Aspect: red_yellow_30
	IconE: TN_y_E.xpm
	IconW: TN_y_W.xpm
	IconN: TN_y_N.xpm
	IconS: TN_y_S.xpm
	Action: speedLimit 30

Aspect: red_yellow_flashing_30
	IconE: TN_y_E.xpm TN_b_E.xpm
	IconW: TN_y_W.xpm TN_b_W.xpm
	IconN: TN_y_N.xpm TN_b_N.xpm
	IconS: TN_y_S.xpm TN_b_S.xpm
	Action: speedLimit 30

Aspect: red_green_30
	IconE: TN_g_E.xpm
	IconW: TN_g_W.xpm
	IconN: TN_g_N.xpm
	IconS: TN_g_S.xpm
	Action: speedLimit 30

Aspect: red_yellow_60
	IconE: TN_y_E.xpm
	IconW: TN_y_W.xpm
	IconN: TN_y_N.xpm
	IconS: TN_y_S.xpm
	Action: speedLimit 60

Aspect: red_yellow_flashing_60
	IconE: TN_y_E.xpm TN_b_E.xpm
	IconW: TN_y_W.xpm TN_b_W.xpm
	IconN: TN_y_N.xpm TN_b_N.xpm
	IconS: TN_y_S.xpm TN_b_S.xpm
	Action: speedLimit 60

Aspect: red_green_60
	IconE: TN_g_E.xpm
	IconW: TN_g_W.xpm
	IconN: TN_g_N.xpm
	IconS: TN_g_S.xpm
	Action: speedLimit 60

Aspect: off
	IconE: TN_d_E.xpm
	IconW: TN_d_W.xpm
	IconN: TN_d_N.xpm
	IconS: TN_d_S.xpm
	Action: stop

Aspect: fault
	IconE: TN_d_E.xpm
	IconW: TN_d_W.xpm
	IconN: TN_d_N.xpm
	IconS: TN_d_S.xpm
	Action: speedLimit 30

# initial aspect

OnInit:
	.departure = 1
	.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
	# Aspetto temporaneo: la OnUpdate imposterà quello giusto
	# Temporary aspect: the OnUpdate will set the right one
	.aspect = red_green_30
end

# this or another signal changed its aspect

OnUpdate:
	# Se chiuso o guasto non cambia - If unclear or faulty no change
	if .aspect = red or .aspect = off or .aspect = fault
		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
	# Se qualcosa forza la manovra o segue un segnale R, S o spento (superabile o non mascherato): S
	# If shunting is forced or a signal at R | S or unlit (passable or unmasked) follows: S
	if next.script = "rfi_sam_i.tds" or next.script = "rfi_marm_i.tds" or next.script = "rfi_marm_id.tds" or .nextLimit < 30 or .color = white or next.aspect = disabled or next.aspect = off or next.aspect = red  or next.aspect = shunt
		.aspect = shunt
		return
	end
	# Aspetti che consentono V - aspects allowing G
	if nextApproach.aspect = green or next.aspect > greem and next.aspect < greeo
		if .nextLimit < 60
			.aspect = red_green_30
		else
			.aspect = red_green_60
		end
		return
	end
	if next.aspect > red_greem and next.aspect < red_greeo
		if .nextLimit < 60
			.aspect = red_green_30
		else
			.aspect = red_green_60
		end
		return
	end
	# Aspetti che consentono Gx - aspects allowing Yx
	if nextApproach.aspect = yellow_flashing or next.aspect > yellow_f and next.aspect < yellow_g
		if .nextLimit < 60
			.aspect = red_yellow_flashing_30
		else
			.aspect = red_yellow_flashing_60
		end
		return
	end
	if next.aspect > red_yellow_f and next.aspect < red_yellow_g
		if .nextLimit < 60
			.aspect = red_yellow_flashing_30
		else
			.aspect = red_yellow_flashing_60
		end
		return
	end
	# Gli altri casi richiedono G - Other cases require Y
	if .nextLimit < 60
		.aspect = red_yellow_30
	else
		.aspect = red_yellow_60
	end
end

# the player or a script cleared the signal for shunting

OnShunt:
	if .aspect = off
		.aspect = fault
	else
		.aspect = shunt
	end
end

# a train passed the signal

OnCross:
	if .aspect = fault
		.aspect = off
	else
		.aspect = red
	end
end

# the player or a script uncleared the signal

OnUncleared:
	if .aspect = fault
		.aspect = off
	else
		.aspect = red
	end
end
