SC2API
An API for AI for StarCraft II
sc2_gametypes.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <vector>
7 #include <string>
8 
9 #include "sc2_common.h"
10 
11 namespace sc2 {
12 
13 typedef uint64_t Tag;
14 static const Tag NullTag = 0LL;
15 
16 enum Race {
17  Terran,
18  Zerg,
19  Protoss,
20  Random
21 };
22 
23 enum GameResult {
24  Win,
25  Loss,
26  Tie,
27  Undecided
28 };
29 
30 enum Difficulty {
31  VeryEasy = 1,
32  Easy = 2,
33  Medium = 3,
34  MediumHard = 4,
35  Hard = 5,
36  HardVeryHard = 6,
37  VeryHard = 7,
38  CheatVision = 8,
39  CheatMoney = 9,
40  CheatInsane = 10
41 };
42 
43 enum PlayerType {
44  Participant = 1,
45  Computer = 2,
46  Observer = 3
47 };
48 
49 enum class ChatChannel {
50  All = 0,
51  Team = 1
52 };
53 
54 class Agent;
55 
57 struct PlayerSetup {
59  PlayerType type;
62 
63  // Only used for Computer
64 
66  Race race;
68  Difficulty difficulty;
69 
70  PlayerSetup() :
71  type(Participant),
72  agent(nullptr),
73  race(Terran),
74  difficulty(Easy) {
75  };
76 
77  PlayerSetup(PlayerType in_type, Race in_race, Agent* in_agent = nullptr, Difficulty in_difficulty = Easy) :
78  type(in_type),
79  agent(in_agent),
80  race(in_race),
81  difficulty(in_difficulty) {
82 
83  }
84 };
85 
86 static inline PlayerSetup CreateParticipant(Race race, Agent* agent) {
87  return PlayerSetup(PlayerType::Participant, race, agent);
88 }
89 
90 static inline PlayerSetup CreateComputer(Race race, Difficulty difficulty = Easy) {
91  return PlayerSetup(PlayerType::Computer, race, nullptr, difficulty);
92 }
93 
95 struct PortSet {
96  int game_port;
97  int base_port;
98 
99  PortSet() :
100  game_port(-1),
101  base_port(-1) {
102  }
103 
104  bool IsValid() const {
105  return game_port > 0 && base_port > 0;
106  }
107 };
108 
110 struct Ports {
111  PortSet server_ports;
112  std::vector<PortSet> client_ports;
113  int shared_port;
114 
115  Ports() :
116  shared_port(-1) {
117  }
118 
119  bool IsValid() const {
120  if (shared_port < 1)
121  return false;
122  if (!server_ports.IsValid())
123  return false;
124  if (client_ports.size() < 1)
125  return false;
126  for (std::size_t i = 0; i < client_ports.size(); ++i)
127  if (!client_ports[i].IsValid())
128  return false;
129 
130  return true;
131  }
132 };
133 
134 static const int max_path_size = 512;
135 static const int max_version_size = 32;
136 static const int max_num_players = 16;
137 
143  int mmr;
145  int apm;
147  Race race;
151  GameResult game_result;
152 
153  ReplayPlayerInfo() :
154  player_id(0),
155  mmr(-10000),
156  apm(0),
157  race(Random),
158  race_selected(Random) {
159  }
160 };
161 
163 struct ReplayInfo {
164  float duration;
165  unsigned int duration_gameloops;
166  int32_t num_players;
167  uint32_t data_build;
168  uint32_t base_build;
169  std::string map_name;
170  std::string map_path;
171  std::string replay_path;
172  std::string version;
173  std::string data_version;
174  ReplayPlayerInfo players[max_num_players];
175 
176  ReplayInfo() :
177  duration(0.0f),
178  duration_gameloops(0),
179  num_players(0),
180  data_build(0),
181  base_build(0) {
182  }
183 
184  bool GetPlayerInfo(ReplayPlayerInfo& replay_player_info, int playerID) const {
185  for (int i = 0; i < num_players; ++i) {
186  if (playerID == players[i].player_id) {
187  replay_player_info = players[i];
188  return true;
189  }
190  }
191 
192  return false;
193  }
194 
195  float GetGameloopsPerSecond() const {
196  return float(duration_gameloops) / duration;
197  }
198 };
199 
200 struct PlayerResult {
201  PlayerResult(uint32_t player_id, GameResult result) : player_id(player_id), result(result) {};
202 
203  uint32_t player_id;
204  GameResult result;
205 };
206 
207 struct ChatMessage {
208  uint32_t player_id;
209  std::string message;
210 };
211 
212 }
Race race_selected
Selected player race. If the race is "Random", the race data member may be different.
Definition: sc2_gametypes.h:149
Common data types, including points, rectangles and colors.
Definition: sc2_gametypes.h:200
int apm
Player actions per minute.
Definition: sc2_gametypes.h:145
Information about a replay file.
Definition: sc2_gametypes.h:163
Definition: sc2_action.h:9
Port setup for one or more clients in a game.
Definition: sc2_gametypes.h:110
Difficulty difficulty
Difficulty: Only for playing against the built-in AI.
Definition: sc2_gametypes.h:68
Port setup for a client.
Definition: sc2_gametypes.h:95
Information about a player in a replay.
Definition: sc2_gametypes.h:139
GameResult game_result
If the player won or lost.
Definition: sc2_gametypes.h:151
int player_id
Player ID.
Definition: sc2_gametypes.h:141
Agent * agent
Agent, if one is available.
Definition: sc2_gametypes.h:61
int mmr
Player ranking.
Definition: sc2_gametypes.h:143
Race race
Race: Terran, Zerg or Protoss. Only for playing against the built-in AI.
Definition: sc2_gametypes.h:66
Setup for a player in a game.
Definition: sc2_gametypes.h:57
Definition: sc2_gametypes.h:207
PlayerType type
Player can be a Participant (usually an agent), Computer (in-built AI) or Observer.
Definition: sc2_gametypes.h:59
The base class for user defined bots.
Definition: sc2_agent.h:22
Race race
Actual player race.
Definition: sc2_gametypes.h:147