BWAPI
|
#include <Commander.h>
The Commander class is the heart of deciding high level strategies like when and where to engage the enemy. It is responsible for deciding when to attack the enemy, where to attack him, and when a retreat is the best option to do. All units are grouped into Squads, and the Commander directs the different Squads to attack or defend positions. Each Squad are in turn responsible for handle the task it has been assigned.
The Commander is implemented as a singleton class. Each class that needs to access Commander can request an instance, and all classes shares the same Commander instance.
Author: Johan Hagelback (johan.hagelback@gmail.com)
Commander::Commander | ( | ) | [protected] |
Destructor.
void Commander::addBunkerSquad | ( | ) |
Adds a bunker squad when a Terran Bunker has been created.
void Commander::assistBuilding | ( | BaseAgent * | building | ) |
Tries to find a free squad to assist a building.
void Commander::assistWorker | ( | BaseAgent * | worker | ) |
Tries to find a free squad to assist a worker that is under attack.
void Commander::checkRemovableObstacles | ( | ) |
Checks if there are any removable obstacles nearby, i.e. minerals with less than 20 resources left.
bool Commander::checkRepairUnits | ( | ) |
Check if there are any important buildings or units to repair. Terran only.
bool Commander::checkUnfinishedBuildings | ( | ) |
Checks if there are any unfinished buildings that does not have an SCV working on them. Terran only.
bool Commander::checkWorkersAttack | ( | BaseAgent * | base | ) |
Checks if workers needs to attack. Happens if base is under attack and no offensive units are available.
void Commander::computeActions | ( | ) |
Called each update to issue orders.
int Commander::enemyUnitsWithinRange | ( | TilePosition | start, |
int | range | ||
) |
Counts the number of enemy units withing range from the start position.
Searches for and returns a good chokepoint position to defend the territory.
TilePosition Commander::findOffensiveSquadPosition | ( | TilePosition | closeEnemy | ) | [protected] |
Used to find where offensive attackin ground squads are, so air squads doesnt get ahead of other squads when attacking.
Searches for a chokepoint that is unfortified, i.e. does not contain for example a Bunker or defensive turret. Returns TilePosition(-1, -1) if no position was found.
void Commander::finishBuild | ( | BaseAgent * | agent | ) |
Assigns a worker to finish constructing an interrupted building. Terran only.
void Commander::forceAttack | ( | ) |
Forces an attack, even if some squads are not full.
Returns the position of the closest enemy building from the start position, or TilePosition(-1,-1) if not found.
Commander * Commander::getInstance | ( | ) | [static] |
Returns the instance of the class.
Squad * Commander::getSquad | ( | int | id | ) |
Returns the Squad with the specified id, or NULL if not found.
vector< Squad * > Commander::getSquads | ( | ) |
Returns all Squads.
void Commander::handleCloakedEnemy | ( | TilePosition | pos, |
Squad * | squad | ||
) |
Called when own units are attacked by a cloaked enemy unit.
bool Commander::isBuildable | ( | TilePosition | pos | ) |
Checks is a position is buildable.
bool Commander::isImportantUnit | ( | Unit * | unit | ) |
Returns true if the unit is important to assist, false if not. All buildings and large expensive units such as siege tanks and battlecruisers are considered important, while small units such as marines and vultures are not considered important. Terran only.
bool Commander::isPowered | ( | TilePosition | pos | ) |
Checks if a position is covered by psi (Protoss only).
bool Commander::needUnit | ( | UnitType | type | ) |
int Commander::noOffensiveSquadsWithin | ( | TilePosition | center, |
int | maxRange | ||
) |
Returns the number of active offensive squads within maxRange of the center position.
void Commander::printInfo | ( | ) |
Shows some info on the screen.
void Commander::repair | ( | BaseAgent * | agent | ) |
Assigns a worker to repair the specified agent. Terran only.
bool Commander::shallEngage | ( | ) |
Checks if it is time to engage the enemy. This happens when all Required squads are active.
void Commander::unitCreated | ( | BaseAgent * | agent | ) |
Called each time a unit is created. The unit is then placed in a Squad.
void Commander::unitDestroyed | ( | BaseAgent * | agent | ) |
Called each time a unit is destroyed. The unit is then removed from its Squad.
void Commander::updateGoals | ( | ) |
const int Commander::ATTACK = 1 [static, protected] |
int Commander::currentID [protected] |
int Commander::currentState [protected] |
const int Commander::DEFEND = 0 [static, protected] |
The total killScore points of all enemy, destroyed units (not buildings).
Commander * Commander::instance = NULL [static, protected] |
The total killScore points of all own, destroyed units (not buildings).
vector<Squad*> Commander::squads [protected] |