/**
 * \file Parser.h
 * \date 30.03.2002
 *
 * Interface for the Parser class
 */

// Poznamka: Tento subor som cely prekopal a vyznam sa v nom. Ak mate
// nejake otazky, spytajte sa ma. Matus

#ifndef MODULES_PARSER_H
#define MODULES_PARSER_H

#ifdef COACH
#	include "Coach/Interfaces/CoachMemory.h"
#	include "Coach/Interfaces/CoachSynchronization.h"
#else  // COACH
#	include "Player/Interfaces/Synchronization.h"
#	include "Player/Interfaces/Tactics.h"
#	include "Player/Interfaces/Memory.h"
#endif // COACH

#include "Common/Interfaces/MsgProcess.h"
#include "Common/Protocol/ParseStructs.h"
#include "Common/Protocol/ServerSocket.h"
#include "Common/Module.h"
#include "Common/Main.h"
#include <stdio.h>

/**
 * \class Parser
 * \author Daniel Novomesky
 * \author Marek Lehuta
 * \brief Message processing task module
 *
 * Processes messages received from the soccer server
 */

class Parser : public Module, public MsgProcessInterface
{
public:
	int CLangParseOpponentHeterotypes(const char * msg);
// Construction and destruction
	Parser();
	virtual ~Parser() {}

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

	virtual int Init(int argc, char **argv, int iTask = -1);
	virtual int ParseMsg(const char *msg);
	
	virtual void SetTeamName(const char *name);
	virtual void SetRealSide(RealSide rs);

protected:
// Operations
	/// Parse brackets
	const char* ParseBracket(const char* str, char* out);
	/// Parse a single object
	const char* ParseObj(const char* str, char* out);

	int ParseScore(const char* msg);
	int ParseInit(const char* msg);
	int ParseHear(const char* msg);
	int ParsePlayerType(const char* msg);
	int ParsePlayerParam(const char* msg);
	int ParseServerParam(const char* msg);
	int ParseChangePT(const char* msg);
	int ParseOk(const char* msg);

#ifdef COACH
	int ParseSeeGlobal(const char* msg);
#else  // COACH
	int ParseSee(const char* msg);
	int ParseSenseBody(const char* msg);
#endif // COACH

#ifndef COACH
	int CLangStripQuotes(const char* str, char* out);
	int CLangParseMsg(const char* msg);
	int CLangParseFreeform(const char* msg);
	int CLangParseDefine(const char* msg);
	int CLangParseDefinerule(const char* msg);
	int CLangParseSetParameter(const char* msg);
	int CLangEvaluateCondition(const char* msg);
	int CLangParseChangeFormation(const char* msg);
#endif // COACH

	void ParseVizParams6(const char* msg, int* entries, float* dist,
		float* dir, float* distChng, float* dirChng, float* bodyDir,
		float* headDir);
	void ParseVizParams4(const char* msg, int* entries, float* dist,
		float* dir, float* distChng, float* dirChng);
	void ParseVizParams2(const char* msg, int* entries, float* dist,
		float* dir);

	/// Parse player information and fill in an AGENT struct
	int ParseSeePlayer(const char* str1, const char* str2, AGENT* agent);

	/// Parse landmark information and fill in an LANDMARK struct
	int ParseSeeLandmark(const char* str, LANDMARK* landmark);

	/// Get flag type from flag info in see message
	FlagType ParseSeeFlagType(const char* str);

	/// Get play mode from play mode string
	PlayMode ParsePlayMode(const char* str);

private:
	/// Team name (max. 31 chars)
	char teamName[32];

#ifndef COACH
	/// Real player side
	RealSide realSide;
#endif // COACH
	
#ifdef COACH
	/// Object implementing memory
	CoachMemoryInterface* memory;
	/// Object implementing synchronization
	CoachSynchronizationInterface* synchro;
#else  // COACH
	/// Object implementing synchronization
	SynchronizationInterface* synchro;
	/// For changing formations
	TacticsInterface* tactics;
	/// For setting variables
	MemoryInterface* memory;
#endif // COACH

};

#endif // MODULES_PARSER_H
