sc2ai 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/data/sc2ai/protocol/common.proto +5 -5
  3. data/data/sc2ai/protocol/data.proto +22 -22
  4. data/data/sc2ai/protocol/debug.proto +24 -24
  5. data/data/sc2ai/protocol/error.proto +216 -215
  6. data/data/sc2ai/protocol/raw.proto +20 -20
  7. data/data/sc2ai/protocol/sc2api.proto +111 -111
  8. data/data/sc2ai/protocol/score.proto +3 -3
  9. data/data/sc2ai/protocol/spatial.proto +5 -5
  10. data/data/sc2ai/protocol/ui.proto +16 -16
  11. data/exe/sc2ai +0 -3
  12. data/lib/docker_build/Dockerfile.ruby +2 -2
  13. data/lib/sc2ai/api/data.rb +3 -3
  14. data/lib/sc2ai/connection/connection_listener.rb +3 -3
  15. data/lib/sc2ai/connection/requests.rb +31 -35
  16. data/lib/sc2ai/connection/status_listener.rb +1 -1
  17. data/lib/sc2ai/connection.rb +2 -3
  18. data/lib/sc2ai/local_play/client/configurable_options.rb +6 -7
  19. data/lib/sc2ai/local_play/client.rb +3 -3
  20. data/lib/sc2ai/local_play/match.rb +7 -2
  21. data/lib/sc2ai/paths.rb +12 -2
  22. data/lib/sc2ai/player/actions.rb +54 -35
  23. data/lib/sc2ai/player/debug.rb +21 -21
  24. data/lib/sc2ai/player/game_state.rb +11 -18
  25. data/lib/sc2ai/player/geo.rb +54 -64
  26. data/lib/sc2ai/player/units.rb +16 -16
  27. data/lib/sc2ai/player.rb +103 -41
  28. data/lib/sc2ai/ports.rb +1 -1
  29. data/lib/sc2ai/protocol/_meta_documentation.rb +265 -265
  30. data/lib/sc2ai/protocol/common_pb.rb +3865 -15
  31. data/lib/sc2ai/protocol/data_pb.rb +9109 -18
  32. data/lib/sc2ai/protocol/debug_pb.rb +10437 -26
  33. data/lib/sc2ai/protocol/error_pb.rb +1086 -10
  34. data/lib/sc2ai/protocol/extensions/ability_remapable.rb +9 -9
  35. data/lib/sc2ai/protocol/extensions/action.rb +60 -0
  36. data/lib/sc2ai/protocol/extensions/point_2_d.rb +5 -0
  37. data/lib/sc2ai/protocol/extensions/position.rb +10 -35
  38. data/lib/sc2ai/protocol/extensions/power_source.rb +3 -0
  39. data/lib/sc2ai/protocol/extensions/unit.rb +19 -35
  40. data/lib/sc2ai/protocol/query_pb.rb +5025 -17
  41. data/lib/sc2ai/protocol/raw_pb.rb +18350 -27
  42. data/lib/sc2ai/protocol/sc2api_pb.rb +48420 -93
  43. data/lib/sc2ai/protocol/score_pb.rb +5968 -12
  44. data/lib/sc2ai/protocol/spatial_pb.rb +11944 -18
  45. data/lib/sc2ai/protocol/ui_pb.rb +12927 -28
  46. data/lib/sc2ai/unit_group/action_ext.rb +0 -2
  47. data/lib/sc2ai/unit_group/filter_ext.rb +10 -9
  48. data/lib/sc2ai/unit_group/geo_ext.rb +0 -2
  49. data/lib/sc2ai/unit_group.rb +1 -1
  50. data/lib/sc2ai/version.rb +2 -3
  51. data/lib/sc2ai.rb +10 -11
  52. data/lib/templates/ladderzip/bin/ladder.tt +0 -3
  53. data/lib/templates/new/api/common.proto +6 -6
  54. data/lib/templates/new/api/data.proto +23 -20
  55. data/lib/templates/new/api/debug.proto +25 -21
  56. data/lib/templates/new/api/error.proto +217 -215
  57. data/lib/templates/new/api/query.proto +1 -1
  58. data/lib/templates/new/api/raw.proto +16 -14
  59. data/lib/templates/new/api/sc2api.proto +108 -94
  60. data/lib/templates/new/api/score.proto +4 -3
  61. data/lib/templates/new/api/spatial.proto +6 -5
  62. data/lib/templates/new/api/ui.proto +17 -14
  63. data/lib/templates/new/boot.rb.tt +1 -1
  64. data/lib/templates/new/my_bot.rb.tt +1 -1
  65. data/lib/templates/new/run_example_match.rb.tt +2 -2
  66. data/sig/sc2ai.rbs +11008 -1929
  67. metadata +25 -36
  68. data/lib/sc2ai/overrides/kernel.rb +0 -33
  69. data/sig/minaswan.rbs +0 -10323
