Module: Sc2::Player::Actions
- Included in:
- Bot
- Defined in:
- lib/sc2ai/player/actions.rb
Overview
Holds action list and queues batch
Constant Summary collapse
- COMBINABLE_ABILITIES =
[ Api::AbilityId::MOVE, Api::AbilityId::ATTACK, Api::AbilityId::SCAN_MOVE, Api::AbilityId::STOP, Api::AbilityId::SMART, Api::AbilityId::HOLDPOSITION, Api::AbilityId::PATROL, Api::AbilityId::HARVEST_GATHER, Api::AbilityId::HARVEST_RETURN, Api::AbilityId::EFFECT_REPAIR, Api::AbilityId::LIFT, Api::AbilityId::BURROWDOWN, Api::AbilityId::BURROWUP, Api::AbilityId::SIEGEMODE_SIEGEMODE, Api::AbilityId::UNSIEGE_UNSIEGE, Api::AbilityId::MORPH_LIBERATORAAMODE, Api::AbilityId::EFFECT_STIM, Api::AbilityId::MORPH_UPROOT, Api::AbilityId::EFFECT_BLINK, Api::AbilityId::MORPH_ARCHON ]
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#action(units:, ability_id:, target: nil, queue_command: false) ⇒ Object
Queues a Api::ActionRawUnitCommand.
-
#action_chat(message, channel: Api::ActionChat::Channel::TEAM) ⇒ Object
Send a chat message.
-
#action_raw_camera_move(point:) ⇒ void
Toggles auto-cast ability for units.
-
#action_raw_toggle_autocast(units:, ability_id:) ⇒ void
Toggles auto-cast ability for units.
-
#action_raw_unit_command(unit_tags:, ability_id:, queue_command: false, target_world_space_pos: nil, target_unit_tag: nil) ⇒ Object
Queues a Api::ActionRaw.
-
#action_spatial_camera_move(center_minimap:) ⇒ void
Simulates a click on the minimap to move the camera.
-
#action_spatial_unit_command(ability_id:, target_screen_coord: nil, target_minimap_coord: nil, queue_command: false) ⇒ void
Issues spatial unit command.
-
#action_spatial_unit_selection_point(type: Api::ActionSpatialUnitSelectionPoint::Type::Select, selection_screen_coord: nil) ⇒ void
Issues spatial unit select point command.
-
#action_spatial_unit_selection_rect(selection_screen_coord:, selection_add: false) ⇒ void
Issue rectangle select.
-
#action_ui_cargo_panel_unload(unit_index:) ⇒ Object
Cargo panel actions for unloading units.
-
#action_ui_control_group(action:, control_group_index:) ⇒ void
Perform action on control group like setting or recalling, use in conjunction with unit selection.
-
#action_ui_multi_panel(type:, unit_index:) ⇒ Object
Multi-panel actions for select/deselect.
-
#action_ui_production_panel_remove_from_queue(unit_index:) ⇒ Object
Remove unit from production queue.
-
#action_ui_select_army(selection_add: false) ⇒ void
Selects army (F2).
-
#action_ui_select_idle_worker(type:) ⇒ Object
Select idle workers.
-
#action_ui_select_larva ⇒ void
Selects larva (Zerg).
-
#action_ui_select_warp_gates(selection_add: false) ⇒ void
Selects warp gates (Protoss).
-
#action_ui_toggle_autocast(ability_id:) ⇒ Object
Toggle autocast on selected unit.
-
#build(units:, unit_type_id:, target: nil, queue_command: false) ⇒ Object
Builds target unit type using units as source at optional target.
-
#queue_action(action) ⇒ void
Queues action for performing end of step.
-
#research(units:, upgrade_id:, queue_command: false) ⇒ Object
Research a specific upgrade.
-
#warp(unit_type_id:, target:, queue_command:, units: nil) ⇒ Object
Warps in unit type at target (location or pylon) with optional source units (warp gates) When not specifying the specific warp gate(s), all warpgates will be used.
Instance Attribute Details
#action_queue ⇒ Array<Api::Action>
31 32 33 |
# File 'lib/sc2ai/player/actions.rb', line 31 def action_queue @action_queue end |
Instance Method Details
#action(units:, ability_id:, target: nil, queue_command: false) ⇒ Object
Queues a Api::ActionRawUnitCommand. Send accepts a Api::Unit, tag or tags and targets Api::Point2D or unit.tag
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sc2ai/player/actions.rb', line 66 def action(units:, ability_id:, target: nil, queue_command: false) = (units) target_pos = nil target_unit_tag = nil case target when Api::Point2D target_pos = target when Api::Point target_pos = target.to_p2d when Api::Unit target_unit_tag = target.tag else target_unit_tag = target end # noinspection RubyMismatchedArgumentType action_raw_unit_command( unit_tags: , ability_id: ability_id, queue_command: queue_command, target_world_space_pos: target_pos, target_unit_tag: target_unit_tag ) end |
#action_chat(message, channel: Api::ActionChat::Channel::TEAM) ⇒ Object
Send a chat message
386 387 388 389 390 391 392 393 |
# File 'lib/sc2ai/player/actions.rb', line 386 def action_chat(, channel: Api::ActionChat::Channel::TEAM) queue_action Api::Action.new( action_chat: Api::ActionChat.new( channel: channel, message: .to_s ) ) end |
#action_raw_camera_move(point:) ⇒ void
This method returns an undefined value.
Toggles auto-cast ability for units
160 161 162 163 164 165 166 167 168 |
# File 'lib/sc2ai/player/actions.rb', line 160 def action_raw_camera_move(point:) queue_action Api::Action.new( action_raw: Api::ActionRaw.new( camera_move: Api::ActionRawCameraMove.new( center_world_space: point ) ) ) end |
#action_raw_toggle_autocast(units:, ability_id:) ⇒ void
This method returns an undefined value.
Toggles auto-cast ability for units
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/sc2ai/player/actions.rb', line 145 def action_raw_toggle_autocast(units:, ability_id:) = (units) queue_action Api::Action.new( action_raw: Api::ActionRaw.new( toggle_autocast: Api::ActionRawToggleAutocast.new( ability_id: ability_id, unit_tags: ) ) ) end |
#action_raw_unit_command(unit_tags:, ability_id:, queue_command: false, target_world_space_pos: nil, target_unit_tag: nil) ⇒ Object
Queues a Api::ActionRaw. Perform ability on unit_tags optionally on target_world_space_pos/target_unit_tag
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sc2ai/player/actions.rb', line 46 def action_raw_unit_command(unit_tags:, ability_id:, queue_command: false, target_world_space_pos: nil, target_unit_tag: nil) queue_action Api::Action.new( action_raw: Api::ActionRaw.new( unit_command: Api::ActionRawUnitCommand.new( unit_tags: , ability_id: ability_id, queue_command: queue_command, target_world_space_pos: target_world_space_pos, target_unit_tag: target_unit_tag ) ) ) end |
#action_spatial_camera_move(center_minimap:) ⇒ void
This method returns an undefined value.
Simulates a click on the minimap to move the camera.
195 196 197 198 199 200 201 202 203 |
# File 'lib/sc2ai/player/actions.rb', line 195 def action_spatial_camera_move(center_minimap:) queue_action Api::Action.new( action_feature_layer: Api::ActionSpatial.new( camera_move: Api::ActionSpatialCameraMove.new( center_minimap: center_minimap ) ) ) end |
#action_spatial_unit_command(ability_id:, target_screen_coord: nil, target_minimap_coord: nil, queue_command: false) ⇒ void
This method returns an undefined value.
Issues spatial unit command. Target is either target_screen_coord or target_minimap_coord.
178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/sc2ai/player/actions.rb', line 178 def action_spatial_unit_command(ability_id:, target_screen_coord: nil, target_minimap_coord: nil, queue_command: false) queue_action Api::Action.new( action_raw: Api::ActionSpatial.new( unit_command: Api::ActionSpatialUnitCommand.new( ability_id: ability_id, target_screen_coord: target_screen_coord, target_minimap_coord: target_minimap_coord, queue_command: queue_command ) ) ) end |
#action_spatial_unit_selection_point(type: Api::ActionSpatialUnitSelectionPoint::Type::Select, selection_screen_coord: nil) ⇒ void
This method returns an undefined value.
Issues spatial unit select point command. Target is either target_screen_coord or target_minimap_coord.
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/sc2ai/player/actions.rb', line 215 def action_spatial_unit_selection_point(type: Api::ActionSpatialUnitSelectionPoint::Type::Select, selection_screen_coord: nil) queue_action Api::Action.new( action_feature_layer: Api::ActionSpatial.new( unit_selection_point: Api::ActionSpatialUnitSelectionPoint.new( type: type, selection_screen_coord: selection_screen_coord ) ) ) end |
#action_spatial_unit_selection_rect(selection_screen_coord:, selection_add: false) ⇒ void
This method returns an undefined value.
Issue rectangle select
230 231 232 233 234 235 236 237 238 239 |
# File 'lib/sc2ai/player/actions.rb', line 230 def action_spatial_unit_selection_rect(selection_screen_coord:, selection_add: false) queue_action Api::Action.new( action_feature_layer: Api::ActionSpatial.new( unit_selection_rect: Api::ActionSpatialUnitSelectionRect.new( selection_screen_coord: selection_screen_coord, selection_add: selection_add ) ) ) end |
#action_ui_cargo_panel_unload(unit_index:) ⇒ Object
Cargo panel actions for unloading units.
347 348 349 350 351 352 353 354 355 |
# File 'lib/sc2ai/player/actions.rb', line 347 def action_ui_cargo_panel_unload(unit_index:) queue_action Api::Action.new( action_ui: Api::ActionUI.new( cargo_panel: Api::ActionCargoPanelUnload.new( unit_index: unit_index ) ) ) end |
#action_ui_control_group(action:, control_group_index:) ⇒ void
This method returns an undefined value.
Perform action on control group like setting or recalling, use in conjunction with unit selection. Populated if Feature Layer or Render interface is enabled.
255 256 257 258 259 260 261 262 263 264 |
# File 'lib/sc2ai/player/actions.rb', line 255 def action_ui_control_group(action:, control_group_index:) queue_action Api::Action.new( action_ui: Api::ActionUI.new( control_group: Api::ActionControlGroup.new( action: action, control_group_index: control_group_index ) ) ) end |
#action_ui_multi_panel(type:, unit_index:) ⇒ Object
Multi-panel actions for select/deselect
334 335 336 337 338 339 340 341 342 343 |
# File 'lib/sc2ai/player/actions.rb', line 334 def action_ui_multi_panel(type:, unit_index:) queue_action Api::Action.new( action_ui: Api::ActionUI.new( multi_panel: Api::ActionMultiPanel.new( type: type, unit_index: unit_index ) ) ) end |
#action_ui_production_panel_remove_from_queue(unit_index:) ⇒ Object
Remove unit from production queue
359 360 361 362 363 364 365 366 367 |
# File 'lib/sc2ai/player/actions.rb', line 359 def action_ui_production_panel_remove_from_queue(unit_index:) queue_action Api::Action.new( action_ui: Api::ActionUI.new( production_panel: Api::ActionProductionPanelRemoveFromQueue.new( unit_index: unit_index ) ) ) end |
#action_ui_select_army(selection_add: false) ⇒ void
This method returns an undefined value.
Selects army (F2)
269 270 271 272 273 274 275 276 277 |
# File 'lib/sc2ai/player/actions.rb', line 269 def action_ui_select_army(selection_add: false) queue_action Api::Action.new( action_ui: Api::ActionUI.new( select_army: Api::ActionSelectArmy.new( selection_add: selection_add ) ) ) end |
#action_ui_select_idle_worker(type:) ⇒ Object
Select idle workers
311 312 313 314 315 316 317 318 319 |
# File 'lib/sc2ai/player/actions.rb', line 311 def action_ui_select_idle_worker(type:) queue_action Api::Action.new( action_ui: Api::ActionUI.new( select_idle_worker: Api::ActionSelectIdleWorker.new( type: type ) ) ) end |
#action_ui_select_larva ⇒ void
This method returns an undefined value.
Selects larva (Zerg)
294 295 296 297 298 299 300 |
# File 'lib/sc2ai/player/actions.rb', line 294 def action_ui_select_larva queue_action Api::Action.new( action_ui: Api::ActionUI.new( select_larva: Api::ActionSelectLarva.new ) ) end |
#action_ui_select_warp_gates(selection_add: false) ⇒ void
This method returns an undefined value.
Selects warp gates (Protoss)
282 283 284 285 286 287 288 289 290 |
# File 'lib/sc2ai/player/actions.rb', line 282 def action_ui_select_warp_gates(selection_add: false) queue_action Api::Action.new( action_ui: Api::ActionUI.new( select_warp_gates: Api::ActionSelectWarpGates.new( selection_add: selection_add ) ) ) end |
#action_ui_toggle_autocast(ability_id:) ⇒ Object
Toggle autocast on selected unit. Also possible with raw actions using a unit target.
371 372 373 374 375 376 377 378 379 |
# File 'lib/sc2ai/player/actions.rb', line 371 def action_ui_toggle_autocast(ability_id:) queue_action Api::Action.new( action_ui: Api::ActionUI.new( toggle_autocast: Api::ActionToggleAutocast.new( unit_index: ability_id ) ) ) end |
#build(units:, unit_type_id:, target: nil, queue_command: false) ⇒ Object
Builds target unit type using units as source at optional target
97 98 99 100 101 102 103 104 |
# File 'lib/sc2ai/player/actions.rb', line 97 def build(units:, unit_type_id:, target: nil, queue_command: false) # Get build ability from target building type action(units:, ability_id: unit_data(unit_type_id).ability_id, target:, queue_command:) subtract_cost(unit_type_id) end |
#queue_action(action) ⇒ void
This method returns an undefined value.
Queues action for performing end of step
36 37 38 |
# File 'lib/sc2ai/player/actions.rb', line 36 def queue_action(action) @action_queue << action end |
#research(units:, upgrade_id:, queue_command: false) ⇒ Object
Research a specific upgrade
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/sc2ai/player/actions.rb', line 129 def research(units:, upgrade_id:, queue_command: false) upgrade = upgrade_data(upgrade_id) # Get build ability from target building type action(units:, ability_id: upgrade.ability_id, queue_command:) @spent_minerals += upgrade.mineral_cost @spent_vespene += upgrade.vespene_cost end |
#warp(unit_type_id:, target:, queue_command:, units: nil) ⇒ Object
Warps in unit type at target (location or pylon) with optional source units (warp gates) When not specifying the specific warp gate(s), all warpgates will be used
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/sc2ai/player/actions.rb', line 112 def warp(unit_type_id:, target:, queue_command:, units: nil) warp_ability = Api::TechTree.unit_type_creation_abilities( source: Api::UnitTypeId::WARPGATE, target: unit_type_id ) units = structures.warpgates if units.nil? action(units: units, ability_id: warp_ability[:ability], target:, queue_command:) subtract_cost(unit_type_id) end |