'##############
'Doors Script
'##############

'Controls Doors

'(c) 2010 Marcel Kuhnt

'Script Version: 1.0
'Omsi release: 1.0

'Needs:
'- none

'Revision History:
'- Marcel Kuhnt		24.04.2010	Grundlagen

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

{trigger:bus_doorfront0}
	1 (S.L.CCW_Tueroeffnen_L)
{end}

{trigger:bus_doorfront0_off}
	0 (S.L.CCW_Tueroeffnen_L)
{end}

{trigger:bus_doorfront1}
	1 (S.L.CCW_Tuerschliessen)
{end}

{trigger:bus_doorfront1_off}
	0 (S.L.CCW_Tuerschliessen)
{end}

{trigger:bus_dooraft}
	1 (S.L.CCW_Tueroeffnen_R)
{end}

{trigger:bus_dooraft_off}
	0 (S.L.CCW_Tueroeffnen_R)
{end}

{macro:Doors_Init}
	0
	(S.L.door_1R)
	(S.L.door_1L)
	(S.L.door_2R)
	(S.L.door_2L)

	(S.L.doors_switch_L)
	(S.L.doors_switch_R)
	(S.L.doorTarget_1R)
	(S.L.doorTarget_1L)
	(S.L.doorTarget_2R)
	(S.L.doorTarget_2L)


	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.door_acc) + (S.L.doorAcc_1R)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.door_acc) + (S.L.doorAcc_2R)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.door_acc) + (S.L.doorAcc_1L)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.door_acc) + (S.L.doorAcc_2L)

	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.door_maxspeed) + (S.L.doorMaxSpeed_1R)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.door_maxspeed) + (S.L.doorMaxSpeed_2R)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.door_maxspeed) + (S.L.doorMaxSpeed_1L)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.door_maxspeed) + (S.L.doorMaxSpeed_2L)
{end}

{macro:Doors_Frame}

'Lesen der Steuerleitungen:
	(L.L.CCR_Tueroeffnen_L)
	{if}
		1 (S.L.doors_switch_L)
	{endif}
	(L.L.CCR_Tueroeffnen_R)
	{if}
		1 (S.L.doors_switch_R)
	{endif}

	(L.L.CCR_Tuerschliessen)
	(L.L.door_klingel_on) ! &&
	(L.L.doors_switch_L) (L.L.doors_switch_R) || &&
	{if}
		1.9 (S.L.door_klingel_timer)
		(T.L.ev_door_klingel)
		1 (S.L.door_close_command)
	{endif}
	
	(L.L.CCR_Tuerschliessen) (S.L.door_klingel_on)
	
	(L.L.door_klingel_timer) (L.S.TimeGap) - 0 max (S.L.door_klingel_timer)

	(L.L.door_klingel_timer) 0 >
	{if}
		1 (S.L.door_warn_lights)
	{else}
		(L.L.door_close_command)
		{if}
			0 (S.L.doors_switch_L) (S.L.doors_switch_R)
			0 (S.L.door_close_command)
		{endif}
	0 (S.L.door_warn_lights)
	{endif}
'Zuweisen der Einzeltüren:
	(L.L.doors_switch_L) (S.L.doorTarget_1L) (S.L.doorTarget_2L) (S.L.doorTarget_3L) (S.L.doorTarget_4L)
	(L.L.doors_switch_R) (S.L.doorTarget_1R) (S.L.doorTarget_2R) (S.L.doorTarget_3R) (S.L.doorTarget_4R)

	(L.L.door_1R) 0.9 > (S.L.PAX_Entry0_Open) (S.L.PAX_Exit0_Open)
	(L.L.door_2R) 0.9 > (S.L.PAX_Entry1_Open) (S.L.PAX_Exit1_Open)
	(L.L.door_1L) 0.9 > (S.L.PAX_Entry4_Open) (S.L.PAX_Exit4_Open)
	(L.L.door_2L) 0.9 > (S.L.PAX_Entry5_Open) (S.L.PAX_Exit5_Open)

	(M.L.Door1R_Calc)
	(M.L.Door2R_Calc)
	(M.L.Door1L_Calc)
	(M.L.Door2L_Calc)
{end}




{macro:Door1R_Calc}
	(L.L.doorTarget_1R) ! (L.L.doorSpeed_1R) s0 abs 0.05 > (L.L.door_1R) 0 > || && 
	{if}
		l0 /-/ (L.L.doorMaxSpeed_1R) <
		{if}
			(L.L.doorSpeed_1R) (L.L.doorAcc_1R) (L.S.Timegap) * - (S.L.doorSpeed_1R)
		{endif}
		(L.L.door_1R) (L.L.doorSpeed_1R) (L.S.Timegap) * + (S.L.door_1R)
	{else}
		(L.L.doorSpeed_1R) abs 0.05 > (L.L.door_1R) 1 < || (L.L.doorTarget_1R) &&
		{if}
			l0 (L.L.doorMaxSpeed_1R) <
			{if}
				(L.L.doorSpeed_1R) (L.L.doorAcc_1R) (L.S.Timegap) * + (S.L.doorSpeed_1R) 
			{endif}
			(L.L.door_1R) (L.L.doorSpeed_1R) (L.S.Timegap) * + (S.L.door_1R)
		{else}
			0 (S.L.doorSpeed_1R)
		{endif}
	{endif}

	(L.L.door_1R) 1 >
	{if}
		(T.L.ev_doorhitopen_1R)
		1 (S.L.door_1R)
		0 (S.L.doorSpeed_1R)
	{else}
		(L.L.door_1R) 0 <
		{if}
			(T.L.ev_doorhitclose_1R)
			0 (S.L.door_1R)
			0 (S.L.doorSpeed_1R)
		{endif}
	{endif}
{end}

