BWAPI
UAlbertaBot_src/Projects/UAlbertaBot/Source/micromanagement/ZerglingManager.h
Go to the documentation of this file.
00001 #ifndef ZERGLINGMANAGER_H_
00002 #define ZERGLINGMANAGER_H_
00003 #include <Common.h>
00004 #include <BWAPI.h>
00005 #include "MicroManager.h"
00006 
00007 class CompareZerglingAttackTarget {
00008         
00009         // the zergling we are comparing this to
00010         BWAPI::Unit * zergling;
00011 
00012 public:
00013 
00014         // constructor, takes in a zergling to compare distance to
00015         CompareZerglingAttackTarget(BWAPI::Unit * z) {
00016                 zergling = z;
00017         }
00018 
00019         // the sorting operator
00020         bool operator() (BWAPI::Unit * u1, BWAPI::Unit * u2) {
00021 
00022                 int p1 = getAttackPriority(u1->getType());
00023                 int p2 = getAttackPriority(u2->getType());
00024 
00025                 return p1 > p2;
00026     }
00027 
00028         // get the attack priority of a type in relation to a zergling
00029         int getAttackPriority(BWAPI::UnitType type) {
00030 
00031                 if (type.isWorker()) {
00032                         return 8;
00033                 } else if (type == BWAPI::UnitTypes::Terran_Medic || type.groundWeapon() != BWAPI::WeaponTypes::None || type ==  BWAPI::UnitTypes::Terran_Bunker) {
00034                         return 9;
00035                 } else if (type ==  BWAPI::UnitTypes::Protoss_High_Templar) {
00036                         return 7;
00037                 } else if (type ==  BWAPI::UnitTypes::Protoss_Photon_Cannon || type == BWAPI::UnitTypes::Zerg_Sunken_Colony) {
00038                         return 3;
00039                 } else if (type.groundWeapon() != BWAPI::WeaponTypes::None) {
00040                         return 2;
00041                 } else if (type.supplyProvided() > 0) {
00042                         return 1;
00043                 } 
00044                 
00045                 return 0;
00046         }
00047 };
00048 
00049 class CompareZerglingAttackTargetSSD {
00050         
00051         // the zergling we are comparing this to
00052         const UnitVector & zerglings;
00053 
00054 public:
00055 
00056         // constructor, takes in a zergling to compare distance to
00057         CompareZerglingAttackTargetSSD(const UnitVector & z) : zerglings(z) {}
00058 
00059         // the sorting operator
00060         bool operator() (BWAPI::Unit * u1, BWAPI::Unit * u2) {
00061 
00062                 int p1 = getAttackPriority(u1->getType());
00063                 int p2 = getAttackPriority(u2->getType());
00064 
00065                 if (p1 != p2) {
00066                         return p1 > p2;
00067                 } else {
00068                         return ssd(u1) < ssd(u2);
00069                 }
00070     }
00071 
00072         // get the attack priority of a type in relation to a zergling
00073         int getAttackPriority(BWAPI::UnitType type) {
00074 
00075                 if (type == BWAPI::UnitTypes::Protoss_Reaver)                           { return 10; } 
00076                 else if (type == BWAPI::UnitTypes::Terran_Medic 
00077                         || type.groundWeapon() != BWAPI::WeaponTypes::None)             { return 9; } 
00078                 else if (type == BWAPI::UnitTypes::Protoss_Dragoon)                     { return 9; } 
00079                 else if (type.isWorker())                                                                       { return 8; } 
00080                 else if (type ==  BWAPI::UnitTypes::Protoss_High_Templar)       { return 7; } 
00081                 else if (type ==  BWAPI::UnitTypes::Terran_Bunker)                      { return 6; } 
00082                 else if (type.supplyProvided() > 0)                                                     { return 5; }
00083                 else                                                                                                            { return 0; }
00084         }
00085 
00086         int ssd(BWAPI::Unit * target) {
00087 
00088                 int sum = 0;
00089                 for (size_t i(0); i<zerglings.size(); ++i) {
00090                         
00091                         int xdiff(zerglings[i]->getPosition().x() - target->getPosition().x());
00092                         int ydiff(zerglings[i]->getPosition().y() - target->getPosition().y());
00093 
00094                         sum += xdiff*xdiff + ydiff*ydiff;
00095                 }
00096 
00097                 return sum;
00098         }
00099 };
00100 
00101 class ZerglingManager : public MicroManager
00102 {
00103 public:
00104 
00105         ZerglingManager();
00106         ~ZerglingManager() {}
00107         void executeMicro(const UnitVector & targets);
00108 
00109         std::vector<GroundThreat> threats;
00110         void fillGroundThreats(std::vector<GroundThreat> & threats, BWAPI::Position target);
00111         double2 getFleeVector(const std::vector<GroundThreat> & threats, BWAPI::Unit * zergling);
00112         BWAPI::Unit * immediateThreat(std::vector<GroundThreat> & threats, BWAPI::Unit * zergling);
00113 
00114         BWAPI::Position calcFleePosition(BWAPI::Unit * zergling, BWAPI::Unit * target);
00115 
00116         BWAPI::Unit * getClosestHarassTarget(UnitVector & targets, BWAPI::Unit * zergling, int workerFirst);
00117         BWAPI::Unit * getClosestAttackTarget(UnitVector & targets, BWAPI::Unit * zergling);
00118 };
00119 
00120 #endif
00121 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines