#ifndef HANDLER_H
#define HANDLER_H

#include <ggzdmod.h>
#include <list>

class Level;
class Cell;
class Sprite;
class Item;
class Bomb;
class Blast;
class Player;
class AI_Player;
class KNet;
class Exit;
class Rule;

class Handler
{
	public:
		Handler();
		~Handler();
		void loop();
		static void event(GGZdMod *ggzdmod, GGZdModEvent event, const void *data);

		void dataEvent(GGZdMod *mod, int fd);
		void joinEvent(GGZdMod *mod, int fd);
		void leaveEvent(GGZdMod *mod, int fd);

		enum States
		{
			state_launched,
			state_map,
			state_waiting,
			state_playing
		};

	private:
		void checkStart(GGZdMod *mod);
		void moveMonsters();
		void progress();
		Item *findItem(int x, int y);
		void checkItem(Player *p, bool isplayer);
		bool walkableTile(int x, int y);
		bool placeBlast(int x, int y);
		void createMonster(int count);
		void createMonster(int id, int x, int y);
		void gameOver(bool playerwins);
		static int generator();

		KNet *net;
		Level *level;
		Rule *rules;
		int m_state;
		char *selected_map;
		int selected_bots;
		int selected_players;
		Exit *exit;
		std::list<AI_Player*> monsterlist;
		std::list<Player*> playerlist;
		std::list<Blast*> blastlist;
		std::list<Bomb*> bomblist;
		std::list<Item*> itemlist;
		std::list<Cell*> freecelllist;
};

#endif

