BWAPI
Skynet/Skynet/Unit.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include "Interface.h"
00004 
00005 #include "TypeSafeEnum.h"
00006 
00007 struct AccessTypeDef
00008 {
00009         enum type
00010         {
00011                 Dead = 0,
00012                 Lost,
00013                 Guess,
00014                 Prediction,
00015                 Partial,
00016                 Full
00017         };
00018 
00019         static std::string getName(type t)
00020         {
00021                 switch(t)
00022                 {
00023                 case Dead:
00024                         return "Dead";
00025                 case Lost:
00026                         return "Lost";
00027                 case Guess:
00028                         return "Guess";
00029                 case Prediction:
00030                         return "Prediction";
00031                 case Partial:
00032                         return "Partial";
00033                 case Full:
00034                         return "Full";
00035                 }
00036                 return "None";
00037         }
00038 };
00039 typedef SafeEnum<AccessTypeDef> AccessType;
00040 
00041 class UnitClass : public std::tr1::enable_shared_from_this<UnitClass>
00042 {
00043 public:
00044         UnitClass(BWAPI::Unit* unit);
00045         UnitClass(Position pos, BWAPI::UnitType type, int completeTime);
00046 
00047         void onDestroy();
00048 
00049         TilePosition getTilePosition();
00050         Position getPosition();
00051         Position getPosition(int inFramesTime);
00052         Position getTargetPosition();
00053 
00054         BWAPI::UnitType getType();
00055 
00056         Player getPlayer();
00057 
00058         Unit getTarget();
00059 
00060         bool exists();
00061         int getExistTime();
00062 
00063         bool isMorphing();
00064         bool isCompleted();
00065         int getCompletedTime();
00066 
00067         bool isConstructing();
00068         bool isBeingConstructed();
00069         bool isTraining();
00070         bool isResearching();
00071         bool isUpgrading();
00072 
00073         int getRemainingTrainTime();
00074         int getRemainingUpgradeTime();
00075         int getRemainingResearchTime();
00076 
00077         int getResources();
00078 
00079         BWAPI::UpgradeType getUpgrade();
00080         BWAPI::TechType getTech();
00081         BWAPI::UnitType getBuildType();
00082 
00083         int getLastSeenTime();
00084 
00085         AccessType accessibility();
00086 
00087         void drawUnitPosition();
00088         void drawUnitTilePosition();
00089 
00090         BWAPI::Order getOrder();
00091         BWAPI::Order getSecondaryOrder();
00092 
00093         bool isLifted();
00094         bool isSieged();
00095 
00096         bool isCarryingGas();
00097         bool isCarryingMinerals();
00098 
00099         bool isLockedDown();
00100         bool isStasised();
00101         bool isCloaked();
00102         bool isBurrowed();
00103         bool isDetected();
00104         bool isStuck();
00105         bool isUnderStorm();
00106         bool isUnderDarkSwarm();
00107         bool isLoaded();
00108 
00109         bool hasAddon();
00110 
00111         bool canAttackNow(Unit unit);
00112         bool canAttack(Unit unit);
00113         bool isInRange(Unit unit);
00114         bool isAttackFrame();
00115 
00116         int getGroundWeaponMaxRange();
00117         int getAirWeaponMaxRange();
00118         int getWeaponMaxRange(Unit unit);
00119         int getWeaponMinRange(Unit unit);
00120         int getWeaponCooldown(Unit unit);
00121         int getRemainingCooldown(Unit unit);
00122         int getRemainingGroundCooldown();
00123         int getRemainingAirCooldown();
00124         int getSpellCooldown();
00125 
00126         int getTimeToKill(Unit unit);
00127         BWAPI::WeaponType getWeapon(Unit unit);
00128 
00129         bool canAttackGround();
00130         bool canAttackAir();
00131 
00132         int getScarabCount();
00133 
00134         int getID();
00135 
00136         double totalHitPointFraction();
00137         int totalHitPoints();
00138         int getHealth();
00139         int getShield();
00140         int getDefenseMatrixPoints();
00141 
00142         bool isRepairing();
00143         bool isHealing();
00144         bool isBeingHealed();
00145         bool isBeingRepaired();
00146 
00147         int getEnergy();
00148         std::list<BWAPI::UnitType> getTrainingQueue();
00149 
00150         int getDistance(BWAPI::UnitType targType, Position position);
00151         int getDistance(Unit unit);
00152         int getDistance(Position position);
00153         int getDistance(Position position, int inFramesTime);
00154 
00155         bool isSelected();
00156 
00157         bool hasPath(Position position);
00158 
00159         BWAPI::UnitCommand getLastCommand();
00160 
00161         bool hasOrder(BWAPI::Order order);
00162 
00163         //Commands
00164         void train(BWAPI::UnitType type);
00165         Unit getBuildUnit();
00166         void gather(Unit unit);
00167         void returnCargo();
00168         void returnCargo(Unit unit);
00169         void build(TilePosition target, BWAPI::UnitType type);
00170         void build(Unit unit);
00171         void morph(BWAPI::UnitType type);
00172         void stop();
00173         bool cancel(int slot = -2);
00174         void upgrade(BWAPI::UpgradeType type);
00175         void research(BWAPI::TechType mType);
00176         void move(Position target, int accuracy = 8);
00177         void attack(Unit unit);
00178         void attack(Position target, int accuracy = 8);
00179         void useTech(BWAPI::TechType tech, Position target);
00180         void useTech(BWAPI::TechType tech, Unit target);
00181 
00182         //Prediction
00183         void promote(BWAPI::Unit* unit);
00184         void setBuildTime(int time);
00185         void setPosition(Position position);
00186 
00187         //save
00188         void update();
00189 
00190 private:
00191         BWAPI::Unit* mUnit;
00192 
00193         Position mStoredPosition;
00194         Position mStoredTargetPosition;
00195         BWAPI::UnitType mStoredType;
00196         Player mStoredPlayer;
00197         bool mStoredCompleted;
00198         bool mStoredMorphing;
00199         int mStoredTime;
00200 
00201         int mStoredCompletedTime;
00202         int mStoredExistsTime;
00203 
00204         int mStoredHealth;
00205         int mStoredShield;
00206 
00207         // getResources
00208         int mStoredInt;
00209 
00210         // isLifted, isSieged
00211         bool mStoredBoolOne;
00212 
00213         AccessType mStoredAccessType;
00214         int mDeleteTimer;
00215         
00216         int mLastOrderExecuteTime;
00217 };
00218 
00219 typedef std::tr1::shared_ptr<UnitClass> Unit;
00220 
00221 class StaticUnits
00222 {
00223 public:
00224         static const Unit nullunit;
00225 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines