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

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

class GameScene;
class GLTextureManager;
class Sound;
class SoundManager;

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

#include <Windows.h>
#include <gl/gl.h>
#include "MathLibrary.h"

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

#include "MovingGameObject.h"

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   GameObject_Emp
// Purpose:      The EMP bomb is a special kind of object that acts as a missile
//               counter measure. It basically destroys all missiles within a
//               certain range and emits bolts of energy as a special effect.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class GameObject_Emp : public MovingGameObject
{

 public:

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

        // Constructor: takes a pointer to the object which fired the emp

        GameObject_Emp( GameObject * firer );

        // Destructor

        ~GameObject_Emp();

        // On frame event for the emp bomb: kills missiles

        void onFrame( float frameTime  );

        // On draw event for the emp bomb: draws lightning stalks

        void onDraw( Camera * camera );

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

 protected:

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

        static const float LIVE_TIME;       // time the emp bomb will live for
        static const float RANGE;           // range in which the emp bomb will destroy missiles

        // Lightning stalk effects

        static const unsigned   NUM_STALKS              = 32;       // number of lighting stalks there is
        static const unsigned   NUM_STALK_PARTS         = 4;        // number of parts to each lighting stalk

        static const float      STALK_CHANGE_TIME;      // time it takes for the lighting stalks to change in seconds
        static const float      STALK_WIDTH;            // width of lightning stalks
        static const float      STALK_PART_MIN_LENGHT;  // minimum lenght of each stalk part
        static const float      STALK_PART_MAX_LENGHT;  // maximum lenght of each stalk part
        static const float      STALK_PART_COLOR_R;     // color of each stalk part: red
        static const float      STALK_PART_COLOR_G;     // color of each stalk part: green
        static const float      STALK_PART_COLOR_B;     // color of each stalk part: blue
        static const float      NOISE_FIRE_DISTANCE;    // distance from which the emp firing noise can be heard
        static const float      NOISE_AMBIENT_DISTANCE; // distance from which the emp ambient noise can be heard

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

        // Generate a new random set of lightning stalk points. Each stalk starts at 0,0,0

        void generateLightningStalkPoints();

        // Draws a lighting stalk part: assumes lightning stalk texture has been bound and blending enabled

        void drawLightingStalkPart
        (
            Camera * camera,    // camera the game is being viewed from
            float x1,           // point at start of lightning stalk: x
            float y1,           // point at start of lightning stalk: y
            float z1,           // point at start of lightning stalk: z
            float x2,           // point at end of lightning stalk: x
            float y2,           // point at end of lightning stalk: y
            float z2,           // point at end of lightning stalk: z
            float r1,           // point at start of lightning stalk: color r
            float g1,           // point at start of lightning stalk: color g
            float b1,           // point at start of lightning stalk: color b
            float r2,           // point at end of lightning stalk: color r
            float g2,           // point at end of lightning stalk: color g
            float b2            // point at end of lightning stalk: color b
        );

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

        // Time the emp has left to live

        float timeLeft;

        // Time passed since the lighting stalks last changed:

        float timeSinceStalkChange;

        // Pointer to the object which fired the emp

        GameObject * firer;

        // Position of the emp bombs center. position in the scene is not used.

        float emp_position[3];

        // Lightning stalk points: described relative to where the emp bomb is located (see above)

        float stalkPoints[NUM_STALKS][ ( NUM_STALK_PARTS + 1 ) * 3 ];

        // Sound id of the emp ambient noise

        unsigned sndEmpAmbientID;

}; // end of: class GameObject_Emp{}

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

#include "GameScene.h"
#include "GLTextureManager.h"
#include "Sound.h"
#include "SoundManager.h"

#endif // end of: ifndef GAMEOBJECT_EMP_H