@@ -5,18 +5,18 @@ module Api
5
5
  # i.e. Api::AbilityId::ATTACK_BATTLECRUISER returns generic Api::AbilityId::ATTACK
6
6
  # @return [Integer]
7
7
  def ability_id
8
- @ability_id ||= Api::AbilityId.generic_id(send(:method_missing, :ability_id))
8
+ @_ability_id ||= Api::AbilityId.generic_id(@ability_id)
9
9
  end
10
10
  end
11
11
  end
12
12
 
13
13
  # AbilityData should not include, since it holds exact info and contains the remap id as attr
14
14
  # Similarly Request* methods only do requests and ew supply correct id's.
15
- Api::AvailableAbility.include Api::AbilityRemapable
16
- Api::UnitOrder.include Api::AbilityRemapable
17
- Api::ActionRawUnitCommand.include Api::AbilityRemapable
18
- Api::ActionRawToggleAutocast.include Api::AbilityRemapable
19
- Api::ActionError.include Api::AbilityRemapable
20
- Api::ActionSpatialUnitCommand.include Api::AbilityRemapable
21
- Api::BuildItem.include Api::AbilityRemapable
22
- Api::ActionToggleAutocast.include Api::AbilityRemapable
15
+ Api::AvailableAbility.prepend Api::AbilityRemapable
16
+ Api::UnitOrder.prepend Api::AbilityRemapable
17
+ Api::ActionRawUnitCommand.prepend Api::AbilityRemapable
18
+ Api::ActionRawToggleAutocast.prepend Api::AbilityRemapable
19
+ Api::ActionError.prepend Api::AbilityRemapable
20
+ Api::ActionSpatialUnitCommand.prepend Api::AbilityRemapable
21
+ Api::BuildItem.prepend Api::AbilityRemapable
22
+ Api::ActionToggleAutocast.prepend Api::AbilityRemapable
@@ -0,0 +1,60 @@
1
+ module Api
2
+ # Adds additional functionality and fixes quirks with color specifically pertaining to debug commands
3
+ module ActionExtension
4
+ # Checks the action type and returns corresponding class
5
+ # @return [Class] class of type, i.e. Api::ActionRaw
6
+ def action_type
7
+ @action_type ||= if has_action_raw?
8
+ Api::ActionRaw
9
+ elsif has_action_chat?
10
+ Api::ActionChat
11
+ elsif has_action_feature_layer?
12
+ Api::ActionSpatial
13
+ elsif has_action_ui?
14
+ Api::ActionUI
15
+ end
16
+ end
17
+
18
+ # Finds unit tags for action, if applicable
19
+ # @return [Array<Integer>] an array of unit tags
20
+ def unit_tags
21
+ tags = []
22
+ if action_type == Api::ActionRaw
23
+ case action_raw.action
24
+ when :unit_command # ActionRawUnitCommand
25
+ tags = action_raw.unit_command.unit_tags
26
+ when :toggle_autocast # ActionRawToggleAutocast
27
+ tags = action_raw.toggle_autocast.unit_tags
28
+ end
29
+ # when Api::ActionSpatial
30
+ # if action == :unit_command # ActionSpatialUnitCommand
31
+ # # For spatial unit commands, one _could_ assume the errors came from
32
+ # # the last selected allied units on the previous frame.
33
+ # # Since we don't have bot access here, leaving this empty.
34
+ # # tags = @bot.previous.all_units.owned.select(&:is_selected).tags
35
+ # end
36
+ end
37
+
38
+ tags
39
+ end
40
+
41
+ # Finds ability_id for the action, if applicable
42
+ # @return [Integer, nil] Api::AbilityID::* or nil if n/a
43
+ def ability_id
44
+ if action_type == Api::ActionRaw
45
+ case action_raw.action
46
+ when :unit_command # ActionRawUnitCommand
47
+ return action_raw.unit_command.ability_id
48
+ when :toggle_autocast # ActionRawToggleAutocast
49
+ return action_raw.toggle_autocast.ability_id
50
+ end
51
+ elsif action_type == Api::ActionSpatial && action_ui.action == :unit_command # ActionSpatialUnitCommand
52
+ return action_ui.unit_command.ability_id
53
+ end
54
+
55
+ nil
56
+ end
57
+ end
58
+ end
59
+
60
+ Api::Action.include Api::ActionExtension
@@ -2,10 +2,12 @@ module Api
2
2
  # Adds additional functionality to message object Api::Point2D
3
3
  module Point2DExtension
4
4
  # @private
5
+ # Hashes on x and y
5
6
  def hash
6
7
  [x, y].hash
7
8
  end
8
9
 
10
+ # @private
9
11
  def eql?(other)
10
12
  self.class == other.class && hash == other.hash
11
13
  end
@@ -15,6 +17,7 @@ module Api
15
17
  def to_p2d = self
16
18
 
17
19
  # Create a new 3d Point, by adding a y axis.
20
+ # @param z [Float, Integer]
18
21
  # @return [Api::Point]
19
22
  def to_3d(z: 0)
20
23
  Api::Point[x, y, z]
@@ -25,6 +28,8 @@ module Api
25
28
  # Shorthand for creating an instance for [x, y]
26
29
  # @example
27
30
  # Api::Point2D[2,4] # Where x is 2.0 and y is 4.0
31
+ # @param x [Float, Integer]
32
+ # @param y [Float, Integer]
28
33
  # @return [Api::Point2D]
29
34
  def [](x, y)
30
35
  Api::Point2D.new(x: x, y: y)
@@ -10,6 +10,8 @@ module Sc2
10
10
  # Loose equality matches on floats x and y.
11
11
  # We never check z-axis, because the map is single-level.
12
12
  # TODO: We should almost certainly introduce TOLERANCE here, but verify it's cost first.
13
+ # @param [Sc2::Position] other
14
+ # @return [Boolean]
13
15
  def ==(other)
14
16
  if other.is_a? Position
15
17
  x == other.x && y == other.y
@@ -61,39 +63,6 @@ module Sc2
61
63
  # @see #divide
62
64
  alias_method :/, :divide
63
65
 
64
- # Returns x coordinate
65
- # @return [Float]
66
- def x
67
- # Perf: Memoizing attributes which are hit hard, show gain
68
- @x ||= send(:method_missing, :x)
69
- end
70
-
71
- # Sets x coordinate
72
- # @return [Float]
73
- def x=(x)
74
- send(:method_missing, :x=, x)
75
- @x = x
76
- end
77
-
78
- # Returns y coordinate
79
- # @return [Float]
80
- def y
81
- # Bug: Psych implements method 'y' on Kernel, but protobuf uses method_missing to read AbstractMethod
82
- # We send method missing ourselves when y to fix this chain.
83
- # This is correct, but an unnecessary conditional:
84
- # raise NoMethodError unless location == self
85
-
86
- # Perf: Memoizing attributes which are hit hard, show gain
87
- @y ||= send(:method_missing, :y)
88
- end
89
-
90
- # Sets y coordinate
91
- # @return [Float]
92
- def y=(y)
93
- send(:method_missing, :y=, y)
94
- @y = y
95
- end
96
-
97
66
  # Randomly adjusts both x and y by a range of: -offset..offset
98
67
  # @param offset [Float]
99
68
  # @return [Sc2::Position] new Position
@@ -111,12 +80,16 @@ module Sc2
111
80
  end
112
81
 
113
82
  # Creates a new point with x and y which is offset
83
+ # @param x [Float, Integer]
84
+ # @param y [Float, Integer]
114
85
  # @return [Sc2::Position] new Position
115
86
  def offset(x = 0, y = 0)
116
87
  dup.offset!(x, y)
