BWAPI::AIModule class

AIModule is a virtual class that is intended to be implemented or inherited by a custom AI class.

The Broodwar interface is guaranteed to be initialized if any of these predefined interface functions are invoked by BWAPI.

Constructors, destructors, conversion operators

AIModule()

Public functions

void onEnd(bool isWinner) virtual
Called once at the end of a game.
void onFrame() virtual
Called once for every execution of a logical frame in Broodwar.
void onNukeDetect(Position target) virtual
Called when a Nuke has been launched somewhere on the map.
void onPlayerLeft(Player player) virtual
Called when a Player leaves the game.
void onReceiveText(Player player, std::string text) virtual
Called when the client receives a message from another Player.
void onSaveGame(std::string gameName) virtual
Called when the state of the Broodwar game is saved to file.
void onSendText(std::string text) virtual
Called when the user attempts to send a text message.
void onStart() virtual
Called only once at the beginning of a game.
void onUnitComplete(Unit unit) virtual
Called when the state of a unit changes from incomplete to complete.
void onUnitCreate(Unit unit) virtual
Called when any unit is created.
void onUnitDestroy(Unit unit) virtual
Called when a unit is removed from the game either through death or other means.
void onUnitDiscover(class Unit unit) virtual
Called when a Unit becomes accessible.
void onUnitEvade(Unit unit) virtual
Called when a Unit becomes inaccessible.
void onUnitHide(Unit unit) virtual
Called just as a visible unit is becoming invisible.
void onUnitMorph(Unit unit) virtual
Called when a unit changes its UnitType.
void onUnitRenegade(Unit unit) virtual
Called when a unit changes ownership.
void onUnitShow(Unit unit) virtual
Called when a previously invisible unit becomes visible.

Function documentation

void BWAPI::AIModule::onEnd(bool isWinner) virtual

Called once at the end of a game.

Parameters
isWinner A boolean value to determine if the current player has won the match. This value will be true if the current player has won, and false if either the player has lost or the game is actually a replay.

void BWAPI::AIModule::onFrame() virtual

Called once for every execution of a logical frame in Broodwar.

Users will generally put most of their code in this function.

void BWAPI::AIModule::onNukeDetect(Position target) virtual

Called when a Nuke has been launched somewhere on the map.

Parameters
target A Position object containing the target location of the Nuke. If the target location is not visible and Flag::CompleteMapInformation is disabled, then target will be Positions::Unknown.

void BWAPI::AIModule::onPlayerLeft(Player player) virtual

Called when a Player leaves the game.

Parameters
player The Player interface object representing the player that left the game.

All of their units are automatically given to the neutral player with their colour and alliance parameters preserved.

void BWAPI::AIModule::onReceiveText(Player player, std::string text) virtual

Called when the client receives a message from another Player.

Parameters
player The Player interface object representing the owner of the text message.
text The text message that the player sent.

This function can be used to retrieve information from allies in team games, or just to respond to other players.

void BWAPI::AIModule::onSaveGame(std::string gameName) virtual

Called when the state of the Broodwar game is saved to file.

Parameters
gameName A String object containing the file name that the game was saved as.

void BWAPI::AIModule::onSendText(std::string text) virtual

Called when the user attempts to send a text message.

Parameters
text A string containing the exact text message that was sent by the user.

This function can be used to make the bot execute text commands entered by the user for debugging purposes.

void BWAPI::AIModule::onStart() virtual

Called only once at the beginning of a game.

It is intended that the AI module do any data initialization in this function.

void BWAPI::AIModule::onUnitComplete(Unit unit) virtual

Called when the state of a unit changes from incomplete to complete.

Parameters
unit The Unit object representing the Unit that has just finished training or constructing.

void BWAPI::AIModule::onUnitCreate(Unit unit) virtual

Called when any unit is created.

Parameters
unit The Unit interface object representing the unit that has just been created.

void BWAPI::AIModule::onUnitDestroy(Unit unit) virtual

Called when a unit is removed from the game either through death or other means.

Parameters
unit Unit object representing the unit that has just been destroyed or otherwise completely removed from the game.

void BWAPI::AIModule::onUnitDiscover(class Unit unit) virtual

Called when a Unit becomes accessible.

Parameters
unit The Unit interface object representing the unit that has just become accessible.

void BWAPI::AIModule::onUnitEvade(Unit unit) virtual

Called when a Unit becomes inaccessible.

Parameters
unit The Unit interface object representing the unit that has just become inaccessible.

void BWAPI::AIModule::onUnitHide(Unit unit) virtual

Called just as a visible unit is becoming invisible.

Parameters
unit The Unit interface object representing the unit that is about to go out of scope.

void BWAPI::AIModule::onUnitMorph(Unit unit) virtual

Called when a unit changes its UnitType.

Parameters
unit Unit object representing the unit that had its UnitType change.

For example, when a Drone transforms into a Hatchery, a Siege Tank uses Siege Mode, or a Vespene Geyser receives a Refinery.

void BWAPI::AIModule::onUnitRenegade(Unit unit) virtual

Called when a unit changes ownership.

Parameters
unit Unit interface object pertaining to the unit that has just changed ownership.

This occurs when the Protoss ability Mind Control is used, or if a unit changes ownership in Use Map Settings .

void BWAPI::AIModule::onUnitShow(Unit unit) virtual

Called when a previously invisible unit becomes visible.

Parameters
unit The Unit interface object representing the unit that has just become visible.