BWAPI
UAlbertaBot_src/Projects/UAlbertaBot/Source/micromanagement/MutaManager.h
Go to the documentation of this file.
00001 #ifndef MUTAMANAGER_H_
00002 #define MUTAMANAGER_H_
00003 #include <Common.h>
00004 #include <BWAPI.h>
00005 #include "MicroManager.h"
00006 #include "MicroUtil.h"
00007 
00008 class CompareMutaTargetSSD {
00009         
00010         // the zergling we are comparing this to
00011         const UnitVector & mutas;
00012 
00013 public:
00014 
00015         // constructor, takes in a zergling to compare distance to
00016         CompareMutaTargetSSD(const UnitVector & z) : mutas(z) {}
00017 
00018         // the sorting operator
00019         bool operator() (BWAPI::Unit * u1, BWAPI::Unit * u2) {
00020 
00021                 int p1 = getAttackPriority(u1->getType());
00022                 int p2 = getAttackPriority(u2->getType());
00023 
00024                 if (p1 != p2) {
00025                         return p1 > p2;
00026                 } else {
00027                         return ssd(u1) < ssd(u2);
00028                 }
00029     }
00030 
00031         // get the attack priority of a type in relation to a zergling
00032         int getAttackPriority(BWAPI::UnitType type) {
00033 
00034                 int priority = 0;
00035                 if (type == BWAPI::UnitTypes::Terran_Medic || type.airWeapon() != BWAPI::WeaponTypes::None) {
00036                         priority = 10;
00037                 } else if (type ==  BWAPI::UnitTypes::Terran_Bunker) {
00038                         priority = 9;
00039                 } else if (type == BWAPI::UnitTypes::Protoss_Reaver) {
00040                         priority = 8;
00041                 } else if (type.isWorker()) {
00042                         priority = 7;
00043                 } else if (type ==  BWAPI::UnitTypes::Protoss_High_Templar) {
00044                         priority = 6;
00045                 } else if (type.groundWeapon() != BWAPI::WeaponTypes::None) {
00046                         priority = 2;
00047                 }  else if (type.supplyProvided() > 0) {
00048                         priority = 1;
00049                 }                                                                                                       
00050                 
00051                 return priority;
00052         }
00053 
00054         int ssd(BWAPI::Unit * target) {
00055 
00056                 int sum = 0;
00057                 for (size_t i(0); i<mutas.size(); ++i) {
00058                         
00059                         int xdiff(mutas[i]->getPosition().x() - target->getPosition().x());
00060                         int ydiff(mutas[i]->getPosition().y() - target->getPosition().y());
00061 
00062                         sum += xdiff*xdiff + ydiff*ydiff;
00063                 }
00064 
00065                 return sum;
00066         }
00067 };
00068 
00069 class MutaManager : public MicroManager
00070 {
00071 
00072 public:
00073 
00074     MutaManager();
00075     virtual ~MutaManager(){}
00076     void executeMicro(const UnitVector & targets);
00077 
00078         // Making these public so I can use them in overlord manager
00079         void fillAirThreats(std::vector<AirThreat> & threats, BWAPI::Unit * target);
00080         double2 getFleeVector(const std::vector<AirThreat> & threats, BWAPI::Unit * mutalisk);
00081 
00082 private:
00083 
00084     const double speed;
00085         const int cooldown, range;
00086     std::vector<AirThreat> threats;
00087 
00088         double totalDistance;
00089         size_t numShots;
00090         size_t numFrames;
00091 
00092         BWAPI::Unit * chooseTarget(const UnitVector & mutas, const UnitVector & targets);
00093         void executeMutaDance(const UnitVector & mutas, BWAPI::Unit * target);
00094         int sumSquaredDistance(const UnitVector & mutas, BWAPI::Unit * target);
00095         void harassMove(BWAPI::Unit * muta, BWAPI::Position location);
00096 };
00097 #endif
00098 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines