BWAPI::Bullet class

An interface object representing a bullet or missile spawned from an attack.

Contents

The Bullet interface allows you to detect bullets, missiles, and other types of non-melee attacks or special abilities that would normally be visible through human eyes (A lurker spike or a Queen's flying parasite), allowing quicker reaction to unavoidable consequences.

For example, ordering medics to restore units that are about to receive a lockdown to compensate for latency and minimize its effects. You can't know entirely which unit will be receiving a lockdown unless you can detect the lockdown missile using the Bullet class.

Bullet objects are re-used after they are destroyed, however their ID is updated when it represents a new Bullet.

If Flag::CompleteMapInformation is disabled, then a Bullet is accessible if and only if it is visible. Otherwise if Flag::CompleteMapInformation is enabled, then all Bullets in the game are accessible.

Base classes

template<typename Interface, typename Data>
struct InterfaceDataWrapper<Bullet, BulletData>

Public functions

auto exists() const -> bool
Checks if the Bullet exists in the view of the BWAPI player.
auto getAngle() const -> double
Retrieve's the direction the Bullet is facing.
auto getPlayer() const -> Player
Retrieves the Player interface that owns the Bullet.
auto getPosition() const -> Position
Retrieves the Bullet's current position.
auto getRemoveTimer() const -> int
Retrieves the timer that indicates the Bullet's life span.
auto getSource() const -> Unit
Retrieves the Unit interface that the Bullet spawned from.
auto getTarget() const -> Unit
Retrieves the Unit interface that the Bullet is heading to.
auto getTargetPosition() const -> Position
Retrieves the target position that the Bullet is heading to.
auto getType() const -> BulletType
Retrieves the type of this Bullet.
auto getVelocityX() const -> double
Retrieves the X component of the Bullet's velocity, measured in pixels per frame.
auto getVelocityY() const -> double
Retrieves the Y component of the Bullet's velocity, measured in pixels per frame.
auto isVisible(Player player = nullptr) const -> bool
Retrieves the visibility state of the Bullet.

Function documentation

bool BWAPI::Bullet::exists() const

Checks if the Bullet exists in the view of the BWAPI player.

Returns
true If the bullet exists or is visible.
false If the bullet was destroyed or has gone out of scope.

If Flag::CompleteMapInformation is disabled, and a Bullet is not visible, then the return value will be false regardless of the Bullet's true existence. This is because absolutely no state information on invisible enemy bullets is made available to the AI.

If Flag::CompleteMapInformation is enabled, then this function is accurate for all Bullet information.

double BWAPI::Bullet::getAngle() const

Retrieve's the direction the Bullet is facing.

Returns A double representing the direction the Bullet is facing.
0.0 If the bullet is inaccessible.

If the angle is 0, then the Bullet is facing right.

Player BWAPI::Bullet::getPlayer() const

Retrieves the Player interface that owns the Bullet.

Returns The owning Player interface object.
nullptr If the Player object for this Bullet is inaccessible.

Position BWAPI::Bullet::getPosition() const

Retrieves the Bullet's current position.

Returns A Position containing the Bullet's current coordinates.
None If the Bullet is inaccessible.

int BWAPI::Bullet::getRemoveTimer() const

Retrieves the timer that indicates the Bullet's life span.

Returns An integer representing the remaining number of frames until the Bullet self-destructs.
0 If the Bullet is inaccessible.

Bullets are not permanent objects, so they will often have a limited life span. This life span is measured in frames. Normally a Bullet will reach its target before being removed.

Unit BWAPI::Bullet::getSource() const

Retrieves the Unit interface that the Bullet spawned from.

Returns The owning Unit interface object.
nullptr If the source can not be identified or is inaccessible.

Unit BWAPI::Bullet::getTarget() const

Retrieves the Unit interface that the Bullet is heading to.

Returns The target Unit interface object, if one exists.
nullptr If the Bullet's target Unit is inaccessible, the Bullet is targetting the ground, or if the Bullet itself is inaccessible.

Position BWAPI::Bullet::getTargetPosition() const

Retrieves the target position that the Bullet is heading to.

Returns A Position indicating where the Bullet is headed.
None If the bullet is inaccessible.

BulletType BWAPI::Bullet::getType() const

Retrieves the type of this Bullet.

Returns A BulletType representing the Bullet's type.
None if the Bullet is inaccessible.

double BWAPI::Bullet::getVelocityX() const

Retrieves the X component of the Bullet's velocity, measured in pixels per frame.

Returns A double representing the number of pixels moved on the X axis per frame.
0.0 if the Bullet is inaccessible.

double BWAPI::Bullet::getVelocityY() const

Retrieves the Y component of the Bullet's velocity, measured in pixels per frame.

Returns A double representing the number of pixels moved on the Y axis per frame.
0.0 if the Bullet is inaccessible.

bool BWAPI::Bullet::isVisible(Player player = nullptr) const

Retrieves the visibility state of the Bullet.

Parameters
player (optional) If this parameter is specified, then the Bullet's visibility to the given player is checked. If this parameter is omitted, then a default value of nullptr is used, which will check if the BWAPI player has vision of the Bullet.
Returns
true If the Bullet is visible to the specified player.
false If the Bullet is not visible to the specified player.