BWAPI
|
00001 #include "DetectorAction.h" 00002 00003 #include "Vector.h" 00004 #include "UnitTracker.h" 00005 #include "UnitHelper.h" 00006 00007 #include <limits> 00008 00009 bool DetectorAction::update(const Goal &squadGoal, const UnitGroup &squadUnitGroup) 00010 { 00011 if(squadGoal.getActionType() == ActionType::Retreat || squadGoal.getActionType() == ActionType::FallBack) 00012 return false; 00013 00014 Unit needsDetecting; 00015 int unitDistance = std::numeric_limits<int>::max(); 00016 for each(Unit unit in UnitTracker::Instance().selectAllEnemy()) 00017 { 00018 const BWAPI::UnitType &unitType = unit->getType(); 00019 if(unitType.hasPermanentCloak() || unitType == BWAPI::UnitTypes::Zerg_Lurker || unit->isCloaked() || unit->isBurrowed()) 00020 { 00021 int thisDistance = mUnit->getDistance(unit); 00022 if(thisDistance < unitDistance) 00023 { 00024 needsDetecting = unit; 00025 unitDistance = thisDistance; 00026 } 00027 } 00028 } 00029 00030 if(needsDetecting) 00031 { 00032 if(unitDistance > BWAPI::UnitTypes::Protoss_Observer.sightRange()) 00033 { 00034 mUnit->move(needsDetecting->getPosition()); 00035 return true; 00036 } 00037 } 00038 00039 //TODO: give actions access to the rest of the squad 00040 UnitGroup protectionUnits; 00041 for each(Unit unit in squadUnitGroup) 00042 { 00043 if(!UnitHelper::isArmyUnit(unit->getType())) 00044 continue; 00045 00046 if(unit->getType() == BWAPI::UnitTypes::Protoss_Arbiter || unit->getType().isBuilding()) 00047 continue; 00048 00049 if(mUnit->getDistance(unit) > 250) 00050 continue; 00051 00052 protectionUnits.insert(unit); 00053 } 00054 00055 if(!protectionUnits.empty()) 00056 { 00057 protectionUnits = protectionUnits.getBestFittingToCircle(136); 00058 if(!protectionUnits.empty()) 00059 { 00060 Position protectedArea = protectionUnits.getCenter(); 00061 if(mUnit->getDistance(protectedArea) > 110) 00062 { 00063 mUnit->move(protectedArea); 00064 return true; 00065 } 00066 } 00067 } 00068 00069 return false; 00070 }