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

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

#include <cstdlib>
#include <cstring>

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

class Galaxy;
class NameGenerator;
class GLTexture;
class GLTextureManager;

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

#include "GoodsInventory.h"

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   StarSystem
// Purpose:      Class that describes a star system. Holds information such as
//               the system's name, its coordinates, the market prices and such.
//               The star system information is generated randomnly from a seed
//               and sector information given.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class StarSystem
{

 public:

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

        static const unsigned MAX_DANGER_LEVEL;     // maximum danger level for a system

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

        // Constructor: takes a random seed and a sector position in the galaxy

        StarSystem( unsigned seed , unsigned sectorX , unsigned sectorY );

        // Default constructor: creates a 'null' star system with no name:

        StarSystem();

        // Destructor:

        ~StarSystem();

        // Copy constructor:

        StarSystem( const StarSystem & system );

        // Overloaded assignment operator

        void operator = ( const StarSystem & system );

        // Equality operator. Two systems are equal if they are on the same sector in the galaxy.

        bool operator == ( const StarSystem & system );

        // Tells if the system is a 'null' system:

        inline bool isNullSystem() const { return ( name == 0 ); }

        // Inlined constant accessors:

        inline unsigned             getSectorX()        const   { return sectorX; }
        inline unsigned             getSectorY()        const   { return sectorY; }
        inline unsigned             getSectorOffsetX()  const   { return sectorOffsetX; }
        inline unsigned             getSectorOffsetY()  const   { return sectorOffsetY; }
        inline unsigned             getBackgroundSeed() const   { return backgroundSeed;}
        inline const char *         getName()           const   { return name; }

        // Get the star color for the system and save to the array given:

        void getStarColor( float * color );

        // Get the planet texture for the system and save to the array given:

        const GLTexture * getPlanetTexture();

        // Get the color of light emmited from the planet:

        void getPlanetLightColor( float * color );

        // Get the danger level for the system

        inline unsigned getDangerLevel(){ return dangerLevel; }

        // Get the goods inventory or stock market for the system

        inline GoodsInventory & getGoodsInventory(){ return goodsInventory; }

        // Set the goods inventory or stock market for the system:

        inline void setGoodsInventory( const GoodsInventory & goods ){ this->goodsInventory = goods; }

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

 protected:

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

        char *          name;                   // name of the system
        unsigned        backgroundSeed;         // random seed for generating a background for this system
        unsigned        backgroundStarColor;    // Background star color. Used by the background scene when generating a background.
        unsigned        backgroundPlanet;       // Background planet number. Used by the background scene when generating a background.
        unsigned        sectorX;                // Which sector or grid square in the galactic map system is in: x coordinate
        unsigned        sectorY;                // Which sector or grid square in the galactic map system is in: y coordinate
        unsigned        sectorOffsetX;          // The position of the the star system within its sector: x
        unsigned        sectorOffsetY;          // The position of the the star system within its sector: y
        unsigned        dangerLevel;            // level of lawlessness for the zero. from 1 to max danger
        GoodsInventory  goodsInventory;         // Goods inventory for the system

}; // end of: class StarSystem{}

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

#include "Galaxy.h"
#include "NameGenerator.h"
#include "GLTexture.h"
#include "GLTextureManager.h"

#endif // end of: ifndef STARSYSTEM_H
