sc2ai 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/sc2ai/protocol/common.proto +5 -5
- data/data/sc2ai/protocol/data.proto +22 -22
- data/data/sc2ai/protocol/debug.proto +24 -24
- data/data/sc2ai/protocol/error.proto +216 -215
- data/data/sc2ai/protocol/raw.proto +20 -20
- data/data/sc2ai/protocol/sc2api.proto +111 -111
- data/data/sc2ai/protocol/score.proto +3 -3
- data/data/sc2ai/protocol/spatial.proto +5 -5
- data/data/sc2ai/protocol/ui.proto +16 -16
- data/exe/sc2ai +0 -3
- data/lib/sc2ai/api/data.rb +3 -3
- data/lib/sc2ai/connection/connection_listener.rb +3 -3
- data/lib/sc2ai/connection/requests.rb +31 -35
- data/lib/sc2ai/connection/status_listener.rb +1 -1
- data/lib/sc2ai/connection.rb +1 -1
- data/lib/sc2ai/local_play/client.rb +2 -2
- data/lib/sc2ai/local_play/match.rb +7 -2
- data/lib/sc2ai/paths.rb +12 -2
- data/lib/sc2ai/player/actions.rb +54 -35
- data/lib/sc2ai/player/debug.rb +21 -21
- data/lib/sc2ai/player/game_state.rb +11 -18
- data/lib/sc2ai/player/geo.rb +54 -64
- data/lib/sc2ai/player/units.rb +16 -16
- data/lib/sc2ai/player.rb +103 -41
- data/lib/sc2ai/ports.rb +1 -1
- data/lib/sc2ai/protocol/_meta_documentation.rb +265 -265
- data/lib/sc2ai/protocol/common_pb.rb +3865 -15
- data/lib/sc2ai/protocol/data_pb.rb +9109 -18
- data/lib/sc2ai/protocol/debug_pb.rb +10437 -26
- data/lib/sc2ai/protocol/error_pb.rb +1086 -10
- data/lib/sc2ai/protocol/extensions/ability_remapable.rb +9 -9
- data/lib/sc2ai/protocol/extensions/action.rb +60 -0
- data/lib/sc2ai/protocol/extensions/point_2_d.rb +5 -0
- data/lib/sc2ai/protocol/extensions/position.rb +10 -35
- data/lib/sc2ai/protocol/extensions/power_source.rb +3 -0
- data/lib/sc2ai/protocol/extensions/unit.rb +19 -35
- data/lib/sc2ai/protocol/query_pb.rb +5025 -17
- data/lib/sc2ai/protocol/raw_pb.rb +18350 -27
- data/lib/sc2ai/protocol/sc2api_pb.rb +48420 -93
- data/lib/sc2ai/protocol/score_pb.rb +5968 -12
- data/lib/sc2ai/protocol/spatial_pb.rb +11944 -18
- data/lib/sc2ai/protocol/ui_pb.rb +12927 -28
- data/lib/sc2ai/unit_group/action_ext.rb +0 -2
- data/lib/sc2ai/unit_group/filter_ext.rb +10 -9
- data/lib/sc2ai/unit_group/geo_ext.rb +0 -2
- data/lib/sc2ai/unit_group.rb +1 -1
- data/lib/sc2ai/version.rb +2 -3
- data/lib/sc2ai.rb +10 -11
- data/lib/templates/ladderzip/bin/ladder.tt +0 -3
- data/lib/templates/new/api/common.proto +6 -6
- data/lib/templates/new/api/data.proto +23 -20
- data/lib/templates/new/api/debug.proto +25 -21
- data/lib/templates/new/api/error.proto +217 -215
- data/lib/templates/new/api/query.proto +1 -1
- data/lib/templates/new/api/raw.proto +16 -14
- data/lib/templates/new/api/sc2api.proto +108 -94
- data/lib/templates/new/api/score.proto +4 -3
- data/lib/templates/new/api/spatial.proto +6 -5
- data/lib/templates/new/api/ui.proto +17 -14
- data/lib/templates/new/boot.rb.tt +1 -1
- data/lib/templates/new/my_bot.rb.tt +1 -1
- data/lib/templates/new/run_example_match.rb.tt +2 -2
- data/sig/sc2ai.rbs +11005 -1926
- metadata +26 -21
- data/lib/sc2ai/overrides/kernel.rb +0 -33
- data/sig/minaswan.rbs +0 -10323
@@ -5,7 +5,7 @@ module Sc2
|
|
5
5
|
# Callbacks when game status changes
|
6
6
|
module StatusListener
|
7
7
|
# Called when game status changes
|
8
|
-
# @param status [:
|
8
|
+
# @param status [:LAUNCHED, :IN_GAME, :IN_REPLAY, :ENDED, :QUIT, :UNKNOWN] game state, i.e. :IN_GAME, :ENDED, :LAUNCHED
|
9
9
|
# noinspection
|
10
10
|
def on_status_change(status)
|
11
11
|
Sc2.logger.debug { "#{self.class}.#{__method__} #{status}" }
|
data/lib/sc2ai/connection.rb
CHANGED
@@ -138,7 +138,7 @@ module Sc2
|
|
138
138
|
|
139
139
|
attr_writer :status, :listeners
|
140
140
|
|
141
|
-
# @return [HTTP::Endpoint] websocket url for establishing protobuf connection
|
141
|
+
# @return [::Async::HTTP::Endpoint] websocket url for establishing protobuf connection
|
142
142
|
def endpoint
|
143
143
|
Async::HTTP::Endpoint.parse("ws://#{@host}:#{@port}/sc2api")
|
144
144
|
end
|
@@ -115,7 +115,7 @@ module Sc2
|
|
115
115
|
|
116
116
|
# @!attribute task
|
117
117
|
# The async task running Sc2. Used when interrupting.
|
118
|
-
# @return [Async::Task]
|
118
|
+
# @return [::Async::Task]
|
119
119
|
attr_accessor :task
|
120
120
|
|
121
121
|
# @private
|
@@ -151,7 +151,7 @@ module Sc2
|
|
151
151
|
|
152
152
|
# @private
|
153
153
|
# Reads bundled versions.json
|
154
|
-
# @return [
|
154
|
+
# @return [Array] JSON contents of versions.json
|
155
155
|
def versions_json
|
156
156
|
JSON.load_file(Paths.gem_data_versions_path)
|
157
157
|
end
|
@@ -72,6 +72,11 @@ module Sc2
|
|
72
72
|
ClientManager.stop(player_index) # unless keep_clients_alive
|
73
73
|
end
|
74
74
|
end
|
75
|
+
# Here, Api players are busy Joining and we wait for map loads
|
76
|
+
# Let's use this time for quick housekeeping before the match
|
77
|
+
run_task.async do
|
78
|
+
Process.warmup
|
79
|
+
end
|
75
80
|
rescue
|
76
81
|
# no op - clean exit from game may cause ws disconnection error
|
77
82
|
end.wait
|
@@ -116,7 +121,7 @@ module Sc2
|
|
116
121
|
# Gets a Sc2 client from Sc2::ClientManager and connects them
|
117
122
|
def connect_players
|
118
123
|
# Depending on number of players, api has different ready states
|
119
|
-
ready_statuses = (api_players.size > 1) ? [:
|
124
|
+
ready_statuses = (api_players.size > 1) ? [:LAUNCHED] : %i[LAUNCHED READY]
|
120
125
|
|
121
126
|
# For each player, attempt to connect and retry once after closing Sc2 in worst-case
|
122
127
|
api_players.each_with_index do |player, i|
|
@@ -149,7 +154,7 @@ module Sc2
|
|
149
154
|
api_players.each do |player|
|
150
155
|
# Clean surrender locally. Lapizistik taught me bad things.
|
151
156
|
def player.leave_game
|
152
|
-
debug_end_game(end_result: :
|
157
|
+
debug_end_game(end_result: :SURRENDER)
|
153
158
|
end
|
154
159
|
end
|
155
160
|
end
|
data/lib/sc2ai/paths.rb
CHANGED
@@ -12,19 +12,26 @@ module Sc2
|
|
12
12
|
# Credit to Hannes, Sean and Burny for setting the standard
|
13
13
|
class Paths
|
14
14
|
# Platform name for Windows
|
15
|
+
# @return [String] "Windows"
|
15
16
|
PF_WINDOWS = "Windows"
|
16
17
|
# Platform name for WSL1
|
18
|
+
# @return [String] "WSL"
|
17
19
|
PF_WSL1 = "WSL1"
|
18
20
|
# Platform name for WSL2
|
21
|
+
# @return [String] "WSL2"
|
19
22
|
PF_WSL2 = "WSL2"
|
20
23
|
# Platform name macOS
|
24
|
+
# @return [String] "Darwin"
|
21
25
|
PF_DARWIN = "Darwin"
|
22
26
|
# Platform name Linux
|
27
|
+
# @return [String] "Linux"
|
23
28
|
PF_LINUX = "Linux"
|
24
29
|
# Platform name for Wine
|
30
|
+
# @return [String] "WineLinux"
|
25
31
|
PF_WINE = "WineLinux"
|
26
32
|
|
27
33
|
# Where within user directory to locate ExecuteInfo.txt
|
34
|
+
# @return [Hash<String, String>] PF_* => "/path/to/StarCraft II"
|
28
35
|
BASE_DIR = {
|
29
36
|
PF_WINDOWS => "C:/Program Files (x86)/StarCraft II",
|
30
37
|
PF_WSL1 => "/mnt/c/Program Files (x86)/StarCraft II",
|
@@ -35,6 +42,7 @@ module Sc2
|
|
35
42
|
}.freeze
|
36
43
|
|
37
44
|
# Where within user directory to locate ExecuteInfo.txt
|
45
|
+
# @return [Hash<String, String>] PF_* => "/path/to/ExecuteInfo.txt"
|
38
46
|
EXEC_INFO_PATH = {
|
39
47
|
PF_WINDOWS => "Documents/StarCraft II/ExecuteInfo.txt",
|
40
48
|
PF_WSL1 => "Documents/StarCraft II/ExecuteInfo.txt",
|
@@ -45,6 +53,7 @@ module Sc2
|
|
45
53
|
}.freeze
|
46
54
|
|
47
55
|
# Path helper for finding executable
|
56
|
+
# @return [Hash<String, String>] PF_* => "SC2_binary.exe"
|
48
57
|
BIN_PATH = {
|
49
58
|
PF_WINDOWS => "SC2_x64.exe",
|
50
59
|
PF_WSL1 => "SC2_x64.exe",
|
@@ -56,6 +65,7 @@ module Sc2
|
|
56
65
|
|
57
66
|
# Working directory sub-folder per platform.
|
58
67
|
# Used when spawning client process on some platforms.
|
68
|
+
# @return [Hash<String, String>] PF_* => "Directory"
|
59
69
|
WORKING_DIR = {
|
60
70
|
PF_WINDOWS => "Support64",
|
61
71
|
PF_WSL1 => "Support64",
|
@@ -74,7 +84,7 @@ module Sc2
|
|
74
84
|
|
75
85
|
# Bucketed platform names follows convention
|
76
86
|
# Uses ENV['SC2PF'] if configured. This is the only way to set "WineLinux"
|
77
|
-
# @return [
|
87
|
+
# @return [String] string platform name
|
78
88
|
def platform
|
79
89
|
return ENV.fetch("SC2PF", nil) unless ENV["SC2PF"].to_s.strip.empty?
|
80
90
|
|
@@ -252,7 +262,7 @@ module Sc2
|
|
252
262
|
end
|
253
263
|
|
254
264
|
# Loads version data
|
255
|
-
# @return [
|
265
|
+
# @return [Array] versions.json
|
256
266
|
def version_json
|
257
267
|
JSON.load_file(Pathname(__dir__.to_s).join("../data/versions.json"))
|
258
268
|
end
|
data/lib/sc2ai/player/actions.rb
CHANGED
@@ -148,8 +148,8 @@ module Sc2
|
|
148
148
|
|
149
149
|
# Issues spatial unit command. Target is either target_screen_coord or target_minimap_coord.
|
150
150
|
# @param ability_id [Api::AbilityId]
|
151
|
-
# @param target_screen_coord [Api::
|
152
|
-
# @param target_minimap_coord [Api::
|
151
|
+
# @param target_screen_coord [Api::PointI]
|
152
|
+
# @param target_minimap_coord [Api::PointI]
|
153
153
|
# @param queue_command [Boolean] shift+command
|
154
154
|
# @return [void]
|
155
155
|
def action_spatial_unit_command(ability_id:, target_screen_coord: nil, target_minimap_coord: nil, queue_command: false)
|
@@ -166,7 +166,7 @@ module Sc2
|
|
166
166
|
end
|
167
167
|
|
168
168
|
# Simulates a click on the minimap to move the camera.
|
169
|
-
# @param center_minimap [Api::
|
169
|
+
# @param center_minimap [Api::PointI]
|
170
170
|
# @return [void]
|
171
171
|
#
|
172
172
|
def action_spatial_camera_move(center_minimap:)
|
@@ -182,10 +182,10 @@ module Sc2
|
|
182
182
|
# Issues spatial unit select point command. Target is either target_screen_coord or target_minimap_coord.
|
183
183
|
# @param type [Integer] 1,2,3,4 = Api::ActionSpatialUnitSelectionPoint::Type::*
|
184
184
|
# enum Type {
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
185
|
+
# SELECT = 1; // EQUIVALENT TO NORMAL CLICK. CHANGES SELECTION TO UNIT.
|
186
|
+
# TOGGLE = 2; // EQUIVALENT TO SHIFT+CLICK. TOGGLE SELECTION OF UNIT.
|
187
|
+
# ALL_TYPE = 3; // EQUIVALENT TO CONTROL+CLICK. SELECTS ALL UNITS OF A GIVEN TYPE.
|
188
|
+
# ADD_ALL_TYPE = 4; // EQUIVALENT TO SHIFT+CONTROL+CLICK. SELECTS ALL UNITS OF A GIVEN TYPE.
|
189
189
|
# }
|
190
190
|
# @param selection_screen_coord [Api::PointI]
|
191
191
|
# @return [void]
|
@@ -221,11 +221,11 @@ module Sc2
|
|
221
221
|
# Populated if Feature Layer or Render interface is enabled.
|
222
222
|
# @param action [Integer] 1-5 = Api::ActionControlGroup::ControlGroupAction::*
|
223
223
|
# enum ControlGroupAction {
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
224
|
+
# RECALL = 1; // EQUIVALENT TO NUMBER HOTKEY. REPLACES CURRENT SELECTION WITH CONTROL GROUP.
|
225
|
+
# SET = 2; // EQUIVALENT TO CONTROL + NUMBER HOTKEY. SETS CONTROL GROUP TO CURRENT SELECTION.
|
226
|
+
# APPEND = 3; // EQUIVALENT TO SHIFT + NUMBER HOTKEY. ADDS CURRENT SELECTION INTO CONTROL GROUP.
|
227
|
+
# SET_AND_STEAL = 4; // EQUIVALENT TO CONTROL + ALT + NUMBER HOTKEY. SETS CONTROL GROUP TO CURRENT SELECTION. UNITS ARE REMOVED FROM OTHER CONTROL GROUPS.
|
228
|
+
# APPEND_AND_STEAL = 5; // EQUIVALENT TO SHIFT + ALT + NUMBER HOTKEY. ADDS CURRENT SELECTION INTO CONTROL GROUP. UNITS ARE REMOVED FROM OTHER CONTROL GROUPS.
|
229
229
|
# }
|
230
230
|
# @param control_group_index [Integer] 0-9
|
231
231
|
# @return [void]
|
@@ -280,10 +280,10 @@ module Sc2
|
|
280
280
|
# @param type [Integer] 1-4 = Api::ActionSelectIdleWorker::Type::*
|
281
281
|
#
|
282
282
|
# enum Type {
|
283
|
-
#
|
284
|
-
#
|
285
|
-
#
|
286
|
-
#
|
283
|
+
# SET = 1; // EQUIVALENT TO CLICK WITH NO MODIFIERS. REPLACES SELECTION WITH SINGLE IDLE WORKER.
|
284
|
+
# ADD = 2; // EQUIVALENT TO SHIFT+CLICK. ADDS SINGLE IDLE WORKER TO CURRENT SELECTION.
|
285
|
+
# ALL = 3; // EQUIVALENT TO CONTROL+CLICK. SELECTS ALL IDLE WORKERS.
|
286
|
+
# ADD_ALL = 4; // EQUIVALENT TO SHIFT+CONTROL+CLICK. ADDS ALL IDLE WORKERS TO CURRENT SELECTION.
|
287
287
|
# }
|
288
288
|
def action_ui_select_idle_worker(type:)
|
289
289
|
queue_action Api::Action.new(
|
@@ -299,15 +299,15 @@ module Sc2
|
|
299
299
|
# @param type [Integer] 1-4 = Api::ActionMultiPanel::Type::*
|
300
300
|
# @param unit_index [Integer] n'th unit on panel
|
301
301
|
# enum Type {
|
302
|
-
#
|
303
|
-
#
|
304
|
-
#
|
305
|
-
#
|
302
|
+
# SINGLE_SELECT = 1; // CLICK ON ICON
|
303
|
+
# DESELECT_UNIT = 2; // SHIFT CLICK ON ICON
|
304
|
+
# SELECT_ALL_OF_TYPE = 3; // CONTROL CLICK ON ICON.
|
305
|
+
# DESELECT_ALL_OF_TYPE = 4; // CONTROL+SHIFT CLICK ON ICON.
|
306
|
+
# }
|
307
|
+
# message ActionMultiPanel {
|
308
|
+
# optional Type type = 1;
|
309
|
+
# optional int32 unit_index = 2;
|
306
310
|
# }
|
307
|
-
# message ActionMultiPanel {
|
308
|
-
# optional Type type = 1;
|
309
|
-
# optional int32 unit_index = 2;
|
310
|
-
# }
|
311
311
|
def action_ui_multi_panel(type:, unit_index:)
|
312
312
|
queue_action Api::Action.new(
|
313
313
|
action_ui: Api::ActionUI.new(
|
@@ -359,8 +359,8 @@ module Sc2
|
|
359
359
|
|
360
360
|
# Send a chat message
|
361
361
|
# @param message [String] to send
|
362
|
-
# @param channel [Integer] 1-2, default:
|
363
|
-
def action_chat(message, channel: Api::ActionChat::Channel::
|
362
|
+
# @param channel [Integer] 1-2, default:TEAM Api::ActionChat::Channel::BROADCAST = 1, Api::ActionChat::Channel::TEAM = 2
|
363
|
+
def action_chat(message, channel: Api::ActionChat::Channel::TEAM)
|
364
364
|
queue_action Api::Action.new(
|
365
365
|
action_chat: Api::ActionChat.new(
|
366
366
|
channel: channel,
|
@@ -371,24 +371,43 @@ module Sc2
|
|
371
371
|
|
372
372
|
private
|
373
373
|
|
374
|
+
# @private
|
375
|
+
# Clears action errors. The list should be empty before we
|
376
|
+
# do build the errors from our batch action of this step
|
377
|
+
def clear_action_errors
|
378
|
+
@action_errors = []
|
379
|
+
end
|
380
|
+
|
374
381
|
# Sends actions via api and flushes action_queue
|
382
|
+
# @return [Api::ResponseAction, nil]
|
375
383
|
def perform_actions
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
384
|
+
return nil if @action_queue.empty?
|
385
|
+
|
386
|
+
response_action = @api.action(@action_queue)
|
387
|
+
if callback_defined?(:on_action_errors)
|
388
|
+
# Clear action errors
|
389
|
+
clear_action_errors
|
390
|
+
# Loop over every executed action response
|
391
|
+
response_action.result.each_with_index do |action_result, i|
|
392
|
+
next if action_result == Api::ActionResult::SUCCESS
|
393
|
+
executed_action = @action_queue[i]
|
394
|
+
next unless [Api::ActionRaw, Api::ActionUI].include?(executed_action.action_type) # undetectable Api::ActionSpatial,
|
395
|
+
|
396
|
+
@action_errors << Api::ActionError.new(
|
397
|
+
unit_tag: executed_action.unit_tags.first,
|
398
|
+
ability_id: executed_action.ability_id,
|
399
|
+
result: action_result
|
400
|
+
)
|
401
|
+
end
|
402
|
+
end
|
382
403
|
clear_action_queue
|
404
|
+
response_action
|
383
405
|
end
|
384
406
|
|
385
407
|
# Empties and resets @action_queue
|
386
408
|
# @return [void]
|
387
409
|
def clear_action_queue
|
388
410
|
@action_queue = []
|
389
|
-
# TYPES.each do |type|
|
390
|
-
# @action_queue[type] = []
|
391
|
-
# end
|
392
411
|
end
|
393
412
|
|
394
413
|
# Returns an array of unit tags from a variety of sources
|
data/lib/sc2ai/player/debug.rb
CHANGED
@@ -22,7 +22,7 @@ module Sc2
|
|
22
22
|
|
23
23
|
# Prints debug text top left corner
|
24
24
|
# @param text [String] will respect newlines
|
25
|
-
# @param size [
|
25
|
+
# @param size [Integer] of font, default 14px
|
26
26
|
# @return [void]
|
27
27
|
def debug_print(text, size: 14)
|
28
28
|
queue_debug_command Api::DebugCommand.new(
|
@@ -43,7 +43,7 @@ module Sc2
|
|
43
43
|
# @param left_percent [Numeric] range 0..100. percent from left of screen
|
44
44
|
# @param top_percent [Numeric] range 0..100. percent from top of screen
|
45
45
|
# @param color [Api::Color] default white
|
46
|
-
# @param size [
|
46
|
+
# @param size [Integer] of font, default 14px
|
47
47
|
# @return [void]
|
48
48
|
def debug_text_screen(text, left_percent: 1.0, top_percent: 1.0, color: nil, size: 14)
|
49
49
|
queue_debug_command Api::DebugCommand.new(
|
@@ -67,7 +67,7 @@ module Sc2
|
|
67
67
|
# @param text [String] will respect newlines
|
68
68
|
# @param point [Api::Point] point in the world, i.e. unit.pos
|
69
69
|
# @param color [Api::Color] default white
|
70
|
-
# @param size [
|
70
|
+
# @param size [Integer] of font, default 14px
|
71
71
|
# @return [void]
|
72
72
|
def debug_text_world(text, point:, color: nil, size: 14)
|
73
73
|
queue_debug_command Api::DebugCommand.new(
|
@@ -152,7 +152,7 @@ module Sc2
|
|
152
152
|
# Renders a block on the floor, drawn by 4 lines
|
153
153
|
# Pass in either a pos (Position/Unit) or exact x * y coordinates
|
154
154
|
# Optional indentation adds padding on borders inward
|
155
|
-
# @param pos [Api::Unit,
|
155
|
+
# @param pos [Api::Unit, Sc2::Position]
|
156
156
|
# @param x [Float, Integer]
|
157
157
|
# @param y [Float, Integer]
|
158
158
|
# @param color [Api::Color]
|
@@ -166,8 +166,8 @@ module Sc2
|
|
166
166
|
x = pos.pos.x.floor
|
167
167
|
y = pos.pos.y.floor
|
168
168
|
elsif pos.is_a?(Sc2::Position)
|
169
|
-
x = pos.
|
170
|
-
y = pos.
|
169
|
+
x = pos.x.floor
|
170
|
+
y = pos.y.floor
|
171
171
|
end
|
172
172
|
|
173
173
|
# Raise above floor to prevent texture clipping
|
@@ -187,18 +187,18 @@ module Sc2
|
|
187
187
|
|
188
188
|
# @param command [Integer] one of Api::DebugGameState::*
|
189
189
|
# Possible values:
|
190
|
-
# Api::DebugGameState::
|
191
|
-
# Api::DebugGameState::
|
192
|
-
# Api::DebugGameState::
|
193
|
-
# Api::DebugGameState::
|
194
|
-
# Api::DebugGameState::
|
195
|
-
# Api::DebugGameState::
|
196
|
-
# Api::DebugGameState::
|
197
|
-
# Api::DebugGameState::
|
198
|
-
# Api::DebugGameState::
|
199
|
-
# Api::DebugGameState::
|
200
|
-
# Api::DebugGameState::
|
201
|
-
# Api::DebugGameState::
|
190
|
+
# Api::DebugGameState::SHOW_MAP
|
191
|
+
# Api::DebugGameState::CONTROL_ENEMY
|
192
|
+
# Api::DebugGameState::FOOD
|
193
|
+
# Api::DebugGameState::FREE
|
194
|
+
# Api::DebugGameState::ALL_RESOURCES
|
195
|
+
# Api::DebugGameState::GOD
|
196
|
+
# Api::DebugGameState::MINERALS
|
197
|
+
# Api::DebugGameState::GAS
|
198
|
+
# Api::DebugGameState::COOLDOWN
|
199
|
+
# Api::DebugGameState::TECH_TREE
|
200
|
+
# Api::DebugGameState::UPGRADE
|
201
|
+
# Api::DebugGameState::FAST_BUILD
|
202
202
|
# @return [void]
|
203
203
|
def debug_game_state(command)
|
204
204
|
queue_debug_command Api::DebugCommand.new(
|
@@ -237,7 +237,7 @@ module Sc2
|
|
237
237
|
|
238
238
|
# @private
|
239
239
|
# Hangs, crashes and exits the Sc2 client. DO NOT USE.
|
240
|
-
# @param test [Integer] one of Api::DebugTestProcess::Test::
|
240
|
+
# @param test [Integer] one of Api::DebugTestProcess::Test::CRASH, Api::DebugTestProcess::Test::HANG, Api::DebugTestProcess::Test::EXIT
|
241
241
|
# @param delay_ms [Integer] default 0, how long this test is delayed
|
242
242
|
# @return [void]
|
243
243
|
def debug_test_process(test:, delay_ms: 0)
|
@@ -260,8 +260,8 @@ module Sc2
|
|
260
260
|
)
|
261
261
|
end
|
262
262
|
|
263
|
-
# Ends game with a specified result of either
|
264
|
-
# @param end_result [Integer] either 1/2. Api::DebugEndGame::EndResult::
|
263
|
+
# Ends game with a specified result of either :SURRENDER or :DECLARE_VICTORY
|
264
|
+
# @param end_result [Integer] either 1/2. Api::DebugEndGame::EndResult::SURRENDER or Api::DebugEndGame::EndResult::DECLARE_VICTORY
|
265
265
|
# @return [void]
|
266
266
|
def debug_end_game(end_result:)
|
267
267
|
queue_debug_command Api::DebugCommand.new(
|
@@ -5,7 +5,7 @@ module Sc2
|
|
5
5
|
# Holds game state
|
6
6
|
module GameState
|
7
7
|
# @!attribute status
|
8
|
-
# @return [:
|
8
|
+
# @return [:LAUNCHED, :IN_GAME, :IN_REPLAY, :ENDED, :QUIT, :UNKNOWN] status
|
9
9
|
attr_accessor :status
|
10
10
|
|
11
11
|
include Connection::StatusListener
|
@@ -27,10 +27,16 @@ module Sc2
|
|
27
27
|
# Access useful game information. Used in parsed pathing grid, terrain height, placement grid.
|
28
28
|
# Holds Api::ResponseGameInfo::#start_locations.
|
29
29
|
# @return [Api::ResponseGameInfo]
|
30
|
-
|
30
|
+
def game_info
|
31
|
+
if @game_info_task&.running?
|
32
|
+
@game_info_task&.wait
|
33
|
+
@game_info_task = nil
|
34
|
+
end
|
35
|
+
@game_info
|
36
|
+
end
|
31
37
|
|
32
38
|
def game_info=(new_info)
|
33
|
-
@game_info_loop = game_loop
|
39
|
+
@game_info_loop = game_loop
|
34
40
|
@game_info = new_info
|
35
41
|
end
|
36
42
|
|
@@ -40,19 +46,6 @@ module Sc2
|
|
40
46
|
# @return [Integer]
|
41
47
|
attr_accessor :game_info_loop
|
42
48
|
|
43
|
-
# Determines if your game_info will be refreshed at this moment
|
44
|
-
# Has a hard-capped refresh of only ever 4 steps
|
45
|
-
# In general game_info is only refreshed Player::Bot reads from pathing_grid or placement_grid
|
46
|
-
# @return [Boolean]
|
47
|
-
def game_info_stale?
|
48
|
-
return true if game_info_loop.nil? || game_info.nil?
|
49
|
-
return false if game_info_loop == game_loop
|
50
|
-
|
51
|
-
# Note: No minimum step count set anymore
|
52
|
-
# We can do something like, only updating every 2+ frames:
|
53
|
-
game_info_loop + 4 <= game_loop
|
54
|
-
end
|
55
|
-
|
56
49
|
# @!attribute data
|
57
50
|
# @return [Api::ResponseData]
|
58
51
|
attr_accessor :data
|
@@ -141,14 +134,14 @@ module Sc2
|
|
141
134
|
player_id: 0,
|
142
135
|
minerals: 50,
|
143
136
|
vespene: 0,
|
144
|
-
food_cap: ((race == Api::Race::
|
137
|
+
food_cap: ((race == Api::Race::ZERG) ? 14 : 15),
|
145
138
|
food_used: 12,
|
146
139
|
food_army: 0,
|
147
140
|
food_workers: 12,
|
148
141
|
idle_worker_count: 0,
|
149
142
|
army_count: 0,
|
150
143
|
warp_gate_count: 0,
|
151
|
-
larva_count: ((race == Api::Race::
|
144
|
+
larva_count: ((race == Api::Race::ZERG) ? 3 : 0)
|
152
145
|
)
|
153
146
|
end
|
154
147
|
|