sc2ai 0.0.0.pre → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/data/data.json +1 -0
  3. data/data/data_readable.json +22842 -0
  4. data/data/sc2ai/protocol/common.proto +59 -0
  5. data/data/sc2ai/protocol/data.proto +120 -0
  6. data/data/sc2ai/protocol/debug.proto +127 -0
  7. data/data/sc2ai/protocol/error.proto +221 -0
  8. data/data/sc2ai/protocol/query.proto +55 -0
  9. data/data/sc2ai/protocol/raw.proto +202 -0
  10. data/data/sc2ai/protocol/sc2api.proto +718 -0
  11. data/data/sc2ai/protocol/score.proto +108 -0
  12. data/data/sc2ai/protocol/spatial.proto +115 -0
  13. data/data/sc2ai/protocol/ui.proto +145 -0
  14. data/data/setup/setup.SC2Map +0 -0
  15. data/data/setup/setup.SC2Replay +0 -0
  16. data/data/stableid.json +35730 -0
  17. data/data/versions.json +554 -0
  18. data/exe/sc2ai +35 -0
  19. data/lib/docker_build/Dockerfile.ruby +74 -0
  20. data/lib/docker_build/docker-compose-base-image.yml +10 -0
  21. data/lib/docker_build/docker-compose-ladderzip.yml +9 -0
  22. data/lib/sc2ai/api/ability_id.rb +1644 -0
  23. data/lib/sc2ai/api/buff_id.rb +306 -0
  24. data/lib/sc2ai/api/data.rb +101 -0
  25. data/lib/sc2ai/api/effect_id.rb +20 -0
  26. data/lib/sc2ai/api/tech_tree.rb +83 -0
  27. data/lib/sc2ai/api/tech_tree_data.rb +2338 -0
  28. data/lib/sc2ai/api/unit_type_id.rb +2022 -0
  29. data/lib/sc2ai/api/upgrade_id.rb +310 -0
  30. data/lib/sc2ai/cli/cli.rb +175 -0
  31. data/lib/sc2ai/cli/ladderzip.rb +154 -0
  32. data/lib/sc2ai/cli/new.rb +88 -0
  33. data/lib/sc2ai/configuration.rb +145 -0
  34. data/lib/sc2ai/connection/connection_listener.rb +30 -0
  35. data/lib/sc2ai/connection/requests.rb +417 -0
  36. data/lib/sc2ai/connection/status_listener.rb +15 -0
  37. data/lib/sc2ai/connection.rb +146 -0
  38. data/lib/sc2ai/local_play/client/configurable_options.rb +115 -0
  39. data/lib/sc2ai/local_play/client.rb +159 -0
  40. data/lib/sc2ai/local_play/client_manager.rb +70 -0
  41. data/lib/sc2ai/local_play/map_file.rb +48 -0
  42. data/lib/sc2ai/local_play/match.rb +184 -0
  43. data/lib/sc2ai/overrides/array.rb +14 -0
  44. data/lib/sc2ai/overrides/async/process/child.rb +31 -0
  45. data/lib/sc2ai/overrides/kernel.rb +33 -0
  46. data/lib/sc2ai/paths.rb +294 -0
  47. data/lib/sc2ai/player/actions.rb +386 -0
  48. data/lib/sc2ai/player/debug.rb +224 -0
  49. data/lib/sc2ai/player/game_state.rb +131 -0
  50. data/lib/sc2ai/player/geometry.rb +766 -0
  51. data/lib/sc2ai/player/previous_state.rb +49 -0
  52. data/lib/sc2ai/player/units.rb +337 -0
  53. data/lib/sc2ai/player.rb +661 -0
  54. data/lib/sc2ai/ports.rb +152 -0
  55. data/lib/sc2ai/protocol/_meta_documentation.rb +39 -0
  56. data/lib/sc2ai/protocol/common_pb.rb +43 -0
  57. data/lib/sc2ai/protocol/data_pb.rb +47 -0
  58. data/lib/sc2ai/protocol/debug_pb.rb +56 -0
  59. data/lib/sc2ai/protocol/error_pb.rb +36 -0
  60. data/lib/sc2ai/protocol/extensions/color.rb +20 -0
  61. data/lib/sc2ai/protocol/extensions/point.rb +23 -0
  62. data/lib/sc2ai/protocol/extensions/point_2_d.rb +26 -0
  63. data/lib/sc2ai/protocol/extensions/position.rb +202 -0
  64. data/lib/sc2ai/protocol/extensions/power_source.rb +19 -0
  65. data/lib/sc2ai/protocol/extensions/unit.rb +489 -0
  66. data/lib/sc2ai/protocol/query_pb.rb +47 -0
  67. data/lib/sc2ai/protocol/raw_pb.rb +57 -0
  68. data/lib/sc2ai/protocol/sc2api_pb.rb +130 -0
  69. data/lib/sc2ai/protocol/score_pb.rb +40 -0
  70. data/lib/sc2ai/protocol/spatial_pb.rb +48 -0
  71. data/lib/sc2ai/protocol/ui_pb.rb +56 -0
  72. data/lib/sc2ai/unit_group/action_ext.rb +74 -0
  73. data/lib/sc2ai/unit_group/filter_ext.rb +379 -0
  74. data/lib/sc2ai/unit_group.rb +277 -0
  75. data/lib/sc2ai/version.rb +2 -1
  76. data/lib/sc2ai.rb +93 -2
  77. data/lib/templates/ladderzip/bin/ladder.tt +23 -0
  78. data/lib/templates/new/.ladderignore +20 -0
  79. data/lib/templates/new/Gemfile.tt +7 -0
  80. data/lib/templates/new/api/common.proto +59 -0
  81. data/lib/templates/new/api/data.proto +120 -0
  82. data/lib/templates/new/api/debug.proto +127 -0
  83. data/lib/templates/new/api/error.proto +221 -0
  84. data/lib/templates/new/api/query.proto +55 -0
  85. data/lib/templates/new/api/raw.proto +202 -0
  86. data/lib/templates/new/api/sc2api.proto +718 -0
  87. data/lib/templates/new/api/score.proto +108 -0
  88. data/lib/templates/new/api/spatial.proto +115 -0
  89. data/lib/templates/new/api/ui.proto +145 -0
  90. data/lib/templates/new/boot.rb.tt +6 -0
  91. data/lib/templates/new/my_bot.rb.tt +23 -0
  92. data/lib/templates/new/run_example_match.rb.tt +14 -0
  93. data/sc2ai.gemspec +80 -0
  94. metadata +344 -13
