'##############
'Door Script
'##############
'--------------------------------------------------------------------------------
'Внимание! Аттеншн! Ахтунг! Увага! Аттенсьон!
'Данный скрипт подогнан мной ровно под Икарус-260.37 от IkarusSatert, который делался
'в рамках The IkarusProject, так что нейух его использовать на других автобусах
'(это, конечно, совет, хотите - делайте, но здесь есть некоторые подзаковырки)
'Текст для гуглопереводчика, без просторечий:
'Text fot translator, without Russian hard common language
'Данный скрипт предназначен только для Икарус-260.37 от IkarusSatert, который делался
'в рамках The IkarusProject, не рекомендую его использовать на других автобусах
'(это, конечно, совет, хотите - делайте, но здесь есть некоторые вещи, которые могут испортить ваш автобус)
'	Исключительно с добрыми пожеланиями и благими намерениями, alexander186 :))))
'
'Значт подогнал под ЛАЗ и неебет ;)
'Скорость створок теперь настраивается в констфайле.
'Вырезанно лишнее ,соединены кнопки открытия\закрытия,входящие пассажиры ожидают,пока выйдут другие.
'Но все-таки нейух использовать на других автобусах (кто это сделает тот Киркоров).
'Vitaly L.
'---------------------------------------------------------------------------

{trigger:bus_doorfront0}
	(L.L.elec_busbar_avail) (C.L.elec_busbar_minV) >
	{if}
		(L.L.doorTarget_1) !
		{if}
			(M.L.trg_bus_door_1)
			1 (S.L.doorTarget_1)
		{else}
			(M.L.trg_bus_door_1)
			0 (S.L.doorTarget_1)
			
		{endif}
	{endif}
	(S.L.cockpit_tuertaster1)
{end}

{trigger:bus_doorfront1}
	(L.L.elec_busbar_avail) (C.L.elec_busbar_minV) >
	{if}
		(L.L.doorTarget_2) !
		{if}
			(M.L.trg_bus_door_2)
			1 (S.L.doorTarget_2)
		{else}
			(M.L.trg_bus_door_2)
			0 (S.L.doorTarget_2)
			
		{endif}
	{endif}
	(S.L.cockpit_tuertaster2)
{end}

'--------------------------------------------------------------------------
'кнопки

{trigger:bus_door_1}
		(L.L.elec_busbar_avail) (C.L.elec_busbar_minV) >
	{if}
		(L.L.doorTarget_1) !
	{if}
		(M.L.trg_bus_door_1)
	1 (S.L.doorTarget_1)
	{else}
	(M.L.trg_bus_door_1)
	0 (S.L.doorTarget_1) 
	{endif}
{endif}
	(S.L.cockpit_tuertaster1)
{end}

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

{trigger:bus_door_2}
		(L.L.elec_busbar_avail) (C.L.elec_busbar_minV) >
	{if}
		(L.L.doorTarget_2) !
	{if}
		(M.L.trg_bus_door_2)
	1 (S.L.doorTarget_2)
	{else}
	(M.L.trg_bus_door_2)
	0 (S.L.doorTarget_2) 
	{endif}
{endif}
	(S.L.cockpit_tuertaster2)
{end}

'--------------------------------------------------------------------------
'краны аварийного открытия


{trigger:bus_door_1_kran}
		(L.L.elec_busbar_avail) (C.L.elec_busbar_minV) >
	{if}
		(L.L.doorTarget_1) !
	{if}
		(M.L.trg_bus_door_1)
	1 (S.L.doorTarget_1) (S.L.cockpit_tuer_kran_1_rot) 
	{else} 
	(M.L.trg_bus_door_1)
	0 (S.L.doorTarget_1) (S.L.cockpit_tuer_kran_1_rot)
	1 (S.L.cockpit_tuer_kran_1_trans)
	{endif}
{endif}
{end}

{trigger:bus_door_1_kran_trans_off}
	0 (S.L.cockpit_tuer_kran_1_trans)
{end}

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


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

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

