BWAPI  4.1.2
An API for interacting with Starcraft: Broodwar (1.16.1)
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules
Public Member Functions | List of all members
BWAPI::PositionOrUnit Class Reference

Public Member Functions

 PositionOrUnit (Unit unit=nullptr)
 
 PositionOrUnit (Position pos)
 
Position getPosition () const
 
Unit getUnit () const
 
bool isPosition () const
 
bool isUnit () const
 
PositionOrUnitoperator= (Unit pUnit)
 
PositionOrUnitoperator= (Position pos)
 

Detailed Description

PositionOrUnit is a class that is either a Position or a Unit.

The purpose of this class is to reduce interface overhead by combining two commonly passed values into one, and to allow more function overloads with less effort.

Constructor & Destructor Documentation

BWAPI::PositionOrUnit::PositionOrUnit ( Unit  unit = nullptr)

Unit constructor.

Assigns this class to contain a unit.

Parameters
unitThe unit to assign to this class.
BWAPI::PositionOrUnit::PositionOrUnit ( Position  pos)

Position constructor.

Assigns this class to contain a position.

Parameters
posThe position to assign to this class.

Member Function Documentation

PositionOrUnit& BWAPI::PositionOrUnit::operator= ( Unit  pUnit)

Unit assignment operator. Assigns a unit to this class.

PositionOrUnit& BWAPI::PositionOrUnit::operator= ( Position  pos)

Position assignment operator. Assigns a position to this class.

bool BWAPI::PositionOrUnit::isUnit ( ) const

Indicates if a Unit is currently held in this class.

Returns
true if the value contained within this class is considered a unit, and false if it is a position.
Unit BWAPI::PositionOrUnit::getUnit ( ) const

Retrieves the Unit attached to this class, if there is one.

Returns
The Unit that was assigned to this class.
Return values
nullptrIf this class does not contain a unit, or if nullptr was assigned to this class as a Unit.
bool BWAPI::PositionOrUnit::isPosition ( ) const

Indicates if a Position is currently held in this class.

Returns
true if the value contained within this class is considered a position, and false if it is a unit.
Position BWAPI::PositionOrUnit::getPosition ( ) const

Retrieves the position if it was assigned to this class, otherwise it will retrieve the position of the unit contained within this class if there is one.

Returns
Position that was stored if there is one. If not, then the position of the unit will be used instead.
Return values
Positions::Noneif a nullptr Unit was assigned to this class.