'##############
'Door Script
'##############

'Controls Doors

'(c) 2007-2009 Rüdiger Hülsmann
'(c) 2007-2009 Marcel Kuhnt

'Script Version: 1.1
'Omsi release: 1.0

'Needs:
'- elec

'Revision History:
'- Marcel Kuhnt		13.06.2009	Batterietrennschalter => elec_busbar_main
'- Marcel Kuhnt		21.06.2009	AI-Unterstützung hinzugefügt	
'- Rüdiger Hülsmann	24.10.2009	Ansteuerung des Kinderwagenwunsches modifiziert
'- Rüdiger Hülsmann	19.12.2009	Timer für Ausstiegstür jetzt Timegap-basiert, Bugfix: Tür schließt jetzt nur bei elec_busbar=1
'- RÜdiger Hülsmann	22.09.2010	Door light trigger value set to 0.1
'- RÜdiger Hülsmann	07.11.2010	Door speed based on reservoir pressure, air-operated doors made an option
'- Marcel Kuhnt		08.11.2010	AI procedure closing doors debugged
'- Rüdiger Hülsmann	21.11.2010	Front doors only operable when busbar on
'- Rüdiger Hülsmann	23.12.2010	External front door operation included, option: doors only operable with actual stop brake
'- Rüdiger Hülsmann	31.12.2010	Electric door function debugged
'- Rüdiger Hülsmann	05.01.2011	20h-switch
'- Rüdiger Hülsmann	07.01.2011	Backdoor manual switch sound debugged, 20h switch depending on bus type
'- Rüdiger Hülsmann	19.01.2011	Electric door support
'- Rüdiger Hülsmann	19.01.2011	Electric door support
'- Morozov Maxim	----------	Removed automatical back door. Added ramp animation... etc...
'- Alexey Vasiliev	09.03.2012	Added more doors for Citaro "Private Edition"
'- Ñåðãåé Wizard	14.11.2013	Added automatical back doors. Rework dooraft for citaro 3door
'--------------------------------------------------------------------------------

{trigger:cp_door_01_nothahn_klappe}
	(L.L.door_01_nothahn_klappe_sw) ! (S.L.door_01_nothahn_klappe_sw)
{end}

{trigger:cp_door_01_nothahn}
	(L.L.door_01_nothahn_sw) ! (S.L.door_01_nothahn_sw)

	(L.L.door_01_nothahn_sw)
	{if}
		(T.L.ev_nothahn01_auf)
		1 (S.L.doorTarget_0) (S.L.doorTarget_1)
		5 random 10 / 0.5 + (S.L.door_0_soll)
		5 random 10 / 0.5 + (S.L.door_1_soll)
	{else}
		(T.L.ev_nothahn01_zu)
	{endif}	
{end}

{trigger:cp_door_23_nothahn_klappe}
	(L.L.door_23_nothahn_klappe_sw) ! (S.L.door_23_nothahn_klappe_sw)
{end}

{trigger:cp_door_23_nothahn}
	(L.L.door_23_nothahn_sw) ! (S.L.door_23_nothahn_sw)

	(L.L.door_23_nothahn_sw)
	{if}
		(T.L.ev_nothahn23_auf)
		1 (S.L.doorTarget_23) (S.L.bremse_halte)
		5 random 10 / 0.5 + (S.L.door_2_soll)
		5 random 10 / 0.5 + (S.L.door_3_soll)
	{else}
		(T.L.ev_nothahn23_zu)
	{endif}
{end}

{trigger:cp_door_45_nothahn_klappe}
	(L.L.door_45_nothahn_klappe_sw) ! (S.L.door_45_nothahn_klappe_sw)
{end}

{trigger:cp_door_45_nothahn}
	(L.L.door_45_nothahn_sw) ! (S.L.door_45_nothahn_sw)

	(L.L.door_45_nothahn_sw)
	{if}
		(T.L.ev_nothahn45_auf)
		1 (S.L.doorTarget_45) (S.L.bremse_halte)
		5 random 10 / 0.5 + (S.L.door_4_soll)
		5 random 10 / 0.5 + (S.L.door_5_soll)
	{else}
		(T.L.ev_nothahn45_zu)
	{endif}
{end}

{trigger:door0_drag}
	(L.S.mouse_x) -400 / (L.L.doorDragAcc_0) + 1 min 0 max (S.L.doorDragAcc_0)
{end}

{trigger:door1_drag}
	(L.S.mouse_x) -400 / (L.L.doorDragAcc_1) + 1 min 0 max (S.L.doorDragAcc_1)
{end}

{trigger:door2_drag}
	(L.S.mouse_x) -400 / (L.L.doorDragAcc_2) + 1 min 0 max (S.L.doorDragAcc_2)
{end}

{trigger:door3_drag}
	(L.S.mouse_x) -400 / (L.L.doorDragAcc_3) + 1 min 0 max (S.L.doorDragAcc_3)
{end}

{trigger:door4_drag}
	(L.S.mouse_x) -400 / (L.L.doorDragAcc_4) + 1 min 0 max (S.L.doorDragAcc_4)
{end}

{trigger:door5_drag}
	(L.S.mouse_x) -400 / (L.L.doorDragAcc_5) + 1 min 0 max (S.L.doorDragAcc_5)
{end}

{trigger:bus_doorfront0}
	(L.L.Door_Error_Count) 1 + (S.L.Door_Error_Count)
	1 (S.L.cockpit_tuertaster1)
	(T.L.ev_tuertaster_ein)
{end}

{trigger:bus_doorfront0_off}
	0 (S.L.cockpit_tuertaster1)
	(T.L.ev_tuertaster_aus)
{end}

{trigger:bus_doorfront1}
	(L.L.Door2_Error_Count) 1 + (S.L.Door2_Error_Count)
	1 (S.L.cockpit_tuertaster2)
	(T.L.ev_tuertaster_ein)
{end}

{trigger:bus_doorfront1_off}
	0 (S.L.cockpit_tuertaster2)
	(T.L.ev_tuertaster_aus)
{end}

{trigger:bus_dooraft}
	(L.L.bus_dooraft_sw) ! (S.L.bus_dooraft_sw)	

	(L.L.bus_dooraft_sw)
	{if}
		(T.L.ev_VDV_on)
	{else}
		(T.L.ev_VDV_off)
	{endif}	

	(L.L.door_handsteuerung) 
	(L.L.bus_dooraft_sw) ! &&
	{if}
		0 (S.L.door_handsteuerung)
		10 (S.L.doorAftLastOpen) (S.L.doorAftLastOpen1)
	{endif}
{end}

{trigger:bus_20h-switch}
	(L.L.bremse_halte_sw) ! (S.L.bremse_halte_sw)

	(L.L.bremse_halte_sw) 1 =
	{if}
		(T.L.ev_VDV_on)
	{else}
		(T.L.ev_VDV_off)
	{endif}
{end}


