BWAPI
|
00001 #pragma once 00002 #include "../../../../Utils/FSM/Condition.h" 00003 #include "HasRangedAttack.h" 00004 #include <BWAPI.h> 00005 00006 class IsWorthFleeing : Condition 00007 { 00008 BWAPI::Unit* m_unit; 00009 00010 typedef Not<HasRangedAttack> IsMelee; 00011 00012 public: 00013 IsWorthFleeing(BWAPI::Unit* unit) : m_unit(unit) {} 00014 00015 bool evaluate() const 00016 { 00017 const bool hasRangedAttack = HasRangedAttack(m_unit).evaluate(); 00018 00019 std::set<BWAPI::Unit*> targetingUnits = Spar->getPerceptualState().getTargetingUnits(m_unit); 00020 00021 for (std::set<BWAPI::Unit*>::const_iterator i=targetingUnits.begin(); i!=targetingUnits.end(); ++i) 00022 { 00023 BWAPI::Unit* enemy = *i; 00024 if (!(hasRangedAttack && IsMelee(enemy).evaluate())) 00025 { 00026 return false; 00027 } 00028 } 00029 00030 return true; 00031 } 00032 };