void Micro::MutaDanceTarget(BWAPI::Unit muta, BWAPI::Unit target) { UAB_ASSERT(muta, "MutaDanceTarget: Muta not valid"); UAB_ASSERT(target, "MutaDanceTarget: Target not valid"); if (!muta || !target) { return; } const int cooldown = muta->getType().groundWeapon().damageCooldown(); const int latency = BWAPI::Broodwar->getLatency(); const double speed = muta->getType().topSpeed(); const double range = muta->getType().groundWeapon().maxRange(); const double distanceToTarget = muta->getDistance(target); const double distanceToFiringRange = std::max(distanceToTarget - range,0.0); const double timeToEnterFiringRange = distanceToFiringRange / speed; const int framesToAttack = static_cast<int>(timeToEnterFiringRange) + 2*latency; // How many frames are left before we can attack? const int currentCooldown = muta->isStartingAttack() ? cooldown : muta->getGroundWeaponCooldown(); BWAPI::Position fleeVector = GetKiteVector(target, muta); BWAPI::Position moveToPosition(muta->getPosition() + fleeVector); // If we can attack by the time we reach our firing range if(currentCooldown <= framesToAttack) { // Move towards and attack the target muta->attack(target); } else // Otherwise we cannot attack and should temporarily back off { // Determine direction to flee // Determine point to flee to if (moveToPosition.isValid()) { muta->rightClick(moveToPosition); } } }
void Micro::SmartAttackMove(BWAPI::Unit attacker, const BWAPI::Position & targetPosition) { //UAB_ASSERT(attacker, "SmartAttackMove: Attacker not valid"); //UAB_ASSERT(targetPosition.isValid(), "SmartAttackMove: targetPosition not valid"); if (!attacker || !targetPosition.isValid()) { return; } // if we have issued a command to this unit already this frame, ignore this one if (attacker->getLastCommandFrame() >= BWAPI::Broodwar->getFrameCount() || attacker->isAttackFrame()) { return; } // get the unit's current command BWAPI::UnitCommand currentCommand(attacker->getLastCommand()); // if we've already told this unit to attack this target, ignore this command if (currentCommand.getType() == BWAPI::UnitCommandTypes::Attack_Move && currentCommand.getTargetPosition() == targetPosition) { return; } // if nothing prevents it, attack the target attacker->attack(targetPosition); TotalCommands++; if (Config::Debug::DrawUnitTargetInfo) { BWAPI::Broodwar->drawCircleMap(attacker->getPosition(), dotRadius, BWAPI::Colors::Orange, true); BWAPI::Broodwar->drawCircleMap(targetPosition, dotRadius, BWAPI::Colors::Orange, true); BWAPI::Broodwar->drawLineMap(attacker->getPosition(), targetPosition, BWAPI::Colors::Orange); } }