//--------------------------------------------- ISSUE COMMAND ---------------------------------------------- bool UnitImpl::issueCommand(UnitCommand command) { if ( !canIssueCommand(command) ) return false; command.unit = this; // If using train or morph on a hatchery, automatically switch selection to larva // (assuming canIssueCommand ensures that there is a larva) if ( (command.type == UnitCommandTypes::Train || command.type == UnitCommandTypes::Morph) && getType().producesLarva() && command.getUnitType().whatBuilds().first == UnitTypes::Zerg_Larva ) { Unitset larvae( this->getLarva() ); foreach (Unit larva, larvae) { if ( !larva->isConstructing() && larva->isCompleted() && larva->canCommand() ) { command.unit = larva; break; } } if ( command.unit == this ) return false; }
//--------------------------------------------- ISSUE COMMAND ---------------------------------------------- bool UnitImpl::issueCommand(UnitCommand command) { if ( !canIssueCommand(command) ) return false; command.unit = this; if (command.type == UnitCommandTypes::Train || command.type == UnitCommandTypes::Morph) if (getType().producesLarva() && command.getUnitType().whatBuilds().first == UnitTypes::Zerg_Larva ) command.unit = *getLarva().begin(); BWAPIC::UnitCommand c; c.type = command.type; c.unitIndex = command.unit->getID(); if ( command.target ) c.targetIndex = command.target->getID(); else c.targetIndex = -1; c.x = command.x; c.y = command.y; c.extra = command.extra; Command(command).execute(0); ((GameImpl*)Broodwar)->addUnitCommand(c); lastCommandFrame = Broodwar->getFrameCount(); lastCommand = command; return true; }
void DrawTextElm::setUnParsestring(const QString &valueUnParss, const QString &valueLogger) { unParsestring = valueUnParss; loggerText = valueLogger; // qDebug() << value; globalPauseLifeTime = 0; globalDeltaComandSize = 0; myParser.ParsingLine(mUnitList, unParsestring, drawTime, globalPauseLifeTime, globalDeltaComandSize, delay); UnitCommand* command = new UnitCommand(); command->setUnitCommandType("Update"); command->setUnitData("1"); // command->unitType = 2; mUnitList.append(command); /*if (needToSaveLifeTime) lifeTime=drawTime;*/ if(mUnitList.size() > 0) tickTime = ((lifeTime - globalPauseLifeTime)/(mUnitList.size() - globalDeltaComandSize - 1)); qDebug()<<"tickTime5:"<<tickTime; }
//--------------------------------------------- ISSUE COMMAND ---------------------------------------------- void UnitImpl::setLastImmediateCommand(const UnitCommand &command) { // Set last immediate command and immediate command frame if ( command.type != UnitCommandTypes::Cloak && command.type != UnitCommandTypes::Decloak && command.type != UnitCommandTypes::Unload && !command.isQueued() ) { static_cast<UnitImpl*>(command.unit)->lastImmediateCommand = command; static_cast<UnitImpl*>(command.unit)->lastImmediateCommandFrame = BroodwarImpl.frameCount; } }
//--------------------------------------------- ISSUE COMMAND ---------------------------------------------- bool UnitImpl::issueCommand(UnitCommand command) { if ( !canIssueCommand(command) ) return false; command.unit = this; // If using train or morph on a hatchery, automatically switch selection to larva // (assuming canIssueCommand ensures that there is a larva) if ( (command.type == UnitCommandTypes::Train || command.type == UnitCommandTypes::Morph) && getType().producesLarva() && command.getUnitType().whatBuilds().first == UnitTypes::Zerg_Larva ) { Unitset larvae( this->getLarva() ); for (Unit larva : larvae) { if ( !larva->isConstructing() && larva->isCompleted() && larva->canCommand() ) { command.unit = larva; break; } } if ( command.unit == this ) return false; } BWAPIC::UnitCommand c; c.type = command.type; #pragma warning(suppress: 6011) c.unitIndex = command.unit->getID(); if ( command.target ) c.targetIndex = command.target->getID(); else c.targetIndex = -1; c.x = command.x; c.y = command.y; c.extra = command.extra; Command(command).execute(0); static_cast<GameImpl*>(BroodwarPtr)->addUnitCommand(c); lastCommandFrame = Broodwar->getFrameCount(); lastCommand = command; return true; }
bool UnitImpl::prepareIssueCommand(UnitCommand &command) { command.unit = this; // If using train or morph on a hatchery, automatically switch selection to larva // (assuming canIssueCommand ensures that there is a larva) if ( (command.type == UnitCommandTypes::Train || command.type == UnitCommandTypes::Morph) && getType().producesLarva() && command.getUnitType().whatBuilds().first == UnitTypes::Zerg_Larva ) { Unitset larvae( this->getLarva() ); for(Unit larva : larvae) { if ( !larva->isConstructing() && larva->isCompleted() && larva->canCommand() ) { command.unit = larva; break; } } if ( command.unit == this ) return false; } // Set last command and command frames static_cast<UnitImpl*>(command.unit)->lastCommandFrame = BroodwarImpl.getFrameCount(); static_cast<UnitImpl*>(command.unit)->lastCommand = command; static_cast<UnitImpl*>(command.unit)->setLastImmediateCommand(command); if (command.type == UnitCommandTypes::Use_Tech_Unit && command.target && (command.extra == TechTypes::Archon_Warp || command.extra == TechTypes::Dark_Archon_Meld)) { static_cast<UnitImpl*>(command.target)->lastCommandFrame = BroodwarImpl.getFrameCount(); static_cast<UnitImpl*>(command.target)->lastCommand = command; static_cast<UnitImpl*>(command.target)->setLastImmediateCommand(command); } // Add to command optimizer if possible, as well as the latency compensation buffer BroodwarImpl.addToCommandBuffer(new Command(command)); return BroodwarImpl.commandOptimizer.add(command); }
void BattleGesture::TouchEnded(Touch* touch) { if (touch == _trackingTouch) { if (_trackingMarker != nullptr) { Unit* unit = _trackingMarker->GetUnit(); UnitCommand command; command.path = _trackingMarker->_path; command.running = _trackingMarker->GetRunning(); command.meleeTarget = _trackingMarker->GetMeleeTarget(); Unit* missileTarget = _trackingMarker->GetMissileTarget(); glm::vec2* orientation = _trackingMarker->GetOrientationX(); if (missileTarget != nullptr) { command.missileTarget = missileTarget; command.missileTargetLocked = true; if (missileTarget != unit) command.bearing = angle(missileTarget->state.center - command.GetDestination()); unit->state.loadingTimer = 0; } else if (orientation) { command.bearing = angle(*orientation - command.GetDestination()); } if (!touch->HasMoved()) { if (_tappedUnitCenter && touch->GetTapCount() > 1) { command.meleeTarget = nullptr; command.ClearPathAndSetDestination(unit->state.center); command.missileTarget = nullptr; command.missileTargetLocked = false; } else if (_tappedDestination && !_tappedUnitCenter) { if (!command.running) { command.running = true; } } else if (_tappedUnitCenter && !_tappedDestination) { if (command.running) { command.running = false; } } } unit->timeUntilSwapFighters = 0.2f; _battleView->RemoveTrackingMarker(_trackingMarker); _trackingMarker = nullptr; _battleView->GetSimulator()->SetUnitCommand(unit, command, _battleView->GetSimulator()->GetTimerDelay()); if (touch->GetTapCount() == 1) SoundPlayer::singleton->Play(SoundBufferCommandAck); } } if (touch == _modifierTouch && _trackingTouch != nullptr) { _trackingTouch->ResetHasMoved(); } if (_trackingTouch != nullptr && _modifierTouch != nullptr) { _trackingTouch->ResetVelocity(); _modifierTouch->ResetVelocity(); } /*if (_trackingTouch == nullptr && _modifierTouch != nullptr) { if (!ViewState::singleton->showTitleScreen) { vector2 velocity = touch->GetVelocity(); float speed = norm(velocity) - 1; if (speed < 0) speed = 0; else if (speed > 10) speed = 10; velocity = vector2::from_polar(velocity.angle(), speed); float k = SamuraiSurface::singleton->renderLayer.actualWidth / 2; if (SamuraiSurface::singleton->renderLayer.flip) k = -k; BoardGesture::scrollVelocity = velocity * k; } }*/ if (touch == _trackingTouch) { _trackingTouch = nullptr; } else if (touch == _modifierTouch) { _modifierTouch = nullptr; } }
void BattleGesture::TouchBegan(Touch* touch) { if (touch->GetSurface() != _battleView->GetSurface()) return; if (touch->HasGesture()) return; if (!_battleView->GetFrame().contains(touch->GetPosition())) return; if (_battleView->GetCommander() == nullptr) return; if (_battleView->GetCommander()->GetType() != BattleCommanderType::Player) return; if (!_battleView->GetCommander()->IsActive()) return; glm::vec2 screenPosition = touch->GetPosition(); glm::vec2 terrainPosition = _battleView->GetTerrainPosition3(screenPosition).xy(); Unit* unit = FindPlayerUnit(screenPosition, terrainPosition); if (_trackingTouch == nullptr) { if (unit == nullptr) return; if (unit != nullptr && _battleView->GetTrackingMarker(unit) == nullptr) { const UnitCommand command = unit->GetCommand(); _allowTargetEnemyUnit = unit->stats.missileType != MissileType::None; _trackingMarker = _battleView->AddTrackingMarker(unit); float distanceToUnitCenter = glm::distance(GetUnitCurrentBounds(unit).center(), screenPosition); float distanceToDestination = glm::distance(GetUnitFutureBounds(unit).center(), screenPosition); float distanceToModifierArea = glm::distance(GetUnitModifierBounds(unit).center(), screenPosition); float distanceMinimum = glm::min(distanceToUnitCenter, glm::min(distanceToDestination, distanceToModifierArea)); _tappedUnitCenter = distanceToUnitCenter == distanceMinimum; _tappedDestination = distanceToDestination == distanceMinimum && !_tappedUnitCenter; _tappedModiferArea = distanceToModifierArea == distanceMinimum && !_tappedUnitCenter && !_tappedDestination; if (_tappedDestination || _tappedModiferArea) { _offsetToMarker = 0;//(_boardView->ContentToScreen(vector3(unit->movement.GetFinalDestination(), 0)).y - _boardView->ContentToScreen(vector3(terrainPosition, 0)).y) * GetFlipSign(); if (_offsetToMarker < 0) _offsetToMarker = 0; std::vector<glm::vec2>& path = _trackingMarker->_path; path.clear(); path.insert(path.begin(), command.path.begin(), command.path.end()); glm::vec2 orientation = command.GetDestination() + 18.0f * vector2_from_angle(command.bearing); _trackingMarker->SetOrientation(&orientation); } else { _offsetToMarker = 0;//(_boardView->ContentToScreen(vector3(unit->state.center, 0)).y - _boardView->ContentToScreen(vector3(terrainPosition, 0)).y) * GetFlipSign(); if (_offsetToMarker < 0) _offsetToMarker = 0; glm::vec2 orientation = unit->state.center + 18.0f * vector2_from_angle(unit->state.bearing); _trackingMarker->SetOrientation(&orientation); } if (touch->GetTapCount() > 1 && _tappedUnitCenter && !_tappedDestination) { UnitCommand command; command.ClearPathAndSetDestination(unit->state.center); _battleView->GetSimulator()->SetUnitCommand(unit, command, _battleView->GetSimulator()->GetTimerDelay()); } _trackingMarker->SetRunning(touch->GetTapCount() > 1 || (!_tappedUnitCenter && command.running)); CaptureTouch(touch); _trackingTouch = touch; } else if (_modifierTouch == nullptr) { CaptureTouch(touch); _modifierTouch = touch; } else { CaptureTouch(touch); _trackingTouch = touch; } } else if (_modifierTouch == nullptr) { if (unit != nullptr) return; if (_gestures != nullptr) { for (Gesture* g : *_gestures) { BattleGesture* gesture = dynamic_cast<BattleGesture*>(g); if (gesture != nullptr && gesture != this && gesture->_trackingTouch != nullptr) { if (glm::length(_trackingTouch->GetPosition() - touch->GetPosition()) > glm::length(gesture->_trackingTouch->GetPosition() - touch->GetPosition())) return; } } } CaptureTouch(touch); _modifierTouch = touch; } }
bool CommandOptimizer::add(UnitCommand command) { // ignore queued and invalid commands, or return if optimizer is disabled if (level == 0 || command.isQueued() || command.getType() >= UnitCommandTypes::None) return false; // Store some commonly accessed variables UnitCommandType uct = command.getType(); Unit utarg = command.getTarget(); UnitType targType = utarg ? utarg->getType() : UnitTypes::None; Unit uthis = command.getUnit(); UnitType thisType = uthis ? uthis->getType() : UnitTypes::None; // Exclude commands that cannot be optimized. if (uct == UnitCommandTypes::Build_Addon || uct == UnitCommandTypes::Land || uct == UnitCommandTypes::Build || uct == UnitCommandTypes::Place_COP || uct == UnitCommandTypes::Research || uct == UnitCommandTypes::Upgrade || (level < 4 && uct == UnitCommandTypes::Use_Tech_Unit && (command.getTechType() == TechTypes::Archon_Warp || command.getTechType() == TechTypes::Dark_Archon_Meld))) return false; // Simplify some commands if possible to decrease their size if (uct == UnitCommandTypes::Attack_Unit) { // Use Right Click for Attack Unit if (thisType.canAttack() && utarg && Broodwar->self() && Broodwar->self()->isEnemy(utarg->getPlayer())) command.type = UnitCommandTypes::Right_Click_Unit; } else if (uct == UnitCommandTypes::Move) { // Use Right Click for Move command = UnitCommand::rightClick(uthis, command.getTargetPosition()); } else if (uct == UnitCommandTypes::Gather) { // Use Right Click for gather if (targType.isResourceContainer()) command = UnitCommand::rightClick(uthis, utarg); } else if (uct == UnitCommandTypes::Set_Rally_Position) { // Use Right Click for Set Rally if (thisType.canProduce() && thisType != UnitTypes::Protoss_Carrier && thisType != UnitTypes::Hero_Gantrithor && thisType != UnitTypes::Protoss_Reaver && thisType != UnitTypes::Hero_Warbringer) command = UnitCommand::rightClick(uthis, command.getTargetPosition()); } else if (uct == UnitCommandTypes::Set_Rally_Unit) { // Use Right Click for Set Rally if (thisType.canProduce() && thisType != UnitTypes::Protoss_Carrier && thisType != UnitTypes::Hero_Gantrithor && thisType != UnitTypes::Protoss_Reaver && thisType != UnitTypes::Hero_Warbringer) command = UnitCommand::rightClick(uthis, utarg); } else if (uct == UnitCommandTypes::Use_Tech_Unit) { // Use Right Click for infestation if (command.getTechType() == TechTypes::Infestation && (thisType == UnitTypes::Zerg_Queen || thisType == UnitTypes::Hero_Matriarch) && targType == UnitTypes::Terran_Command_Center) command = UnitCommand::rightClick(uthis, utarg); } else if (uct == UnitCommandTypes::Train) { // Create a single placeholder since we assume it stores an interceptor or scarab when it's not important if (thisType == UnitTypes::Protoss_Carrier || thisType == UnitTypes::Hero_Gantrithor || thisType == UnitTypes::Protoss_Reaver || thisType == UnitTypes::Hero_Warbringer) command = UnitCommand::train(uthis, UnitTypes::Protoss_Interceptor); } else if (uct == UnitCommandTypes::Use_Tech) { // Simplify siege/cloak/burrow tech to their specific commands to allow grouping them switch (command.getTechType()) { case TechTypes::Enum::Tank_Siege_Mode: if (command.unit && command.unit->isSieged()) command = UnitCommand::unsiege(uthis); else command = UnitCommand::siege(uthis); break; case TechTypes::Enum::Personnel_Cloaking: case TechTypes::Enum::Cloaking_Field: if (command.unit && command.unit->isCloaked()) command = UnitCommand::decloak(uthis); else command = UnitCommand::cloak(uthis); break; case TechTypes::Enum::Burrowing: if (command.unit && command.unit->isBurrowed()) command = UnitCommand::unburrow(uthis); else command = UnitCommand::burrow(uthis); break; } } // Exclude commands not optimized at optimizer level 1 (no multi-select buildings) if (level <= 1 && thisType < UnitTypes::None && thisType.isBuilding()) return false; // Exclude commands not optimized at or below optimizer level 2 (no position commands) if (level <= 2 && (uct == UnitCommandTypes::Attack_Move || uct == UnitCommandTypes::Move || uct == UnitCommandTypes::Patrol || uct == UnitCommandTypes::Right_Click_Position || uct == UnitCommandTypes::Set_Rally_Position || uct == UnitCommandTypes::Unload_All_Position || uct == UnitCommandTypes::Use_Tech_Position)) return false; if (level >= 4) { // Convert tech unit target to tech position target commands so that they can be // optimized with nearby tech position commands of the same type. if (uct == UnitCommandTypes::Use_Tech_Unit && command.getTechType().targetsPosition() && utarg) command = UnitCommand::useTech(uthis, command.getTechType(), utarg->getPosition()); // Align locations to 32 pixels if (uct == UnitCommandTypes::Attack_Move || uct == UnitCommandTypes::Move || uct == UnitCommandTypes::Patrol || uct == UnitCommandTypes::Right_Click_Position || uct == UnitCommandTypes::Set_Rally_Position || uct == UnitCommandTypes::Unload_All_Position || uct == UnitCommandTypes::Use_Tech_Position) command = UnitCommand(uthis, uct, utarg, command.x & (~0x1F), command.y & (~0x1F), command.extra); else if (uct == UnitCommandTypes::Use_Tech_Unit && // Group Archon & Dark Archon merging (command.getTechType() == TechTypes::Archon_Warp || command.getTechType() == TechTypes::Dark_Archon_Meld)) command = UnitCommand::useTech(uthis, command.getTechType(), nullptr); } // Set last immediate command again in case it was altered when inserting it into the optimizer static_cast<UnitImpl*>(command.unit)->setLastImmediateCommand(command); // Add command to the command optimizer buffer and unload it later (newest commands first) optimizerQueue[command.getType().getID()].push_front(command); return true; }