{macro:Door_Init}
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.door_acc_1R) + (S.L.doorAcc_1R)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.door_acc_1L) + (S.L.doorAcc_1L)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.door_acc_2R) + (S.L.doorAcc_2R)
	1000 random 500 / 1 - (C.L.door_acc_var) * (C.L.door_acc_2L) + (S.L.doorAcc_2L)

	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.door_maxspeed_1R) + (S.L.doorMaxSpeed_1R_norm)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.door_maxspeed_1L) + (S.L.doorMaxSpeed_1L_norm)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.door_maxspeed_2R) + (S.L.doorMaxSpeed_2R_norm)
	1000 random 500 / 1 - (C.L.door_maxspeed_var) * (C.L.door_maxspeed_2L) + (S.L.doorMaxSpeed_2L_norm)

	(C.L.door_refl_1R) (S.L.doorRefl_1R)
	(C.L.door_refl_1L) (S.L.doorRefl_1L)
	(C.L.door_refl_2R) (S.L.doorRefl_2R)
	(C.L.door_refl_2L) (S.L.doorRefl_2L)
	
{end}

{macro:Door_Frame}
	(M.L.Door1_Calc)
	(M.L.Door2_Calc)

	(L.L.door_1R) 0.9 > (S.L.PAX_Entry0_Open) (S.L.PAX_Exit0_Open)
	(L.L.door_2L) 0.9 > (S.L.PAX_Entry1_Open) (S.L.PAX_Exit1_Open)

'	"Dauerfeuer"-Haltewunsch ьber Kinderwagenschalter (macht genau dasselbe wie der "trigger:int_haltewunsch"):
	(L.L.door_handsteuerung) (L.L.door_haltewunsch_knopfdruck) ||
	{if}
		1 (S.L.haltewunsch)
	{endif}

	(L.L.PAX_Exit1_Req) (L.L.door_haltewunsch_knopfdruck) || (L.L.elec_busbar_main) (C.L.elec_busbar_minV) > &&
	{if}
		1 (S.L.haltewunschlampe)
	{endif}

	(L.L.PAX_Exit0_Req) (L.L.door_haltewunsch_knopfdruck) || (L.L.elec_busbar_main) (C.L.elec_busbar_minV) > &&
	{if}
		1 (S.L.haltewunschlampe)
	{endif}


	(L.L.haltewunsch) (L.L.door_2L) 0.2 > (L.L.door_2R) 0.2 > || &&
	(L.L.elec_busbar_main) (C.L.elec_busbar_minV) < ||
	{if}
		0 (S.L.haltewunschlampe) (S.L.door_haltewunsch_knopfdruck) 
	{endif}

'	Beleuchtung der Einstiege
	(L.L.elec_busbar_main) (C.L.elec_busbar_minV) >
{if}
		(L.L.door_2L) (L.L.door_2R) || 0.1 > (S.L.door_light_2)
	{else}
		0 (S.L.door_light_1) (S.L.door_light_2)
	{endif}
	
'	двери
	(L.L.elec_busbar_main) (C.L.elec_busbar_minV) >
{if}
		(L.L.door_1L) (L.L.door_2R) || 0.1 > (S.L.door_opn_light)
	{endif}

	(L.L.door_1L) 0.1 < (L.L.door_1R) 0.1 < &&
	(L.L.door_2R) 0.1 < (L.L.door_2L) 0.1 < && &&
	{if}
		(T.L.ev_csengo_aus)
		0 (S.L.cockpit_csengo_button)
	{endif}

'	Druckabhдngige Tьrgeschwindigkeit
	
	(L.L.doorMaxSpeed_1R_norm) (L.L.bremse_p_Tank04) 100000 - 85000 / (S.L.doorMaxSpeed_1R)
	(L.L.doorMaxSpeed_1L_norm) (L.L.bremse_p_Tank04) 100000 - 85000 / (S.L.doorMaxSpeed_1L)
	(L.L.doorMaxSpeed_2R_norm) (L.L.bremse_p_Tank04) 100000 - 85000 / (S.L.doorMaxSpeed_2R)
	(L.L.doorMaxSpeed_2L_norm) (L.L.bremse_p_Tank04) 100000 - 85000 / (S.L.doorMaxSpeed_2L)

'----------------------
'	AI-Ablauf:

(L.L.AI_Scheduled_AtStation) s0
1 =
{if}
'Wenn Tьren geцffnet werden sollen:
	(L.L.Velocity) (C.L.Door_Bremse_Halte_MaxKMH) <
	{if}
