# Segnale di avviso speciale che mostra la posizione delle sbarre di un PL,
# da collegare all'elemento di binario subito dopo la 'strada' (usare
# un segnale per ciascuna direzione), al quale va assegnato lo script 
# "rfi_sig_up_on_exit.tds" per far aggiornare i segnali quando un treno passa.
# Le sbarre si aprono quando tale elemento  libero (nero) e si chiudono quando
#  bloccato, tipicamente perch  stato aperto il segnale precedente al PL.
# Se i binari sono pi di uno  necessario adattare due copie di questo script
# per ogni binario del PL (ne verr usata una per ogni direzione), inserendo al
# posto di B1..B4 le coordinate degli elementi a cui sono collegate le sbarre
# o le luci degli altri binari e spostando il # dal caso desiderato al primo.

# Aspetti: open (sbarre aperte), closed (sbarre chiuse), unlit (sbarre guaste)

# Special distant signal showing the position of the gates of a level crossing.
# It must be linked to the track element just after the 'road' (use a signal
# for each direction), to which the "rfi_sig_up_on_exit.tds" script must be as-
# signed, so passing trains update the signals. 
# The barriers are raised when the above track element is free (black) and close
# down otherwise, tipically beacause the signal preceding the LC has been cleared.
# If the tracks are more then one, two copies of this script must be adapted
# for each track of the LC (one for each direction), by replacing B1..B4 with
# the coordinates to which the barriers or lights of the other tracks are
# linked, and by moving the # from the needed case to the first one.

# Aspects of the gates: open, closed, unlit

# P.Rosati  01/06/2020 (Versione 5.0)

Aspect: open
	IconE: PL_I_X.xpm
	IconW: PL_I_X.xpm
	IconN: PL_I_X.xpm
	IconS: PL_I_X.xpm
	Action: none

Aspect: unlit
	IconE: PL___X.xpm
	IconW: PL___X.xpm
	IconN: PL___X.xpm
	IconS: PL___X.xpm
	Action: none

Aspect: closed
	IconE: PL_-_X.xpm
	IconW: PL_-_X.xpm
	IconN: PL_-_X.xpm
	IconS: PL_-_X.xpm
	Action: none

# initial aspect

OnInit:
	.aspect = open
end

# the player or a script cleared the signal

OnCleared:
end

# the player or a script cleared the signal for shunting

OnShunt:
end

# another signal changed its aspect

OnUpdate:
	if .aspect = unlit
		return
			# Con pi binari spostare il # dal caso desiderato a alla linea dopo 'else'
	else	# With more tracks move the # from the desired case to the line after 'else'
		if Track(28,28).color ! black or Track(30,28).color ! black		
			.aspect = closed	
		else
			.aspect = open
		end
	end
end