#pragma once
#include "../../../../Utils/Process/FSM/Condition.h"

//Pourrait-être envoyé dans un .cpp
#include "../../../../PerceptualState/PerceptualState.h"

const int DANGER_RANGE = 50; // I should have called that "danger zone" (hilarious I know)

class InDanger : public Condition
{
public:
  InDanger(BWAPI::Unit* unit)
    : m_unit(unit)
  {
	  currentHit = unit->getHitPoints();
	  currentShield = unit->getShields();
  }

  bool evaluate()
  {
	  int oldHit = currentHit;
	  currentHit = m_unit->getHitPoints();
    int oldShield = currentShield;
	  currentShield = m_unit->getShields();
	  if(oldHit > currentHit || oldShield > currentShield){
	    return true;
	  }
	  std::set<BWAPI::Unit*> enemyGroup = Spar->getPerceptualState()->getEnemiesNearUnit(m_unit, DANGER_RANGE);
	  
    return !enemyGroup.empty();
  /*bool evaluate() const
  {
    //Get all units in a range X
	std::set<BWAPI::Unit*> enemyGroup = Spar->getPerceptualState()->getEnemiesNearUnit(m_unit,BWAPI::WeaponTypes::Arclite_Cannon.maxRange());
    //If can attack in the next second : in danger
	for (std::set<BWAPI::Unit*>::const_iterator it = enemyGroup.begin(); it != enemyGroup.end(); ++it)
	{ 
	  if((*it)->getType().canAttack()){
	    if(m_unit->getType().isFlyer()){
		  if((*it)->getType().airWeapon() != BWAPI::WeaponTypes::None){
			if(m_unit->getDistance((*it)) < (*it)->getType().airWeapon().maxRange() + 16){
			  return true;
			}
			else if((*it)->getType().canMove()){
			  if(m_unit->getDistance((*it)) < (*it)->getType().airWeapon().maxRange() + 10 - ((*it)->getType().topSpeed()*10)){
			    return true;
			  }
			}
		  }
	    }
	    else{
		  if((*it)->getType().groundWeapon() != BWAPI::WeaponTypes::None){
		  	if(m_unit->getDistance((*it)) < (*it)->getType().groundWeapon().maxRange() + 16){
			  return true;
			}
			else if((*it)->getType().canMove()){
			  if(m_unit->getDistance((*it)) < (*it)->getType().groundWeapon().maxRange() + 10 + ((*it)->getType().topSpeed()*5)){
			    return true;
			  }
			}
		  }	  
	    }
	  }
	}
    //else not
    return false;*/
  }

protected:
  BWAPI::Unit* const m_unit;
  int currentHit;
  int currentShield;

private :
  //Prevents using the assignment operator
  InDanger& operator= (const InDanger&);

};