'##############
'Heizungs-Script
'##############

'Simuliert Wagenheizung/Klima

'(c) 13.11.2017 Christian Rolle

'Script Version: 1.0
'Omsi release: 2.0

'Needs:
'elec
'doors

'Revision History:
'- Christian Rolle	13.11.2017	created from scratch
'------------------------------------------------------------------------------------------

{trigger:cp_heizregler_verteilung_drag}

	(L.S.mouse_X) 150 / (L.L.cockpit_heizregler_verteilung) + 0 max 1 min (S.L.cockpit_heizregler_verteilung)

{end}

{trigger:cp_heizregler_temp_drag}

	(L.S.mouse_X) 150 / (L.L.cockpit_heizregler_temp) + 0 max 1 min (S.L.cockpit_heizregler_temp)

{end}

{trigger:cp_heizregler_geblaese_drag}

	(L.S.mouse_X) 150 / (L.L.cockpit_heizregler_geblaese) + 0 max 1 min (S.L.cockpit_heizregler_geblaese)

{end}

{trigger:taster_fahrerklima}
	
	1 (S.L.taster_fahrerklima_anim)

	(L.L.cp_taster_fahrerklima) ! (S.L.cp_taster_fahrerklima) s0
	1 =
	{if}
		(T.L.ev_VDV_toggle_on)
	{else}
		(T.L.ev_VDV_toggle_off)
	{endif}

{end}

{trigger:taster_fahrerklima_off}

	0 (S.L.taster_fahrerklima_anim)

{end}
{trigger:taster_frischumluft}
	
	1 (S.L.taster_frischumluft_anim)

	(L.L.cp_taster_frischumluft) ! (S.L.cp_taster_frischumluft) s0
	1 =
	{if}
		(T.L.ev_VDV_toggle_on)
	{else}
		(T.L.ev_VDV_toggle_off)
	{endif}
{end}

{trigger:taster_frischumluft_off}

	0 (S.L.taster_frischumluft_anim)

{end}

{trigger:taster_klima}

	1 (S.L.taster_klima_anim)

	(L.L.cp_taster_klima) ! (S.L.cp_taster_klima) s0
	1 =
	{if}
		(T.L.ev_VDV_toggle_on)
	{else}
		(T.L.ev_VDV_toggle_off)
	{endif}
{end}

{trigger:taster_klima_off}

	0 (S.L.taster_klima_anim)
	
{end}

{trigger:taster_zusatzheizung}
	
	1 (S.L.taster_zusatzheizung_anim)

	(L.L.cp_taster_zusatzheizung) ! (S.L.cp_taster_zusatzheizung) s0
	1 =
	{if}
		(T.L.ev_VDV_toggle_on)
	{else}
		(T.L.ev_VDV_toggle_off)
	{endif}
{end}

{trigger:taster_zusatzheizung_off}

	0 (S.L.taster_zusatzheizung_anim)

{end}

{trigger:taster_heat_or_frost}

	1 (S.L.taster_heat_or_frost_anim)

	(L.L.cp_taster_heat_or_frost) ! (S.L.cp_taster_heat_or_frost) s0
	1 =
	{if}
		(T.L.ev_VDV_toggle_on)
	{else}
		(T.L.ev_VDV_toggle_off)
	{endif}
	l0
	{if}
		(L.L.Cabinair_Temp) 20 <
		{if}
			1 (S.L.klima_enabled)
		{endif}
		(L.L.Cabinair_Temp) 22 >
		{if}
			1 (S.L.raumheiz_enabled)
		{endif}
	{else}
		0 (S.L.klima_enabled)
		0 (S.L.raumheiz_enabled)
	{endif}
{end}

{trigger:taster_heat_or_frost_off}

	0 (S.L.taster_heat_or_frost_anim)
	
{end}

{trigger:cp_schalter_heiz_up_toggle}
	(L.L.cp_heiz_sw) s1
	{if}
		0 (S.L.cp_heiz_sw)
		0 (S.L.heiz_lm)
		0 (S.L.Podestluefter_stufe)
	{else}
		1 (S.L.cp_heiz_sw) (S.L.heiz_lm)
		1 (S.L.Podestluefter_stufe)
	{endif}
	l1 1 =
	{if}
		(T.L.ev_VDV_toggle_on)
	{else}
		(T.L.ev_VDV_toggle_off)
	{endif}
{end}

