#ifndef __level_h__
#define __level_h__
#include "Wumbo-Scene.h"
#include <string>
#include <vector>
#include "Batch.h"
#include "Entity.h"

const unsigned int RT_OUTSIDE = 0;
const unsigned int RT_UNDERGROUND = 1;
const unsigned int RT_NULL = 2;
const unsigned int RT_MAGIC = 3;

const unsigned int VC_DEFAULT = 0;
const unsigned int VC_BIRD = 1;
const unsigned int VC_SCRIBBLE = 2;

const unsigned int TILE_NONE = 0;
const unsigned int TILE_ROCK = 1;
const unsigned int TILE_HOLE = 2;
const unsigned int TILE_LIGHT = 3;
const unsigned int TILE_BRICK = 4;
const unsigned int TILE_BRICKWINDOW = 5;
const unsigned int TILE_DOOR = 6;
const unsigned int TILE_DIRT = 7;
const unsigned int TILE_FENCE = 8;
const unsigned int TILE_STAIRSUP = 9;
const unsigned int TILE_STAIRSDOWN = 10;
const unsigned int TILE_WHOOSHDOOR = 11;
const unsigned int TILE_SPIKE = 12;
const unsigned int TILE_TREE = 13;
const unsigned int TILE_SKULL = 14;

const unsigned int TILE_SIGN = 20;
const unsigned int TILE_BIRD = 21;
const unsigned int TILE_SCRIBBLE = 22;
const unsigned int TILE_GRAVESTONE = 23;
const unsigned int TILE_BOOKSHELF = 24;

const unsigned int TILE_OUTOFBOUNDS = 65535;

inline bool tileIsSolid(int type)
{
	switch(type)
	{
	case TILE_ROCK: case TILE_BRICK: case TILE_BRICKWINDOW: case TILE_FENCE: case TILE_DIRT: case TILE_SPIKE: case TILE_TREE: case TILE_SKULL: case TILE_OUTOFBOUNDS:
	case TILE_SIGN: case TILE_BIRD: case TILE_SCRIBBLE: case TILE_GRAVESTONE: case TILE_BOOKSHELF:
		return true;
	}
	return false;
}

inline bool tileIsBlocking(int type)
{
	switch(type)
	{
	case TILE_NONE: case TILE_FENCE: case TILE_SIGN: case TILE_WHOOSHDOOR: case TILE_SPIKE: case TILE_HOLE: case TILE_SKULL: case TILE_OUTOFBOUNDS:
		return true;
	}
	return false;
}

inline bool tileIsTransport(int type)
{
	switch(type)
	{
	case TILE_DOOR: case TILE_STAIRSDOWN: case TILE_STAIRSUP:
		return true;
	}
	return false;
}

inline bool tileIsTalker(int type)
{
	switch(type)
	{
	case TILE_SIGN: case TILE_BIRD: case TILE_SCRIBBLE: case TILE_GRAVESTONE: case TILE_BOOKSHELF:
		return true;
	}
	return false;
}

class Transport
{
public:
	Transport(int _x, int _y, char *_name, int _destX, int _destY);
	bool isAtGridPosition(int x, int y);
	int x;
	int y;
	int w;
	int h;
	char *name;
	int destX;
	int destY;
};


typedef struct {
	int voice;
	std::string text;
} TalkerPhrase;

#include "Talker.h"
class Rabbit;
class Level : public Wumbo::Scene
{
public:
	static unsigned int lastRoomType;
	bool displayingDialog;
	std::string PREPARETRANSFER_name;
	int PREPARETRANSFER_x;
	int PREPARETRANSFER_y;
	int PREPARETRANSFER_animate;

	int cameraXoffset;
	int cameraYoffset;



	std::string levelname;
	unsigned int roomType;
	Rabbit *rabbit;
	std::vector<Entity*> entities;
	int startX, startY;
	std::string startName;
	int startRot;
	bool startFall;
	int talkPosition;
	int talkTicker;

	std::vector<TalkerPhrase> phrases;
	std::vector<Transport> transports;
	std::vector<Talker> talkers;
	Batch *model;
	unsigned int *data;
	int width;
	int height;
	Level(Wumbo::Program *prog, std::string name, int x, int y, bool fall, int rot);
	~Level();
	void set(int x, int y, unsigned int tile);
	unsigned int get(int x, int y);



	void begin();
	void update();
	void render();

	void addPhrase(std::string text, int voice);
};
#endif