
///////////////////////////////////////////////////////////////////////////////
//
// File   : AVP_Predator_MovesBranch.cpp
// Author : Anthony Gregson
// Date   : 16/11/07
//
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////

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

#include "Core/Asura.h"

// This file's header...
#include "Moves/Vertebrates/Predator/AVP_Predator_MovesBranch.h"

// Asura independent header-files...

// Game independent header-files...
#include "Actor/AVP_Actor_PhysicsObjectHandler.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Predator/AVP_ClientActor_Predator.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Predator/AVP_Messages_Predator.h"


////////////////////////////////////////////////////////////////////////////////
// Constant declarations...
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
// Static variable declarations...
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Move_Predator_MountBranch::AVP_Move_Predator_MountBranch
// Author       : Anthony Gregson
// Date         : 16/11/07
////////////////////////////////////////////////////////////////////////////////

AVP_Move_Predator_MountBranch::AVP_Move_Predator_MountBranch(Asura_Movement_System& xParentSystem)
: PARENT(xParentSystem, GetStaticHash())
{
	// Initialise the move flags...
	m_bDisableMovement	= true;
	m_eAimDirectionUsage = AVP_ClientEntity_Actor::AIM_DIRECTION_LOCK;
}

/// End of function 'AVP_Move_Predator_MountBranch::AVP_Move_Predator_MountBranch'. ///


////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Move_Predator_MountBranch::Start
// Author       : Anthony Gregson
// Date         : 16/11/07
////////////////////////////////////////////////////////////////////////////////
DEBUGVAR float dbg_fMountBranchMoveTime = 0.2f;

bool AVP_Move_Predator_MountBranch::Start(const Asura_Msg_Move* pxStartMsg)
{
	// Have we been told to start via a message?
	if(pxStartMsg == NULL)
	{
		Asura_Assert(false, "Predator mount branch move can only be triggered by message.");
		return(false);
	}
	else
	{
		AVP_ClientActor_Predator& xPredatorOwner = static_cast<AVP_ClientActor_Predator&>(GetAVPParentSystem().GetActorOwner());

		const AVP_Message_Predator_Move_MountBranch_Start* pxMessage = static_cast<const AVP_Message_Predator_Move_MountBranch_Start*>(pxStartMsg);

		Asura_Vector_3 xTargetPosition;

		// Calculate our target position...
		pxMessage->GetDestinationPosition(xTargetPosition);

		// TODO - vary the duration based on distance to move
		m_xPositionInterpolationData.SetDuration(dbg_fMountBranchMoveTime);
		m_xPositionInterpolationData.SetFinal(xTargetPosition);

		m_xOrientationInterpolationData.SetDuration(dbg_fMountBranchMoveTime);
		m_xOrientationInterpolationData.SetFinal(xPredatorOwner.GetCurrentOrientation());

		InitialisePositionInterpolation(m_xPositionInterpolationData);
		InitialiseOrientationInterpolation(m_xOrientationInterpolationData);

		// Finally, call the base-function...
		return(PARENT::Start(pxStartMsg));
	}
}

/// End of function 'AVP_Move_Predator_MountBranch::Start'. ///

////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Move_Predator_DismountBranch::AVP_Move_Predator_DismountBranch
// Author       : Anthony Gregson
// Date         : 19/11/07
////////////////////////////////////////////////////////////////////////////////

AVP_Move_Predator_DismountBranch::AVP_Move_Predator_DismountBranch(Asura_Movement_System& xParentSystem)
: PARENT(xParentSystem, GetStaticHash())
, m_xMovementDirection(Asura_Maths::ZeroVector3)
, m_fTimeInMove(0.0f)
{
	m_eAimDirectionUsage = AVP_ClientEntity_Actor::AIM_DIRECTION_LOCK;
}

bool AVP_Move_Predator_DismountBranch::Start(const Asura_Msg_Move* pxStartMsg)
{
	// Have we been told to start via a message?
	if(pxStartMsg == NULL)
	{
		Asura_Assert(false, "Predator dismount branch move can only be triggered by message.");
		return false;
	}
	else
	{
		const AVP_Message_Predator_Move_DismountBranch_Start* pxMessage = static_cast<const AVP_Message_Predator_Move_DismountBranch_Start*>(pxStartMsg);

		// Calculate our target position...
		pxMessage->GetDirection(m_xMovementDirection);

		m_fTimeInMove = 0.0f;

		// Finally, call the base-function...
		return PARENT::Start(pxStartMsg);
	}
}

void AVP_Move_Predator_DismountBranch::UpdateStates(const float fTimeStep)
{
	m_fTimeInMove += Asura_Timers::GetGameTimeSlice();

	PARENT::UpdateStates(fTimeStep);
}

DEBUGVAR float dbg_fDismountBranchMoveTime = 0.5f;

bool AVP_Move_Predator_DismountBranch::HasFinished() const
{
	return m_fTimeInMove >= dbg_fDismountBranchMoveTime;
}

/// End of file. ///
