class MotorcycleComponent extends VehicleComponent
{

	protected event OnVehicleParkedEvent( evt : VehicleParkedEvent )
	{
		if( evt.park )
		{
			ParkBike();
		}
		else
		{
			UnParkBike();
		}
	}

	protected event OnMountingEvent( evt : MountingEvent )
	{
		super.OnMountingEvent( evt );
		WakeUpBike();
	}

	private function WakeUpBike()
	{
		GetVehicle().PhysicsWakeUp();
		UnParkBike();
		PickUpBike();
	}

	protected event OnUnmountingEvent( evt : UnmountingEvent )
	{
		super.OnUnmountingEvent( evt );
		StopBike();
	}

	private function StopBike()
	{
		var knockOverBike : KnockOverBikeEvent;
		var currentSpeed : Float;
		currentSpeed = GetVehicle().GetCurrentSpeed();
		if( currentSpeed >= 3.0 )
		{
			knockOverBike = new KnockOverBikeEvent;
			GetVehicle().QueueEvent( knockOverBike );
		}
		else
		{
			ParkBike();
		}
	}

	protected event OnRemoteControlEvent( evt : VehicleRemoteControlEvent )
	{
		var playerPuppet : PlayerPuppet;
		super.OnRemoteControlEvent( evt );
		if( evt.remoteControl )
		{
			WakeUpBike();
			playerPuppet = ( ( PlayerPuppet )( GameInstance.GetPlayerSystem( GetVehicle().GetGame() ).GetLocalPlayerMainGameObject() ) );
			if( playerPuppet.CheckIsStandingOnVehicle( GetVehicle().GetEntityID() ) )
			{
				GetVehicle().SetVehicleRemoteControlled( false, false, true );
			}
		}
		else
		{
			StopBike();
		}
	}

	protected event OnToggleBrokenTireEvent( evt : VehicleToggleBrokenTireEvent )
	{
		var currentSpeed : Float;
		var recordID : TweakDBID;
		var vehicleRecord : Vehicle_Record;
		var vehicleDataPackage : weak< VehicleDataPackage_Record >;
		super.OnToggleBrokenTireEvent( evt );
		recordID = GetVehicle().GetRecordID();
		vehicleRecord = TweakDBInterface.GetVehicleRecord( recordID );
		vehicleDataPackage = vehicleRecord.VehDataPackage();
		currentSpeed = Vector4.Length( GetVehicle().GetLinearVelocity() );
		if( ( ( evt.tireIndex == 0 ) && evt.toggle == true ) && ( currentSpeed > 5.0 ) )
		{
			HandleBikeCollisionReaction( MinF( currentSpeed, vehicleDataPackage.KnockOffForce() ) + 1.0, Vector4.Normalize( GetVehicle().GetLinearVelocity() ) );
		}
	}

	private function ParkBike()
	{
		var currentTiltAngle : Float;
		var desiredTiltAngle : Float;
		var record : weak< Vehicle_Record >;
		var vehicleDataPackage : weak< VehicleDataPackage_Record >;
		currentTiltAngle = ( ( BikeObject )( GetVehicle() ) ).GetCustomTargetTilt();
		record = GetVehicle().GetRecord();
		vehicleDataPackage = record.VehDataPackage();
		desiredTiltAngle = vehicleDataPackage.ParkingAngle();
		if( !( ( ( BikeObject )( GetVehicle() ) ).IsTiltControlEnabled() ) )
		{
			return;
		}
		if( ( currentTiltAngle == 0.0 ) && !( VehicleComponent.IsVehicleOccupied( GetVehicle().GetGame(), GetVehicle() ) ) )
		{
			( ( BikeObject )( GetVehicle() ) ).SetCustomTargetTilt( desiredTiltAngle );
			AnimationControllerComponent.PushEvent( GetVehicle(), 'toPark' );
			AnimationControllerComponent.PushEvent( GetVehicle(), 'readyModeEnd' );
			GetVehicle().PhysicsWakeUp();
		}
	}

	private function UnParkBike()
	{
		( ( BikeObject )( GetVehicle() ) ).SetCustomTargetTilt( 0.0 );
		AnimationControllerComponent.PushEvent( GetVehicle(), 'unPark' );
	}

	private function PickUpBike()
	{
		if( !( ( ( BikeObject )( GetVehicle() ) ).IsTiltControlEnabled() ) )
		{
			( ( BikeObject )( GetVehicle() ) ).EnableTiltControl( true );
		}
	}

	protected event OnKnockOverBikeEvent( evt : KnockOverBikeEvent )
	{
		var bikeImpulseEvent : PhysicalImpulseEvent;
		var tempVec4 : Vector4;
		if( evt.forceKnockdown )
		{
			if( ( ( BikeObject )( GetVehicle() ) ).IsTiltControlEnabled() )
			{
				UnParkBike();
				( ( BikeObject )( GetVehicle() ) ).EnableTiltControl( false );
			}
		}
		else if( !( VehicleComponent.IsVehicleOccupied( GetVehicle().GetGame(), GetVehicle() ) ) )
		{
			if( ( ( BikeObject )( GetVehicle() ) ).IsTiltControlEnabled() )
			{
				UnParkBike();
				( ( BikeObject )( GetVehicle() ) ).EnableTiltControl( false );
			}
		}
		if( evt.applyDirectionalForce )
		{
			bikeImpulseEvent = new PhysicalImpulseEvent;
			bikeImpulseEvent.radius = 1.0;
			tempVec4 = GetVehicle().GetWorldPosition();
			bikeImpulseEvent.worldPosition.X = tempVec4.X;
			bikeImpulseEvent.worldPosition.Y = tempVec4.Y;
			bikeImpulseEvent.worldPosition.Z = tempVec4.Z + 0.5;
			tempVec4 = WorldTransform.GetRight( GetVehicle().GetWorldTransform() );
			tempVec4 *= ( GetVehicle().GetTotalMass() * 3.79999995 );
			bikeImpulseEvent.worldImpulse = Vector4.Vector4To3( tempVec4 );
			GetVehicle().QueueEvent( bikeImpulseEvent );
		}
	}

}

class KnockOverBikeEvent extends Event
{
	var forceKnockdown : Bool;
	var applyDirectionalForce : Bool;
}

