sc2ai 0.0.6 → 0.0.7

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.
@@ -227,6 +227,7 @@ module Api
227
227
  # @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
228
228
  # @param queue_command [Boolean] shift+command
229
229
  def attack(target:, queue_command: false)
230
+ return false if target.nil?
230
231
  action(ability_id: Api::AbilityId::ATTACK, target:, queue_command:)
231
232
  end
232
233
 
@@ -241,7 +242,7 @@ module Api
241
242
  end
242
243
 
243
244
  # Builds target unit type, i.e. issuing a build command to worker.build(...Api::UnitTypeId::BARRACKS)
244
- # @param unit_type_id [Integer] Api::UnitTypeId the unit type which will do the creation
245
+ # @param unit_type_id [Integer] Api::UnitTypeId the unit type you wish to build
245
246
  # @param target [Api::Point2D, Integer, nil] is a unit tag or a Api::Point2D. Nil for addons/orbital
246
247
  # @param queue_command [Boolean] shift+command
247
248
  def build(unit_type_id:, target: nil, queue_command: false)
@@ -263,7 +264,7 @@ module Api
263
264
  end
264
265
 
265
266
  # Research a specific upgrade
266
- # @param upgrade_id [Integer] Api::UnitTypeId the unit type which will do the creation
267
+ # @param upgrade_id [Integer] Api::UnitTypeId the unit type you wish to research
267
268
  # @param queue_command [Boolean] shift+command
268
269
  def research(upgrade_id:, queue_command: false)
269
270
  @bot.research(units: self, upgrade_id:, queue_command:)
@@ -359,7 +360,7 @@ module Api
359
360
  # @param target [Api::Unit, Integer] optionally check if unit is engaged with specific target
360
361
  def is_attacking?(target: nil)
361
362
  is_performing_ability_on_target?(
362
- [Api::AbilityId::ATTACK_ATTACK],
363
+ [Api::AbilityId::ATTACK_ATTACK, Api::AbilityId::ATTACK],
363
364
  target:
364
365
  )
365
366
  end
@@ -421,6 +422,14 @@ module Api
421
422
  end
422
423
  end
423
424
 
425
+ # Returns whether this unit has an ability available
426
+ # Queries API if necessary
427
+ # @param [Integer] ability_id
428
+ # @return [Boolean]
429
+ def ability_available?(ability_id)
430
+ @bot.unit_ability_available?(unit_tag: tag, ability_id:)
431
+ end
432
+
424
433
  # Checks whether a weapon can target a unit
425
434
  # @param unit [Api::unit]
426
435
  # @param weapon [Api::Weapon]
@@ -546,8 +555,25 @@ module Api
546
555
  build(unit_type_id: unit_type_id, queue_command:)
547
556
  end
548
557
 
558
+ # PROTOSS Convenience functions ---
559
+
560
+ # Warps in unit type at target (location or pylon)
561
+ # Only works if the source is a Warp Gate
562
+ # @param unit_type_id [Integer] Api::UnitTypeId the unit type you wish to build
563
+ # @param target [Api::Point2D] a point, which should be inside an energy source
564
+ # @param queue_command [Boolean] shift+command
565
+ def warp(unit_type_id:, target:, queue_command: false)
566
+ @bot.warp(units: self, unit_type_id:, target:, queue_command:)
567
+ end
568
+
549
569
  # GENERAL Convenience functions ---
550
570
 
571
+ # Returns true if unit does not have orders
572
+ # @return [Boolean] whether unit is idle
573
+ def is_idle?
574
+ orders.empty?
575
+ end
576
+
551
577
  # ...
552
578
 
553
579
  private
@@ -0,0 +1,9 @@
1
+ module Api
2
+ # Adds additional functionality to message object Api::Unit
3
+ module UnitTypeExtension
4
+ def mood
5
+ "Crafty"
6
+ end
7
+ end
8
+ end
9
+ Api::UnitTypeData.prepend Api::UnitTypeExtension
@@ -26,7 +26,7 @@ module Sc2
26
26
  end
27
27
 
28
28
  # Builds target unit type, i.e. issuing a build command to worker.build(...Api::UnitTypeId::BARRACKS)
29
- # @param unit_type_id [Integer] Api::UnitTypeId the unit type which will do the creation
29
+ # @param unit_type_id [Integer] Api::UnitTypeId the unit type you wish to build
30
30
  # @param target [Api::Point2D, Integer, nil] is a unit tag or a Api::Point2D. Nil for addons/orbital
31
31
  # @param queue_command [Boolean] shift+command
32
32
  def build(unit_type_id:, target: nil, queue_command: false)
@@ -41,10 +41,10 @@ module Sc2
41
41
 
42
42
  # Warps in unit type at target (location or pylon)
43
43
  # Will only have affect is this group consists of warp gates, i.e. bot.structures.warpgates
44
- # @param unit_type_id [Integer] Api::UnitTypeId the unit type which will do the creation
44
+ # @param unit_type_id [Integer] Api::UnitTypeId the unit type you wish to build
45
45
  # @param target [Api::Point2D] a point, which should be inside an energy source
46
46
  # @param queue_command [Boolean] shift+command
47
- def warp(unit_type_id:, target: nil, queue_command: false)
47
+ def warp(unit_type_id:, target:, queue_command: false)
48
48
  return if size.zero?
49
49
  bot&.warp(units: self, unit_type_id:, target:, queue_command:)
50
50
  end
@@ -121,13 +121,14 @@ module Sc2
121
121
 
122
122
  # @private
123
123
  # Does the opposite of selector and returns those values for parent
124
- def select_type(*)
125
- @parent.reject_type(*)
124
+ def select(...)
125
+ @parent.reject(...)
126
126
  end
127
127
 
128
+ # @private
128
129
  # Does the opposite of selector and returns those values for parent
129
- def reject_type(*)
130
- @parent.select_type(*)
130
+ def reject(...)
131
+ @parent.select(...)
131
132
  end
132
133
  end
133
134
 
@@ -230,14 +231,28 @@ module Sc2
230
231
  alias_method :assimilators, :gas
231
232
 
232
233
  # Selects only units which have finished constructing, i.o.w. build_progress == 1.0
233
- # @return [UnitGroup] gas structures
234
+ # @return [UnitGroup] complete unit group
234
235
  def completed
235
236
  select(&:is_completed?)
236
237
  end
237
238
 
239
+ # Selects only units which have finished constructing, i.o.w. build_progress != 1.0
240
+ # @return [UnitGroup] incomplete unit group
241
+ def incomplete
242
+ reject(&:is_completed?)
243
+ end
244
+
238
245
  # Selects only units which do not have orders
239
246
  def idle
240
- select { |unit| unit.orders.empty? }
247
+ select(&:is_idle?)
248
+ end
249
+
250
+ # Selects units which have this ability available\
251
+ # Queries API if necessary
252
+ # @param [Integer] ability_id
253
+ # @return [UnitGroup] units which have the ability available
254
+ def ability_available?(ability_id)
255
+ select { |unit| unit.ability_available?(ability_id) }
241
256
  end
242
257
 
243
258
  # NEUTRAL ------------------------------------------
@@ -340,7 +355,7 @@ module Sc2
340
355
  # Selects pylons and warp prisms in phasing mode
341
356
  # @return [Sc2::UnitGroup] pylons annd warp prisms phasing
342
357
  def warpables
343
- select_type([Api::UnitTypeId::PYLON, Api::UnitTypeId::WARPPRISMPHASING])
358
+ select_type([Api::UnitTypeId::PYLON, Api::UnitTypeId::WARPPRISMPHASING]).completed
344
359
  end
345
360
 
346
361
  # Geometric/Map ---
data/lib/sc2ai/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Sc2
4
4
  # gem version
5
- VERSION = "0.0.6"
5
+ VERSION = "0.0.7"
6
6
  end
@@ -10,5 +10,5 @@ Sc2::Match.new(
10
10
  $bot,
11
11
  Sc2::Player::Computer.new(race: Api::Race::Random, difficulty: Api::Difficulty::VeryEasy)
12
12
  ],
13
- map: "Goldenaura512V2AIE" # Or any of the downloaded map names
13
+ map: "GoldenAura513AIE" # Or any of the downloaded map names
14
14
  ).run