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