
///////////////////////////////////////////////////////////////////////////////
//
// File   : AVP_Alien_AnimationHandler.h
// Author : Andy Tate
// Date   : 18-Oct-2006
//
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
	#pragma once
#endif   // ifdef ASURA_USE_PRAGMA_ONCE

#ifndef __AVP_ALIEN_ANIMATIONHANDLER_H__
#define __AVP_ALIEN_ANIMATIONHANDLER_H__

////////////////////////////////////////////////////////////////////////////////
// Include files...
////////////////////////////////////////////////////////////////////////////////

#include "Animation/IK/Asura_Animation_IK_Chain_LOS.h"
#include "Core/Asura_Maths.h"

#include "Animation/AVP_Animation_BodyRig.h"
#include "Animation/AVP_Animation_IK_Chain_Tail.h"
#include "Animation/AVP_BoneDataModifier_TargetRelative.h"
#include "Actor/Vertebrates/AVP_Vertebrate_AnimationHandler.h"
#include "Actor/Vertebrates/Alien/AVP_Alien_Description.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/AVP_ClientActor_Vertebrate.h"

DEBUGVAR float dbg_fAlienRagdollStartFadingOutTime = 5.0f;

////////////////////////////////////////////////////////////////////////////////
// Forward class declarations...
////////////////////////////////////////////////////////////////////////////////

class AVP_ClientActor_Alien;


////////////////////////////////////////////////////////////////////////////////
// Class declaration...
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Class        : AVP_Alien_AnimationHandler
// Author       : Andy Tate
// Date         : 18-Oct-2006
//
// Description  : Class to handle the animations needed by the Alien.
////////////////////////////////////////////////////////////////////////////////

class AVP_Alien_AnimationHandler : public AVP_Vertebrate_AnimationHandler
{
public:

	// Public functions...
	AVP_Alien_AnimationHandler          (AVP_ClientActor_Alien& xOwner);
	virtual ~AVP_Alien_AnimationHandler ();

	virtual void Initialise( void );
	virtual void Shutdown( void );

	virtual	void Reset (void) { PARENT::Reset(); }

	virtual void HandleAnimationRequest	(const AVP_Message_Actor_RequestAnimation& xAnimRequestData);
    virtual void Update();

	void EnableAllIKButTail();
	void DisableAllIKButTail();
	void EnableArmsIK();
	void DisableArmsIK();

	virtual const Asura_Animation_IK_Chain_LOS* GetLimbIKChainLOS( u_int uLimbItr ) const;

	void StartTailStab_ObjectSpaceTarget(const Asura_Vector_3& xOSTarget)						{ m_bTailStabbing = true; m_xTailStabTargetPos = xOSTarget; }
	void StartTailStab_WorldSpaceTarget(const Asura_Vector_3& xWSTarget)						{ m_bTailStabbing = true; m_bTailStabUsingWorldspaceTarget = true; m_xTailStabTargetPos = xWSTarget; }
	void StartTailStab_EntityTarget(const Asura_Guid uEntity, const Asura_Hash_ID uMarkerPoint)	{ m_bTailStabbing = true; m_bTailStabUsingEntityTarget = true; m_uTailStabEntityTargetGuid = uEntity; m_uTailStabEntityTargetMarkerPoint = uMarkerPoint; }
	void FinishTailStab()																		{ m_bTailStabbing = false; m_bTailStabUsingWorldspaceTarget = false; m_bTailStabUsingEntityTarget = false; }

protected:
	// Protected functions...
	void CreateRequestedAnimation( const Asura_Hash_ID uAnimHashID, const u_int uAnimFlags );

	virtual void UpdateRagdollFading( Asura_Ragdoll_Wrapper* pxRagdollrapper );
	virtual float GetRagdollStartFadingOutTime() const { return dbg_fAlienRagdollStartFadingOutTime; }
	virtual int GetRagdollPriority() const { return 20; }

	void UpdateMouthAnim();

	AVP_ClientEntity_Actor&	m_xOwnerAlien;
	Asura_Animation_IK_Chain_LOS m_axIKLOSChains[ AVP_Alien_Description::NUM_IK_CHAINS - 1 ];
	AVP_Animation_IK_Chain_Tail m_xTailIKChain;

	Asura_Hash_ID m_uMouthControllerHash;

	Asura_Hash_ID m_uMouthStartAnimID;
	Asura_Hash_ID m_uMouthIdleAnimID;
	Asura_Hash_ID m_uMouthFinishAnimID;

private:
	void InitialiseIKSolver();

	bool CalculateTailStabTargetPosition(Asura_Vector_3& xOSTargetPos) const;

	AVP_BoneDataModifier_TargetRelative*	m_pxTailStabBoneModifier;
	Asura_Vector_3							m_xTailStabTargetPos; // May be object-space or world-space, depending on the bool below.
	Asura_Guid								m_uTailStabEntityTargetGuid;
	Asura_Hash_ID							m_uTailStabEntityTargetMarkerPoint; // If unset, just use entity position.
	Asura_Hash_ID							m_uRagdollFadingPFXHash;
	bool									m_bTailStabbing;
	bool									m_bTailStabUsingWorldspaceTarget;
	bool									m_bTailStabUsingEntityTarget;
	float									m_fPFXTimer;

	typedef AVP_Vertebrate_AnimationHandler PARENT;

	// Declarations without definitions to ensure no-one uses these accidentally.
	AVP_Alien_AnimationHandler  (void);
	AVP_Alien_AnimationHandler  (const AVP_Alien_AnimationHandler& xOther);

	AVP_Alien_AnimationHandler&	operator=	(const AVP_Alien_AnimationHandler& xOther);
};   // End of class 'AVP_Alien_AnimationHandler'.


#endif   // ifndef __AVP_ALIEN_ANIMATIONHANDLER_H__


/// End of file. ///
