//** Uses tech on triggering unit or all units when no enemy is within radius bool Fireteam::useAbilityOnClear(std::string name, int radius, bool includeBuildings, bool allUnits) { bool techUsed = false; std::set<BWAPI::Unit*> unitsToUseTech; std::set<BWAPI::Unit*> unitsInRange; bool enemyFound = false; for(std::set<BWAPI::Unit*>::const_iterator i=units.begin(); i != units.end(); i++) { unitsInRange = (*i)->getUnitsInRadius(radius); for(std::set<BWAPI::Unit*>::const_iterator j=unitsInRange.begin(); j != unitsInRange.end(); j++) { if((*j)->getPlayer()->isEnemy((*i)->getPlayer()) && ((*j)->getType().isBuilding() == false || includeBuildings)) { enemyFound = true; } } if(!enemyFound) { unitsToUseTech.insert((*i)); } } if(allUnits && !unitsToUseTech.empty()) { techUsed = useAbility(name); } else { for(std::set<BWAPI::Unit*>::const_iterator i=unitsToUseTech.begin(); i != unitsToUseTech.end(); i++) { if( (name != "Personnel_Cloaking" || !(*i)->isCloaked()) && (name != "Decloak" || (*i)->isCloaked()) && (name != "Tank_Siege_Mode" || !(*i)->isSieged()) && (name != "Unsiege" || (*i)->isSieged()) && (name != "Stim_Packs" || !(*i)->isStimmed()) && (name != "Defensive_Matrix" || !(*i)->isDefenseMatrixed()) ) { techUsed = true; if(name == "Unsiege") { (*i)->unsiege(); } else if(name == "Decloak") { (*i)->decloak(); } else { techUsed = (*i)->useTech(BWAPI::TechTypes::getTechType(name)); } } } } return techUsed; }
void Player::performAbility(double deltaTime, ObjectManager* manager, MainWindow* window) { // Check to see if the drop particles ability has been activated. if ((window->getMouseState() & Qt::LeftButton) || window->getKeyPressed(GameEngine::DROP)) dropParticles(manager); // Force push ability. Force push and force pull are only applied to // particles and stars. else if ((window->getMouseState() & Qt::RightButton) || window->getKeyPressed(GameEngine::PUSH)) forcePush(manager, deltaTime); // Force pull. else if ((window->getMouseState() & Qt::MiddleButton) || window->getKeyPressed(GameEngine::PULL)) forcePull(manager, deltaTime); // Use special ability. else if (window->getKeyPressed(GameEngine::ABILITY)) useAbility(deltaTime, manager); // Change special ability. else if (window->getKeyPressed(GameEngine::CHGABILITY)) changeAbility(deltaTime); // Perform any clean-up required for when a special ability has not been // activated. if (!window->getKeyPressed(GameEngine::ABILITY)) { // Reset the lightning target to prevent the lightning effect from // continuing to be drawn if this ability was activated on the last call // to update. lightningTarget = NULL; // Ditto for storm targets. stormTargets.clear(); } // If the change ability button is not pressed, then reset the variables for // keeping track of how often the player's special ability can be changed. if (!window->getKeyPressed(GameEngine::CHGABILITY)) { chgAbilityActivatedOnLastUpdate = false; timeSinceLastChgAbility = 0; } }
//** Uses tech on triggering unit or all units when a unit is attacked bool Fireteam::useAbilityOnAttacked(std::string name, bool allUnits) { bool techUsed = false; for(std::set<BWAPI::Unit*>::const_iterator i=units.begin(); i != units.end(); i++) { if((*i)->isUnderAttack() && (name != "Personnel_Cloaking" || !(*i)->isCloaked()) && (name != "Decloak" || (*i)->isCloaked()) && (name != "Tank_Siege_Mode" || !(*i)->isSieged()) && (name != "Unsiege" || (*i)->isSieged()) && (name != "Stim_Packs" || !(*i)->isStimmed()) && (name != "Defensive_Matrix" || !(*i)->isDefenseMatrixed()) ) { techUsed = true; if(allUnits) { techUsed = useAbility(name); break; } if(name == "Unsiege") { (*i)->unsiege(); } else if(name == "Decloak") { (*i)->decloak(); } else { techUsed = (*i)->useTech(BWAPI::TechTypes::getTechType(name)); } } } return techUsed; }