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

#include <MorphTask.h>

Inheritance diagram for MorphTask:
Inheritance graph
[legend]
Collaboration diagram for MorphTask:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MorphTask (TaskType priority, BWAPI::UnitType type)
virtual int getEndTime () const
virtual int getEndTime (Unit unit) const
virtual int getPriority (Unit unit) const
virtual Position getStartLocation (Unit unit) const
virtual Position getEndLocation (Unit unit) const
virtual bool preUpdate ()
virtual bool update ()
virtual void updateRequirements ()
virtual bool waitingForUnit (Unit unit) const
virtual void giveUnit (Unit unit)
virtual void returnUnit (Unit unit)
virtual bool morph (Unit unit, BWAPI::UnitType previousType)
virtual UnitGroup getFinishedUnits ()
virtual std::string getTaskName () const
virtual std::string getOutputName () const
virtual void setRequiredSatisfyTime (RequirementGroup requirements, int time, int delay)
virtual int dispatchTime () const
virtual int startTime () const
virtual bool hasDispatched () const
virtual bool inProgress () const

Private Member Functions

void reserveResources ()
void freeResources ()

Private Attributes

BWAPI::UnitType mType
Unit mUnit
int mRequiredSatisfyTime
bool mReservedResources

Detailed Description

Definition at line 7 of file MorphTask.h.


Constructor & Destructor Documentation

MorphTask::MorphTask ( TaskType  priority,
BWAPI::UnitType  type 
)

Definition at line 5 of file MorphTask.cpp.

        : Task(priority)
        , mType(type)
        , mReservedResources(false)
        , mRequiredSatisfyTime(BWAPI::Broodwar->getFrameCount())
{
}

Member Function Documentation

virtual int MorphTask::dispatchTime ( ) const [inline, virtual]

Reimplemented from Task.

Definition at line 36 of file MorphTask.h.

References mRequiredSatisfyTime.

void MorphTask::freeResources ( ) [private]

Definition at line 138 of file MorphTask.cpp.

References BWAPI::UnitType::gasPrice(), Singleton< T >::Instance(), BWAPI::UnitType::mineralPrice(), mRequiredSatisfyTime, mReservedResources, mType, and BWAPI::UnitType::supplyRequired().

Referenced by morph(), and updateRequirements().

Here is the call graph for this function:

Here is the caller graph for this function:

Position MorphTask::getEndLocation ( Unit  unit) const [virtual]

Implements Task.

Definition at line 31 of file MorphTask.cpp.

{
        return unit->getPosition();
}
int MorphTask::getEndTime ( ) const [virtual]

Implements Task.

Definition at line 13 of file MorphTask.cpp.

References BWAPI::UnitType::buildTime(), Task::isCompleted(), mRequiredSatisfyTime, mType, and mUnit.

Referenced by getEndTime().

