/**
 * \file PlayerCommunication.h
 * \date 22.11.2002
 * \author Pavol Misik
 * interface for the CPlayerCommunication class.
 */
#if !defined(_PLAYER_COMMUNICATION_H_)
#define      _PLAYER_COMMUNICATION_H_

#include "Player/World/World.h"


class PlayerCommunication  
{
public:
	void DefaultMessage(World *world);
	
	void Send(char* msg);
	enum {sign_bit = 0x10, 
		  enemy_bit=0x10};
	/// \enum zadefinovane typy sprav
	enum message_types{
		msg_za_tebou =0,	///< sprava za tebou
		msg_pusti,			///< indikuje, ze hrac nema chytat loptu
		msg_prihraj,		///< indikuje, ze hrac si pyta nahravku
		msg_bez,			///< indikuje, aby hrac bezal
		msg_chytaj,			///< indikuje, aby hrac chytal prihravku
		msg_mam,			///< indikuje, ze hrac ma loptu
		msg_default			///< standardna StjupitDox sprava
	};

	PlayerCommunication();
	virtual ~PlayerCommunication();
	void Init(int maximumMessageSize);
	
	bool GetMessage(char*& pszMsg, World* w);
	void OnHear(const char* pOdkaz, unsigned Sender, World* world);	///< spracovanie sprav OnHear
	void SMam(Point pos, Vector vel);
	void SChytaj(Point pos, unsigned int nPlayer);
	void SBez(Vector vel, unsigned int nPlayer);
	void SPrihraj(Point pos, unsigned nPlayer);
	void SPusti(Point pos, unsigned nPlayer);
	void SZaTebou(Point pos, Vector vel, unsigned number);

	Log *log;
	int m_nStepsOurHaveBall;
protected:
	void DecodeMsgPVP(const char *msg, Point &pos, Vector &vel,unsigned int &num, bool &bEnemy);
	void DecodeMsgPP(const char *msg, Point &pos, unsigned &num, bool &bEnemy);
	void DecodeMsgPV(const char *msg, Point &pos, Vector &vel);
	char GetMessageId(const char* pszMsg);
	char DecodePlayerNumber(char coded, bool &bEnemy );	///< dekoduje cislo hraca
	char EncodePlayerNumber(char, bool bEnemy);			///< zakoduje cislo hraca
	bool EncodePosition(Point &x, char *msg);			///< zakoduje poziciu do retazca
	void DecodePosition(const char *szMsg, Point &x);	///< dekoduje poziciu z retazca
	bool EncodeVector(Vector &vect, char *szMsg);		///< zakoduje vektor do retazca
	void DecodeVector(const char *szMsg, Vector &x);	///< dekoduje vektor z retazca
	float DecodeFloat(const char* msg);					///< dekoduje realne cislo
	char DecodeByte(unsigned char ch);					///< dekoduje "znak"
	char EncodeByte(unsigned char);						///< zakoduje znak
	bool EncodeFloat(float value, char *msg);			///< dekoduje realne cislo
	
	
private:
	char m_szSayHash[75];								///< hashovacia tabulka pre kodovanie
	char m_szHearHash[256];								///< dekodovacia tabulka pre kodovanie
	char *m_pszMessage;									///< sprava na dosolanie
	bool m_bHaveMsg;									///< indikuje, ci mam co poslat
	
};
#endif // !defined(_PLAYER_COMMUNICATION_H_)