{trigger:cp_schalter_heiz_down_toggle}
	(L.L.cp_heiz_sw) 0 =
	{if}
		-1 (S.L.cp_heiz_sw) 
		1 (S.L.heiz_lm)
		2 (S.L.Podestluefter_stufe)
	{else}
		0 (S.L.cp_heiz_sw)
		0 (S.L.heiz_lm)
		0 (S.L.Podestluefter_stufe)
	{endif}
	l1 1 =
	{if}
		(T.L.ev_VDV_toggle_on)
	{else}
		(T.L.ev_VDV_toggle_off)
	{endif}
{end}



'----------------------
'	Init
'----------------------
{macro:heizung_init}
	3 random (L.S.Weather_Temperature) + (S.L.Cabinair_Temp)
	3 random (L.S.Weather_AbsHum) + (S.L.Cabinair_absHum)
{end}


{macro:heizung_frame}

	(L.L.elec_busbar_main)
	{if}
		(L.L.heizung_lock) !
		{if}
			0 (M.V.GetDepotStringGlobal) "HB_Bremen_2018" $=
			0 (M.V.GetDepotStringGlobal) "HB_Bremen_2016" $= ||
			0 (M.V.GetDepotStringGlobal) "HB_Bremen_2010" $= ||
			{if}
				1 (S.L.cp_taster_klima) (S.L.heizung_lock)
			{endif}
		{endif}
'Leuchtmelder:
		(L.L.cp_taster_heat_or_frost) (S.L.cp_taster_heat_or_frost_led)
		(L.L.cp_taster_zusatzheizung) (S.L.cp_taster_zusatzheizung_led)
		(L.L.cp_taster_klima) (S.L.cp_taster_klima_led)
		(L.L.cp_taster_frischumluft) (S.L.cp_taster_frischumluft_led)
		(L.L.cp_taster_fahrerklima) (S.L.cp_taster_fahrerklima_led)
	
'Gebläse Fahrer:
		(L.L.engine_n) 400 >
		{if}
			(L.L.cockpit_heizregler_geblaese) s1
		{else}
			0 s1
		{endif}
		l1 100 * (L.L.cockpit_geblaese_RPM) > 
		{if}
			1.5 s0
		{else}
			0.5 s0
		{endif}
		l1 100 * 
		(L.L.cockpit_geblaese_RPM)
		- s0 * (L.S.Timegap) *
		(L.L.cockpit_geblaese_RPM) + (S.L.cockpit_geblaese_RPM)
'Podestheizung Fahrer:
		(L.L.engine_n) 400 >
		{if}
			(L.L.Podestluefter_stufe) 2 / s1
		{else}
			0 s1
		{endif}
		l1 100 * (L.L.Podestluefter_RPM) > 
		{if}
			1.5 s0
		{else}
			0.5 s0
		{endif}
		l1 100 * 
		(L.L.Podestluefter_RPM)
		- s0 * (L.S.Timegap) *
		(L.L.Podestluefter_RPM) + (S.L.Podestluefter_RPM)
'Raumheizgeräte:
		(L.L.engine_n) 400 >
		{if}
			(L.L.raumheiz_enabled) s1			
		{else}
			0 s1
		{endif}
		l1 100 * (L.L.geblaese_RPM) > 
		{if}
			1.5 s0
		{else}
			0.5 s0
		{endif}
		l1 100 * 
		(L.L.geblaese_RPM)
		- s0 * (L.S.Timegap) *
		(L.L.geblaese_RPM) + (S.L.geblaese_RPM)
'Klimaanlage:
		(L.L.engine_n) 400 >
		{if}
			(L.L.klima_enabled) s1
		{else}
			0 s1
		{endif}
		l1 100 * (L.L.cp_Klima_RPM) > 
		{if}
			1.5 s0
		{else}
			0.5 s0
		{endif}
		l1 100 * 
		(L.L.cp_Klima_RPM)
		- s0 * (L.S.Timegap) *
		(L.L.cp_Klima_RPM) + (S.L.cp_Klima_RPM)

