abstract class RestrictedMovementAreaCondition extends AIbehaviorconditionScript
{

	protected function GetRestrictMovementAreaManager( context : ScriptExecutionContext ) : RestrictMovementAreaManager
	{
		return GameInstance.GetRestrictMovementAreaManager( GetGame( context ) );
	}

	protected function IsOwnerConnectedToRestirctMovementArea( areaManager : RestrictMovementAreaManager, owner : GameObject ) : Bool
	{
		if( !( areaManager ) )
		{
			return false;
		}
		if( !( areaManager.HasAssignedRestrictMovementArea( owner.GetEntityID() ) ) )
		{
			return false;
		}
		return true;
	}

	protected function IsOwnerInRestirctMovementArea( areaManager : RestrictMovementAreaManager, owner : GameObject ) : Bool
	{
		if( !( areaManager ) || !( owner ) )
		{
			return false;
		}
		return areaManager.IsPointInRestrictMovementArea( owner.GetEntityID(), owner.GetWorldPosition() );
	}

}

class AIReturnToRestrictMovementAreaCondition extends RestrictedMovementAreaCondition
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		SetUpdateInterval( context, RandomizeOffsetForUpdateInterval( 0.5 ) );
	}

	private override final function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		var areaManager : RestrictMovementAreaManager;
		var point : Vector4;
		areaManager = GetRestrictMovementAreaManager( context );
		if( !( areaManager ) )
		{
			return true;
		}
		if( !( IsOwnerConnectedToRestirctMovementArea( areaManager, ScriptExecutionContext.GetOwner( context ) ) ) )
		{
			return false;
		}
		if( areaManager.IsPointInRestrictMovementArea( ScriptExecutionContext.GetOwner( context ).GetEntityID(), ScriptExecutionContext.GetOwner( context ).GetWorldPosition() ) )
		{
			return false;
		}
		if( areaManager.FindPointInRestrictMovementArea( GetPuppet( context ).GetEntityID(), GetPuppet( context ).GetWorldPosition(), point ) )
		{
			if( !( Vector4.IsZero( point ) ) )
			{
				ScriptExecutionContext.SetArgumentVector( context, 'MovementTarget', point );
				return true;
			}
		}
		return false;
	}

}

class IsStimSourceInRestrictMovementArea extends RestrictedMovementAreaCondition
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		SetUpdateInterval( context, RandomizeOffsetForUpdateInterval( 0.5 ) );
	}

	private override final function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		var areaManager : RestrictMovementAreaManager;
		var stimSource : Vector4;
		areaManager = GetRestrictMovementAreaManager( context );
		if( !( areaManager ) )
		{
			return true;
		}
		if( !( IsOwnerConnectedToRestirctMovementArea( areaManager, ScriptExecutionContext.GetOwner( context ) ) ) )
		{
			return true;
		}
		stimSource = ScriptExecutionContext.GetArgumentVector( context, 'StimSource' );
		if( areaManager.IsPointInRestrictMovementArea( ScriptExecutionContext.GetOwner( context ).GetEntityID(), stimSource ) )
		{
			return true;
		}
		return false;
	}

}

class AIReturnToRestrictMovementArea extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		SetUpdateInterval( context, RandomizeOffsetForUpdateInterval( 0.5 ) );
	}

	protected override function Update( context : ScriptExecutionContext ) : AIbehaviorUpdateOutcome
	{
		var gam : RestrictMovementAreaManager;
		var point : Vector4;
		gam = GameInstance.GetRestrictMovementAreaManager( GetGame( context ) );
		if( !( gam ) )
		{
			return AIbehaviorUpdateOutcome.FAILURE;
		}
		if( !( gam.HasAssignedRestrictMovementArea( GetPuppet( context ).GetEntityID() ) ) )
		{
			return AIbehaviorUpdateOutcome.FAILURE;
		}
		if( gam.FindPointInRestrictMovementArea( GetPuppet( context ).GetEntityID(), GetPuppet( context ).GetWorldPosition(), point ) )
		{
			if( !( Vector4.IsZero( point ) ) )
			{
				ScriptExecutionContext.SetArgumentVector( context, 'MovementTarget', point );
			}
		}
		return AIbehaviorUpdateOutcome.IN_PROGRESS;
	}

}

