SC2API
An API for AI for StarCraft II
sc2_data.h
1 #pragma once
2 
3 #include "sc2_proto_interface.h"
4 #include "sc2_gametypes.h"
5 #include "sc2_typeenums.h"
6 #include <vector>
7 #include <string>
8 #include <stdint.h>
9 
10 namespace sc2 {
11 
12 class ObservationInterface;
13 
14 typedef MessageResponsePtr<SC2APIProtocol::ResponseData> ResponseDataPtr;
15 
18  AvailableAbility() = default;
20  ability_id(ability_id),
21  requires_point(requires_point) {};
22 
24  AbilityID ability_id = 0;
26  bool requires_point = false;
27 };
28 
30 struct AbilityData {
32  enum class Target {
34  None = 1,
36  Point = 2,
38  Unit = 3,
40  PointOrUnit = 4,
42  PointOrNone = 5
43  };
44 
46  bool available;
50  std::string link_name;
52  uint32_t link_index;
54  std::string button_name;
56  std::string friendly_name;
58  std::string hotkey;
62  std::vector<uint32_t> remaps_from_ability_id;
76  float cast_range;
77 
79  AbilityData();
80 
83  void ReadFromProto(const SC2APIProtocol::AbilityData& ability_data);
85  std::string Log() const;
86 };
87 
88 typedef std::vector<AbilityData> Abilities;
89 
93  std::vector<AvailableAbility> abilities;
95  Tag unit_tag;
98 
101  bool IsValid() const {
102  return unit_tag && unit_type_id;
103  }
104 };
105 
107 enum class Attribute {
108  Light = 1,
109  Armored = 2,
110  Biological = 3,
111  Mechanical = 4,
112  Robotic = 5,
113  Psionic = 6,
114  Massive = 7,
115  Structure = 8,
116  Hover = 9,
117  Heroic = 10,
118  Summoned = 11,
119  Invalid = 12
120 };
121 
123 struct DamageBonus {
124  Attribute attribute;
125  float bonus;
126 
127  DamageBonus();
128 
129  void ReadFromProto(const SC2APIProtocol::DamageBonus& damage_bonus);
130 };
131 
133 struct Weapon {
134  enum class TargetType {
135  Ground = 1,
136  Air = 2,
137  Any = 3,
138  Invalid = 4
139  };
140  TargetType type;
141  float damage_;
142  std::vector<DamageBonus> damage_bonus; // Extra damage when attacking a unit of a certain attribute
143  uint32_t attacks; // Number of hits per attack. (eg. Colossus has 2 beams)
144  float range;
145  float speed; // Time between attacks
146 
147  Weapon();
148 
149  void ReadFromProto(const SC2APIProtocol::Weapon& weapon);
150 };
151 
153 struct UnitTypeData {
157  std::string name;
159  bool available;
161  uint32_t cargo_size;
166 
168  std::vector<Attribute> attributes;
172  float armor;
174  std::vector<Weapon> weapons;
182  Race race;
184  float build_time;
190  float sight_range;
191 
193  std::vector<UnitTypeID> tech_alias;
200 
202  UnitTypeData();
203 
206  void ReadFromProto(const SC2APIProtocol::UnitTypeData& unit_data);
208  std::string Log() const;
209 };
210 
211 typedef std::vector<UnitTypeData> UnitTypes;
212 
214 struct UpgradeData {
216  uint32_t upgrade_id;
218  std::string name;
220  uint32_t mineral_cost;
222  uint32_t vespene_cost;
227 
228  UpgradeData();
229 
230  void ReadFromProto(const SC2APIProtocol::UpgradeData& upgrade_data);
231  std::string Log() const;
232 };
233 
234 typedef std::vector<UpgradeData> Upgrades;
235 
237 struct BuffData {
239  uint32_t buff_id;
241  std::string name;
242 
243  BuffData();
244 
245  void ReadFromProto(const SC2APIProtocol::BuffData& buff_data);
246  std::string Log() const;
247 };
248 
249 typedef std::vector<BuffData> Buffs;
250 
252 struct EffectData {
254  uint32_t effect_id;
256  std::string name;
258  std::string friendly_name;
260  float radius;
261 
262  void ReadFromProto(const SC2APIProtocol::EffectData& effect_data);
263  std::string Log() const;
264 };
265 
266 typedef std::vector<EffectData> Effects;
267 
269 struct PowerSource {
270  PowerSource(const Point2D in_position, float in_radius, Tag in_tag) :
271  position(in_position),
272  radius(in_radius),
273  tag(in_tag) {};
274 
278  float radius;
280  Tag tag;
281 };
282 
284 struct Effect {
286  uint32_t effect_id;
289  std::vector<Point2D> positions;
290 
291  void ReadFromProto(const SC2APIProtocol::Effect& effect);
292 };
293 
294 AbilityID GetGeneralizedAbilityID(uint32_t ability_id, const ObservationInterface& observation);
295 
296 }
float research_time
Time in GameLoops to research this upgrade.
Definition: sc2_data.h:226
uint32_t effect_id
Stable ID. This ID will not change between patches.
Definition: sc2_data.h:254
bool available
If true, the ability is available to the current mods/map.
Definition: sc2_data.h:46
uint32_t upgrade_id
Stable ID. This ID will not change between patches.
Definition: sc2_data.h:216
Damage bonus of unit.
Definition: sc2_data.h:123
Tag tag
Unit tag of the power source.
Definition: sc2_data.h:280
UnitTypeID unit_type_id
Stable ID. This ID will not change between patches.
Definition: sc2_data.h:155
std::string friendly_name
In case the button name is not descriptive.
Definition: sc2_data.h:56
The visuals of a persistent ability on the map. (eg. Psistorm)
Definition: sc2_data.h:284
AbilityID ability_id
Ability that researches this upgrade.
Definition: sc2_data.h:224
Target target
Determines if a point, unit, both or none is required as a target.
Definition: sc2_data.h:64
A unit. Could be a structure, a worker or a military unit.
Definition: sc2_unit.h:69
AbilityID ability_id
Ability that is available.
Definition: sc2_data.h:24
bool allow_autocast
Autocast can be set.
Definition: sc2_data.h:68
uint32_t link_index
Catalog (game data xml) index of the ability.
Definition: sc2_data.h:52
float food_provided
How much food the unit provides.
Definition: sc2_data.h:178
float sight_range
Range the unit reveals vision.
Definition: sc2_data.h:190
Definition: sc2_common.h:49
float radius
Power source radius.
Definition: sc2_data.h:278
UnitTypeID tech_requirement
Structure required to build this unit. (Or any with the same tech_alias)
Definition: sc2_data.h:197
UnitTypeID unit_type_id
The unit type.
Definition: sc2_data.h:97
Definition: sc2_action.h:9
bool is_building
Requires placement to construct a building.
Definition: sc2_data.h:70
uint32_t effect_id
Type of the effect.
Definition: sc2_data.h:286
Target
Type of target this ability applies to.
Definition: sc2_data.h:32
std::string friendly_name
A more recognizable name of the effect.
Definition: sc2_data.h:258
Race race
The race the unit belongs to.
Definition: sc2_data.h:182
bool is_instant_placement
Placement next to an existing structure, e.g., an add-on like a Tech Lab.
Definition: sc2_data.h:74
std::string name
Effect name, corresponds to the game&#39;s catalog.
Definition: sc2_data.h:256
A list of enums provided for your convenience.
bool require_attached
Whether tech_requirement is an add-on.
Definition: sc2_data.h:199
std::vector< AvailableAbility > abilities
The available abilities.
Definition: sc2_data.h:93
float footprint_radius
If the ability is placing a building, give the radius of the footprint.
Definition: sc2_data.h:72
bool has_vespene
Whether the unit can have vespene (vespene geysers).
Definition: sc2_data.h:188
uint32_t buff_id
Stable ID. This ID will not change between patches.
Definition: sc2_data.h:239
std::vector< UnitTypeID > tech_alias
Units this is equivalent to in terms of satisfying tech requirements.
Definition: sc2_data.h:193
All available abilities for a unit.
Definition: sc2_data.h:91
std::string button_name
Name of the button for the command card.
Definition: sc2_data.h:54
bool IsValid() const
Definition: sc2_data.h:101
float armor
Armor of unit type.
Definition: sc2_data.h:172
std::vector< uint32_t > remaps_from_ability_id
Other abilities remapped to this generic ability.
Definition: sc2_data.h:62
AbilityID ability_id
Stable ID. For a given ability, this value will be immutable throughout different patches...
Definition: sc2_data.h:48
Buff data.
Definition: sc2_data.h:237
std::string link_name
Catalog (game data xml) name of the ability.
Definition: sc2_data.h:50
float movement_speed
Movement speed of unit type.
Definition: sc2_data.h:170
bool has_minerals
Whether the unit can have minerals (mineral patches).
Definition: sc2_data.h:186
std::vector< Weapon > weapons
Weapons on this unit type.
Definition: sc2_data.h:174
std::vector< Point2D > positions
Definition: sc2_data.h:289
int vespene_cost
Cost in vespene to build this unit type.
Definition: sc2_data.h:165
std::vector< Attribute > attributes
Unit attributes, may change based on upgrades.
Definition: sc2_data.h:168
Power source information for Protoss.
Definition: sc2_data.h:269
uint32_t remaps_to_ability_id
This ability id may be represented by the given more generic id.
Definition: sc2_data.h:60
UnitTypeID unit_alias
Units that are morphed variants of the same unit.
Definition: sc2_data.h:195
AbilityID ability_id
Which ability id creates the unit.
Definition: sc2_data.h:180
The ObservationInterface reflects the current state of the game. Guaranteed to be valid when OnGameSt...
Definition: sc2_interfaces.h:47
Effect data.
Definition: sc2_data.h:252
Types used in setting up a game.
std::string name
Unit type name, corresponds to the game&#39;s catalog.
Definition: sc2_data.h:157
float food_required
How much food the unit requires.
Definition: sc2_data.h:176
std::string name
Buff name, corresponds to the game&#39;s catalog.
Definition: sc2_data.h:241
bool allow_minimap
Can be cast in the minimap. (Not implemented)
Definition: sc2_data.h:66
float build_time
How long the unit takes to build.
Definition: sc2_data.h:184
Upgrade data.
Definition: sc2_data.h:214
uint32_t cargo_size
Number of cargo slots they occupy in a transport.
Definition: sc2_data.h:161
float radius
Size of the circle the effect impacts.
Definition: sc2_data.h:260
Tag unit_tag
The unit.
Definition: sc2_data.h:95
std::string hotkey
UI hotkey.
Definition: sc2_data.h:58
Indicates if an ability is available, and if that ability requires a point.
Definition: sc2_data.h:17
Unit weapon.
Definition: sc2_data.h:133
int mineral_cost
Cost in minerals to build this unit type.
Definition: sc2_data.h:163
std::string name
Upgrade name, corresponds to the game&#39;s catalog.
Definition: sc2_data.h:218
float cast_range
Range unit can cast ability without needing to approach target.
Definition: sc2_data.h:76
uint32_t mineral_cost
Mineral cost of researching the upgrade.
Definition: sc2_data.h:220
bool requires_point
Indicates if the ability requires a point to invoke.
Definition: sc2_data.h:26
Point2D position
Power source position.
Definition: sc2_data.h:273
uint32_t vespene_cost
Vespene cost of researching the upgrade.
Definition: sc2_data.h:222
Data about a unit type. This data is derived from the catalog (xml) data of the game and upgrades...
Definition: sc2_data.h:153
bool available
If true, the unit is available to the current mods/map.
Definition: sc2_data.h:159
Data about an ability.
Definition: sc2_data.h:30