/*
	Trig Wars.
	Copyright (c) 2008, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef OBSTACLE_MANAGER_H
#define OBSTACLE_MANAGER_H

//=====================================================================================================================
//=====================================================================================================================

#include "GameObjects\GameObjectBase.h"

//=====================================================================================================================
//=====================================================================================================================

namespace Game
{
	//=================================================================================================================
	//=================================================================================================================
	
	class QuadTree;
	class Obstacle;

	//=================================================================================================================
	/// @brief		This class is responsible for randomly generating a series of obstacles and for allowing collision
	///				detection against those obstacles. Obstacles are deformed circular shapes that can be collided
	///				with.
	//=================================================================================================================

	class ObstacleManager : public GameObjectBase
	{
		public:
		
			//=========================================================================================================
			// Constants
			//=========================================================================================================
			
				/// The maximum radius of each obstacle
				
				static const float OBSTACLE_MAX_RADIUS;
				
				/// The minimum radius of each obstacle
				
				static const float OBSTACLE_MIN_RADIUS;
				
				/// The minimum distance obstacles should be from the center of the map where the player spawns
				
				static const float OBSTACLE_MIN_PLAYER_DIST;

			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Creates the obstacle manager with the specified number of obstacles in the level
				
				ObstacleManager( unsigned num_obstacles );
				
				/// Destroys the obstacle manager
				
				virtual ~ObstacleManager();
				
				/// Draw function. Draws all obstacles
				
				virtual void OnDraw( Camera2D * c );
				
				/// Returns the type name for this object

				virtual const char * GetTypeName() const;
				
				/// Returns a list of pointers to obstacles that the given circle collides with
				
				unsigned ObstacleCollide( const Vec2f & circle_pos , float circle_radius , Stack & results_stack , Stack & work_stack  );

		private:
		
			//=========================================================================================================
			// Constants
			//=========================================================================================================
			
				/// Minimum percent of obstacle radius a point in an obstacle can be at from obstacle center
				
				static const float OBSTACLE_PT_MIN_RADIUS_PC;
				
				/// Maximum percent of obstacle radius a point in an obstacle can be at from obstacle center
				
				static const float OBSTACLE_PT_MAX_RADIUS_PC;
				
				/// Minimum number of points an obstacle can have
				
				static const unsigned OBSTACLE_MIN_POINTS;
				
				/// Maximum number of points an obstacle can have
				
				static const unsigned OBSTACLE_MAX_POINTS;
		
			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// A quad tree holding the positions of all the obstacles in the manager
			
				QuadTree * m_quad_tree;
				
				/// An array holding pointers to all of our obstacles
				
				Obstacle ** m_obstacles;
				
				/// The number of obstacles that are in the manager
				
				unsigned m_num_obstacles;
	};
};

#endif
