/*****************************************************************************
 * $Id: mod_pony_water.hh,v 1.1 2006/11/24 21:56:58 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Water objects.
 *//*
 * LEGAL:	COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#if COMPILING_MODULE_PONY
#ifndef MOD_PONY_WATER_HH
#define MOD_PONY_WATER_HH 1

class Lake;

////////////////////////////////////////////////////////////////////////////////
/// @brief Water class.
class Water : public Special
{
private:
	PREVENT_COPYING(Water)
	typedef Special Parent;

public:
	explicit			Water( QuadrantPtrConst q );
	virtual				~Water();
	void				FinalConstruction( void ) { }
	bool				Reproducible( void ) { return true; }
	int					Visible( void ) { return 0; }
	void				Draw( void ) { }
	const string		GetName( void ) { return string("Water"); }
	bool				IfOverWater( const Posrad& posrad ) const;

private:
	void				MakeLakes( QuadrantPtrConst q );

	Dlist<Lake> 		mLakeDlist;
};

////////////////////////////////////////////////////////////////////////////////
/// @brief Lake basis parameters.
///
/// A Lake object is constructed from parameters in LakeBasis.
class LakeBasis
{
	PREVENT_COPYING(LakeBasis)
public:
						LakeBasis( QuadrantPtrConst q, const Water* water, const fp cx, const fp cz );

	enum				{ mPointsMax = 100 };
	short				mPointCnt;			///< elems in points[]
	WorldVertex			mPoints[mPointsMax];///< set of points that is basis of lake shape
	fp					mPointsRadius;		///< radius extending from every point (forming a disc)
	fp					mTileWidth;			///< width of a tile in world coords
	short				mTileDimX;			///< amount of tiles in X dimension
	short				mTileDimZ;			///< amount of tiles in Z dimension
	RectXZ				mRect;				///< encloses radiated points (world coords)
	Posrad				mPosrad;			///< to be assigned to Fixed.center/.radius
	Bool				mValid;
};

////////////////////////////////////////////////////////////////////////////////
/// @brief Lake class.
class Lake : public FixedData
{
private:
	PREVENT_COPYING(Lake)
	typedef FixedData Parent;

public:
						Lake( QuadrantPtrConst q, LakeBasis* lb );
						~Lake();
	void				FinalConstruction( void ) { CalcRadius(); }	// calls Lake::CalcRadius()
	void				Draw( void );
	const string		GetName( void ) { return string("Lake"); }
	void				CalcRadius( void );
	bool				IfOver( const Posrad& posrad );

private:
	void				MakeTiles( void );
	void				SmoothTiles( void );
	uint				ExamineAdjacentTiles( uint* bits/*OUT*/, int x, int z  );
	uint				GetTile( int x, int z );
	int					IsWaterOverTile( const WorldVertex* v );

	LakeBasis*			mLb;
	uint8*				mTiles;
	enum
	{					eLakeTile_DRY			 = 0,	///< no water over tile
						eLakeTile_FULL			 = 1,	///< water fully over tile
						eLakeTile_FULL_ANTIALIAS = 64,	///< water fully over tile (anti-aliased)
						eLakeTile_TRIANGLE		 = 128	///< triangle (half wet, half dry)
	};
	WorldVertex			mWorldVertexsVisiTest[4];
};

#endif // MOD_PONY_WATER_HH
#endif // COMPILING_MODULE_PONY
