//////////////////////////////////////////////////////////////////////////////
//
// FILE : ToolsAVP_Entity_Human.cpp
//
// Inherits from Tools_Entity_PhysicalObject
//
// AUTHORS : Chris Wallace
//
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////

// I N C L U D E S ///////////////////////////////////////////////////////////

// core
#include "Core/Asura.h"

// header
#include "Entity/PhysicalObject/Actor/Vertebrates/Human/ToolsAVP_Entity_Human.h"

// asura
#include "Blueprint/Asura_Blueprint_System.h"
#include "Camera/Asura_Camera.h"
#include "Core/Asura_HashedLocalisedText.h"
#include "Entity/Asura_StaticMessage_System.h"
#include "Entity/Tools_Entity_Data.h"
#include "GUIMenu/Asura_GUIMenu_System.h"
#include "GUIMenu/Tools_Mode_GUIMenu.h"
#include "Interface/Asura_Dialog.h"
#include "Interface/Asura_Overlay.h"
#include "Load&Save/Tools_SaveAsura.h"
#include "Mesh/Asura_Mesh_System.h"
#include "Objects/Tools_Object_System.h"
#include "Rendering/Asura_Render.h"
#include "Rendering/Asura_Text_Output.h"

// avp
#include "Actor/Vertebrates/Human/AVP_Human_Description.h"
#include "Entity/AVP_Entity_Classification.h"
#include "Entity/AVP_Entity_EventIDs.h"
#include "Entity/AVP_Messages.h"
#include "Entity/Locations/GuardZone/AVP_ServerNode_GuardZone.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Human/AVP_ServerActor_Human.h"
#include "Objects/ToolsAVP_Object_Type.h"
#include "ToolsAVP_ChooseObjects.h"
#include "Entity/Controller/AVP_ServerEntity_Squad_Marine.h"

#include "Entity/Controller/ToolsAVP_Entity_MarineSquad.h"
#include "Misc/Tools_Render.h"

TOOLS_DECLARE_SHARED_PARAM( bool, 0x29FC0644, UseTestBehaviour );
TOOLS_DECLARE_SHARED_PARAM( bool, 0xbfb446cd, StartAsInjured );

bool										ToolsAVP_Entity_Human::s_bAddRemoveLink			= false;
ToolsAVP_Entity_Human*						ToolsAVP_Entity_Human::s_pxSelectedHuman		= NULL;	
ToolsAVP_Entity_Human*						ToolsAVP_Entity_Human::s_pxStaticThisPointer	= NULL;	
Asura_Hashed_List<ToolsAVP_Entity_Human>	ToolsAVP_Entity_Human::s_xList;

//////////////////////////////////////////////////////////////////////////////
//
// ToolsAVP_Entity_Human
//
//////////////////////////////////////////////////////////////////////////////

ToolsAVP_Entity_Human::ToolsAVP_Entity_Human(AVP_ServerActor_Human* pxActor)
: Tools_Entity_PhysicalObject( pxActor )
, PARENT( pxActor )
, m_pxOverlay(NULL)
, m_pxHuman( pxActor )
, m_bChanged(false)
{
	Type	= TOT_Entity_Human;

	s_pxStaticThisPointer = this;
	
	Asura_String mesh_name = "ToolsShape_Human";
	Mesh = Asura_Mesh_System::GetMesh(mesh_name);

	s_xList.AddToList(this);
}

void ToolsAVP_Entity_Human::RestoreMesh()
{
	// Restore original mesh
	SetMesh(Asura_Mesh_System::GetMesh("ToolsShape_Human"));
}

ToolsAVP_Entity_Human::~ToolsAVP_Entity_Human()
{
	s_xList.RemoveFromList(this);
}

