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

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

#include "GameObjects\AttackingEnemy.h"

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

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

	class Camera2D;
	class AIManager;

	//=================================================================================================================
	/// @brief		Represents a wasp interceptor enemy. Wasps swarm towards the player and try to intercept the players
	///				future position when up close.
	//=================================================================================================================

	class EnemyWasp : public AttackingEnemy
	{
		public:
		
			//=========================================================================================================
			// Enums
			//=========================================================================================================		
		
				/// Current goal of the wasp
				
				enum Goal
				{
					/// Wasp is wandering about on the map
					
					GOAL_WANDER	, 
					
					/// Wasp is swarming towards the player in a group with other wasps
					
					GOAL_SWARM , 
					
					/// Wasp is trying to intercept the player when up close
					
					GOAL_INTERCEPT
				};

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

				/// Amount of linear acceleration the enemy wasp has

				static const float LIN_ACCELERATION;

				/// Amount of angular acceleration the enemy wasp has

				static const float ANG_ACCELERATION;				
				
				/// Size of the enemy wasp
				
				static const Vec2f SIZE;			

				/// Color of this enemy

				static const Color SHAPE_COLOR;				

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

				/// Draw function. Draws this type of enemy 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 wasp if wandering
				
				inline Vec2f GetWanderPoint(){ return m_wander_point; }
				
				/// Resets the state of the wasp, health, goal etc.
				
				void ResetState();
				
				/// Gets the score given for killing this object
				
				virtual float GetKillScore(){ return 100.0f; }
				
		private:

			//=========================================================================================================
			// Constants
			//=========================================================================================================
		
				/// Time it takes for a wasp to fade in
				
				static const float FADE_IN_TIME;
				
				/// Time it takes to change from the wandering goal
				
				static const float GOAL_WANDER_CHANGE_TIME;
				
				/// Time it takes to change from the swarm goal to another
				
				static const float GOAL_SWARM_CHANGE_TIME;
				
				/// Time it takes to change from the intercept goal to another
				
				static const float GOAL_INTERCEPT_CHANGE_TIME;

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

				static const Vec3f SHAPE_POINTS[];
				
				/// Distance to the player at which the wasp will try to intercept the player

				static const float INTERCEPT_DISTANCE;
				
				/// How far the enemy looks ahead into the future when trying to intercept the player's ship and plotting players future position
				
				static const float INTERCEPT_LOOKAHEAD_TIME;
				
			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Updates the goal of factory
				
				void UpdateGoal( float time_delta );
				
				/// Does the wandering goal
				
				void DoWandering( float time_delta );
				
				/// Does the swarming goal
				
				void DoSwarming( float time_delta );

				/// Does the intercept goal
				
				void DoIntercept( float time_delta );

			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// Current goal of the wasp
				
				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;
	};
};

#endif
