use of bwta.BaseLocation in project BWJSAL by RobinsonMann.
the class InformationManagerAcceptanceTest method multipleResourceDepotsAtBaseOneDestroyed_baseLocationStillEnemies.
/**
* Verify that enemy base locations are not removed if multiple resource depots are observed at the same location.
*/
@Test
public void multipleResourceDepotsAtBaseOneDestroyed_baseLocationStillEnemies() {
final Race enemyRace = createMockRace(mock(UnitType.class), mock(UnitType.class));
when(this.enemy.getRace()).thenReturn(enemyRace);
final BaseLocation selfStartingLocation = mock(BaseLocation.class);
final BaseLocation enemyStartingLocation = mock(BaseLocation.class);
final BaseLocation otherStartingLocation = mock(BaseLocation.class);
setStartingLocationsOnMock(this.bwtaWrapper, selfStartingLocation, enemyStartingLocation, otherStartingLocation);
setSelfStartingLocationOnMock(this.bwtaWrapper, this.self, selfStartingLocation);
this.target.onStart();
assertThat(this.target.getEnemyBases()).as("no known enemy bases").isEmpty();
// observe multiple resource depots in enemy base location
final TilePosition firstResourceDepotPosition = mock(TilePosition.class);
setNearestBaseLocationOnMock(this.bwtaWrapper, firstResourceDepotPosition, enemyStartingLocation);
final Unit firstResourceDepot = UnitBuilder.mockUnit(this.enemy, mockResourceDepotUnitType(), firstResourceDepotPosition);
this.target.onUnitDiscover(firstResourceDepot);
final TilePosition secondResourceDepotPosition = mock(TilePosition.class);
setNearestBaseLocationOnMock(this.bwtaWrapper, secondResourceDepotPosition, enemyStartingLocation);
final Unit secondResourceDepot = UnitBuilder.mockUnit(this.enemy, mockResourceDepotUnitType(), firstResourceDepotPosition);
this.target.onUnitDiscover(secondResourceDepot);
// first resource depot destroyed
this.target.onUnitDestroy(firstResourceDepot);
// verify location is still enemy
assertThat(this.target.getEnemyBases()).as("selfStartingLocation still enemy base").containsExactly(enemyStartingLocation);
}
use of bwta.BaseLocation in project BWJSAL by RobinsonMann.
the class EnemyBaseTracker method possibleEnemyStartingLocation.
/**
* Will return a base location belonging to the enemy if the given building
* is inside of a region that also contains a starting location that could contain
* an enemy base.
*/
private Optional<BaseLocation> possibleEnemyStartingLocation(final Unit building) {
// Find the region that this building belongs to.
final Region unitRegion = this.bwta.getRegion(building.getTilePosition());
final List<BaseLocation> baseLocationsInsideRegion = unitRegion.getBaseLocations();
// starting locations that could contain the enemy. If so, return.
for (final BaseLocation baseLocationInsideRegion : baseLocationsInsideRegion) {
if (this.startLocationsThatCouldContainEnemy.contains(baseLocationInsideRegion)) {
return Optional.of(baseLocationInsideRegion);
}
}
return Optional.empty();
}
use of bwta.BaseLocation in project BWJSAL by RobinsonMann.
the class EnemyBaseTracker method onUnitDiscover.
@Override
public void onUnitDiscover(final Unit unitDiscovered) {
if (this.game.self().isEnemy(unitDiscovered.getPlayer()) == false) {
return;
}
// of the enemy.
if (scoutedAnEnemyBase() == false && unitDiscovered.getType().isBuilding()) {
final Optional<BaseLocation> enemyBaseLocation = possibleEnemyStartingLocation(unitDiscovered);
if (enemyBaseLocation.isPresent()) {
// So the enemy probably spawned here.
markBaseLocationAsEnemyBase(enemyBaseLocation.get());
}
}
if (unitDiscovered.getType().isResourceDepot()) {
final BaseLocation nearestBaseLocation = this.bwta.getNearestBaseLocation(unitDiscovered.getTilePosition());
markBaseLocationAsEnemyBase(nearestBaseLocation, unitDiscovered);
}
}
Aggregations