/// Returns target attack priority. /// Returned value must be greater than 0 int VultureManagerExt::getAttackPriority(BWAPI::Unit * selectedUnit, BWAPI::Unit * target) { BWAPI::UnitType selectedUnitType = selectedUnit->getType(); BWAPI::UnitType targetType = target->getType(); bool canAttackUs = targetType.groundWeapon() != BWAPI::WeaponTypes::None; int selectedUnitWeaponRange = selectedUnitType.groundWeapon().maxRange(); // 160, Concussive int targetWeaponRange = targetType.groundWeapon().maxRange(); // Larvas are low priority targets if (targetType == BWAPI::UnitTypes::Zerg_Larva || targetType == BWAPI::UnitTypes::Protoss_Interceptor) { return 1; } else if (targetType == BWAPI::UnitTypes::Protoss_Pylon) { return 3; } else if ((targetType.isBuilding()) && !(targetType.canAttack())) { return 2; } else if (targetType == BWAPI::UnitTypes::Protoss_Photon_Cannon) { return 4; } // Templars are extremely dangerous to bio units and should be eliminated asap. else if (targetType == BWAPI::UnitTypes::Protoss_High_Templar || targetType == BWAPI::UnitTypes::Terran_Medic) { return selectedUnitWeaponRange + 10; } // Faster than Marine (without Stimpack) else if ((targetType.topSpeed() >= selectedUnitType.topSpeed()) || ((targetType == BWAPI::UnitTypes::Protoss_Zealot) && (BWAPI::Broodwar->enemy()->getUpgradeLevel(BWAPI::UpgradeTypes::Leg_Enhancements) > 0))) { return selectedUnitWeaponRange; // return 160 } // Slower than Vulture else { int priority = selectedUnitWeaponRange - targetWeaponRange; if (priority <= 0) { priority = 1; } return priority; } }
// get the attack priority of a type in relation to a zergling int MeleeManager::getAttackPriority(BWAPI::Unit attacker, BWAPI::Unit unit) { BWAPI::UnitType type = unit->getType(); if (attacker->getType() == BWAPI::UnitTypes::Protoss_Dark_Templar && unit->getType() == BWAPI::UnitTypes::Terran_Missile_Turret && (BWAPI::Broodwar->self()->deadUnitCount(BWAPI::UnitTypes::Protoss_Dark_Templar) == 0)) { return 13; } if (attacker->getType() == BWAPI::UnitTypes::Protoss_Dark_Templar && unit->getType().isWorker()) { return 12; } // highest priority is something that can attack us or aid in combat if (type == BWAPI::UnitTypes::Terran_Bunker) { return 11; } else if (type == BWAPI::UnitTypes::Terran_Medic || (type.groundWeapon() != BWAPI::WeaponTypes::None && !type.isWorker()) || type == BWAPI::UnitTypes::Terran_Bunker || type == BWAPI::UnitTypes::Protoss_High_Templar || type == BWAPI::UnitTypes::Protoss_Reaver || (type.isWorker() && unitNearChokepoint(unit))) { return 10; } // next priority is worker else if (type.isWorker()) { return 9; } // next is special buildings else if (type == BWAPI::UnitTypes::Zerg_Spawning_Pool) { return 5; } // next is special buildings else if (type == BWAPI::UnitTypes::Protoss_Pylon) { return 5; } // next is buildings that cost gas else if (type.gasPrice() > 0) { return 4; } else if (type.mineralPrice() > 0) { return 3; } // then everything else else { return 1; } }
// test constructor for setting all variables of a unit Unit::Unit(const BWAPI::UnitType unitType, const Position & pos, const IDType & unitID, const IDType & playerID, const HealthType & hp, const HealthType & energy, const TimeType & tm, const TimeType & ta) : _unitType (unitType) , _range (PlayerWeapon(&PlayerProperties::Get(playerID), unitType.groundWeapon()).GetMaxRange() + Constants::Range_Addition) //, _range (unitType.groundWeapon().maxRange() + Constants::Range_Addition) , _position (pos) , _unitID (unitID) , _playerID (playerID) , _currentHP (hp) , _currentEnergy (energy) , _timeCanMove (tm) , _timeCanAttack (ta) , _previousActionTime (0) , _prevCurrentPosTime (0) { System::checkSupportedUnitType(unitType); }
// constructor for units to construct basic units, sets some things automatically Unit::Unit(const BWAPI::UnitType unitType, const IDType & playerID, const Position & pos) : _unitType (unitType) , _range (PlayerWeapon(&PlayerProperties::Get(playerID), unitType.groundWeapon()).GetMaxRange() + Constants::Range_Addition) //, _range (unitType.groundWeapon().maxRange() + Constants::Range_Addition) , _position (pos) , _unitID (0) , _playerID (playerID) , _currentHP (maxHP()) , _currentEnergy (unitType == BWAPI::UnitTypes::Terran_Medic ? Constants::Starting_Energy : 0) , _timeCanMove (0) , _timeCanAttack (0) , _previousActionTime (0) , _prevCurrentPosTime (0) , _previousPosition (pos) , _prevCurrentPos (pos) { System::checkSupportedUnitType(unitType); }
// constructor for units to construct basic units, sets some things automatically Unit::Unit(const BWAPI::UnitType unitType, const IDType & playerID, const Position & pos) : _unitType (unitType) , _range (PlayerWeapon(&PlayerProperties::Get(playerID), unitType.groundWeapon()).GetMaxRange() + unitType.dimensionDown() + 5/* + Constants::Range_Addition*/) //, _range (unitType.groundWeapon().maxRange() + Constants::Range_Addition) , _position (pos) , _unitID (0) , _playerID (playerID) , _currentHP (maxHP()) , _currentshield (maxshield()) , _currentEnergy ((unitType == BWAPI::UnitTypes::Terran_Medic) ||(unitType == BWAPI::UnitTypes::Protoss_High_Templar) ? Constants::Starting_Energy : 0) , _timeCanMove (0) , _timeCanAttack (0) , _timeCanCast (0) , _previousActionTime (0) , _previousPosition (pos) , _prevCurrentPosTime (0) , _prevCurrentPos (pos) , _isloaded (false) { System::checkSupportedUnitType(unitType); }
int RangedManager::getPriorityDefault(BWAPI::Unit rangedUnit, BWAPI::Unit target) { BWAPI::UnitType rangedType = rangedUnit->getType(); BWAPI::UnitType targetType = target->getType(); if (target->getType() == BWAPI::UnitTypes::Zerg_Overlord) return 1; if (target->getType() == BWAPI::UnitTypes::Protoss_Photon_Cannon || target->getType() == BWAPI::UnitTypes::Zerg_Sunken_Colony) { return 8; } if (rangedUnit->getType() == BWAPI::UnitTypes::Zerg_Scourge) { if (target->getType() == BWAPI::UnitTypes::Protoss_Carrier) { return 100; } if (target->getType() == BWAPI::UnitTypes::Protoss_Corsair) { return 90; } } bool isThreat = rangedType.isFlyer() ? targetType.airWeapon() != BWAPI::WeaponTypes::None : targetType.groundWeapon() != BWAPI::WeaponTypes::None; if (target->getType().isWorker()) { isThreat = false; } if (target->getType() == BWAPI::UnitTypes::Zerg_Larva || target->getType() == BWAPI::UnitTypes::Zerg_Egg) { return 0; } if (rangedUnit->isFlying() && target->getType() == BWAPI::UnitTypes::Protoss_Carrier) { return 101; } // if the target is building something near our base something is fishy // highest priority is something that can attack us or aid in combat if (targetType == BWAPI::UnitTypes::Terran_Bunker || isThreat) { return 11; } // next priority is worker else if (targetType.isWorker()) { if (order.getType() != SquadOrderTypes::Defend&&BWTA::getRegion(rangedUnit->getPosition()) != BWTA::getRegion(BWAPI::Broodwar->self()->getStartLocation())) { return 4; } else return 1; } // next is special buildings else if (targetType == BWAPI::UnitTypes::Zerg_Spawning_Pool) { return 5; } // next is special buildings else if (targetType == BWAPI::UnitTypes::Protoss_Pylon) { return 5; } // next is buildings that cost gas else if (targetType.gasPrice() > 0) { return 4; } else if (targetType.mineralPrice() > 0) { return 3; } // then everything else else { return 1; } }
BWAPI::WeaponType UnitUtil::GetWeapon(BWAPI::UnitType attacker, BWAPI::UnitType target) { return target.isFlyer() ? attacker.airWeapon() : attacker.groundWeapon(); }
// get the attack priority of a type in relation to a zergling int LurkerManager::getAttackPriority(BWAPI::Unit LurkerUnit, BWAPI::Unit target) { BWAPI::UnitType LurkerType = LurkerUnit->getType(); BWAPI::UnitType targetType = target->getType(); bool isThreat = LurkerType.isFlyer() ? targetType.airWeapon() != BWAPI::WeaponTypes::None : targetType.groundWeapon() != BWAPI::WeaponTypes::None; if (target->getType().isWorker()) { isThreat = false; } if (target->getType() == BWAPI::UnitTypes::Zerg_Larva || target->getType() == BWAPI::UnitTypes::Zerg_Egg) { return 0; } // if the target is building something near our base something is fishy BWAPI::Position ourBasePosition = BWAPI::Position(BWAPI::Broodwar->self()->getStartLocation()); if (target->getType().isWorker() && (target->isConstructing() || target->isRepairing()) && target->getDistance(ourBasePosition) < 1200) { return 100; } if (target->getType().isBuilding() && (target->isCompleted() || target->isBeingConstructed()) && target->getDistance(ourBasePosition) < 1200) { return 90; } // highest priority is something that can attack us or aid in combat if (targetType == BWAPI::UnitTypes::Terran_Bunker || isThreat) { return 11; } // next priority is worker else if (targetType.isWorker()) { return 11; } // next is special buildings else if (targetType == BWAPI::UnitTypes::Protoss_Pylon) { return 5; } // next is buildings that cost gas else if (targetType.gasPrice() > 0) { return 4; } else if (targetType.mineralPrice() > 0) { return 3; } // then everything else else { return 50; } }
int InterceptorManager::getPriorityDefault(BWAPI::Unit rangedUnit, BWAPI::Unit target) { BWAPI::UnitType rangedType = rangedUnit->getType(); BWAPI::UnitType targetType = target->getType(); if (target->getType() == BWAPI::UnitTypes::Protoss_Photon_Cannon || target->getType() == BWAPI::UnitTypes::Zerg_Sunken_Colony) { return 8; } if (rangedUnit->getType() == BWAPI::UnitTypes::Zerg_Scourge) { if (target->getType() == BWAPI::UnitTypes::Protoss_Carrier) { return 100; } if (target->getType() == BWAPI::UnitTypes::Protoss_Corsair) { return 90; } } bool isThreat = rangedType.isFlyer() ? targetType.airWeapon() != BWAPI::WeaponTypes::None : targetType.groundWeapon() != BWAPI::WeaponTypes::None; if (target->getType().isWorker()) { isThreat = false; } if (target->getType() == BWAPI::UnitTypes::Zerg_Larva || target->getType() == BWAPI::UnitTypes::Zerg_Egg) { return 0; } if (rangedUnit->isFlying() && target->getType() == BWAPI::UnitTypes::Protoss_Carrier) { return 101; } // if the target is building something near our base something is fishy BWAPI::Position ourBasePosition = BWAPI::Position(BWAPI::Broodwar->self()->getStartLocation()); if (target->getType().isWorker() && (target->isConstructing() || target->isRepairing()) && target->getDistance(ourBasePosition) < 1200) { return 100; } if (target->getType().isBuilding() && (target->isCompleted() || target->isBeingConstructed()) && target->getDistance(ourBasePosition) < 1200) { return 90; } // highest priority is something that can attack us or aid in combat if (targetType == BWAPI::UnitTypes::Terran_Bunker || isThreat) { return 11; } // next priority is worker else if (targetType.isWorker()) { if (rangedUnit->getType() == BWAPI::UnitTypes::Terran_Vulture) { return 11; } return 11; } // next is special buildings else if (targetType == BWAPI::UnitTypes::Zerg_Spawning_Pool) { return 5; } // next is special buildings else if (targetType == BWAPI::UnitTypes::Protoss_Pylon) { return 5; } // next is buildings that cost gas else if (targetType.gasPrice() > 0) { return 4; } else if (targetType.mineralPrice() > 0) { return 3; } // then everything else else { return 1; } }
// get the attack priority of a type in relation to a zergling int RangedManager::getAttackPriority(BWAPI::UnitInterface* rangedUnit, BWAPI::UnitInterface* target) { BWAPI::UnitType rangedUnitType = rangedUnit->getType(); BWAPI::UnitType targetType = target->getType(); bool canAttackUs = rangedUnitType.isFlyer() ? targetType.airWeapon() != BWAPI::WeaponTypes::None : targetType.groundWeapon() != BWAPI::WeaponTypes::None; // highest priority is something that can attack us or aid in combat if (targetType == BWAPI::UnitTypes::Terran_Medic || canAttackUs || targetType == BWAPI::UnitTypes::Terran_Bunker) { return 3; } // next priority is worker else if (targetType.isWorker()) { return 2; } // then everything else else { return 1; } }
Composition getCounters(BWAPI::UnitType enemyUnitType) { auto allUnitTypes = BWAPI::UnitTypes::allUnitTypes(); std::unordered_map<BWAPI::UnitType, int> unitTypeCounterAmount; //LF new name pls auto groundDamageType = enemyUnitType.groundWeapon().damageType(); auto airDamageType = enemyUnitType.airWeapon().damageType(); auto sizeType = enemyUnitType.size(); bool flyer = enemyUnitType.isFlyer(); for each (auto unitType in allUnitTypes) { if (unitType.getRace() != util::game::getSelf()->getRace() || unitType.isHero() || unitType.isBuilding() || unitType.isWorker()) continue; //if enemy unit flies and friendly unit can damage it... if (flyer) { if (unitType.airWeapon().damageAmount() > 0) { unitTypeCounterAmount[unitType]++; //if friendly unit flies and enemy unit can't damage it... if (!(enemyUnitType.airWeapon().damageAmount() > 0)) unitTypeCounterAmount[unitType]++; //if enemy unit damage type is concussive and friendly unit size is small... if (airDamageType == BWAPI::DamageTypes::Concussive && unitType.size() == BWAPI::UnitSizeTypes::Small) unitTypeCounterAmount[unitType]++; //if enemy unit damage type is explosive and friendly unit size is large... else if (airDamageType == BWAPI::DamageTypes::Explosive && unitType.size() == BWAPI::UnitSizeTypes::Large) unitTypeCounterAmount[unitType]++; //if enemy unit size is small and friendly damage type is explosive... if (sizeType == BWAPI::UnitSizeTypes::Small && unitType.airWeapon().damageType() == BWAPI::DamageTypes::Explosive) unitTypeCounterAmount[unitType]++; //if enemy unit size is medium or large and friendly damage type is concussive... else if ((sizeType == BWAPI::UnitSizeTypes::Medium || sizeType == BWAPI::UnitSizeTypes::Large) && unitType.airWeapon().damageType() == BWAPI::DamageTypes::Concussive) unitTypeCounterAmount[unitType]++; } else continue; } //if enemy unit is ground unit and friendly unit can damage it... if (!flyer && unitType.groundWeapon().damageAmount() > 0) { unitTypeCounterAmount[unitType]++; //if friendly unit flies and enemy unit can't damage it... if (unitType.isFlyer() && !(enemyUnitType.airWeapon().damageAmount() > 0)) unitTypeCounterAmount[unitType]++; //if enemy unit damage type is concussive and friendly unit size is small... if (groundDamageType == BWAPI::DamageTypes::Concussive && unitType.size() == BWAPI::UnitSizeTypes::Small) unitTypeCounterAmount[unitType]++; //if enemy unit damage type is explosive and friendly unit size is large... else if (groundDamageType == BWAPI::DamageTypes::Explosive && unitType.size() == BWAPI::UnitSizeTypes::Large) unitTypeCounterAmount[unitType]++; //if enemy unit size is small and friendly damage type is explosive... if (sizeType == BWAPI::UnitSizeTypes::Small && unitType.groundWeapon().damageType() == BWAPI::DamageTypes::Explosive) unitTypeCounterAmount[unitType]++; //if enemy unit size is medium or large and friendly damage type is concussive... else if ((sizeType == BWAPI::UnitSizeTypes::Medium || sizeType == BWAPI::UnitSizeTypes::Large) && unitType.groundWeapon().damageType() == BWAPI::DamageTypes::Concussive) unitTypeCounterAmount[unitType]++; } else continue; } Composition counterComposition; for (auto &unitType = unitTypeCounterAmount.begin(); unitType != unitTypeCounterAmount.end(); unitType++) { if (unitType->first == BWAPI::UnitTypes::Spell_Scanner_Sweep) counterComposition.addType(BWAPI::UnitTypes::Terran_Comsat_Station, unitType->second); else if (unitType->first == BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode) counterComposition.addType(BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode, unitType->second); else if(unitType->first == BWAPI::UnitTypes::Terran_Vulture_Spider_Mine) counterComposition.addType(BWAPI::UnitTypes::Terran_Vulture, unitType->second); else counterComposition.addType(unitType->first, unitType->second); } return counterComposition; }
/// Returns target attack priority. /// Returned value must be greater than 0 int BattlecruiserManagerExt::getAttackPriority(BWAPI::Unit * selectedUnit, BWAPI::Unit * target) { BWAPI::UnitType selectedUnitType = selectedUnit->getType(); BWAPI::UnitType targetType = target->getType(); bool canAttackUs = targetType.airWeapon() != BWAPI::WeaponTypes::None; int selectedUnitWeaponRange = selectedUnitType.groundWeapon().maxRange(); // 160, Concussive int targetWeaponRange = targetType.groundWeapon().maxRange(); // Detectors are top priority but Photon Cannons are too strong if (targetType == BWAPI::UnitTypes::Protoss_Carrier) { useYamatoGun(selectedUnit, target); return 99; } else if (targetType.isDetector() && targetType != BWAPI::UnitTypes::Protoss_Photon_Cannon) { useYamatoGun(selectedUnit, target); return 100; } // Larvas are low priority targets else if (targetType == BWAPI::UnitTypes::Zerg_Larva || targetType == BWAPI::UnitTypes::Protoss_Interceptor) { return 1; } else if (targetType == BWAPI::UnitTypes::Protoss_Pylon) { return 3; } else if ((targetType.isBuilding()) && !(targetType.canAttack())) { return 2; } // Workers are priority over ground units and buildings else if (targetType.isWorker()) { return 4; } else if (isTurret(target)) { // Attack tower if in its weapon range // Otherwise attack something else if (target->isInWeaponRange(selectedUnit)) { return 5; } else { return 1; } } // Anti air units are top priority else if (canAttackUs) { return selectedUnitWeaponRange + 10; } else { return 1; } }