#include "MW4Headers.hpp"
#include "Adept\AdeptHeaders.hpp"

#include "mw4.hpp"
#include "moverai.hpp"
#include "Adept\Interface.hpp"
#include "Adept\Application.hpp"
#include "Adept\player.hpp"
#include "torso.hpp"

#include "aimovedata.hpp"

using namespace MechWarrior4;
using namespace MW4AI;
#pragma warning (push)
#include <algorithm>
#pragma warning (pop)

CMoveLocPointData::CMoveLocPointData (MW4AI::CRailGraph *graph,MoverAI *owner) : CMoveData (graph,owner)
{
	m_Location = Stuff::Point3D (0,0,0);
	m_MoveType = MOVE_LOCPOINT;
}

CMoveLocPointData::~CMoveLocPointData (void)
{
	m_Location = Stuff::Point3D (0,0,0);
}

void CMoveLocPointData::Save (MemoryStream *stream)
{
	*stream << m_Location;

	CMoveData::Save (stream);
}

void CMoveLocPointData::Load (MemoryStream *stream)
{
	*stream >> m_Location;
	CMoveData::Load (stream);
}

void CMoveLocPointData::InsertPoint (const Stuff::Point3D& loc)
{
	m_Location = loc;
	ConvertPointToGrid (m_Location);
	inherited::InsertPoint (loc);
}

void CMoveLocPointData::StartExecuting (MoverAI *ai,Stuff::Time till)
{
	CPathRequest *req;
	CRailPath *path;

	inherited::StartExecuting (ai,till);

	req = Request ();
	if (!req->Done ())
	{
		Executing (false);
		return;
	}
	path = req->NodePath ();
	ai->NewPath (req->DetachNodePath ());
}
void CMoveLocPointData::PathDone (MoverAI *ai,Stuff::Time till,bool failed)
{
	inherited::PathDone (ai,till,failed);
	if (failed)
		return;

	Verify (ai->m_Vehicle);
	Done (true);
}

void CMoveLocPointData::CreateRequests (const Stuff::Point3D& start,int usageflags)
{
	inherited::CreateRequests (start,usageflags);
	m_PathRequest = g_PathManager->AddRequest (gos_GetElapsedTime (),m_Graph,start,m_Location,usageflags,m_AI,m_AI->AllowTenMeter ());

}
bool CMoveLocPointData::operator== (const CMoveLocPointData& p1)
{
	if (!inherited::operator== ((inherited)p1))
		return false;
	if (m_Location != p1.m_Location)
		return false;
	return true;
}

Stuff::Point3D CMoveLocPointData::Location (int id)
{
	return m_Location;
}

int CMoveLocPointData::LocationSize (void) const
{
	return 1;
}
