BWAPI
|
#include <MacroManager.h>
Definition at line 74 of file MacroManager.h.
MacroManagerClass::MacroManagerClass | ( | ) | [inline] |
Definition at line 77 of file MacroManager.h.
{}
void MacroManagerClass::addNeeded | ( | std::set< BWAPI::UnitType > & | neededUnits | ) | [private] |
Definition at line 534 of file MacroManager.cpp.
References isPlanningUnit(), BWAPI::UnitType::requiredUnits(), BWAPI::UnitType::whatBuilds(), BWAPI::UnitTypes::Zerg_Hatchery, and BWAPI::UnitTypes::Zerg_Larva.
Referenced by getNeededUnits().
{ bool addedUnits = false; std::set<BWAPI::UnitType> tempList; for each(BWAPI::UnitType type in neededUnits) { BWAPI::UnitType whatBuilds = type.whatBuilds().first; if(whatBuilds == BWAPI::UnitTypes::Zerg_Larva) whatBuilds = BWAPI::UnitTypes::Zerg_Hatchery; if(!isPlanningUnit(whatBuilds) && neededUnits.count(whatBuilds) == 0) { addedUnits = true; tempList.insert(whatBuilds); } for(std::map<BWAPI::UnitType, int>::const_iterator it = type.requiredUnits().begin(); it != type.requiredUnits().end(); ++it) { if (it->first == BWAPI::UnitTypes::Zerg_Larva) continue; if(!isPlanningUnit(it->first) && neededUnits.count(it->first) == 0) { addedUnits = true; tempList.insert(it->first); } } } neededUnits.insert(tempList.begin(), tempList.end()); if(addedUnits) addNeeded(neededUnits); }
void MacroManagerClass::createTechItems | ( | ) | [private] |
Definition at line 716 of file MacroManager.cpp.
References Singleton< T >::Instance(), OrderDef::MacroCanTech, TaskTypeDef::MacroTech, mTechItems, and mTechItemsToCreate.
Referenced by onChangeBuild(), and update().
{ if(!mTechItemsToCreate.empty() && BuildOrderManager::Instance().getOrder(Order::MacroCanTech)) { for(std::list<MacroItem>::iterator it = mTechItemsToCreate.begin(); it != mTechItemsToCreate.end(); ++it) { TaskPointer task = it->createTask(TaskType::MacroTech); if(task) mTechItems.push_back(std::make_pair(*it, task)); } mTechItemsToCreate.clear(); } }
std::set< BWAPI::UnitType > MacroManagerClass::getNeededUnits | ( | BWAPI::UnitType | type | ) |
Definition at line 476 of file MacroManager.cpp.
References addNeeded(), isPlanningUnit(), BWAPI::UnitType::requiredUnits(), BWAPI::UnitType::whatBuilds(), BWAPI::UnitTypes::Zerg_Hatchery, and BWAPI::UnitTypes::Zerg_Larva.
Referenced by onChangeBuild().
{ std::set<BWAPI::UnitType> neededUnits; BWAPI::UnitType whatBuilds = type.whatBuilds().first; if(whatBuilds == BWAPI::UnitTypes::Zerg_Larva) whatBuilds = BWAPI::UnitTypes::Zerg_Hatchery; if(!isPlanningUnit(whatBuilds)) neededUnits.insert(whatBuilds); for(std::map<BWAPI::UnitType, int>::const_iterator it = type.requiredUnits().begin(); it != type.requiredUnits().end(); ++it) { if(it->first == BWAPI::UnitTypes::Zerg_Larva) continue; if(!isPlanningUnit(it->first)) neededUnits.insert(it->first); } addNeeded(neededUnits); return neededUnits; }
std::set< BWAPI::UnitType > MacroManagerClass::getNeededUnits | ( | BWAPI::TechType | type | ) |
Definition at line 502 of file MacroManager.cpp.
References addNeeded(), isPlanningUnit(), and BWAPI::TechType::whatResearches().
{ std::set<BWAPI::UnitType> neededUnits; if(!isPlanningUnit(type.whatResearches())) neededUnits.insert(type.whatResearches()); addNeeded(neededUnits); return neededUnits; }
std::set< BWAPI::UnitType > MacroManagerClass::getNeededUnits | ( | BWAPI::UpgradeType | type, |
int | level | ||
) |
Definition at line 513 of file MacroManager.cpp.
References addNeeded(), isPlanningUnit(), BWAPI::UpgradeTypes::Protoss_Air_Armor, BWAPI::UpgradeTypes::Protoss_Air_Weapons, BWAPI::UnitTypes::Protoss_Cybernetics_Core, BWAPI::UnitTypes::Protoss_Fleet_Beacon, BWAPI::UpgradeTypes::Protoss_Ground_Armor, BWAPI::UpgradeTypes::Protoss_Ground_Weapons, BWAPI::UpgradeTypes::Protoss_Plasma_Shields, BWAPI::UnitTypes::Protoss_Templar_Archives, and BWAPI::UpgradeType::whatUpgrades().
{ std::set<BWAPI::UnitType> neededUnits; if(!isPlanningUnit(type.whatUpgrades())) neededUnits.insert(type.whatUpgrades()); if(level > 1) { if((type == BWAPI::UpgradeTypes::Protoss_Ground_Weapons || type == BWAPI::UpgradeTypes::Protoss_Ground_Armor) && !isPlanningUnit(BWAPI::UnitTypes::Protoss_Templar_Archives)) neededUnits.insert(BWAPI::UnitTypes::Protoss_Templar_Archives); else if(type == BWAPI::UpgradeTypes::Protoss_Plasma_Shields && !isPlanningUnit(BWAPI::UnitTypes::Protoss_Cybernetics_Core)) neededUnits.insert(BWAPI::UnitTypes::Protoss_Cybernetics_Core); else if((type == BWAPI::UpgradeTypes::Protoss_Air_Armor || type == BWAPI::UpgradeTypes::Protoss_Air_Weapons) && !isPlanningUnit(BWAPI::UnitTypes::Protoss_Fleet_Beacon)) neededUnits.insert(BWAPI::UnitTypes::Protoss_Fleet_Beacon); } addNeeded(neededUnits); return neededUnits; }
int MacroManagerClass::getPlannedCount | ( | BWAPI::UnitType | unitType | ) |
Definition at line 569 of file MacroManager.cpp.
References mTasksPerProducedType.
Referenced by getPlannedTotal().
{ int count = 0; for each(TaskPointer task in mTasksPerProducedType[unitType]) { if(!task->inProgress()) ++count; } return count; }
int MacroManagerClass::getPlannedCount | ( | BWAPI::TechType | techType | ) |
Definition at line 591 of file MacroManager.cpp.
References mTasksPerTechType.
{ int count = 0; for each(TaskPointer task in mTasksPerTechType[techType]) { if(!task->inProgress()) ++count; } return count; }
int MacroManagerClass::getPlannedCount | ( | BWAPI::UpgradeType | upgradeType, |
int | level | ||
) |
Definition at line 613 of file MacroManager.cpp.
References mTasksPerUpgradeType.
{ int count = 0; for each(TaskPointer task in mTasksPerUpgradeType[upgradeType][level]) { if(!task->inProgress()) ++count; } return count; }
int MacroManagerClass::getPlannedTotal | ( | BWAPI::UnitType | unitType | ) |
Definition at line 581 of file MacroManager.cpp.
References BWAPI::Player::allUnitCount(), BWAPI::Broodwar, getPlannedCount(), and BWAPI::Game::self().
Referenced by isPlanningTech(), isPlanningUnit(), isPlanningUpgrade(), and updateObserverProduction().
{ return getPlannedCount(unitType) + BWAPI::Broodwar->self()->allUnitCount(unitType); }
int MacroManagerClass::getPlannedTotal | ( | BWAPI::TechType | techType | ) |
Definition at line 603 of file MacroManager.cpp.
References BWAPI::Broodwar, getPlannedCount(), BWAPI::Player::hasResearched(), and BWAPI::Game::self().
{ return getPlannedCount(techType) + (BWAPI::Broodwar->self()->hasResearched(techType) ? 1 : 0); }
int MacroManagerClass::getPlannedTotal | ( | BWAPI::UpgradeType | upgradeType, |
int | level | ||
) |
Definition at line 625 of file MacroManager.cpp.
References BWAPI::Broodwar, getPlannedCount(), BWAPI::Player::getUpgradeLevel(), and BWAPI::Game::self().
{ return getPlannedCount(upgradeType, level) + (BWAPI::Broodwar->self()->getUpgradeLevel(upgradeType) >= level ? 1 : 0); }
bool MacroManagerClass::hasRequirements | ( | BWAPI::UnitType | type | ) |
Definition at line 433 of file MacroManager.cpp.
References BWAPI::Broodwar, BWAPI::UnitType::requiredUnits(), and BWAPI::UnitType::whatBuilds().
Referenced by updateObserverProduction(), updateProductionProduction(), and updateUnitProduction().
{ if(BWAPI::Broodwar->self()->completedUnitCount(type.whatBuilds().first) == 0) return false; for(std::map<BWAPI::UnitType, int>::const_iterator it = type.requiredUnits().begin(); it != type.requiredUnits().end(); ++it) { if(BWAPI::Broodwar->self()->completedUnitCount(it->first) == 0) return false; } return true; }
bool MacroManagerClass::hasRequirements | ( | BWAPI::TechType | type | ) |
Definition at line 447 of file MacroManager.cpp.
References BWAPI::Broodwar, and BWAPI::TechType::whatResearches().
{ if(BWAPI::Broodwar->self()->completedUnitCount(type.whatResearches()) == 0) return false; return true; }
bool MacroManagerClass::hasRequirements | ( | BWAPI::UpgradeType | type, |
int | level | ||
) |
Definition at line 455 of file MacroManager.cpp.
References BWAPI::Broodwar, BWAPI::Player::completedUnitCount(), BWAPI::UpgradeTypes::Protoss_Air_Armor, BWAPI::UpgradeTypes::Protoss_Air_Weapons, BWAPI::UnitTypes::Protoss_Cybernetics_Core, BWAPI::UnitTypes::Protoss_Fleet_Beacon, BWAPI::UpgradeTypes::Protoss_Ground_Armor, BWAPI::UpgradeTypes::Protoss_Ground_Weapons, BWAPI::UpgradeTypes::Protoss_Plasma_Shields, BWAPI::UnitTypes::Protoss_Templar_Archives, BWAPI::Game::self(), and BWAPI::UpgradeType::whatUpgrades().
{ if(BWAPI::Broodwar->self()->completedUnitCount(type.whatUpgrades()) == 0) return false; if(level != 1 && BWAPI::Broodwar->self()->getUpgradeLevel(type) != (level - 1)) return false; if(level > 1) { if((type == BWAPI::UpgradeTypes::Protoss_Ground_Weapons || type == BWAPI::UpgradeTypes::Protoss_Ground_Armor) && BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Protoss_Templar_Archives) == 0) return false; else if(type == BWAPI::UpgradeTypes::Protoss_Plasma_Shields && BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Protoss_Cybernetics_Core) == 0) return false; else if((type == BWAPI::UpgradeTypes::Protoss_Air_Armor || type == BWAPI::UpgradeTypes::Protoss_Air_Weapons) && BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Protoss_Fleet_Beacon) == 0) return false; } return true; }
bool MacroManagerClass::isPlanningTech | ( | BWAPI::TechType | techType | ) |
Definition at line 608 of file MacroManager.cpp.
References getPlannedTotal().
{ return getPlannedTotal(techType) != 0; }
bool MacroManagerClass::isPlanningUnit | ( | BWAPI::UnitType | unitType | ) |
Definition at line 586 of file MacroManager.cpp.
References getPlannedTotal().
Referenced by addNeeded(), and getNeededUnits().
{ return getPlannedTotal(unitType) != 0; }
bool MacroManagerClass::isPlanningUpgrade | ( | BWAPI::UpgradeType | upgradeType, |
int | level | ||
) |
Definition at line 630 of file MacroManager.cpp.
References getPlannedTotal().
{ return getPlannedTotal(upgradeType, level) != 0; }
void MacroManagerClass::onBegin | ( | ) |
Definition at line 8 of file MacroManager.cpp.
References BWAPI::UpgradeTypes::Adrenal_Glands, BWAPI::UpgradeTypes::Anabolic_Synthesis, BWAPI::UpgradeTypes::Antennae, BWAPI::UpgradeTypes::Apial_Sensors, BWAPI::UpgradeTypes::Apollo_Reactor, BWAPI::TechTypes::Archon_Warp, BWAPI::UpgradeTypes::Argus_Jewel, BWAPI::UpgradeTypes::Argus_Talisman, BWAPI::Orders::Burrowing, BWAPI::UpgradeTypes::Caduceus_Reactor, BWAPI::UpgradeTypes::Carrier_Capacity, BWAPI::UpgradeTypes::Charon_Boosters, BWAPI::UpgradeTypes::Chitinous_Plating, BWAPI::TechTypes::Cloaking_Field, BWAPI::UpgradeTypes::Colossus_Reactor, BWAPI::BulletTypes::Consume, BWAPI::TechTypes::Dark_Archon_Meld, BWAPI::ExplosionTypes::Dark_Swarm, BWAPI::TechTypes::Defensive_Matrix, BWAPI::ExplosionTypes::Disruption_Web, BWAPI::ExplosionTypes::EMP_Shockwave, BWAPI::ExplosionTypes::Ensnare, BWAPI::ExplosionTypes::Feedback, BWAPI::UpgradeTypes::Gamete_Meiosis, BWAPI::UpgradeTypes::Gravitic_Boosters, BWAPI::UpgradeTypes::Gravitic_Drive, BWAPI::UpgradeTypes::Gravitic_Thrusters, BWAPI::UpgradeTypes::Grooved_Spines, BWAPI::TechTypes::Hallucination, BWAPI::TechTypes::Healing, BWAPI::TechTypes::Infestation, Singleton< T >::Instance(), BWAPI::UpgradeTypes::Ion_Thrusters, BWAPI::ExplosionTypes::Irradiate, BWAPI::UpgradeTypes::Khaydarin_Amulet, BWAPI::UpgradeTypes::Khaydarin_Core, BWAPI::UpgradeTypes::Leg_Enhancements, BWAPI::ExplosionTypes::Lockdown, BWAPI::TechTypes::Lurker_Aspect, BWAPI::ExplosionTypes::Maelstrom, BWAPI::UpgradeTypes::Metabolic_Boost, BWAPI::UpgradeTypes::Metasynaptic_Node, BWAPI::ExplosionTypes::Mind_Control, BWAPI::UpgradeTypes::Moebius_Reactor, mTechPriorityMap, mUpgradePriorityMap, BWAPI::UpgradeTypes::Muscular_Augments, BWAPI::TechTypes::Nuclear_Strike, BWAPI::UpgradeTypes::Ocular_Implants, BWAPI::ExplosionTypes::Optical_Flare, BWAPI::ExplosionTypes::Parasite, BWAPI::TechTypes::Personnel_Cloaking, BWAPI::ExplosionTypes::Plague, BWAPI::UpgradeTypes::Pneumatized_Carapace, BWAPI::Races::Protoss, BWAPI::UpgradeTypes::Protoss_Air_Armor, BWAPI::UpgradeTypes::Protoss_Air_Weapons, BWAPI::UpgradeTypes::Protoss_Ground_Armor, BWAPI::UpgradeTypes::Protoss_Ground_Weapons, BWAPI::UpgradeTypes::Protoss_Plasma_Shields, BWAPI::BulletTypes::Psionic_Storm, BWAPI::UpgradeTypes::Reaver_Capacity, BWAPI::TechTypes::Recall, BWAPI::ExplosionTypes::Restoration, BWAPI::TechTypes::Scanner_Sweep, BWAPI::UpgradeTypes::Scarab_Damage, BWAPI::UpgradeTypes::Sensor_Array, BWAPI::UpgradeTypes::Singularity_Charge, BWAPI::TechTypes::Spawn_Broodlings, BWAPI::TechTypes::Spider_Mines, BWAPI::ExplosionTypes::Stasis_Field, BWAPI::TechTypes::Stim_Packs, BWAPI::TechTypes::Tank_Siege_Mode, BWAPI::UpgradeTypes::Terran_Infantry_Armor, BWAPI::UpgradeTypes::Terran_Infantry_Weapons, BWAPI::UpgradeTypes::Terran_Ship_Plating, BWAPI::UpgradeTypes::Terran_Ship_Weapons, BWAPI::UpgradeTypes::Terran_Vehicle_Plating, BWAPI::UpgradeTypes::Terran_Vehicle_Weapons, BWAPI::UpgradeTypes::Titan_Reactor, BWAPI::UpgradeTypes::U_238_Shells, BWAPI::UpgradeTypes::Ventral_Sacs, BWAPI::BulletTypes::Yamato_Gun, BWAPI::Races::Zerg, BWAPI::UpgradeTypes::Zerg_Carapace, BWAPI::UpgradeTypes::Zerg_Flyer_Attacks, BWAPI::UpgradeTypes::Zerg_Flyer_Carapace, BWAPI::UpgradeTypes::Zerg_Melee_Attacks, and BWAPI::UpgradeTypes::Zerg_Missile_Attacks.
{ using namespace BWAPI::TechTypes; using namespace BWAPI::UpgradeTypes; //Terran Tech mTechPriorityMap[Tank_Siege_Mode] = 110; mTechPriorityMap[Spider_Mines] = 100; mTechPriorityMap[Stim_Packs] = 90; mTechPriorityMap[Yamato_Gun] = 90; //Battlecruiser mTechPriorityMap[Cloaking_Field] = 85; mTechPriorityMap[Irradiate] = PlayerTracker::Instance().isEnemyRace(BWAPI::Races::Zerg) ? 89 : 0; mTechPriorityMap[EMP_Shockwave] = PlayerTracker::Instance().isEnemyRace(BWAPI::Races::Protoss) ? 99 : 0; mTechPriorityMap[Personnel_Cloaking] = 75; mTechPriorityMap[Healing] = 10; mTechPriorityMap[Lockdown] = 10; mTechPriorityMap[Restoration] = 10; mTechPriorityMap[Optical_Flare] = 5; //Pre Researched mTechPriorityMap[Nuclear_Strike] = 0; mTechPriorityMap[Scanner_Sweep] = 0; mTechPriorityMap[Defensive_Matrix] = 0; //Zerg Tech mTechPriorityMap[Burrowing] = 100; mTechPriorityMap[Consume] = 100; mTechPriorityMap[Dark_Swarm] = 100; mTechPriorityMap[Ensnare] = 100; mTechPriorityMap[Infestation] = 100; mTechPriorityMap[Lurker_Aspect] = 100; mTechPriorityMap[Parasite] = 100; mTechPriorityMap[Plague] = 100; mTechPriorityMap[Spawn_Broodlings] = 100; //Protoss Tech mTechPriorityMap[Disruption_Web] = 0; mTechPriorityMap[Feedback] = 0; mTechPriorityMap[Hallucination] = 0; mTechPriorityMap[Maelstrom] = 0; //Dark Arcon freezes targeted units mTechPriorityMap[Mind_Control] = 0; mTechPriorityMap[Psionic_Storm] = 120; mTechPriorityMap[Recall] = 90; mTechPriorityMap[Stasis_Field] = 80; //Pre Researched mTechPriorityMap[Archon_Warp] = 0; mTechPriorityMap[Dark_Archon_Meld] = 0; //Terran Upgrades mUpgradePriorityMap[Terran_Infantry_Armor] = 85; mUpgradePriorityMap[Terran_Infantry_Weapons] = 90; mUpgradePriorityMap[Terran_Ship_Plating] = 65; mUpgradePriorityMap[Terran_Ship_Weapons] = 60; mUpgradePriorityMap[Terran_Vehicle_Plating] = 85; mUpgradePriorityMap[Terran_Vehicle_Weapons] = 90; mUpgradePriorityMap[U_238_Shells] = 85; //Marine Range mUpgradePriorityMap[Charon_Boosters] = 85; //Goliath Range mUpgradePriorityMap[Ion_Thrusters] = 95; //Vulture Speed mUpgradePriorityMap[Apollo_Reactor] = 40; //Wraith Energy mUpgradePriorityMap[Caduceus_Reactor] = 60; //Medic Energy mUpgradePriorityMap[Colossus_Reactor] = 40; //Battlecruiser Energy mUpgradePriorityMap[Moebius_Reactor] = 40; //Ghost Energy Upgrade mUpgradePriorityMap[Ocular_Implants] = 40; //Ghost Sight Range mUpgradePriorityMap[Titan_Reactor] = 70; //Science Vessel Energy //Zerg Upgrades mUpgradePriorityMap[Ventral_Sacs] = 80; //Overlord drop mUpgradePriorityMap[Zerg_Carapace] = 95; mUpgradePriorityMap[Zerg_Flyer_Attacks] = 100; mUpgradePriorityMap[Zerg_Flyer_Carapace] = 95; mUpgradePriorityMap[Zerg_Melee_Attacks] = 100; mUpgradePriorityMap[Zerg_Missile_Attacks] = 100; mUpgradePriorityMap[Metabolic_Boost] = 100; //Zergling Movement Speed mUpgradePriorityMap[Adrenal_Glands] = 100; //Zergling Attack Speed mUpgradePriorityMap[Anabolic_Synthesis] = 100; //Ultralisk Speed mUpgradePriorityMap[Antennae] = 100; //Overlord Sight Range mUpgradePriorityMap[Chitinous_Plating] = 100; //Ultralisk +2 armor mUpgradePriorityMap[Gamete_Meiosis] = 100; // Zerg queen Energy mUpgradePriorityMap[Grooved_Spines] = 100; // Hydralisk range mUpgradePriorityMap[Metasynaptic_Node] = 100; // Defiler Energy mUpgradePriorityMap[Muscular_Augments] = 100; //Hydralisk Speed mUpgradePriorityMap[Pneumatized_Carapace] = 100; //Overlord Speed //Protoss Upgrades mUpgradePriorityMap[Protoss_Air_Weapons] = 0; mUpgradePriorityMap[Protoss_Air_Armor] = 0; mUpgradePriorityMap[Protoss_Ground_Weapons] = 100; mUpgradePriorityMap[Protoss_Plasma_Shields] = 70; mUpgradePriorityMap[Protoss_Ground_Armor] = 95; mUpgradePriorityMap[Reaver_Capacity] = 85; //More scarabs mUpgradePriorityMap[Scarab_Damage] = 100; //Increase Reaver Scarab Damage mUpgradePriorityMap[Singularity_Charge] = 110; //Dragoon Range mUpgradePriorityMap[Carrier_Capacity] = 110; //MOAR INTERCEPTORS! mUpgradePriorityMap[Apial_Sensors] = 100; //Scout Sight mUpgradePriorityMap[Argus_Jewel] = 100; //Cosair Energy mUpgradePriorityMap[Argus_Talisman] = 100; //Dark Archon Energy mUpgradePriorityMap[Gravitic_Boosters] = 80; //Observer Speed mUpgradePriorityMap[Gravitic_Drive] = 97; //Shuttle Speed mUpgradePriorityMap[Gravitic_Thrusters] = 100; //Scout Speed mUpgradePriorityMap[Khaydarin_Amulet] = 90; //High Templar Energy mUpgradePriorityMap[Khaydarin_Core] = 80; //Arbitor Energy mUpgradePriorityMap[Leg_Enhancements] = 110; //Zealot Speed Upgrades mUpgradePriorityMap[Sensor_Array] = 60; // Observer Sight }
void MacroManagerClass::onBuildTask | ( | TaskPointer | task, |
BWAPI::UnitType | unitType | ||
) |
Definition at line 698 of file MacroManager.cpp.
References mTasksPerProducedType, mTasksPerProductionType, and BWAPI::UnitType::whatBuilds().
{ mTasksPerProductionType[unitType.whatBuilds().first].push_back(task); mTasksPerProducedType[unitType].push_back(task); }
void MacroManagerClass::onChangeBuild | ( | ) |
Definition at line 253 of file MacroManager.cpp.
References BWAPI::UnitType::abilities(), BWAPI::Broodwar, createTechItems(), BWAPI::UnitType::gasPrice(), getNeededUnits(), UnitToProduce::getPriority(), BWAPI::Races::getRace(), UnitToProduce::getUnitType(), BWAPI::UpgradeTypes::Gravitic_Drive, Singleton< T >::Instance(), macroCompare(), BWAPI::UpgradeType::maxRepeats(), BWAPI::UnitType::mineralPrice(), mLowGasUnits, mLowMineralUnits, mNormalUnits, mTechItems, mTechItemsToCreate, mTechPriorityMap, mUpgradePriorityMap, BWAPI::Races::Protoss, BWAPI::UpgradeTypes::Protoss_Air_Weapons, BWAPI::UnitTypes::Protoss_Carrier, BWAPI::UnitTypes::Protoss_Observer, BWAPI::UnitTypes::Protoss_Photon_Cannon, BWAPI::UnitTypes::Protoss_Reaver, BWAPI::UpgradeTypes::Scarab_Damage, updateTaskLists(), and BWAPI::UnitType::upgrades().
{ mNormalUnits.clear(); mLowMineralUnits.clear(); mLowGasUnits.clear(); mNormalUnits = BuildOrderManager::Instance().getCurrentBuild().getUnitsToProduce(); for each(UnitToProduce unit in mNormalUnits) { double mineralToGasRatio = unit.getUnitType().gasPrice() == 0 ? 1 : double(unit.getUnitType().mineralPrice())/double(unit.getUnitType().gasPrice()); double gasToMineralRatio = unit.getUnitType().mineralPrice() == 0 ? 1 : double(unit.getUnitType().gasPrice())/double(unit.getUnitType().mineralPrice()); if(gasToMineralRatio < 0.4) mLowGasUnits.push_back(unit); else if(mineralToGasRatio < 0.4) mLowMineralUnits.push_back(unit); } for(std::list<std::pair<MacroItem, TaskPointer>>::iterator it = mTechItems.begin(); it != mTechItems.end(); ++it) { if(!it->second->inProgress()) it->second->cancel(); } mTechItems.clear(); mTechItemsToCreate.clear(); updateTaskLists(); std::list<UnitToProduce> normalWithExtra = mNormalUnits; if(BWAPI::Broodwar->self()->getRace() == BWAPI::Races::Protoss) { normalWithExtra.push_back(UnitToProduce(BWAPI::UnitTypes::Protoss_Observer, 1, 115)); normalWithExtra.push_back(UnitToProduce(BWAPI::UnitTypes::Protoss_Photon_Cannon, 1, 95)); } std::set<BWAPI::TechType> techSet; std::set<BWAPI::UpgradeType> upgradeSet; for each(UnitToProduce unit in normalWithExtra) { for each(BWAPI::UnitType type in getNeededUnits(unit.getUnitType())) { mTechItemsToCreate.push_back(MacroItem(type, unit.getPriority())); } for each(BWAPI::TechType tech in unit.getUnitType().abilities()) { techSet.insert(tech); } for each(BWAPI::UpgradeType upgrade in unit.getUnitType().upgrades()) { upgradeSet.insert(upgrade); } if(unit.getUnitType() == BWAPI::UnitTypes::Protoss_Reaver) { // Scarab damage doesn't pick up under its upgrades upgradeSet.insert(BWAPI::UpgradeTypes::Scarab_Damage); // Reaver is usually used with shuttle, speed upgrade will probably help upgradeSet.insert(BWAPI::UpgradeTypes::Gravitic_Drive); } else if(unit.getUnitType() == BWAPI::UnitTypes::Protoss_Carrier) upgradeSet.insert(BWAPI::UpgradeTypes::Protoss_Air_Weapons); } for each(BWAPI::TechType tech in techSet) { if(mTechPriorityMap[tech] < 30) continue; mTechItemsToCreate.push_back(MacroItem(tech, mTechPriorityMap[tech])); for each(BWAPI::UnitType type in getNeededUnits(tech)) { mTechItemsToCreate.push_back(MacroItem(type, mTechPriorityMap[tech])); } } for each(BWAPI::UpgradeType upgrade in upgradeSet) { if(mUpgradePriorityMap[upgrade] < 30) continue; for(int i = 1; i <= upgrade.maxRepeats(); ++i) { int priority = mUpgradePriorityMap[upgrade] - ((i-1)*10); mTechItemsToCreate.push_back(MacroItem(upgrade, i, priority)); for each(BWAPI::UnitType type in getNeededUnits(upgrade, i)) { mTechItemsToCreate.push_back(MacroItem(type, priority)); } } } mTechItemsToCreate.sort(macroCompare); //remove duplicates now so the highest is kept std::set<BWAPI::UnitType> unitSet; for(std::list<MacroItem>::iterator it = mTechItemsToCreate.begin(); it != mTechItemsToCreate.end();) { if(it->isUnitType()) { if(unitSet.count(it->getUnitType()) != 0) { mTechItemsToCreate.erase(it++); continue; } else unitSet.insert(it->getUnitType()); } ++it; } createTechItems(); }
void MacroManagerClass::onTechTask | ( | TaskPointer | task, |
BWAPI::TechType | techType | ||
) |
Definition at line 704 of file MacroManager.cpp.
References mTasksPerProductionType, mTasksPerTechType, and BWAPI::TechType::whatResearches().
{ mTasksPerProductionType[techType.whatResearches()].push_back(task); mTasksPerTechType[techType].push_back(task); }
void MacroManagerClass::onUpgradeTask | ( | TaskPointer | task, |
BWAPI::UpgradeType | upgradeType, | ||
int | level | ||
) |
Definition at line 710 of file MacroManager.cpp.
References mTasksPerProductionType, mTasksPerUpgradeType, and BWAPI::UpgradeType::whatUpgrades().
{ mTasksPerProductionType[upgradeType.whatUpgrades()].push_back(task); mTasksPerUpgradeType[upgradeType][level].push_back(task); }
void MacroManagerClass::update | ( | ) |
Definition at line 114 of file MacroManager.cpp.
References createTechItems(), BWAPI::Orders::getOrder(), Singleton< T >::Instance(), OrderDef::MacroArmyProduction, OrderDef::MacroCanTech, OrderDef::MacroProductionFacilities, updateObserverProduction(), updateProductionProduction(), updateTaskLists(), updateTech(), and updateUnitProduction().
{ updateTaskLists(); if(BuildOrderManager::Instance().getOrder(Order::MacroArmyProduction)) { updateObserverProduction(); updateUnitProduction(); } if(BuildOrderManager::Instance().getOrder(Order::MacroProductionFacilities)) updateProductionProduction(); if(BuildOrderManager::Instance().getOrder(Order::MacroCanTech)) createTechItems(); updateTech(); /*int y = 60; for each(std::pair<MacroItem, TaskPointer> item in mTechItems) { if(item.second->inProgress()) BWAPI::Broodwar->drawTextScreen(5, y, "%s : (In Progress)", item.first.getDebugInfo().c_str()); else BWAPI::Broodwar->drawTextScreen(5, y, "%s", item.first.getDebugInfo().c_str()); y += 10; }*/ }
Definition at line 375 of file MacroManager.cpp.
References TaskTypeDef::Army, BWAPI::Broodwar, TaskTypeDef::Defense, getPlannedTotal(), BWAPI::Races::getRace(), hasRequirements(), Singleton< T >::Instance(), TaskTypeDef::MacroUrgent, mObserver, BWAPI::Races::Protoss, and BWAPI::UnitTypes::Protoss_Observer.
Referenced by update().
{ if(BWAPI::Broodwar->self()->getRace() == BWAPI::Races::Protoss) { if(hasRequirements(BWAPI::UnitTypes::Protoss_Observer)) { TaskType type = TaskType::Defense; int num = getPlannedTotal(BWAPI::UnitTypes::Protoss_Observer); if(num > 3) return; else if(num == 0) type = TaskType::MacroUrgent; else if(num == 1) type = TaskType::Army; // Cancel and recreate if its the wrong type incase it was create when we had more but are now low on observers if(!mObserver || mObserver->inProgress() || mObserver->hasEnded() || mObserver->getType() != type) { if(mObserver && !mObserver->inProgress()) mObserver->cancel(); mObserver = TaskManager::Instance().build(BWAPI::UnitTypes::Protoss_Observer, type); } } } }
Definition at line 402 of file MacroManager.cpp.
References UnitToProduce::canBuildFactory(), UnitToProduce::getUnitType(), hasRequirements(), Singleton< T >::Instance(), TaskTypeDef::MacroExtraProduction, mNormalUnits, mTasksPerProducedType, BWAPI::UnitType::whatBuilds(), BWAPI::UnitTypes::Zerg_Hatchery, and BWAPI::UnitTypes::Zerg_Larva.
Referenced by update().
{ for each(UnitToProduce unit in mNormalUnits) { if(hasRequirements(unit.getUnitType()) && unit.canBuildFactory()) { BWAPI::UnitType whatBuilds = unit.getUnitType().whatBuilds().first; if(whatBuilds == BWAPI::UnitTypes::Zerg_Larva) whatBuilds = BWAPI::UnitTypes::Zerg_Hatchery; bool unstartedBuild = false; for each(TaskPointer task in mTasksPerProducedType[whatBuilds]) { if(!task->inProgress()) unstartedBuild = true; } if(unstartedBuild) continue; int idleOfThis = 0; for each(Unit building in UnitTracker::Instance().selectAllUnits(whatBuilds)) { if(building->isCompleted() && !building->isTraining()) ++idleOfThis; } if(idleOfThis == 0) TaskManager::Instance().build(whatBuilds, TaskType::MacroExtraProduction); } } }
void MacroManagerClass::updateTaskLists | ( | ) |
Definition at line 635 of file MacroManager.cpp.
References mTasksPerProducedType, mTasksPerProductionType, mTasksPerTechType, mTasksPerUpgradeType, and mUnitProduce.
Referenced by onChangeBuild(), and update().
{ for(std::list<std::pair<TaskPointer, BWAPI::UnitType>>::iterator it = mUnitProduce.begin(); it != mUnitProduce.end();) { if(it->first->hasEnded()) mUnitProduce.erase(it++); else ++it; } for(std::map<BWAPI::UnitType, std::list<TaskPointer>>::iterator it = mTasksPerProductionType.begin(); it != mTasksPerProductionType.end(); ++it) { for(std::list<TaskPointer>::iterator it2 = it->second.begin(); it2 != it->second.end();) { if((*it2)->hasEnded()) it->second.erase(it2++); else ++it2; } } for(std::map<BWAPI::UnitType, std::list<TaskPointer>>::iterator it = mTasksPerProducedType.begin(); it != mTasksPerProducedType.end(); ++it) { for(std::list<TaskPointer>::iterator it2 = it->second.begin(); it2 != it->second.end();) { if((*it2)->hasEnded()) it->second.erase(it2++); else ++it2; } } for(std::map<BWAPI::TechType, std::list<TaskPointer>>::iterator it = mTasksPerTechType.begin(); it != mTasksPerTechType.end(); ++it) { for(std::list<TaskPointer>::iterator it2 = it->second.begin(); it2 != it->second.end();) { if((*it2)->hasEnded()) it->second.erase(it2++); else ++it2; } } for(std::map<BWAPI::UpgradeType, std::map<int, std::list<TaskPointer>>>::iterator it = mTasksPerUpgradeType.begin(); it != mTasksPerUpgradeType.end(); ++it) { for(std::map<int, std::list<TaskPointer>>::iterator it1 = it->second.begin(); it1 != it->second.end(); ++it1) { for(std::list<TaskPointer>::iterator it2 = it1->second.begin(); it2 != it1->second.end();) { if((*it2)->hasEnded()) it1->second.erase(it2++); else ++it2; } } } }
void MacroManagerClass::updateTech | ( | ) |
Definition at line 683 of file MacroManager.cpp.
References mTechItems.
Referenced by update().
{ for(std::list<std::pair<MacroItem, TaskPointer>>::iterator it = mTechItems.begin(); it != mTechItems.end();) { // if its ended or something else is creating this, cancel it to avoid duplicates if(it->second->hasEnded() || (!it->second->inProgress() && it->first.inProgress())) { it->second->cancel(); mTechItems.erase(it++); } else ++it; } }
Definition at line 143 of file MacroManager.cpp.
References TaskTypeDef::Army, BWAPI::Broodwar, UnitToProduce::getUnitType(), UnitToProduce::getUnitWeight(), hasRequirements(), Singleton< T >::Instance(), mLowGasUnits, mLowMineralUnits, mNormalUnits, mTasksPerProductionType, mUnitProduce, BWAPI::BulletTypes::None, BWAPI::UnitTypes::None, BWAPI::DamageTypes::Normal, and BWAPI::UnitType::whatBuilds().
Referenced by update().
{ TrainType trainType = TrainType::Normal; int mineral = ResourceTracker::Instance().availableMineralAtTime(BWAPI::Broodwar->getFrameCount() + 450); int gas = ResourceTracker::Instance().availableGasAtTime(BWAPI::Broodwar->getFrameCount() + 450); double LowMineralRatio = gas == 0 ? 1 : double(mineral)/double(gas); double LowGasRatio = mineral == 0 ? 1 : double(gas)/double(mineral); if(std::max(gas, mineral) > 500) { if(LowMineralRatio < 0.4) trainType = TrainType::LowMineral; else if(LowGasRatio < 0.4) trainType = TrainType::LowGas; } std::list<UnitToProduce> unitsToProduce; if(trainType == TrainType::LowMineral) unitsToProduce = mLowMineralUnits; else if(trainType == TrainType::LowGas) unitsToProduce = mLowGasUnits; else if(trainType == TrainType::Normal) unitsToProduce = mNormalUnits; for(std::list<UnitToProduce>::iterator it = unitsToProduce.begin(); it != unitsToProduce.end();) { if(!hasRequirements(it->getUnitType()) || !it->canBuildUnit()) unitsToProduce.erase(it++); else ++it; } if(trainType != TrainType::Normal) { std::set<BWAPI::UnitType> unitsWeAreProducing; for each(UnitToProduce unit in unitsToProduce) { unitsWeAreProducing.insert(unit.getUnitType()); } for(std::list<std::pair<TaskPointer, BWAPI::UnitType>>::reverse_iterator it = mUnitProduce.rbegin(); it != mUnitProduce.rend(); ++it) { if(!it->first->inProgress() && unitsWeAreProducing.count(it->second) == 0) { it->first->cancel(); mUnitProduce.erase( --(it.base()) ); break; } } } // cancel and non dispatched unit that is normal but not this type std::map<BWAPI::UnitType, int> totalPerProductionBuilding; std::map<BWAPI::UnitType, int> UnitTotals; std::map<BWAPI::UnitType, std::map<BWAPI::UnitType, int>> UnitToBuilding; std::map<BWAPI::UnitType, int> totalWeightPerBuilding; // TODO: try to maintain some sort of balance between buildings for each(UnitToProduce unit in unitsToProduce) { int plannedTotalUnit = UnitTracker::Instance().selectAllUnits(unit.getUnitType()).size(); totalPerProductionBuilding[unit.getUnitType().whatBuilds().first] += plannedTotalUnit; UnitTotals[unit.getUnitType()] += plannedTotalUnit; totalWeightPerBuilding[unit.getUnitType().whatBuilds().first] += unit.getUnitWeight(); UnitToBuilding[unit.getUnitType().whatBuilds().first][unit.getUnitType()] = unit.getUnitWeight(); } for each(std::pair<BWAPI::UnitType, int> totalPair in totalPerProductionBuilding) { int buildings = UnitTracker::Instance().selectAllUnits(totalPair.first).size() * 2; int queued = mTasksPerProductionType[totalPair.first].size(); int freeProductionBuildings = buildings - queued; if(freeProductionBuildings > 0) { BWAPI::UnitType chosenUnit = BWAPI::UnitTypes::None; double biggestDifference = std::numeric_limits<double>::max(); for each(std::pair<BWAPI::UnitType, int> producePair in UnitToBuilding[totalPair.first]) { double neededRatio = double(producePair.second) / double(totalWeightPerBuilding[totalPair.first]); double currentRatio = 0; if(totalPair.second != 0) currentRatio = double(UnitTotals[producePair.first]) / double(totalPair.second); double difference = currentRatio - neededRatio; if(difference < biggestDifference) { biggestDifference = difference; chosenUnit = producePair.first; } } if(chosenUnit != BWAPI::UnitTypes::None) mUnitProduce.push_back(std::make_pair(TaskManager::Instance().build(chosenUnit, TaskType::Army), chosenUnit)); freeProductionBuildings--; } } }
std::list<UnitToProduce> MacroManagerClass::mLowGasUnits [private] |
Definition at line 119 of file MacroManager.h.
Referenced by onChangeBuild(), and updateUnitProduction().
std::list<UnitToProduce> MacroManagerClass::mLowMineralUnits [private] |
Definition at line 120 of file MacroManager.h.
Referenced by onChangeBuild(), and updateUnitProduction().
std::list<UnitToProduce> MacroManagerClass::mNormalUnits [private] |
Definition at line 118 of file MacroManager.h.
Referenced by onChangeBuild(), updateProductionProduction(), and updateUnitProduction().
TaskPointer MacroManagerClass::mObserver [private] |
Definition at line 128 of file MacroManager.h.
Referenced by updateObserverProduction().
std::map<BWAPI::UnitType, std::list<TaskPointer> > MacroManagerClass::mTasksPerProducedType [private] |
Definition at line 126 of file MacroManager.h.
Referenced by getPlannedCount(), onBuildTask(), updateProductionProduction(), and updateTaskLists().
std::map<BWAPI::UnitType, std::list<TaskPointer> > MacroManagerClass::mTasksPerProductionType [private] |
Definition at line 123 of file MacroManager.h.
Referenced by onBuildTask(), onTechTask(), onUpgradeTask(), updateTaskLists(), and updateUnitProduction().
std::map<BWAPI::TechType, std::list<TaskPointer> > MacroManagerClass::mTasksPerTechType [private] |
Definition at line 124 of file MacroManager.h.
Referenced by getPlannedCount(), onTechTask(), and updateTaskLists().
std::map<BWAPI::UpgradeType, std::map<int, std::list<TaskPointer> > > MacroManagerClass::mTasksPerUpgradeType [private] |
Definition at line 125 of file MacroManager.h.
Referenced by getPlannedCount(), onUpgradeTask(), and updateTaskLists().
std::list<std::pair<MacroItem, TaskPointer> > MacroManagerClass::mTechItems [private] |
Definition at line 131 of file MacroManager.h.
Referenced by createTechItems(), onChangeBuild(), and updateTech().
std::list<MacroItem> MacroManagerClass::mTechItemsToCreate [private] |
Definition at line 130 of file MacroManager.h.
Referenced by createTechItems(), and onChangeBuild().
std::map<BWAPI::TechType, int> MacroManagerClass::mTechPriorityMap [private] |
Definition at line 115 of file MacroManager.h.
Referenced by onBegin(), and onChangeBuild().
std::list<std::pair<TaskPointer, BWAPI::UnitType> > MacroManagerClass::mUnitProduce [private] |
Definition at line 122 of file MacroManager.h.
Referenced by updateTaskLists(), and updateUnitProduction().
std::map<BWAPI::UpgradeType, int> MacroManagerClass::mUpgradePriorityMap [private] |
Definition at line 116 of file MacroManager.h.
Referenced by onBegin(), and onChangeBuild().