117
88
  end
118
89
 
119
90
  # Changes this point's x and y by the supplied offset
91
+ # @param x [Float, Integer]
92
+ # @param y [Float, Integer]
120
93
  # @return [Sc2::Position] self
121
94
  def offset!(x = 0, y = 0)
122
95
  self.x += x
@@ -182,7 +155,7 @@ module Sc2
182
155
  end
183
156
 
184
157
  # The squared distance between this point and the other point.
185
- # @param other [Point2D] The other point to calculate the squared distance to.
158
+ # @param other [Api::Point2D] The other point to calculate the squared distance to.
186
159
  # @return [Float]
187
160
  def distance_squared_to(other)
188
161
  if other.nil? || other == self
@@ -192,13 +165,15 @@ module Sc2
192
165
  end
193
166
 
194
167
  # Distance between this point and coordinate of x and y
168
+ # @param x [Float, Integer]
169
+ # @param y [Float, Integer]
195
170
  # @return [Float]
196
171
  def distance_to_coordinate(x:, y:)
197
172
  Math.hypot(self.x - x, self.y - y)
198
173
  end
199
174
 
200
175
  # The distance from this point to the circle.
201
- # @param center [Point2D] The center of the circle.
176
+ # @param center [Api::Point2D] The center of the circle.
202
177
  # @param radius [Float] The radius of the circle.
203
178
  # @return [Float]
204
179
  def distance_to_circle(center, radius)
@@ -9,6 +9,9 @@ module Api
9
9
  # @example
10
10
  # Api::Point[1,2,3] # Where x is 1.0, y is 2.0 and z is 3.0
11
11
  # @return [Api::Point]
12
+ # @param x [Float, Integer]
13
+ # @param y [Float, Integer]
14
+ # @param z [Float, Integer]
12
15
  def [](x, y, z)
13
16
  Api::Point.new(x: x, y: y, z: z)
14
17
  end
@@ -9,22 +9,6 @@ module Api
9
9
  tag || super
10
10
  end
11
11
 
12
- # Returns an integer unique identifier
13
- # If the unit goes out of vision and is snapshot-able, they get a random id
14
- # - Such a unit gets the same unit tag when it re-enters vision
15
- # @return [Integer]
16
- def tag
17
- # Perf: This speeds up hash and therefore common UnitGroup operations. Sometimes 3x!
18
- @tag ||= send(:method_missing, :tag)
19
- end
20
-
21
- # Sets unit tag
22
- # @return [Integer]
23
- def tag=(tag)
24
- send(:method_missing, :tag=, tag)
25
- @tag = tag
26
- end
27
-
28
12
  # Every unit gets access back to the bot to allow api access.
29
13
  # For your own units, this allows API access.
30
14
  # @return [Sc2::Player] player with active connection
@@ -55,8 +39,8 @@ module Api
55
39
  new_unit = @bot.all_units[tag]
56
40
  return false if new_unit.nil? || new_unit == self
57
41
 
58
- self.class.descriptor.entries.each do |entry|
59
- send(:"#{entry.name}=", new_unit.send(:method_missing, entry.name.to_sym))
42
+ method(:initialize).parameters.each do |_, entry|
43
+ send(:"#{entry.name}=", new_unit.send(entry))
60
44
  end
61
45
 
62
46
  true
@@ -73,8 +57,8 @@ module Api
73
57
  # Checks unit data for an attribute value
74
58
  # @return [Boolean] whether unit has attribute
75
59
  # @example
76
- # unit.has_attribute?(Api::Attribute::Mechanical)
77
- # unit.has_attribute?(:Mechanical)
60
+ # unit.has_attribute?(Api::Attribute::MECHANICAL)
61
+ # unit.has_attribute?(:MECHANICAL)
78
62
  def has_attribute?(attribute)
79
63
  attributes.include? attribute
80
64
  end
@@ -82,67 +66,67 @@ module Api
82
66
  # Checks if unit is light
83
67
  # @return [Boolean] whether unit has attribute :Light
84
68
  def is_light?
85
- has_attribute?(:Light)
69
+ has_attribute?(:LIGHT)
86
70
  end
87
71
 
88
72
  # Checks if unit is armored
