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

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

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

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

class GameScene;
class GameObject;
class GLTexture;
class GLTextureManager;
class Camera;
class Sound;
class SoundManager;

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   Laser
// Purpose:      Simple class that describes a laser weapon and handles drawing
//               of laser beams and hitting of other objects and such.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class Laser
{

 public:

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

        static const float MAX_HEAT;        // maximum amount of heat a laser can have
        static const float MIN_COOL_TIME;   // minimum amount of time a laser must cool for when first overheated

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

        // Constructor for the laser

        Laser
        (
            float strenght,         // how much damage the laser does
            float coolingAmount,    // how much cooling the laser has
            float colorR,           // laser color: r
            float colorG,           // laser color: g
            float colorB            // laser color: b
        );

        // Fire the laser: will fail and try to cool laser, if laser is too hot

        void fire
        (
            GameScene  *    scene,          // scene in which the laser is being fired
            GameObject *    firer,          // object that fired the laser- will not be hit by the laser
            float           frameTime,      // time the last frame took in seconds
            float           originX,        // point from which it is being fired: x
            float           originY,        // point from which it is being fired: y
            float           originZ,        // point from which it is being fired: z
            float           directionX,     // direction in which it is being fired: x (does not need to be normalised)
            float           directionY,     // direction in which it is being fired: y (does not need to be normalised)
            float           directionZ      // direction in which it is being fired: z (does not need to be normalised)
        );

        // Resets the lasers heat amount:

        void resetCurrentHeat();

        // Cools the laser down:

        void cool( GameScene * scene , float frameTime );

        // Draws the laser: will not draw anything if the laser is not firing

        void draw( Camera * camera );

        // Gets the current heat level of the laser:

        inline float getHeat() const { return currentHeat; }

        // Get the strenght and cooling capacity of a laser:

        inline float getStrenght()      const { return strenght;        }
        inline float getCoolingAmount() const { return coolingAmount;   }

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

 protected:

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

        static const float BEAM_WIDTH;                          // width of the laser beam when drawn
        static const float BEAM_WIDTH_RANDOMNESS;               // Amount the width of the beam can randomnly vary
        static const float BEAM_WIDTH_RANDOM_CHANGE_INTERVAL;   // how much time in seconds must pass before the laser beams width can be randomnly changed again

        static const float HIT_PARTICLE_INTERVAL;               // minimum amount of time that must pass in between spawning particles when the laser hits something
        static const int   HIT_PARTICLE_COUNT;                  // number of hit particles to spawn at a time
        static const float HIT_PARTICLE_SIZE1;                  // hit particle: size 1
        static const float HIT_PARTICLE_SIZE2;                  // hit particle: size 2
        static const float HIT_PARTICLE_VEL1;                   // hit particle: velocity 1
        static const float HIT_PARTICLE_VEL2;                   // hit particle: velocity 2
        static const float HIT_PARTICLE_TIME1;                  // hit particle: time to live 1
        static const float HIT_PARTICLE_TIME2;                  // hit particle: time to live 2
        static const float HIT_PARTICLE_R1;                     // hit particle: color red1
        static const float HIT_PARTICLE_G1;                     // hit particle: color green1
        static const float HIT_PARTICLE_B1;                     // hit particle: color blue1
        static const float HIT_PARTICLE_R2;                     // hit particle: color red2
        static const float HIT_PARTICLE_G2;                     // hit particle: color green2
        static const float HIT_PARTICLE_B2;                     // hit particle: color blue2

        static const float LASER_NOISE_DISTANCE;                // distance from which lasers can be heard

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

        float strenght;                     // amount of damage the laser does: higher values do more damage but cause more over heating
        float coolingAmount;                // amount of cooling per second the laser does
        float currentHeat;                  // current heat level of the laser
        float coolingTimeLeft;              // amount of time left to cool lasers before they can be fired again
        float beamWidthRandomness;          // current random change to the beams default width
        float timeSinceRandomWidthChange;   // time since the last change in the beams random width: in seconds
        float timeSinceHitParticles;        // time passed since the last batch of hit particles were spawned

        float colorR;           // color of the laser: red
        float colorG;           // color of the laser: green
        float colorB;           // color of the laser: blue

        float beamStartX;       // start point of beam last time it was fired: x
        float beamStartY;       // start point of beam last time it was fired: y
        float beamStartZ;       // start point of beam last time it was fired: z

        float beamEndX;         // end point of beam last time it was fired: x
        float beamEndY;         // end point of beam last time it was fired: y
        float beamEndZ;         // end point of beam last time it was fired: z

        bool  firing;           // is the laser currently firing ?

        unsigned sndLaserID;    // sound ID for the laser sound

}; // end of: class Laser{}

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

#include "GameScene.h"
#include "GameObject.h"
#include "GLTexture.h"
#include "GLTextureManager.h"
#include "Camera.h"
#include "Sound.h"
#include "SoundManager.h"

#endif // end of: ifndef LASER_H
