/*
	Lan Wars.
	Copyright (c) 2009, 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 GAME_ROCKET_H
#define GAME_ROCKET_H

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

#include "GameObjects\PositionalObject.h"

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

namespace Game
{
	//=================================================================================================================
	//=================================================================================================================
	
	class SpriteAnimation;
	class GameMap;
	class GamePlayer;
	class GameEnemy;

	//=================================================================================================================
	/// @brief		This class represents a rocket. Rockets are not owned by anything and are always created first
	///				on the server.
	//=================================================================================================================

	class GameRocket : public PositionalObject
	{
		public:		
		
			//=========================================================================================================
			// Constants
			//=========================================================================================================
			
				/// Speed at which rockets move
				
				static const float SPEED;
				
				/// Amount of damage that the rocket does
				
				static const float DAMAGE;
				
				/// Damage radius: damage decreases as the rocket gets further away
				
				static const float DAMAGE_RADIUS;
				
				/// Collision radius for the rocket: collides with walls and other objects when within this radius
				
				static const float COLLISION_RADIUS;
				
				/// Damage force: force that is applied to objects that get damaged

				static const float SPLASH_FORCE;
				
				/// Damage amount in health: amount of damage that a rocket does
				
				static const float SPLASH_DAMAGE;
				
				/// How much to scale the y component of splash force
				
				static const float SPLASH_Y_SCALE;
				
			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Constructor. Creates the rocket.
				
				GameRocket
				( 
					const Vec3f &	position , 
					const Vec3f &	direction , 
					unsigned		net_id = NetObject::NET_ID_INVALID , 
					GamePlayer *	owner = 0
				);

				/// Destructor.

				~GameRocket();
				
				//=====================================================================================================
				/// @brief		Tells the object to announce it's type name: this is the type name without the 
				///				Game:: namespace
				/// @returns	The type name of the object.
				//=====================================================================================================
				
				virtual const char * GetTypeName() const { return "GameRocket"; }
				
				/// Update function. called once for every frame. 
				
				virtual void OnUpdate( float time_delta );

				/// Draws the rocket
				
				virtual void OnDraw( Camera3D * c );
				
				/// Called when the object is added into the game
				
				virtual void OnGameAdded();
				
				/// Called when the object is removed into the game
				
				virtual void OnGameRemoved();

				//=====================================================================================================
				/// @brief		Returns the direction the rocket is travelling in
				/// @returns	Direction of the rocket
				//=====================================================================================================
				
				inline const Vec3f & GetDirection() const { return m_direction; }
				
		private:
		
			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Checks if the rocket collides with the world: returns true if it is
				
				bool CheckWorldCollision();
				
				/// Checks if the rocket collides with players: returns true if it is
				
				bool CheckPlayerCollision();

				/// Checks if the rocket collides with enemies: returns true if it is

				bool CheckEnemyCollision();
				
				/// Server only: does splash damage against players
				
				void SplashDamagePlayers();

				/// Server only: does splash damage against enemies

				void SplashDamageEnemies();

				/// Server only: does a raycast to the given enemy and checks if the enemy can hear us from our current position

				bool CanEnemyHearRocket( GameEnemy * enemy );
		
			//=========================================================================================================
			// Variables
			//=========================================================================================================
				
				/// Direction the rocket is moving in
				
				Vec3f m_direction;
				
				/// Sprite for the rocket
				
				SpriteAnimation * m_sprite;
				
				/// The doom level:
				
				GameMap * m_map;
				
				/// Game player that owns the rocket: only used on the server to avoid collisions with the firer
				
				GamePlayer * m_owner;
	};
};

#endif