89
73
  # @return [Boolean] whether unit has attribute :Armored
90
74
  def is_armored?
91
- has_attribute?(:Armored)
75
+ has_attribute?(:ARMORED)
92
76
  end
93
77
 
94
78
  # Checks if unit is biological
95
79
  # @return [Boolean] whether unit has attribute :Biological
96
80
  def is_biological?
97
- has_attribute?(:Biological)
81
+ has_attribute?(:BIOLOGICAL)
98
82
  end
99
83
 
100
84
  # Checks if unit is mechanical
101
85
  # @return [Boolean] whether unit has attribute :Mechanical
102
86
  def is_mechanical?
103
- has_attribute?(:Mechanical)
87
+ has_attribute?(:MECHANICAL)
104
88
  end
105
89
 
106
90
  # Checks if unit is robotic
107
91
  # @return [Boolean] whether unit has attribute :Robotic
108
92
  def is_robotic?
109
- has_attribute?(:Robotic)
93
+ has_attribute?(:ROBOTIC)
110
94
  end
111
95
 
112
96
  # Checks if unit is psionic
113
97
  # @return [Boolean] whether unit has attribute :Psionic
114
98
  def is_psionic?
115
- has_attribute?(:Psionic)
99
+ has_attribute?(:PSIONIC)
116
100
  end
117
101
 
118
102
  # Checks if unit is massive
119
103
  # @return [Boolean] whether unit has attribute :Massive
120
104
  def is_massive?
121
- has_attribute?(:Massive)
105
+ has_attribute?(:MASSIVE)
122
106
  end
123
107
 
124
108
  # Checks if unit is structure
125
109
  # @return [Boolean] whether unit has attribute :Structure
126
110
  def is_structure?
127
- has_attribute?(:Structure)
111
+ has_attribute?(:STRUCTURE)
128
112
  end
129
113
 
130
114
  # Checks if unit is hover
131
115
  # @return [Boolean] whether unit has attribute :Hover
132
116
  def is_hover?
133
- has_attribute?(:Hover)
117
+ has_attribute?(:HOVER)
134
118
  end
135
119
 
136
120
  # Checks if unit is heroic
137
121
  # @return [Boolean] whether unit has attribute :Heroic
138
122
  def is_heroic?
139
- has_attribute?(:Heroic)
123
+ has_attribute?(:HEROIC)
140
124
  end
141
125
 
142
126
  # Checks if unit is summoned
143
127
  # @return [Boolean] whether unit has attribute :Summoned
144
128
  def is_summoned?
145
- has_attribute?(:Summoned)
129
+ has_attribute?(:SUMMONED)
146
130
  end
147
131
 
148
132
  # @!group Virtual properties
@@ -457,15 +441,15 @@ module Api
457
441
  end
458
442
 
459
443
  # Checks whether a weapon can target a unit
460
- # @param unit [Api::unit]
444
+ # @param unit [Api::Unit]
461
445
  # @param weapon [Api::Weapon]
462
446
  # @return [Boolean]
463
447
  def can_weapon_target_unit?(unit:, weapon:)
464
448
  # false if enemy is air and we can only shoot ground
465
- return false if unit.is_flying && weapon.type == :Ground # Api::Weapon::TargetType::Ground
449
+ return false if unit.is_flying && weapon.type == :GROUND # Api::Weapon::TargetType::GROUND
466
450
 
467
451
  # false if enemy is ground and we can only shoot air
468
- return false if unit.is_ground? && weapon.type == :Air # A pi::Weapon::TargetType::Air
452
+ return false if unit.is_ground? && weapon.type == :AIR # Api::Weapon::TargetType::AIR
469
453
 
470
454
  # Check if weapon and unit models are in range
471
455
  in_attack_range?(unit:, range: weapon.range)
@@ -473,7 +457,7 @@ module Api
473
457
 
474
458
  def can_ability_target_unit?(unit:, ability:)
475
459
  # false if enemy is air and we can only shoot ground
476
- return false if ability.target == Api::AbilityData::Target::None
460
+ return false if ability.target == Api::AbilityData::Target::NONE
477
461
 
478
462
  # Check if weapon and unit models are in range
479
463
  in_attack_range?(unit:, range: ability.cast_range)