'Heizen oder Kühlen:

		(L.L.cp_taster_klima)
		{if}
		
			(L.S.Weather_Temperature) -20 >
			(L.S.Weather_Temperature) 2 < &&
			{if}
				(L.L.Cabinair_Temp) 14 <=
				{if}
					1 (S.L.raumheiz_enabled)
					0 (S.L.klima_enabled)
				{else}
					0 (S.L.raumheiz_enabled)
					1 (S.L.klima_enabled)
				{endif}
			{endif}
			
			(L.S.Weather_Temperature) 2 >=
			(L.S.Weather_Temperature) 15 < &&
			{if}
				(L.L.Cabinair_Temp) 19 <=
				{if}
					1 (S.L.raumheiz_enabled)
					0 (S.L.klima_enabled)
				{else}
					0 (S.L.raumheiz_enabled)
					1 (S.L.klima_enabled)
				{endif}
			{endif}
			
			(L.S.Weather_Temperature) 15 >=
			{if}			
				(L.L.Cabinair_Temp) 16 <
				{if}
					1 (S.L.raumheiz_enabled)
				{endif}
				(L.L.Cabinair_Temp) 20 >
				{if}
					0 (S.L.raumheiz_enabled)
				{endif}
				(L.L.Cabinair_Temp) 24 >
				{if}
					1 (S.L.klima_enabled)
				{endif}
				(L.L.Cabinair_Temp) 21 <
				{if}
					0 (S.L.klima_enabled)
				{endif}
			{endif}
		{else}
			0 (S.L.klima_enabled)
			0 (S.L.raumheiz_enabled)
		{endif}
	{else}
		0 (S.L.cp_taster_heat_or_frost_led) (S.L.cp_taster_zusatzheizung_led) (S.L.cp_taster_klima_led) (S.L.cp_taster_frischumluft_led) (S.L.cp_taster_fahrerklima_led)		
	{endif}
'Berechung der Temperatur:
	
	(L.S.Weather_Temperature) (L.L.Cabinair_Temp) <
	{if}
		(L.L.Cabinair_Temp) s0
		(L.L.door_0) trunc (L.L.door_1) trunc +
		(L.L.door_2) trunc (L.L.door_3) trunc + +
		(L.L.door_3) trunc (L.L.door_4) trunc + + 5000 / (L.S.Timegap) * 100 * s1
		(L.L.cp_klappfenster_1) trunc (L.L.cp_klappfenster_2) trunc +
		(L.L.cp_klappfenster_2) trunc (L.L.cp_klappfenster_3) trunc + + 8000 / (L.S.Timegap) * 100 * s2
		(L.L.cp_fahrerfenster_pos) trunc 8000 / (L.S.Timegap) * 100 * s3
		l0 l1 - l2 - l3 - (S.L.Cabinair_Temp)
	{else}
		(L.L.Cabinair_Temp) s0
		(L.L.door_0) trunc (L.L.door_1) trunc +
		(L.L.door_2) trunc (L.L.door_3) trunc + +
		(L.L.door_3) trunc (L.L.door_4) trunc + + 5000 / (L.S.Timegap) * 100 * s1
		(L.L.cp_klappfenster_1) trunc (L.L.cp_klappfenster_2) trunc +
		(L.L.cp_klappfenster_2) trunc (L.L.cp_klappfenster_3) trunc + + 8000 / (L.S.Timegap) * 100 * s2
		(L.L.cp_fahrerfenster_pos) trunc 8000 / (L.S.Timegap) * 100 * s3
		l0 l1 + l2 + l3 + (S.L.Cabinair_Temp)
	{endif}
	(L.L.Cabinair_Temp) s0
	(L.L.cockpit_heizregler_geblaese) 10000 / (L.S.Timegap) * 100 * (L.L.cockpit_heizregler_temp) 0.5 - * s1
	(L.L.Podestluefter_stufe) 10000 / (L.S.Timegap) * 100 * s2
	(L.L.cp_taster_frischumluft) !
	{if}
		(L.L.cp_taster_zusatzheizung) !
		{if}
			(L.L.raumheiz_enabled) 5000 / (L.S.Timegap) * 100 * s3
		{else}
			(L.L.raumheiz_enabled) 4000 / (L.S.Timegap) * 100 * s3
		{endif}
	{else}
		(L.L.cp_taster_zusatzheizung) !
		{if}
			(L.L.raumheiz_enabled) 3000 / (L.S.Timegap) * 100 * s3
		{else}
			(L.L.raumheiz_enabled) 2000 / (L.S.Timegap) * 100 * s3
		{endif}
	{endif}
	(L.L.klima_enabled) 4000 / (L.S.Timegap) * 100 * s4
	(L.S.Weather_Temperature) (L.L.Cabinair_Temp) >
	{if}
		(L.S.Weather_Temperature) (L.L.Cabinair_Temp) - 500000 / (L.S.Timegap) * 100 * s5
	{else}
		(L.S.Weather_Temperature) (L.L.Cabinair_Temp) - 500000 / (L.S.Timegap) * 100 * s5
	{endif}
	 l0 l1 + l2 + l3 + l4 - l5 + (S.L.Cabinair_Temp)
{end}

