BWAPI
Skynet/Skynet/AOEThreat.cpp
Go to the documentation of this file.
00001 #include "AOEThreat.h"
00002 
00003 AOEThreatClass::AOEThreatClass(Unit unit)
00004         : mUnit(unit)
00005         , mBullet(NULL)
00006 {
00007 }
00008 
00009 AOEThreatClass::AOEThreatClass(BWAPI::Bullet* bullet)
00010         : mUnit()
00011         , mBullet(bullet)
00012 {
00013 }
00014 
00015 bool AOEThreatClass::hasGone() const
00016 {
00017         return getPosition() == BWAPI::Positions::Invalid;
00018 }
00019 
00020 Position AOEThreatClass::getPosition() const
00021 {
00022         if(mUnit && mUnit->exists())
00023         {
00024                 const BWAPI::UnitType &type = mUnit->getType();
00025                 if(type == BWAPI::UnitTypes::Terran_Vulture_Spider_Mine)
00026                 {
00027                         if(mUnit->getTarget())
00028                                 return mUnit->getTarget()->getPosition();
00029                         else
00030                                 return mUnit->getPosition();
00031                 }
00032                 else if(type == BWAPI::UnitTypes::Protoss_Scarab)
00033                 {
00034                         if(mUnit->getTarget())
00035                                 return mUnit->getTarget()->getPosition();
00036                         else
00037                                 return BWAPI::Positions::Invalid;
00038                 }
00039                 else
00040                         return mUnit->getPosition();
00041         }
00042         else if(mBullet && mBullet->exists())
00043         {
00044                 const BWAPI::BulletType &type = mBullet->getType();
00045                 if(type == BWAPI::BulletTypes::Psionic_Storm)
00046                         return mBullet->getPosition();
00047                 else if(type == BWAPI::BulletTypes::EMP_Missile)
00048                         return mBullet->getTargetPosition();
00049         }
00050 
00051         return BWAPI::Positions::Invalid;
00052 }
00053 
00054 int AOEThreatClass::getRadius() const
00055 {
00056         if(mUnit && mUnit->exists())
00057         {
00058                 int radius = 0;
00059                 if(isAirThreat())
00060                         radius = mUnit->getType().airWeapon().medianSplashRadius();
00061                 if(isGroundThreat())
00062                         radius = std::max(mUnit->getType().groundWeapon().medianSplashRadius(), radius);
00063                 
00064                 if(!mUnit->getTarget())
00065                         return radius / 2;
00066                 else
00067                         return radius;
00068         }
00069         else if(mBullet && mBullet->exists())
00070         {
00071                 const BWAPI::BulletType &type = mBullet->getType();
00072                 if(type == BWAPI::BulletTypes::Psionic_Storm)
00073                         return 64;
00074                 else if(type == BWAPI::BulletTypes::EMP_Missile)
00075                         return 96;
00076         }
00077 
00078         return 0;
00079 }
00080 
00081 void AOEThreatClass::draw() const
00082 {
00083         const Position &pos = getPosition();
00084         BWAPI::Broodwar->drawCircleMap(pos.x(), pos.y(), getRadius(), BWAPI::Colors::Red);
00085 }
00086 
00087 Unit AOEThreatClass::getTarget() const
00088 {
00089         if(mUnit && mUnit->exists())
00090                 return mUnit->getTarget();
00091 
00092         return StaticUnits::nullunit;
00093 }
00094 
00095 bool AOEThreatClass::isAirThreat() const
00096 {
00097         if(mBullet && mBullet->exists())
00098         {
00099                 if(mBullet->getType() == BWAPI::BulletTypes::Psionic_Storm)
00100                         return true;
00101         }
00102 
00103         return false;
00104 }
00105 
00106 bool AOEThreatClass::isGroundThreat() const
00107 {
00108         if(mUnit && mUnit->exists())
00109         {
00110                 const BWAPI::UnitType &type = mUnit->getType();
00111                 if(type == BWAPI::UnitTypes::Protoss_Scarab || type == BWAPI::UnitTypes::Terran_Vulture_Spider_Mine)
00112                         return true;
00113         }
00114         else if(mBullet && mBullet->exists())
00115         {
00116                 if(mBullet->getType() == BWAPI::BulletTypes::Psionic_Storm)
00117                         return true;
00118         }
00119 
00120         return false;
00121 }
00122 
00123 bool AOEThreatClass::isEnergyThreat() const
00124 {
00125         if(mBullet && mBullet->exists())
00126         {
00127                 if(mBullet->getType() == BWAPI::BulletTypes::EMP_Missile)
00128                         return true;
00129         }
00130 
00131         return false;
00132 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines