|
BWAPI
|
00001 #pragma once; 00002 00003 #include <Common.h> 00004 #include "MicroManager.h" 00005 00006 class MicroManager; 00007 00008 class CompareDragoonAttackTarget { 00009 00010 public: 00011 00012 const UnitVector & dragoons; 00013 00014 // constructor, takes in a zergling to compare distance to 00015 CompareDragoonAttackTarget(const UnitVector & z) : dragoons(z) {} 00016 00017 // the sorting operator 00018 bool operator() (BWAPI::Unit * u1, BWAPI::Unit * u2) { 00019 00020 int p1 = getAttackPriority(u1); 00021 int p2 = getAttackPriority(u2); 00022 00023 if (p1 != p2) 00024 { 00025 return p1 > p2; 00026 } 00027 else 00028 { 00029 return distanceToClosestDragoon(u1) < distanceToClosestDragoon(u2); 00030 } 00031 } 00032 00033 // get the attack priority of a type in relation to a zergling 00034 int getAttackPriority(BWAPI::Unit * unit) { 00035 00036 BWAPI::UnitType type = unit->getType(); 00037 00038 //UnitInfoVector & enemyDetectors = UnitInfoState::getInstance()->getEnemyDetectors(); 00039 00040 if (type.isWorker()) { 00041 return 8; 00042 } else if (type == BWAPI::UnitTypes::Terran_Medic || type.groundWeapon() != BWAPI::WeaponTypes::None || type == BWAPI::UnitTypes::Terran_Bunker) { 00043 return 9; 00044 } else if (type == BWAPI::UnitTypes::Protoss_High_Templar) { 00045 return 7; 00046 } else if (type == BWAPI::UnitTypes::Protoss_Photon_Cannon || type == BWAPI::UnitTypes::Zerg_Sunken_Colony) { 00047 return 3; 00048 } else if (type.groundWeapon() != BWAPI::WeaponTypes::None) { 00049 return 2; 00050 } else if (type.supplyProvided() > 0) { 00051 return 1; 00052 } 00053 00054 return 0; 00055 } 00056 00057 double distanceToClosestDragoon(BWAPI::Unit * unit) 00058 { 00059 double minDistance = 0; 00060 00061 BOOST_FOREACH (BWAPI::Unit * dragoon, dragoons) 00062 { 00063 double distance = dragoon->getDistance(unit); 00064 if (!minDistance || distance < minDistance) 00065 { 00066 minDistance = distance; 00067 } 00068 } 00069 00070 return minDistance; 00071 } 00072 }; 00073 00074 class DragoonManager : public MicroManager 00075 { 00076 public: 00077 00078 DragoonManager(); 00079 ~DragoonManager() {} 00080 void executeMicro(const UnitVector & targets, BWAPI::Position regroup = BWAPI::Position(0,0)); 00081 00082 BWAPI::Unit * chooseTarget(BWAPI::Unit * dragoon, const UnitVector & targets, std::map<BWAPI::Unit *, int> & numTargeting); 00083 BWAPI::Unit * closestDragoon(BWAPI::Unit * target, std::set<BWAPI::Unit *> & dragoonsToAssign); 00084 00085 int getAttackPriority(BWAPI::Unit * unit); 00086 BWAPI::Unit * getTarget(BWAPI::Unit * dragoon, UnitVector & targets); 00087 };
1.7.6.1