BWAPI
UAlbertaBot_src/Projects/UAlbertaBot/Source/base/MetaType.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include "Common.h"
00004 
00005 struct MetaType {
00006 
00007         enum type_enum {Unit, Tech, Upgrade, Command, Default};
00008         type_enum type;
00009 
00010         BWAPI::UnitCommandType commandType;
00011         BWAPI::UnitType unitType;
00012         BWAPI::TechType techType;
00013         BWAPI::UpgradeType upgradeType;
00014 
00015         MetaType () : type(MetaType::Default) {}
00016         MetaType (BWAPI::UnitType t) :        unitType(t),    type(MetaType::Unit) {}
00017         MetaType (BWAPI::TechType t) :        techType(t),    type(MetaType::Tech) {}
00018         MetaType (BWAPI::UpgradeType t) :     upgradeType(t), type(MetaType::Upgrade) {}
00019         MetaType (BWAPI::UnitCommandType t) : commandType(t), type(MetaType::Command) {}
00020 
00021         bool isUnit()           { return type == Unit; }
00022         bool isTech()           { return type == Tech; }
00023         bool isUpgrade()        { return type == Upgrade; }
00024         bool isCommand()        { return type == Command; }
00025         bool isBuilding()       { return type == Unit && unitType.isBuilding(); }
00026         bool isRefinery()       { return isBuilding() && unitType.isRefinery(); }
00027 
00028         int supplyRequired()
00029         {
00030                 if (isUnit())
00031                 {
00032                         return unitType.supplyRequired();
00033                 }
00034                 else
00035                 {
00036                         return 0;
00037                 }
00038         }
00039 
00040         int mineralPrice()
00041         {
00042                 return isUnit() ? unitType.mineralPrice() : (isTech() ? techType.mineralPrice() : upgradeType.mineralPrice());
00043         }
00044 
00045         int gasPrice()
00046         {
00047                 return isUnit() ? unitType.gasPrice() : (isTech() ? techType.gasPrice() : upgradeType.gasPrice());
00048         }
00049 
00050         BWAPI::UnitType whatBuilds()
00051         {
00052                 return isUnit() ? unitType.whatBuilds().first : (isTech() ? techType.whatResearches() : upgradeType.whatUpgrades());
00053         }
00054 
00055         std::string getName()
00056         {
00057                 if (isUnit())
00058                 {
00059                         return unitType.getName();
00060                 }
00061                 else if (isTech())
00062                 {
00063                         return techType.getName();
00064                 }
00065                 else if (isUpgrade())
00066                 {
00067                         return upgradeType.getName();
00068                 }
00069                 else if (isCommand())
00070                 {
00071                         return commandType.getName();
00072                 }
00073                 else
00074                 {
00075                         assert(false);
00076                         return "LOL";   
00077                 }
00078         }
00079 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines