'##############
'Matrix Script
'##############

'Simulates 80s style Matrix Line and Terminus Display (Type Annax)

'(c) 13.04.2010 Marcel Kuhnt

'Script Version: 1.1
'Omsi release: 1.0

'Needs:
'- Cockpit (Batterietrennschalter)
'- IBIS


'Revision History:
'- Marcel Kuhnt		10.08.2009	Added Revision History
'- Marcel Kuhnt		13.04.2010	Added Line List Script
'- Marcel Kuhnt		23.04.2010	Line right formatted
'- Dmitrij             12.2012  Изменён вывод конечной. Добавлена бегущая строка.
'								Заменять русские символы на это !!!
'								Д — }, Ц — |, Ь — ~, Я — #
'								д — $, ц — =, ь — >, я — ^

'------------------------------------------------------------------------------------------
{trigger:Matrix}

	(L.L.matrix_power) ! (S.L.matrix_power)
	(T.L.ev_kippschalter_aus)
	
{end}

{macro:Matrix_init}
	0 (S.L.Matrix_TerminusIndex_Last)
	0 (S.L.Matrix_Nr_Last)
	"                " (S.$.Matrix_str)
	"                @                @                " (S.$.Matrix_Terminus)
	"    " (S.$.Matrix_Nr)
{end}


{trigger:ai_scheduled_settarget}

'Stromversorgung herstellen  Для питания:
	1.0 (S.L.elec_V_battery)
	1 (S.L.elec_busbar_main_sw)
	1 (S.L.matrix_power)
	1 (S.L.bt_elec_12v)	


'Hier wird die Nummer eingestellt   Вот номер набора:
	(L.$.SetLineTo) 4 $SetLengthL (S.$.Matrix_Nmr)

'Hier wird das Ziel eingestellt   Вот целевой набор:
	1 (S.L.elec_busbar_main_sw)
	(L.L.AI_target_index) (S.L.IBIS_TerminusIndex) (M.V.GetTerminusCode) (S.L.Debug_2) (S.L.IBIS_TerminusCode)
	
{end}


{macro:Matrix_frame}


	(L.S.Month) 1 =
	{if}
		"#НВ"  (S.$.Month)
	{endif}
	
	(L.S.Month) 2 =
	{if}
		"ФЕВ"  (S.$.Month)
	{endif}
	
	(L.S.Month) 3 =
	{if}
		"МАР"  (S.$.Month)
	{endif}

	(L.S.Month) 4 =
	{if}
		"АПР"  (S.$.Month)
	{endif}
	
	(L.S.Month) 5 =
	{if}
		"МАЙ"  (S.$.Month)
	{endif}
	
	(L.S.Month) 6 =
	{if}
		"ИЮН"  (S.$.Month)
	{endif}
	
	(L.S.Month) 7 =
	{if}
		"ИЮЛ"  (S.$.Month)
	{endif}
	
	(L.S.Month) 8 =
	{if}
		"АВГ"  (S.$.Month)
	{endif}
	
	(L.S.Month) 9 =
	{if}
		"СЕН"  (S.$.Month)
	{endif}
	
	(L.S.Month) 10 =
	{if}
		"ОКТ"  (S.$.Month)
	{endif}
	
	(L.S.Month) 11 =
	{if}
		"НО#"  (S.$.Month)
	{endif}
	
	(L.S.Month) 12 =
	{if}
		"}ЕК"  (S.$.Month)
	{endif}

'-------------------------------------------------------------
'Бегущая строка

	(L.L.elec_busbar_main)
	(L.L.elec_12v) (L.L.matrix_power) && &&
	{if}

	
'----------------
'Вычисления
	(L.L.str_change_symbol) (S.L.str_change_symbol_last)

	(L.L.str_change_symbol) 1 <
	{if}
		(L.L.str_change_symbol) (L.S.Timegap) (C.L.str_speed) * + (S.L.str_change_symbol)
	{else}
		0 (S.L.str_change_symbol)
	{endif}
	
	(L.L.str_number_line) 4 <
	{if}
		(L.L.str_change_symbol) (L.L.str_change_symbol_last) !
		{if}
			(L.L.str_number_symbol) 16 <
			{if}
				(L.L.str_number_symbol) 1 + (S.L.str_number_symbol)
			{else}
				0 (S.L.str_number_symbol)
				(L.$.Matrix_str) (S.$.Matrix_Oldstr)
				(L.L.str_number_line) 1 + (S.L.str_number_line)
			{endif}
		{endif}
	{else}
		(L.L.time_show_str) (C.L.time_show_str) <
		{if}
			(L.L.time_show_str) (L.S.Timegap) + (S.L.time_show_str)
		{else}
			(L.L.str_number_line) (C.L.str_number_line) <
			{if}
				(L.L.str_number_line) 1 + (S.L.str_number_line)
				0 (S.L.time_show_str)
			{else}
				0 (S.L.str_number_line) (S.L.time_show_str)
				"                " (S.$.Matrix_Oldstr)
			{endif}	
		{endif}
	{endif}
		
