#ifndef _TETRINET_CPP_H
#define _TETRINET_CPP_H
using namespace std;

class TetrinetServer;
class BlockStatus;

#include <pthread.h>
#include <string>
#include "TetrinetField.h"
#include "blockmap.h"

class BlockStatus
{
public:
	void printBlock();
	int type;
	int x;
	int y;
};

// fuck you very much
extern "C" {
        #include "tclient.h"
}

class MutexLocker
{
public:
	MutexLocker(pthread_mutex_t *m)
	{
		myMutex=m;
		pthread_mutex_lock(myMutex);
	};
	~MutexLocker()
	{
		pthread_mutex_unlock(myMutex);
	};
private:
	pthread_mutex_t *myMutex;
};

class TetrinetServer
{
public:
	TetrinetServer(string host, int port, string name, string team, string channel);
	~TetrinetServer();
	bool startGame();
	bool connected();
	bool rotateClockwise();
	bool rotateAnticlockwise();
	bool dropBlock();
	bool moveLeft();
	bool moveRight();
	bool moveDown();
	void pollEvents();
	TetrinetField getField(int player = -1);
	BlockStatus getCurrentBlock(int player = -1);
	BlockStatus getNextBlock();
	int getOwnPlayer();
	int getMaxSpecials();
	vector<char> getSpecials();
	volatile int linesAdded[6];
	volatile bool fieldValid[6];
protected:
	int ownPlayer;
	
	bool isConnected;
	bool gameOn;
	pthread_mutex_t myMutex;

	// client library fu
	struct TC_GameData *gdata;
};

#endif
