/**
 * \file CommandGen.h
 * \date 02.03.2002
 *
 * Interface for the CommandGen class
 */

#ifndef MODULES_COMMANDGEN_H
#define MODULES_COMMANDGEN_H

#include "Common/Interfaces/Commands.h"
#include "Common/Interfaces/Communication.h"
#include "Common/Interfaces/MsgProcess.h"
// Toto je asi zle, preco z common includujeme playerov interface, 
// nevadi to coachovi?
#include "Player/Interfaces/Synchronization.h"
#include "Common/Protocol/ServerSocket.h"
#include "Common/World/Types.h"
#include "Common/Module.h"
#include "Common/Main.h"


/**
 * \class CommandGen
 * \author Daniel Novomesky
 * \author Marek Lehuta
 * \brief Commands task module
 *
 * Sends commands by communication task
 */

class CommandGen : public Module, public CommandsInterface
{
public:
// Construction and destruction
	CommandGen();
	virtual ~CommandGen() {}

	virtual void SetRealSide(RealSide rs);

// Interface implementation
	virtual Interface* GetInterface(int iTask = -1) const;

	virtual int Init(int argc, char** argv, int iTask = -1);
//	virtual int SendCommand(int, void*) { return 1; }

	virtual int Dash(float fPower);
	virtual int Turn(float fMoment);
	virtual int Kick(float fPower, float fDirection);
	virtual int Move(float fX, float fY);
	virtual int Catch(float fDirection);
	virtual int Tackle(float power);

	virtual int TurnNeck(int iAngle);
	virtual int Say(const char* pMsg);
	virtual int SenseBody();
#ifdef COACH
	virtual int Eye(const char* onOff);
	virtual int TeamNames();
	virtual int ChangePlayerType(const int uniformNumber, const int type);

//!!!!!!!!! Gridders ad !!!!!!!!!!!!!
	virtual int ChangePlayerNo(int playerNumber, int playerType);
//!!!!!!!!! Gridders ad !!!!!!!!!!!!!

	virtual int TeamGraphic(int i, int j, const char* lines);
#endif // COACH

	virtual int ServerInit(const char* teamName, bool goalie = false, 
		const char* ver = NULL);
	virtual int CLangInit();
	virtual int Reconnect(const char* pTeamName, unsigned uUniformNumber);
	virtual int Bye();

	virtual int Score();
	virtual int ChangeView(ViewWidth iWidth);

protected:
	inline static float RoundFloat(float fVal);

private:
	/// Buffer for sending messages
	char m_outBuff[BUFFERSIZE];
	
	/// Socket for communication
	CommunicationInterface* m_pSocket;
	/// Parser
	MsgProcessInterface* m_pParser;
	/// Synchronization
	SynchronizationInterface* m_pSynchro;
	
	/// Sent message count
	COMMAND_COUNTS m_outCounts;

#ifndef COACH
	/// Real player side
	RealSide realSide;
#endif // COACH

};


/**
 * Round float as in %0.2f
 *
 * \param num Float for rounding
 * \return Rounded num (23.4567 -> 23.45)
 */
float CommandGen::RoundFloat(float num)
{
	return (float) ((int) (100.0f * num)) / 100.0f;
}

#endif // MODULES_COMMANDGEN_H
