BWAPI
SPAR/AIModule/SparAIModule/DecisionMaking/Layer1Reactive/FSM/Conditions/HasCriticalHealth.h
Go to the documentation of this file.
00001 #pragma once
00002 #include "../../../../Utils/FSM/Condition.h"
00003 #include "../../../../Common.h"
00004 #include <string>
00005 #include <sstream>
00006 
00007 static const double MAX_LIFE_PCT = 0.4f;
00008 static const double MIN_HEALTH_POINTS = 0.15f;
00009 
00010 class HasCriticalHealth : public Condition
00011 {
00012 public:
00013   HasCriticalHealth(BWAPI::Unit* unit)
00014     : m_unit(unit)
00015   {
00016           fullHit = unit->getHitPoints();
00017           fullShield = unit->getShields();
00018   }
00019 
00020   bool evaluate()
00021   {
00022     double life = (double)(m_unit->getHitPoints() + m_unit->getShields())/(double)(fullHit + fullShield);
00023           double totalLife = m_unit->getType().maxHitPoints() + m_unit->getType().maxShields();
00024           bool eval = life < MAX_LIFE_PCT && totalLife > MIN_HEALTH_POINTS;
00025           if(eval)
00026           {
00027                   fullHit = m_unit->getHitPoints();
00028                   fullShield = m_unit->getShields();
00029           }
00030           return eval;
00031   }
00032 
00033 protected:
00034   BWAPI::Unit* const m_unit;
00035   int fullHit;
00036   int fullShield;
00037 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines