|
BWAPI
|
#include <DefaultSquad.h>


Public Member Functions | |
| DefaultSquadTask (ArmyBehaviour behaviour) | |
| 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 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 |
| unsigned int | controlSize () |
| virtual void | updateRequirements () |
Private Attributes | |
| UnitGroup | mUnits |
| std::map< Unit, Behaviour > | mUnitBehaviours |
| Unit | mObserver |
| Goal | mLastGoal |
| bool | mEngageFull |
Definition at line 8 of file DefaultSquad.h.
| DefaultSquadTask::DefaultSquadTask | ( | ArmyBehaviour | behaviour | ) |
Definition at line 11 of file DefaultSquad.cpp.
: BaseSquadTask(behaviour) , mEngageFull(false) { }
| unsigned int DefaultSquadTask::controlSize | ( | ) | [inline, virtual] |
Implements BaseSquadTask.
Definition at line 33 of file DefaultSquad.h.
References mUnits, and UnitGroup::size().

| Position DefaultSquadTask::getEndLocation | ( | Unit | unit | ) | const [virtual] |
Implements BaseSquadTask.
Definition at line 37 of file DefaultSquad.cpp.
{
return unit->getPosition();
}
| int DefaultSquadTask::getEndTime | ( | ) | const [virtual] |
Implements BaseSquadTask.
Definition at line 17 of file DefaultSquad.cpp.
References Requirement::maxTime.
{
return Requirement::maxTime;
}
| int DefaultSquadTask::getEndTime | ( | Unit | unit | ) | const [virtual] |
Implements BaseSquadTask.
Definition at line 22 of file DefaultSquad.cpp.
References Requirement::maxTime.
{
return Requirement::maxTime;
}
| UnitGroup DefaultSquadTask::getFinishedUnits | ( | ) | [virtual] |
Implements BaseSquadTask.
Definition at line 297 of file DefaultSquad.cpp.
References mUnits.
{
return mUnits;
}
| virtual std::string DefaultSquadTask::getOutputName | ( | ) | const [inline, virtual] |
| int DefaultSquadTask::getPriority | ( | Unit | unit | ) | const [virtual] |
Implements BaseSquadTask.
Definition at line 27 of file DefaultSquad.cpp.
{
return unit->getType().isWorker() ? 5 : 20;
}
| Position DefaultSquadTask::getStartLocation | ( | Unit | unit | ) | const [virtual] |
Implements BaseSquadTask.
Definition at line 32 of file DefaultSquad.cpp.
{
return unit->getPosition();
}
| virtual std::string DefaultSquadTask::getTaskName | ( | ) | const [inline, virtual] |
| void DefaultSquadTask::giveUnit | ( | Unit | unit | ) | [virtual] |
Implements BaseSquadTask.
Definition at line 271 of file DefaultSquad.cpp.
References UnitGroup::insert(), mObserver, mUnitBehaviours, mUnits, and BWAPI::UnitTypes::Protoss_Observer.
{
if(unit->getType() == BWAPI::UnitTypes::Protoss_Observer)
mObserver = unit;
mUnits.insert(unit);
mUnitBehaviours[unit] = Behaviour(unit);
}

| bool DefaultSquadTask::morph | ( | Unit | unit, |
| BWAPI::UnitType | previousType | ||
| ) | [virtual] |
| bool DefaultSquadTask::preUpdate | ( | ) | [virtual] |
Implements BaseSquadTask.
Definition at line 42 of file DefaultSquad.cpp.
References Task::hasEnded(), and updateRequirements().
{
updateRequirements();
return hasEnded();
}

| void DefaultSquadTask::returnUnit | ( | Unit | unit | ) | [virtual] |
Implements BaseSquadTask.
Definition at line 281 of file DefaultSquad.cpp.
References UnitGroup::erase(), mObserver, mUnitBehaviours, mUnits, and StaticUnits::nullunit.
{
mUnits.erase(unit);
mUnitBehaviours[unit].onDeleted();
mUnitBehaviours.erase(unit);
if(unit == mObserver)
mObserver = StaticUnits::nullunit;
}

