'##########################################
'AVL SP TRANS by Zane
'##########################################

' 2020 Marcos Zane

'----------------------
'	Init
'----------------------
{macro:avl_init}
{end}

'----------------------
'	Frame
'----------------------
{macro:avl_frame}
'    (L.L.elec_busbar_main)
'    {if}
'       Get the matrix destinations
'        "LINHA: " (L.$.Matrix_InnerDispStatus) $+ 48 $SetLengthL (S.$.avl_disp_line1)
'
'       ***************** AUTOMATIC CONTINUATION
'        (L.L.schedule_active)
'	    {if}
'						
'		    (M.V.GetTTBusstopIndex) (L.L.avl_stop) = !		
'		    (M.V.GetTTBusstopIndex) -1 > &&		
'		    {if}
'		    	(L.L.avl_stop) 1 + (S.L.avl_stop)
'		    	(L.L.avl_stop) 0 > (M.V.GetTTBusstopIndex) (M.V.GetTTBusstopName) (M.V.GetTTBusstopIndex) 1 - (M.V.GetTTBusstopName) $= ! &&
'		    	{if}
'		    		1 (S.L.avl_stop_update)			
'		    	{endif}								
'		    {endif}	

'       Reset from ride_activated to allow calculation of the next lap
'       if stop status > as the number of stops on the current route
'            (L.L.avl_stop) 1 + (M.V.GetTTBusstopCount) = 
'		    {if}
'		    	1 (S.L.avl_next) 
'		    {endif}
'
'            (L.L.avl_stop) (M.V.GetTTBusstopName) 18 $SetLengthL (S.$.avl_next_stop_1)
'            (L.L.avl_stop) 1 + (M.V.GetTTBusstopName) 18 $SetLengthL (S.$.avl_next_stop_2)
'
'            (L.L.avl_stop) (M.V.GetTTBusstopCount) =
'		    (L.L.avl_next) (M.V.GetTTBusstopIndex) 0 = && ||
'		    {if}	
'		        0 (S.L.avl_stop) (S.L.avl_next) 			
'		    {endif}

'       ***************** DISPLAY LATE TIME
'		    (L.L.AI) !
'		    {if}
'		    	(M.V.GetTTDelay) (S.L.avl_calcdelay)
'		    {else}
'		    	0 (S.L.avl_calcdelay)
'		    {endif}		
'    
'		    (L.L.avl_calcdelay) 10 >
'		    {if} 
'		    	"+" (L.L.avl_calcdelay) abs 60.0 / s0 l0 trunc $IntToStr $+ ":" $+ 
'		    	(L.L.avl_calcdelay) abs 60.0 / s0 l0 trunc (L.L.avl_calcdelay) abs 60.0 / - /-/ 6 * trunc $IntToStr $+
'		    	0 (S.L.avl_versp_rot)
'		    {endif} 
'    
'		    (L.L.avl_calcdelay) 10 <= (L.L.avl_calcdelay) 0 > &&
'		    {if} 
'		    	" " (L.L.avl_calcdelay) 10 - abs 60.0 / s0 l0 trunc $IntToStr $+ ":" $+ 
'		    	(L.L.avl_calcdelay) 10 - abs 60.0 / s0 l0 trunc (L.L.avl_calcdelay) 10 - abs 60.0 / - /-/ 6 * trunc $IntToStr $+
'		    	0 (S.L.avl_versp_rot)
'		    {endif}			
'
'		    (L.L.avl_calcdelay) 0 <= 
'		    {if} 
'		    	"-" (L.L.avl_calcdelay) 10 - abs 60.0 / s0 l0 trunc $IntToStr $+ ":" $+ 
'		    	(L.L.avl_calcdelay) 10 - abs 60.0 / s0 l0 trunc (L.L.avl_calcdelay) 10 - abs 60.0 / - /-/ 6 * trunc $IntToStr $+
'		    	1 (S.L.avl_versp_rot)
'		    {endif}		
'
'		     "0" $+ 
'		    (S.$.avl_s_versp)
'
'            "Prox.: " (L.$.avl_next_stop_1) $+ "   Delay: " $+ (L.$.avl_s_versp) $+
'            (S.$.avl_disp_line2)


'*********** If no trip is active and no schedule_active					
'	    {else}		
'			 
'		    "--:--" (S.$.avl_s_versp)
'            "SEM VIAGEM ATIVA " 43 $SetLengthL (L.$.avl_s_versp) $+
'            48 $SetLengthL (S.$.avl_disp_line2)
'		    0 (S.L.avl_versp_rot) (S.L.avl_stop) (S.L.avl_next)
'        {endif}
'    {else}
'        "" (S.$.avl_disp_line1) (S.$.avl_disp_line2)
'    {endif}

'*********** Dynamic line plates

    (L.$.Matrix_Nr) $RemoveSpaces 7 $SetLengthL (S.$.linenum)
    (L.$.Matrix_MEPStatus2) (S.$.dest)
    (L.$.Matrix_MEPStatus3) (S.$.via)


    (L.L.schedule_active)
    (L.L.vis_placasdinamicas_off) ! &&
    {if}

        (M.V.GetTTBusstopCount) s0

        l0 5 >=
        {if}
            l0 5 / trunc s1

            l1     (M.V.GetTTBusstopName) 24 $SetLengthL (S.$.streets_line1)
            l1 2 * (M.V.GetTTBusstopName) 24 $SetLengthL (S.$.streets_line2) (S.$.front_street1)
            l1 3 * (M.V.GetTTBusstopName) 24 $SetLengthL (S.$.streets_line3)
            l1 4 * (M.V.GetTTBusstopName) 24 $SetLengthL (S.$.streets_line4) (S.$.front_street2)
            l1 5 * (M.V.GetTTBusstopName) 24 $SetLengthL (S.$.streets_line5)

        {else}
            l0 s1

            l1 0 >
            {if}
                l1 (M.V.GetTTBusstopName) 24 $SetLengthL (S.$.streets_line1) 
                l1 1 - s1
            {endif}

            l1 0 >
            {if}
                l1 (M.V.GetTTBusstopName) 24 $SetLengthL (S.$.streets_line2) (S.$.front_street1)
                l1 1 - s1
            {endif}

            l1 0 >
            {if}
                l1 (M.V.GetTTBusstopName) 24 $SetLengthL (S.$.streets_line3) (S.$.front_street2)
                l1 1 - s1
            {endif}

            l1 0 >
            {if}
                l1 (M.V.GetTTBusstopName) 24 $SetLengthL (S.$.streets_line4)
                l1 1 - s1
            {endif}

        {endif}



        

    {else}
        ""
        (S.$.front_street1) (S.$.front_street2)

        (S.$.streets_line1)
        (S.$.streets_line2)
        (S.$.streets_line3)
        (S.$.streets_line4)
        (S.$.streets_line5)
    {endif}

{end}

'----------------------
'	Macro
'----------------------