/***************************************************************************
 *   Copyright (C) 2004 by ian reinhart geiser                             *
 *   ian@geiseri.com                                                       *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BOARDMODEL_H
#define BOARDMODEL_H

#include <QAbstractTableModel>
#include <QVector>
#include <QList>

#include "cell.h"
#include "monster.h"
#include "player.h"
#include "item.h"
#include "reference.h"

/**
Model for the game board.

	@author ian reinhart geiser <ian@geiseri.com>
*/
class BoardModel : public QAbstractTableModel
{
Q_OBJECT
public:
	BoardModel(QObject *parent = 0);

	~BoardModel();

	virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
	virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
	virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
	virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

	virtual bool loadMap( const QString &mapName );
	virtual void generateMap( int width, int height );

	int boardIndex( int X, int Y ) const;

	void addPlayer( Player *player, int Xpos, int Ypos );
	void addMonster( Monster *monster, int Xpos, int Ypos );

	int monsterAtPoint( int Xpos, int Ypos ) const;

public slots:
	void movePlayerUp();
	void movePlayerDown();
	void movePlayerLeft();
	void movePlayerRight();

signals:
	void playerDead();
	void status( const QString &message);

private:
	void updatePosition(int oldX, int oldY, int newX, int newY );
	void updateView( int newX, int newY );
	void updateMonsters( );
	void resetModel();

	QVector<Cell> m_board;
	QList< Monster *> m_monsters;
	QList< Item *> m_items;
	Player *m_player;
};

#endif

