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

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

#include "GameObjects\AttackingEnemy.h"

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

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

	class Camera2D;
	class AIManager;

	//=================================================================================================================
	/// @brief		Represents the predator enemy. Predators actively hunt the player, even when they are not 
	///				offscreen. 
	//=================================================================================================================

	class EnemyPredator : public AttackingEnemy
	{
		public:
		
			//=========================================================================================================
			// Enums
			//=========================================================================================================		
		
				/// Current goal of the wasp
				
				enum Goal
				{				
					/// Predator is hunting the player
					
					GOAL_HUNTING	, 
					
					/// Predator is attacking the player when offscreen
					
					GOAL_ATTACK , 
					
					/// Predator is moving to a point away from the player before attacking again
					
					GOAL_ATTACK_REST , 
					
					/// Used when the player is dead: predator simply keeps moving in current direction
					
					GOAL_MOVE_STRAIGHT
				};

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

				/// Amount of linear acceleration the enemy predator has

				static const float LIN_ACCELERATION;

				/// Amount of angular acceleration the enemy predator has

				static const float ANG_ACCELERATION;				
				
				/// Size of the enemy predator
				
				static const Vec2f SIZE;
				
				/// Color of this enemy

				static const Color SHAPE_COLOR;				

			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				/// Constructor: creates a predator at position 0,0. This object is designed to be pooled, hence the 
				/// lack of a more definite constructor.
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				
				EnemyPredator( 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; }
				
				/// Resets the state of the predator, health, goal etc.
				
				void ResetState();
				
				/// Gets the score given for killing this object
				
				virtual float GetKillScore(){ return 1000.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 hunt goal
				
				static const float GOAL_HUNTING_CHANGE_TIME;
				
				/// Maximum amount of time the predator can be in the attack goal until a goal change
				
				static const float GOAL_ATTACK_CHANGE_TIME;			
				
				/// Distance the predator has to be from the player for the predator to disengage attack for a while
				
				static const float GOAL_ATTACK_BACKOFF_DISTANCE;	
				
				/// Distance the predator will try to move away from the player when disengaging attack
				
				static const float REST_FALLBACK_DISTANCE;
				
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				/// Time it takes to change from the attack rest goal: if the predator reaches its goal point 
				/// before then however this time may be terminated. It is there simply to ensure the predator does
				/// not spend too much time resting after attacking the player.
				//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				
				static const float GOAL_ATTACK_REST_CHANGE_TIME;

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

				static const Vec3f SHAPE_POINTS[];
				
			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Updates the goal of the predator
				
				void UpdateGoal( float time_delta );
				
				/// Does the move straight goal:
				
				void DoMoveStraight( float time_delta );
				
				/// Does the hunt player goal
				
				void DoHunting( float time_delta );
				
				/// Does the attack run for the predator
				
				void DoAttack( float time_delta );
				
				/// Does the attack rest goal for the predator
				
				void DoAttackRest( float time_delta );
				
				/// Picks a point to move to when the enemy is taking a little break from attacking
				
				void PickAttackRestGoalPoint();

			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// Current goal of the predator
				
				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 moving to when backing off from the player in the attack rest goal
				
				Vec2f m_attack_rest_goal_pt;
	};
};

#endif
