
///////////////////////////////////////////////////////////////////////////////
//
// File   : Tools_Entity_Affector_Wind.cpp
// Author : Andy Tate
// Date   : 8-Dec-2006
//
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////

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

#include "Core/Asura.h"

// This file's header...
#include "Entity/Tools_Entity_Affector_Wind.h"

// Asura independent header-files...
#include "Affectors/Asura_Affector_Global.h"
#include "Camera/Asura_Camera.h"
#include "Core/Asura_LOS.h"
#include "Core/Asura_Maths.h"
#include "Entity/Affector/Asura_ServerEntity_Affector_Wind.h"
#include "Interface/Asura_Dialog.h"
#include "Interface/Asura_Overlay.h"
#include "Mesh/Asura_Mesh_System.h"
#include "Network/Asura_Message.h"
#include "Rendering/Asura_Text_Output.h"

// Asura platform header-files...

// Tools header-files...
#include "Load&Save/Tools_SaveAsura.h"
#include "Misc/Tools_Render.h"
#include "Misc/Tools_Timed_Messages.h"
#include "Objects/Tools_Object_System.h"


#if defined(ASURA_USE_AFFECTORS)

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


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


////////////////////////////////////////////////////////////////////////////////
// Private functions...
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
// Protected functions...
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
// Public functions...
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Function     : Tools_Entity_Affector_Wind::Tools_Entity_Affector_Wind
// Author       : Andy Tate
// Date         : 6-Dec-2006
////////////////////////////////////////////////////////////////////////////////

Tools_Entity_Affector_Wind::Tools_Entity_Affector_Wind (Asura_Entity* pxEntity)
: PARENT(pxEntity)
{
	const Asura_ServerEntity_Affector_Wind*	pxAsuraEntity	= static_cast<Asura_ServerEntity_Affector_Wind*>(Entity);
	const Asura_Affector_Global*			pxAffector		= pxAsuraEntity->GetAffector();

	Type	= TOT_Entity_Affector_Wind;
	Mesh	= Asura_Mesh_System::GetMesh("ToolsShape_Arrow");

	// Initialise our local variables...
	m_fStrength			= pxAffector->GetStrength();
	m_fResponseScale	= pxAffector->GetResponseScale();
}

/// End of function 'Tools_Entity_Affector_Wind::Tools_Entity_Affector_Wind'. ///



////////////////////////////////////////////////////////////////////////////////
// Function     : Tools_Entity_Affector_Wind::AddOverlayControls
// Author       : Andy Tate
// Date         : 6-Dec-2006
////////////////////////////////////////////////////////////////////////////////

