Search in sources :

Example 11 with UnitType

use of bwapi.UnitType in project BWJSAL by RobinsonMann.

the class UnitTypeUtils method mockResourceDepotUnitType.

/**
 * Create a mock instance of a unit type that represents a resource depot.
 *
 * @return Mock instance of UnitType where isResourceDepot() returns true.
 */
public static UnitType mockResourceDepotUnitType() {
    final UnitType resourceDepot = Mockito.mock(UnitType.class);
    when(resourceDepot.isResourceDepot()).thenReturn(true);
    return resourceDepot;
}
Also used : UnitType(bwapi.UnitType)

Example 12 with UnitType

use of bwapi.UnitType in project BWJSAL by RobinsonMann.

the class UnitTypeUtils method mockUnitTypeFromOfflineData.

public static void mockUnitTypeFromOfflineData(final String unitTypeName) {
    final OfflineUnitType offlineData = OfflineUnitType.getOfflineUnitType(unitTypeName);
    final UnitType mockUnitType = Mockito.mock(UnitType.class);
    when(mockUnitType.mineralPrice()).thenReturn(offlineData.mineralPrice);
    when(mockUnitType.gasPrice()).thenReturn(offlineData.vespeneGasPrice);
    when(mockUnitType.supplyRequired()).thenReturn(offlineData.supplyRequired);
    setStaticFinalField(UnitType.class, unitTypeName, mockUnitType);
}
Also used : UnitType(bwapi.UnitType)

Example 13 with UnitType

use of bwapi.UnitType in project BWJSAL by RobinsonMann.

the class BfsBuildingPlacer method canBuildHereWithSpace.

private boolean canBuildHereWithSpace(ReservedMap reservedMap, UnitType type, TilePosition position, Unit builder, int buildDist) {
    if (type.isAddon()) {
        type = type.whatBuilds().first;
    }
    if (builder != null) {
        if (!reservedMap.canBuildHere(builder, position, type)) {
            return false;
        }
    } else {
        if (!reservedMap.canBuildHere(position, type)) {
            return false;
        }
    }
    if (type.isRefinery()) {
        return true;
    }
    int width = type.tileWidth();
    int height = type.tileHeight();
    // make sure we leave space for add - ons. These types of units can have addons:
    if (type == UnitType.Terran_Command_Center || type == UnitType.Terran_Factory || type == UnitType.Terran_Starport || type == UnitType.Terran_Science_Facility) {
        width += 2;
    }
    int startx = position.getX() - buildDist;
    if (startx < 0) {
        return false;
    }
    int starty = position.getY() - buildDist;
    if (starty < 0) {
        return false;
    }
    int endx = position.getX() + width + buildDist;
    if (endx > game.mapWidth()) {
        return false;
    }
    int endy = position.getY() + height + buildDist;
    if (endy > game.mapHeight()) {
        return false;
    }
    for (int x = startx; x < endx; x++) {
        for (int y = starty; y < endy; y++) {
            if (!isBuildable(builder, x, y) || reservedMap.isReserved(x, y)) {
                return false;
            }
        }
    }
    if (position.getX() > 3) {
        int startx2 = Math.max(startx - 2, 0);
        for (int x = startx2; x < startx; x++) {
            for (int y = starty; y < endy; y++) {
                for (Unit u : game.getUnitsOnTile(x, y)) {
                    if (!u.isLifted() && u != builder) {
                        UnitType type2 = u.getType();
                        if (type2 == UnitType.Terran_Command_Center || type2 == UnitType.Terran_Factory || type2 == UnitType.Terran_Starport || type2 == UnitType.Terran_Science_Facility) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : UnitType(bwapi.UnitType) Unit(bwapi.Unit)

Aggregations

UnitType (bwapi.UnitType)13 TilePosition (bwapi.TilePosition)4 Unit (bwapi.Unit)4 Test (org.junit.Test)4 RaceUtils.createMockRace (BWJSAL.utils.RaceUtils.createMockRace)1 Race (bwapi.Race)1 Point (java.awt.Point)1 SneakyThrows (lombok.SneakyThrows)1