#ifndef RULESET_H
#define RULESET_H

#include <stdint.h>

#include "Player.h"
#include "PlayerDuringBattle.h"
#include "Enemy.h"
#include "EnemyDuringBattle.h"
#include "Store.h"
#include "Map.h"
#include "MapUnit.h"

#include "BattleAbility.h"

#include <vector>
using namespace std;

#define BATTLE_RESULT_NO_BATTLE 0
#define BATTLE_RESULT_NOT_FINISHED 1
#define BATTLE_RESULT_PLAYER_WON 2
#define BATTLE_RESULT_PLAYER_LOST 3

//Commands are passed to the ruleset

class Ruleset {
 public:
  Ruleset ();
  ~Ruleset ();
  void initialize ();
  void newBattle ();

  void deleteBattle ();
  void deleteLevel ();

  void newPlayer (uint8_t classID);
  void newGame ();

  bool getIntroBattle ();
  void clearIntroBattle ();

  Player & getPlayer ();
  Enemy & getEnemy ();

  Map & getMap ();
  MapUnit & getPlayerMapUnit ();
  vector <MapUnit> & getEnemyMapUnits ();

  bool isItPlayerTurn ();

  void nextTurn ();

  void newStore ();
  Store & getStore ();
  void deleteStore ();

  bool getBetweenLevels ();

  uint8_t determineWinner ();
  void applyVictory ();

  //STUB: ruleset should know who won and who lost
  void declarePlayerWon ();
  void declarePlayerLost ();

  //STUB: This should be private
  void setBetweenLevels (bool a);

  void newLevel ();

  void setMapWayPoint (int32_t x, int32_t y);
  int32_t getMapWayPointX ();
  int32_t getMapWayPointY ();
  bool getMapWayPointActivate ();
  bool isPlayerOnEndOfMap ();

  void setActionTime (uint32_t time);
  void mapAction (uint32_t time);

  uint8_t mapUnitMapIntersectionCheck (vector <vector <uint8_t> > & mapLayout, MapUnit & mu, uint32_t tim);
  uint8_t mapUnitMapIntersectionCheckHelper (vector <vector <uint8_t> > & mapLayout, MapUnit & mu, uint32_t tim, bool);

  bool isPlayerAboutToEngageInBattle ();

  void addEnemyMapUnit (vector <uint8_t> :: iterator xPos, vector <uint8_t> :: iterator yPos, vector <string> :: iterator stringPos);

  vector<BattleAbility> & getPlayerBattleAbilities ();

//fills given arguments comparing a selected ability, given the slot the attack appears in.
  void compareAbilityToEnemy (int16_t slot, int & abilityType,
                              string & abilityName, string & desc,
                              int & quantityOrRecharge, uint8_t & rechargeTimeRemaining, uint8_t & pattern,
                              int & allowedMisses, uint8_t & bonusDamage, bool & minimalDamageWarning,
                              int & drawingDifficulty);

 private:
  bool battleFinished;
  bool playerWins;

  Map mep;

  Player p1;
  MapUnit playerMapUnit;

  Enemy e1;
  bool introBattle;
  bool playerTurn;
  vector <MapUnit> enemyMapUnits;

  PlayerDuringBattle pdb;
  EnemyDuringBattle edb;
  MapUnit * enemyMapUnitEngaged;

  Store stre;

  //STUB: The ruleset should know when the player has started a level.
  bool betweenLevels;

  int32_t mapWayPointX, mapWayPointY;
  bool mapWayPointActivate;
  uint32_t timeStamp;

  //battle stuff
  vector<BattleAbility>battleAbilities;
};

#endif
