Module: Sc2::Player::Actions
- Included in:
- Bot
- Defined in:
- lib/sc2ai/player/actions.rb
Overview
Holds action list and queues batch
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 message ActionMultiPanel { optional Type type = 1; optional int32 unit_index = 2; }.
-
#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>
8 9 10 |
# File 'lib/sc2ai/player/actions.rb', line 8 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sc2ai/player/actions.rb', line 43 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
363 364 365 366 367 368 369 370 |
# File 'lib/sc2ai/player/actions.rb', line 363 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
137 138 139 140 141 142 143 144 145 |
# File 'lib/sc2ai/player/actions.rb', line 137 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
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sc2ai/player/actions.rb', line 122 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
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sc2ai/player/actions.rb', line 23 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.
172 173 174 175 176 177 178 179 180 |
# File 'lib/sc2ai/player/actions.rb', line 172 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.
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/sc2ai/player/actions.rb', line 155 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.
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/sc2ai/player/actions.rb', line 192 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
207 208 209 210 211 212 213 214 215 216 |
# File 'lib/sc2ai/player/actions.rb', line 207 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.
324 325 326 327 328 329 330 331 332 |
# File 'lib/sc2ai/player/actions.rb', line 324 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.
232 233 234 235 236 237 238 239 240 241 |
# File 'lib/sc2ai/player/actions.rb', line 232 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 message ActionMultiPanel
optional Type type = 1;
optional int32 unit_index = 2;
311 312 313 314 315 316 317 318 319 320 |
# File 'lib/sc2ai/player/actions.rb', line 311 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
336 337 338 339 340 341 342 343 344 |
# File 'lib/sc2ai/player/actions.rb', line 336 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)
246 247 248 249 250 251 252 253 254 |
# File 'lib/sc2ai/player/actions.rb', line 246 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
288 289 290 291 292 293 294 295 296 |
# File 'lib/sc2ai/player/actions.rb', line 288 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)
271 272 273 274 275 276 277 |
# File 'lib/sc2ai/player/actions.rb', line 271 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)
259 260 261 262 263 264 265 266 267 |
# File 'lib/sc2ai/player/actions.rb', line 259 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.
348 349 350 351 352 353 354 355 356 |
# File 'lib/sc2ai/player/actions.rb', line 348 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
74 75 76 77 78 79 80 81 |
# File 'lib/sc2ai/player/actions.rb', line 74 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
13 14 15 |
# File 'lib/sc2ai/player/actions.rb', line 13 def queue_action(action) @action_queue << action end |
#research(units:, upgrade_id:, queue_command: false) ⇒ Object
Research a specific upgrade
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sc2ai/player/actions.rb', line 106 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
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sc2ai/player/actions.rb', line 89 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 |