'##############
'Collision Script
'##############

'Controls all functions dealing with collisions

'(c) 30.10.2012 Marcel Kuhnt

'Script Version: 1.0
'Omsi release: 1.0

'Needs:
'- elec
'- engine
'- lights
'- antrieb


'Revision History:
'- Marcel Kuhnt		09.06.2009	File created, added electricity, engine & gearbox failure
'- Marcel Kuhnt		04.07.2011	Added Malfunction Repair Time Calculation
'- Marcel Kuhnt		30.10.2012	Added Malfunction Live Time Subtraction Call, new calculation algorithm

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

{macro:Collision_Malfunction_Reset}
	0
	(S.L.collision_energy)

	(S.L.elec_failure_general)

	(S.L.collision_energy_eng)
	(S.L.engine_failure_general)

	(M.L.Collision_Init)
{end}

{macro:Collision_Malfunction_TimeCalc}

'Berechnung der Zeit, die benötigt wird, um die Schäden zu reparieren:

	s0

	(L.L.elec_failure_general)     0 = ! 20 * l0 + s0
	(L.L.engine_failure_general)   0 = ! 75 * l0 + s0

	l0
{end}

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

{macro:Collision_Init}
	(C.L.collision_energy_elec_threshold_max) (C.L.collision_energy_elec_threshold_min) -
	random (C.L.collision_energy_elec_threshold_min) + (S.L.collision_energy_elec_threshold)

	(C.L.collision_energy_eng_threshold_max) (C.L.collision_energy_eng_threshold_min) -
	random (C.L.collision_energy_eng_threshold_min) + (S.L.collision_energy_eng_threshold)
{end}

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

'malfunction minute trigger:

{macro:Collision_Frame}
		(L.L.malfunction_minute_trigger_lastsecond) (L.S.Timegap) - (S.L.malfunction_minute_trigger_lastsecond)
		0 <
		{if}
	
			6 (S.L.malfunction_minute_trigger_lastsecond)
		{endif}

'		(L.L.malfunction_minute_trigger_lastsecond) 3.5 >
'		(L.S.Time) 6 % s0 2.5 < &&
'		{if}
'		{endif}
'		l0 (S.L.malfunction_minute_trigger_lastsecond)
	{endif}
{end}


{macro:Collision_Trigger}

'-------------------------------
'General Failure:

	(L.L.collision_energy) (L.S.coll_energy) + (S.L.collision_energy)

' - Elect.:
	(L.L.collision_energy_elec_threshold) >
	{if}
		1 (S.L.elec_failure_general)
	{endif}

'-------------------------------
'Engine Failure:

'	only if collision point is below z=1.1m and behind y=-4.7m!

	(L.S.coll_pos_y) -4.70 <
	(L.S.coll_pos_z) 1.10 < &&
	{if}
		(L.L.collision_energy_eng) (L.S.coll_energy) + (S.L.collision_energy_eng)
		(L.L.collision_energy_eng_threshold) s0



		l0 >
		{if}
			1 (S.L.engine_failure_general)
		{endif}
	{endif}

{end}