{macro:Door2R_Calc}
	(L.L.doorTarget_2R) ! (L.L.doorSpeed_2R) s0 abs 0.05 > (L.L.door_2R) 0 > || && 
	{if}
		l0 /-/ (L.L.doorMaxSpeed_2R) <
		{if}
			(L.L.doorSpeed_2R) (L.L.doorAcc_2R) (L.S.Timegap) * - (S.L.doorSpeed_2R)
		{endif}
		(L.L.door_2R) (L.L.doorSpeed_2R) (L.S.Timegap) * + (S.L.door_2R)
	{else}
		(L.L.doorSpeed_2R) abs 0.05 > (L.L.door_2R) 1 < || (L.L.doorTarget_2R) &&
		{if}
			l0 (L.L.doorMaxSpeed_2R) <
			{if}
				(L.L.doorSpeed_2R) (L.L.doorAcc_2R) (L.S.Timegap) * + (S.L.doorSpeed_2R) 
			{endif}
			(L.L.door_2R) (L.L.doorSpeed_2R) (L.S.Timegap) * + (S.L.door_2R)
		{else}
			0 (S.L.doorSpeed_2R)
		{endif}
	{endif}

	(L.L.door_2R) 1 >
	{if}
		(T.L.ev_doorhitopen_2R)
		1 (S.L.door_2R)
		0 (S.L.doorSpeed_2R)
	{else}
		(L.L.door_2R) 0 <
		{if}
			(T.L.ev_doorhitclose_2R)
			0 (S.L.door_2R)
			0 (S.L.doorSpeed_2R)
		{endif}
	{endif}
{end}


{macro:Door1L_Calc}
	(L.L.doorTarget_1L) ! (L.L.doorSpeed_1L) s0 abs 0.05 > (L.L.door_1L) 0 > || && 
	{if}
		l0 /-/ (L.L.doorMaxSpeed_1L) <
		{if}
			(L.L.doorSpeed_1L) (L.L.doorAcc_1L) (L.S.Timegap) * - (S.L.doorSpeed_1L)
		{endif}
		(L.L.door_1L) (L.L.doorSpeed_1L) (L.S.Timegap) * + (S.L.door_1L)
	{else}
		(L.L.doorSpeed_1L) abs 0.05 > (L.L.door_1L) 1 < || (L.L.doorTarget_1L) &&
		{if}
			l0 (L.L.doorMaxSpeed_1L) <
			{if}
				(L.L.doorSpeed_1L) (L.L.doorAcc_1L) (L.S.Timegap) * + (S.L.doorSpeed_1L) 
			{endif}
			(L.L.door_1L) (L.L.doorSpeed_1L) (L.S.Timegap) * + (S.L.door_1L)
		{else}
			0 (S.L.doorSpeed_1L)
		{endif}
	{endif}

	(L.L.door_1L) 1 >
	{if}
		(T.L.ev_doorhitopen_1L)
		1 (S.L.door_1L)
		0 (S.L.doorSpeed_1L)
	{else}
		(L.L.door_1L) 0 <
		{if}
			(T.L.ev_doorhitclose_1L)
			0 (S.L.door_1L)
			0 (S.L.doorSpeed_1L)
		{endif}
	{endif}
{end}



{macro:Door2L_Calc}
	(L.L.doorTarget_2L) ! (L.L.doorSpeed_2L) s0 abs 0.05 > (L.L.door_2L) 0 > || && 
	{if}
		l0 /-/ (L.L.doorMaxSpeed_2L) <
		{if}
			(L.L.doorSpeed_2L) (L.L.doorAcc_2L) (L.S.Timegap) * - (S.L.doorSpeed_2L)
		{endif}
		(L.L.door_2L) (L.L.doorSpeed_2L) (L.S.Timegap) * + (S.L.door_2L)
	{else}
		(L.L.doorSpeed_2L) abs 0.05 > (L.L.door_2L) 1 < || (L.L.doorTarget_2L) &&
		{if}
			l0 (L.L.doorMaxSpeed_2L) <
			{if}
				(L.L.doorSpeed_2L) (L.L.doorAcc_2L) (L.S.Timegap) * + (S.L.doorSpeed_2L) 
			{endif}
			(L.L.door_2L) (L.L.doorSpeed_2L) (L.S.Timegap) * + (S.L.door_2L)
		{else}
			0 (S.L.doorSpeed_2L)
		{endif}
	{endif}

	(L.L.door_2L) 1 >
	{if}
		(T.L.ev_doorhitopen_2L)
		1 (S.L.door_2L)
		0 (S.L.doorSpeed_2L)
	{else}
		(L.L.door_2L) 0 <
		{if}
			(T.L.ev_doorhitclose_2L)
			0 (S.L.door_2L)
			0 (S.L.doorSpeed_2L)
		{endif}
	{endif}
{end}
