//
// ToolsAVP_Entity_CommandPost.h
//
// Created by RDM - 21 November 2006
//
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __TOOLSAVP_ENTITY_COMMANDPOST_H__
#define __TOOLSAVP_ENTITY_COMMANDPOST_H__

/************/
/* Includes */
/************/

// asura

// AVP
#include "Entity/PhysicalObject/CommandPost/AVP_ServerEntity_CommandPost.h"
#include "Entity/PhysicalObject/PhysicsObject/ToolsAVP_Entity_PhysicsObject.h"
#include "Objects/ToolsAVP_Object_Type.h"

/***********/
/* Classes */
/***********/

// prototypes
class Asura_Overlay;
class Asura_Dialog;
class ToolsAVP_ChooseObject;

/*************************************************************
 *
 * Class Name    : ToolsAVP_Entity_CommandPost
 *
 * Author        : Richard May
 *
 * Description   : Tools entity for the BF3 command posts.
 *
 *************************************************************/
class ToolsAVP_Entity_CommandPost : public ToolsAVP_Entity_PhysicsObject
{

private:
	typedef ToolsAVP_Entity_PhysicsObject PARENT;

public:
	/* Public interface functions. */
	ToolsAVP_Entity_CommandPost( AVP_ServerEntity_CommandPost* pxEntity );
	virtual ~ToolsAVP_Entity_CommandPost();

	virtual const char* GetTypeDescription()												{ return "Command Post"; }
	virtual void AddOverlayControls( Asura_Overlay* pxOverlay, Asura_Vector_2& xOffset );
	virtual void AddFilesToExportList( List<Asura_String>& xNameList ) const;
	virtual bool HandlesThisEvent( int iEventID ) const; 
	virtual bool HandlesThisMessage(int messageID);
	virtual void PrintInfo( float& x, float& y );
	virtual void OnSelection();
	virtual void OnDeselection();
	virtual void Render();
	virtual void UpdateWhileSelected();

	/* Static functions. */
	static void Create( void );
	static void Project_Create(void);
	static Tools_Object* Create(Asura_Entity* pxEntity)										{ return new ToolsAVP_Entity_CommandPost( AVP_ServerEntity_CommandPost::FindEntity( pxEntity->GetGuid() )); }
	static ToolsAVP_Entity_CommandPost* FindEntity( Asura_Guid uGuid )						{ return s_xList.FindEntity( uGuid ); }
	static void			SelectGuardZoneAddLink				(int iIndex);
	static void			SelectGuardZoneRemoveLink			(int iIndex);

	// Allow command post node to be added during copy
	void AddNewChildNode( Asura_Guid uGuid, u_int m_uProbability );

	virtual void Copy(const Tools_Object*);
	virtual bool CanBeCopied() const { return Type == TOT_Entity_CommandPost; }
	virtual Tools_Object* CreateObjectOfThisType() const;

protected:
	/* Constructors/destructor. */

	/* Helper functions. */
	void ValidateChildNodes();

	static bool CaptureByBotsButtonIsEnabled();
	static void AddNewChildNode();

	static void GuardZone0AddLink();
	static void GuardZone1AddLink();
	static void GuardZone2AddLink();
	static void GuardZone3AddLink();

	static void GuardZoneSwap0();
	static void GuardZoneSwap1();
	static void GuardZoneSwap2();

	static void GuardZone0GoTo();
	static void GuardZone1GoTo();
	static void GuardZone2GoTo();
	static void GuardZone3GoTo();

	static void SelectGuardZoneAddLink();
	static void SelectGuardZoneMoveLink();
	static void MoveCameraToGuardZone();

	static void CreateNewChildNode();
	static void DeleteChildNode( int iGuid );
	static void GotoChildNode( int iGuid );
	static void OnSelectNewChildNode( Tools_Object* pxObject );
	static void OnSelectGuardZone( Tools_Object* pxObject );

	void AddGuardZoneLink(Asura_Guid uGuid, u_int iIndex);
	bool AreWeLinkedToThisGuardZone(Asura_Guid uGuid);
	void ValidateGuardZoneLinks();
	void UpdateGuardZoneDialogueText(const int iIndex);

	/* Data. */	
	bool m_bCaptureDisabled;
	bool m_bCaptureByBotDisabled;
	bool m_bDefaultSpawnPoint;
	bool m_bUsesOrientation;

	/* Static Data. */
	static Asura_Hashed_List<ToolsAVP_Entity_CommandPost> s_xList;
	static ToolsAVP_ChooseObject* s_pxObjectChooser;
	static ToolsAVP_Entity_CommandPost* s_pxThis;
	static u_int s_uGuardZoneLink;

private:
	/* private data */
	Asura_Guid		m_auLinkedGuardZones[AVP_COMMANDPOST_MAX_NUM_LINKED_GUARDZONES];
	Asura_Dialog*	m_apxGuardZoneDialogueText[AVP_COMMANDPOST_MAX_NUM_LINKED_GUARDZONES];
	Asura_Overlay*	m_pxOverlay; 

	// CommandPost name localised hash id
	void ChooseText();
	void UpdateText();

	static void ChooseText(int iThis){((ToolsAVP_Entity_CommandPost*)iThis)->ChooseText();}


	#ifdef TEST_COMMAND_POST_SPAWNER
	static void TestSpawner();
	#endif
};
/* end of class AVP_ClientEntity_CommandPost */

/***************/
/* End of File */
/***************/

#endif//__TOOLSAVP_ENTITY_COMMANDPOST_H__