lib/sc2ai/player/debug.rb in sc2ai-0.1.0 vs lib/sc2ai/player/debug.rb in sc2ai-0.2.0
- old
+ new
@@ -119,12 +119,12 @@
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.02),
- max: Api::Point.new(x: point.x + radius, y: point.y + radius, z: point.z + (radius * 2) + 0.02),
+ 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:
)
]
)
)
@@ -145,9 +145,43 @@
color:
)
]
)
)
+ end
+
+ # 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
+ # @param pos [Api::Unit, Api::Position]
+ # @param x [Float, Integer]
+ # @param y [Float, Integer]
+ # @param color [Api::Color]
+ # @param indent [Float] default 0.05. should be lower than < 1.0
+ # @example
+ # debug_tile(x: 12.3, y: 4.56, color: Api::Color.new(r: 255, g: 0, b: 0))
+ # debug_tile(some_unit)
+ # debug_tile(some_unit.pos)
+ 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.pos.x.floor
+ y = pos.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
# Other Commands ---
# @param command [Integer] one of Api::DebugGameState::*