//
// Asura_StaticMessageBlock.h
//
// Created by Richard Rice - 15/11/2006
// 
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __ASURA_STATICMESSAGEBLOCK__
#define __ASURA_STATICMESSAGEBLOCK__

#include "Network/Asura_Guid.h"

class Asura_Chunk_Stream;
struct Asura_StaticMessage;
class Asura_StaticMessage_Handler;


//For storing a set of messages outside of the static message system
class Asura_StaticMessageBlock
{
public :
	Asura_StaticMessageBlock();
	Asura_StaticMessageBlock(u_int uNumMessages);//allocate some empty messages at the same time
	~Asura_StaticMessageBlock();

	#ifdef ASURA_TOOLS
	Asura_StaticMessageBlock& operator = (const Asura_StaticMessageBlock& xBlock);
	#endif

	void ReadFromChunkStream(Asura_Chunk_Stream& xStream);
	#ifdef ASURA_TOOLS
	//Skip past a static message block in chunk stream
	static void SkipInChunkStream(Asura_Chunk_Stream& xStream);
	#endif
	
	//deals with old versions of Asura_Chunk_StaticMessages
	void ReadOldStaticMessageChunkFromChunkStream(Asura_Chunk_Stream &xStream, u_int uVersion, bool bHasToolsData);

	#ifdef ASURA_TOOLS
	void WriteToChunkStream(Asura_Chunk_Stream& xStream) const;
	#endif

	u_int GetNumberOfMessagesInBlock() const {return m_uNumMessages;}
	Asura_StaticMessage* GetMessagePointer(u_int uIndex);
	const Asura_StaticMessage* GetMessagePointer(u_int uIndex) const;

	#ifdef ASURA_USE_DIALOGUE_SYSTEM
	//Sends the messages in the message block. Current implementation is somewhat specific to the requirements
	//for the dialogue system
	void SendMessagesForDialogueSystem(Asura_Guid uSpeaker,unsigned short usExtraMessageBlock,Asura_StaticMessage_Handler* pxHandler) const;
	#endif

	//Send messages without the dialogue system stuff
	void SendMessages(Asura_Guid uFrom, float fDelay, Asura_StaticMessage_Handler* pxHandler);


	void AddMessage(const Asura_StaticMessage& xMessage);
	void DeleteMessage(u_int uIndex);
	void AllocateMessages(u_int uNumMessages);//allocates some empty messages. Only expected on a new message block

private :

	u_int m_uNumMessages;
	Asura_StaticMessage* m_pxMessages;
};

#endif //__ASURA_STATICMESSAGEBLOCK__
