#ifndef UNIVERSE_H
#define UNIVERSE_H

#include "LDTypes.h"

#include <string>
#include <map>
#include <list>
#include <vector>



struct IDirect3DDevice8;

class Universe
{

  public:

    enum PlanetType
    {
      PT_NONE       = 0,
      PT_ROCK       = 0x00000001,
      PT_LAVA       = 0x00000002,
      PT_ICE        = 0x00000004,
      PT_DIRT       = 0x00000008,
      PT_WATER      = 0x00000010,
      PT_FIRE       = 0x00000020,
      PT_SAND       = 0x00000040,
    };

    struct Planet
    {
      unsigned int    PlanetType;
      bool            Visited;
      int             Seed;

      Planet() :
        PlanetType( 0 ),
        Visited( false ),
        Seed( 0 )
      {
      }
    };

    struct Star
    {
      tPoint                Location;
      int                   Distance;
      int                   Seed;
      std::string           Name;
      int                   Type;
      bool                  Visited;
      bool                  HasAlienTech;

      std::vector<Planet>   Planets;

      Star() :
        Distance( 0 ),
        Seed( 0 ),
        Type( 0 ),
        Visited( false ),
        HasAlienTech( false )
      {
      }
    };

    struct tTile
    {
      LD::TileType        Type;

      tTile() :
        Type( LD::TT_ROCK )
      {
      }
    };

    tTile                   m_Tiles[200][200];

    std::map<tPoint,std::list<Star> >     m_Stars;

    
    Planet*         m_pFinalPlanet;


    Universe();


    void            CreateFromSeed( int Seed = 0 );
    std::string     RandomName( int Seed );

    void            DisplayStars( IDirect3DDevice8* pDevice, int AllowedDistance );
    void            DisplayPlanet( IDirect3DDevice8* pDevice, Planet& Planet, int OffsetX, int OffsetY );

    tTile&          Tile( int X, int Y );

    void            FetchPlanet( Star* pStar, int Planet, std::list<LD::Resource>& Resources );
    bool            HasPlanetResource( Star* pStar, int Planet, LD::ResourceType Resource );


    static std::string    ResourceName( LD::ResourceType Resource );

};


#endif // UNIVERSE_H
