/**
 * \file PlayerTactics.h
 * \date 08.05.2002
 *
 * Interface for the PlayerTactics class
 */
//#define PASS_TRAINING
//#define TACKLE_TRAINING
#ifndef MODULES_PLAYERTACTICS_H
#define MODULES_PLAYERTACTICS_H

#include "Player/PlayerSkills.h"
#include "Common/Main.h"
#include "Formation.h"
#include "Player/Interfaces/Tactics.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();
	FILE *subor;
	FILE *drib;
	bool FM_tacklebool;
	Vector FM_tacklevek;
// GP
	

	void OnInit(RealSide realSide, unsigned uniform, PlayMode iMode);
	virtual Interface* GetInterface(int task) const;
	
// Operations
	/// \return player that is most suitable for a pass; -1 -> no player is
	int GetPassAbleFriend();

	/// \return is player offside?
	bool InOffsidePos(float) const;
	/// \return offside line location
	float GetOffsideLine() const;
	int FM_GetFarthestFriend(Point &target);
	int FM_GetNearestEnemy();
	int FM_GetNearestEnemy(Point &pos);
	int FM_GetFreeFriendNear(Point &target);
	int FM_GetNearestFriend(Point &target);
	int FM_GetRandomFriend(const Point &target);
	/// \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();
	bool FM_SimulateShouldKickOnGoal(Vector futureballvel, Point futureballpos,Vector futuremyvel,Point futuremypos);
	float DistanceToGoal(const Point&) const;

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

	bool SmartDribleTo(const Point&);
	bool ShortKick(const Point&);
	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 nearest opponent
	float GetNearestEnemyDistance(const Point& target);
	/// Get nearest friend player index
	int GetNearestFriend(const Point& target);
	/// \return distance to nearest friend
	float GetNearestFriendDistance(const Point& target);
	/// \return distance to ball
	float GetPlayerBallDistance(int who);
	
	/// Pass to running player
	bool PassIntoRun();
	/// 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);

private:
	Formation m_cFormation;
	float FM_superoffset;
	//int FM_Time;
    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;

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

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

public:
	int FM_GetNearestFriendStandard(Point &target);
	int FM_GetNearestEnemyStandard(Point &target);
	void KickToGoal3();
	
	int FCGetPassAbleFriend(bool *run);
	void RealToBin(double num, double* buff);
	//FCNetwork	*m_PassNet;
//***************Peter***********************************	
//	FILE *subor;
	FM_Network *FM_net;//------------
	FM_Network *FM_NeuroTackle;
	//int FM_Time;
//	Point FM_runto;

};

#endif// MODULES_PLAYERTACTICS_H
