/* Raptor Attack
//
// This machine should be used through the normal call mechanism
//
*/
machine RaptorAttack
{
	default state AttackStart
	{
		transition IsTargetDead()
		{
			goto AttackExitEnd
		}
		transition CanAttackTarget() == false
		{
			action ClearTarget()
			goto AttackExitEnd
		}

		;//action SetAesPosInterp(false)
		action LockMachine(false)
		action SetSpeedModifier(1.0)
		action SetRunMode(true)
		action StopLook()
		/*transition InTargetProximityRadius(0.6, true)
		{
			direct goto AttackSetup
		}*/
		transition
		{
			goto SeekFood
		}
	}

	state SeekFood
	{
		action AddRandomAnimation("call", "01_lp", 4.0, 10.0)
		transition
		{
			goto PreSeekLoop
		}
	}
	state PreSeekLoop
	{
		transition HasTarget() == false
		{
			goto AttackExitEnd
		}
		transition IsTargetDead()
		{
			goto AttackExitEnd
		}
		transition IsFacingTargetUnit()
		{
      			action SetRandomTimerBetween(0, 1.5, 1.5)
			goto SeekLoop
		}
		action FaceTarget()
	}
	state SeekLoop
	{
		/*
		Param0:		float	distance offset
		Param1:		float	rotation offset
		Param2:		bool	True if we should face target.
		Param3:		bool	True if we want a random rotation
		Param4:		bool	True if rotation is offset from forward
		*/
		transition HasTarget() == false
		{
			goto AttackExitEnd
		}
		transition IsTargetDead()
		{
			goto AttackExitEnd
		}
		transition InTargetProximityRadius(0.6, true)
		{
			direct goto SeekFacingCheck
		}
		transition SeekTargetOffset(1.0, 0.0, false, false, true) == false
		{
			goto CornerSeek
		}
		transition IsTimerUp(0)
		{
			goto TargetFaceSeek
		}
	}

	state TargetFaceSeek
	{
		transition IsFacingTargetUnit()
		{
			action SetRandomTimerBetween(0, 1.5, 1.5)
			goto SeekLoop
		}
		transition IsTargetDead()
		{
			goto AttackExitEnd
		}
		transition
		{
			action SetRandomTimerBetween(0, 1.0, 1.0)
			action FaceTarget()
			goto TargetFaceSeekCheck
		}
	}
	state TargetFaceSeekCheck
	{
		transition IsFacingTargetUnit()
		{
			action ClearTarget()
			goto ReAcquireTarget
		}
		transition IsTargetDead()
		{
			goto AttackExitEnd
		}
		transition IsTimerUp(0)
		{
			action ClearTarget()
			goto ReAcquireTarget
		}
	}
	state ReAcquireTarget
	{
		action AcquirePrefPrey()
		transition HasTarget() == false
		{
			goto AttackExitEnd
		}
		transition IsTargetDead()
		{
			goto AttackExitEnd
		}
		transition IsTargetSmall() == false
		{
			action ClearTarget()
			goto AttackExitEnd
		}

		transition CanAttackTarget() == false
		{
			action ClearTarget()
			goto AttackExitEnd
		}
		transition
		{
      			action SetRandomTimerBetween(0, 1.5, 1.5)
			goto SeekLoop
		}
	}

;/////////////////////////////////
	state CornerSeek
	{
		transition HasTarget() == false
		{
			action ClearTarget()
			goto AttackExitEnd
		}
		transition IsTargetDead()
		{
			goto AttackExitEnd
		}
		transition InTargetProximityRadius(0.6, true)
		{
			direct goto SeekFacingCheck
		}
		transition SeekTargetOffset(1.0, 0.0, false, false, true)
		{
			direct goto SeekLoop
		}
		transition SeekTargetOffset(-5.0, 0.0, false, false, true) == false
		{
			action ClearTarget()
			goto AttackExitEnd
		}
		transition IsTimerUp(0)
		{
			goto TargetFaceSeek
		}
	}

	state SeekFacingCheck
	{
		transition IsTargetDead()
		{
			goto AttackExitEnd
		}
		transition IsFacingTargetUnit()
		{
			goto AttackSetup
		}
		transition
		{
			action FaceTarget()
			goto SeekFacingAlignWait
		}
	}

	state SeekFacingAlignWait
	{
		transition HasArrived()
		{
      			action SetRandomTimerBetween(0, 1.5, 1.5)
			direct goto SeekLoop
		}
	}
;///////////////////////////////
	state AttackSetup
	{
		transition IsTargetDead()
		{
			goto AttackExitEnd
		}
		transition IsTargetFSMRunning(fsm::"KnockOver")
		{
			goto AttackExitEnd
		}
		transition CanKnockTarget(0.0) == false
		{
			goto AttackExitEnd
		}

		;// My setup
		action StopAllRandomAnimations()
		action LockMachine(true)
		action LookEnd()
		action SetStandStill()
		action SetSpeedDirect(0.0)
		action SetAvoidanceSteer(false)
		;//action SetAvoidanceWorld(false)
		action SetAutoMovementBlend(false)
		action FaceTargetInstant()
		action PlayAnim("atk", "vis01", false, 0.0)
		action SetRandomTimerBetween(1, 0.26, 0.26)

		;// target setup
		action SetTargetToSlave()
		
		transition
		{
			goto AttackInit
		}
	}

	state AttackInit
	{
		transition IsAnimPlayingTarget("grab", "st", false)
		{
			goto AttackExitEnd
		}
		transition IsAnimPlayingTarget("grab", "shake_lp", false)
		{
			goto AttackExitEnd
		}
		transition IsAnimPlayingTarget("grab", "swal_ed", false)
		{
			goto AttackExitEnd
		}
		action FaceTargetInstant()
		transition IsTimerUp(1)
		{
			action SetNumPassedParamTarget(1)
			action SetPassedParamTargetKnockDir(0)
			action SetTargetsTargetToMe()
			action SetTargetFSM(fsm::"KnockOver")
			direct goto AttackLoop
		}
	}

	state Attackloop
	{
		transition IsAnimPlaying("atk", "vis01", false) == false
		{
			action SetTransfromFromLocator("D", true)
			action StopAnimInstant("atk", "vis01")
			action PlayAnimInstant("idle", "brth_lp", false)
			action SetStandStill()
			action SetAutoMovementBlend(true)
			action SetRandomTimerBetween(3, 1.0, 1.0)

			goto AttackFinish
		}
	}

	state AttackFinish
	{
		transition IsTimerUp(3)
		{
			action SetAutoMovementBlend(false)
			action PlayAnimInstant("idle", "post_lp", false)
			goto PostureWait
		}
	}

	state PostureWait
	{
		transition IsAnimPlaying("idle", "post_lp", false) == false
		{
			action SetAutoMovementBlend(true)

			action SetSpeedModifierWalk(1.0)
			action SetRunMode(false)

			action SeekTargetOffset(5.0, 0, false, true, true)
			action SetRandomTimerBetween(1, 1.0, 1.0)

			action UpdateVariable("Stress", -0.05)
			goto MoveOffFood
		}
	}

	state MoveOffFood
	{
		transition IsTargetDead()
		{
			action AddKillExperience(1, 0.0)
			goto MoveOffFoodLoop
		}
		transition
		{
			goto MoveOffFoodLoop
		}
	}

	state MoveOffFoodLoop
	{
		transition IsTimerUp(1)
		{
			action SetStandStill()
			goto AttackExitStart
		}
		transition InTargetProximityRadius(2.0, false) == false
		{
			action SetStandStill()
			goto AttackExitStart
		}
		transition HasArrived()
		{
			goto AttackExitStart
		}
	}


;------------------------ Exit States Begin ----------------------
	exitstart state AttackExitStart
	{
		transition
		{
			goto AttackExitEnd
		}
	}

	exitend state AttackExitEnd
	{
		action SetFlockHungerNeed(false)
		action StopAllRandomAnimations()
		action SetSpeedModifier(1.0)
		action SetRunMode(false)
		action SetAvoidanceSteer(true)
		action SetAvoidanceWorld(true)
		action LookEnd()
		action StopAnimState("atk")
		action LockMachine(false)
		;//action SetAesPosInterp(true)
	}
;------------------------ Exit States End ----------------------
}
