/*
	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.
*/

#ifndef TRACKSECTION_H
#define TRACKSECTION_H

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

#include <windows.h>

//##############################################################################
// Forward declarations
//##############################################################################

class Window;
class Bitmap;
class Camera;
class Game;
class GameObject;

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   TrackSection
// Purpose:      Class that represents each horizontal strip of the track
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class TrackSection
{
 /*-----------------------------------------------------------------------------
 Public functions and data
 -----------------------------------------------------------------------------*/

 public:

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

        // Maximum number of game objects that can be contained in this track section

        static const unsigned int SECTION_MAX_OBJECTS = 32;

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

        // Constructor

        TrackSection
            (
            unsigned int section_number,    // which section of the track is this?
            float fl_x,                     // section front left   x
            float fr_x,                     // section front right  x
            float bl_x,                     // section back  left   x
            float br_x,                     // section back  right  x
            float f_y,                      // section front        y
            float b_y                       // section back         y
            );

        // Draw the track segment

        void draw
            (
            Window & window, // window to draw to
            Camera * camera  // viewpoint to draw from
            );

        // Add or remove a reference to an object from the track section

        void addObject( GameObject * object );
        void delObject( GameObject * object );

        // Accessors

        inline float    get_f_y()      { return section_f_y; }  // get front y value of section
        inline float    get_b_y()      { return section_b_y; }  // get back  y value of section
        inline float    get_f_z()      { return section_f_z; }  // get front z value of section
        inline float    get_b_z()      { return section_b_z; }  // get back  z value of section
        inline float    get_fl_x()     { return tarmac_fl_x; }  // get front left  x value of the tarmac part of the section
        inline float    get_fr_x()     { return tarmac_fr_x; }  // get front right x value of the tarmac part of the section
        inline float    get_bl_x()     { return tarmac_bl_x; }  // get back  left  x value of the tarmac part of the section
        inline float    get_br_x()     { return tarmac_br_x; }  // get back  right x value of the tarmac part of the section
        inline float    get_normal_y() { return normal_y; }     // get the y coordinate of the normal
        inline float    get_normal_z() { return normal_z; }     // get the z coordinate of the normal

        // return the null terminated list of objects in the section

        inline GameObject ** get_objects()  { return object_array; }

        // Lookup table creation and deletion

        static void createColorLookupTables();   // create the color lookup tables and brushes with windows
        static void deleteColorLookupTables();   // delete all created colors with windows

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

 /*-----------------------------------------------------------------------------
 Private functions and data
 -----------------------------------------------------------------------------*/

 private:

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

        // Shading

        static const float SECTION_GROUND_COL_R;		// section ground color: r
        static const float SECTION_GROUND_COL_G;		// section ground color: g
        static const float SECTION_GROUND_COL_B;		// section ground color: b

        static const float SECTION_TARMAC_COL_R;		// section taramc color: r
        static const float SECTION_TARMAC_COL_G;		// section taramc color: g
        static const float SECTION_TARMAC_COL_B;		// section taramc color: b

        static const float SECTION_LINE_LR_COL_R;       // section line left/right color: r
        static const float SECTION_LINE_LR_COL_G;       // section line left/right color: g
        static const float SECTION_LINE_LR_COL_B;		// section line left/right color: b

        static const float SECTION_LINE_C_COL_R;       // section line center color: r
        static const float SECTION_LINE_C_COL_G;       // section line center color: g
        static const float SECTION_LINE_C_COL_B;       // section line center color: b

        static const float SECTION_DIST_FADE_AMT;  // amount each section fades with distance

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

        // y and z values for the front and back of the section

        float section_f_y;  // front y value
        float section_f_z;  // front z value
        float section_b_y;  // back  y value
        float section_b_z;  // back  z value

        // Geometry for the tarmac part of the section

        float tarmac_fl_x;  // front left  part of section: x value
        float tarmac_fr_x;  // front right part of section: x value
        float tarmac_bl_x;  // back  left  part of section: x value
        float tarmac_br_x;  // back  right part of section: x value

        // Geometry for the left road line

        float line_l_fl_x;  // front left  part of the left road line:  x value
        float line_l_fr_x;  // front right part of the left road line:  x value
        float line_l_bl_x;  // back  left  part of the left road line:  x value
        float line_l_br_x;  // back  right part of the left road line:  x value

        // Geometry for the right road line

        float line_r_fl_x;  // front left  part of the left road line:  x value
        float line_r_fr_x;  // front right part of the left road line:  x value
        float line_r_bl_x;  // back  left  part of the left road line:  x value
        float line_r_br_x;  // back  right part of the left road line:  x value

        // Geometry for the center road line

        float line_c_fl_x;  // front left  part of the center road line:  x value
        float line_c_fr_x;  // front right part of the center road line:  x value
        float line_c_bl_x;  // back  left  part of the center road line:  x value
        float line_c_br_x;  // back  right part of the center road line:  x value

        float line_c_f_y;   // front y value for center line
        float line_c_b_y;   // back  y value for center line
        float line_c_f_z;   // front z value for center line
        float line_c_b_z;   // back  z value for center line

        // Normal y and z values. X value is not included because 3D normals are not needed.

        float normal_y;
        float normal_z;

        // Speed hack: to save time creating brushes when picking different colors for track,
        // create all the possible colors here as windows brushes and just select instead.
        // These tables represent each color at intensities ranging from 0 to 255.

        static HBRUSH brush_table_tarmac[256];     // lookup table of colors for the tarmac
        static HBRUSH brush_table_ground[256];     // lookup table of colors for the ground
        static HBRUSH brush_table_lineLR[256];     // lookup table of colors for the left and right lines
        static HBRUSH brush_table_lineC [256];     // lookup table of colors for the center line

        // Null terminated internal array of game objects on the track section: used when drawing

        GameObject *  object_array[SECTION_MAX_OBJECTS+1];
        unsigned int  object_count;

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

        // Draw all objects contained within the track section

        void drawContainedObjects(Window & window, Camera * camera);

}; // end of: class TrackSection{}

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

#include "Window.h"
#include "Bitmap.h"
#include "Camera.h"
#include "Game.h"
#include "GameObject.h"

#endif // end of: ifndef TRACKSECTION_H
