//
// Asura_Attractor_Data.h
//
// Created by JGP 10/05/06
//
// Copyright (C) 2006 Rebellion (Derby), All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __ASURA_ATTRACTOR_DATA_H__
#define __ASURA_ATTRACTOR_DATA_H__


// required
#include "Core/Asura_Hash.h"
#include "Debugging/Asura_Assert.h"
#include "Network/Asura_Guid.h"

const u_int uASURA_ATTRACTOR_ID_NONE = 0;

//Flags for the attractors.
//Last 16 bits are reserved for project use.
//RAR 09/05/2007
#define ASURA_ATTRACTOR_FLAG_ACTIVE 0x00000001

/*
	Asura_Attractor_Data

	The data stored by an attractor
*/
class Asura_Attractor_Data
{

public:

	// friend for editing class
	friend class Tools_Object_Attractor_Node;
	friend class Asura_Chunk_Attractors;
	friend class Asura_Chunk_Tools_Attractors;

	Asura_Attractor_Data();
    virtual ~Asura_Attractor_Data( void ) { }

	void SetRadius( const float fRadius ) { m_fRadius = fRadius; }
	float GetRadius() const { return m_fRadius; }

	void SetType( const Asura_Hash_ID xType ) { m_xType = xType; }
	Asura_Hash_ID GetType() const { return m_xType; }

	//Get the unique (within the zone) non-zero ID of the attractor
	//Note that	the ID of the compiled attractors correspond to the ID of
	//the tools attractor nodes , and not to the ID of the tools attractors.
	u_int GetID() const {return m_uID;}
	void SetID(u_int uID) {m_uID = uID;}

	//For getting the ID of linked attractors
	u_int GetNumLinks() const {return m_uNumLinks;}
	u_int GetLink(u_int uIndex) const
	{
		Asura_Assert(uIndex<m_uNumLinks,"Invalid link index");
		return (uIndex<m_uNumLinks) ? m_puLinks[uIndex] : 0;
	}

	void SetFlags(u_int uFlags)	 {m_uFlags = uFlags;}
	u_int GetFlags() const {return m_uFlags;}


	//Functions for used by the hashed list
	Asura_Guid GetGuid() const {return m_uID;}
	bool IsDestroyed() const {return false;}

	bool IsActive() const {return (m_uFlags & ASURA_ATTRACTOR_FLAG_ACTIVE)!=0;}
	void SetActive(bool bSet)
	{
		if(bSet) m_uFlags |= ASURA_ATTRACTOR_FLAG_ACTIVE;
		else m_uFlags &=~ ASURA_ATTRACTOR_FLAG_ACTIVE;
	}


private:

	float m_fRadius;
	Asura_Hash_ID m_xType;

	//unique non-zero ID for the attractor (derived from the IDs of the tools nodes)
	//For streaming these are only unique within a given zone/handler
	u_int m_uID;

	//Flags field using values from defines above.
	u_int m_uFlags;

protected  :
	//List of linked attractors (the effect of the links is project specific)
	//In the compiled attractors the pointers will be into an array in the attractor system.
	//For the tools attractors , the pointers are allocated/deallocated by the attractor itself
	u_int m_uNumLinks;
	u_int* m_puLinks; //IDs of the linked attractor


};


#endif // __ASURA_ATTRACTOR_DATA_H__
