SC2API
An API for AI for StarCraft II
sc2_client.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 #include <cassert>
14 
15 #include "sc2api/sc2_typeenums.h"
16 
17 namespace sc2 {
18 
19 class ControlImp;
20 class Unit;
21 class ObservationInterface;
22 class QueryInterface;
23 class DebugInterface;
24 class ControlInterface;
25 class ControlImp;
26 
28 enum class ClientError {
29  ErrorSC2,
30  InvalidAbilityRemap,
31  InvalidResponse,
32  NoAbilitiesForTag,
33  ResponseNotConsumed,
34  ResponseMismatch,
35  ConnectionClosed,
36  SC2UnknownStatus,
37  SC2AppFailure,
38  SC2ProtocolError,
39  SC2ProtocolTimeout,
40  WrongGameVersion,
41 };
42 
44 class ClientEvents {
45 public:
47  virtual void OnGameFullStart() {}
48 
50  virtual void OnGameStart() {}
51 
53  virtual void OnGameEnd() {}
54 
57  virtual void OnStep() {}
58 
61  virtual void OnUnitDestroyed(const Unit*) {}
62 
65  virtual void OnUnitCreated(const Unit*) {}
66 
72  virtual void OnUnitIdle(const Unit*) {}
73 
76  virtual void OnUpgradeCompleted(UpgradeID) {}
77 
80  virtual void OnBuildingConstructionComplete(const Unit*) {}
81 
83  virtual void OnNydusDetected() {}
84 
86  virtual void OnNuclearLaunchDetected() {}
87 
90  virtual void OnUnitEnterVision(const Unit*) {}
91 
93  virtual void OnError(const std::vector<ClientError>& /*client_errors*/, const std::vector<std::string>& /*protocol_errors*/ = {}) {}
94 };
95 
97 class Client : public ClientEvents {
98 public:
99  Client();
100  virtual ~Client();
101 
103  const ObservationInterface* Observation() const;
104 
106  QueryInterface* Query();
107 
109  DebugInterface* Debug();
110 
113  ControlInterface* Control();
114  const ControlInterface* Control() const;
115 
116  void Reset();
117 
118 private:
120  ControlImp* control_imp_;
121 };
122 
128 bool IsCarryingMinerals(const Unit& unit);
129 
135 bool IsCarryingVespene(const Unit& unit);
136 
137 struct IsVisible {
138  bool operator()(const Unit& unit);
139 };
140 
141 }
A set of common events a user can override in their derived bot or replay observer class...
Definition: sc2_client.h:44
virtual void OnBuildingConstructionComplete(const Unit *)
Definition: sc2_client.h:80
A unit. Could be a structure, a worker or a military unit.
Definition: sc2_unit.h:69
virtual void OnError(const std::vector< ClientError > &, const std::vector< std::string > &={})
Called for various errors the library can encounter. See ClientError enum for possible errors...
Definition: sc2_client.h:93
Definition: sc2_interfaces.h:236
virtual void OnNydusDetected()
Called when a nydus is placed.
Definition: sc2_client.h:83
virtual void OnNuclearLaunchDetected()
Called when a nuclear launch is detected.
Definition: sc2_client.h:86
virtual void OnUnitDestroyed(const Unit *)
Definition: sc2_client.h:61
The base class for Agent and ReplayObserver.
Definition: sc2_client.h:97
Definition: sc2_action.h:9
ClientError
Definition: sc2_client.h:28
virtual void OnGameEnd()
Called when a game has ended.
Definition: sc2_client.h:53
A list of enums provided for your convenience.
bool IsCarryingMinerals(const Unit &unit)
bool IsCarryingVespene(const Unit &unit)
The ObservationInterface reflects the current state of the game. Guaranteed to be valid when OnGameSt...
Definition: sc2_interfaces.h:47
Definition: sc2_types.h:19
virtual void OnStep()
Definition: sc2_client.h:57
Definition: sc2_control_interfaces.h:16
virtual void OnGameFullStart()
Called when a game is started after a load. Fast restarting will not call this.
Definition: sc2_client.h:47
virtual void OnGameStart()
Called when a game is started or restarted.
Definition: sc2_client.h:50
virtual void OnUnitIdle(const Unit *)
Definition: sc2_client.h:72
virtual void OnUnitEnterVision(const Unit *)
Definition: sc2_client.h:90
Definition: sc2_interfaces.h:423
virtual void OnUnitCreated(const Unit *)
Definition: sc2_client.h:65
Definition: sc2_client.h:137
virtual void OnUpgradeCompleted(UpgradeID)
Definition: sc2_client.h:76