/*
	Wheels Of Steel
	Copyright (c) 2006, 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.
*/

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   Obj_SnowPuff
// Purpose:      A snow puff object that displays various frames of a snow puff
//               animation and then deletes itself from the game. Essentially
//               just a basic particle effect..
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

#include "Obj_SnowPuff.h"

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

// Size of the snow puff

const float Obj_SnowPuff::SNOWPUFF_SIZE_X = 700.0f;
const float Obj_SnowPuff::SNOWPUFF_SIZE_Y = 500.0f;
const float Obj_SnowPuff::SNOWPUFF_SIZE_Z = 1.0f;

// time in seconds the snow puff stays in existance for

const float Obj_SnowPuff::SNOWPUFF_TIME_TO_LIVE = 0.25f;    

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Name:     Obj_SnowPuff::Obj_SnowPuff
Purpose:  Constructor for the snow puff type of game object
Params:   As commented
Returns:  none

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

Obj_SnowPuff::Obj_SnowPuff
(
    float pos_x,                // position: x
    float pos_y,                // position: y
    float pos_z                 // position: z

) : GameObject(pos_x,pos_y,pos_z,true)
{
    // Set a pointer to the array of snow puff images. Retrieve from the mipmap manager.

    mipArraySnowPuff = MipmapManager::getMipArraySnowPuff();

    // Set object size

    this->size_x = SNOWPUFF_SIZE_X;
    this->size_y = SNOWPUFF_SIZE_Y;
    this->size_z = SNOWPUFF_SIZE_Z;

    // Set object attributes

    this->solid             = false;
    this->gravityAffected   = false;
    this->weight            = 1.0f;

    // Set the time the snow puff has been alive for to zero

    this->timeAlive = 0;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Name:     Obj_SnowPuff::~Obj_SnowPuff
Purpose:  Destructor. Does nothing.
Params:   none
Returns:  none

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

Obj_SnowPuff::~Obj_SnowPuff()
{
    // DO NOTHING
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Name:     Obj_SnowPuff::event_collision
Purpose:  Collision event. Does nothing.
Params:   Object that collided with this object.
Returns:  none

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

// No unreferenced param warning

#pragma warning(disable:4100)

void Obj_SnowPuff::event_collision( GameObject * collider)
{
    // DO NOTHING
}

// Restore this warning to normal

#pragma warning(default:4100)

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Name:     Obj_SnowPuff::event_move
Purpose:  Move event. Increments the time the snow puff is alive for and deletes
          the object if it is past its time to live.
Params:   Track and time last frame took in seconds
Returns:  none

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

// No unreferenced param warning

#pragma warning(disable:4100)

void Obj_SnowPuff::event_move( Track * track , float frameTime )
{
    // Increment the time alive by the frame time

    timeAlive += frameTime;

    // If past the allowed live time then kill the snow puff object

    if ( timeAlive >= SNOWPUFF_TIME_TO_LIVE )
    {
        // Past the time to live for the object: delete

        GameObjectManager::delObject(this);
    }
}

// Restore this warning to normal

#pragma warning(default:4100)

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Name:     Obj_SnowPuff::event_draw
Purpose:  Draw event. Draws a frame of the snow puff animation. The frame drawn
          depends on how long the puff has been in existance for.
Params:   Window and camera position
Returns:  none

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void Obj_SnowPuff::event_draw( Window & window, Camera * camera)
{
    // Decide what image of the snow puff animation to use and clamp to image range

    int imageNum = int( timeAlive / ( SNOWPUFF_TIME_TO_LIVE / 6.0f ) );

    if ( imageNum < 0 ) imageNum = 0;
    if ( imageNum > 5 ) imageNum = 5;

    // Draw the snow puff

    drawPerspectiveImage
    (
        window,
        camera,
        mipArraySnowPuff[imageNum]
    );

}