'Nur, wenn v < maxkmh, sonst warten
'Taster jeweils nur betдtigen, falls noch nicht an
		(L.L.doorTarget_1) ! (L.L.door_AI_timer) 0.3 > &&
		{if}
			1 (S.L.doorTarget_1)
			(M.L.trg_bus_door_1)
		{endif}
		(L.L.doorTarget_2) ! (L.L.door_AI_timer) 0.6 > &&
		{if}
			1 (S.L.doorTarget_2)
			(M.L.trg_bus_door_2)
		{endif}
	{else}
		0 (S.L.door_AI_timer)
	{endif}
	(L.L.door_AI_timer) (L.S.Timegap) + (S.L.door_AI_timer)
{else}
l0 -1 =
{if}
'Wenn Tьren geschlossen werden sollen:
'Taster jeweils nur betдtigen, falls noch nicht aus:
	(L.L.doorTarget_2)
	{if}
		(M.L.trg_bus_door_2)
		0 (S.L.doorTarget_2)
		0 (S.L.door_AI_timer)
	{endif}
	(L.L.doorTarget_1) (L.L.door_AI_timer) 0.3 > &&
	{if}
		(M.L.trg_bus_door_1)
		0 (S.L.doorTarget_1)
	{endif}
'Haltestellenbremse erst wegnehmen, wenn alle Tьren zu. Dann auch erst den Bus AI-mдЯig freigeben:
	(L.L.door_1R) 0.1 <
	(L.L.door_2R) 0.1 < &&
	(L.L.door_1L) 0.1 < &&
	(L.L.door_2L) 0.1 < &&
	{if}
		0 (S.L.AI_Scheduled_AtStation)
	{endif}
	(L.L.door_AI_timer) (L.S.Timegap) + (S.L.door_AI_timer)
{endif}
{endif}


{end}



