BWAPI
Public Member Functions | Private Member Functions | Private Attributes
UnitTrackerClass Class Reference

#include <UnitTracker.h>

Collaboration diagram for UnitTrackerClass:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 UnitTrackerClass ()
void pumpUnitEvents ()
void update ()
void onUnitDiscover (BWAPI::Unit *unit)
void onUnitDestroy (BWAPI::Unit *unit)
Unit getUnit (BWAPI::Unit *unit)
UnitGroup getUnitGroup (std::set< BWAPI::Unit * > units)
const UnitGroupgetGeysers ()
const UnitGroupgetMinerals ()
const UnitGroupgetSupplyProviders () const
UnitGroup getUnitsOnTile (int x, int y)
const UnitGroupgetAllUnits ()
const UnitGroupselectAllUnits (BWAPI::UnitType type, Player player=BWAPI::Broodwar->self())
const UnitGroupselectAllUnits (Player player=BWAPI::Broodwar->self())
UnitGroup selectAllEnemy (Player player=BWAPI::Broodwar->self())
UnitGroup selectAllEnemy (BWAPI::UnitType type, Player player=BWAPI::Broodwar->self())
void onDiscover (Unit unit)
void onMorphRenegade (Unit unit)
void onDestroy (Unit unit)

Private Member Functions

void checkUnit (Unit unit)

Private Attributes

std::map< BWAPI::Unit *, UnitmUnits
std::map< Unit, PlayermUnitToPlayer
std::map< Unit, BWAPI::UnitTypemUnitToType
std::map< Player, std::map
< BWAPI::UnitType, UnitGroup > > 
mPlayerToTypeToUnits
std::map< Player, UnitGroupmPlayerToUnits
UnitGroup mAllUnits
UnitGroup mMySupplyProviders
bool mOnBeginCalled

Detailed Description

Definition at line 9 of file UnitTracker.h.


Constructor & Destructor Documentation

Definition at line 12 of file UnitTracker.cpp.

        : mOnBeginCalled(false)
{
}

Member Function Documentation

void UnitTrackerClass::checkUnit ( Unit  unit) [private]

Definition at line 183 of file UnitTracker.cpp.

References AccessTypeDef::Dead, mUnitToPlayer, mUnitToType, onDestroy(), and onMorphRenegade().

Referenced by onUnitDiscover(), and update().