| bool DefaultSquadTask::update | ( | ) | [virtual] |
Implements BaseSquadTask.
Definition at line 66 of file DefaultSquad.cpp.
References ArmyBehaviourDef::Aggresive, ActionTypeDef::Attack, GoalTypeDef::Base, BWAPI::Broodwar, UnitGroup::canMajorityAttack(), ActionTypeDef::Defend, PositionTypeDef::DefenseChokepoint, UnitGroup::empty(), Goal::getActionType(), Goal::getBase(), BWAPI::Player::getForce(), Goal::getGoalType(), getLargestChoke(), Task::hasEnded(), ActionTypeDef::Hold, Singleton< T >::Instance(), UnitGroup::isAnyInRange(), UnitHelper::isStaticDefense(), UnitGroup::isWorthEngaging(), BWAPI::UpgradeTypes::Leg_Enhancements, AccessTypeDef::Lost, BaseSquadTask::mArmyBehaviour, BorderPosition::mChoke, mEngageFull, UnitGroup::minDistanceBetween(), mLastGoal, mUnitBehaviours, mUnits, GoalTypeDef::None, BWAPI::BulletTypes::None, UnitGroup::ratingDifference(), BWAPI::Game::self(), UnitGroup::size(), BWAPI::Player::supplyUsed(), BWAPI::TechTypes::Tank_Siege_Mode, PositionTypeDef::TechDefenseChokepoint, StateTypeDef::TechHigh, and BWAPI::Races::Terran.
{
Goal squadsGoal;
// Just attack if its not mining anywhere
bool hasMiningBases = false;
int techStructures = 0;
Base baseToDefend;
bool baseUnderAttack = false;
const int mySupply = BWAPI::Broodwar->self()->supplyUsed();
for each(Base base in BaseTracker::Instance().getPlayerBases())
{
const int techBuildings = base->getNumberOfTechBuildings();
if(!base->getEnemyThreats().empty() && (techBuildings > 0 || (!base->isMinedOut() && base->getResourceDepot())))
{
bool thisUnderAttack = base->isUnderAttack();
if((thisUnderAttack && !baseUnderAttack) || (thisUnderAttack == baseUnderAttack && techBuildings > techStructures))
{
baseUnderAttack = thisUnderAttack;
baseToDefend = base;
techStructures = techBuildings;
}
}
if(!base->getMinerals().empty() && base->getResourceDepot() && base->getResourceDepot()->exists())
hasMiningBases = true;
}
UnitGroup avoidGroup;
UnitGroup engageGroup;
for each(const UnitGroup &unitGroup in PlayerTracker::Instance().getEnemyClusters())
{
if(!hasMiningBases && mUnits.canMajorityAttack(unitGroup))
{
engageGroup += unitGroup;
continue;
}
if(mUnits.minDistanceBetween(unitGroup) > 540)
continue;
const int rating = mUnits.ratingDifference(unitGroup);
if(mySupply < 360 && ((!mEngageFull && rating < -350) || rating < -1000))
avoidGroup += unitGroup;
else if(mUnits.canMajorityAttack(unitGroup) && (mUnits.isWorthEngaging(unitGroup) || unitGroup.isAnyInRange(mUnits)))
engageGroup += unitGroup;
}
mEngageFull = !engageGroup.empty();
if(mEngageFull)
squadsGoal = Goal(ActionType::Attack, engageGroup, avoidGroup);
else if(baseUnderAttack)
{
const int rating = mUnits.ratingDifference(baseToDefend->getEnemyThreats());
if(rating >= 0 || (rating > -1000 && baseUnderAttack))
squadsGoal = Goal(ActionType::Defend, baseToDefend->getEnemyThreats(), avoidGroup);
}
if(squadsGoal.getGoalType() == GoalType::None)
{
for each(Base base in BaseTracker::Instance().getPlayerBases())
{
if(base->isContested())
{
for each(Unit building in base->getBuildings())
{
if(BWAPI::Broodwar->self()->isEnemy(building->getPlayer()))
{
squadsGoal = Goal(ActionType::Attack, building, engageGroup, avoidGroup);
break;
}
}
}
if(squadsGoal.getGoalType() != GoalType::None)
break;
}
}
if(squadsGoal.getGoalType() == GoalType::None)
{
int enemyKnownSupply = 0;
int enemyGuessSupply = 0;
for each(Unit unit in UnitTracker::Instance().selectAllEnemy())
{
int supply = unit->getType().supplyRequired();
if(UnitHelper::isStaticDefense(unit->getType()))
supply = 7;
if(unit->accessibility() != AccessType::Lost)
enemyKnownSupply += supply;
enemyGuessSupply += supply;
}
int alliesSize = 1;
std::map<BWAPI::Force*, int> enemyForces;
for each(Player player in BWAPI::Broodwar->getPlayers())
{
if(player == BWAPI::Broodwar->self())
continue;
if(BWAPI::Broodwar->self()->isAlly(player))
++alliesSize;
if(BWAPI::Broodwar->self()->isEnemy(player))
++enemyForces[player->getForce()];
}
int maxEnemiesSize = 0;
for each(std::pair<BWAPI::Force*, int> force in enemyForces)
{
if(force.second > maxEnemiesSize)
maxEnemiesSize = force.second;
}
bool shouldAttackBase = !hasMiningBases;
if(mUnits.size() >= 3)
{
if(mySupply > 380)
shouldAttackBase = true;
else if(GameProgressDetection::Instance().getState() != StateType::TechHigh)
{
// If its a terran with siege tanks don't attack a base without leg speed and also ensure we are better matched as siege tanks can hurt
bool isTerranWithSiege = PlayerTracker::Instance().isEnemyRace(BWAPI::Races::Terran) && PlayerTracker::Instance().enemyHasReseached(BWAPI::TechTypes::Tank_Siege_Mode);
if(isTerranWithSiege && BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Leg_Enhancements) > 0 && mUnits.size() > 45 && mySupply > (enemyGuessSupply * 4))
shouldAttackBase = true;
else if(!isTerranWithSiege && mUnits.size() > 35 && mySupply > (enemyKnownSupply * 4))
shouldAttackBase = true;
else if(mArmyBehaviour <= ArmyBehaviour::Aggresive)
{
if(maxEnemiesSize <= alliesSize)
shouldAttackBase = true;
}
// Agains't weak opponents it can usually attack when these pass
// how ever against stronger opponents, or terran with siege tanks it will just lose a few units time and again then lose to a push
// easier to just sit back and turtle alittle
/*else if(mArmyBehaviour <= ArmyBehaviour::Default)
{
if(mySupply > (enemyGuessSupply * 4))
shouldAttackBase = true;
}
else if(mArmyBehaviour == ArmyBehaviour::Defensive)
{
if(mySupply > (enemyGuessSupply * 5))
shouldAttackBase = true;
}*/
}
}
if(shouldAttackBase)
{
Base bestBaseToAttack;
if(mLastGoal.getGoalType() == GoalType::Base && mLastGoal.getActionType() == ActionType::Attack && mLastGoal.getBase()->isEnemyBase())
bestBaseToAttack = mLastGoal.getBase();
for each(Base base in BaseTracker::Instance().getEnemyBases())
{
if(!bestBaseToAttack || base->getBuildings().size() < bestBaseToAttack->getBuildings().size())
bestBaseToAttack = base;
}
if(bestBaseToAttack)
squadsGoal = Goal(ActionType::Attack, bestBaseToAttack, engageGroup, avoidGroup);
}
}
if(squadsGoal.getGoalType() == GoalType::None && baseToDefend && mUnits.canMajorityAttack(baseToDefend->getEnemyThreats()))
squadsGoal = Goal(ActionType::Defend, baseToDefend->getCenterLocation(), engageGroup, avoidGroup);
if(squadsGoal.getGoalType() == GoalType::None)
{
if(!BorderTracker::Instance().getBorderPositions(PositionType::TechDefenseChokepoint).empty())
squadsGoal = Goal(ActionType::Hold, getLargestChoke(BorderTracker::Instance().getBorderPositions(PositionType::TechDefenseChokepoint)).mChoke->getCenter(), engageGroup, avoidGroup);
}
if(squadsGoal.getGoalType() == GoalType::None)
{
if(!BorderTracker::Instance().getBorderPositions(PositionType::DefenseChokepoint).empty())
squadsGoal = Goal(ActionType::Hold, getLargestChoke(BorderTracker::Instance().getBorderPositions(PositionType::DefenseChokepoint)).mChoke->getCenter(), engageGroup, avoidGroup);
}
if(squadsGoal.getGoalType() == GoalType::None)
squadsGoal = Goal(ActionType::Attack, Position(BWAPI::Broodwar->mapWidth()*24, BWAPI::Broodwar->mapHeight()*16), engageGroup, avoidGroup);
if(!mEngageFull && !avoidGroup.empty() && squadsGoal.getActionType() == ActionType::Attack && squadsGoal.getGoalType() == GoalType::Base)
squadsGoal = Goal(ActionType::Attack, avoidGroup.getCenter(), engageGroup, avoidGroup);
mLastGoal = squadsGoal;
if(squadsGoal.getGoalType() != GoalType::None)
{
for(std::map<Unit, Behaviour>::iterator it = mUnitBehaviours.begin(); it != mUnitBehaviours.end(); ++it)
it->second.update(squadsGoal, mUnits);
}
return hasEnded() && mUnits.empty();
}