{macro:Door1_Calc}

		(L.L.doorTarget_1)
		{if}
			(L.L.door_1R) (F.L.door_1R_opn_speed) (S.L.doorMaxSpeed_1R_norm)
		{else}
			(L.L.door_1R) (F.L.door_1R_cls_speed) (S.L.doorMaxSpeed_1R_norm)
		{endif}

	(L.L.doorTarget_1) ! (L.L.doorSpeed_1R) s0 abs 0.05 > (L.L.door_1R) 0 > || && 
	{if}
		l0 /-/ (L.L.doorMaxSpeed_1R) <
		{if}
			(L.L.door_1R) 0.95 <
			(L.L.door_1R) 0 > &&
			{if}
				(L.L.doorSpeed_1R) (L.L.doorAcc_1R) (L.S.Timegap) * - (S.L.doorSpeed_1R)
			{else}
				(L.L.door_1R) 0.95 >
				{if}
					(L.L.door_1R_timer) (L.S.Timegap) + (S.L.door_1R_timer) (C.L.door_1R_op_zakr) >=
					{if}
						(L.L.doorSpeed_1R) (L.L.doorAcc_1R) (L.S.Timegap) * - (S.L.doorSpeed_1R)
					{endif}
				{endif}
			{endif}
		{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_1) &&
		{if}
			l0 (L.L.doorMaxSpeed_1R) <
			{if}
				(L.L.door_1R) 0.05 >
				(L.L.door_1R) 1 < &&
				{if}
					(L.L.doorSpeed_1R) (L.L.doorAcc_1R) (L.S.Timegap) * + (S.L.doorSpeed_1R)
				{else}
					(L.L.door_1R) 0.05 <
					{if}
						(L.L.door_1R_timer) (L.S.Timegap) + (S.L.door_1R_timer) (C.L.door_1R_op_otkr) >=
						{if}
							(L.L.doorSpeed_1R) (L.L.doorAcc_1R) (L.S.Timegap) * + (S.L.doorSpeed_1R)
						{endif}
					{endif}
				{endif}
			{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.12 >
	{if}
		0 (S.L.door_1R_timer)
		(T.L.ev_doorhitopen_1)
		1.12 (S.L.door_1R)
		(L.L.doorSpeed_1R) /-/ (L.L.doorRefl_1R) * (S.L.doorSpeed_1R)
	{else}
		(L.L.door_1R) 1 >
		(L.L.door_1R) 1.01 < &&
		(L.L.doorSpeed_1R) 0 < &&
		{if}
			0 (S.L.doorSpeed_1R)
			1 (S.L.door_1R)
		{else}
			(L.L.door_1R) 0 <
			{if}
				(T.L.ev_doorhitclose_1)
				0 (S.L.door_1R) (S.L.door_1R_timer)
				(L.L.doorSpeed_1R) /-/ (L.L.doorRefl_1R) * (S.L.doorSpeed_1R)
			{endif}
		{endif}
	{endif}


		(L.L.doorTarget_1)
		{if}
			(L.L.door_1L) (F.L.door_1L_opn_speed) (S.L.doorMaxSpeed_1L_norm)
		{else}
			(L.L.door_1L) (F.L.door_1L_cls_speed) (S.L.doorMaxSpeed_1L_norm)
		{endif}

	(L.L.doorTarget_1) ! (L.L.doorSpeed_1L) s0 abs 0.05 > (L.L.door_1L) 0 > || && 
	{if}
		l0 /-/ (L.L.doorMaxSpeed_1L) <
		{if}
			(L.L.door_1L) 0.95 <
			(L.L.door_1L) 0 > &&
			{if}
				(L.L.doorSpeed_1L) (L.L.doorAcc_1L) (L.S.Timegap) * - (S.L.doorSpeed_1L)
			{else}
				(L.L.door_1L) 0.95 >
				{if}
					(L.L.door_1L_timer) (L.S.Timegap) + (S.L.door_1L_timer) (C.L.door_1L_op_zakr) >=
					{if}
						(L.L.doorSpeed_1L) (L.L.doorAcc_1L) (L.S.Timegap) * - (S.L.doorSpeed_1L)
					{endif}
				{endif}
			{endif}
		{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.1 < || (L.L.doorTarget_1) &&
		{if}
			l0 (L.L.doorMaxSpeed_1L) <
			{if}
				(L.L.door_1L) 0.05 >
				(L.L.door_1L) 1 < &&
				{if}
					(L.L.doorSpeed_1L) (L.L.doorAcc_1L) (L.S.Timegap) * + (S.L.doorSpeed_1L)
				{else}
					(L.L.door_1L) 0.05 <
					{if}
						(L.L.door_1L_timer) (L.S.Timegap) + (S.L.door_1L_timer) (C.L.door_1L_op_otkr) >=
						{if}
							(L.L.doorSpeed_1L) (L.L.doorAcc_1L) (L.S.Timegap) * + (S.L.doorSpeed_1L)
						{endif}
					{endif}
				{endif}
			{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.1 >
	{if}
		0 (S.L.door_1L_timer)
		(T.L.ev_doorhitopen_1)
		1.1 (S.L.door_1L)
		(L.L.doorSpeed_1L) /-/ (L.L.doorRefl_1L) * (S.L.doorSpeed_1L)
	{else}
		(L.L.door_1L) 0 <
		{if}
			(T.L.ev_doorhitclose_1)
			0 (S.L.door_1L) (S.L.door_1L_timer)
			(L.L.doorSpeed_1L) /-/ (L.L.doorRefl_1L) * (S.L.doorSpeed_1L)
		{endif}
	{endif}

{end}

{macro:Door2_Calc}

		(L.L.doorTarget_2)
		{if}
			(L.L.door_2R) (F.L.door_2R_opn_speed) (S.L.doorMaxSpeed_2R_norm)
		{else}
			(L.L.door_2R) (F.L.door_2R_cls_speed) (S.L.doorMaxSpeed_2R_norm)
		{endif}

	(L.L.doorTarget_2) ! (L.L.doorSpeed_2R) s0 abs 0.05 > (L.L.door_2R) 0 > || && 
	{if}
		l0 /-/ (L.L.doorMaxSpeed_2R) <
		{if}
			(L.L.door_2R) 0.95 <
			(L.L.door_2R) 0 > &&
			{if}
				(L.L.doorSpeed_2R) (L.L.doorAcc_2R) (L.S.Timegap) * - (S.L.doorSpeed_2R)
			{else}
				(L.L.door_2R) 0.95 >
				{if}
					(L.L.door_2R_timer) (L.S.Timegap) + (S.L.door_2R_timer) (C.L.door_2R_op_zakr) >=
					{if}
						(L.L.doorSpeed_2R) (L.L.doorAcc_2R) (L.S.Timegap) * - (S.L.doorSpeed_2R)
					{endif}
				{endif}
			{endif}
		{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_2) &&
		{if}
			l0 (L.L.doorMaxSpeed_2R) <
			{if}
				(L.L.door_2R) 0.05 >
				(L.L.door_2R) 1 < &&
				{if}
					(L.L.doorSpeed_2R) (L.L.doorAcc_2R) (L.S.Timegap) * + (S.L.doorSpeed_2R)
				{else}
					(L.L.door_2R) 0.05 <
					{if}
						(L.L.door_2R_timer) (L.S.Timegap) + (S.L.door_2R_timer) (C.L.door_2R_op_otkr) >=
						{if}
							(L.L.doorSpeed_2R) (L.L.doorAcc_2R) (L.S.Timegap) * + (S.L.doorSpeed_2R)
						{endif}
					{endif}
				{endif}
			{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.12 >
	{if}
		0 (S.L.door_2R_timer)
		(T.L.ev_doorhitopen_1)
		1.12 (S.L.door_2R)
		(L.L.doorSpeed_2R) /-/ (L.L.doorRefl_2R) * (S.L.doorSpeed_2R)
	{else}
		(L.L.door_2R) 1 >
		(L.L.door_2R) 1.01 < &&
		(L.L.doorSpeed_2R) 0 < &&
		{if}
			0 (S.L.doorSpeed_2R)
			1 (S.L.door_2R)
		{else}
			(L.L.door_2R) 0 <
			{if}
				(T.L.ev_doorhitclose_1)
				0 (S.L.door_2R) (S.L.door_2R_timer)
				(L.L.doorSpeed_2R) /-/ (L.L.doorRefl_2R) * (S.L.doorSpeed_2R)
			{endif}
		{endif}
	{endif}

		(L.L.doorTarget_2)
		{if}
			(L.L.door_2L) (F.L.door_2L_opn_speed) (S.L.doorMaxSpeed_2L_norm)
		{else}
			(L.L.door_2L) (F.L.door_2L_cls_speed) (S.L.doorMaxSpeed_2L_norm)
		{endif}

	(L.L.doorTarget_2) ! (L.L.doorSpeed_2L) s0 abs 0.05 > (L.L.door_2L) 0 > || && 
	{if}
		l0 /-/ (L.L.doorMaxSpeed_2L) <
		{if}
			(L.L.door_2L) 0.95 <
			(L.L.door_2L) 0 > &&
			{if}
				(L.L.doorSpeed_2L) (L.L.doorAcc_2L) (L.S.Timegap) * - (S.L.doorSpeed_2L)
			{else}
				(L.L.door_2L) 0.95 >
				{if}
					(L.L.door_2L_timer) (L.S.Timegap) + (S.L.door_2L_timer) (C.L.door_2L_op_zakr) >=
					{if}
						(L.L.doorSpeed_2L) (L.L.doorAcc_2L) (L.S.Timegap) * - (S.L.doorSpeed_2L)
					{endif}
				{endif}
			{endif}
		{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.1 < || (L.L.doorTarget_2) &&
		{if}
			l0 (L.L.doorMaxSpeed_2L) <
			{if}
				(L.L.door_2L) 0.05 >
				(L.L.door_2L) 1 < &&
				{if}
					(L.L.doorSpeed_2L) (L.L.doorAcc_2L) (L.S.Timegap) * + (S.L.doorSpeed_2L)
				{else}
					(L.L.door_2L) 0.05 <
					{if}
						(L.L.door_2L_timer) (L.S.Timegap) + (S.L.door_2L_timer) (C.L.door_2L_op_otkr) >=
						{if}
							(L.L.doorSpeed_2L) (L.L.doorAcc_2L) (L.S.Timegap) * + (S.L.doorSpeed_2L)
						{endif}
					{endif}
				{endif}
			{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.1 >
	{if}
		0 (S.L.door_2L_timer)
		(T.L.ev_doorhitopen_1)
		1.1 (S.L.door_2L)
		(L.L.doorSpeed_2L) /-/ (L.L.doorRefl_2L) * (S.L.doorSpeed_2L)
	{else}
		(L.L.door_2L) 0 <
		{if}
			(T.L.ev_doorhitclose_1)
			0 (S.L.door_2L) (S.L.door_2L_timer)
			(L.L.doorSpeed_2L) /-/ (L.L.doorRefl_2L) * (S.L.doorSpeed_2L)
		{endif}
	{endif}
{end}

{macro:trg_bus_door_1}
	(L.L.doorTarget_1)
	{if}
		(T.L.ev_doortriggerclose_1)
	{else}
		(T.L.ev_doortriggeropen_1)
	{endif}
	(L.L.bremse_p_Tank04) 100000 - 0.98 * 100000 + (S.L.bremse_p_Tank04)
{end}


{macro:trg_bus_door_2}

	(L.L.doorTarget_2)
	{if}
		(T.L.ev_doortriggerclose_1)
	{else}
		(T.L.ev_doortriggeropen_1)
	{endif}
	(L.L.bremse_p_Tank04) 100000 - 0.98 * 100000 + (S.L.bremse_p_Tank04)
{end}
