// STEP 2: ASSIGN WORKERS TO BUILDINGS WITHOUT THEM void BuildingManager::assignWorkersToUnassignedBuildings() { // for each building that doesn't have a builder, assign one buildingData.begin(ConstructionData::Unassigned); while (buildingData.hasNextBuilding(ConstructionData::Unassigned)) { Building & b = buildingData.getNextBuilding(ConstructionData::Unassigned); if (debugMode) { BWAPI::Broodwar->printf("Assigning Worker To: %s", b.type.getName().c_str()); } // remove all refineries after 3, i don't know why this happens if (b.type.isRefinery() && (BWAPI::Broodwar->self()->allUnitCount(b.type) >= 3)) { buildingData.removeCurrentBuilding(ConstructionData::Unassigned); break; } // grab a worker unit from WorkerManager which is closest to this final position BWAPI::UnitInterface* workerToAssign = WorkerManager::Instance().getBuilder(b); // if the worker exists if (workerToAssign) { //BWAPI::Broodwar->printf("VALID WORKER BEING ASSIGNED: %d", workerToAssign->getID()); // TODO: special case of terran building whose worker died mid construction // send the right click command to the buildingUnit to resume construction // skip the buildingsAssigned step and push it back into buildingsUnderConstruction // set the worker we have assigned b.builderUnit = workerToAssign; // re-search for a building location with the builder unit ignored for space BWAPI::TilePosition testLocation = getBuildingLocation(b); // hopefully this will not blow up if (!testLocation.isValid()) { continue; } // set the final position of the building b.finalPosition = testLocation; // reserve this space BuildingPlacer::Instance().reserveTiles(b.finalPosition, b.type.tileWidth(), b.type.tileHeight()); // this building has now been assigned buildingData.addBuilding(ConstructionData::Assigned, b); // remove this Building buildingData.removeCurrentBuilding(ConstructionData::Unassigned); } } }
// STEP 2: ASSIGN WORKERS TO BUILDINGS WITHOUT THEM void BuildingManager::assignWorkersToUnassignedBuildings() { // for each building that doesn't have a builder, assign one for (Building & b : _buildings) { if (b.status != BuildingStatus::Unassigned) { continue; } if (_debugMode) { BWAPI::Broodwar->printf("Assigning Worker To: %s", b.type.getName().c_str()); } if (createdHatchery && !isCreepStarted() && createdHatcheriesVector.size() >= 1 && startedPool) { //BWAPI::TilePosition myHatch = createdSunkenVector[0]; b.builderUnit = sunkenUnit; } else { BWAPI::Unit workerToAssign = WorkerManager::Instance().getBuilder(b); if (workerToAssign) { b.builderUnit = workerToAssign; } } //BWAPI::Broodwar->printf("VALID WORKER BEING ASSIGNED: %d", workerToAssign->getID()); // TODO: special case of terran building whose worker died mid construction // send the right click command to the buildingUnit to resume construction // skip the buildingsAssigned step and push it back into buildingsUnderConstruction BWAPI::TilePosition testLocation = getBuildingLocation(b); if (!testLocation.isValid()) { continue; } b.finalPosition = testLocation; // reserve this building's space BuildingPlacer::Instance().reserveTiles(b.finalPosition, b.type.tileWidth(), b.type.tileHeight()); b.status = BuildingStatus::Assigned; } }
// STEP 2: ASSIGN WORKERS TO BUILDINGS WITHOUT THEM void BuildingManager::assignWorkersToUnassignedBuildings() { // for each building that doesn't have a builder, assign one for (Building & b : _buildings) { if (b.status != BuildingStatus::Unassigned) { continue; } if (_debugMode) { BWAPI::Broodwar->printf("Assigning Worker To: %s",b.type.getName().c_str()); } // grab a worker unit from WorkerManager which is closest to this final position BWAPI::Unit workerToAssign = WorkerManager::Instance().getBuilder(b); if (workerToAssign) { //BWAPI::Broodwar->printf("VALID WORKER BEING ASSIGNED: %d", workerToAssign->getID()); // TODO: special case of terran building whose worker died mid construction // send the right click command to the buildingUnit to resume construction // skip the buildingsAssigned step and push it back into buildingsUnderConstruction b.builderUnit = workerToAssign; BWAPI::TilePosition testLocation = getBuildingLocation(b); if (!testLocation.isValid()) { continue; } b.finalPosition = testLocation; // reserve this building's space BuildingPlacer::Instance().reserveTiles(b.finalPosition,b.type.tileWidth(),b.type.tileHeight()); b.status = BuildingStatus::Assigned; } } }