class AIAlertedStateDelegate extends ScriptBehaviorDelegate
{
	var m_attackInstigatorPosition : Vector4;

	public function DoSetExplosionInstigatorPositionAsStimSource( context : ScriptExecutionContext ) : Bool
	{
		var stimuliCache : array< StimEventTaskData >;
		var investigateData : stimInvestigateData;
		if( !( Vector4.IsZero( m_attackInstigatorPosition ) ) )
		{
			ScriptExecutionContext.SetArgumentVector( context, 'StimSource', m_attackInstigatorPosition );
		}
		else
		{
			stimuliCache = ( ( ScriptedPuppet )( ScriptExecutionContext.GetOwner( context ) ) ).GetStimReactionComponent().GetStimuliCache();
			if( stimuliCache.Size() != 0 )
			{
				investigateData = stimuliCache[ stimuliCache.Size() - 1 ].cachedEvt.stimInvestigateData;
				if( stimuliCache[ ( stimuliCache.Size() - 1 ) ].cachedEvt.GetStimType() == gamedataStimType.Explosion && investigateData.revealsInstigatorPosition )
				{
					m_attackInstigatorPosition = investigateData.attackInstigatorPosition;
					ScriptExecutionContext.SetArgumentVector( context, 'StimSource', investigateData.attackInstigatorPosition );
				}
			}
		}
		return true;
	}

	public function DoSetRandomAimPointLeft( context : ScriptExecutionContext ) : Bool
	{
		var aimPoint : Vector4;
		aimPoint = GetPositionAroundInstigator( context, RandRangeF( 2.79999995, 4.5999999 ), 0.0, RandRangeF( 1.79999995, 3.5999999 ) );
		ScriptExecutionContext.SetArgumentVector( context, 'StimSource', aimPoint );
		return true;
	}

	public function DoSetRandomAimPointRight( context : ScriptExecutionContext ) : Bool
	{
		var aimPoint : Vector4;
		aimPoint = GetPositionAroundInstigator( context, RandRangeF( -2.79999995, -4.5999999 ), 0.0, RandRangeF( 1.79999995, 3.4000001 ) );
		ScriptExecutionContext.SetArgumentVector( context, 'StimSource', aimPoint );
		return true;
	}

	public function DoLowerWeapon( context : ScriptExecutionContext ) : Bool
	{
		var animFeature : AnimFeature_AIAction;
		animFeature = new AnimFeature_AIAction;
		animFeature.state = 3;
		AnimationControllerComponent.ApplyFeatureToReplicate( ScriptExecutionContext.GetOwner( context ), 'NonCombatAim', animFeature );
		return true;
	}

	private function GetPositionAroundInstigator( context : ScriptExecutionContext, xOffset : Float, yOffset : Float, zOffset : Float ) : Vector4
	{
		var ownerPuppet : ScriptedPuppet;
		var instigatorSimulatedRotation : Quaternion;
		var aimOffset : Vector4;
		var worldAimOffset : Vector4;
		var worldPosition : Vector4;
		ownerPuppet = ( ( ScriptedPuppet )( ScriptExecutionContext.GetOwner( context ) ) );
		instigatorSimulatedRotation = Quaternion.BuildFromDirectionVector( ownerPuppet.GetWorldPosition() - m_attackInstigatorPosition, ownerPuppet.GetWorldUp() );
		aimOffset = Vector4( xOffset, yOffset, zOffset, 1.0 );
		worldAimOffset = Vector4.RotByAngleXY( aimOffset, Vector4.Heading( Quaternion.GetForward( instigatorSimulatedRotation ) ) );
		worldPosition = m_attackInstigatorPosition + worldAimOffset;
		return worldPosition;
	}

}

class AlertedAnimWrapper extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		AnimationControllerComponent.SetAnimWrapperWeightOnOwnerAndItems( ScriptExecutionContext.GetOwner( context ), 'alertedLocomotion', 1.0 );
	}

}

