/**
*
* \file Asura_ServerEntity_Trigger.h
*
* Created by Kevin Lea - 15/04/2002 16:06:05
*
* Copyright (C) 2002 Rebellion, All Rights Reserved.
*
* \brief
*
**/
#ifdef ASURA_USE_PRAGMA_ONCE
	#pragma once
#endif

#ifndef __ASURA_SERVERENTITY_TRIGGER_H__
#define __ASURA_SERVERENTITY_TRIGGER_H__

#include "Asura_ServerEntity_Activatable.h"

enum ASURA_TRIGGER_ENTITY_STATE
{
	ASURA_TRIGGER_ENTITY_ONACTIVATION=0,
	ASURA_TRIGGER_ENTITY_ONDEACTIVATION,
	ASURA_TRIGGER_ENTITY_ONBEINGTRIGGERED,
	ASURA_TRIGGER_ENTITY_ONDESTRUCTION,
	ASURA_TRIGGER_ENTITY_ONUNTRIGGER,

	ASURA_TRIGGER_ENTITY_NOOFSTATES,
};

class Asura_ServerEntity_Trigger : public Asura_ServerEntity_Activatable
{
	typedef Asura_ServerEntity_Activatable PARENT;

	public:
		Asura_ServerEntity_Trigger(bool initiallyActive = true);
		Asura_ServerEntity_Trigger(Asura_Guid uGuid);
		//constructor from load
		Asura_ServerEntity_Trigger(Asura_Guid guid,const char*& chunkBuffer);
		virtual ~Asura_ServerEntity_Trigger();

		static const Asura_Hashed_List<Asura_ServerEntity_Trigger>* GetList() { return &s_xList; }
		static Asura_ServerEntity_Trigger* FindEntity(Asura_Guid uGuid) { return s_xList.FindEntity(uGuid); }
	
		virtual void Update();
		
		#ifdef ASURA_TOOLS
		virtual void ApplyChangesForTemplateInstance(class Tools_EntityTemplateInstance* pxInstance);
		unsigned short GetMessageBlock(int iIndex) { return MessageBlock[iIndex]; }
		unsigned short* GetMessageBlockPointer(int iIndex) { return &MessageBlock[iIndex]; }
		#endif



	protected:
	
		/// Kevin Lea - 16/04/2002 10:37:44 - this trigger method is the core
		/// functionality for derived classes.
		virtual bool IsTriggered(void) = 0;
		virtual bool IsUnTriggered(void) {return false;}
		/// Kevin Lea - 22/04/2002 10:46:21 - Reset is called when object is made active (e.g. to trigger logic)
		virtual void Reset(void){};

		//virtual function overides from Activatable
		virtual void OnActivation();
		virtual void OnDeactivation();
		virtual void OnTrigger();
		virtual void OnDestruction();
		virtual void OnUnTrigger();



		virtual void SendMessages(enum ASURA_TRIGGER_ENTITY_STATE state);

		//virtual function overides for saving
//		virtual	bool	IsFilledFromChunkBuffer		(void) const					{ return (true); }

		virtual	int		GetChunkBufferSize			(void);
		virtual	void	FillInChunkBuffer			(char*& pcChunkBuffer);
//		virtual	void	InitialiseFromChunkBuffer	(const char*& pcChunkBuffer);

		virtual	void	ReadFromChunkStream			(Asura_Chunk_Stream& xStream);
		virtual	void	WriteToChunkStream			(Asura_Chunk_Stream& xStream) const;
		
		
		/// Kevin Lea - 17/04/2002 16:45:00 - this may have to change to unsigned int if there are more than 65,535 message blocks...
		/// something to watch out for during development. At the time of writing there are 4 trigger entity states, and so as a worse
		/// case scenario each trigger entity would require 4 message blocks (incidentally with a limit of 255 messages per block) which
		/// comes out to 16,000 entities. Should be enough for one level, I'd think. Famous last words, no doubt. ;)
		unsigned short MessageBlock[ASURA_TRIGGER_ENTITY_NOOFSTATES];

		static Asura_Hashed_List<Asura_ServerEntity_Trigger> s_xList;

		friend class Tools_Entity_Trigger_Object;
};

#endif//__ASURA_SERVERENTITY_TRIGGER_H__
