|
BWAPI
|
#include <MineBlockingMineralTask.h>


Public Member Functions | |
| MineBlockingMineralTask (TaskType priority, UnitGroup minerals) | |
| 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 |
Private Attributes | |
| Unit | mUnit |
| UnitGroup | mMinerals |
Definition at line 8 of file MineBlockingMineralTask.h.
| MineBlockingMineralTask::MineBlockingMineralTask | ( | TaskType | priority, |
| UnitGroup | minerals | ||
| ) |
Definition at line 3 of file MineBlockingMineralTask.cpp.
| Position MineBlockingMineralTask::getEndLocation | ( | Unit | unit | ) | const [virtual] |
Implements Task.
Definition at line 29 of file MineBlockingMineralTask.cpp.
{
return unit->getPosition();
}
| int MineBlockingMineralTask::getEndTime | ( | ) | const [virtual] |
Implements Task.
Definition at line 9 of file MineBlockingMineralTask.cpp.
References Requirement::maxTime.
Referenced by getEndTime().
{
return Requirement::maxTime;
}

| int MineBlockingMineralTask::getEndTime | ( | Unit | unit | ) | const [virtual] |
Implements Task.
Definition at line 14 of file MineBlockingMineralTask.cpp.
References getEndTime().
{
return getEndTime();
}

| UnitGroup MineBlockingMineralTask::getFinishedUnits | ( | ) | [virtual] |
Implements Task.
Definition at line 111 of file MineBlockingMineralTask.cpp.
References UnitGroup::insert(), and mUnit.

| virtual std::string MineBlockingMineralTask::getOutputName | ( | ) | const [inline, virtual] |
| int MineBlockingMineralTask::getPriority | ( | Unit | unit | ) | const [virtual] |
| Position MineBlockingMineralTask::getStartLocation | ( | Unit | unit | ) | const [virtual] |
Implements Task.
Definition at line 24 of file MineBlockingMineralTask.cpp.
{
return unit->getPosition();
}
| virtual std::string MineBlockingMineralTask::getTaskName | ( | ) | const [inline, virtual] |
Implements Task.
Definition at line 32 of file MineBlockingMineralTask.h.
{ return "Mine Blocking Mineral"; }
| void MineBlockingMineralTask::giveUnit | ( | Unit | unit | ) | [virtual] |
Implements Task.
Definition at line 96 of file MineBlockingMineralTask.cpp.
References mUnit.
{
mUnit = unit;
}
| bool MineBlockingMineralTask::morph | ( | Unit | unit, |
| BWAPI::UnitType | previousType | ||
| ) | [virtual] |
| bool MineBlockingMineralTask::preUpdate | ( | ) | [virtual] |
Implements Task.
Definition at line 34 of file MineBlockingMineralTask.cpp.
References UnitGroup::begin(), Task::complete(), AccessTypeDef::Dead, UnitGroup::empty(), UnitGroup::end(), UnitGroup::erase(), Task::hasEnded(), mMinerals, and mUnit.
{
for(std::set<Unit>::iterator it = mMinerals.begin(); it != mMinerals.end();)
{
if((*it)->accessibility() == AccessType::Dead)
mMinerals.erase(it++);
else
++it;
}
if(mMinerals.empty())
complete();
return hasEnded() && mUnit;
}

| void MineBlockingMineralTask::returnUnit | ( | Unit | unit | ) | [virtual] |
Implements Task.
Definition at line 101 of file MineBlockingMineralTask.cpp.
References mUnit, and StaticUnits::nullunit.
{
mUnit = StaticUnits::nullunit;
}
| bool MineBlockingMineralTask::update | ( | ) | [virtual] |
Implements Task.
Definition at line 50 of file MineBlockingMineralTask.cpp.
References Task::hasEnded(), mMinerals, and mUnit.
{
if(mUnit)
{
if(mUnit->isCarryingGas() || mUnit->isCarryingMinerals())
mUnit->returnCargo();
else
{
Unit closestMineral;
int closestDistance = std::numeric_limits<int>::max();
for each(Unit mineral in mMinerals)
{
int distance = mineral->getDistance(mUnit);
if(distance < closestDistance)
{
closestMineral = mineral;
closestDistance = distance;
}
}
if(closestMineral)
mUnit->gather(closestMineral);
}
}
return hasEnded() && !mUnit;
}

| void MineBlockingMineralTask::updateRequirements | ( | ) | [virtual] |
Reimplemented from Task.
Definition at line 78 of file MineBlockingMineralTask.cpp.
References Task::addRequirement(), RequirementGroup::addUnitFilterRequirement(), UnitGroup::begin(), Task::clearRequirements(), UnitGroup::empty(), UnitFilterFlags::IsComplete, UnitFilterFlags::IsWorker, Requirement::maxTime, mMinerals, mUnit, and Task::shouldReturnUnit().
{
clearRequirements();
if(!mUnit && !shouldReturnUnit() && !mMinerals.empty())
{
RequirementGroup requirementOne;
requirementOne.addUnitFilterRequirement(35, Requirement::maxTime, UnitFilter(UnitFilterFlags::type(UnitFilterFlags::IsWorker | UnitFilterFlags::IsComplete)), (*mMinerals.begin())->getPosition());
addRequirement(requirementOne);
}
}

| bool MineBlockingMineralTask::waitingForUnit | ( | Unit | unit | ) | const [virtual] |
UnitGroup MineBlockingMineralTask::mMinerals [private] |
Definition at line 38 of file MineBlockingMineralTask.h.
Referenced by preUpdate(), update(), and updateRequirements().
Unit MineBlockingMineralTask::mUnit [private] |
Definition at line 36 of file MineBlockingMineralTask.h.
Referenced by getFinishedUnits(), giveUnit(), preUpdate(), returnUnit(), update(), and updateRequirements().
1.7.6.1