void BaseManager::updateDepositCenterPosition() { std::set<Base*> allBases = this->getAllBases(); if (allBases.size() <=1) { return; } for(std::set<Base*>::iterator b = allBases.begin(); b != allBases.end(); b++) { BWAPI::TilePosition tile = (*b)->getBaseLocation()->getTilePosition(); std::set<BWAPI::Unit*> units = BWAPI::Broodwar->getUnitsOnTile(tile.x(),tile.y()); if (units.size() == 0) { UnitGroup commandCenters = SelectAll(BWAPI::UnitTypes::Terran_Command_Center).inRadius(400, (*b)->getBaseLocation()->getPosition()); if (commandCenters.size() > 0) { (*(commandCenters.begin()))->lift(); if ((*(commandCenters.begin()))->isLifted()) { (*(commandCenters.begin()))->land(tile); } } } } }
void AIModule::camera() { if (game->getMouseState(BWAPI::M_LEFT)) { return; } const int CENTER_SCREEN_X = 320; const int CENTER_SCREEN_Y = 140; if (!autocam) { return; } UnitGroup interestingUnits = AllUnits()(isAttacking); if (interestingUnits.size() == 0) { return; } BWAPI::Unit *unit = (*interestingUnits.begin()); BWAPI::Position unitPosition = unit->getPosition(); int x, y; x = unitPosition.x() - CENTER_SCREEN_X; y = unitPosition.y() - CENTER_SCREEN_Y; if (x < 0) { x = 0; } if (y < 0) { y = 0; } BWAPI::Broodwar->setScreenPosition(x, y); }
void BaseManager::update() { for(std::set<Base*>::iterator b = this->allBases.begin(); b != this->allBases.end(); b++) { Base *base = (*b); // periodicky check, ci baza pouziva najblizsi resource depot if (BWAPI::Broodwar->getFrameCount() % 300 == 231) { BWAPI::TilePosition tilePosition = base->getBaseLocation()->getTilePosition(); BWAPI::Position position = BWAPI::Position(tilePosition); UnitGroup centers = UnitGroup::getUnitGroup(BWAPI::Broodwar->getUnitsInRadius(position, 600)) (BWAPI::Broodwar->self()) (isResourceDepot); UnitGroup::iterator it; BWAPI::Unit *nearestCenter = NULL; double distance = 10000; for (it = centers.begin(); it != centers.end(); it++) { BWAPI::Unit *centerCandidate = (*it); dementor::Vector vector = dementor::Vector::fromPositions(position, centerCandidate->getPosition()); if (vector.getLength() < distance) { nearestCenter = centerCandidate; distance = vector.getLength(); } } if (nearestCenter != NULL) { base->setResourceDepot(nearestCenter); } if (base->getResourceDepot() != NULL) { if (!base->getResourceDepot()->exists()) { base->setResourceDepot(NULL); } else if (base->getResourceDepot()->isCompleted() || base->getResourceDepot()->getRemainingBuildTime() < 250) { base->setActive(true); } } } //Set Refinerys if (!base->isActiveGas() && base->hasGas()) { if (base->getRefinery() == NULL) { std::set<BWAPI::Unit*> baseGeysers = (*b)->getBaseLocation()->getGeysers(); BWAPI::TilePosition geyserLocation; //cycle through geysers & get tile location for(std::set<BWAPI::Unit*>::iterator bg = baseGeysers.begin(); bg != baseGeysers.end(); bg++) { geyserLocation = (*bg)->getTilePosition(); } //check for refinery already on geyser std::set<BWAPI::Unit*> unitsOnGeyser = BWAPI::Broodwar->getUnitsOnTile(geyserLocation.x(),geyserLocation.y()); for(std::set<BWAPI::Unit*>::iterator u = unitsOnGeyser.begin(); u != unitsOnGeyser.end(); u++) { BWAPI::Unit *unit = (*u); if (unit->getPlayer() == BWAPI::Broodwar->self() && unit->getType().isRefinery()) { base->setRefinery(*u); break; } } } if (base->getRefinery() != NULL) { if (!base->getRefinery()->exists()) { base->setResourceDepot(NULL); } else { if (base->getRefinery()->isCompleted() || base->getRefinery()->getRemainingBuildTime() < 250) { base->setActiveGas(true); } } } } } //check to see if any new base locations need to be added for(std::set<BWTA::BaseLocation*>::const_iterator bl = BWTA::getBaseLocations().begin(); bl != BWTA::getBaseLocations().end(); bl++) { if (location2base.find(*bl) == location2base.end()) { BWAPI::TilePosition tile = (*bl)->getTilePosition(); std::set<BWAPI::Unit*> units = BWAPI::Broodwar->getUnitsOnTile(tile.x(), tile.y()); for(std::set<BWAPI::Unit*>::iterator u = units.begin(); u != units.end(); u++) { if ((*u)->getPlayer() == BWAPI::Broodwar->self() && (*u)->getType().isResourceDepot()) { addBase(*bl); } } } } if(BWAPI::Broodwar->getFrameCount() % 500 == 0 && BWAPI::Broodwar->getFrameCount() >= 3000 && refineryBuildPriority > 0) { updateRefineries(); } }