'----------------

		
		(L.L.str_number_line) 0 =
		{if}
			"      Сле$ующа^ " (S.$.Matrix_Newstr)
		{endif}
		
		(L.L.str_number_line) 1 =
		{if}
			"остановка       " (S.$.Matrix_Newstr)
		{endif}
		
		(L.L.str_number_line) 2 =
		{if}
			(L.$.IBIS_busstop_name_next) 16 $SetLengthL (S.$.Matrix_Newstr)
		{endif}
		
		(L.L.str_number_line) 3 =
		{if}
			"                " (S.$.Matrix_Newstr)
		{endif}
		
		(L.L.str_number_line) 4 =
		{if}
'Вывод даты и время
'	Stunden: Часы :
			" "
			(L.S.Time) 3600 / s0 trunc s1 "02" $IntToStrEnh $+
			(L.L.Time_BlinkOn)
			{if}
				":" $+
			{else}
				" " $+
			{endif}
				
'	Minuten: Минуты :
			l0 l1 - 60 * s0 trunc s1 "02" $IntToStrEnh $+
			"  " $+
'	Tag: День:
			(L.S.Day) "02" $IntToStrEnh $+ "-" $+
'	Monat: Месяц :
			(L.$.Month) $+ "." $+
			" " $+
			(S.$.Matrix_str)
		{endif}
		
		(L.L.str_number_line) 5 =
		{if}
			" В салоне"
			" " $+
			(L.L.Cabinair_Temp) 0 >
			{if}
				"+" $+
			{else}
				"-" $+
			{endif}
			(L.L.Cabinair_Temp) abs " 2" $IntToStrEnh $+
			"?С " $+
			(S.$.Matrix_str)
		{endif}
		
		(L.L.str_number_line) 6 =
		{if}
			" На ули=е"
			" " $+
			(L.S.Weather_Temperature) 0 >
			{if}
				"+" $+
			{else}
				"-" $+
			{endif}
			(L.S.Weather_Temperature) abs " 2" $IntToStrEnh $+
			"?С " $+
			(S.$.Matrix_str)
		{endif}

		(L.L.str_number_line) 4 <
		{if}
'Вывод строки
			(L.$.Matrix_Oldstr) 16 (L.L.str_number_symbol) - $SetLengthR
			(L.$.Matrix_Newstr) (L.L.str_number_symbol) $SetLengthL $+
			(S.$.Matrix_str)
		{endif}

	{else}
		"                " (S.$.Matrix_str)	
	{endif}


'-------------------------------------------------------------


'				******************************+
' 		  		 Terminus-Matrix
'				******************************+
' Zeitdifferenz:
' разница во времени:
	(L.S.GetTime) (L.L.Matrix_TerminusActTimer) - s2

	l2 0 <
	{if}
		(L.S.GetTime) (S.L.Matrix_TerminusActTimer) 0 s2
		1 (S.L.Matrix_TerminusCreateString)
	{endif}


' Ob der Suffix >= 94 ist, speichere in s4:
	(L.L.IBIS_Linie_Suffix) 94 >= s4

'Changecounter zurьcksetzen: (wenn kein Wechselziel angezeigt wird)
	(L.L.IBIS_Linie_Suffix) 97 <=
	(L.L.IBIS_Linie_Suffix) 96 = ! &&
	(L.L.IBIS_Linie_Suffix) 95 = ! &&
	{if}
		0 (S.L.Matrix_ChangeCounter)
	{endif}


' Wenn sich das neue Ziel vom alten unterscheidet, dann wechsele:

	l4 ! (L.L.IBIS_TerminusIndex) s0 (L.L.Matrix_TerminusIndex_Last) = !  &&

