MCPcopy Create free account
hub / github.com/bwapi/bwapi / issueCommand

Method issueCommand

bwapi/BWAPI/Source/BWAPI/GameImpl.cpp:675–738  ·  view source on GitHub ↗

------------------------------------------ ISSUE COMMAND -------------------------------------------------

Source from the content-addressed store, hash-verified

673 }
674 //------------------------------------------ ISSUE COMMAND -------------------------------------------------
675 bool GameImpl::issueCommand(const Unitset& units, UnitCommand command)
676 {
677 std::vector< std::vector<Unit> > groupsOf12;
678 std::vector<Unit> nextGroup;
679
680 // Iterate the set of units
681 for (Unit u : units)
682 {
683 // Skip on invalid units that can't issue commands
684 if ( !u->exists() )
685 continue;
686
687 // If unit can't issue the command while grouped (e.g. if it is a building) then try to issue
688 // it individually instead.
689 if ( !u->canIssueCommandGrouped(command) )
690 {
691 u->issueCommand(command);
692 continue;
693 }
694
695 // If the command optimizer has taken over the command, then don't add it to this group
696 if ( static_cast<UnitImpl*>(u)->prepareIssueCommand(command) )
697 continue;
698
699 // Insert the unit into the next group
700 nextGroup.push_back(u);
701
702 // Create a new group of 12
703 if ( nextGroup.size() >= 12 )
704 {
705 groupsOf12.push_back(nextGroup);
706 nextGroup.clear();
707 }
708 }
709
710 // Insert the last group into the groups of 12, if it is an incomplete group
711 if ( !nextGroup.empty() )
712 groupsOf12.push_back(nextGroup);
713
714 // Return if no units to command
715 if ( groupsOf12.empty() )
716 return false;
717
718 // Iterate our groups of 12
719 for ( auto &v : groupsOf12 )
720 {
721 // Get the first unit available
722 command.unit = v.front();
723
724 // Command optimization (no select) for unit unloading, but only if optimizer level >= 2
725 // TODO this piece should be extracted to the CommandOptimizer
726 if ( command.type != BWAPI::UnitCommandTypes::Unload || commandOptimizer.level < 2 )
727 {
728 // Select the unit group
729 BW::Orders::Select sel(v);
730 QueueGameCommand(&sel, sel.size());
731 apmCounter.addSelect();
732 }

Callers

nothing calls this directly

Calls 8

QueueGameCommandFunction · 0.85
prepareIssueCommandMethod · 0.80
addSelectMethod · 0.80
executeCommandMethod · 0.80
existsMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected