BWAPI
Functions
UnitHelper Namespace Reference

Functions

bool unitProducesGround (BWAPI::UnitType type)
std::vector< UnitGroupgetClusters (const UnitGroup &units, int distance, int minSize)
bool hasAddon (BWAPI::UnitType type)
bool isStaticDefense (BWAPI::UnitType type)
bool isArmyUnit (BWAPI::UnitType type)
Position tileToPosition (TilePosition tile, BWAPI::UnitType type)
int getDistance (const Position &pos1, const BWAPI::UnitType type1, const Position &pos2, const BWAPI::UnitType type2)
int getDistance (const Position &pos1, const BWAPI::UnitType type1, const Position &pos2)

Function Documentation

std::vector< UnitGroup > UnitHelper::getClusters ( const UnitGroup units,
int  distance,
int  minSize 
)

Definition at line 35 of file UnitHelper.cpp.

References UnitGroup::insert().

Referenced by TerrainAnaysisClass::createBases(), and PlayerTrackerClass::update().

{
        std::vector<UnitGroup> clusters;

        for each(Unit unit in units)
        {
                std::vector<size_t> clustersInRange;
                for(size_t i = 0; i < clusters.size(); ++i)
                {
                        for each(Unit clusterUnit in clusters[i])
                        {
                                if(unit->getPosition().getApproxDistance(clusterUnit->getPosition()) <= distance)
                                {
                                        clustersInRange.push_back(i);
                                        break;
                                }
                        }
                }

                if(clustersInRange.empty())
                {
                        UnitGroup newCluster;
                        newCluster.insert(unit);
                        clusters.push_back(newCluster);
                }
                else
                {
                        clusters[clustersInRange[0]].insert(unit);

                        for(size_t i = 1; i < clustersInRange.size(); ++i)
                        {
                                for each(Unit clusterUnit in clusters[clustersInRange[i]])
                                {
                                        clusters[clustersInRange[0]].insert(clusterUnit);
                                }
                                clusters[clustersInRange[i]].clear();
                        }
                }
        }

        clusters.erase(std::remove_if(clusters.begin(), clusters.end(), ClusterCompare(minSize)), clusters.end());

        return clusters;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int UnitHelper::getDistance ( const Position pos1,
const BWAPI::UnitType  type1,
const Position pos2,
const BWAPI::UnitType  type2 
)

Definition at line 129 of file UnitHelper.cpp.

References BWAPI::UnitType::dimensionDown(), BWAPI::UnitType::dimensionLeft(), BWAPI::UnitType::dimensionRight(), BWAPI::UnitType::dimensionUp(), BWAPI::Position::getApproxDistance(), BWAPI::Position::x(), and BWAPI::Position::y().

{
        const int uLeft       = pos1.x() - type1.dimensionLeft();
        const int uTop        = pos1.y() - type1.dimensionUp();
        const int uRight      = pos1.x() + type1.dimensionRight() + 1;
        const int uBottom     = pos1.y() + type1.dimensionDown() + 1;

        const int targLeft    = pos2.x() - type2.dimensionLeft();
        const int targTop     = pos2.y() - type2.dimensionUp();
        const int targRight   = pos2.x() + type2.dimensionRight() + 1;
        const int targBottom  = pos2.y() + type2.dimensionDown() + 1;

        int xDist = uLeft - targRight;
        if(xDist < 0)
        {
                xDist = targLeft - uRight;
                if(xDist < 0)
                        xDist = 0;
        }

        int yDist = uTop - targBottom;
        if(yDist < 0)
        {
                yDist = targTop - uBottom;
                if(yDist < 0)
                        yDist = 0;
        }

        return Position(0, 0).getApproxDistance(Position(xDist, yDist));
}

Here is the call graph for this function:

int UnitHelper::getDistance ( const Position pos1,
const BWAPI::UnitType  type1,
const Position pos2 
)

Definition at line 160 of file UnitHelper.cpp.

References BWAPI::UnitType::dimensionDown(), BWAPI::UnitType::dimensionLeft(), BWAPI::UnitType::dimensionRight(), BWAPI::UnitType::dimensionUp(), BWAPI::Position::getApproxDistance(), BWAPI::Position::x(), and BWAPI::Position::y().

{
        const int uLeft       = pos1.x() - type1.dimensionLeft();
        const int uTop        = pos1.y() - type1.dimensionUp();
        const int uRight      = pos1.x() + type1.dimensionRight() + 1;
        const int uBottom     = pos1.y() + type1.dimensionDown() + 1;

        int xDist = uLeft - (pos2.x() + 1);
        if(xDist < 0)
        {
                xDist = pos2.x() - uRight;
                if(xDist < 0)
                        xDist = 0;
        }

        int yDist = uTop - (pos2.y() + 1);
        if(yDist < 0)
        {
                yDist = pos2.y() - uBottom;
                if(yDist < 0)
                        yDist = 0;
        }

        return Position(0, 0).getApproxDistance(Position(xDist, yDist));
}

Here is the call graph for this function:

Definition at line 103 of file UnitHelper.cpp.

References BWAPI::Broodwar, BWAPI::UnitType::isBuilding(), BWAPI::UnitType::isSpell(), BWAPI::UnitType::isWorker(), BWAPI::UnitTypes::Protoss_Interceptor, BWAPI::UnitTypes::Protoss_Observer, BWAPI::UnitTypes::Protoss_Scarab, BWAPI::UnitTypes::Terran_Vulture_Spider_Mine, BWAPI::UnitTypes::Zerg_Egg, and BWAPI::UnitTypes::Zerg_Larva.

Referenced by UnitFilter::filter(), DetectorAction::update(), ArbiterAction::update(), BasicUnitAction::update(), and BaseClass::update().

{
        if(type.isBuilding())
                return false;
        if(type.isSpell())
                return false;
        if(type.isWorker())
                return false;
        if(type == BWAPI::Broodwar->self()->getRace().getSupplyProvider())
                return false;
        if(type == BWAPI::UnitTypes::Zerg_Egg)
                return false;
        if(type == BWAPI::UnitTypes::Protoss_Interceptor)
                return false;
        if(type == BWAPI::UnitTypes::Terran_Vulture_Spider_Mine)
                return false;
        if(type == BWAPI::UnitTypes::Zerg_Larva)
                return false;
        if(type == BWAPI::UnitTypes::Protoss_Scarab)
                return false;
        if(type == BWAPI::UnitTypes::Protoss_Observer)
                return false;

        return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 88 of file UnitHelper.cpp.

References BWAPI::UnitType::tileHeight(), BWAPI::UnitType::tileWidth(), BWAPI::TilePosition::x(), and BWAPI::TilePosition::y().

{
        return Position(tile.x()*32+(type.tileWidth()*16), tile.y()*32+(type.tileHeight()*16));
}

Here is the call graph for this function:

Definition at line 5 of file UnitHelper.cpp.

References BWAPI::UnitTypes::allUnitTypes(), BWAPI::UnitType::isFlyer(), and BWAPI::UnitType::whatBuilds().

Referenced by BuildingPlacerClass::isLocationNonBlocking().

{
        static std::set<BWAPI::UnitType> unitData;
        if(unitData.empty())
        {
                for each(BWAPI::UnitType type in BWAPI::UnitTypes::allUnitTypes())
                {
                        if(!type.isFlyer() && type.whatBuilds().first.isBuilding())
                                unitData.insert(type.whatBuilds().first);
                }
        }

        return unitData.count(type) != 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines