/**
 * \file PlayerTactics.h
 * \date 08.05.2002
 *
 * Interface for the PlayerTactics class
 */

#ifndef MODULES_PLAYERTACTICS_H
#define MODULES_PLAYERTACTICS_H

#include "Player/PlayerSkills.h"
#include "Common/Main.h"
#include "Formation.h"
#include "Player/Interfaces/Tactics.h"
#include "PlayerExperience.h"

//#define KICKIN_DBGN DBGN
#define KICKIN_DBGN DO_NOTHING

/**
 * \class PlayerTactics
 * \author Daniel Novomesky
 * \author Martin Zuzcak
 * \author Marek Lehuta
 * \brief PlayerTactics module
 */
class PlayerTactics : public PlayerSkills, public TacticsInterface 
{
public:
// Construction and destruction
	PlayerTactics();
	virtual ~PlayerTactics();

// GP
	void OnInit(RealSide realSide, unsigned uniform, PlayMode iMode);
	virtual Interface* GetInterface(int task) const;

// Operations
	/// \return is player offside?
	bool InOffsidePos(float) const;
	/// \return offside line location
	float GetOffsideLine() const;

	/// \return is player responsible for the ball?
	//bool DependentForBall() const;

protected:
	virtual void BehaveWithBall();
	virtual void BehaveWithoutBall();
	virtual void BehaveWithBallGoalie();
	virtual void BehaveWithoutBallGoalie();

	virtual Point GetHomePos();

	void ExitOffside();

	/// returns NULL if enemy's goalie is not in this player's world
	Player* GetEnemyGoalie() const;

	bool ShouldKickOnGoal();

	/// No enemies are around, so dribble
	bool NoEnemiesAround() const;

	float GetKickPower(const Point& ciel, int steps);

	/// \return does an enemy block our pass to given place?
	bool IsBlockingEnemy(const Point& target);

	// Try to unblock myself from receiving a pass
	bool UnblockMyself(Vector* shift);

	/// \return distance to ball
	float GetPlayerBallDistance(int who);

	/// Run to a tactical position or watch the ball if already there
	void Patrol();
	/// \return is given place offside?
	bool IsOffsidePosition(Point target);

	/// \return is our player nearest to the ball?
	bool IsOurBall();
	/// Go to the best place where someone could pass the ball to you
	bool GotoPositionToPass();

	/// Should we kick the ball in when it is not PlayOn?
	virtual bool ShouldKickIn();

	/// Change play mode handler
	virtual void OnChangeMode(int time, PlayMode mode);

    // GP
    void ChangeFormation(const char* formation);

	// shoot on goal, with making experience (L.Fazekas)
	void KickToGoal4(float p_Probability, Point Target);

	void OnSenseBody(const SENSE_BODY* sb);
	void OnGoal(bool p_WeGaveTheGoal);

	// get number o cycles in which we are awaiting goal
	int GetCyclesToPossibleGoal();

	// zisti, ci je hrac prilis blizko superovho brankara
	bool AmITooCloseToEnemyGoalie(Player* enemyGoalie);

	// uskutocni nahravku naslepo (ked sme prilis blizko brankara)
	void TooCloseToGoalieBlindPass(Player* enemyGoalie);

	// zisti ci nastala situacia: nevidim spoluhraca a som vo vyhradenom sektore pred superovou brankou
	bool NoTeammateFoundAndInSector(int teammate);

	// zahratie lopty hracom (volne kopy, rohove kopy, ...)
	void KickIn();

	// vyhodnoti, ci je vhodne vystrelit; a ak ano, tak vystreli
	// vrati true ak vystrelit; ak nevystrelil, vrati false
	bool ShootOnGoalIfAdequate();

	// driblovanie vo funkcii BehaveWithBall (nevidime spoluhraca a nie je vhodne vystrelit)
	void BehaveWithBallDribble();

	// iba predvadzacia funkcia vracajuca pravdepodobnost golu napevno
	float PredvadzaciaProbability();

	/// Dribbling
	bool WaitingDribble();				//vyckavacia klucka
	bool SmartDribleTo(const Point&);	//kryjeme si loptu pred supermi a postupujeme k brane
	bool ShortKick(const Point&);		//predkopavame si loptu
	bool is_dribbling;					//posledna faza vyckavacej klucky
	bool is_waiting;					//sme v stave cakania pri vyckavacej klucke
	int  dribbling_against;

private:
	Formation m_cFormation;

    int GetFormation(const char* formation);
    int GetUnit(int PlayerCount, char type);

	/// Current angle for scanning before kick off
	float scanBeforeKickOffAngle;

	/// Ignore the ball while goalie has a free kick
	bool letGoalieRest;

	// player experience
	PlayerExperience m_PlayerExperience;

//*********************************************************** FC Mirio a Ajvn

#ifdef PASS_TRAINING
	char	FFileName[20];
	FILE	*ff;
	bool	chytilsom;
#endif

public:
	
	int FCGetPassAbleFriend();
	void RealToBin(double num, double* buff);
	FCNetwork	*m_PassNet;

};

#endif // MODULES_PLAYERTACTICS_H