' ODER wenn die Nummer eine "zielbeeinflussende" ist und ungleich dem negativen Matrix_terminusIndex_Last:

	l4 (L.L.IBIS_Linie_Suffix) s1 /-/ (L.L.Matrix_TerminusIndex_Last) = ! && ||
	(L.L.elec_busbar_main) &&
	(L.L.elec_12v) (L.L.matrix_power) && &&
	{if}
		l2 (C.L.Matrix_Waittime) (C.L.Matrix_Changetime_Terminus) 3.5 * + <
		{if}
			l2 (C.L.Matrix_Waittime) >
			{if}
				(L.L.Matrix_TerminusCreateString)
				{if}
					l0 1 (M.V.GetTerminusString) 16 $SetLengthL (S.$.Matrix_NewTerminus_1)
					l0 2 (M.V.GetTerminusString) 16 $SetLengthL (S.$.Matrix_NewTerminus_2)
					l0 3 (M.V.GetTerminusString) 16 $SetLengthL (S.$.Matrix_NewTerminus_3)
					0 (S.L.Matrix_TerminusCreateString)

'Das soeben in den temporдren Speicher geschriebene Ziel:
'Это просто записывается на временное хранение конечной:
					l4
					{if}
						l1 /-/ 
					{else}
						l0 
					{endif}
					(S.L.Matrix_TerminusAct)
				{endif}

'Zahl von aktualisierten Zeichen:
'Число обновленных символов:
				l2 (C.L.Matrix_Waittime) - 0 max 16 * (C.L.Matrix_Changetime_Terminus) / trunc 16 min s3

				l3 1 >=
				{if}
'((Уезжает вправо))
					(L.$.Matrix_NewTerminus_1) l3 $SetLengthR
					(L.$.Matrix_OldTerminus_1) 16 l3 - $SetLengthL $+
					(S.$.Matrix_Terminus_1)
					
'((Уезжает вправо))
					(L.$.Matrix_NewTerminus_2) l3 $SetLengthR
					(L.$.Matrix_OldTerminus_2) 16 l3 - $SetLengthL $+
					(S.$.Matrix_Terminus_2)
				{endif}
			{endif}
'__________________________________________________
		{else}
			l1 98 >=
			l1 96 = ||
			l1 95 = ||
			{if}
				(L.L.Matrix_ChangeCounter) ! (S.L.Matrix_ChangeCounter)
'Hierdurch wird der Wechsel der Nummern-Matrix initiiert:
				-1 (S.L.Matrix_Nr_Last)
			{else}
				(L.L.Matrix_TerminusAct) (S.L.Matrix_TerminusIndex_Last) (S.L.target_index_int)
			{endif}
			1 (S.L.Matrix_TerminusCreateString)
			(L.S.GetTime) (S.L.Matrix_TerminusActTimer)
			(L.$.Matrix_Terminus_1) (S.$.Matrix_OldTerminus_1)
			(L.$.Matrix_Terminus_2) (S.$.Matrix_OldTerminus_2)
			(L.$.Matrix_Terminus_3) (S.$.Matrix_OldTerminus_3)
		{endif}

'Omsi sagen, dass die Strings-Ausgaben aktualisiert werden sollen:
		1 (S.L.Refresh_Strings)
	
	{else}
		(L.S.GetTime) (S.L.Matrix_TerminusActTimer)
		1 (S.L.Matrix_TerminusCreateString)
	{endif}
	
	(L.L.elec_busbar_main)
	(L.L.elec_12v) (L.L.matrix_power) && &&
	{if}
		(L.$.Matrix_Terminus_1) 16 $SetLengthL "@" $+
		(L.$.Matrix_Terminus_2) 16 $SetLengthL "@" $+ $+
		(L.$.Matrix_Terminus_3) 16 $SetLengthL $+
		(S.$.Matrix_Terminus)
		1 (S.L.Matrix_on)
		
		(L.L.time_show_data_ext) (C.L.time_show) <
		{if}
			(L.L.time_show_data_ext) (L.S.Timegap) + (S.L.time_show_data_ext)
		{else}
			(L.L.matrix_3str) ! (S.L.matrix_3str)
			0 (S.L.time_show_data_ext)
		{endif}
		
		(L.L.matrix_3str)
		{if}
			(L.$.Matrix_Terminus_2)

		{else}
			" "
'	Часы:
			(L.S.Time) 3600 / s0 trunc s1 "02" $IntToStrEnh $+
			(L.L.Time_BlinkOn)
			{if}
				":" $+
			{else}
				" " $+
			{endif}
							
'	Минуты :
			l0 l1 - 60 * s0 trunc s1 "02" $IntToStrEnh $+
			"  " $+
