'##############
'AI Script
'##############

'Controls some functions while vehicle is driven by AI

'(c) 17.05.2012 Marcel Kuhnt

'Script Version: 1.0
'Omsi release: 1.0

'Needs:
'- door

'Revision History:
'- Marcel Kuhnt		15.05.2010	Created
'- Marcel Kuhnt		14.01.2011	Added light switching
'- Marcel Kuhnt		23.01.2011	Close Doors Timer
'- Marcel Kuhnt		17.05.2012	Both sides openable

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



{macro:ai_frame}



'----------------------------------
'Doors:

	(L.L.AI_Scheduled_AtStation) s0
	1 =
	{if}
		0 (S.L.CCW_Tuerschliessen)
'Wenn Türen geöffnet werden sollen:
		(L.L.Velocity) 3 <
		{if}
'Nur, wenn v < maxkmh, sonst warten
'Taster jeweils nur betätigen, falls noch nicht an
			(L.L.CCW_Tueroeffnen_L) ! (L.L.AI_Scheduled_AtStation_Side) 1 >= &&
			{if}
				1 (S.L.CCW_Tueroeffnen_L)
			{endif}
			(L.L.CCW_Tueroeffnen_R) ! (L.L.AI_Scheduled_AtStation_Side) 1 = ! &&
			{if}
				1 (S.L.CCW_Tueroeffnen_R)
			{endif}
		{endif}
	{else}
	l0 -1 =
	{if}
		(L.L.doors_switch_L) (L.L.doors_switch_R) ||
		{if}
			0 (S.L.CCW_Tueroeffnen_L) (S.L.CCW_Tueroeffnen_R)

			1 (S.L.CCW_Tuerschliessen)
		{endif}

		(L.L.AI_Timer_DoorClose) 6 >
		{if}
			0 (S.L.AI_Scheduled_AtStation)
		{else}
			(L.L.AI_Timer_DoorClose) (L.S.Timegap) + (S.L.AI_Timer_DoorClose)
		{endif}
	{else}
		(L.L.AI) (L.L.Velocity) 3 >= && (S.L.CCW_Tuerschliessen)
		0 (S.L.AI_Timer_DoorClose)
	{endif}
	{endif}



'----------------------------------
'Lights:
	
	(L.L.ai_engine) 0.5 > (S.L.Lights_white) ! (L.L.train_frontcoupling) ! && (S.L.Lights_red)



{end}