void ToolsAVP_Entity_Human::AddFilesToExportList(List<Asura_String>& nameList) const
{
	// Call the base-function...
	PARENT::AddFilesToExportList(nameList);

	// Export the necessary human data...

	switch (m_pxHuman->GetClassification())
	{
		//-----------------------------------------------------------------------------------------
		case AVP_ENTITYCLASS_ANDROID:
		{
			AVP_Human_Description::AddAndroidFilesToExport(false, m_uBlueprintHashID, nameList);
		}break;
		//-----------------------------------------------------------------------------------------
		case AVP_ENTITYCLASS_CIVILIAN:
		{
			AVP_Human_Description::AddCivilianFilesToExport(false, m_uBlueprintHashID, nameList);
		}break;
		//-----------------------------------------------------------------------------------------
		case AVP_ENTITYCLASS_MARINE:
		{
			AVP_Human_Description::AddMarineFilesToExport(false, m_uBlueprintHashID, nameList);
		}break;
		//-----------------------------------------------------------------------------------------
		default:
		{
			Asura_Assert(false, "ToolsAVP_Entity_Human :: AddFilesToExportList - Unrecognised human type, please ensure you are using either an Android, a Civilian or a Human");
		}break;
		//-----------------------------------------------------------------------------------------
	}
	
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_Human::OnSelection
// Author       : Stuart Perry
// Date         : 23-April-2007
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_Human::OnSelection()
{
	s_pxSelectedHuman = this;

	PARENT::OnSelection();
}

/// End of function 'ToolsAVP_Entity_Human::OnSelection'. ///

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_Human::OnDeselection
// Author       : Stuart Perry
// Date         : 23-April-2007
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_Human::OnDeselection()
{
	s_pxSelectedHuman = NULL;

	PARENT::OnDeselection();
}

/// End of function 'ToolsAVP_Entity_Human::OnDeselection'. ///

//-----------------------------------------------------------------------------
// ToolsAVP_Entity_Human :: Copy
//-----------------------------------------------------------------------------
void ToolsAVP_Entity_Human::Copy(const Tools_Object* pxObject)
{
	PARENT::Copy( pxObject );

	ToolsAVP_Entity_Human* pxFromObject = ToolsAVP_Entity_Human::FindEntity( pxObject->GetGuid() );

	if ( pxFromObject )
	{
		AVP_ServerActor_Human* pxFromEntity = pxFromObject->m_pxHuman;
		AVP_ServerActor_Human* pxToEntity = m_pxHuman;

		if (pxFromEntity && pxToEntity)
		{
			pxFromEntity->SetUseTestBehaviour( pxToEntity->GetUseTestBehaviour() );
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_Human::HandlesThisMessage
// Author       : Andy Tate
// Date         : 24-Jan-2008
////////////////////////////////////////////////////////////////////////////////

bool ToolsAVP_Entity_Human::HandlesThisMessage(int iMessageID)
{
	switch(iMessageID)
	{
		case AVP_MSGID_MOUNT_LIFT:
		case AVP_MSGID_DISMOUNT_LIFT:
		case AVP_MSGID_REQUEST_TORCH_ON:
		case AVP_MSGID_REQUEST_TORCH_OFF:
		case AVP_MSGID_LOOK_AT_ENTITY:
		case AVP_MSGID_STOP_LOOKING_AT_ENTITY:
		case AVP_MSGID_SET_GS2_MOVE_SPEED:
		case AVP_MSGID_ATTACK_SCRIPTED_TARGET:
		case AVP_MSGID_STOP_ATTACKING_SCRIPTED_TARGET:
		case AVP_MSGID_ALIENQUEEN_ADD_TO_TARGET_LIST:
		case AVP_MSGID_ALIENQUEEN_REMOVE_FROM_TARGET_LIST:
		{
			return(true);
		}

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

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

bool ToolsAVP_Entity_Human::HandlesThisEvent( int iEventID ) const
{
	switch( iEventID )
	{
		case AVP_ENTITY_EVENT_ON_PICKED_UP_BY_PLAYER:
		case AVP_ENTITY_EVENT_ON_PUT_DOWN_BY_PLAYER:
		{
			return(true);
		}

		default:
		{
			return(PARENT::HandlesThisEvent(iEventID));
		}
	}
}

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

	pxDialog = new Asura_Function_Dialog("Name",xOffset,ChooseText,(int)this);
	pxDialog->SetHelpText("Select this human name.");
	pxDialog->m_iControlID = Asura_GetHashID("SelectText");
	pxOverlay->AddDialog(pxDialog);
	xOffset.y += Asura_Dialog::DefaultSpacing();


	// Head ripping message if any
	Asura_Char szBuffer[32];
	if (m_pxHuman)
	{
		Asura_PrintfToBfr( szBuffer,"On Head ripped (%d)", 32, true, Asura_StaticMessage_System::GetNumberOfMessagesInBlock( m_pxHuman->m_usHeadRippedMessageBlock ) );
		pxDialog = new Asura_Function_Dialog( szBuffer, xOffset, EditOnHeadRippedMessages );
		pxOverlay->AddDialog( pxDialog );
		xOffset.y += Asura_Dialog::DefaultSpacing();
	}

	PARENT::AddOverlayControls(pxOverlay, xOffset);

	if (Entity->GetClassification() != AVP_ENTITYCLASS_CIVILIAN)
	{
		xOffset.y += Asura_Dialog::DefaultSpacing();
		pxDialog = new Asura_SharedTickbox_Dialog( "Start as Injured", xOffset, &g_xParam_StartAsInjured );
		pxDialog->SetHelpText( "Have this ticked to start the actor as injured sitting on the floor" );
		pxOverlay->AddDialog( pxDialog );
		xOffset.y += Asura_Dialog::LargeSpacing();

		pxDialog = new Asura_SharedTickbox_Dialog("Use Test Behaviour", xOffset, &g_xParam_UseTestBehaviour);
		pxDialog->SetHelpText("Having this ticked will make the AI use the test behaviour instead of the normal Human AI behaviour.");
		pxOverlay->AddDialog(pxDialog);
		xOffset.y += Asura_Dialog::LargeSpacing();

		pxDialog = new Asura_Function_Dialog("Select Squad", xOffset, SelectSquad, &m_bChanged);
		pxDialog->SetHelpText("Enables the selection of a squad for this humanoid.");
		pxOverlay->AddDialog(pxDialog);
		xOffset.y += Asura_Dialog::DefaultSpacing();

		pxDialog = new Asura_Function_Dialog("Clear Selected Squad", xOffset, ClearSelectedSquad, &m_bChanged);
		pxDialog->SetHelpText("Clears the selected squad for this humanoid.");
		pxOverlay->AddDialog(pxDialog);
		xOffset.y += Asura_Dialog::DefaultSpacing();
	}

	m_pxOverlay = pxOverlay;
	// Update text
	UpdateText();
}

bool ToolsAVP_Entity_Human::GetEventDescForMessageBlock( unsigned short usMessageBlockID, Asura_String& xOutputDesc )
{
	if ( m_pxHuman ) 
	{
		if ( m_pxHuman->m_usHeadRippedMessageBlock == usMessageBlockID )
		{
			xOutputDesc = "On Head ripped";
			return true;
		}
	}
	return false;
}

void ToolsAVP_Entity_Human::EditOnHeadRippedMessages()
{
	if (s_pxSelectedHuman != NULL)
	{
		AVP_ServerActor_Human* pxAVPHuman = AVP_ServerActor_Human::FindEntity(s_pxSelectedHuman->GetGuid());
		if( pxAVPHuman )
		{
			Tools_Object_System::EditMessageBlock( "On Head ripped", &pxAVPHuman->m_usHeadRippedMessageBlock );
		}
	}
}

bool ToolsAVP_Entity_Human::OwnsThisMessageBlock( unsigned short usMessageBlockID )
{
	if ( m_pxHuman &&  m_pxHuman->m_usHeadRippedMessageBlock == usMessageBlockID ) 
	{
		return true;
	}

	return PARENT::OwnsThisMessageBlock( usMessageBlockID );
}

void ToolsAVP_Entity_Human::Destroy()
{
	if ( m_pxHuman )
	{
		//delete all the static messages
		Asura_StaticMessage_System::DeleteMessageBlock(m_pxHuman->m_usHeadRippedMessageBlock);
		m_pxHuman->m_usHeadRippedMessageBlock = ASURA_STATICMESSAGE_EMPTYBLOCK;
	}
	PARENT::Destroy();
}

void ToolsAVP_Entity_Human::SelectSquad(void)
{
	ToolsAVP_ChooseObject_ByType* pxChooseObject = new ToolsAVP_ChooseObject_ByType(TOT_Entity_MarineSquad, SetSelectedSquad);
	Tools_Object_System::ChooseObject("Select The Squad To Join", pxChooseObject);
}

void ToolsAVP_Entity_Human::ClearSelectedSquad(void)
{
	if (s_pxSelectedHuman != NULL)
	{
		AVP_ServerActor_Human* pxAVPHuman = AVP_ServerActor_Human::FindEntity(s_pxSelectedHuman->GetGuid());

		if (pxAVPHuman)
		{
			pxAVPHuman->SetInitialSquadGuid(ASURA_GUID_UNREGISTERED);
		}
	}
}

void ToolsAVP_Entity_Human::SetSelectedSquad(Asura_Guid uGuid)
{
	if (s_pxSelectedHuman != NULL)
	{
		AVP_ServerActor_Human* pxAVPHuman = AVP_ServerActor_Human::FindEntity(s_pxSelectedHuman->GetGuid());

		if (pxAVPHuman)
		{
			pxAVPHuman->SetInitialSquadGuid(uGuid);
		}
	}
}

void ToolsAVP_Entity_Human::UpdateWhileSelected()
{
	PARENT::UpdateWhileSelected();

	if ( m_bChanged )
	{
        m_bChanged = false;

        Tools_SaveAsura::SetEntityModified();
	}
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_Human::Render
// Author       : Gareth Thomas
// Date         : 08 / 02 / 2008
////////////////////////////////////////////////////////////////////////////////
void ToolsAVP_Entity_Human::Update()
{
	if (m_pxHuman)
	{
		if (m_pxHuman->GetInitialSquadGuid() != ASURA_GUID_UNREGISTERED)
		{
			AVP_ServerEntity_Squad_Marine* pxSquad = AVP_ServerEntity_Squad_Marine::FindEntity(m_pxHuman->GetInitialSquadGuid());

			if (!pxSquad)
			{
				m_pxHuman->SetInitialSquadGuid(ASURA_GUID_UNREGISTERED);
			}
		}

		// temp while we clear out all the uninitialised flags
		m_pxHuman->m_bPickUpAble	= false;
		m_pxHuman->m_bDroppable		= false;
		m_pxHuman->m_bPickedUp		= false;
	}
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_Human::Render
// Author       : Stuart Perry
// Date         : 23-April-2007
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_Human::Render(void)
{
	// Only render lines for linked entities...
	if (IsSelected())
	{
		if ( m_uLinkedGuardZoneGuid != ASURA_GUID_UNREGISTERED )
		{
			const AVP_ServerNode_GuardZone*	pxServer			= AVP_ServerNode_GuardZone::FindEntity(m_uLinkedGuardZoneGuid);

			if(pxServer)
			{
				Asura_Render::RenderLine(Position,pxServer->GetPosition(),0xFFFF8000);
			}		
		}
	}

	AVP_ServerActor_Human* pxAVPHuman = AVP_ServerActor_Human::FindEntity(GetGuid());

	if (pxAVPHuman && (pxAVPHuman->GetInitialSquadGuid() != ASURA_GUID_UNREGISTERED))
	{
		ToolsAVP_Entity_MarineSquad* pxSquad = ToolsAVP_Entity_MarineSquad::FindEntity(pxAVPHuman->GetInitialSquadGuid());

		if (pxSquad)
		{
			Asura_Vector_3 xHumanPos = pxAVPHuman->GetPosition();
			xHumanPos.y -= 1.6f;
			Tools_Render::RenderCylinder(xHumanPos, pxSquad->Position, 0.025f, 0xff00ff00, false);
		}
	}

	// Call the base-function...
	PARENT::Render();
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_Human::PrintInfo
// Author       : Gaz Thomas
// Date         : 22 / 05 / 08
////////////////////////////////////////////////////////////////////////////////
void ToolsAVP_Entity_Human::PrintInfo(float& x, float& y)
{
	 PARENT::PrintInfo(x, y);

	 AVP_ServerActor_Human* pxAVPHuman = AVP_ServerActor_Human::FindEntity(GetGuid());

	 if (pxAVPHuman && pxAVPHuman->GetInitialSquadGuid() != ASURA_GUID_UNREGISTERED)
	 {
		 ToolsAVP_Entity_MarineSquad* pxSquad = ToolsAVP_Entity_MarineSquad::FindEntity(pxAVPHuman->GetInitialSquadGuid());

		 if (pxSquad)
		 {
			 Asura_Text_Output::Print(x, y++, 0xffffffff,0, "Assigned Squad : %s", pxSquad->GetName());
			 Asura_Text_Output::Print(x, y++, 0xffffffff,0, "Assigned Squad Guid : %u", pxSquad->GetGuid());
		 }
	 }
}

/// End of function 'ToolsAVP_Entity_Human::Render'. ///

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_Human::SelectGuardZoneAddLink
// Author       : Stuart Perry
// Date         : 23-April-2007
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_Human::SelectGuardZoneAddLink(int iIndex)
{
	const Asura_Guid								uDestinationGuid	= ASURA_GUID_UNREGISTERED;
	Tools_Object*									pxToolsObject		= Tools_Object_System::GetObjectFromGuid(uDestinationGuid);
	ToolsAVP_ChooseObject_Human*					pxChooseObject		= new ToolsAVP_ChooseObject_Human (iIndex, s_pxSelectedHuman);

	char											szPrompt[256];
	Asura_PrintfToBfr(szPrompt, "Select the Guard Zone to link the Human to:", sizeof(szPrompt), true);

	s_bAddRemoveLink = true;

	Tools_Object_System::ChooseObject(szPrompt, pxChooseObject, pxToolsObject);
}

/// End of function 'ToolsAVP_Entity_Human::SelectGuardZoneAddLink'. ///

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_Human::SelectGuardZoneRemoveLink
// Author       : Stuart Perry
// Date         : 23-April-2007
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_Human::SelectGuardZoneRemoveLink(int iIndex)
{
	const Asura_Guid								uDestinationGuid	= ASURA_GUID_UNREGISTERED;
	Tools_Object*									pxToolsObject		= Tools_Object_System::GetObjectFromGuid(uDestinationGuid);
	ToolsAVP_ChooseObject_Human*					pxChooseObject		= new ToolsAVP_ChooseObject_Human (iIndex, s_pxSelectedHuman);

	char											szPrompt[256];
	Asura_PrintfToBfr(szPrompt, "Select the Guard Zone link to remove", sizeof(szPrompt), true);

	s_bAddRemoveLink = false;

	Tools_Object_System::ChooseObject(szPrompt, pxChooseObject, pxToolsObject);
}

/// End of function 'ToolsAVP_Entity_Human::SelectGuardZoneRemoveLink'. ///

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_Human::SetDestination
// Author       : Stuart Perry
// Date         : 23-April-2007
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_Human::SetDestination(const int iIndex, Tools_Object* pxObject)
{
	Asura_Guid							uDestinationGuid		= (pxObject == NULL) ? ASURA_GUID_UNREGISTERED : pxObject->GetGuid();
	Tools_Object*						pxToolsObject			= Tools_Object_System::GetObjectFromGuid(uDestinationGuid);

	// Check to make sure a destination had been selected
	if ( pxToolsObject == NULL )
	{
		return;
	}

	// ADD link
	if ( s_bAddRemoveLink )
	{
		m_uLinkedGuardZoneGuid = uDestinationGuid;
	}
	// REMOVE link
	else
	{
		m_uLinkedGuardZoneGuid = ASURA_GUID_UNREGISTERED;
	}
}

/// End of function 'ToolsAVP_Entity_Human::SetDestination'. ///

void ToolsAVP_Entity_Human::UpdateText()
{
	Asura_Hash_ID uMenuPage = Asura_GetHashID("Menu") ;

	if (s_pxSelectedHuman)
	{
		AVP_ServerActor_Human* pxAVPEntity = AVP_ServerActor_Human::FindEntity(s_pxSelectedHuman->GetGuid());

		if(pxAVPEntity)
		{
			char szText[100];
			const Asura_HashedLocalisedText_Page* pxPage = Asura_HashedLocalisedText::GetPage(uMenuPage);

			const char* szTextID = 0;

			if(pxPage && pxPage->HasTextIDStrings())
			{
				szTextID = pxPage->GetTextIDString(pxAVPEntity->GetNameText().GetTextID());
			}

			if(szTextID)
			{
				Asura_PrintfToBfr(szText,"Name : %s",sizeof(szText),true,szTextID);	
			}
			else
			{
				strcpy(szText,"Name : *Unknown*");
			}
	
			m_pxOverlay->UpdateDialogLabel(Asura_GetHashID("SelectText"),szText);
		}
	}
}

void ToolsAVP_Entity_Human::ChooseText()
{
	Asura_Hash_ID uMenuPage = Asura_GetHashID("Menu") ;

	if (s_pxSelectedHuman)
	{
		AVP_ServerActor_Human* pxAVPEntity = AVP_ServerActor_Human::FindEntity(s_pxSelectedHuman->GetGuid());

		if(pxAVPEntity)
		{
			Asura_Hash_ID uTextID = pxAVPEntity->GetNameText().GetTextID();
			if(!Tools_Mode_GUIMenu::ChooseText(uMenuPage, uTextID)) { return; }

			if(uTextID != pxAVPEntity->GetNameText().GetTextID())
			{
				pxAVPEntity->GetNameText().SetTextID(uTextID);
				UpdateText();
				Tools_SaveAsura::SetEntityModified(pxAVPEntity);
			}	
		}
	}
}


bool ToolsAVP_Entity_Human::GetParameter( Asura_Hash_ID uParamID, Tools_Parameter* pxParam ) const
{
	switch(uParamID)
	{
		case g_uHash_UseTestBehaviour:
		{
			pxParam->SetBool( m_pxHuman->m_bUseTestBehaviour != 0 );
		}
		break;

		case g_uHash_StartAsInjured:
		{
			pxParam->SetBool( m_pxHuman->m_bStartAsInjured != 0 );
		}
		break;

		default :
		{
			return PARENT::GetParameter(uParamID, pxParam);
		}
	}
	return true;
}

bool ToolsAVP_Entity_Human::SetParameter( Asura_Hash_ID uParamID, const Tools_Parameter* pxParam )
{
	switch(uParamID)
	{
		case g_uHash_UseTestBehaviour:
		{
			m_pxHuman->m_bUseTestBehaviour = pxParam->GetBool();
		}
		break;

		case g_uHash_StartAsInjured:
		{
			m_pxHuman->m_bStartAsInjured = pxParam->GetBool();
		}
		break;

		default :
		{
			return PARENT::SetParameter(uParamID, pxParam);
		}
	}

	SetEntityModified();
	return true;
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_ChooseObject_Human::CanBeSelected
// Author       : Stuart Perry
// Date         : 23-April-2007
////////////////////////////////////////////////////////////////////////////////

bool ToolsAVP_ChooseObject_Human::CanBeSelected(Tools_Object* pxObject)
{
	if ( pxObject->Type != TOT_Entity_GuardZone )
	{
		return false;
	}

	ToolsAVP_Entity_Human* pxServer	= ToolsAVP_Entity_Human::GetSelectedHumanPointer();
	Asura_Guid uDestinationGuid					= (pxObject == NULL) ? ASURA_GUID_UNREGISTERED : pxObject->GetGuid();

	// If adding new links to entities, just show the entities that don't have links
	if ( pxServer->GetAddRemoveLink() )
	{
		// If already has a link then don't allow another as Human can only link to 1 guard zone
		if ( pxServer->GetLinkedGuardZoneGuid() != ASURA_GUID_UNREGISTERED )
		{
			return false;
		}
		if ( uDestinationGuid == pxServer->GetLinkedGuardZoneGuid() )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		if ( uDestinationGuid == pxServer->GetLinkedGuardZoneGuid() )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

/// End of function 'ToolsAVP_ChooseObject_Human::CanBeSelected'. ///

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_ChooseObject_Human::ObjectSelected
// Author       : Stuart Perry
// Date         : 23-April-2007
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_ChooseObject_Human::ObjectSelected(Tools_Object* pxObject)
{
	m_pxHuman->SetDestination(m_iIndex, pxObject);
}

/// End of function 'ToolsAVP_ChooseObject_Human::ObjectSelected'. ///


/// End of file. ///

