SC2API
An API for AI for StarCraft II
sc2_unit.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "sc2_proto_interface.h"
7 #include "sc2_gametypes.h"
8 #include "sc2_common.h"
9 #include "sc2_typeenums.h"
10 #include <vector>
11 #include <unordered_map>
12 #include <string>
13 #include <stdint.h>
14 
15 namespace sc2 {
16 
17 class ObservationInterface;
18 
20 struct UnitOrder {
28  float progress;
29 
30  UnitOrder() :
31  ability_id(0),
32  target_unit_tag(NullTag),
33  progress(0.0f) {
34  }
35 };
36 
38 struct PassengerUnit {
40  Tag tag;
42  float health;
44  float health_max;
46  float shield;
48  float energy;
51 
52  PassengerUnit() :
53  tag(NullTag),
54  health(0.0f),
55  health_max(0.0f),
56  shield(0.0f),
57  energy(0.0f),
58  unit_type(0) {
59  }
60 };
61 
63 class Unit {
64 public:
66  enum DisplayType {
68  Visible = 1,
71  Snapshot = 2,
73  Hidden = 3,
74  };
75 
77  enum Alliance {
79  Self = 1,
81  Ally = 2,
83  Neutral = 3,
85  Enemy = 4
86  };
87 
89  enum CloakState {
91  Cloaked = 1,
93  CloakedDetected = 2,
95  NotCloaked = 3,
97  Unknown = 4
98  };
99 
104 
106  Tag tag;
110  int owner;
111 
115  float facing;
117  float radius;
120 
123 
127  float radar_range;
128 
134  bool is_blip;
135 
136  // Not populated for snapshots
137 
139  float health;
141  float health_max;
143  float shield;
145  float energy;
151  bool is_flying;
156 
157  // Not populated for enemies/snapshots
158 
160  std::vector<UnitOrder> orders;
164  std::vector<PassengerUnit> passengers;
176  std::vector<BuffID> buffs;
179 
180  Unit();
181 
182  operator Tag() const { return tag; }
183 };
184 
185 typedef std::vector<Unit> Units;
186 typedef std::unordered_map<Tag, size_t> UnitIdxMap;
187 
189 struct IsUnit {
190  IsUnit(UNIT_TYPEID type) : type_(type) {};
191  UNIT_TYPEID type_;
192  bool operator()(const Unit& unit) { return unit.unit_type == type_; };
193 };
194 
196 struct IsUnits {
197  IsUnits(std::vector<UNIT_TYPEID> types) : types_(types) {};
198  std::vector<UNIT_TYPEID> types_;
199  bool operator()(const Unit& unit) {
200  bool included = false;
201  for (const auto& type : types_) {
202  included = included || (unit.unit_type == type);
203  }
204  return included;
205  };
206 };
207 
208 }
bool is_on_screen
Visible and within the camera frustum.
Definition: sc2_unit.h:132
Tag tag
The tag of the unit in the transport.
Definition: sc2_unit.h:40
float health
The health of the unit in the transport.
Definition: sc2_unit.h:42
CloakState
Unit cloak state.
Definition: sc2_unit.h:89
Common data types, including points, rectangles and colors.
A unit. Could be a structure, a worker or a military unit.
Definition: sc2_unit.h:63
Alliance
Relationship to this player.
Definition: sc2_unit.h:77
std::vector< UnitOrder > orders
Orders on a unit. Only valid for this player&#39;s units.
Definition: sc2_unit.h:160
Definition: sc2_common.h:14
int owner
Which player owns a unit.
Definition: sc2_unit.h:110
bool is_blip
Detected by sensor tower.
Definition: sc2_unit.h:134
Definition: sc2_common.h:49
float radius
Radius of the unit.
Definition: sc2_unit.h:117
Determines if the unit matches the unit type.
Definition: sc2_unit.h:189
Definition: sc2_action.h:9
UnitTypeID unit_type
An identifier of the type of unit.
Definition: sc2_unit.h:108
std::vector< PassengerUnit > passengers
Passengers in this transport. Only valid for this player&#39;s units.
Definition: sc2_unit.h:164
CloakState cloak
If the unit is cloaked.
Definition: sc2_unit.h:122
A list of enums provided for your convenience.
float shield
The shield of the unit in the transport.
Definition: sc2_unit.h:46
float health
Health of the unit. Not set for snapshots.
Definition: sc2_unit.h:139
float radar_range
Range of radar for units that are radar units.
Definition: sc2_unit.h:127
UnitTypeID unit_type
The type of unit in the transport.
Definition: sc2_unit.h:50
float facing
Direction the unit faces in radians (1 radian == 57.296 degrees)
Definition: sc2_unit.h:115
A passenger on a transport.
Definition: sc2_unit.h:38
float progress
Progress of the order.
Definition: sc2_unit.h:28
int ideal_harvesters
Number of harvesters that can be assigned to a town hall (e.g., Command Center). Only valid for this ...
Definition: sc2_unit.h:172
int cargo_space_taken
Number of cargo slots used in the transport. Only valid for this player&#39;s units.
Definition: sc2_unit.h:166
Tag target_unit_tag
Target unit of the order, if there is one.
Definition: sc2_unit.h:24
Determines if units matches the unit type.
Definition: sc2_unit.h:196
float energy
The energy of the unit in the transport.
Definition: sc2_unit.h:48
Point3D pos
Position of the unit in the world.
Definition: sc2_unit.h:113
float build_progress
Gives progress under construction. Range: [0.0, 1.0]. 1.0 == finished.
Definition: sc2_unit.h:119
Tag add_on_tag
Add-on like a tech lab or reactor. Only valid for this player&#39;s units.
Definition: sc2_unit.h:162
float weapon_cooldown
Time remaining for a weapon on cooldown. Not set for snapshots.
Definition: sc2_unit.h:155
Types used in setting up a game.
float energy
Energy of the unit. Not set for snapshots.
Definition: sc2_unit.h:145
AbilityID ability_id
Ability ID that triggered the order.
Definition: sc2_unit.h:22
Point2D target_pos
Target position of the order, if there is one.
Definition: sc2_unit.h:26
An order that is active on a unit.
Definition: sc2_unit.h:20
Alliance alliance
Relationship of the unit to this player.
Definition: sc2_unit.h:103
int mineral_contents
Amount of minerals if the unit is a mineral field. Not set for snapshots.
Definition: sc2_unit.h:147
std::vector< BuffID > buffs
Buffs on this unit. Only valid for this player&#39;s units.
Definition: sc2_unit.h:176
float shield
Shield of the unit. Not set for snapshots.
Definition: sc2_unit.h:143
int vespene_contents
Amount of vespene if the unit is a geyser. Not set for snapshots.
Definition: sc2_unit.h:149
float health_max
The max possible health of the unit in the transport.
Definition: sc2_unit.h:44
float health_max
Max health for the unit. Not set for snapshots.
Definition: sc2_unit.h:141
bool is_burrowed
If the unit is burrowed. Not set for snapshots.
Definition: sc2_unit.h:153
Tag engaged_target_tag
Target unit of a unit. Only valid for this player&#39;s units.
Definition: sc2_unit.h:174
bool is_flying
If the unit is flying. Not set for snapshots.
Definition: sc2_unit.h:151
int assigned_harvesters
Number of harvesters associated with a town hall (e.g., Command Center). Only valid for this player&#39;s...
Definition: sc2_unit.h:170
float detect_range
Range of detector for detector units.
Definition: sc2_unit.h:125
bool is_powered
Whether the unit is powered by a pylon.
Definition: sc2_unit.h:178
int cargo_space_max
Number of cargo slots available for a transport. Only valid for this player&#39;s units.
Definition: sc2_unit.h:168
Tag tag
A unique identifier for the instance of a unit.
Definition: sc2_unit.h:106
bool is_selected
If the unit is in the current selection of the player.
Definition: sc2_unit.h:130
DisplayType display_type
If the unit is shown on screen or not.
Definition: sc2_unit.h:101
DisplayType
If the unit is shown on screen or not.
Definition: sc2_unit.h:66