SC2API
An API for AI for StarCraft II
sc2_interfaces.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include "sc2api/sc2_common.h"
12 #include "sc2api/sc2_action.h"
13 #include "sc2api/sc2_unit.h"
14 #include "sc2api/sc2_data.h"
15 
16 #include <vector>
17 
18 // Forward declarations to avoid including proto headers everywhere.
19 namespace SC2APIProtocol {
20  class Observation;
21 }
22 
23 namespace sc2 {
24 
25 enum class UNIT_TYPEID;
26 enum class ABILITY_ID;
27 
28 class ObservationInterface;
29 struct Score;
30 struct GameInfo;
31 
32 enum class Visibility {
33  Hidden = 0,
34  Fogged = 1,
35  Visible = 2,
36  FullHidden = 3
37 };
38 
44 typedef std::function<bool(const Unit& unit)> Filter;
45 
48 public:
49  virtual ~ObservationInterface() = default;
50 
53  virtual uint32_t GetPlayerID() const = 0;
54 
57  virtual uint32_t GetGameLoop() const = 0;
58 
61  virtual Units GetUnits() const = 0;
62 
68  virtual Units GetUnits(Unit::Alliance alliance, Filter filter = {}) const = 0;
69 
74  virtual Units GetUnits(Filter filter) const = 0;
75 
79  virtual const Unit* GetUnit(Tag tag) const = 0;
80 
83  virtual const RawActions& GetRawActions() const = 0;
84 
87  virtual const SpatialActions& GetFeatureLayerActions() const = 0;
88 
91  virtual const SpatialActions& GetRenderedActions() const = 0;
92 
95  virtual const std::vector<ChatMessage>& GetChatMessages() const = 0;
96 
99  virtual const std::vector<PowerSource>& GetPowerSources() const = 0;
100 
103  virtual const std::vector<Effect>& GetEffects() const = 0;
104 
107  virtual const std::vector<UpgradeID>& GetUpgrades() const = 0;
108 
111  virtual const Score& GetScore() const = 0;
112 
116  virtual const Abilities& GetAbilityData(bool force_refresh = false) const = 0;
117 
121  virtual const UnitTypes& GetUnitTypeData(bool force_refresh = false) const = 0;
122 
126  virtual const Upgrades& GetUpgradeData(bool force_refresh = false) const = 0;
127 
131  virtual const Buffs& GetBuffData(bool force_refresh = false) const = 0;
132 
136  virtual const Effects& GetEffectData(bool force_refresh = false) const = 0;
137 
140  virtual const GameInfo& GetGameInfo() const = 0;
141 
144  virtual int32_t GetMinerals() const = 0;
145 
148  virtual int32_t GetVespene() const = 0;
149 
153  virtual int32_t GetFoodCap() const = 0;
154 
158  virtual int32_t GetFoodUsed() const = 0;
159 
163  virtual int32_t GetFoodArmy() const = 0;
164 
168  virtual int32_t GetFoodWorkers() const = 0;
169 
172  virtual int32_t GetIdleWorkerCount() const = 0;
173 
176  virtual int32_t GetArmyCount() const = 0;
177 
180  virtual int32_t GetWarpGateCount() const = 0;
181 
184  virtual Point2D GetCameraPos() const = 0;
185 
188  virtual Point3D GetStartLocation() const = 0;
189 
192  virtual const std::vector<PlayerResult>& GetResults() const = 0;
193 
197  virtual bool HasCreep(const Point2D& point) const = 0;
198 
202  virtual Visibility GetVisibility(const Point2D& point) const = 0;
203 
205  // include pathing blockers like structures. For more accurate pathing results
206  // use QueryInterface::PathingDistance.
209  virtual bool IsPathable(const Point2D& point) const = 0;
210 
212  // include blockers like other structures. For more accurate building placement
213  // results use QueryInterface::Placement.
216  virtual bool IsPlacable(const Point2D& point) const = 0;
217 
221  virtual float TerrainHeight(const Point2D& point) const = 0;
222 
224  // it is highly discouraged. It should only be used for extracting feature layers because it would be inefficient to copy these each frame.
227  virtual const SC2APIProtocol::Observation* GetRawObservation() const = 0;
228 
229 };
230 
231 
237 public:
238  virtual ~QueryInterface() = default;
239 
244  virtual AvailableAbilities GetAbilitiesForUnit(const Unit* unit, bool ignore_resource_requirements = false) = 0;
250  virtual std::vector<AvailableAbilities> GetAbilitiesForUnits(const Units& units, bool ignore_resource_requirements = false) = 0;
251 
256  virtual float PathingDistance(const Point2D& start, const Point2D& end) = 0;
262  virtual float PathingDistance(const Unit* start, const Point2D& end) = 0;
263 
264  struct PathingQuery {
265  Tag start_unit_tag_ = NullTag;
266  Point2D start_;
267  Point2D end_;
268  };
270  virtual std::vector<float> PathingDistance(const std::vector<PathingQuery>& queries) = 0;
271 
279  virtual bool Placement(const AbilityID& ability, const Point2D& target_pos, const Unit* unit = nullptr) = 0;
280 
281  struct PlacementQuery {
282  PlacementQuery() = default;
283  PlacementQuery(AbilityID ability_id, Point2D target) :
284  ability(ability_id),
285  target_pos(target) {};
286 
287  AbilityID ability;
288  Point2D target_pos;
289  Tag placing_unit_tag = 0LL; // Optional. Used for testing placement with add-ons.
290  };
295  virtual std::vector<bool> Placement(const std::vector<PlacementQuery>& queries) = 0;
296 };
297 
298 
302 public:
303  virtual ~ActionInterface() = default;
304 
313  virtual void UnitCommand(const Unit* unit, AbilityID ability, bool queued_command = false) = 0;
317 
322  virtual void UnitCommand(const Unit* unit, AbilityID ability, const Point2D& point, bool queued_command = false) = 0;
323 
328  virtual void UnitCommand(const Unit* unit, AbilityID ability, const Unit* target, bool queued_command = false) = 0;
329 
331  virtual void UnitCommand(const Units& units, AbilityID ability, bool queued_move = false) = 0;
332 
334  virtual void UnitCommand(const Units& units, AbilityID ability, const Point2D& point, bool queued_command = false) = 0;
335 
337  virtual void UnitCommand(const Units& units, AbilityID ability, const Unit* target, bool queued_command = false) = 0;
338 
342  virtual const std::vector<Tag>& Commands() const = 0;
343 
347  virtual void ToggleAutocast(Tag unit_tag, AbilityID ability) = 0;
351  virtual void ToggleAutocast(const std::vector<Tag>& unit_tags, AbilityID ability) = 0;
352 
356  virtual void SendChat(const std::string& message, ChatChannel channel = ChatChannel::All) = 0;
357 
362  virtual void SendActions() = 0;
363 };
364 
368 public:
369  virtual ~ActionFeatureLayerInterface() = default;
370 
373  virtual void UnitCommand(AbilityID ability) = 0;
374 
379  virtual void UnitCommand(AbilityID ability, const Point2DI& point, bool minimap = false) = 0;
380 
382  virtual void CameraMove(const Point2DI& center) = 0;
383 
387  virtual void Select(const Point2DI& center, PointSelectionType selection_type) = 0;
388 
393  virtual void Select(const Point2DI& p0, const Point2DI& p1, bool add_to_selection = false) = 0;
394 
397  virtual void SendActions() = 0;
398 };
399 
402 public:
403  virtual ~ObserverActionInterface () = default;
404 
409  virtual void CameraMove(const Point2D& point, float distance = 0.0f) = 0;
410 
412  virtual void CameraFollowPlayer() = 0;
413 
416  virtual void SendActions() = 0;
417 };
418 
424 public:
425  virtual ~DebugInterface() = default;
426 
427  // Debug drawing primitives.
428 
432  virtual void DebugTextOut(const std::string& out, Color color = Colors::White) = 0;
438  virtual void DebugTextOut(const std::string& out, const Point2D& pt_virtual_2D, Color color = Colors::White, uint32_t size = 8) = 0;
444  virtual void DebugTextOut(const std::string& out, const Point3D& pt3D, Color color = Colors::White, uint32_t size = 8) = 0;
449  virtual void DebugLineOut(const Point3D& p0, const Point3D& p1, Color color = Colors::White) = 0;
454  virtual void DebugBoxOut(const Point3D& p_min, const Point3D& p_max, Color color = Colors::White) = 0;
459  virtual void DebugSphereOut(const Point3D& p, float r, Color color = Colors::White) = 0;
460 
461  // Cheats.
462 
468  virtual void DebugCreateUnit(UnitTypeID unit_type, const Point2D& p, uint32_t player_id = 1, uint32_t count = 1) = 0;
469 
472  virtual void DebugKillUnit(const Unit* unit) = 0;
473 
475  virtual void DebugShowMap() = 0;
477  virtual void DebugEnemyControl() = 0;
479  virtual void DebugIgnoreFood() = 0;
481  virtual void DebugIgnoreResourceCost() = 0;
483  virtual void DebugGiveAllResources() = 0;
485  virtual void DebugGodMode() = 0;
487  virtual void DebugIgnoreMineral() = 0;
489  virtual void DebugNoCooldowns() = 0;
491  virtual void DebugGiveAllTech() = 0;
493  virtual void DebugGiveAllUpgrades() = 0;
495  virtual void DebugFastBuild() = 0;
497  virtual void DebugSetScore(float score) = 0;
500  virtual void DebugEndGame(bool victory = false) = 0;
504  virtual void DebugSetEnergy(float value, const Unit* unit) = 0;
508  virtual void DebugSetLife(float value, const Unit* unit) = 0;
512  virtual void DebugSetShields(float value, const Unit* unit) = 0;
513 
516  virtual void DebugMoveCamera(const Point2D& pos) = 0;
517 
518  enum AppTest {
519  hang = 1,
520  crash = 2,
521  exit = 3
522  };
526  virtual void DebugTestApp(AppTest app_test, int delay_ms = 0) = 0;
527 
530  virtual void SendDebug() = 0;
531 };
532 
533 }
Possible actions for feature layers.
Definition: sc2_action.h:113
Definition: sc2_interfaces.h:281
Common data types, including points, rectangles and colors.
A unit. Could be a structure, a worker or a military unit.
Definition: sc2_unit.h:69
Unit data in an observation.
Alliance
Relationship to this player.
Definition: sc2_unit.h:83
Definition: sc2_interfaces.h:236
2D integer point.
Definition: sc2_common.h:95
Scores.
Definition: sc2_score.h:179
Definition: sc2_common.h:14
Definition: sc2_common.h:49
Definition: sc2_action.h:9
All available abilities for a unit.
Definition: sc2_data.h:91
RGB Color.
Definition: sc2_common.h:115
Definition: sc2_interfaces.h:264
The ObservationInterface reflects the current state of the game. Guaranteed to be valid when OnGameSt...
Definition: sc2_interfaces.h:47
std::function< bool(const Unit &unit)> Filter
Definition: sc2_interfaces.h:44
The ObserverActionInterface corresponds to the actions available in the observer UI.
Definition: sc2_interfaces.h:401
Initial data for a game and map.
Definition: sc2_map_info.h:69
Definition: sc2_interfaces.h:423
Definition: sc2_interfaces.h:301
Definition: sc2_connection.h:16
Definition: sc2_interfaces.h:367