/****************************************************************
**
** Attal : Lords of Doom
**
** genericFightMap.h
**  generic class for managing (not graphical) fightMap
**
** Version : $Id: genericFightMap.h,v 1.8 2004/08/01 11:30:19 audoux Exp $
**
** Author(s) : Pascal Audoux - Cyrille Verrier
**
** Date : 02/08/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.
**
****************************************************************/

 
#ifndef GENERICFIGHTMAP_H
#define GENERICFIGHTMAP_H
 
 
// generic include files
// include files for QT
#include <qptrlist.h>
#include <qptrstack.h>
// application specific include
#include "libCommon/genericFightCell.h" 


class PathFightFinder;
class GenericFightUnit;

/*              ------------------------------
 *                         GenericFightMap
 *              ------------------------------ */



/** generic class for managing (not graphical) cells */
class GenericFightMap
{

public:
	/** Constructor */
	GenericFightMap();

	/** Destructor */
	virtual ~GenericFightMap();

	/** Return cell of the fightMap */
	GenericFightCell * at( int i, int j )
		{ return _genericFightCells[i][j]; }

	/** Create new fight map */
	virtual void newFightMap( int h, int w, bool horizontalDraw = false );

	virtual void reinit();

	virtual void initPath( GenericFightUnit * unit );
	void printPath();
	virtual void clearPath();

	QPtrStack<GenericFightCell> computePath( GenericFightUnit * unit, GenericFightCell * cell );

	GenericFightCell * getNeighbour1( GenericFightCell * cell );
	GenericFightCell * getNeighbour2( GenericFightCell * cell );
	GenericFightCell * getNeighbour3( GenericFightCell * cell );
	GenericFightCell * getNeighbour4( GenericFightCell * cell );
	GenericFightCell * getNeighbour5( GenericFightCell * cell );
	GenericFightCell * getNeighbour6( GenericFightCell * cell );

	bool areNeighbours( GenericFightCell * cell1, GenericFightCell * cell2 );

	int getHeight () { return _height; }

	int getWidth () { return _width; }

protected:
	GenericFightCell * giveNeighbourOnPath( GenericFightCell * cell, int dist );

	int _height, _width;
	PathFightFinder * _path;

	bool _horizontalDraw;

	GenericFightCell *** _genericFightCells;
};

/** pseudo-pile of GenericFightCell (in fact, a list..) */
class FightPile : public QPtrList<GenericFightCell>
{
public:
	/** Constrcutor */
	FightPile( GenericFightMap * map, int limit, GenericFightUnit* unit );

	/** \return Returns the 'smallest' cell */
	GenericFightCell * takeSmallest();

	/** Appends neighbours of a cell */
	void appendNeighbours( GenericFightCell * cell );
private:
	void handleNeighbour( GenericFightCell * neighbour, int dist );

	bool testHeadFree( GenericFightCell * cell );

	GenericFightMap * _map;
	int _limit;
	GenericFightUnit * _unit;
};

#endif // GENERICFIGHTMAP_H   
