BTHAI 2.3
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes
Commander Class Reference

#include <Commander.h>

List of all members.

Public Member Functions

 ~Commander ()
void computeActions ()
bool shallEngage ()
void updateGoals ()
void unitCreated (BaseAgent *agent)
void unitDestroyed (BaseAgent *agent)
bool needUnit (UnitType type)
SquadgetSquad (int id)
vector< Squad * > getSquads ()
TilePosition getClosestEnemyBuilding (TilePosition start)
int noOffensiveSquadsWithin (TilePosition center, int maxRange)
bool checkWorkersAttack (BaseAgent *base)
void assistBuilding (BaseAgent *building)
void assistWorker (BaseAgent *worker)
int enemyUnitsWithinRange (TilePosition start, int range)
void handleCloakedEnemy (TilePosition pos, Squad *squad)
void checkRemovableObstacles ()
void forceAttack ()
void printInfo ()
TilePosition findUnfortifiedChokePoint ()
TilePosition findChokePoint ()
bool isPowered (TilePosition pos)
bool isBuildable (TilePosition pos)
bool checkUnfinishedBuildings ()
bool checkRepairUnits ()
bool isImportantUnit (Unit *unit)
void repair (BaseAgent *agent)
void finishBuild (BaseAgent *agent)
void addBunkerSquad ()

Static Public Member Functions

static CommandergetInstance ()

Public Attributes

int ownDeadScore
int enemyDeadScore

Protected Member Functions

TilePosition findOffensiveSquadPosition (TilePosition closeEnemy)

Protected Attributes

vector< Squad * > squads
int currentID
int currentState

Static Protected Attributes

static Commanderinstance = NULL
static const int DEFEND = 0
static const int ATTACK = 1

Detailed Description

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)


Constructor & Destructor Documentation

Commander::~Commander ( )

Destructor.


Member Function Documentation

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.

TilePosition Commander::findChokePoint ( )

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.

TilePosition Commander::findUnfortifiedChokePoint ( )

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.

TilePosition Commander::getClosestEnemyBuilding ( TilePosition  start)

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).

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.


Member Data Documentation

The total killScore points of all enemy, destroyed units (not buildings).

The total killScore points of all own, destroyed units (not buildings).


The documentation for this class was generated from the following files:
 All Classes Functions Variables