| 47 | } |
| 48 | } |
| 49 | bool UnitImpl::prepareIssueCommand(UnitCommand &command) |
| 50 | { |
| 51 | command.unit = this; |
| 52 | |
| 53 | // If using train or morph on a hatchery, automatically switch selection to larva |
| 54 | // (assuming canIssueCommand ensures that there is a larva) |
| 55 | if ( (command.type == UnitCommandTypes::Train || |
| 56 | command.type == UnitCommandTypes::Morph) && |
| 57 | getType().producesLarva() && command.getUnitType().whatBuilds().first == UnitTypes::Zerg_Larva ) |
| 58 | { |
| 59 | Unitset larvae( this->getLarva() ); |
| 60 | for(Unit larva : larvae) |
| 61 | { |
| 62 | if ( !larva->isConstructing() && larva->isCompleted() && larva->canCommand() ) |
| 63 | { |
| 64 | command.unit = larva; |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | if ( command.unit == this ) |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | // Set last command and command frames |
| 73 | static_cast<UnitImpl*>(command.unit)->lastCommandFrame = BroodwarImpl.getFrameCount(); |
| 74 | static_cast<UnitImpl*>(command.unit)->lastCommand = command; |
| 75 | static_cast<UnitImpl*>(command.unit)->setLastImmediateCommand(command); |
| 76 | if (command.type == UnitCommandTypes::Use_Tech_Unit && command.target && |
| 77 | (command.extra == TechTypes::Archon_Warp || command.extra == TechTypes::Dark_Archon_Meld)) |
| 78 | { |
| 79 | static_cast<UnitImpl*>(command.target)->lastCommandFrame = BroodwarImpl.getFrameCount(); |
| 80 | static_cast<UnitImpl*>(command.target)->lastCommand = command; |
| 81 | static_cast<UnitImpl*>(command.target)->setLastImmediateCommand(command); |
| 82 | } |
| 83 | |
| 84 | // Add to command optimizer if possible, as well as the latency compensation buffer |
| 85 | BroodwarImpl.addToCommandBuffer(Command{ command }); |
| 86 | return BroodwarImpl.commandOptimizer.add(command); |
| 87 | } |
| 88 | bool UnitImpl::issueCommand(UnitCommand command) |
| 89 | { |
| 90 | if ( !canIssueCommand(command) ) |
no test coverage detected