Building expansion

Issue #22 new
Brandon Chatham created an issue

Hi there,

So my issue is that I am using BWTA to get potential expansion locations. I am correctly finding the nearest unused location but when I try to use unitBuilder->build(centerProviderType, buildLocation); (buildLocation is a TilePosition I want to build at) it does no trigger the event, however, when I tell the builder to move() to that position, it will go to the left-most corner of that base location. I am assuming I am trying to build at too close of a location to the minerals? Is there any simple way around this?

Here's some code:

UnitType centerProviderType = base->getType().getRace().getCenter();
Unit centerBuilder = base->getClosestUnit(GetType == centerProviderType.whatBuilds().first && (IsIdle || IsGatheringMinerals) && IsOwned);

// If a unit was found.
if (centerBuilder && !player->buildingCommandCenter)
{
    if (centerProviderType.isBuilding())
    {

        TilePosition targetBuildLocation = Broodwar->getBuildLocation(centerProviderType, buildLocation);
        if (buildLocation)
        {
            // Register an event that draws the target build location.
            Broodwar->registerEvent([buildLocation, centerProviderType](Game*)
            {
                Broodwar->drawBoxMap(Position(buildLocation), Position(buildLocation + centerProviderType.tileSize()), Colors::Blue);
            },
            nullptr, 
            centerProviderType.buildTime() + 100);  // frames to run.

            // Order the builder to construct the center structure.
            centerBuilder->move(Position(buildLocation));
            centerBuilder->build(centerProviderType, buildLocation);

Thanks for your help!

Comments (3)

  1. Alberto Uriarte repo owner

    In the code provided I don't see how you get buildLocation. You can print a "box" for each BaseLocation and see if the worker is moving to the correct "left-most corner" of one of these locations. If it is, you can try to call BWAPI::Game::getLastError() after your build order to see the problem. Maybe there is another unit where you want to build that is blocking the action.

  2. Brandon Chatham reporter

    What I am doing is iterating through the getBaseLocations() and finding the nearest one, then getting the TilePosition of that base and that is the buildLocation variable. I will try getLastError(). That may help me gain some insight. It correctly sends the unit to the base I want, but it simply won't take the next step of building.

  3. Joseph Huang

    You are sending the move command AND the build command on the same frame. What you want to do is send the move command OR the build command, depending on the distance from the build tile.

  4. Log in to comment