{
        unit->update();

        if(mUnitToPlayer[unit] != unit->getPlayer() || mUnitToType[unit] != unit->getType())
                onMorphRenegade(unit);

        AccessType thisAccess = unit->accessibility();
        if(thisAccess == AccessType::Dead)
                onDestroy(unit);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 30 of file UnitTracker.h.

References mAllUnits.

{ return mAllUnits; }

Definition at line 26 of file UnitTracker.h.

References mMySupplyProviders.

{ return mMySupplyProviders; }

Definition at line 155 of file UnitTracker.cpp.

References mUnits, and StaticUnits::nullunit.

{
        std::map<BWAPI::Unit*, Unit>::iterator it = mUnits.find(unit);
        if(it != mUnits.end())
                 return it->second;

        return StaticUnits::nullunit;
}

Definition at line 164 of file UnitTracker.cpp.

References mUnits.

Referenced by getUnitsOnTile().

{
        UnitGroup returnUnits;

        for each(BWAPI::Unit* unit in units)
        {
                std::map<BWAPI::Unit*, Unit>::iterator it = mUnits.find(unit);
                if(it != mUnits.end())
                        returnUnits.insert(it->second);
        }

        return returnUnits;
}

Here is the caller graph for this function:

Definition at line 178 of file UnitTracker.cpp.

References BWAPI::Broodwar, and getUnitGroup().

Here is the call graph for this function:

Definition at line 118 of file UnitTracker.cpp.

References UnitGroup::erase(), Singleton< T >::Instance(), LOGMESSAGE, mAllUnits, mMySupplyProviders, mOnBeginCalled, mPlayerToTypeToUnits, mPlayerToUnits, mUnitToPlayer, and mUnitToType.

Referenced by checkUnit(), and onUnitDestroy().

{
        mAllUnits.erase(unit);
        mPlayerToUnits[mUnitToPlayer[unit]].erase(unit);
        mPlayerToTypeToUnits[mUnitToPlayer[unit]][mUnitToType[unit]].erase(unit);
        mUnitToType.erase(unit);
        mUnitToPlayer.erase(unit);

        mMySupplyProviders.erase(unit);

        if(!mOnBeginCalled)
                return;

        LOGMESSAGE(String_Builder() << "onDestroy() : " << unit->getType().getName() << ", ID : " << unit->getID() << ", Player : " << unit->getPlayer()->getName());

        unit->onDestroy();
        PylonPowerTracker::Instance().onDestroy(unit);
        ResourceManager::Instance().onDestroy(unit);
        BaseTracker::Instance().onDestroy(unit);
        TaskManager::Instance().onDestroy(unit);
        BuildingPlacer::Instance().onDestroy(unit);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 56 of file UnitTracker.cpp.

References BWAPI::Broodwar, UnitGroup::insert(), Singleton< T >::Instance(), LOGMESSAGE, mAllUnits, mMySupplyProviders, mOnBeginCalled, mPlayerToTypeToUnits, mPlayerToUnits, mUnitToPlayer, mUnitToType, and BWAPI::Game::self().

Referenced by onUnitDiscover(), and pumpUnitEvents().

{
        unit->update();

        mUnitToType[unit] = unit->getType();
        mUnitToPlayer[unit] = unit->getPlayer();
        mPlayerToTypeToUnits[unit->getPlayer()][unit->getType()].insert(unit);
        mPlayerToUnits[unit->getPlayer()].insert(unit);
        mAllUnits.insert(unit);

        if(unit->getType().supplyProvided() > 0 && unit->getPlayer() == BWAPI::Broodwar->self())
                mMySupplyProviders.insert(unit);

        if(!mOnBeginCalled)
                return;

        LOGMESSAGE(String_Builder() << "onDiscover() : " << unit->getType().getName() << ", ID : " << unit->getID() << ", Player : " << unit->getPlayer()->getName());

        PylonPowerTracker::Instance().onDiscover(unit);
        PlayerTracker::Instance().onDiscover(unit);
        BaseTracker::Instance().onDiscover(unit);
        TaskManager::Instance().onDiscover(unit);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 80 of file UnitTracker.cpp.

References BWAPI::Broodwar, UnitGroup::erase(), BWAPI::Player::getName(), BWAPI::UnitType::getName(), UnitGroup::insert(), Singleton< T >::Instance(), LOGMESSAGE, mMySupplyProviders, mOnBeginCalled, mPlayerToTypeToUnits, mPlayerToUnits, mUnitToPlayer, mUnitToType, BWAPI::UnitTypes::None, and BWAPI::Game::self().

Referenced by checkUnit().

{
        Player lastPlayer = mUnitToPlayer[unit];
        BWAPI::UnitType lastType = mUnitToType[unit];

        if(lastPlayer != unit->getPlayer() || lastType != unit->getType())
        {
                Player lastPlayerForFunc = lastPlayer == unit->getPlayer() ? NULL : lastPlayer;
                BWAPI::UnitType lastTypeForFunc = lastType == unit->getType() ? BWAPI::UnitTypes::None : lastType;
                //TODO: unit has morphed, if its morphing into something known set the completed time to the build time

                if(mOnBeginCalled)
                {
                        LOGMESSAGE(String_Builder() << "onMorphRenegade() : " << unit->getType().getName() << ", ID : " << unit->getID() << ", Player : " << unit->getPlayer()->getName());
                        if(lastTypeForFunc != BWAPI::UnitTypes::None)
                                LOGMESSAGE(String_Builder() << "    Previous Type : " << lastTypeForFunc.getName());
                        if(lastPlayerForFunc != NULL)
                                LOGMESSAGE(String_Builder() << "    Previous Player : " << lastPlayerForFunc->getName());

                        PylonPowerTracker::Instance().onMorphRenegade(unit, lastPlayerForFunc, lastTypeForFunc);
                        PlayerTracker::Instance().onMorphRenegade(unit, lastPlayerForFunc, lastTypeForFunc);
                        BaseTracker::Instance().onMorphRenegade(unit, lastPlayerForFunc, lastTypeForFunc);
                        TaskManager::Instance().onMorphRenegade(unit, lastPlayerForFunc, lastTypeForFunc);

                        mPlayerToUnits[lastPlayer].erase(unit);
                        mPlayerToTypeToUnits[lastPlayer][lastType].erase(unit);
                        mUnitToType[unit] = unit->getType();
                        mUnitToPlayer[unit] = unit->getPlayer();
                        mPlayerToUnits[unit->getPlayer()].insert(unit);
                        mPlayerToTypeToUnits[unit->getPlayer()][unit->getType()].insert(unit);
                }

                mMySupplyProviders.erase(unit);
                if(unit->getType().supplyProvided() > 0 && unit->getPlayer() == BWAPI::Broodwar->self())
                        mMySupplyProviders.insert(unit);
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 46 of file UnitTracker.cpp.

References mUnits, and onDestroy().

{
        std::map<BWAPI::Unit*, Unit>::iterator it = mUnits.find(unit);
        if(it != mUnits.end())
        {
                onDestroy(it->second);
                mUnits.erase(it);
        }
}

Here is the call graph for this function:

Definition at line 24 of file UnitTracker.cpp.

References checkUnit(), Singleton< T >::Instance(), mUnits, and onDiscover().

{
        std::map<BWAPI::Unit*, Unit>::iterator it = mUnits.find(unit);
        if(it != mUnits.end())
        {
                checkUnit(it->second);
                return;
        }

        Unit prediction = UnitPredictor::Instance().onNewUnit(unit);
        if(prediction)
        {
                mUnits[unit] = prediction;
                return;
        }

        Unit newUnit(new UnitClass(unit));
        mUnits[unit] = newUnit;

        onDiscover(newUnit);
}

Here is the call graph for this function:

Definition at line 17 of file UnitTracker.cpp.

References mOnBeginCalled, mUnits, and onDiscover().

{
        mOnBeginCalled = true;
        for(std::map<BWAPI::Unit*, Unit>::iterator it = mUnits.begin(); it != mUnits.end(); ++it)
                onDiscover(it->second);
}

Here is the call graph for this function:

Definition at line 195 of file UnitTracker.cpp.

References Singleton< T >::Instance(), and mPlayerToUnits.

{
        UnitGroup enemies;
        for each(Player player in PlayerTracker::Instance().getEnemies(player))
        {
                enemies += mPlayerToUnits[player];
        }

        return enemies;
}

Here is the call graph for this function:

Definition at line 206 of file UnitTracker.cpp.

References Singleton< T >::Instance(), and mPlayerToTypeToUnits.

{
        UnitGroup enemies;
        for each(Player player in PlayerTracker::Instance().getEnemies(player))
        {
                enemies += mPlayerToTypeToUnits[player][type];
        }

        return enemies;
}

Here is the call graph for this function:

const UnitGroup& UnitTrackerClass::selectAllUnits ( BWAPI::UnitType  type,
Player  player = BWAPI::Broodwar->self() 
) [inline]

Definition at line 31 of file UnitTracker.h.

References mPlayerToTypeToUnits.

{ return mPlayerToTypeToUnits[player][type]; }
const UnitGroup& UnitTrackerClass::selectAllUnits ( Player  player = BWAPI::Broodwar->self()) [inline]

Definition at line 32 of file UnitTracker.h.

References mPlayerToUnits.

{ return mPlayerToUnits[player]; }

Definition at line 141 of file UnitTracker.cpp.

References UnitGroup::begin(), checkUnit(), AccessTypeDef::Dead, UnitGroup::end(), mAllUnits, and mUnits.

{
        for(std::set<Unit>::iterator it = mAllUnits.begin(); it != mAllUnits.end();)
                checkUnit(*(it++));

        for(std::map<BWAPI::Unit*, Unit>::iterator it = mUnits.begin(); it != mUnits.end();)
        {
                if(it->second->accessibility() == AccessType::Dead)
                        mUnits.erase(it++);
                else
                        ++it;
        }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 49 of file UnitTracker.h.

Referenced by getAllUnits(), onDestroy(), onDiscover(), and update().

Definition at line 51 of file UnitTracker.h.

Referenced by getSupplyProviders(), onDestroy(), onDiscover(), and onMorphRenegade().

Definition at line 53 of file UnitTracker.h.

Referenced by onDestroy(), onDiscover(), onMorphRenegade(), and pumpUnitEvents().

Definition at line 47 of file UnitTracker.h.

Referenced by onDestroy(), onDiscover(), onMorphRenegade(), selectAllEnemy(), and selectAllUnits().

std::map<BWAPI::Unit*, Unit> UnitTrackerClass::mUnits [private]

Definition at line 43 of file UnitTracker.h.

Referenced by checkUnit(), onDestroy(), onDiscover(), and onMorphRenegade().

Definition at line 44 of file UnitTracker.h.

Referenced by checkUnit(), onDestroy(), onDiscover(), and onMorphRenegade().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines