/*
	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 ENEMY_FACTORY_H
#define ENEMY_FACTORY_H

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

#include "GameObjects\AIControlled.h"

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

namespace Game
{
	//=================================================================================================================
	//=================================================================================================================

	class Camera2D;
	class AIManager;

	//=================================================================================================================
	/// @brief		Represents one factory ship enemy. Factories wander at random until they encounter the player and
	///				flock to avoid the player. They also spawn wasp interceptors.
	//=================================================================================================================

	class EnemyFactory : public AIControlled
	{
		public:
		
			//=========================================================================================================
			// Enums
			//=========================================================================================================		
		
				/// Current goal of the factory
				
				enum Goal
				{
					/// Factory is wandering randomly from point to point
					
					GOAL_WANDER	, 
					
					/// Factory is trying to flee from the player
					
					GOAL_FLEEING
				};

			//=========================================================================================================
			// Constants
			//=========================================================================================================

				/// Amount of linear acceleration the enemy factory has

				static const float LIN_ACCELERATION;

				/// Amount of angular acceleration the enemy factory has

				static const float ANG_ACCELERATION;				
				
				/// Size of the enemy factory
				
				static const Vec2f SIZE;
				
				/// Color of this enemy in unsigned format

				static const Color SHAPE_COLOR;								

			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				/// Constructor: creates a factory at position 0,0. This object is designed to be pooled, hence the 
				/// lack of a more definite constructor.
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				
				EnemyFactory( AIManager * m );

				/// Draw function. Draws the player ship

				virtual void OnDraw( Camera2D * c );
				
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				/// This is a more optimised version of the OnDraw() function which uses the buffered line 
				/// rendererer from the game. It is used for batch rendering of these enemy types.
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

				virtual unsigned BufferedDraw( Stack & s , const Vec2f & cam_pos , float z );

				/// Does AI and movement

				virtual void OnUpdate( float time_delta );

				/// Returns the type name for this object

				virtual const char * GetTypeName() const;				
				
				/// Gets the current goal of the factory
				
				inline Goal GetGoal(){ return m_current_goal; }
				
				/// Gets the current wander point of the factory if wandering
				
				inline Vec2f GetWanderPoint(){ return m_wander_point; }
				
				/// Resets the state of the factory, health, goal etc.
				
				void ResetState();
				
				/// Gets the score given for killing this object
				
				virtual float GetKillScore(){ return 500.0f; }														
				
		private:

			//=========================================================================================================
			// Constants
			//=========================================================================================================
			
				/// Minimum time in between spawning wasp enemies for the factory
				
				static const float WASP_SPAWN_INTERVAL_MIN;
				
				/// Maximum time in between spawning wasp enemies for the factory
				
				static const float WASP_SPAWN_INTERVAL_MAX;
				
				/// Minimum time in between spawning predator enemies for the factory
				
				static const float PREDATOR_SPAWN_INTERVAL_MIN;
				
				/// Maximum time in between spawning predator enemies for the factory
				
				static const float PREDATOR_SPAWN_INTERVAL_MAX;
				
				/// Minimum radius to spawn away from the factory
				
				static const float SPAWN_RADIUS_MIN;
				
				/// Maximum radius to spawn away from the factory
				
				static const float SPAWN_RADIUS_MAX;			
		
				/// Time it takes for a factory to fade in
				
				static const float FADE_IN_TIME;
				
				/// Time it takes to change from the wandering goal to another
				
				static const float GOAL_WANDER_CHANGE_TIME;
				
				/// Time it takes to change from the fleeing goal to another
				
				static const float GOAL_FLEEING_CHANGE_TIME;

				/// Points that make up the shape of the ship;

				static const Vec3f SHAPE_POINTS[];

			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Updates the goal of factory
				
				void UpdateGoal( float time_delta );
				
				/// Does the wandering goal
				
				void DoWandering( float time_delta );
				
				/// Does the fleeing goal
				
				void DoFleeing( float time_delta );
				
				/// Does spawning for the enemy if it can spawn:
				
				void DoSpawning( float time_delta );							

			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// Current goal of the factory
				
				Goal m_current_goal;

				/// Amount of time this enemy has to fade in
				
				float m_fade_in_time_left;
				
				/// Amount of time left till the next goal change
				
				float m_goal_change_time_left;
				
				/// Current point we are wandering to
				
				Vec2f m_wander_point;
				
				/// Amount of time till the next spawn can be done
				
				float m_time_till_spawn;
	};
};

#endif
