/***************************************************************************
 *   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.             *
 ***************************************************************************/
#include "cell.h"
#include <QPixmap>
#include <QBrush>

Cell::Cell() : m_tileBackground(NormalType), m_player(0), m_monster(0), m_item(0), m_isVisible(false), m_explored(false)
{
}

Cell::~Cell()
{
}

Player *Cell::player() const
{
	return m_player;
}


void Cell::setPlayer (  Player *theValue )
{
	m_player = theValue;
}


Item *Cell::item() const
{
	return m_item;
}


void Cell::setItem ( Item *theValue )
{
	m_item = theValue;
}


QPixmap Cell::pixmap() const
{
	if( m_player  )
		return m_player->sprite();
	else if( m_monster && m_isVisible  )
		return m_monster->sprite();
	else if( m_item  && m_isVisible )
		return m_item->sprite();
	else
		return QPixmap();
}

QBrush Cell::background() const
{
	//NormalType, WaterType, PathType, WallType
	if( !m_explored )
		return Qt::black;
	else if( m_tileBackground == NormalType && m_isVisible )
		return Qt::gray;
	else if( m_tileBackground == WaterType && m_isVisible )
		return Qt::blue;
	else if( m_tileBackground == PathType && m_isVisible )
		return Qt::lightGray;
	else if( m_tileBackground == WallType )
		return Qt::darkGray;
	else if( m_isVisible )
		return QBrush(Qt::green);
	else
		return Qt::black;
}

Cell::TileType Cell::tileBackground() const
{
	return m_tileBackground;
}

Cell::CharType Cell::tileForground() const
{
	if( m_player  )
		return PlayerType;
	else if( m_monster  )
		return MonsterType;
	else if( m_item   )
		return ItemType;
	else
		return EmptyType;
}

void Cell::setTileBackground ( const TileType& theValue )
{
	m_tileBackground = theValue;
}

void Cell::clearPlayer()
{
	m_player = 0;
}

void Cell::clearItem()
{
	m_item = 0;
}


Monster *Cell::monster() const
{
	return m_monster;
}


void Cell::setMonster (Monster *theValue )
{
	m_monster = theValue;
}

void Cell::clearMonster()
{
	m_monster = 0;
}


bool Cell::isVisible() const
{
	return m_isVisible;
}


void Cell::setIsVisible( bool theValue )
{
	m_isVisible = theValue;
	if( m_isVisible && !m_explored)
		m_explored = true;
}

