/****************************************************************
**
** Attal : Lords of Doom
**
** graphicalFightCell.cpp
** this class draws a hexagonal fightCell 
**
** Version : $Id: graphicalFightCell.cpp,v 1.6 2003/09/27 12:20:57 audoux Exp $
**
** Author(s) : Pascal Audoux - Cyrille Verrier
**
** Date : 07/12/2000
**
** Licence :    
**	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, 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.
**
****************************************************************/

#include "graphicalFightCell.h"

 
// generic include files
#include <stdlib.h>
#include <math.h>
// include files for QT
#include <qpainter.h>
// application specific include
#include "conf.h"
#include "libCommon/genericFightCell.h"
#include "libCommon/log.h"

const int GraphicalFightCell::RTTI = 44;
const double GraphicalFightCell::_sqrt3 = sqrt(3);
const int GraphicalFightCell::_size = 15;

int VShift = 150;
int HShift = 0;

/** this class draws a hexagonal fightCell */
GraphicalFightCell::GraphicalFightCell( int row, int col, QCanvas * canvas, bool horizontalDraw )
	: QCanvasPolygon( canvas )
{
	_horizontal = horizontalDraw;
	setColor( QColor( "grey" ) );

	_pa =  QPointArray(7);
	if( _horizontal ) {
 		_pa[0] = QPoint( int(_size * _sqrt3) , 4 * _size);
		_pa[1] = QPoint( 0, 3 * _size );
		_pa[2] = QPoint( 0,  _size );
		_pa[3] = QPoint( int( _size * _sqrt3), 0 );
		_pa[4] = QPoint( int( 2 * _size * _sqrt3), _size );
		_pa[5] = QPoint( int( 2 * _size * _sqrt3), 3 * _size  );
		_pa[6] = _pa[0];

		if( row % 2 == 0 ) {
			move( int (HShift + 2*_sqrt3*_size*col ), int ( 3*_size*row) + VShift );
		} else {
			move( int (HShift + 2*_sqrt3*_size*(col + 0.5) ), int ( 3*_size*row) + VShift );
		}
	} else {
		_pa[0] = QPoint( 4 * _size, int(_size * _sqrt3) );
		_pa[1] = QPoint( 3 * _size, 0 );
		_pa[2] = QPoint( _size, 0 );
		_pa[3] = QPoint( 0, int(_size * _sqrt3) );
		_pa[4] = QPoint( _size, int(2 * _size * _sqrt3) );
		_pa[5] = QPoint( 3 * _size, int(2 * _size * _sqrt3) );
		_pa[6] = _pa[0];

		if( col % 2 == 0 ) {
			move( int ( 3*_size*col), int (VShift + 2*_sqrt3*_size*row ) );
		} else {
			move( int ( 3*_size*col), int (VShift + 2*_sqrt3*_size*(row+0.5) ) );
		}
	}
	setPoints( _pa );

	setEnabled( true );
	setVisible( true );
	//collisions( true );

	setZ( CAN_F_GROUND );
	show();
}

void GraphicalFightCell::drawShape( QPainter & p )
{
	p.setPen( _color );
	QPointArray array = points();
	array.translate( (int)x(), (int)y() );
	p.drawPolyline( array );
}

QPoint GraphicalFightCell::getCenter()
{
	return boundingRect().center();
}