{trigger:int_haltewunsch}
	1 (S.L.haltewunsch)
{end}

{trigger:door_haltewunsch}
	1 (S.L.haltewunsch)
{end}

{trigger:door_oeffnen45}
	1 (S.L.door_haltewunsch_knopfdruck) (S.L.haltewunsch)
{end}

{trigger:door_oeffnen45_off}
	0 (S.L.door_haltewunsch_knopfdruck)
{end}

{trigger:door_kinderwagenwunsch}
	1 (S.L.door_kinderwagenwunsch) (S.L.haltewunsch)
{end}

{trigger:door_rollstuhlwunsch}
	1 (S.L.door_rollstuhlwunsch) (S.L.haltewunsch)
{end}


{macro:Door_Init}
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.fdoor_acc) + (S.L.doorAcc_0)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.fdoor_acc) + (S.L.doorAcc_1)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.bdoor_acc) + (S.L.doorAcc_2)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.bdoor_acc) + (S.L.doorAcc_3)	
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.bdoor_acc) + (S.L.doorAcc_4)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.bdoor_acc) + (S.L.doorAcc_5)

	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.fdoor_maxspeed) + (S.L.doorMaxSpeed_0_norm)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.fdoor_maxspeed) + (S.L.doorMaxSpeed_1_norm)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.bdoor_maxspeed) + (S.L.doorMaxSpeed_2_norm)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.bdoor_maxspeed) + (S.L.doorMaxSpeed_3_norm)	
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.bdoor_maxspeed) + (S.L.doorMaxSpeed_4_norm)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.bdoor_maxspeed) + (S.L.doorMaxSpeed_5_norm)
	
	(C.L.door_refl) (S.L.doorRefl_0)
	(C.L.door_refl) (S.L.doorRefl_1)
	(C.L.door_refl) (S.L.doorRefl_2)
	(C.L.door_refl) (S.L.doorRefl_3)
	(C.L.door_refl) (S.L.doorRefl_4)
	(C.L.door_refl) (S.L.doorRefl_5)
	
	(C.L.tuerverzoegerung) (S.L.doortimer23)
	(C.L.tuerverzoegerung_hinten) (S.L.doortimer45) (S.L.doortimer67)
{end}

{macro:Door_Frame}
	(M.L.Door0_Calc)
	(M.L.Door1_Calc)
	(M.L.DoorAftCalc)
	(M.L.Door2_Calc)
	(M.L.Door3_Calc)
	(M.L.Door4_Calc)
	(M.L.Door5_Calc)

	(L.L.door_0) 0.9 > (S.L.PAX_Entry0_Open)
	(L.L.door_1) 0.9 > (S.L.PAX_Entry1_Open)
	(L.L.door_2) 0.9 > (S.L.PAX_Exit0_Open) 
	(L.L.door_3) 0.9 > (S.L.PAX_Exit1_Open)
	(L.L.door_4) 0.9 > (S.L.PAX_Exit2_Open)

	(L.L.door_2) (F.L.door2_xposition) (S.L.door2_positionx)
	(L.L.door_2) (F.L.door2_yposition) (S.L.door2_positiony)
	(L.L.door_3) (F.L.door3_xposition) (S.L.door3_positionx)
	(L.L.door_3) (F.L.door3_yposition) (S.L.door3_positiony)
	(L.L.door_4) (F.L.door4_xposition) (S.L.door4_positionx)
	(L.L.door_4) (F.L.door4_yposition) (S.L.door4_positiony)

'	Nothahn-Rebelüftung

	(L.L.door_01_nothahn_sw)
	{if}
		1 (S.L.door_01_nothahn)
	{endif}
	(L.L.door_01_nothahn)
	(L.L.door_01_nothahn_sw) ! &&
	{if}
		(L.L.door_0_soll) s0
		(L.L.doorDragAcc_0) s1
		1 s2
		1 s3
		(M.L.door_traegheit)
		(S.L.doorDragAcc_0)

		(L.L.door_1_soll) s0
		(L.L.doorDragAcc_1) s1
		1 s2
		1 s3
		(M.L.door_traegheit)
		(S.L.doorDragAcc_1)

		(L.L.cockpit_tuertaster1)
		{if}
			0 (S.L.door_01_nothahn) (S.L.doorTarget_0) (S.L.doorTarget_1)
			(L.L.door_0) 0.5 >
			(L.L.door_1) 0.5 > ||
			{if}
				(T.L.ev_doortriggerclose_0)
				(T.L.ev_doortriggerclose_1)
			{endif}
		{endif}
	{endif}

	(L.L.door_23_nothahn_sw)
	{if}
		1 (S.L.door_23_nothahn)
	{endif}
	(L.L.door_23_nothahn)
	(L.L.door_23_nothahn_sw) ! &&
	{if}
		(L.L.door_2_soll) s0
		(L.L.doorDragAcc_2) s1
		1 s2
		1 s3
		(M.L.door_traegheit)
		(S.L.doorDragAcc_2)

		(L.L.door_3_soll) s0
		(L.L.doorDragAcc_3) s1
		1 s2
		1 s3
		(M.L.door_traegheit)
		(S.L.doorDragAcc_3)

		(L.L.cockpit_tuertaster2)
		{if}
			0 (S.L.door_23_nothahn) (S.L.doorTarget_23)
			(L.L.door_2) 0.5 >
			{if}
				(T.L.ev_doortriggerclose_2)
			{endif}
		{endif}
	{endif}

	(L.L.door_45_nothahn_sw)
	{if}
		1 (S.L.door_45_nothahn)
	{endif}
	(L.L.door_45_nothahn)
	(L.L.door_45_nothahn_sw) ! &&
	{if}
		(L.L.door_4_soll) s0
		(L.L.doorDragAcc_4) s1
		1 s2
		1 s3
		(M.L.door_traegheit)
		(S.L.doorDragAcc_4)

		(L.L.door_5_soll) s0
		(L.L.doorDragAcc_5) s1
		1 s2
		1 s3
		(M.L.door_traegheit)
		(S.L.doorDragAcc_5)

		(L.L.doorAftLastOpen1) (C.L.doorAftOpenTime) >
		{if}
			0 (S.L.door_45_nothahn) (S.L.doorTarget_45)
		{endif}
	{endif}

	(C.L.HST_Bremse_aktiv)
	{if}
		(L.L.door_0) 0 =
		(L.L.door_1) 0 = &&
		{if}
			1 (S.L.Freigabe)
		{else}
			0 (S.L.Freigabe)
		{endif}
	{else}
		1 (S.L.Freigabe)
	{endif}

	(L.L.PAX_Exit0_Req) 0 >
	(L.L.PAX_Exit1_Req) 0 > ||
	(L.L.velocity) 5 > &&
	{if}
		1 (S.L.exit1_lichtschranke)
	{endif}

	(L.L.PAX_Exit2_Req) 0 >
	(L.L.velocity) 5 > &&
	{if}
		1 (S.L.exit2_lichtschranke)
	{endif}