| void DefaultSquadTask::updateRequirements | ( | ) | [virtual] |
Reimplemented from BaseSquadTask.
Definition at line 302 of file DefaultSquad.cpp.
References Task::addRequirement(), RequirementGroup::addUnitFilterRequirement(), RequirementGroup::addUnitRequirement(), BWAPI::Broodwar, Task::clearRequirements(), UnitGroup::count(), Task::hasEnded(), Singleton< T >::Instance(), BWAPI::UnitType::isAddon(), BWAPI::UnitType::isBuilding(), UnitFilterFlags::IsComplete, BWAPI::UnitType::isWorker(), Requirement::maxTime, mObserver, mUnits, BWAPI::UnitTypes::Protoss_Interceptor, BWAPI::UnitTypes::Protoss_Observer, BWAPI::UnitTypes::Protoss_Scarab, BWAPI::UnitTypes::Zerg_Egg, and BWAPI::UnitTypes::Zerg_Larva.
Referenced by preUpdate().
{
clearRequirements();
if(!hasEnded())
{
for each(Unit unit in UnitTracker::Instance().selectAllUnits())
{
if(!unit->isCompleted())
continue;
if(mUnits.count(unit) != 0)
continue;
const BWAPI::UnitType &type = unit->getType();
if(type.isBuilding())
continue;
if(type.isAddon())
continue;
if(type == BWAPI::Broodwar->self()->getRace().getSupplyProvider())
continue;
if(type == BWAPI::UnitTypes::Zerg_Egg)
continue;
if(type == BWAPI::UnitTypes::Protoss_Interceptor)
continue;
if(type == BWAPI::UnitTypes::Zerg_Larva)
continue;
if(type == BWAPI::UnitTypes::Protoss_Scarab)
continue;
if(type == BWAPI::UnitTypes::Protoss_Observer)
continue;
RequirementGroup req;
req.addUnitRequirement(unit, type.isWorker() ? 5 : 20, Requirement::maxTime);
addRequirement(req);
}
if(!mObserver)
{
RequirementGroup req;
req.addUnitFilterRequirement(20, Requirement::maxTime, UnitFilter(BWAPI::UnitTypes::Protoss_Observer) && UnitFilter(UnitFilterFlags::IsComplete));
addRequirement(req);
}
}
}

| bool DefaultSquadTask::waitingForUnit | ( | Unit | unit | ) | const [virtual] |
bool DefaultSquadTask::mEngageFull [private] |
Definition at line 44 of file DefaultSquad.h.
Referenced by update().
Goal DefaultSquadTask::mLastGoal [private] |
Definition at line 43 of file DefaultSquad.h.
Referenced by update().
Unit DefaultSquadTask::mObserver [private] |
Definition at line 41 of file DefaultSquad.h.
Referenced by giveUnit(), returnUnit(), and updateRequirements().
std::map<Unit, Behaviour> DefaultSquadTask::mUnitBehaviours [private] |
Definition at line 39 of file DefaultSquad.h.
Referenced by giveUnit(), returnUnit(), and update().
UnitGroup DefaultSquadTask::mUnits [private] |
Definition at line 38 of file DefaultSquad.h.
Referenced by controlSize(), getFinishedUnits(), giveUnit(), returnUnit(), update(), and updateRequirements().
1.7.6.1