#pragma once
#include "../../../../Utils/Process/FSM/Condition.h"
#include <string>
#include <sstream>

static const double MAX_LIFE_PCT = 0.4f;
static const double MIN_HEALTH_POINTS = 0.15f;

class HasCriticalHealth : public Condition
{
public:
  HasCriticalHealth(BWAPI::Unit* unit)
    : m_unit(unit)
  {
	  fullHit = unit->getHitPoints();
	  fullShield = unit->getShields();
  }

  bool evaluate()
  {
    double life = (double)(m_unit->getHitPoints() + m_unit->getShields())/(double)(fullHit + fullShield);
	  double totalLife = m_unit->getType().maxHitPoints() + m_unit->getType().maxShields();
	  bool eval = life < MAX_LIFE_PCT && totalLife > MIN_HEALTH_POINTS;
	  if(eval)
	  {
		  fullHit = m_unit->getHitPoints();
		  fullShield = m_unit->getShields();
	  }
	  return eval;
  }

protected:
  BWAPI::Unit* const m_unit;
  int fullHit;
  int fullShield;

private:
  //const member prevent the use of the assigment operator
  HasCriticalHealth& operator=(const HasCriticalHealth&);
};