void InformationManager::updateBuildTime(BWAPI::UnitType type, int time) { std::map<BWAPI::UnitType, int>::iterator i=buildTime.find(type); if (i!=buildTime.end() && (i->second<=time || i->second==0)) return; buildTime[type]=time; if (time<0) return; for(std::map<const BWAPI::UnitType*,int>::const_iterator i=type.requiredUnits().begin();i!=type.requiredUnits().end();i++) { updateBuildTime(*i->first,time-i->first->buildTime()); } }
void InformationManager::onUnitShow(BWAPI::Unit* unit) { savedData[unit].exists=true; if (!BWAPI::Broodwar->self()->isEnemy(unit->getPlayer())) return; int time=BWAPI::Broodwar->getFrameCount(); BWAPI::UnitType type=unit->getType(); updateBuildTime(type,time-type.buildTime()); if (unit->getType().isResourceDepot()) { BWTA::BaseLocation* b=BWTA::getNearestBaseLocation(unit->getTilePosition()); enemyBases.insert(b); enemyBaseCenters[b]=unit; } }
void InformationManager::onUnitDiscover( BWAPI::Unit* unit ) { // Sanity check if ( unit == NULL ) { return; } m_savedData[unit].m_exists = true; // If this is an enemy unit, try to infer build time and start location, and base location if ( BWAPI::Broodwar->self()->isEnemy( unit->getPlayer() ) ) { int time = BWAPI::Broodwar->getFrameCount(); BWAPI::UnitType type = unit->getType(); updateBuildTime( type, time - type.buildTime() ); if ( m_scoutedAnEnemyBase == false && unit->getType().isBuilding() ) { // We haven't scouted the enemy base yet, but this is a building BWTA::Region* r = BWTA::getRegion( unit->getTilePosition() ); if ( r->getBaseLocations().size() == 1 ) { // So the enemy probably spawned here. BWTA::BaseLocation* b = *( r->getBaseLocations().begin() ); m_enemyBases.insert( b ); m_scoutedAnEnemyBase = true; } } if ( unit->getType().isResourceDepot() ) { // This is a center, so we know its a base location BWTA::BaseLocation* b = BWTA::getNearestBaseLocation( unit->getTilePosition() ); m_enemyBases.insert( b ); m_enemyBaseCenters[b] = unit; m_scoutedAnEnemyBase = true; } } }
void InformationManager::updateBuildTime( BWAPI::UnitType type, int time ) { std::map< BWAPI::UnitType, int >::iterator i = m_buildTime.find( type ); if ( i != m_buildTime.end() && ( i->second <= time || i->second == 0 ) ) { // We have already determined an earlier build time return; } m_buildTime[type] = time; // Sanity check if ( time < 0 ) { return; } // Update earliest known build times of required units for ( std::map< BWAPI::UnitType, int >::const_iterator r = type.requiredUnits().begin(); r != type.requiredUnits().end(); r++ ) { updateBuildTime( r->first, time - r->first.buildTime() ); } }