#ifndef MAP_H
#define MAP_H

#include <stdint.h>

#include <vector>
#include <string>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>

#include "../graphics/AnimatedState.h"
using namespace std;

//Map.

#define MAP_TERRAIN_NULL 0
#define MAP_TERRAIN_GROUND 2
#define MAP_TERRAIN_UNPASSABLE 3
#define MAP_TERRAIN_ENDPOINT 4
#define MAP_TERRAIN_LOCKED 5

#define MAP_TILE_NUM_TILES 6
#define MAP_TILE_NULL 0
#define MAP_TILE_FOG 1
#define MAP_TILE_GROUND 2
#define MAP_TILE_UNPASSABLE 3
#define MAP_TILE_ENDPOINT 4
#define MAP_TILE_LOCKED 5

class Map {
 public:
  Map ();
  ~Map ();

  void initialize();

  void setStartPoint (uint8_t x, uint8_t y);
  uint8_t getStartPointX ();
  uint8_t getStartPointY ();

  void setEndPoint (uint8_t x, uint8_t y);
  uint8_t getEndPointX ();
  uint8_t getEndPointY ();

  uint8_t setDimensions (uint8_t width, uint8_t height);
  uint8_t getMapWidth ();
  uint8_t getMapHeight ();

  void setMapTerrain (uint8_t x, uint8_t y, uint8_t terrainType);

  void printMap ();
  void printMapWithPlayerVision (vector <vector <uint8_t> > &, vector <vector <bool> > &);
  void getMapTerrain (vector <vector <uint8_t> > &);
  void getMapFog (vector <vector <bool> > &);

  uint8_t loadMap (const string & mapIndex);
  bool loadMapHelper (xmlDocPtr doc, xmlXPathContextPtr xpathCtx, const string & xpath);

  const string & getName ();
  void setName (const string &);

  const string & getBackgroundImageName ();
  const string & getTileImageName (uint8_t tilename);
  void setBackgroundImageName (const string & str);
  void setTileImageName (const string & str, uint8_t tilename);

  void setTileSize (uint8_t ts);
  uint8_t getTileSize ();

  vector <uint8_t> & getEnemyStartingPositionsX ();
  vector <uint8_t> & getEnemyStartingPositionsY ();
  vector <string> & getEnemyMapUnitPicNames ();
  vector <AnimatedState> & getEnemyAnimatedStates ();

 private:
  vector <vector <uint8_t> > terrain;
  vector <vector<bool> > fog;
  uint8_t playerStartX, playerStartY;
  uint8_t playerEndX, playerEndY;
  string name;
  vector <string> graphics;
  uint8_t tileSize;
  vector <uint8_t> enemyStartingPositionsX;
  vector <uint8_t> enemyStartingPositionsY;
  vector <string> mapUnitEnemyGraphics;
  vector <AnimatedState> enemyAnimatedStates;
};

#endif
