enum MountType
{
	Hijack = 0,
	Regular = 1,
}

import class gamevehicleVehicleMountableComponent extends MountableComponent
{

	protected event OnInteractionChoice( choiceEvent : InteractionChoiceEvent )
	{
		var record : weak< InteractionMountBase_Record >;
		var activator : weak< GameObject >;
		var slotName : CName;
		activator = choiceEvent.activator;
		if( super.IsInteractionAcceptable( choiceEvent ) && DoStatusEffectsAllowMounting( activator ) )
		{
			record = ( ( weak< weak< InteractionMountBase_Record > > )( InteractionChoiceMetaData.GetTweakData( choiceEvent.choice.choiceMetaData ) ) );
			slotName = record.VehicleMountSlot();
			MountEntityToSlot( choiceEvent.hotspot.GetEntityID(), activator.GetEntityID(), slotName, MountType.Regular );
		}
	}

	protected event OnActionDemolition( evt : ActionDemolition )
	{
		var executor : weak< GameObject >;
		executor = evt.GetExecutor();
		if( DoStatusEffectsAllowMounting( executor ) )
		{
			MountEntityToSlot( evt.GetRequesterID(), executor.GetEntityID(), evt.prop.name, MountType.Hijack );
		}
	}

	protected event OnActionEngineering( evt : ActionEngineering )
	{
		var executor : weak< GameObject >;
		executor = evt.GetExecutor();
		if( DoStatusEffectsAllowMounting( executor ) )
		{
			MountEntityToSlot( evt.GetRequesterID(), executor.GetEntityID(), evt.prop.name, MountType.Hijack );
		}
	}

	private function DoStatusEffectsAllowMounting( executor : weak< GameObject > ) : Bool
	{
		if( StatusEffectSystem.ObjectHasStatusEffect( executor, T"BaseStatusEffect.VehicleKnockdown" ) || StatusEffectSystem.ObjectHasStatusEffect( executor, T"BaseStatusEffect.BikeKnockdown" ) )
		{
			return false;
		}
		return true;
	}

	protected function MountEntityToSlot( parentID : EntityID, childId : EntityID, slot : CName, mountType : MountType )
	{
		var mountingRequest : MountingRequest;
		var lowLevelMountingInfo : MountingInfo;
		var mountData : MountEventData;
		var mountOptions : MountEventOptions;
		var npcMountInfo : MountingInfo;
		var npcMountInfos : array< MountingInfo >;
		var attitude : EAIAttitude;
		var i : Int32;
		var scriptedPuppet : weak< GameObject >;
		var isNPCAlive : Bool;
		var isNPCInactive : Bool;
		var vehObject : weak< VehicleObject >;
		var isOccupiedByNonFriendly : Bool;
		mountingRequest = new MountingRequest;
		mountData = new MountEventData;
		mountOptions = new MountEventOptions;
		lowLevelMountingInfo.parentId = parentID;
		lowLevelMountingInfo.childId = childId;
		lowLevelMountingInfo.slotId.id = slot;
		npcMountInfo = GameInstance.GetMountingFacility( ( ( weak< weak< GameObject > > )( GetEntity() ) ).GetGame() ).GetMountingInfoSingleWithIds( , lowLevelMountingInfo.parentId, lowLevelMountingInfo.slotId );
		npcMountInfos = GameInstance.GetMountingFacility( ( ( weak< weak< GameObject > > )( GetEntity() ) ).GetGame() ).GetMountingInfoMultipleWithIds( , lowLevelMountingInfo.parentId );
		if( EntityID.IsDefined( npcMountInfo.childId ) )
		{
			scriptedPuppet = ( ( weak< weak< GameObject > > )( GameInstance.FindEntityByID( ( ( weak< weak< GameObject > > )( GetEntity() ) ).GetGame(), npcMountInfo.childId ) ) );
			isNPCAlive = ScriptedPuppet.IsActive( scriptedPuppet );
			isNPCInactive = !( isNPCAlive );
		}
		if( mountType == MountType.Hijack || isNPCInactive )
		{
			vehObject = ( ( VehicleObject )( GetEntity() ) );
			vehObject.PreHijackPrepareDriverSlot();
		}
		for( i = 0; i < npcMountInfos.Size(); i += 1 )
		{
			if( EntityID.IsDefined( npcMountInfos[ i ].childId ) )
			{
				VehicleComponent.GetAttitudeOfPassenger( ( ( weak< weak< GameObject > > )( GetEntity() ) ).GetGame(), npcMountInfos[ i ].parentId, npcMountInfos[ i ].slotId, attitude );
				if( attitude != EAIAttitude.AIA_Friendly )
				{
					isOccupiedByNonFriendly = true;
				}
			}
		}
		mountingRequest.lowLevelMountingInfo = lowLevelMountingInfo;
		mountingRequest.preservePositionAfterMounting = true;
		mountingRequest.mountData = mountData;
		mountOptions.entityID = npcMountInfo.childId;
		mountOptions.alive = isNPCAlive;
		mountOptions.occupiedByNonFriendly = isOccupiedByNonFriendly;
		mountingRequest.mountData.mountEventOptions = mountOptions;
		GameInstance.GetMountingFacility( ( ( weak< weak< GameObject > > )( GetEntity() ) ).GetGame() ).Mount( mountingRequest );
	}

}

