Race

class BWAPI.Race

The Race object is used to get information about a particular race.

For example, the default worker and supply provider UnitType.

As you should already know, Starcraft has three races: Terran , Protoss , and Zerg .

Constructors

Race([id = Races.Enum.None])

Expected type constructor.

If the type is an invalid type, then it becomes Unknown. A type is invalid if its value is less than 0 or greater than Unknown.

Parameters:id (int) – The id that corresponds to this type. It is typically an integer value that corresponds to an internal Broodwar type. If the given id is invalid, then it becomes Unknown.

Member Functions

getID() → int

Retrieves this type’s identifier as an integer.

Returns:An integer representation of this type.
Return type:int
isValid() → boolean

Checks if the current type has a valid identifier. The purpose of this function is to prevent buffer overflows if a type has been handled improperly.

A type is valid if it is between 0 and Unknown (inclusive).

Returns:true if this type is valid and false otherwise.
Return type:boolean
getName() → string
Returns:The variable name of the type.
Return type:string
getResourceDepot() → UnitType

Retrieves the default resource depot UnitType that workers of this Race can construct and return resources to.

Returns:UnitType of the center that this race uses.
Return type:BWAPI.UnitType

Note

In Starcraft, the center is the very first structure of the Race‘s technology tree. Also known as its base of operations or resource depot.

getCenter() → UnitType

Deprecated since version BWAPI: 4.2.0 Use getResourceDepot() instead.

getRefinery() → UnitType

Retrieves the default structure UnitType for this Race that is used to harvest gas from Vespene Geysers.

Returns:UnitType of the structure used to harvest gas.
Return type:BWAPI.UnitType

Note

In Starcraft, you must first construct a structure over a Vespene Geyser in order to begin harvesting Vespene Gas.

getSupplyProvider() → UnitType

Retrieves the default supply provider UnitType for this race that is used to construct units.

Returns:UnitType that provides the player with supply.
Return type:BWAPI.UnitType

Note

In Starcraft, training, morphing, or warping in units requires that the player has sufficient supply available for their Race.

getTransport() → UnitType

Retrieves the default transport UnitType for this race that is used to transport ground units across the map.

Returns:UnitType for transportation.
Return type:BWAPI.UnitType

Note

In Starcraft, transports will allow you to carry ground units over unpassable terrain.

getWorker() → UnitType

Retrieves the default worker type for this Race.

Returns:UnitType of the worker that this race uses.
Return type:BWAPI.UnitType

Note

In Starcraft, workers are the units that are used to construct structures.

Raceset

class BWAPI.Raceset

A container for a set of Race objects.

Constructors

Raceset()

Default constructor.

Raceset(set)

Copy constructor.

Parameters:set (BWAPI.Raceset) – The Raceset to copy.
Raceset(tbl)

Constructor to convert a Lua table to a set. Any values in the table that are of type Race are added to the set.

Parameters:tbl (table) – A table containing Race objects.

Member Functions

iterator() → iteratorFunction

Returns an iterator function intended to be used in for loops (e.g. for item in set:iterator() do).

Returns:An iterator function that will return the next value in the set with each successive call.
Return type:function
asTable() → table

Returns the values of the set as an array-like Lua table.

Note

The ordering of the returned table is arbitrary (due to sets being unordered in the C++ implementation).

Returns:An array-like Lua table containing each value in the set.
Return type:table
count(val) → int

Searches the set for elements with a value of val and returns the number of elements found. Because sets do not allow for duplicate values, this means that the function will return either 1 or 0. Because of this, it’s recommended to use contains() instead.

contains(val) → boolean

Checks if this set contains a specific value.

Returns:true if the set contains the specified value, or false otherwise.
Return type:boolean
size() → int
Returns:The number of values in the set.
Return type:int

Note

set:size() is exactly equivalent to #set

empty() → boolean
Returns:true if the set is empty (size() == 0), or false otherwise.
Return type:boolean
insert(val)

Inserts the value into the set.

Note

Sets cannot contain duplicate values. If the value already exists in the set, the set will not be modified.

erase(val) → numElementsErased

Removes val from the set if it exists.

Returns:The number of elements removed. Because sets do not allow for duplicate values, this means that the function will return either 1 or 0.
Return type:int
clear()

Removes all elements from the set, leaving it with a size of 0.

eraseIf(pred)

Iterates the set and erases each element x where pred(x) returns true. The set is modified in place.

Parameters:pred (function) – A predicate function that takes a value and returns true for values that should be erased and false otherwise.
erase_if(pred)

Alias of eraseIf()

filter(pred)

Iterates the set and erases each element x where pred(x) returns false. The set is modified in place.

Parameters:pred (function) – A predicate function that takes a value and returns true for values that should be kept and false for elements that should be erased.
keepIf(pred)

Alias of filter()/keep_if()

keep_if(pred)

Alias of filter()/keepIf()