/**
 * \file ParseStructures.h
 * \date 02.03.2002
 * \author Daniel Novomesky
 * \author Marek Lehuta
 *
 * Structures used for parsing server messages
 */

#ifndef COMMON_COMMUNICATION_PARSESTRUCTURES_H
#define COMMON_COMMUNICATION_PARSESTRUCTURES_H

#include "Common/World/Types.h"

#ifdef COACH
#	include "Common/World/Point.h"
#	include "Common/World/Vector.h"
#endif // COACH


/// Number of sent or received commands
struct COMMAND_COUNTS
{
	int kickCount;
	int dashCount;
	int turnCount;
	int sayCount;
	int turnNeckCount;
	int catchCount;
	int moveCount;
	int changeViewCount;
	int tackleCount;
	int attentiontoCount;
	int pointtoCount;
};

struct SENSE_BODY
{
	int time;	///< simulation time from server

	float stamina;
	float effort;
	float speedSize;
	float speedDirection;
	float headAngle;

	/// Number of cycles until tackle expires, 0 if not tackling
	int tackleExpires;

	/// Focused-on player side
	bool focusedSide;
	/// Focused-on player number (0 -> no focus)
	int focusedNumber;

	/// Number of cycles until arm is movable again
	int armMovableAfter;
	/// Number of cycles until arm stops pointing
	int armExpires;
	/// Arm pointing distance
	float armDistance;
	/// Arm pointing direction
	float armDirection;

	ViewQuality viewQuality;
	ViewWidth viewWidth;

	COMMAND_COUNTS counts;
};

/// One line from visual information
struct LINE
{
	/// Line distance
    float dist;
	/// Line direction
    float dir;

    LineType type;
};

/// One flag in visual information
struct LANDMARK
{
	/// Is this whole record valid?
	bool valid;

	/// Landmark distance
    float dist;
	/// Landmark direction
    float dir;
    /// Distance validity
	bool distValid;

	/// Landmark distance change
    float distChange;
	/// Landmark direction change
    float dirChange;
	/// Are dir and dist changes valid?
	bool changesValid;

    FlagType type;
};

/// Player in visual information
struct AGENT
{
	/// Is this whole record valid?
	bool valid;

    /// Player number, 0 if unknown
    int uniformNumber;
	/// Is player goalie?
    bool goalie;

    /// Distance to player
	float dist;
    /// Direction to player (always valid)
	float dir;
    /// Distance to player validity
	bool distValid;

	/// Distance change   
	float distChange;
	/// Direction change   
    float dirChange;
	/// Are dir and dist changes valid?
	bool changesValid;

	/// Body direction
    float bodyFacingDir;
	/// Head direction
    float headFacingDir;
	/// Are body and head directions valid?
	bool facingValid;

	/// Player arm direction
	float armDir;
	/// Player arm direction validity
	bool armValid;
};

/// Whole visual information
struct VISUAL_INFO
{
	int time;				///< Simulation time from server

	int oursCnt;			///< Number of friends in VI
	AGENT ours[10];
	int theirCnt;			///< Number of opponents in VI
	AGENT their[11];
	int unknownCnt;			///< Number of unknown players in VI (too distant)
	AGENT unknown[21];
	int nearbyCnt;			///< Number of unknown players in VI (within 3 meters)
	AGENT nearby[21];

	int lineCnt;			///< Number of lines
	LINE lines[4];
	int landmarkCnt;		///< Number of flags
	LANDMARK landmarks[55];

	LANDMARK ball;
	int ballCnt;			///< 0 -> ball info is not valid
};

#ifdef COACH
/// Ball in coach's visual information
/// \author Peter Trebaticky
struct COACH_BALL
{
    /// Ball's absolute coordinates
	Point pos;
	/// Ball's speed in x and y direction [meters/cycle]
	Vector speed;
};

/// Player in coach's visual information
/// \author Peter Trebaticky
struct COACH_PLAYER
{
    /// Player number
    int uniformNumber;
	/// Is player goalie?
    bool goalie;

    /// Player's absolute coordinates
	Point pos;
	/// Player's speed in x and y direction [meters/cycle]
	Vector speed;
	/// Body direction
    float bodyFacingDir;
	/// Head direction
    float headFacingDir;
};

/// Whole visual information for coach
/// \author Peter Trebaticky
struct COACH_VISUAL_INFO
{
	int time;				///< Simulation time from server

	int oursCount;			///< Number of our players
	COACH_PLAYER ours[11];
	int theirCount;			///< Number of opponent's players
	COACH_PLAYER their[11];

	COACH_BALL ball;		///< Ball 
};
#endif // COACH


#endif // COMMON_COMMUNICATION_PARSESTRUCTURES_H
