#ifndef MAP_H
#define MAP_H

#include "base_types.h"

// Maximum map is 65530 x 65530 because qHash may be repeat and towers has same Id

class Map : public QObject
{
Q_OBJECT
public:
	enum CellType
	{
		Player = 1,
		PlayerAlien = 1001,
		PlayerTower = -1,
		Wall = -1000,
		Start = 9999,
		Finish = 8888
	};
	// 1 - free for player 1
	// 2 - free for player 2
	// 3 - -/-
	// 1001 - player 1, free, but it is alien path (for optimization)
	// 1002 - -/-
	// 99999 - start field or finish field
	// -1 - player 1 tower
	// -2 - player 2 tower
	// -3 - -/-
	// -1000 - it is wall or some place where you can't build


	explicit Map(QByteArray data, QSize size, QString name, int maxPlayers, int image, QObject *parent = 0);
	bool addTowerOnMap(int playerId, QPoint pos);
	bool isFreePlace(QPoint pos);
	void delTowerOnMap(QPoint pos);
	void removeAliensPath();
	QVector <QPointF> CreatePath(QPoint start, QPoint finish);
	QRect Rect() const {return QRect(QPoint(),mapSize);}
//	QString name() const {return mapName;}
	QList <QPoint> Starts() const {return starts;}
	QList <QPoint> Finishs() const {return finishs;}
	int Image() const {return imageType;}
signals:
	void RecreateAlienPath(bool * pathOK);
public slots:
	void printMap();

private:
	QSize mapSize;
	QString mapName;
	int players;
	int imageType;
	QVector < QVector <int> > Cells;
	QList <QPoint> starts;
	QList <QPoint> finishs;

	QVector < QVector <int> > TmpCells;

	QVector<QPoint> InvWaveTrace(QPoint finish, int cnt);
	int WaveTrace(QPoint start, QPoint finish);
	//void CreateMapExample();
	//void ReadSettings();
};

#endif // MAP_H