{
        if(mUnit && (mUnit->isMorphing() || !isCompleted()))
                return mUnit->getCompletedTime();

        return mRequiredSatisfyTime + mType.buildTime();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int MorphTask::getEndTime ( Unit  unit) const [virtual]

Implements Task.

Definition at line 21 of file MorphTask.cpp.

References getEndTime().

{
        return getEndTime();
}

Here is the call graph for this function:

Implements Task.

Definition at line 91 of file MorphTask.cpp.

References UnitGroup::insert(), and mUnit.

{
        UnitGroup returnUnits;

        if(mUnit)
                returnUnits.insert(mUnit);

        return returnUnits;
}

Here is the call graph for this function:

virtual std::string MorphTask::getOutputName ( ) const [inline, virtual]

Implements Task.

Definition at line 32 of file MorphTask.h.

References BWAPI::UnitType::getName(), and mType.

{ return mType.getName(); }

Here is the call graph for this function:

int MorphTask::getPriority ( Unit  unit) const [virtual]

Implements Task.

Definition at line 101 of file MorphTask.cpp.

{
        return 40;
}
Position MorphTask::getStartLocation ( Unit  unit) const [virtual]

Implements Task.

Definition at line 26 of file MorphTask.cpp.

{
        return unit->getPosition();
}
virtual std::string MorphTask::getTaskName ( ) const [inline, virtual]

Implements Task.

Definition at line 31 of file MorphTask.h.

{ return "Morphing"; }
void MorphTask::giveUnit ( Unit  unit) [virtual]

Implements Task.

Definition at line 60 of file MorphTask.cpp.

References mType, mUnit, reserveResources(), and BWAPI::UnitType::whatBuilds().

{
        if(unit->getType() == mType.whatBuilds().first)
        {
                mUnit = unit;
                reserveResources();
        }
}

Here is the call graph for this function:

virtual bool MorphTask::hasDispatched ( ) const [inline, virtual]

Reimplemented from Task.

Definition at line 39 of file MorphTask.h.

References mUnit.

{ return mUnit; }
virtual bool MorphTask::inProgress ( ) const [inline, virtual]

Reimplemented from Task.

Definition at line 40 of file MorphTask.h.

References mUnit.

{ return mUnit && mUnit->isMorphing(); }
bool MorphTask::morph ( Unit  unit,
BWAPI::UnitType  previousType 
) [virtual]

Implements Task.

Definition at line 80 of file MorphTask.cpp.

References freeResources(), and mType.

{
        if(unit->getType() == mType || unit->getBuildType() == mType)
        {
                freeResources();
                return false;
        }

        return true;
}

Here is the call graph for this function:

bool MorphTask::preUpdate ( ) [virtual]

Implements Task.

Definition at line 36 of file MorphTask.cpp.

References Task::complete(), mType, and mUnit.

{
        if(mUnit && mUnit->isCompleted() && mUnit->getType() == mType)
        {
                complete();
                return true;
        }

        return false;
}

Here is the call graph for this function:

void MorphTask::reserveResources ( ) [private]

Definition at line 127 of file MorphTask.cpp.

References BWAPI::UnitType::gasPrice(), Task::hasEnded(), Singleton< T >::Instance(), BWAPI::UnitType::mineralPrice(), mRequiredSatisfyTime, mReservedResources, mType, and BWAPI::UnitType::supplyRequired().

Referenced by giveUnit(), and returnUnit().

Here is the call graph for this function:

Here is the caller graph for this function:

void MorphTask::returnUnit ( Unit  unit) [virtual]

Implements Task.

Definition at line 69 of file MorphTask.cpp.

References mUnit, StaticUnits::nullunit, and reserveResources().

{
        if(mUnit == unit)
        {
                reserveResources();
                mUnit = StaticUnits::nullunit;
        }
        else
                assert(false);
}

Here is the call graph for this function:

virtual void MorphTask::setRequiredSatisfyTime ( RequirementGroup  requirements,
int  time,
int  delay 
) [inline, virtual]

Reimplemented from Task.

Definition at line 34 of file MorphTask.h.

References mRequiredSatisfyTime.

virtual int MorphTask::startTime ( ) const [inline, virtual]

Reimplemented from Task.

Definition at line 37 of file MorphTask.h.

References mRequiredSatisfyTime.

bool MorphTask::update ( ) [virtual]

Implements Task.

Definition at line 47 of file MorphTask.cpp.

References Task::hasEnded(), mType, and mUnit.

{
        if(mUnit && mUnit->getType() != mType)
                mUnit->morph(mType);

        return hasEnded() && !mUnit;
}

Here is the call graph for this function:

void MorphTask::updateRequirements ( ) [virtual]
bool MorphTask::waitingForUnit ( Unit  unit) const [virtual]

Implements Task.

Definition at line 55 of file MorphTask.cpp.

{
        return false;
}

Member Data Documentation

Definition at line 49 of file MorphTask.h.

Referenced by freeResources(), and reserveResources().


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