'	День:
			(L.S.Day) "02" $IntToStrEnh $+ "-" $+
'	Месяц :
			(L.$.Month) $+ "." $+
			" " $+
		{endif}
		(S.$.Matrix_Terminus_3)

	{else}
		"                @                @                " (S.$.Matrix_Terminus)
		0 (S.L.Matrix_on) (S.L.time_show_data_ext)
	{endif}

'******************************+
'    Nr-Matrix
'******************************+

' Zeitdifferenz:
	(L.S.GetTime) (L.L.Matrix_NrActTimer) - s2

	l2 0 <
	{if}
		(L.S.GetTime) (S.L.Matrix_NrActTimer) 0 s2
		1 (S.L.Matrix_NrCreateString)
	{endif}

' Wenn sich die neue Linie von der alten unterscheidet, dann wechsele:
	(L.L.IBIS_Linie_Complex) s0 (L.L.Matrix_Nr_Last) = ! 
	(L.L.elec_busbar_main) &&
	{if}
		l2 (C.L.Matrix_Waittime) (C.L.Matrix_Changetime_Nr) 1.5 * + <
		{if}
			l2 (C.L.Matrix_Waittime) >
			{if}
' Nur beim ersten Mal:
				(L.L.Matrix_NrCreateString)
				{if}
					l0 100 / trunc s1
					(L.L.IBIS_Linie_Suffix) s4
' l0: Originalzahl; l1: erste drei Ziffern; l4: letzte zwei Ziffern

' Falls gleich 0, dann gar nix:
					l1 0 =
					{if}
						""
					{else}
' Sonst die normale Nummer:
						l1 trunc $IntToStr
					{endif}

					(S.$.Matrix_NewNr)

' ===============================================================================
' Falls jetzt die hinteren beiden Ziffern (l2) etwas Interessantes enthalten:
' ===============================================================================

' Zunдchst wird verlдngert, wenn einstellig - und zwar je nach Anwendung links- oder rechtsbьndig:

					(L.$.Matrix_NewNr) $length 1 <=
					{if}
						l4 4 =
						l4 0 = ||
						l4 10 = ||
						l4 30 = ||
						l4 31 = ||
						l4 32 = ||
						l4 35 = ||
						l4 36 = ||
						{if}
							4 $SetLengthL
						{else}
							4 $SetLengthR
						{endif}
					{endif}

					(S.$.Matrix_NewNr)

					
					l4 0 =
					{if}
						(L.$.Matrix_NewNr) 3 $SetLengthR " " $+
					{endif}
					l4 1 =
					{if}
						"E" (L.$.Matrix_NewNr) 2 $SetLengthR " " $+ $+
					{endif}
					l4 2 =
					{if}
						"/^\ "
					{endif}
					l4 3 =
					{if}
						"gh  "
					{endif}
					l4 4 =
					{if}
						(L.$.Matrix_NewNr) 3 $SetLengthR "N" $+
					{endif}
					l4 5 = l4 24 = ||
					{if}
						"S" (L.$.Matrix_NewNr) 2 $SetLengthR " " $+ $+
					{endif}
					l4 6 =
					{if}
						"A" (L.$.Matrix_NewNr) 2 $SetLengthR " " $+ $+
					{endif}

					l4 9 =
					{if}
						" E" (L.$.Matrix_NewNr) 1 $SetLengthR " " $+ $+
					{endif}
					l4 10 =
					{if}
						(L.$.Matrix_NewNr) 3 $SetLengthR "E" $+
					{endif}
					l4 11 =
					{if}
						" D" (L.$.Matrix_NewNr) 1 $SetLengthR " " $+ $+
					{endif}
					l4 12 =
					{if}
						" C" (L.$.Matrix_NewNr) 1 $SetLengthR " " $+ $+
					{endif}
					l4 13 =
					{if}
						" B" (L.$.Matrix_NewNr) 1 $SetLengthR " " $+ $+
					{endif}
					l4 14 =
					{if}
						" A" (L.$.Matrix_NewNr) 1 $SetLengthR " " $+ $+
					{endif}
					l4 15 =
					{if}
						" N" (L.$.Matrix_NewNr) 1 $SetLengthR " " $+ $+
					{endif}

					l4 23 =
					{if}
						" S" (L.$.Matrix_NewNr) 1 $SetLengthR " " $+ $+
					{endif}