'	Türsteuerung:
'Tür 1
	(L.L.cockpit_tuertaster1)
	(L.L.AI_Scheduled_AtStation) 1 = ||
	(L.L.door_0) 0.5 < &&
	(L.L.door_1) 0.5 < &&
	(L.L.doorTarget_0) 0 = (L.L.doorTarget_1) 0 = && &&
	(L.L.velocity) (C.L.tueroeffnung) < &&
	(C.L.Tuerfehlertoleranz) (L.L.wearlifespan) * (L.L.Door_Error_Count) > &&
	(L.L.elec_busbar_main) &&
	(L.L.bremse_p_tank04) 550000 > &&
	(L.L.door_01_nothahn_sw) ! &&
	{if}
		(L.L.tuersperre) 0 =
		{if}
			1 (S.L.doorTarget_0) (S.L.doorTarget_1)
			(T.L.ev_doortriggeropen_0)
			(T.L.ev_doortriggeropen_1)
		{endif}

		(L.L.tuersperre) 0 <
		{if}
			1 (S.L.doorTarget_1)
			(T.L.ev_doortriggeropen_1)
		{endif}

		(L.L.tuersperre) 0 >
		{if}
			1 (S.L.doorTarget_0)
			(T.L.ev_doortriggeropen_0)
		{endif}

		(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)

	{endif}

	(L.L.cockpit_tuertaster1)
	(L.L.AI_Scheduled_AtStation) -1 = ||
	(L.L.door_0) 0.5 >
	(L.L.door_1) 0.5 > || &&
	(L.L.doorTarget_0) 1 = (L.L.doorTarget_1) 1 = || &&
	(L.L.velocity) (C.L.tueroeffnung) < &&
	(C.L.Tuerfehlertoleranz) (L.L.wearlifespan) * (L.L.Door_Error_Count) > &&
	(L.L.elec_busbar_main) &&
	(L.L.bremse_p_tank04) 550000 > &&
	(L.L.door_01_nothahn_sw) ! &&
	{if}
		(L.L.tuersperre) 0 =
		{if}
			0 (S.L.doorTarget_0) (S.L.doorTarget_1)
			(T.L.ev_doortriggerclose_0)
			(T.L.ev_doortriggerclose_1)
		{endif}

		(L.L.tuersperre) 0 <
		{if}
			0 (S.L.doorTarget_1)
			(T.L.ev_doortriggerclose_1)
		{endif}

		(L.L.tuersperre) 0 >
		{if}
			0 (S.L.doorTarget_0)
			(T.L.ev_doortriggerclose_0)
		{endif}

		(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)

		(L.L.kneel_locked)
		(L.L.doorTarget_0) ! &&
		(L.L.doorTarget_1) ! &&
		(L.L.doorTarget_23) ! &&
		(L.L.doorTarget_45) ! &&
'		(L.L.doorTarget_67) ! &&
		{if}
			0 (S.L.kneel_locked)
		{endif}
	{endif}