void Tools_Entity_Affector_Wind::AddOverlayControls (Asura_Overlay* pxOverlay,
													 Asura_Vector_2& xOffset)
{
	Asura_Dialog*	pxDialog;

	// Add any parent controls...
	PARENT::AddOverlayControls(pxOverlay, xOffset);

	// Add our own controls...
	xOffset.y += Asura_Dialog::SmallSpacing();

	pxDialog = new Asura_Numerical_Dialog("Strength", xOffset, &m_fStrength, -100.0f, 100.0f, 1.000f, "%.3f", &Changed);
	pxDialog->SetHelpText("This is the strength of the affector at it centre,\nthis scales of to 0 at the limit of the range.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y += Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Numerical_Dialog("Response-scale", xOffset, &m_fResponseScale, 0.001f, 10.0f, 0.100f, "%.3f", &Changed);
	pxDialog->SetHelpText("This value modifies the rate at which the direction of the wind affector changes.");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y += Asura_Dialog::DefaultSpacing();
}

/// End of function 'Tools_Entity_Affector_Wind::AddOverlayControls'. ///



////////////////////////////////////////////////////////////////////////////////
// Function     : Tools_Entity_Affector_Wind::UpdateWhileSelected
// Author       : Andy Tate
// Date         : 6-Dec-2006
////////////////////////////////////////////////////////////////////////////////

void Tools_Entity_Affector_Wind::UpdateWhileSelected (void)
{
	if(Changed)
	{
		Asura_ServerEntity_Affector_Wind* pxAsuraEntity = Asura_ServerEntity_Affector_Wind::FindEntity(GetGuid());
		if (pxAsuraEntity)
		{
			Asura_Affector_Global* pxAffector = pxAsuraEntity->GetAffector();
			if (pxAffector)
			{

				// Initialise our local variables...
				pxAffector->SetStrength(m_fStrength);
				pxAffector->SetResponseScale(m_fResponseScale);
			}
		}
	}

	// Call the parent...
	PARENT::UpdateWhileSelected();
}

/// End of function 'Tools_Entity_Affector_Wind::UpdateWhileSelected'. ///


void Tools_Entity_Affector_Wind::SetEntityModified()
{
	PARENT::SetEntityModified();
	Asura_ServerEntity_Affector_Wind* pxAsuraEntity = Asura_ServerEntity_Affector_Wind::FindEntity(GetGuid());
	if (pxAsuraEntity)
	{
		Asura_Affector_Global* pxAffector = pxAsuraEntity->GetAffector();
		if (pxAffector)
		{
			pxAffector->SetAsActive(pxAsuraEntity->IsEntityActive());
		}
	}
}



////////////////////////////////////////////////////////////////////////////////
// Function     : Tools_Entity_Affector_Wind::HandlesThisMessage
// Author       : Andy Tate
// Date         : 6-Dec-2006
////////////////////////////////////////////////////////////////////////////////

bool Tools_Entity_Affector_Wind::HandlesThisMessage (int iMessageID)
{
	switch(iMessageID)
	{
		case ASURA_MSG_DESTRUCT:
		case ASURA_MSG_ACTIVATE:
		case ASURA_MSG_DEACTIVATE:
		{
			return(true);
		}

		default:
		{
			return(PARENT::HandlesThisMessage(iMessageID));
		}
	}		// End of switch.
}

/// End of function 'Tools_Entity_Affector_Wind::HandlesThisMessage'. ///



////////////////////////////////////////////////////////////////////////////////
// Function     : Tools_Entity_Affector_Wind::PrintInfo
// Author       : Andy Tate
// Date         : 6-Dec-2006
////////////////////////////////////////////////////////////////////////////////

void Tools_Entity_Affector_Wind::PrintInfo (float& fX, float& fY)
{
	PARENT::PrintInfo(fX, fY);

	// Print our data...
	Asura_Text_Output::Print(fX, fY++, 0xFFFFFFFF, 0, "Strength : %.3f", m_fStrength);
	Asura_Text_Output::Print(fX, fY++, 0xFFFFFFFF, 0, "Response-scale : %.3f", m_fResponseScale);
}

/// End of function 'Tools_Entity_Affector_Wind::PrintInfo'. ///



////////////////////////////////////////////////////////////////////////////////
// Function     : Tools_Entity_Affector_Wind::Copy
// Author       : Andy Tate
// Date         : 6-Dec-2006
////////////////////////////////////////////////////////////////////////////////

void Tools_Entity_Affector_Wind::Copy (const Tools_Object* pxObject)
{
	const Tools_Entity_Affector_Wind*		pxAffectorObject	= static_cast<const Tools_Entity_Affector_Wind*>(pxObject);
	const Asura_ServerEntity_Affector_Wind*	pxEntityToCopy		= static_cast<Asura_ServerEntity_Affector_Wind*>(pxAffectorObject->Entity);
	const Asura_Affector_Global*			pxAffectorToCopy	= pxEntityToCopy->GetAffector();
	Asura_ServerEntity_Affector_Wind*		pxEntity			= static_cast<Asura_ServerEntity_Affector_Wind*>(Entity);
	Asura_Affector_Global*					pxAffector			= pxEntity->GetAffector();

	PARENT::Copy(pxObject);

	// Copy our data...
	*pxAffector	= *pxAffectorToCopy;

	// Initialise our local variables...
	m_fStrength			= pxAffector->GetStrength();
	m_fResponseScale	= pxAffector->GetResponseScale();
}

/// End of function 'Tools_Entity_Affector_Wind::Copy'. ///



////////////////////////////////////////////////////////////////////////////////
// Function     : Tools_Entity_Affector_Wind::CreateObjectOfThisType
// Author       : Andy Tate
// Date         : 6-Dec-2006
////////////////////////////////////////////////////////////////////////////////

Tools_Object* Tools_Entity_Affector_Wind::CreateObjectOfThisType (void) const
{
	Create();
	return(Tools_Object_System::SelectedObject);
}

/// End of function 'Tools_Entity_Affector_Wind::CreateObjectOfThisType'. ///



////////////////////////////////////////////////////////////////////////////////
// Function     : Tools_Entity_Affector_Wind::Create
// Author       : Andy Tate
// Date         : 6-Dec-2006
////////////////////////////////////////////////////////////////////////////////

void Tools_Entity_Affector_Wind::Create (void)
{
	const Asura_Guid	uGuid		= Asura_Entity_System::GetCreatedByToolsGuid();
	Tools_Entity_Data*	pxToolsData	= CreateToolsDataWithDefaultName("Affector", "Affector", uGuid, GetNamePrefix());

	if(pxToolsData == NULL)
	{
		Asura_Assert(false, "Tools_Entity_Affector_Wind::Create() - no tools data" );
	}
	else
	{
		Asura_ServerEntity_Affector_Wind::Create(uGuid);

		Asura_ServerEntity_Affector_Wind*	pxServer	= Asura_ServerEntity_Affector_Wind::FindEntity(uGuid);

		if(pxServer == NULL)
		{
			Asura_Assert(false, "Tools_Entity_Affector_Wind::Create() - no server object");
		}
		else
		{
			pxServer->ToolsData	= pxToolsData;

			Tools_Entity_Affector_Wind* pxToolsObject = new Tools_Entity_Affector_Wind(pxServer);

			if(pxToolsObject == NULL)
			{
				Asura_Assert(false, "Tools_Entity_Affector_Wind::Create() - no Tools object" );
			}
			else
			{
				Tools_Object_System::SelectObject(pxToolsObject);

				pxToolsObject->Position		= *Asura_Camera::GetPosition();
				pxToolsObject->Orientation	= *Asura_Camera::GetOrientation();

				Tools_Timed_Message_System::AddMessage(0xffffff, "Created new Affector");
				Tools_SaveAsura::SetEntityModified();
			}
		}
	}
}

/// End of function 'Tools_Entity_Affector_Wind::Create'. ///

#endif	// defined(ASURA_USE_AFFECTORS)


/// End of file. ///