' 24 s.o. bei 5!
					l4 25 =
					{if}
						" U" (L.$.Matrix_NewNr) 1 $SetLengthR " " $+ $+
					{endif}
					l4 26 =
					{if}
						"U" (L.$.Matrix_NewNr) 2 $SetLengthR " " $+ $+
					{endif}
					l4 27 =
					{if}
						" M" (L.$.Matrix_NewNr) 1 $SetLengthR " " $+ $+
					{endif}
					l4 28 =
					{if}
						"M" (L.$.Matrix_NewNr) 2 $SetLengthR " " $+ $+
					{endif}
					l4 29 =
					{if}
						"BVG "
					{endif}
					l4 30 =
					{if}
						(L.$.Matrix_NewNr) 3 $SetLengthR "S" $+
					{endif}
					l4 31 =
					{if}
						(L.$.Matrix_NewNr) 3 $SetLengthR "U" $+
					{endif}
					l4 32 =
					{if}
						(L.$.Matrix_NewNr) 3 $SetLengthR "M" $+
					{endif}
					l4 35 =
					{if}
						"N" (L.$.Matrix_NewNr) 2 $SetLengthR " " $+ $+
					{endif}
					l4 36 =
					{if}
						"X" (L.$.Matrix_NewNr) 2 $SetLengthR " " $+ $+
					{endif}
					l4 98 = (L.L.Matrix_ChangeCounter) &&
					{if}
						"yxy "
					{else}
					l4 98 =
					{if}
						"xyx "
					{endif}
					{endif}
					l4 99 = (L.L.Matrix_ChangeCounter) &&
					{if}
						"    "
					{else}
					l4 99 =
					{if}
						"zzz "
					{endif}
					{endif}

'D oder SD? Das ist hier die Frage...:
					4 $SetLengthR

					(S.$.Matrix_NewNr)

					0 (S.L.Matrix_NrCreateString)
					(T.L.ev_Matrix_Line_change)
					l0 (S.L.Matrix_NrAct)
				{endif}

'Zahl von aktualisierten Zeichen:

				l2 (C.L.Matrix_Waittime) - 0 max 3 * (C.L.Matrix_Changetime_Nr) / trunc 4 min s3

				l3 1 >=
				{if}
					(L.$.Matrix_NewNr) l3 $SetLengthL
					(L.$.Matrix_Nr) 4 l3 - $SetLengthR $+
					(S.$.Matrix_Nmr)
					
					(L.$.Matrix_Nmr) (S.$.Matrix_Nr)
				{endif}
			{endif}
		{else}
			(L.L.Matrix_NrAct) (S.L.Matrix_Nr_Last)
			(L.$.Matrix_NewNr) (S.$.Matrix_Nr)
			1 (S.L.Matrix_NrCreateString)
			(L.S.GetTime) (S.L.Matrix_NrActTimer)
		{endif}

'Omsi sagen, dass die Strings-Ausgaben aktualisiert werden sollen:
		1 (S.L.Refresh_Strings)
	{else}
		(L.S.GetTime) (S.L.Matrix_NrActTimer)
		1 (S.L.Matrix_NrCreateString)
	{endif}
	
	(L.L.elec_busbar_main)
	(L.L.elec_12v) (L.L.matrix_power) 1 = && &&
	{if}
		(L.$.Matrix_Nmr) (S.$.Matrix_Nr)
	{else}
		"    " (S.$.Matrix_Nr)
	{endif}
	
	
	(L.L.liazlogo_timer_start) 5 >
	(L.L.elec_busbar_main) 1 = &&
	{if}
		1 (S.L.ekran_on_visible)
	{else}
		0 (S.L.ekran_on_visible)
	{endif}

	(L.L.elec_12V)
	(L.L.cp_monitor) &&
	(L.L.elec_busbar_main) &&
	{if}
		1 (S.L.monitor_on_visible)
	{else}
		0 (S.L.monitor_on_visible)
	{endif}

	(L.L.elec_busbar_main)
	(L.L.cp_konvekta_sw) &&
	{if}
		1 (S.L.konvekta_visible)
	{else}
		0 (S.L.konvekta_visible)
	{endif}

	(L.L.elec_busbar_main)
	(L.L.vdo_panel_button) &&
	{if}
		1 (S.L.vdo_visible)
	{else}
		0 (S.L.vdo_visible)
	{endif}


'Aktualisierung der Code-Tafel:

	"Linienlisten\" (L.$.yard) "_ANX.jpg" $+ $+ (S.$.Matrix_Linelist)
	

{end}