'Tür 2

	(L.L.cockpit_tuertaster2)
	(L.L.AI_Scheduled_AtStation) 1 = ||
	(L.L.door_2) 0.5 < &&
	(L.L.door_3) 0.5 < &&
	(L.L.doorTarget_23_delayed) 0 = &&
	(L.L.velocity) (C.L.tueroeffnung) < &&
	(C.L.Tuerfehlertoleranz) (L.L.wearlifespan) * (L.L.Door2_Error_Count) > &&
	(L.L.elec_busbar_main) &&
	(L.L.bremse_p_tank04) 550000 > &&
	(L.L.door_23_nothahn_sw) ! &&
	{if}
		1 (S.L.doorTarget_23_delayed)
		(T.L.ev_doortriggeropen_2)

		(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
		0 (S.L.trigger_antirepeat23)
	{endif}

	(L.L.cockpit_tuertaster2)
	(L.L.AI_Scheduled_AtStation) -1 = ||
	(L.L.door_2) 0.5 >
	(L.L.door_3) 0.5 > || &&
	(L.L.doorTarget_23_delayed) 1 = &&
	(L.L.velocity) (C.L.tueroeffnung) < &&
	(C.L.Tuerfehlertoleranz) (L.L.wearlifespan) * (L.L.Door2_Error_Count) > &&
	(L.L.elec_busbar_main) &&
	(L.L.pandus_opn) ! &&
	(L.L.bremse_p_tank04) 550000 > &&
	(L.L.door_23_nothahn_sw) ! &&
	{if}
		0 (S.L.doorTarget_23_delayed)

		(C.L.tuerverzoegerung) 0 >
		(L.L.door_2) 1 = &&
		(L.L.door_3) 1 = &&
		{if}
			(T.L.ev_doorwarn)
		{endif}
	{endif}

	(L.L.doorTarget_23_delayed) !
	(L.L.pandus_opn) ! &&
	{if}
		(L.L.door_2) 1 =
		(L.L.door_3) 1 =
		{if}
			(L.L.doortimer23) (L.S.Timegap) + (C.L.tuerverzoegerung) min (S.L.doortimer23)
			(C.L.tuerverzoegerung) =
			{if}
				0 (S.L.doorTarget_23)
				(L.L.kneel_locked)
				(L.L.doorTarget_0) ! &&
				(L.L.doorTarget_1) ! &&
				(L.L.doorTarget_23) ! &&
				(L.L.doorTarget_45) ! &&
'				(L.L.doorTarget_67) ! &&
				{if}
					0 (S.L.kneel_locked)
				{endif}

				(L.L.trigger_antirepeat23) !
				{if}
					(T.L.ev_doortriggerclose_2)
					1 (S.L.trigger_antirepeat23)
					(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
				{endif}
			{endif}
		{else}
			0 (S.L.doorTarget_23)

			(L.L.trigger_antirepeat23) !
			{if}
				(T.L.ev_doortriggerclose_2)
				1 (S.L.trigger_antirepeat23)
				(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
			{endif}
		{endif}
	{else}
		1 (S.L.doorTarget_23)
		0 (S.L.doortimer23)
	{endif}

'	Lichtschranke wird per Zufall Blockiert durch Dreck oder ist gestört

	(L.L.lichtschranke_gestoert) 4 =
	(L.L.doorTarget_45) ! &&
	(L.L.door_4) 0.2 < &&
	{if}
		1 (S.L.lichtschranke_befehl)
	{else}
		0 (S.L.lichtschranke_befehl)
	{endif}

'	Setzen der Haltestellenbremse erst bei Stillstand des Busses:
	(L.L.bremse_halte_sw) (L.L.bus_dooraft_sw) || (L.L.door_20h_sw) ||
	(C.L.auto_HST_bremse) (L.L.velocity) 0.1 < && (L.L.brake) 0.1 > && (L.L.antrieb_gear_engaged_timer) (C.L.antrieb_gear_engaged_mintime) >= && ||
	(L.L.freigabe) 0 = || (L.L.door_2) 0 > || (L.L.door_3) 0 > || (L.L.door_4) 0 > || (L.L.door_5) 0 > || (L.L.door_6) 0 > || (L.L.door_7) 0 > || 
	(L.L.kneel_allowed) ||
	(L.L.bremse_halte) ! (L.L.Velocity) (C.L.Door_Bremse_Halte_MaxKMH) < && &&
	(L.L.cp_notloese_hsb) ! &&
	{if}
		(L.L.elec_busbar_main)
		{if}
			(L.L.bremse_halte) !
			{if}
				(T.L.ev_haltebremse_an)		
			{endif}	
			1 (S.L.bremse_halte)
			(L.L.bsb_Error_Count) 1 + (S.L.bsb_Error_Count)
		{endif}
	{else}
		(L.L.elec_busbar_main) !
		(L.L.cp_notloese_hsb) ||
		{if}
			(L.L.bremse_halte)
			{if}
				(T.L.ev_haltebremse_aus)		
				0 (S.L.bremse_halte)
			{endif}
		{endif}
	{endif}

	(M.L.DoorAft_Open)

'	Türfreigabekriterium

	(L.L.bremse_halte_sw) (L.L.bremse_halte) && (S.L.door_freigabe)

'	Haltewunschlampe:
	(L.L.haltewunsch) (L.L.door_2) 0.2 < (L.L.door_5) 0.2 < (L.L.elec_busbar_main) && && &&
	{if}
		1 (S.L.haltewunschlampe)
	{else}
		0 (S.L.haltewunschlampe) (S.L.haltewunsch)
	{endif}

'	Kinderwagenwunsch:
	(L.L.door_2) 0.2 > (L.L.door_3) 0.2 > || (L.L.elec_busbar_main) &&
	{if}
		0 (S.L.door_kinderwagenwunsch) (S.L.zufall_kinderwagenwunsch)
	{endif}

'	Abfall des Kinderwagenwunsch-Relais bei fehlender Stromversorgung:

	(L.L.elec_busbar_main) 0 = 
	{if}
		0 (S.L.door_kinderwagenwunsch) (S.L.zufall_kinderwagenwunsch)
	{endif}

'	Zufälliges zusätzliches Aufleuchten des Kinderwagenwunsches bei Haltewunsch:

	(L.L.haltewunsch) 1 =
	(L.L.zufall_kinderwagenwunsch) 0 = &&
	(L.S.Time) 72000 < (L.S.Time) 28800 > && &&
	{if}
		10 random (S.L.zufall_kinderwagenwunsch)
		(L.L.zufall_kinderwagenwunsch) 9 >=
		{if}
			1 (S.L.door_kinderwagenwunsch)
		{endif}
	{endif}


'	Rollstuhlwunsch:
	(L.L.door_2) 0.2 > (L.L.door_3) 0.2 > || (L.L.elec_busbar_main) 1 = &&
	{if}
		0 (S.L.door_rollstuhlwunsch) (S.L.zufall_rollstuhlwunsch)
	{endif}

'	Abfall des Kinderwagenwunsch-Relais bei fehlender Stromversorgung:

	(L.L.elec_busbar_main) 0 = 
	{if}
		0 (S.L.door_rollstuhlwunsch) (S.L.zufall_rollstuhlwunsch)
	{endif}

'	Zufälliges zusätzliches Aufleuchten des Kinderwagenwunsches bei Haltewunsch:

	(L.L.haltewunsch) 1 =
	(L.L.zufall_rollstuhlwunsch) 0 = &&
	{if}
		10 random (S.L.zufall_rollstuhlwunsch)
		(L.L.zufall_rollstuhlwunsch) 9 >=
		{if}
			1 (S.L.door_rollstuhlwunsch)
		{endif}
	{endif}
'	Beleuchtung der Einstiege

'	Druckabhängige Türgeschwindigkeit
	
	(C.L.door_druckluft)
	{if}
		(L.L.doorMaxSpeed_0_norm) (L.L.bremse_p_Tank04) 100000 - 850000 / (S.L.doorMaxSpeed_0)
		(L.L.doorMaxSpeed_1_norm) (L.L.bremse_p_Tank04) 100000 - 850000 / (S.L.doorMaxSpeed_1)
		(L.L.doorMaxSpeed_2_norm) (L.L.bremse_p_Tank04) 100000 - 850000 / (S.L.doorMaxSpeed_2)
		(L.L.doorMaxSpeed_3_norm) (L.L.bremse_p_Tank04) 100000 - 850000 / (S.L.doorMaxSpeed_3)		
		(L.L.doorMaxSpeed_4_norm) (L.L.bremse_p_Tank04) 100000 - 850000 / (S.L.doorMaxSpeed_4)
		(L.L.doorMaxSpeed_5_norm) (L.L.bremse_p_Tank04) 100000 - 850000 / (S.L.doorMaxSpeed_5)
	{endif}

'	Gemecker bei nicht freigegebener Tür

	(L.L.door_2) 0 >
	(L.L.door_3) 0 > ||
	(L.L.door_4) 0 = &&
	(L.L.door_5) 0 = &&
	(L.L.PAX_Exit2_Req) &&
	{if}
		(L.L.mecker_timer) (L.S.Timegap) + (S.L.mecker_timer)
		(L.L.mecker_timer) 3 > (L.L.mecker_timer) 3.1 < &&
		{if}
			(T.L.ev_meckern)
		{endif}
	{else}
		0 (S.L.mecker_timer)
	{endif}

'----------------------
'	AI-Ablauf:
	(L.L.AI_Scheduled_AtStation) 1 =
	(L.L.velocity) 0.5 < &&
	{if}
		1 (S.L.bus_dooraft_sw)
	{endif}

'Haltestellenbremse erst wegnehmen, wenn alle Türen zu. Dann auch erst den Bus AI-mäßig freigeben:
	(L.L.light_timer1) 1 >
	(L.L.light_timer2) 1 > &&
	(L.L.light_timer3) 1 > &&
	(L.L.light_timer4) 1 > &&
	(L.L.AI_Scheduled_AtStation) -1 = &&
	{if}
		0 (S.L.bremse_halte_sw) (S.L.AI_Scheduled_AtStation) (S.L.bremse_halte) (S.L.bus_dooraft_sw)
	{endif}


{end}




{macro:Door0_Calc}
(L.L.door_01_nothahn) !
{if}
	(C.L.electric_doors)
	{if}
		(L.L.doorTarget_0)
		{if}
			(L.L.door_0) (F.L.door_0_opn_speed) (S.L.doorMaxSpeed_0)
		{else}
			(L.L.door_0) (F.L.door_0_cls_speed) (S.L.doorMaxSpeed_0)
		{endif}

		(C.L.fdoor_acc) (S.L.doorAcc_0)

		(L.L.doorTarget_0) ! (L.L.doorSpeed_0) s0 abs 0.05 > (L.L.door_0) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_0) <
			{if}
				(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * - (S.L.doorSpeed_0)
			{else}
				(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * + (S.L.doorSpeed_0)
			{endif}
			(L.L.door_0) (L.L.doorSpeed_0) (L.S.Timegap) * + (S.L.door_0)
		{else}
			(L.L.doorSpeed_0) abs 0.05 > (L.L.door_0) 1 < || (L.L.doorTarget_0) &&
			{if}
				l0 (L.L.doorMaxSpeed_0) <
				{if}
					(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * + (S.L.doorSpeed_0) 
				{else}
					(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * - (S.L.doorSpeed_0) 
				{endif}
				(L.L.door_0) (L.L.doorSpeed_0) (L.S.Timegap) * + (S.L.door_0)
			{else}
				0 (S.L.doorSpeed_0)
			{endif}
		{endif}
	{else}
		(L.L.doorTarget_0) ! (L.L.doorSpeed_0) s0 abs 0.05 > (L.L.door_0) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_0) <
			{if}
				(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * - (S.L.doorSpeed_0)
			{endif}
			(L.L.door_0) (L.L.doorSpeed_0) (L.S.Timegap) * + (S.L.door_0)
		{else}
			(L.L.doorSpeed_0) abs 0.05 > (L.L.door_0) 1 < || (L.L.doorTarget_0) &&
			{if}
				l0 (L.L.doorMaxSpeed_0) <
				{if}
					(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * + (S.L.doorSpeed_0) 
				{endif}
				(L.L.door_0) (L.L.doorSpeed_0) (L.S.Timegap) * + (S.L.door_0)
			{else}
				0 (S.L.doorSpeed_0)
			{endif}
		{endif}
	{endif}

	(L.L.door_0) 1 >
	{if}
		(T.L.ev_doorhitopen_0)
		1 (S.L.door_0)
		(L.L.doorSpeed_0) /-/ (L.L.doorRefl_0) * (S.L.doorSpeed_0)
	{else}
		(L.L.door_0) 0 <
		{if}
			(T.L.ev_doorhitclose_0)
			0 (S.L.door_0)
			(L.L.doorSpeed_0) /-/ (L.L.doorRefl_0) * (S.L.doorSpeed_0)
		{endif}
	{endif}
	(L.L.door_0) (S.L.doorDragAcc_0)
{else}
	(L.L.doorDragAcc_0) (S.L.door_0)
{endif}
{end}

{macro:Door1_Calc}
(L.L.door_01_nothahn) !
{if}
	(C.L.electric_doors)
	{if}
		(L.L.doorTarget_1)
		{if}
			(L.L.door_1) (F.L.door_1_opn_speed) (S.L.doorMaxSpeed_1)
		{else}
			(L.L.door_1) (F.L.door_1_cls_speed) (S.L.doorMaxSpeed_1)
		{endif}

		(C.L.fdoor_acc) (S.L.doorAcc_1)

		(L.L.doorTarget_1) ! (L.L.doorSpeed_1) s0 abs 0.05 > (L.L.door_1) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_1) <
			{if}
				(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * - (S.L.doorSpeed_1)
			{else}
				(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * + (S.L.doorSpeed_1)
			{endif}
			(L.L.door_1) (L.L.doorSpeed_1) (L.S.Timegap) * + (S.L.door_1)
		{else}
			(L.L.doorSpeed_1) abs 0.05 > (L.L.door_1) 1 < || (L.L.doorTarget_1) &&
			{if}
				l0 (L.L.doorMaxSpeed_1) <
				{if}
					(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * + (S.L.doorSpeed_1) 
				{else}
					(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * - (S.L.doorSpeed_1) 
				{endif}
				(L.L.door_1) (L.L.doorSpeed_1) (L.S.Timegap) * + (S.L.door_1)
			{else}
				0 (S.L.doorSpeed_1)
			{endif}
		{endif}
	{else}
		(L.L.doorTarget_1) ! (L.L.doorSpeed_1) s0 abs 0.05 > (L.L.door_1) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_1) <
			{if}
				(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * - (S.L.doorSpeed_1)
			{endif}
			(L.L.door_1) (L.L.doorSpeed_1) (L.S.Timegap) * + (S.L.door_1)
		{else}
			(L.L.doorSpeed_1) abs 0.05 > (L.L.door_1) 1 < || (L.L.doorTarget_1) &&
			{if}
				l0 (L.L.doorMaxSpeed_1) <
				{if}
					(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * + (S.L.doorSpeed_1) 
				{endif}
				(L.L.door_1) (L.L.doorSpeed_1) (L.S.Timegap) * + (S.L.door_1)
			{else}
				0 (S.L.doorSpeed_1)
			{endif}
		{endif}
	{endif}

	(L.L.door_1) 1 >
	{if}
		(T.L.ev_doorhitopen_1)
		1 (S.L.door_1)
		(L.L.doorSpeed_1) /-/ (L.L.doorRefl_1) * (S.L.doorSpeed_1)
	{else}
		(L.L.door_1) 0 <
		{if}
			(T.L.ev_doorhitclose_1)
			0 (S.L.door_1)
			(L.L.doorSpeed_1) /-/ (L.L.doorRefl_1) * (S.L.doorSpeed_1)
		{endif}
	{endif}
	(L.L.door_1) (S.L.doorDragAcc_1)
{else}
	(L.L.doorDragAcc_1) (S.L.door_1)
{endif}
{end}


{macro:DoorAftCalc}
	(L.L.bremse_halte_sw) !
      	(L.L.bus_dooraft_sw) ! &&
	(L.L.Freigabe) &&
	(L.L.door_2) 0 = &&
	(L.L.door_3) 0 = &&
	(L.L.door_4) 0 = &&
	(L.L.door_5) 0 = &&
	(L.L.bremse_halte) &&
	(L.L.throttle) 0.1 > &&
      	(L.L.kneel_timer) 0 = &&
	(L.L.vdv_error_bsb_active) ! &&
	{if}
		0 (S.L.bremse_halte) 
		0 (S.L.doorAftLastOpen) (S.L.doorAftLastOpen1)
		(T.L.ev_haltebremse_aus)
	{endif}


{end}

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


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

{macro:DoorAft_Open}

	(L.L.exit2_lichtschranke)
	(L.L.door_haltewunsch_knopfdruck) ||
	(L.L.lichtschranke_befehl) ||
	(L.L.door_45_nothahn_sw) ||
	(L.L.bremse_p_tank04) 550000 > &&
	{if}
		(L.L.doorTarget_45) !
		(L.L.bus_dooraft_sw) &&
		(L.L.velocity) 0.1 < &&
		(L.L.lichtschranke_befehl) ||
		{if}
			(C.L.lichtschrankenanfaelligkeit) random (S.L.lichtschranke_gestoert)
			(T.L.ev_doortriggeropen_5)
			1 (S.L.doorTarget_45)
			1 (S.L.bremse_halte)
			(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
			0 (S.L.exit2_lichtschranke)
		{endif}
		0 (S.L.doorAftLastOpen1)
	{endif}

	(L.L.PAX_Exit2_Req) 
	{if}
		0 (S.L.doorAftLastOpen1)
	{endif}

	(L.L.elec_busbar_main)
	{if}
		(L.L.bremse_halte)
		(L.L.bremse_feststell) ||
		{if}
			(L.L.doorAftLastOpen1) (L.S.Timegap) + (S.L.doorAftLastOpen1)
		{endif}

		(L.L.doorTarget_45)
		(L.L.doorAftLastOpen1) (C.L.doorAftOpenTime) > &&
		(L.L.bremse_p_tank04) 550000 > &&
		{if}
			(L.L.doortimer45) (L.S.Timegap) + (C.L.tuerverzoegerung) min (S.L.doortimer45)
			(C.L.tuerverzoegerung) 0 >
			{if}
				(L.L.doortimer45) 0.05 <
				{if}
					(T.L.ev_doorwarn2)
				{endif}
				(L.L.doortimer45) (C.L.tuerverzoegerung) =
				{if}
					0 (S.L.doorTarget_45)
					(T.L.ev_doortriggerclose_5)
					(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
				{endif}
			{else}
				(T.L.ev_doortriggerclose_5)
				0 (S.L.doorTarget_45)
				(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
			{endif}
		{endif}
	{endif}
{end}

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

{macro:Door2_Calc}
(L.L.door_23_nothahn) !
{if}
	(C.L.electric_doors)
	{if}
		(L.L.doorTarget_23)
		{if}
			(L.L.door_2) (F.L.door_2_opn_speed) (S.L.doorMaxSpeed_2)
		{else}
			(L.L.door_2) (F.L.door_2_cls_speed) (S.L.doorMaxSpeed_2)
		{endif}

		(C.L.bdoor_acc) (S.L.doorAcc_2)

		(L.L.doorTarget_23) ! (L.L.doorSpeed_2) s0 abs 0.05 > (L.L.door_2) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_2) <
			{if}
				(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * - (S.L.doorSpeed_2)
			{else}
				(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * + (S.L.doorSpeed_2)
			{endif}
			(L.L.door_2) (L.L.doorSpeed_2) (L.S.Timegap) * + (S.L.door_2)
		{else}
			(L.L.doorSpeed_2) abs 0.05 > (L.L.door_2) 1 < || (L.L.doorTarget_23) &&
			{if}
				l0 (L.L.doorMaxSpeed_2) <
				{if}
					(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * + (S.L.doorSpeed_2) 
				{else}
					(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * - (S.L.doorSpeed_2) 
				{endif}
				(L.L.door_2) (L.L.doorSpeed_2) (L.S.Timegap) * + (S.L.door_2)
				0 (S.L.trigger_antirepeat23)
			{else}
				0 (S.L.doorSpeed_2)
			{endif}
		{endif}
	{else}
		(L.L.doorTarget_23) ! (L.L.doorSpeed_2) s0 abs 0.05 > (L.L.door_2) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_2) <
			{if}
				(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * - (S.L.doorSpeed_2)
			{endif}
			(L.L.door_2) (L.L.doorSpeed_2) (L.S.Timegap) * + (S.L.door_2)
		{else}
			(L.L.doorSpeed_2) abs 0.05 > (L.L.door_2) 1 < || (L.L.doorTarget_23) &&
			{if}
				l0 (L.L.doorMaxSpeed_2) <
				{if}
					(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * + (S.L.doorSpeed_2) 
				{endif}
				(L.L.door_2) (L.L.doorSpeed_2) (L.S.Timegap) * + (S.L.door_2)
			{else}
				0 (S.L.doorSpeed_2)
			{endif}
		{endif}
	{endif}

	(L.L.door_2) 1 >
	{if}
		(T.L.ev_doorhitopen_2)
		1 (S.L.door_2)
		(L.L.doorSpeed_2) /-/ (L.L.doorRefl_2) * (S.L.doorSpeed_2)
	{else}
		(L.L.door_2) 0 <
		{if}
			(T.L.ev_doorhitclose_2)
			0 (S.L.door_2)
			(L.L.doorSpeed_2) /-/ (L.L.doorRefl_2) * (S.L.doorSpeed_2)
		{endif}
	{endif}
	(L.L.door_2) (S.L.doorDragAcc_2)
{else}
	(L.L.doorDragAcc_2) (S.L.door_2)
{endif}
{end}

{macro:Door3_Calc}
(L.L.door_23_nothahn) !
{if}
	(C.L.electric_doors)
	{if}
		(L.L.doorTarget_23)
		{if}
			(L.L.door_3) (F.L.door_3_opn_speed) (S.L.doorMaxSpeed_3)
		{else}
			(L.L.door_3) (F.L.door_3_cls_speed) (S.L.doorMaxSpeed_3)
		{endif}

		(C.L.bdoor_acc) (S.L.doorAcc_3)

		(L.L.doorTarget_23) ! (L.L.doorSpeed_3) s0 abs 0.05 > (L.L.door_3) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_3) <
			{if}
				(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * - (S.L.doorSpeed_3)
			{else}
				(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * + (S.L.doorSpeed_3)
			{endif}
			(L.L.door_3) (L.L.doorSpeed_3) (L.S.Timegap) * + (S.L.door_3)
		{else}
			(L.L.doorSpeed_3) abs 0.05 > (L.L.door_3) 1 < || (L.L.doorTarget_23) &&
			{if}
				l0 (L.L.doorMaxSpeed_3) <
				{if}
					(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * + (S.L.doorSpeed_3) 
				{else}
					(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * - (S.L.doorSpeed_3) 
				{endif}
				(L.L.door_3) (L.L.doorSpeed_3) (L.S.Timegap) * + (S.L.door_3)
			{else}
				0 (S.L.doorSpeed_3)
			{endif}
		{endif}
	{else}
		(L.L.doorTarget_23) ! (L.L.doorSpeed_3) s0 abs 0.05 > (L.L.door_3) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_3) <
			{if}
				(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * - (S.L.doorSpeed_3)
			{endif}
			(L.L.door_3) (L.L.doorSpeed_3) (L.S.Timegap) * + (S.L.door_3)
		{else}
			(L.L.doorSpeed_3) abs 0.05 > (L.L.door_3) 1 < || (L.L.doorTarget_23) &&
			{if}
				l0 (L.L.doorMaxSpeed_3) <
				{if}
					(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * + (S.L.doorSpeed_3) 
				{endif}
				(L.L.door_3) (L.L.doorSpeed_3) (L.S.Timegap) * + (S.L.door_3)
			{else}
				0 (S.L.doorSpeed_3)
			{endif}
		{endif}
	{endif}

	(L.L.door_3) 1 >
	{if}
		(T.L.ev_doorhitopen_3)
		1 (S.L.door_3)
		(L.L.doorSpeed_3) /-/ (L.L.doorRefl_3) * (S.L.doorSpeed_3)
	{else}
		(L.L.door_3) 0 <
		{if}
			(T.L.ev_doorhitclose_3)
			0 (S.L.door_3)
			(L.L.doorSpeed_3) /-/ (L.L.doorRefl_3) * (S.L.doorSpeed_3)
		{endif}
	{endif}
	(L.L.door_3) (S.L.doorDragAcc_3)
{else}
	(L.L.doorDragAcc_3) (S.L.door_3)
{endif}
{end}

{macro:Door4_Calc}
(L.L.door_45_nothahn) !
{if}
	(C.L.electric_doors)
	{if}
		(L.L.doorTarget_45)
		{if}
			(L.L.door_4) (F.L.door_4_opn_speed) (S.L.doorMaxSpeed_4)
		{else}
			(L.L.door_4) (F.L.door_4_cls_speed) (S.L.doorMaxSpeed_4)
		{endif}

		(C.L.bdoor_acc) (S.L.doorAcc_4)

		(L.L.doorTarget_45) ! (L.L.doorSpeed_4) s0 abs 0.05 > (L.L.door_4) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_4) <
			{if}
				(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * - (S.L.doorSpeed_4)
			{else}
				(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * + (S.L.doorSpeed_4)
			{endif}
			(L.L.door_4) (L.L.doorSpeed_4) (L.S.Timegap) * + (S.L.door_4)
		{else}
			(L.L.doorSpeed_4) abs 0.05 > (L.L.door_4) 1 < || (L.L.doorTarget_45) &&
			{if}
				l0 (L.L.doorMaxSpeed_4) <
				{if}
					(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * + (S.L.doorSpeed_4) 
				{else}
					(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * - (S.L.doorSpeed_4) 
				{endif}
				(L.L.door_4) (L.L.doorSpeed_4) (L.S.Timegap) * + (S.L.door_4)
			{else}
				0 (S.L.doorSpeed_4)
			{endif}
		{endif}
	{else}
		(L.L.doorTarget_45) ! (L.L.doorSpeed_4) s0 abs 0.05 > (L.L.door_4) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_4) <
			{if}
				(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * - (S.L.doorSpeed_4)
			{endif}
			(L.L.door_4) (L.L.doorSpeed_4) (L.S.Timegap) * + (S.L.door_4)
		{else}
			(L.L.doorSpeed_4) abs 0.05 > (L.L.door_4) 1 < || (L.L.doorTarget_45) &&
			{if}
				l0 (L.L.doorMaxSpeed_4) <
				{if}
					(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * + (S.L.doorSpeed_4) 
				{endif}
				(L.L.door_4) (L.L.doorSpeed_4) (L.S.Timegap) * + (S.L.door_4)
			{else}
				0 (S.L.doorSpeed_4)
			{endif}
		{endif}
	{endif}

	(L.L.door_4) 1 >
	{if}
		(T.L.ev_doorhitopen_4)
		1 (S.L.door_4)
		(L.L.doorSpeed_4) /-/ (L.L.doorRefl_4) * (S.L.doorSpeed_4)
	{else}
		(L.L.door_4) 0 <
		{if}
			(T.L.ev_doorhitclose_4)
			0 (S.L.door_4)
			(L.L.doorSpeed_4) /-/ (L.L.doorRefl_4) * (S.L.doorSpeed_4)
		{endif}
	{endif}
	(L.L.door_4) (S.L.doorDragAcc_4)
{else}
	(L.L.doorDragAcc_4) (S.L.door_4)
{endif}
{end}

{macro:Door5_Calc}
(L.L.door_45_nothahn) !
{if}
	(C.L.electric_doors)
	{if}
		(L.L.doorTarget_45)
		{if}
			(L.L.door_5) (F.L.door_5_opn_speed) (S.L.doorMaxSpeed_5)
		{else}
			(L.L.door_5) (F.L.door_5_cls_speed) (S.L.doorMaxSpeed_5)
		{endif}

		(C.L.bdoor_acc) (S.L.doorAcc_5)

		(L.L.doorTarget_45) ! (L.L.doorSpeed_5) s0 abs 0.05 > (L.L.door_5) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_5) <
			{if}
				(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * - (S.L.doorSpeed_5)
			{else}
				(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * + (S.L.doorSpeed_5)
			{endif}
			(L.L.door_5) (L.L.doorSpeed_5) (L.S.Timegap) * + (S.L.door_5)

			(L.L.kneel_locked)
			(L.L.doorTarget_0) ! &&
			(L.L.doorTarget_1) ! &&
			(L.L.doorTarget_23) ! &&
			(L.L.doorTarget_45) ! &&
'			(L.L.doorTarget_67) ! &&
			{if}
				0 (S.L.kneel_locked)
			{endif}
		{else}
			(L.L.doorSpeed_5) abs 0.05 > (L.L.door_5) 1 < || (L.L.doorTarget_45) &&
			{if}
				l0 (L.L.doorMaxSpeed_5) <
				{if}
					(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * + (S.L.doorSpeed_5) 
				{else}
					(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * - (S.L.doorSpeed_5) 
				{endif}
				(L.L.door_5) (L.L.doorSpeed_5) (L.S.Timegap) * + (S.L.door_5)
				0 (S.L.doortimer45)
				0 (S.L.trigger_antirepeat45)
			{else}
				0 (S.L.doorSpeed_5)
			{endif}
		{endif}
	{else}
		(L.L.doorTarget_45) ! (L.L.doorSpeed_5) s0 abs 0.05 > (L.L.door_5) 0 > || && 
		{if}
			l0 /-/ (L.L.doorMaxSpeed_5) <
			{if}
				(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * - (S.L.doorSpeed_5)
			{endif}
			(L.L.door_5) (L.L.doorSpeed_5) (L.S.Timegap) * + (S.L.door_5)
		{else}
			(L.L.doorSpeed_5) abs 0.05 > (L.L.door_5) 1 < || (L.L.doorTarget_45) &&
			{if}
				l0 (L.L.doorMaxSpeed_5) <
				{if}
					(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * + (S.L.doorSpeed_5) 
				{endif}
				(L.L.door_5) (L.L.doorSpeed_5) (L.S.Timegap) * + (S.L.door_5)
				0 (S.L.doortimer45)
				0 (S.L.trigger_antirepeat45)
			{else}
				0 (S.L.doorSpeed_5)
			{endif}
		{endif}
	{endif}

	(L.L.door_5) 1 >
	{if}
		(T.L.ev_doorhitopen_5)
		1 (S.L.door_5)
		(L.L.doorSpeed_5) /-/ (L.L.doorRefl_5) * (S.L.doorSpeed_5)
	{else}
		(L.L.door_5) 0 <
		{if}
			(T.L.ev_doorhitclose_5)
			0 (S.L.door_5)
			(L.L.doorSpeed_5) /-/ (L.L.doorRefl_5) * (S.L.doorSpeed_5)
		{endif}
	{endif}
	(L.L.door_5) (S.L.doorDragAcc_5)
{else}
	(L.L.doorDragAcc_5) (S.L.door_5)
{endif}
{end}


{macro:trg_bus_doorfront0}

	(L.L.doorTarget_0) ! (S.L.doorTarget_0) 
	{if}
		(T.L.ev_doortriggeropen_0)
	{else}
		(T.L.ev_doortriggerclose_0)
	{endif}
		(C.L.door_druckluft)
		{if}
		(L.L.bremse_p_Tank04) 100000 - 0.98 * 100000 + (S.L.bremse_p_Tank04)
		{endif}
{end}

{macro:trg_bus_doorfront1}

	(L.L.doorTarget_1) ! (S.L.doorTarget_1) 
	{if}
		(T.L.ev_doortriggeropen_0)
	{else}
		(T.L.ev_doortriggerclose_0)
	{endif}	
		(C.L.door_druckluft)
		{if}
		(L.L.bremse_p_Tank04) 100000 - 0.98 * 100000 + (S.L.bremse_p_Tank04)
		{endif}
{end}

{macro:trg_bus_doorback23}

	(L.L.doorTarget_23) ! (S.L.doorTarget_23) 
	{if}
		(T.L.ev_doortriggeropen_2)
	{else}
		(C.L.tuerverzoegerung) 0 >
		{if}
			(T.L.ev_doorwarn)
		{else}
			(T.L.ev_doortriggerclose_2)
		{endif}
	{endif}	
		(C.L.door_druckluft)
		{if}
		(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
		{endif}
{end}

{macro:trg_bus_doorfront5}

	(L.L.doorTarget_45) ! (S.L.doorTarget_45) 
	{if}
		(T.L.ev_doortriggeropen_5)
	{else}
		(C.L.tuerverzoegerung) 0 >
		{if}
			(T.L.ev_doorwarn2)
		{else}
			(T.L.ev_doortriggerclose_5)
		{endif}
	{endif}	
		(C.L.door_druckluft)
		{if}
		(L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
		{endif}
{end}

{macro:trg_bus_20h-switch}
	(L.L.door_20h_sw) ! (S.L.door_20h_sw)
	
	(L.L.door_20h_sw)
	{if}
		(T.L.ev_haltebremse_sw_an)
	{else}
		(T.L.ev_haltebremse_sw_aus)
	{endif}	
{end}

{macro:trg_bus_dooraft}
	(L.L.bremse_halte_sw) ! (S.L.bremse_halte_sw)
	
	(L.L.bremse_halte_sw)
	{if}
		(T.L.ev_haltebremse_sw_an)
	{else}
		(T.L.ev_haltebremse_sw_aus)
	{endif}	
{end}

{trigger:cp_schulfahrschalter}
	1 (S.L.schulfahrschaltung)	
	(T.L.ev_VDV_toggle_on)
	1 (S.L.schulfahrschalter_sw)
{end}

{trigger:cp_schulfahrschalter_off}	
	0 (S.L.schulfahrschalter_sw)
	(T.L.ev_VDV_toggle_off)	
{end}

{trigger:cp_schulfahrschalter_aus}
	0 (S.L.schulfahrschaltung)	
	(T.L.ev_VDV_toggle_on)
	-1 (S.L.schulfahrschalter_sw)
{end}

{trigger:cp_schulfahrschalter_aus_off}	
	0 (S.L.schulfahrschalter_sw)
	(T.L.ev_VDV_toggle_off)	
{end}

{trigger:cp_tuersperre}	
	(L.L.tuersperre) 1 =
	(L.L.tuersperre) -1 = ||
	{if}
		0 (S.L.tuersperre)
		(T.L.ev_VDV_off)

		(L.L.doorTarget_1) 1 =
		(L.L.doorTarget_0) 0 = &&
		{if}
			1 (S.L.doorTarget_0)
			(T.L.ev_doortriggeropen_0)
		{endif}
		(L.L.doorTarget_0) 1 =
		(L.L.doorTarget_1) 0 = &&
		{if}
			1 (S.L.doorTarget_1)
			(T.L.ev_doortriggeropen_1)
		{endif}
	{else}
		-1 (S.L.tuersperre)
		(T.L.ev_VDV_on)

		(L.L.doorTarget_0) 1 =
		{if}
			0 (S.L.doorTarget_0)
			(T.L.ev_doortriggerclose_0)
		{endif}
	{endif}
{end}

{trigger:cp_tuersperre_2}	
	(L.L.tuersperre) 1 =
	(L.L.tuersperre) -1 = ||
	{if}
		0 (S.L.tuersperre)
		(T.L.ev_VDV_off)

		(L.L.doorTarget_0) 1 =
		(L.L.doorTarget_1) 0 = &&
		{if}
			1 (S.L.doorTarget_1)
			(T.L.ev_doortriggeropen_1)
		{endif}
		(L.L.doorTarget_1) 1 =
		(L.L.doorTarget_0) 0 = &&
		{if}
			1 (S.L.doorTarget_0)
			(T.L.ev_doortriggeropen_0)
		{endif}
	{else}
		1 (S.L.tuersperre)
		(T.L.ev_VDV_on)

		(L.L.doorTarget_1) 1 =
		{if}
			0 (S.L.doorTarget_1)
			(T.L.ev_doortriggerclose_1)
		{endif}
	{endif}
{end}

{macro:door_traegheit}

'Simuliert träges Verhalten (exponentiell)

'Ladekonventionen:
'	Sollwert		l0
'	Istwert			l1
'	Konstante Anlauf	l2 (Einheiten/s)
'	Konstante Ablauf	l3 (Einheiten/s)

'Anlauf oder Auslauf?
	l0 l1 > 
	{if}
		l2 (L.S.Timegap) * 1 min -1 max s4
	{else}
		l3 (L.S.Timegap) * 1 min -1 max s4
	{endif}


'Sollwert:
	l0
'Istwert:
	l1
'Beschleunigung:
	- l4 *
'Addition zum Istwert:
	l1 + s1
{end}