Module: Sc2::Player::Debug
- Included in:
- Bot
- Defined in:
- lib/sc2ai/player/debug.rb
Overview
WARNING! Debug methods will not be available on Ladder This provides debug helper functions for RequestDebug
Instance Attribute Summary collapse
-
#debug_command_queue ⇒ Object
Holds debug commands which will be queued off each time we step forward.
- #debug_commands_queue ⇒ Array<Api::Action>
Instance Method Summary collapse
-
#debug_create_unit(unit_type_id:, owner:, pos:, quantity: 1) ⇒ void
Spawns a quantity of units under an owner at position given.
-
#debug_draw_box(point:, radius: 0.5, color: nil) ⇒ void
Draws a box around position xy at base of z.
-
#debug_draw_line(p0:, p1:, color: nil) ⇒ void
Draws a line between two Api::Point’s for color.
-
#debug_draw_sphere(point:, radius: 1.0, color: nil) ⇒ void
Debug draws a sphere at position with a radius in color.
-
#debug_end_game(end_result:) ⇒ void
Ends game with a specified result of either :SURRENDER or :DECLARE_VICTORY.
-
#debug_game_state(command) ⇒ void
Possible values: Api::DebugGameState::SHOW_MAP Api::DebugGameState::CONTROL_ENEMY Api::DebugGameState::FOOD Api::DebugGameState::FREE Api::DebugGameState::ALL_RESOURCES Api::DebugGameState::GOD Api::DebugGameState::MINERALS Api::DebugGameState::GAS Api::DebugGameState::COOLDOWN Api::DebugGameState::TECH_TREE Api::DebugGameState::UPGRADE Api::DebugGameState::FAST_BUILD.
-
#debug_kill_unit(unit_tags:) ⇒ void
Kills a target unit or unit tag.
-
#debug_print(text, size: 14) ⇒ void
Prints debug text top left corner.
-
#debug_set_score(score: 0.0) ⇒ Object
Useful only for single-player “curriculum” maps.
-
#debug_set_unit_value(unit_tag:, unit_value:, value:) ⇒ void
Sets unit_value Energy, Life or Shields for a specific unit tag to given value.
-
#debug_test_process(test:, delay_ms: 0) ⇒ void
Hangs, crashes and exits the Sc2 client.
-
#debug_text_screen(text, left_percent: 1.0, top_percent: 1.0, color: nil, size: 14) ⇒ void
Prints text on screen from top and left.
-
#debug_text_world(text, point:, color: nil, size: 14) ⇒ void
Prints text on screen at 3d world position.
-
#debug_tile(pos = nil, x: nil, y: nil, color: nil, indent: 0.05) ⇒ Object
Renders a block on the floor, drawn by 4 lines Pass in either a pos (Position/Unit) or exact x * y coordinates Optional indentation adds padding on borders inward.
-
#queue_debug_command(debug_command) ⇒ void
Queues debug command for performing later.
Instance Attribute Details
#debug_command_queue ⇒ Object
Holds debug commands which will be queued off each time we step forward
11 12 13 |
# File 'lib/sc2ai/player/debug.rb', line 11 def debug_command_queue @debug_command_queue end |
#debug_commands_queue ⇒ Array<Api::Action>
11 |
# File 'lib/sc2ai/player/debug.rb', line 11 attr_accessor :debug_command_queue |
Instance Method Details
#debug_create_unit(unit_type_id:, owner:, pos:, quantity: 1) ⇒ void
This method returns an undefined value.
Spawns a quantity of units under an owner at position given
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/sc2ai/player/debug.rb', line 215 def debug_create_unit(unit_type_id:, owner:, pos:, quantity: 1) queue_debug_command Api::DebugCommand.new( create_unit: Api::DebugCreateUnit.new( unit_type: unit_type_id, owner:, pos:, quantity: ) ) end |
#debug_draw_box(point:, radius: 0.5, color: nil) ⇒ void
Api::Color RGB is broken for this command. Will use min(r,b)
Z index is elevated 0.02 so the line is visible and doesn’t clip through terrain
This method returns an undefined value.
Draws a box around position xy at base of z. Good for structure boxing.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/sc2ai/player/debug.rb', line 119 def debug_draw_box(point:, radius: 0.5, color: nil) queue_debug_command Api::DebugCommand.new( draw: Api::DebugDraw.new( boxes: [ Api::DebugBox.new( min: Api::Point.new(x: point.x - radius, y: point.y - radius, z: point.z + 0.03), max: Api::Point.new(x: point.x + radius, y: point.y + radius, z: point.z + (radius * 2) + 0.03), color: ) ] ) ) end |
#debug_draw_line(p0:, p1:, color: nil) ⇒ void
This method returns an undefined value.
Draws a line between two Api::Point’s for color
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sc2ai/player/debug.rb', line 92 def debug_draw_line(p0:, p1:, color: nil) queue_debug_command Api::DebugCommand.new( draw: Api::DebugDraw.new( lines: [ Api::DebugLine.new( color:, line: Api::Line.new( p0:, p1: ) ) ] ) ) end |
#debug_draw_sphere(point:, radius: 1.0, color: nil) ⇒ void
This method returns an undefined value.
Debug draws a sphere at position with a radius in color
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/sc2ai/player/debug.rb', line 138 def debug_draw_sphere(point:, radius: 1.0, color: nil) queue_debug_command Api::DebugCommand.new( draw: Api::DebugDraw.new( spheres: [ Api::DebugSphere.new( p: point, r: radius, color: ) ] ) ) end |
#debug_end_game(end_result:) ⇒ void
This method returns an undefined value.
Ends game with a specified result of either :SURRENDER or :DECLARE_VICTORY
266 267 268 269 270 271 272 |
# File 'lib/sc2ai/player/debug.rb', line 266 def debug_end_game(end_result:) queue_debug_command Api::DebugCommand.new( end_game: Api::DebugEndGame.new( end_result: ) ) end |
#debug_game_state(command) ⇒ void
This method returns an undefined value.
Possible values:
Api::DebugGameState::SHOW_MAP
Api::DebugGameState::CONTROL_ENEMY
Api::DebugGameState::FOOD
Api::DebugGameState::FREE
Api::DebugGameState::ALL_RESOURCES
Api::DebugGameState::GOD
Api::DebugGameState::MINERALS
Api::DebugGameState::GAS
Api::DebugGameState::COOLDOWN
Api::DebugGameState::TECH_TREE
Api::DebugGameState::UPGRADE
Api::DebugGameState::FAST_BUILD
203 204 205 206 207 |
# File 'lib/sc2ai/player/debug.rb', line 203 def debug_game_state(command) queue_debug_command Api::DebugCommand.new( game_state: command ) end |
#debug_kill_unit(unit_tags:) ⇒ void
This method returns an undefined value.
Kills a target unit or unit tag
229 230 231 232 233 234 235 236 |
# File 'lib/sc2ai/player/debug.rb', line 229 def debug_kill_unit(unit_tags:) = [] if .is_a? Integer queue_debug_command Api::DebugCommand.new( kill_unit: Api::DebugKillUnit.new( tag: ) ) end |
#debug_print(text, size: 14) ⇒ void
This method returns an undefined value.
Prints debug text top left corner
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sc2ai/player/debug.rb', line 27 def debug_print(text, size: 14) queue_debug_command Api::DebugCommand.new( draw: Api::DebugDraw.new( text: [ Api::DebugText.new( text:, size:, virtual_pos: Api::Point.new(x: 0.01, y: 0.01) # unit or fixed position. ) ] ) ) end |
#debug_set_score(score: 0.0) ⇒ Object
Useful only for single-player “curriculum” maps
255 256 257 258 259 260 261 |
# File 'lib/sc2ai/player/debug.rb', line 255 def debug_set_score(score: 0.0) queue_debug_command Api::DebugCommand.new( score: Api::DebugSetScore.new( score: ) ) end |
#debug_set_unit_value(unit_tag:, unit_value:, value:) ⇒ void
This method returns an undefined value.
Sets unit_value Energy, Life or Shields for a specific unit tag to given value
279 280 281 282 283 284 285 286 287 |
# File 'lib/sc2ai/player/debug.rb', line 279 def debug_set_unit_value(unit_tag:, unit_value:, value:) queue_debug_command Api::DebugCommand.new( unit_value: Api::DebugSetUnitValue.new( unit_tag:, unit_value:, # property value: # value ) ) end |
#debug_test_process(test:, delay_ms: 0) ⇒ void
This method returns an undefined value.
Hangs, crashes and exits the Sc2 client. DO NOT USE.
243 244 245 246 247 248 249 250 |
# File 'lib/sc2ai/player/debug.rb', line 243 def debug_test_process(test:, delay_ms: 0) queue_debug_command Api::DebugCommand.new( test_process: Api::DebugTestProcess.new( test:, delay_ms: ) ) end |
#debug_text_screen(text, left_percent: 1.0, top_percent: 1.0, color: nil, size: 14) ⇒ void
This method returns an undefined value.
Prints text on screen from top and left
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sc2ai/player/debug.rb', line 48 def debug_text_screen(text, left_percent: 1.0, top_percent: 1.0, color: nil, size: 14) queue_debug_command Api::DebugCommand.new( draw: Api::DebugDraw.new( text: [ Api::DebugText.new( text:, virtual_pos: Api::Point.new( x: left_percent.to_f / 100, y: top_percent.to_f / 100 ), color:, size: ) ] ) ) end |
#debug_text_world(text, point:, color: nil, size: 14) ⇒ void
This method returns an undefined value.
Prints text on screen at 3d world position
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sc2ai/player/debug.rb', line 72 def debug_text_world(text, point:, color: nil, size: 14) queue_debug_command Api::DebugCommand.new( draw: Api::DebugDraw.new( text: [ Api::DebugText.new( text:, world_pos: point, color:, size: ) ] ) ) end |
#debug_tile(pos = nil, x: nil, y: nil, color: nil, indent: 0.05) ⇒ Object
Renders a block on the floor, drawn by 4 lines Pass in either a pos (Position/Unit) or exact x * y coordinates Optional indentation adds padding on borders inward
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/sc2ai/player/debug.rb', line 164 def debug_tile(pos = nil, x: nil, y: nil, color: nil, indent: 0.05) if pos.is_a?(Api::Unit) x = pos.pos.x.floor y = pos.pos.y.floor elsif pos.is_a?(Sc2::Position) x = pos.x.floor y = pos.y.floor end # Raise above floor to prevent texture clipping z = geo.terrain_height(x:, y:).to_f + 0.1 tl = Api::Point[x + indent, y + 1.0 - indent, z] bl = Api::Point[x + indent, y + indent, z] br = Api::Point[x + 1.0 - indent, y + indent, z] tr = Api::Point[x + 1.0 - indent, y + 1.0 - indent, z] debug_draw_line(p0: tl, p1: bl, color:) debug_draw_line(p0: bl, p1: br, color:) debug_draw_line(p0: br, p1: tr, color:) debug_draw_line(p0: tr, p1: tl, color:) end |
#queue_debug_command(debug_command) ⇒ void
This method returns an undefined value.
Queues debug command for performing later
16 17 18 19 |
# File 'lib/sc2ai/player/debug.rb', line 16 def queue_debug_command(debug_command) @debug_command_queue ||= [] @debug_command_queue << debug_command end |