@@ -0,0 +1,386 @@
1
+ module Sc2
2
+ class Player
3
+ # Holds action list and queues batch
4
+ module Actions
5
+ # Holds actions which will be queued off each time we step forward
6
+ # @!attribute action_queue
7
+ # @return [Array<Api::Action>]
8
+ attr_accessor :action_queue
9
+
10
+ # Queues action for performing end of step
11
+ # @param action [Api::Action]
12
+ # @return [void]
13
+ def queue_action(action)
14
+ @action_queue << action
15
+ end
16
+
17
+ # Queues a Api::ActionRaw. Perform ability on unit_tags optionally on target_world_space_pos/target_unit_tag
18
+ # @param unit_tags [Array<Integer>]
19
+ # @param ability_id [Integer]
20
+ # @param queue_command [Boolean] Shift+Click, default: false
21
+ # @param target_world_space_pos [Api::Point2D]
22
+ # @param target_unit_tag [Integer]
23
+ def action_raw_unit_command(unit_tags:, ability_id:, queue_command: false, target_world_space_pos: nil, target_unit_tag: nil)
24
+ queue_action Api::Action.new(
25
+ action_raw: Api::ActionRaw.new(
26
+ unit_command: Api::ActionRawUnitCommand.new(
27
+ unit_tags: unit_tags,
28
+ ability_id: ability_id,
29
+ queue_command: queue_command,
30
+ target_world_space_pos: target_world_space_pos,
31
+ target_unit_tag: target_unit_tag
32
+ )
33
+ )
34
+ )
35
+ end
36
+
37
+ # Queues a Api::ActionRawUnitCommand.
38
+ # Send accepts a Api::Unit, tag or tags and targets Api::Point2D or unit.tag
39
+ # @param units [Array<Integer>,Integer,Api::Unit] can be an Api::Unit, array of Api::Unit#tag or single tag
40
+ # @param ability_id [Integer]
41
+ # @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
42
+ # @param queue_command [Boolean] Shift+Click, default: false
43
+ def action(units:, ability_id:, target: nil, queue_command: false)
44
+ unit_tags = unit_tags_from_source(units)
45
+
46
+ target_pos = nil
47
+ target_unit_tag = nil
48
+ if target.is_a? Api::Point2D
49
+ target_pos = target
50
+ elsif target.is_a? Api::Unit
51
+ target_unit_tag = target.tag
52
+ else
53
+ target_unit_tag = target
54
+ end
55
+
56
+ # noinspection RubyMismatchedArgumentType
57
+ action_raw_unit_command(
58
+ unit_tags: unit_tags,
59
+ ability_id: ability_id,
60
+ queue_command: queue_command,
61
+ target_world_space_pos: target_pos,
62
+ target_unit_tag: target_unit_tag
63
+ )
64
+ end
65
+
66
+ # Builds target unit type using units as source at optional target
67
+ # @param unit_type_id [Integer] Api::UnitTypeId the unit type which will do the creation
68
+ # @param target [Api::Point2D, Integer, nil] is a unit tag or a Api::Point2D. Nil for addons/orbital
69
+ # @param queue_command [Boolean] shift+command
70
+ def build(units:, unit_type_id:, target: nil, queue_command: false)
71
+ # Get build ability from target building type
72
+ action(units:,
73
+ ability_id: unit_data(unit_type_id).ability_id,
74
+ target:,
75
+ queue_command:)
76
+ subtract_cost(unit_type_id)
77
+ end
78
+
79
+ # Warps in unit type at target (location or pylon) with optional source units (warp gates)
80
+ # When not specifying the specific warp gate(s), all warpgates will be used
81
+ # @param unit_type_id [Integer] Api::UnitTypeId the unit type which will do the creation
82
+ # @param target [Api::Point2D, Integer] is a unit tag or a Api::Point2D
83
+ def warp(unit_type_id:, target:, queue_command:, units: nil)
84
+ warp_ability = Api::TechTree.unit_type_creation_abilities(
85
+ source: Api::UnitTypeId::WARPGATE,
86
+ target: unit_type_id
87
+ )
88
+ units = structures.warpgates if units.nil?
89
+ action(units: units,
90
+ ability_id: warp_ability[:ability],
91
+ target:,
92
+ queue_command:)
93
+ subtract_cost(unit_type_id)
94
+ end
95
+
96
+ # Toggles auto-cast ability for units
97
+ # @param units [Array<Integer>, Integer, Api::Unit] can be an Api::Unit, array of Tags or single Tag
98
+ # @param ability_id [Integer]
99
+ # @return [void]
100
+ def action_raw_toggle_autocast(units:, ability_id:)
101
+ unit_tags = unit_tags_from_source(units)
102
+ queue_action Api::Action.new(
103
+ action_raw: Api::ActionRaw.new(
104
+ toggle_autocast: Api::ActionRawToggleAutocast.new(
105
+ ability_id: ability_id,
106
+ unit_tags: unit_tags
107
+ )
108
+ )
109
+ )
110
+ end
111
+
112
+ # Toggles auto-cast ability for units
113
+ # @param point [Api::Point]
114
+ # @return [void]
115
+ def action_raw_camera_move(point:)
116
+ queue_action Api::Action.new(
117
+ action_raw: Api::ActionRaw.new(
118
+ camera_move: Api::ActionRawCameraMove.new(
119
+ center_world_space: point
120
+ )
121
+ )
122
+ )
123
+ end
124
+
125
+ # ActionSpatial - Feature layer --------
126
+
127
+ # Issues spatial unit command. Target is either target_screen_coord or target_minimap_coord.
128
+ # @param ability_id [Api::AbilityId]
129
+ # @param target_screen_coord [Api::Point2I]
130
+ # @param target_minimap_coord [Api::Point2I]
131
+ # @param queue_command [Boolean] Shift+Click, default: false
132
+ # @return [void]
133
+ def action_spatial_unit_command(ability_id:, target_screen_coord: nil, target_minimap_coord: nil, queue_command: false)
134
+ queue_action Api::Action.new(
135
+ action_raw: Api::ActionSpatial.new(
136
+ unit_command: Api::ActionSpatialUnitCommand.new(
137
+ ability_id: ability_id,
138
+ target_screen_coord: target_screen_coord,
139
+ target_minimap_coord: target_minimap_coord,
140
+ queue_command: queue_command
141
+ )
142
+ )
143
+ )
144
+ end
145
+
146
+ # Simulates a click on the minimap to move the camera.
147
+ # @param center_minimap [Api::Point2I]
148
+ # @return [void]
149
+ #
150
+ def action_spatial_camera_move(center_minimap:)
151
+ queue_action Api::Action.new(
152
+ action_feature_layer: Api::ActionSpatial.new(
153
+ camera_move: Api::ActionSpatialCameraMove.new(
154
+ center_minimap: center_minimap
155
+ )
156
+ )
157
+ )
158
+ end
159
+
160
+ # Issues spatial unit select point command. Target is either target_screen_coord or target_minimap_coord.
161
+ # @param type [Integer] 1,2,3,4 = Api::ActionSpatialUnitSelectionPoint::Type::*
162
+ # enum Type {
163
+ # Select = 1; // Equivalent to normal click. Changes selection to unit.
164
+ # Toggle = 2; // Equivalent to shift+click. Toggle selection of unit.
165
+ # AllType = 3; // Equivalent to control+click. Selects all units of a given type.
166
+ # AddAllType = 4; // Equivalent to shift+control+click. Selects all units of a given type.
167
+ # }
168
+ # @param selection_screen_coord [Api::PointI]
169
+ # @return [void]
170
+ def action_spatial_unit_selection_point(type: Api::ActionSpatialUnitSelectionPoint::Type::Select, selection_screen_coord: nil)
171
+ queue_action Api::Action.new(
172
+ action_feature_layer: Api::ActionSpatial.new(
173
+ unit_selection_point: Api::ActionSpatialUnitSelectionPoint.new(
174
+ type: type,
175
+ selection_screen_coord: selection_screen_coord
176
+ )
177
+ )
178
+ )
179
+ end
180
+
181
+ # Issue rectangle select
182
+ # @param selection_screen_coord [Api::RectangleI] rectangle coordinates
183
+ # @param selection_add [Boolean] default false Equivalent to shift+drag. Adds units to selection. default false
184
+ # @return [void]
185
+ def action_spatial_unit_selection_rect(selection_screen_coord:, selection_add: false)
186
+ queue_action Api::Action.new(
187
+ action_feature_layer: Api::ActionSpatial.new(
188
+ unit_selection_rect: Api::ActionSpatialUnitSelectionRect.new(
189
+ selection_screen_coord: selection_screen_coord,
190
+ selection_add: selection_add
191
+ )
192
+ )
193
+ )
194
+ end
195
+
196
+ # ActionUI - Feature layer --------
197
+
198
+ # Perform action on control group like setting or recalling, use in conjunction with unit selection.
199
+ # Populated if Feature Layer or Render interface is enabled.
200
+ # @param action [Integer] 1-5 = Api::ActionControlGroup::ControlGroupAction::*
201
+ # enum ControlGroupAction {
202
+ # Recall = 1; // Equivalent to number hotkey. Replaces current selection with control group.
203
+ # Set = 2; // Equivalent to Control + number hotkey. Sets control group to current selection.
204
+ # Append = 3; // Equivalent to Shift + number hotkey. Adds current selection into control group.
205
+ # SetAndSteal = 4; // Equivalent to Control + Alt + number hotkey. Sets control group to current selection. Units are removed from other control groups.
206
+ # AppendAndSteal = 5; // Equivalent to Shift + Alt + number hotkey. Adds current selection into control group. Units are removed from other control groups.
207
+ # }
208
+ # @param control_group_index [Integer] 0-9
209
+ # @return [void]
210
+ def action_ui_control_group(action:, control_group_index:)
211
+ queue_action Api::Action.new(
212
+ action_ui: Api::ActionUI.new(
213
+ control_group: Api::ActionControlGroup.new(
214
+ action: action,
215
+ control_group_index: control_group_index
216
+ )
217
+ )
218
+ )
219
+ end
220
+
221
+ # Selects army (F2)
222
+ # @param selection_add [Boolean] default false To add to other selected items
223
+ # @return [void]
224
+ def action_ui_select_army(selection_add: false)
225
+ queue_action Api::Action.new(
226
+ action_ui: Api::ActionUI.new(
227
+ select_army: Api::ActionSelectArmy.new(
228
+ selection_add: selection_add
229
+ )
230
+ )
231
+ )
232
+ end
233
+
234
+ # Selects warp gates (Protoss)
235
+ # @param selection_add [Boolean] default false To add to other selected items
236
+ # @return [void]
237
+ def action_ui_select_warp_gates(selection_add: false)
238
+ queue_action Api::Action.new(
239
+ action_ui: Api::ActionUI.new(
240
+ select_warp_gates: Api::ActionSelectWarpGates.new(
241
+ selection_add: selection_add
242
+ )
243
+ )
244
+ )
245
+ end
246
+
247
+ # Selects larva (Zerg)
248
+ # @return [void]
249
+ def action_ui_select_larva
250
+ queue_action Api::Action.new(
251
+ action_ui: Api::ActionUI.new(
252
+ select_larva: Api::ActionSelectLarva.new
253
+ )
254
+ )
255
+ end
256
+
257
+ # Select idle workers
258
+ # @param type [Integer] 1-4 = Api::ActionSelectIdleWorker::Type::*
259
+ #
260
+ # enum Type {
261
+ # Set = 1; // Equivalent to click with no modifiers. Replaces selection with single idle worker.
262
+ # Add = 2; // Equivalent to shift+click. Adds single idle worker to current selection.
263
+ # All = 3; // Equivalent to control+click. Selects all idle workers.
264
+ # AddAll = 4; // Equivalent to shift+control+click. Adds all idle workers to current selection.
265
+ # }
266
+ def action_ui_select_idle_worker(type:)
267
+ queue_action Api::Action.new(
268
+ action_ui: Api::ActionUI.new(
269
+ select_idle_worker: Api::ActionSelectIdleWorker.new(
270
+ type: type
271
+ )
272
+ )
273
+ )
274
+ end
275
+
276
+ # Multi-panel actions for select/deselect
277
+ # @param type [Integer] 1-4 = Api::ActionMultiPanel::Type::*
278
+ # @param unit_index [Integer] n'th unit on panel
279
+ # enum Type {
280
+ # SingleSelect = 1; // Click on icon
281
+ # DeselectUnit = 2; // Shift Click on icon
282
+ # SelectAllOfType = 3; // Control Click on icon.
283
+ # DeselectAllOfType = 4; // Control+Shift Click on icon.
284
+ # }
285
+ # message ActionMultiPanel {
286
+ # optional Type type = 1;
287
+ # optional int32 unit_index = 2;
288
+ # }
289
+ def action_ui_multi_panel(type:, unit_index:)
290
+ queue_action Api::Action.new(
291
+ action_ui: Api::ActionUI.new(
292
+ multi_panel: Api::ActionMultiPanel.new(
293
+ type: type,
294
+ unit_index: unit_index
295
+ )
296
+ )
297
+ )
298
+ end
299
+
300
+ # Cargo panel actions for unloading units.
301
+ # @param unit_index [Integer] index of unit to unload
302
+ def action_ui_cargo_panel_unload(unit_index:)
303
+ queue_action Api::Action.new(
304
+ action_ui: Api::ActionUI.new(
305
+ cargo_panel: Api::ActionCargoPanelUnload.new(
306
+ unit_index: unit_index
307
+ )
308
+ )
309
+ )
310
+ end
311
+
312
+ # Remove unit from production queue
313
+ # @param unit_index [Integer] target unit index
314
+ def action_ui_production_panel_remove_from_queue(unit_index:)
315
+ queue_action Api::Action.new(
316
+ action_ui: Api::ActionUI.new(
317
+ production_panel: Api::ActionProductionPanelRemoveFromQueue.new(
318
+ unit_index: unit_index
319
+ )
320
+ )
321
+ )
322
+ end
323
+
324
+ # Toggle autocast on selected unit. Also possible with raw actions using a unit target.
325
+ # @param ability_id [Integer] Api::AbilityId::* ability
326
+ def action_ui_toggle_autocast(ability_id:)
327
+ queue_action Api::Action.new(
328
+ action_ui: Api::ActionUI.new(
329
+ toggle_autocast: Api::ActionToggleAutocast.new(
330
+ unit_index: ability_id
331
+ )
332
+ )
333
+ )
334
+ end
335
+
336
+ # Generic --------
337
+
338
+ # Send a chat message
339
+ # @param message [String] to send
340
+ # @param channel [Integer] 1-2, default:Team Api::ActionChat::Channel::Broadcast = 1, Api::ActionChat::Channel::Team = 2
341
+ def action_chat(message, channel: Api::ActionChat::Channel::Team)
342
+ queue_action Api::Action.new(
343
+ action_chat: Api::ActionChat.new(
344
+ channel: channel,
345
+ message: message.to_s
346
+ )
347
+ )
348
+ end
349
+
350
+ private
351
+
352
+ # Sends actions via api and flushes action_queue
353
+ def perform_actions
354
+ # request_actions = []
355
+ # @action_queue.each do |queue_type, actions|
356
+ # request_actions.push(actions)
357
+ # end
358
+
359
+ @api.action(@action_queue) unless @action_queue.empty?
360
+ clear_action_queue
361
+ end
362
+
363
+ # Empties and resets @action_queue
364
+ # @return [void]
365
+ def clear_action_queue
366
+ @action_queue = []
367
+ # TYPES.each do |type|
368
+ # @action_queue[type] = []
369
+ # end
370
+ end
371
+
372
+ # Returns an array of unit tags from a variety of sources
373
+ # @param source [Integer, Array<Integer>, Api::Unit, Sc2::UnitGroup] unit tag, tags, unit or unit group
374
+ # @return [Array<Integer>] unit tag array
375
+ # noinspection RubyMismatchedReturnType
376
+ def unit_tags_from_source(source)
377
+ return [] if source.nil?
378
+ return [source.tag] if source.is_a? Api::Unit
379
+ return source.tags if source.is_a? Sc2::UnitGroup
380
+ return [source] unless source.is_a? Array
381
+
382
+ source
383
+ end
384
+ end
385
+ end
386
+ end
@@ -0,0 +1,224 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sc2
4
+ class Player
5
+ # WARNING! Debug methods will not be available on Ladder
6
+ # This provides debug helper functions for RequestDebug
7
+ module Debug
8
+ # Holds debug commands which will be queued off each time we step forward
9
+ # @!attribute debug_commands_queue
10
+ # @return [Array<Api::Action>]
11
+ attr_accessor :debug_command_queue
12
+
13
+ # Queues debug command for performing later
14
+ # @param debug_command [Api::DebugCommand]
15
+ # @return [void]
16
+ def queue_debug_command(debug_command)
17
+ @debug_command_queue << debug_command
18
+ end
19
+
20
+ # Draw Commands ---
21
+
22
+ # Prints debug text top left corner
23
+ # @param text [String] will respect newlines
24
+ # @param size [Size] of font, default 14px
25
+ # @return [void]
26
+ def debug_print(text, size: 14)
27
+ queue_debug_command Api::DebugCommand.new(
28
+ draw: Api::DebugDraw.new(
29
+ text: [
30
+ Api::DebugText.new(
31
+ text:,
32
+ size:,
33
+ virtual_pos: Api::Point.new(x: 0.01, y: 0.01) # unit or fixed position.
34
+ )
35
+ ]
36
+ )
37
+ )
38
+ end
39
+
40
+ # Draws a line between two Api::Point's for color
41
+ # @param p0 [Api::Point] the first point
42
+ # @param p1 [Api::Point] the second point
43
+ # @param color [Api::Color] default white
44
+ # @return [void]
45
+ def debug_draw_line(p0:, p1:, color: nil)
46
+ queue_debug_command Api::DebugCommand.new(
47
+ draw: Api::DebugDraw.new(
48
+ lines: [
49
+ Api::DebugLine.new(
50
+ color:,
51
+ line: Api::Line.new(
52
+ p0:,
53
+ p1:
54
+ )
55
+ )
56
+ ]
57
+ )
58
+ )
59
+ end
60
+
61
+ # Draws a box around position xy at base of z. Good for structure boxing.
62
+ # @example
63
+ # # Draws a box on structure placement grid
64
+ # debug_draw_box(point: unit.pos, radius: unit.footprint_radius)
65
+ #
66
+ # Note: Api::Color RGB is broken for this command. Will use min(r,b)
67
+ # Note: Z index is elevated 0.01 so the line is visible and doesn't clip through terrain
68
+ # @param point [Api::Point]
69
+ # @param radius [Float] default one tile wide, 1.0
70
+ # @param color [Api::Color] default white. min(r,b) is used for both r&b
71
+ # @return [void]
72
+ def debug_draw_box(point:, radius: 0.5, color: nil)
73
+ queue_debug_command Api::DebugCommand.new(
74
+ draw: Api::DebugDraw.new(
75
+ boxes: [
76
+ Api::DebugBox.new(
77
+ min: Api::Point.new(x: point.x - radius, y: point.y - radius, z: point.z + 0.01),
78
+ max: Api::Point.new(x: point.x + radius, y: point.y + radius, z: point.z + (radius * 2) + 0.01),
79
+ color:
80
+ )
81
+ ]
82
+ )
83
+ )
84
+ end
85
+
86
+ # Debug draws a sphere at position with a radius in color
87
+ # @param point [Api::Point]
88
+ # @param radius [Float] default one tile wide, 1.0
89
+ # @param color [Api::Color] default white. min(r,b) is used for both r&b
90
+ # @return [void]
91
+ def debug_draw_sphere(point:, radius: 1.0, color: nil)
92
+ queue_debug_command Api::DebugCommand.new(
93
+ draw: Api::DebugDraw.new(
94
+ spheres: [
95
+ Api::DebugSphere.new(
96
+ p: point,
97
+ r: radius,
98
+ color:
99
+ )
100
+ ]
101
+ )
102
+ )
103
+ end
104
+
105
+ # Other Commands ---
106
+
107
+ # Toggles cheat commands on/off (send only once to enable)
108
+ # @param command [Integer] one of Api::DebugGameState::*
109
+ # Possible values:
110
+ # Api::DebugGameState::Show_map
111
+ # Api::DebugGameState::Control_enemy
112
+ # Api::DebugGameState::Food
113
+ # Api::DebugGameState::Free
114
+ # Api::DebugGameState::all_resources
115
+ # Api::DebugGameState::God
116
+ # Api::DebugGameState::Minerals
117
+ # Api::DebugGameState::Gas
118
+ # Api::DebugGameState::Cooldown
119
+ # Api::DebugGameState::Tech_tree
120
+ # Api::DebugGameState::Upgrade
121
+ # Api::DebugGameState::Fast_build
122
+ # @return [void]
123
+ def debug_game_state(command)
124
+ queue_debug_command Api::DebugCommand.new(
125
+ game_state: command
126
+ )
127
+ end
128
+
129
+ # Spawns a quantity of units under an owner at position given
130
+ # @param unit_type_id [Integer] Api::UnitTypeId::*
131
+ # @param owner [Integer] typically you are 1 and 2 is enemy (see @common.player_id)
132
+ # @param pos [Api::Point2D] position in 2d
133
+ # @param quantity [Integer] default 1
134
+ # @return [void]
135
+ def debug_create_unit(unit_type_id:, owner:, pos:, quantity: 1)
136
+ queue_debug_command Api::DebugCommand.new(
137
+ create_unit: Api::DebugCreateUnit.new(
138
+ unit_type: unit_type_id,
139
+ owner:,
140
+ pos:,
141
+ quantity:
142
+ )
143
+ )
144
+ end
145
+
146
+ # Kills a target unit or unit tag
147
+ # @param unit_tags [Integer, Array<Integer>] one or many unit tags to kill
148
+ # @return [void]
149
+ def debug_kill_unit(unit_tags:)
150
+ unit_tags = [unit_tags] if unit_tags.is_a? Integer
151
+ queue_debug_command Api::DebugCommand.new(
152
+ kill_unit: Api::DebugKillUnit.new(
153
+ tag: unit_tags
154
+ )
155
+ )
156
+ end
157
+
158
+ # @private
159
+ # Hangs, crashes and exits the Sc2 client. DO NOT USE.
160
+ # @param test [Integer] one of Api::DebugTestProcess::Test::Crash, Api::DebugTestProcess::Test::Hang, Api::DebugTestProcess::Test::Exit
161
+ # @param delay_ms [Integer] default 0, how long this test is delayed
162
+ # @return [void]
163
+ def debug_test_process(test:, delay_ms: 0)
164
+ queue_debug_command Api::DebugCommand.new(
165
+ test_process: Api::DebugTestProcess.new(
166
+ test:,
167
+ delay_ms:
168
+ )
169
+ )
170
+ end
171
+
172
+ # @private
173
+ # Useful only for single-player "curriculum" maps
174
+ # @param score [Float] sets the score
175
+ def debug_set_score(score: 0.0)
176
+ queue_debug_command Api::DebugCommand.new(
177
+ score: Api::DebugSetScore.new(
178
+ score:
179
+ )
180
+ )
181
+ end
182
+
183
+ # Ends game with a specified result of either Surrender or DeclareVictory
184
+ # @param end_result [Integer] either 1/2. Api::DebugEndGame::EndResult::Surrender or Api::DebugEndGame::EndResult::DeclareVictory
185
+ # @return [void]
186
+ def debug_end_game(end_result:)
187
+ queue_debug_command Api::DebugCommand.new(
188
+ end_game: Api::DebugEndGame.new(
189
+ end_result:
190
+ )
191
+ )
192
+ end
193
+
194
+ # Sets unit_value Energy, Life or Shields for a specific unit tag to given value
195
+ # @param unit_tag [Integer]
196
+ # @param unit_value [Integer] 1=Energy,2=Life,3=Shields one of Api::DebugSetUnitValue::UnitValue::*
197
+ # @param value [Float] the value which the attribute will be set to
198
+ # @return [void]
199
+ def debug_set_unit_value(unit_tag:, unit_value:, value:)
200
+ queue_debug_command Api::DebugCommand.new(
201
+ unit_value: Api::DebugSetUnitValue.new(
202
+ unit_tag:,
203
+ unit_value:, # property
204
+ value: # value
205
+ )
206
+ )
207
+ end
208
+
209
+ private
210
+
211
+ # Sends actions via api and flushes debug_commands_queue
212
+ def perform_debug_commands
213
+ @api.debug(@debug_command_queue) unless @debug_command_queue.empty?
214
+ clear_debug_command_queue
215
+ end
216
+
217
+ # Empties and resets @debug_queue
218
+ # @return [void]
219
+ def clear_debug_command_queue
220
+ @debug_command_queue = []
221
+ end
222
+ end
223
+ end
224
+ end