// this function will check to see if all preconditions are met and then create a unit void ProductionManager::create(BWAPI::Unit producer, BuildOrderItem & item) { if (!producer) { return; } MetaType t = item.metaType; // if we're dealing with a building if (t.isUnit() && t.getUnitType().isBuilding() && t.getUnitType() != BWAPI::UnitTypes::Zerg_Lair && t.getUnitType() != BWAPI::UnitTypes::Zerg_Hive && t.getUnitType() != BWAPI::UnitTypes::Zerg_Greater_Spire && !t.getUnitType().isAddon()) { // send the building task to the building manager if (t.getUnitType() == BWAPI::UnitTypes::Terran_Bunker) { BWAPI::TilePosition tp = BWAPI::TilePosition(BWTA::getNearestChokepoint(BWAPI::Position(BWAPI::Broodwar->self()->getStartLocation()))->getCenter()); BuildingManager::Instance().addBuildingTask(t.getUnitType(), tp, item.isGasSteal); } else { BuildingManager::Instance().addBuildingTask(t.getUnitType(), BWAPI::Broodwar->self()->getStartLocation(), item.isGasSteal); } } else if (t.getUnitType().isAddon()) { //BWAPI::TilePosition addonPosition(producer->getTilePosition().x + producer->getType().tileWidth(), producer->getTilePosition().y + producer->getType().tileHeight() - t.unitType.tileHeight()); producer->buildAddon(t.getUnitType()); } // if we're dealing with a non-building unit else if (t.isUnit()) { // if the race is zerg, morph the unit if (t.getUnitType().getRace() == BWAPI::Races::Zerg) { producer->morph(t.getUnitType()); // if not, train the unit } else { producer->train(t.getUnitType()); } } // if we're dealing with a tech research else if (t.isTech()) { producer->research(t.getTechType()); } else if (t.isUpgrade()) { //Logger::Instance().log("Produce Upgrade: " + t.getName() + "\n"); producer->upgrade(t.getUpgradeType()); } else { } }
/* morphs the unit type specified in the build order item */ void ProductionManager::morphUnit(BuildOrderItem<PRIORITY_TYPE> element) { BWAPI::Unit* structure; //check that we can afford to train the new unit if((Broodwar->self()->minerals() >= element.metaType.mineralPrice()) && (Broodwar->self()->gas() >= element.metaType.gasPrice())) { structure = getBuilding(BWAPI::UnitTypes::Zerg_Hatchery); if(structure == NULL) { structure = getBuilding(BWAPI::UnitTypes::Zerg_Lair); } if(structure == NULL) { structure = getBuilding(BWAPI::UnitTypes::Zerg_Hive); } if(structure != NULL) { std::set<BWAPI::Unit*> larvae = structure->getLarva(); //if there are any idle larvae, then train the unit if (larvae.size() > 0) { BWAPI::Unit* larva = *larvae.begin(); larva->morph(element.metaType.unitType); } else { return; } } else { Broodwar->printf("ProductionManager Error: No available hatcheries"); return; } } }
// this function will check to see if all preconditions are met and then create a unit void ProductionManager::create(BWAPI::Unit producer, BuildOrderItem & item) { if (!producer) { return; } MetaType t = item.metaType; // if we're dealing with a building if (t.isUnit() && t.getUnitType().isBuilding() && t.getUnitType() != BWAPI::UnitTypes::Zerg_Lair && t.getUnitType() != BWAPI::UnitTypes::Zerg_Hive && t.getUnitType() != BWAPI::UnitTypes::Zerg_Greater_Spire && t.getUnitType() != BWAPI::UnitTypes::Zerg_Sunken_Colony && !t.getUnitType().isAddon()) { // send the building task to the building manager BuildingManager::Instance().addBuildingTask(t.getUnitType(), BWAPI::Broodwar->self()->getStartLocation(), item.isGasSteal); } else if (t.getUnitType().isAddon()) { //BWAPI::TilePosition addonPosition(producer->getTilePosition().x + producer->getType().tileWidth(), producer->getTilePosition().y + producer->getType().tileHeight() - t.unitType.tileHeight()); producer->buildAddon(t.getUnitType()); } // if we're dealing with a non-building unit else if (t.isUnit()) { // if the race is zerg, morph the unit if (t.getUnitType().getRace() == BWAPI::Races::Zerg) { producer->morph(t.getUnitType()); if (t.getUnitType() == BWAPI::UnitTypes::Zerg_Overlord) { _overlordTimer = BWAPI::Broodwar->getFrameCount() + t.getUnitType().buildTime() + 35; } // if not, train the unit } else { producer->train(t.getUnitType()); } } // if we're dealing with a tech research else if (t.isTech()) { producer->research(t.getTechType()); } else if (t.isUpgrade()) { //Logger::Instance().log("Produce Upgrade: " + t.getName() + "\n"); if (t.getUpgradeType() == BWAPI::UpgradeTypes::Muscular_Augments) { muscBuildTimer = BWAPI::Broodwar->getFrameCount() + t.getUpgradeType().upgradeTime(); muscBuild = true; } producer->upgrade(t.getUpgradeType()); } else { } }
// this function will check to see if all preconditions are met and then create a unit void ProductionManager::create(BWAPI::Unit producer, BuildOrderItem & item) { if (!producer) { return; } MetaType t = item.metaType; // if we're dealing with a building if (t.isUnit() && t.getUnitType().isBuilding() && t.getUnitType() != BWAPI::UnitTypes::Zerg_Lair && t.getUnitType() != BWAPI::UnitTypes::Zerg_Hive && t.getUnitType() != BWAPI::UnitTypes::Zerg_Greater_Spire && t.getUnitType() != BWAPI::UnitTypes::Zerg_Sunken_Colony && !t.getUnitType().isAddon()) { // send the building task to the building manager BuildingManager::Instance().addBuildingTask(t.getUnitType(), BWAPI::Broodwar->self()->getStartLocation(), item.isGasSteal); } else if (t.getUnitType().isAddon()) { //BWAPI::TilePosition addonPosition(producer->getTilePosition().x + producer->getType().tileWidth(), producer->getTilePosition().y + producer->getType().tileHeight() - t.unitType.tileHeight()); producer->buildAddon(t.getUnitType()); } // if we're dealing with a non-building unit else if (t.isUnit()) { // if the race is zerg, morph the unit if (t.getUnitType().getRace() == BWAPI::Races::Zerg) { if (t.getUnitType() == BWAPI::UnitTypes::Zerg_Overlord) { overlordBuildTimer = BWAPI::Broodwar->getFrameCount() + t.getUnitType().buildTime(); canOverlord = true; } producer->morph(t.getUnitType()); // if not, train the unit } else { producer->train(t.getUnitType()); } } // if we're dealing with a tech research else if (t.isTech()) { producer->research(t.getTechType()); } else if (t.isUpgrade()) { if (t.getUpgradeType() == BWAPI::UpgradeTypes::Zerg_Carapace) { BWAPI::Broodwar->printf("Got a request for carapace upgrade using producer x %d y %d: \n", producer->getTilePosition().x, producer->getTilePosition().y); } else if (t.getUpgradeType() == BWAPI::UpgradeTypes::Zerg_Missile_Attacks) { BWAPI::Broodwar->printf("Got a request for missile attacks upgrade using producer x %d y %d : \n", producer->getTilePosition().x, producer->getTilePosition().y); } producer = getEvolutionChamberProducer(producer, t); //BWAPI::Broodwar->printf("Got request for capace or missile attacks with producer type : x : %d y: %d\n", producer->getTilePosition().x, producer->getTilePosition().y); //} //Logger::Instance().log("Produce Upgrade: " + t.getName() + "\n"); producer->upgrade(t.getUpgradeType()); upgradingStuff.insert(producer); } else { } }