BWAPI
Skynet/Skynet/GameProgressDetection.cpp
Go to the documentation of this file.
00001 #include "GameProgressDetection.h"
00002 
00003 #include "UnitTracker.h"
00004 #include "ResourceTracker.h"
00005 #include "PlayerTracker.h"
00006 #include "MacroManager.h"
00007 
00008 void GameProgressDetectionClass::update()
00009 {
00010         mState = StateType::TechNormal;
00011         mShouldGG = false;
00012         mShouldAttack = true;
00013 
00014         int enemyKnownSupply = 0;
00015         int enemyGuessSupply = 0;
00016         int mySupply = BWAPI::Broodwar->self()->supplyUsed();
00017 
00018         for each(Unit unit in UnitTracker::Instance().selectAllEnemy())
00019         {
00020                 int supply = unit->getType().supplyRequired();
00021 
00022                 if(unit->accessibility() != AccessType::Lost)
00023                         enemyKnownSupply += supply;
00024 
00025                 enemyGuessSupply += supply;
00026         }
00027 
00028         if(PlayerTracker::Instance().getEnemies().size() < 2)
00029         {
00030                 int buildingCount = 0;
00031                 for each(Unit unit in UnitTracker::Instance().selectAllUnits())
00032                 {
00033                         if(unit->getType().isBuilding() && !unit->getType().isAddon())
00034                                 ++buildingCount;
00035                 }
00036 
00037                 if(buildingCount != 0)
00038                 {
00039                         if(enemyKnownSupply > mySupply*2 && ResourceTracker::Instance().getMineralRate() < 5.0)
00040                                 mShouldGG = true;
00041 
00042                         if(enemyGuessSupply > mySupply*3 && ResourceTracker::Instance().getMineralRate() < 5.0)
00043                                 mShouldGG = true;
00044 
00045                         if(enemyGuessSupply > mySupply*4 || enemyKnownSupply > mySupply*3)
00046                                 mShouldGG = true;
00047                 }
00048         }
00049         
00050         // if bases available to attack are up small chokes, dont attack without recall or a much bigger army
00051         if(BWAPI::Broodwar->self()->getRace() == BWAPI::Races::Protoss)
00052         {
00053                 if(UnitTracker::Instance().selectAllUnits(BWAPI::UnitTypes::Protoss_Observer).size() == 0)
00054                 {
00055                         if(BWAPI::Broodwar->getFrameCount() > 24*60*10)
00056                                 mState = StateType::TechHigh;
00057                         else if((UnitTracker::Instance().selectAllEnemy(BWAPI::UnitTypes::Zerg_Lurker).size() + UnitTracker::Instance().selectAllEnemy(BWAPI::UnitTypes::Protoss_Dark_Templar).size()) > 0)
00058                                 mState = StateType::TechHigh;
00059                 }
00060                 if(BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Leg_Enhancements) == 0 && !BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Leg_Enhancements) && PlayerTracker::Instance().enemyHasReseached(BWAPI::TechTypes::Tank_Siege_Mode))
00061                         mState = StateType::TechHigh;
00062 
00063                 if(PlayerTracker::Instance().isEnemyRace(BWAPI::Races::Protoss) && !MacroManager::Instance().hasRequirements(BWAPI::UnitTypes::Protoss_High_Templar) && UnitTracker::Instance().selectAllUnits(BWAPI::UnitTypes::Protoss_Reaver).empty())
00064                 {
00065                         if(BWAPI::Broodwar->getFrameCount() > 24*60*12 || (UnitTracker::Instance().selectAllEnemy(BWAPI::UnitTypes::Protoss_High_Templar).size() + UnitTracker::Instance().selectAllEnemy(BWAPI::UnitTypes::Protoss_Reaver).size()) > 0)
00066                                 mState = StateType::TechHigh;
00067                 }
00068         }
00069 
00070         if(mState != StateType::TechHigh)
00071         {
00072                 if(enemyGuessSupply > mySupply)//TODO: also if attacking successfully
00073                         mState = StateType::BuildArmy;
00074                 else
00075                 {
00076                         if(!mShouldAttack || mySupply > 380)
00077                                 mState = StateType::TechHigh;
00078                 }
00079         }
00080 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines