# Segnale specifico di protezione di un PL con barriere, versione grande.
# Va preceduto dal relativo avviso, perché è un segnale imperativo.
# Se seguito dal segnale di avviso che simula le sbarre o le luci per le
# auto il funzionamento è più realistico: i segnali di tutti i lati dove
# ciò accade si apriranno insieme, e si chiuderanno (insieme) quando l'ul-
# timo treno libera il PL.
#
# Aspetti: unclear_* (chiuso), clear_* (aperto), *_off (spento),
#          *_not_closed (PL aperto o guasto), *_closed (PL chiuso)

# Special signal protecting a level crossing with gates, bigger version.
# It's a main signal that stops trains, so it should be preceded by a
# level crossing distant. If followed by the distant that simulates the
# gates or the lights for the cars, the simulation will be more realistic:
# the signals an all the sides where this happens will clear together, and
# will unclear (together) when the last train frees the LC.
#
# Aspects: unclear_* (unclear), clear_* (clear), *_off (unlit),
#          *_not_closed (LC open or faulty), *_closed (LC closed)

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

Aspect: unclear_not_closed
	IconE: LQ_r_big_E.xpm
	IconW: LQ_r_big_W.xpm
	IconN: LQ_r_big_N.xpm
	IconS: LQ_r_big_S.xpm
	Action: stop

Aspect: clear_not_closed
	IconE: LQ_r_big_E.xpm
	IconW: LQ_r_big_W.xpm
	IconN: LQ_r_big_N.xpm
	IconS: LQ_r_big_S.xpm
	Action: speedLimit 10

Aspect: clear_closed
	IconE: LQ_g_big_E.xpm
	IconW: LQ_g_big_W.xpm
	IconN: LQ_g_big_N.xpm
	IconS: LQ_g_big_S.xpm
	Action: proceed

Aspect: unclear_closed
	IconE: LQ_g_big_E.xpm
	IconW: LQ_g_big_W.xpm
	IconN: LQ_g_big_N.xpm
	IconS: LQ_g_big_S.xpm
	Action: stop

Aspect: clear_off
	IconE: LQ_b_big_E.xpm
	IconW: LQ_b_big_W.xpm
	IconN: LQ_b_big_N.xpm
	IconS: LQ_b_big_S.xpm
	Action: speedLimit 10

Aspect: unclear_off
	IconE: LQ_b_big_E.xpm
	IconW: LQ_b_big_W.xpm
	IconN: LQ_b_big_N.xpm
	IconS: LQ_b_big_S.xpm
	Action: stop

# initial aspect

OnInit:
	.aspect = unclear_not_closed
end

# the player or a script cleared the signal

OnCleared:
	if .aspect = unclear_off
		.aspect = clear_off
	else
		if nextApproach.aspect = unlit
			.aspect = clear_not_closed
		else
			.aspect = clear_closed
		end
	end
end

# this or another signal changed its aspect

OnUpdate:
	# Se guasto non cambia - If faulty no change
	if .aspect = unclear_off or .aspect = clear_off
		return
	end
	# Se verde: diventa rosso superabile se le barriere o le luci si guastano
	# If green: turns red but passable if the gates or the lights go faulty
	if .aspect = clear_closed
		if nextApproach.aspect = unlit
			.aspect = clear_not_closed
		end
		return
	end
	# Se rosso superabile: torna verde se il PL torna chiuso  
	# If reb but passable: turns green if the LC turns closed 
	if .aspect = clear_not_closed
		if .color = green and nextApproach.aspect = closed
			.aspect = clear_closed
		end
		return
	end
	# Qui è chiuso: verde se il PL è chiuso per altri treni
	# Here it's unclear: green if the LC is closed for other trains
	if nextApproach.aspect = closed
		.aspect = unclear_closed
	else
		.aspect = unclear_not_closed
	end
end

# the player or a script cleared the signal for shunting

OnShunt:
	if .aspect = unclear_off
		.aspect = clear_off
	else
		.aspect = clear_not_closed
	end
end

# a train passed the signal

OnCross:
	if .aspect = clear_off
		.aspect = unclear_off
		return
	end
	if .aspect = clear_not_closed
		.aspect = unclear_not_closed
		return
	end
	# Resta verde fino a che il PL si apre - # Remains green until the LC opens
	if nextApproach.aspect = closed
		.aspect = unclear_closed
	else
		.aspect = unclear_not_closed
	end
end

# the player or a script uncleared the signal

OnUncleared:
	if .aspect = clear_off
		.aspect = unclear_off
		return
	end
	if .aspect = clear_not_closed
		.aspect = unclear_not_closed
		return
	end
	# Resta verde se il PL è chiuso per altri treni
	# Remains green if the LC is closed for other trains
	if nextApproach.aspect = closed
		.aspect = unclear_closed
	else
		.aspect = unclear_not_closed
	end
end
