/*
 * Tile.h
 *
 *  Created on: 2009-07-10
 *      Author: wasyl
 */

#ifndef TILE_H_
#define TILE_H_

#include <allegro5/allegro.h>
#include "../prep/ent/Entity.h"
#include "../prep/res/Sheet.h"
class Level;

class Tile : public Entity
{
enum Lines {L=1, R=2, U=4, D=8, LU=16, LD=32, RU=64, RD=128};

private:
	Sheet *mSheet;
	int mType;
	Level *mLevel;
	int mLines;
	int mX, mY;
	ALLEGRO_COLOR mBlack, mLight, mDark;

	bool differs(int x, int y);
	static bool sTypePresent[10];

public:

	static void setPresent(int type, bool present) { sTypePresent[type] = present; }
	static void resetPresent() { for (int i = 0; i < 10; i++) sTypePresent[i] = true; }

	Tile(int type, Level *level, int x, int y);

	int *indices()
	{
		static int ind[] = {ID("entt"), ID("rndr"), ID("posi"), ID("tile"), 0};
		return ind;
	}

	int order(int index)
	{
		if (index == ID("rndr"))
			return 50;
		else
			return (int)this;
	}

	void setup();
	void render();

	Entity *clone() { return new Tile(mType, NULL, mX, mY); }
	const char *code() { return "tl"; }
	std::string edString() { return SPrintF::format("tile(%d)", mType); };
	void load(FILE *f);
	void save(FILE *f);

	void setLevel(Level *lv, int x, int y) { mLevel = lv; mX = x; mY = y; }

	bool present() { return sTypePresent[mType]; }
};

#endif /* TILE_H_ */
