/*
	Rogue Trader.
	Copyright (c) 2007, 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 GAMEOBJECT_MISSILE_H
#define GAMEOBJECT_MISSILE_H

//##############################################################################
// Forward references
//##############################################################################

class MeshManager;
class GameScene;
class GameObject_Explosion;
class Sound;
class SoundManger;

//##############################################################################
// C Includes
//##############################################################################

#include "MathLibrary.h"

//##############################################################################
// Stuff that cannot be forward referenced
//##############################################################################

#include "MovingGameObject.h"

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   GameObject_Missile
// Purpose:      Class describing a missile in the game. The missile seeks towards
//               its target but burns out after a while if it has not hit a target.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class GameObject_Missile : public MovingGameObject
{

 public:

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // Constructor for the missile object

        GameObject_Missile
        (
            float           pos_x,      // initial position: x
            float           pos_y,      // initial position: y
            float           pos_z,      // initial position: z
            GameObject *    firer,      // hook to the object that fired the missile. the missile will not be able to hit this object
            GameObject *    target      // hook to the object that the missile is targeting. missile will seek towards this target and attempt to hit it.
        );

        // Destructor: spawns an explosion

        ~GameObject_Missile();

        // On frame event for the missile:

        void onFrame( float frameTime );

        // Get the firer and target of the missile:

        inline GameObject * getFirer()  const { return firer;   }
        inline GameObject * getTarget() const { return target;  }

        // Get the missile time left to live:

        inline float getTimeLeft() const { return timeLeft; }

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

 protected:

        //----------------------------------------------------------------------
        // Constants
        //----------------------------------------------------------------------

        static const float      LIVE_TIME;                      // time missiles live for in seconds
        static const float      HEALTH;                         // health a missile has
        static const float      DAMAGE;                         // damaged inflicted by a missile hit
        static const float      SPEED;                          // missile top speed
        static const float      ACCELERATION;                   // missile acceleration
        static const float      BOUNDING_SPHERE_SCALE;          // Amount to scale the missile bounding sphere by when testing for collisions.
        static const float      EXPLOSION_TIME;                 // time the missile explosion lasts for in seconds
        static const float      EXPLOSION_SCALE;                // scale of the missile explosion
        static const float      PARTICLE_INTERVAL;              // amount of time in seconds between bursts of particles coming from the missile
        static const float      PARTICLE_TIME1;                 // missile particle live time 1
        static const float      PARTICLE_TIME2;                 // missile particle live time 2
        static const float      PARTICLE_COLOR1_R;              // missile particle color: red
        static const float      PARTICLE_COLOR1_G;              // missile particle color: green
        static const float      PARTICLE_COLOR1_B;              // missile particle color: blue
        static const float      PARTICLE_COLOR2_R;              // missile particle color: red
        static const float      PARTICLE_COLOR2_G;              // missile particle color: green
        static const float      PARTICLE_COLOR2_B;              // missile particle color: blue
        static const float      PARTICLE_SIZE1;                 // the size of missile particles
        static const float      PARTICLE_SIZE2;                 // the size of missile particles
        static const float      PARTICLE_DIR_RANDOMNESS;        // amount of variation from missiles velocity direction particles can go
        static const float      PARTICLE_VEL_RANDOMNESS;        // amount of variation from missiles velocity amount particles can have
        static const float      PARTICLE_CONST_VEL_RANDOMNESS;  // amount of random variation in particle velocity to apply, regardless of missiles speed
        static const float      PARTICLE_OFFSET;                // offset from the center of the mesh to bounding sphere end for particle spawns. Given in percent.
        static const unsigned   PARTICLE_COUNT;                 // number of particles to create in an missile particle stream
        static const float      NOISE_ENGINE_DISTANCE;          // distance from which the engine noise can be heard
        static const float      NOISE_FIRE_DISTANCE;            // distance from which the firing noise can be heard

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // Spawn the missiles particles:

        void spawnParticles( float frameTime );

        //----------------------------------------------------------------------
        // Variables
        //----------------------------------------------------------------------

        // Object which fired the missile and object targeted by missile

        GameObject * firer;
        GameObject * target;

        // the amount of time left in seconds till ship creates another set of particles

        float timeToParticles;

        // the amount of time the missile has left to live:

        float timeLeft;

        // Sound ID of the rocket engine sound

        unsigned sndEngineID;

}; // end of: class GameObject_Missile{}

//##############################################################################
// C++ includes
//##############################################################################

#include "GameScene.h"
#include "MeshManager.h"
#include "GameObject_Explosion.h"
#include "Sound.h"
#include "SoundManager.h"

#endif // end of: ifndef GAMEOBJECT_MISSILE_H
