Ejemplo n.º 1
0
size_t UnitUtil::GetAllUnitCount(BWAPI::UnitType type)
{
    size_t count = 0;
    for (const auto & unit : BWAPI::Broodwar->self()->getUnits())
    {
        // trivial case: unit which exists matches the type
        if (unit->getType() == type)
        {
            count++;
        }

        // case where a zerg egg contains the unit type
        if (unit->getType() == BWAPI::UnitTypes::Zerg_Egg && unit->getBuildType() == type)
        {
            count += type.isTwoUnitsInOneEgg() ? 2 : 1;
        }

        // case where a building has started constructing a unit but it doesn't yet have a unit associated with it
        if (unit->getRemainingTrainTime() > 0)
        {
            BWAPI::UnitType trainType = unit->getLastCommand().getUnitType();

            if (trainType == type && unit->getRemainingTrainTime() == trainType.buildTime())
            {
                count++;
            }
        }
    }

    return count;
}
Ejemplo n.º 2
0
// UnitType constructor
ActionTypeData::ActionTypeData(BWAPI::UnitType t, const ActionID id) 
	: type                      (UnitType)
	, unit                      (t)
    , raceID                    (GetRaceID(t.getRace()))
	, actionID                  (id)
	, mineralPriceVal           (t.mineralPrice() * Constants::RESOURCE_SCALE)
	, gasPriceVal               (t.gasPrice() * Constants::RESOURCE_SCALE)
	, supplyRequiredVal         (t.supplyRequired())
	, supplyProvidedVal         (t.supplyProvided())
	, buildTimeVal              (t.buildTime())
	, numberProduced            (1)
	, name                      (t.getName())
	, metaName                  (t.getName())
	, building                  (t.isBuilding())
	, worker                    (t.isWorker())
	, refinery                  (t.isRefinery())
	, resourceDepot             (t.isResourceDepot())
	, supplyProvider            (t.supplyProvided() > 0 && !t.isResourceDepot())
	, canProduceBool            (t.isBuilding() && t.canProduce())
	, canAttackBool             (t.canAttack())
	, whatBuildsUnitType        (t.whatBuilds().first)
    , addon                     (t.isAddon())
    , morphed                   (false)
    , reqAddon                  (false)
    , reqAddonID                (0)
{
	if (t == BWAPI::UnitTypes::Zerg_Zergling || t == BWAPI::UnitTypes::Zerg_Scourge)
	{
		numberProduced = 2;
	}

    if (t == BWAPI::UnitTypes::Zerg_Lair ||
        t == BWAPI::UnitTypes::Zerg_Hive ||
        t == BWAPI::UnitTypes::Zerg_Greater_Spire ||
        t == BWAPI::UnitTypes::Zerg_Lurker ||
        t == BWAPI::UnitTypes::Zerg_Guardian ||
        t == BWAPI::UnitTypes::Zerg_Sunken_Colony ||
        t == BWAPI::UnitTypes::Zerg_Spore_Colony)
    {
        morphed = true;
    }

    setShortName();
}
Ejemplo n.º 3
0
// this will return true if any unit is on the first frame if it's training time remaining
// this can cause issues for the build order search system so don't plan a search on these frames
bool ProductionManager::canPlanBuildOrderNow() const
{
    for (const auto & unit : BWAPI::Broodwar->self()->getUnits())
    {
        if (unit->getRemainingTrainTime() == 0)
        {
            continue;       
        }

        BWAPI::UnitType trainType = unit->getLastCommand().getUnitType();

        if (unit->getRemainingTrainTime() == trainType.buildTime())
        {
            return false;
        }
    }

    return true;
}
Ejemplo n.º 4
0
UnitClass::UnitClass(Position pos, BWAPI::UnitType type, int startTime)
	: mUnit(NULL)
	, mStoredPosition(pos)
	, mStoredTargetPosition(pos)
	, mStoredType(type)
	, mStoredAccessType(AccessType::Prediction)
	, mStoredPlayer(BWAPI::Broodwar->self())
	, mStoredBoolOne(false)
	, mStoredCompleted(false)
	, mStoredMorphing(false)
	, mStoredCompletedTime(startTime + type.buildTime())
	, mStoredTime(BWAPI::Broodwar->getFrameCount())
	, mStoredInt(0)
	, mStoredExistsTime(startTime)
	, mStoredHealth(0)
	, mStoredShield(0)
	, mLastOrderExecuteTime(0)
{
}
Ejemplo n.º 5
0
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;
        }
    }
}