BWAPI
Skynet/Skynet/ArconZealotKillUnDetected.cpp
Go to the documentation of this file.
00001 #include "ArconZealotKillUnDetected.h"
00002 
00003 #include "UnitTracker.h"
00004 #include "UnitInformation.h"
00005 #include "LatencyTracker.h"
00006 #include "Logger.h"
00007 
00008 bool ArconZealotKillUnDetected::update(const Goal &squadGoal, const UnitGroup &squadUnitGroup)
00009 {
00010         if(mUnit->getOrder() == BWAPI::Orders::CompletingArchonsummon)
00011                 return true;
00012 
00013         const int minDistance = 32*5;
00014 
00015         Unit lurker;
00016         int lurkerDistance = std::numeric_limits<int>::max();
00017         for each(Unit unit in UnitTracker::Instance().selectAllEnemy())
00018         {
00019                 if(unit->exists() && !unit->isDetected() && (unit->isCloaked() || unit->getType().hasPermanentCloak() || (unit->getType() == BWAPI::UnitTypes::Zerg_Lurker && unit->isBurrowed())))
00020                 {
00021                         int thisDistance = mUnit->getDistance(unit);
00022                         if(thisDistance < lurkerDistance)
00023                         {
00024                                 lurkerDistance = thisDistance;
00025                                 lurker = unit;
00026                         }
00027                 }
00028         }
00029 
00030         if(!lurker || lurkerDistance > minDistance)
00031                 return false;
00032 
00033         BWAPI::UnitType typeToFind = mUnit->getType() == BWAPI::UnitTypes::Protoss_Archon ? BWAPI::UnitTypes::Protoss_Zealot : BWAPI::UnitTypes::Protoss_Archon;
00034         Unit other = UnitTracker::Instance().selectAllUnits(typeToFind).getClosestUnit(lurker);
00035 
00036         if(!other)
00037                 return false;
00038 
00039         int otherDistance = other->getDistance(lurker);
00040         if(otherDistance > minDistance)
00041                 return false;
00042 
00043         if(typeToFind == BWAPI::UnitTypes::Protoss_Archon)
00044         {
00045                 if(mUnit != UnitTracker::Instance().selectAllUnits(BWAPI::UnitTypes::Protoss_Zealot).getClosestUnit(lurker))
00046                         return false;
00047 
00048                 mUnit->move(lurker->getPosition());
00049                 return true;
00050         }
00051         else
00052         {
00053                 if(otherDistance <= 14)
00054                 {
00055                         mUnit->attack(other);
00056                         return true;
00057                 }
00058                 else
00059                 {
00060                         mUnit->move(other->getPosition());
00061                         return true;
00062                 }
00063         }
00064 
00065         return false;
00066 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines