Search in sources :

Example 6 with UnitType

use of bwapi.UnitType in project BWJSAL by RobinsonMann.

the class BuildTimeTracker method updateBuildTime.

/**
 * Mark that we have observed the given UnitType at the current time.
 * This will recursively update the BuildTime for all units along the units tech tree.
 */
private void updateBuildTime(final UnitType unitType, final int time) {
    if (this.earliestBuildTime.containsKey(unitType)) {
        final int previouslyObservedBuiltTime = this.earliestBuildTime.get(unitType);
        if (previouslyObservedBuiltTime <= time || previouslyObservedBuiltTime == 0) {
            return;
        }
    }
    this.earliestBuildTime.put(unitType, time);
    // Sanity check. (Present inside of original BWSAL)
    if (time < 0) {
        return;
    }
    // Update earliest known build times of required units
    for (final UnitType techTreeParent : unitType.requiredUnits().keySet()) {
        final int latestPossibleBuildTimeOfParentTechType = time - techTreeParent.buildTime();
        updateBuildTime(techTreeParent, latestPossibleBuildTimeOfParentTechType);
    }
}
Also used : UnitType(bwapi.UnitType)

Example 7 with UnitType

use of bwapi.UnitType in project Ecgberht by Jabbo16.

the class InfluenceMap method updateMap.

public void updateMap(Unit arg0, boolean Destroyed) {
    int influence = 0;
    UnitType type = arg0.getType();
    TilePosition tile = arg0.getTilePosition().makeValid();
    if (type.isBuilding()) {
        if (type.canAttack() || type.equals(UnitType.Terran_Bunker)) {
            influence = defensivo;
        } else {
            if (type.canProduce()) {
                influence = ofensivo;
            } else {
                influence = neutro;
            }
        }
    } else {
        if (type.isFlyer()) {
            influence = volador;
        } else if (type.isMechanical()) {
            influence = maquina;
        } else {
            influence = biologica;
        }
    }
    if (Destroyed) {
        influence *= -1;
    }
    if (arg0.getPlayer().isEnemy(self)) {
        influence *= -1;
    }
    updateCellInfluence(new Pair<Point, Integer>(new Point(tile.getY(), tile.getX()), influence), type.isBuilding());
}
Also used : UnitType(bwapi.UnitType) TilePosition(bwapi.TilePosition) Point(java.awt.Point) Point(java.awt.Point)

Example 8 with UnitType

use of bwapi.UnitType in project BWJSAL by RobinsonMann.

the class ReservedMapTest method canBuildHere_blockingTilesWereReservedAndFreed.

@Test
public void canBuildHere_blockingTilesWereReservedAndFreed() {
    final TilePosition positionToBuild = new TilePosition(2, 2);
    final Unit builder = Mockito.mock(Unit.class);
    final UnitType typeToBuild = Mockito.mock(UnitType.class);
    when(typeToBuild.tileWidth()).thenReturn(2);
    when(typeToBuild.tileHeight()).thenReturn(2);
    when(this.mockGame.canBuildHere(positionToBuild, typeToBuild, builder)).thenReturn(true);
    // Reserve a tile that blocks building placement
    this.target.reserveTiles(3, 3);
    // Verify that tile does block placement
    assertThat(this.target.canBuildHere(builder, positionToBuild, typeToBuild)).isFalse();
    // Free blocking tile
    this.target.freeTiles(3, 3);
    // Verify that we can now place
    assertThat(this.target.canBuildHere(builder, positionToBuild, typeToBuild)).isTrue();
    verify(this.mockGame, times(2)).canBuildHere(positionToBuild, typeToBuild, builder);
    verify(typeToBuild, times(2)).tileWidth();
    verify(typeToBuild, times(2)).tileHeight();
}
Also used : UnitType(bwapi.UnitType) TilePosition(bwapi.TilePosition) Unit(bwapi.Unit) Test(org.junit.Test)

Example 9 with UnitType

use of bwapi.UnitType in project BWJSAL by RobinsonMann.

the class BuildTimeTracker method onUnitDiscover.

public void onUnitDiscover(final Unit unit, final Integer time) {
    if (this.self.isEnemy(unit.getPlayer())) {
        final UnitType unitType = unit.getType();
        updateBuildTime(unitType, time - unitType.buildTime());
    }
}
Also used : UnitType(bwapi.UnitType)

Example 10 with UnitType

use of bwapi.UnitType in project BWJSAL by RobinsonMann.

the class UnitTypeUtils method replaceUnitTypeWithMock.

/**
 * Replaces the static final UnitType.unitTypeName with a mock UnitType.
 * This is needed as UnitType values are loaded from DLLs, and we do not want to do this
 * for our unit tests.
 */
public static void replaceUnitTypeWithMock(final String unitTypeName) {
    final UnitType mockUnitType = Mockito.mock(UnitType.class);
    setStaticFinalField(UnitType.class, unitTypeName, mockUnitType);
}
Also used : UnitType(bwapi.UnitType)

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