use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class FinishedBattle method removeAttack.
@Override
public void removeAttack(final Route route, final Collection<Unit> units) {
m_attackingUnits.removeAll(units);
// the route could be null, in the case of a unit in a territory where a sub is submerged.
if (route == null) {
return;
}
final Territory attackingFrom = route.getTerritoryBeforeEnd();
Collection<Unit> attackingFromMapUnits = m_attackingFromMap.get(attackingFrom);
// handle possible null pointer
if (attackingFromMapUnits == null) {
attackingFromMapUnits = new ArrayList<>();
}
attackingFromMapUnits.removeAll(units);
if (attackingFromMapUnits.isEmpty()) {
m_attackingFrom.remove(attackingFrom);
}
// deal with amphibious assaults
if (attackingFrom.isWater()) {
if (route.getEnd() != null && !route.getEnd().isWater() && units.stream().anyMatch(Matches.unitIsLand())) {
m_amphibiousLandAttackers.removeAll(CollectionUtils.getMatches(units, Matches.unitIsLand()));
}
// that territory is no longer an amphibious assault
if (attackingFromMapUnits.stream().noneMatch(Matches.unitIsLand())) {
m_amphibiousAttackFrom.remove(attackingFrom);
// do we have any amphibious attacks left?
m_isAmphibious = !m_amphibiousAttackFrom.isEmpty();
}
}
for (final Collection<Unit> dependent : m_dependentUnits.values()) {
dependent.removeAll(units);
}
}
use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class FinishedBattle method addAttackChange.
@Override
public Change addAttackChange(final Route route, final Collection<Unit> units, final HashMap<Unit, HashSet<Unit>> targets) {
final Map<Unit, Collection<Unit>> addedTransporting = TransportTracker.transporting(units);
for (final Unit unit : addedTransporting.keySet()) {
if (m_dependentUnits.get(unit) != null) {
m_dependentUnits.get(unit).addAll(addedTransporting.get(unit));
} else {
m_dependentUnits.put(unit, addedTransporting.get(unit));
}
}
final Territory attackingFrom = route.getTerritoryBeforeEnd();
m_attackingFrom.add(attackingFrom);
m_attackingUnits.addAll(units);
m_attackingFromMap.putIfAbsent(attackingFrom, new ArrayList<>());
final Collection<Unit> attackingFromMapUnits = m_attackingFromMap.get(attackingFrom);
attackingFromMapUnits.addAll(units);
// are we amphibious
if (route.getStart().isWater() && route.getEnd() != null && !route.getEnd().isWater() && units.stream().anyMatch(Matches.unitIsLand())) {
m_amphibiousAttackFrom.add(route.getTerritoryBeforeEnd());
m_amphibiousLandAttackers.addAll(CollectionUtils.getMatches(units, Matches.unitIsLand()));
m_isAmphibious = true;
}
return ChangeFactory.EMPTY_CHANGE;
}
use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class EndRoundDelegate method checkVictoryCities.
private void checkVictoryCities(final IDelegateBridge bridge, final String victoryMessage, final String victoryType) {
final GameData data = bridge.getData();
final Collection<Territory> territories = data.getMap().getTerritories();
for (final String allianceName : data.getAllianceTracker().getAlliances()) {
final int vcAmount = getVcAmount(data, allianceName, victoryType);
final Set<PlayerID> teamMembers = data.getAllianceTracker().getPlayersInAlliance(allianceName);
int teamVCs = 0;
for (final Territory t : territories) {
if (Matches.isTerritoryOwnedBy(teamMembers).test(t)) {
final TerritoryAttachment ta = TerritoryAttachment.get(t);
if (ta != null) {
teamVCs += ta.getVictoryCity();
}
}
}
if (teamVCs >= vcAmount) {
bridge.getHistoryWriter().startEvent(allianceName + victoryMessage + vcAmount + " Victory Cities!");
final Collection<PlayerID> winners = data.getAllianceTracker().getPlayersInAlliance(allianceName);
// Added this to end the game on victory conditions
signalGameOver(allianceName + victoryMessage + vcAmount + " Victory Cities!", winners, bridge);
}
}
}
use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class InitializationDelegate method initOriginalOwner.
private static void initOriginalOwner(final IDelegateBridge bridge) {
final GameData data = bridge.getData();
final CompositeChange changes = new CompositeChange();
for (final Territory current : data.getMap()) {
if (!current.getOwner().isNull()) {
final TerritoryAttachment territoryAttachment = TerritoryAttachment.get(current);
if (territoryAttachment == null) {
throw new IllegalStateException("No territory attachment for " + current);
}
if (territoryAttachment.getOriginalOwner() == null && current.getOwner() != null) {
changes.add(OriginalOwnerTracker.addOriginalOwnerChange(current, current.getOwner()));
}
final Collection<Unit> factoryAndInfrastructure = current.getUnits().getMatches(Matches.unitIsInfrastructure());
changes.add(OriginalOwnerTracker.addOriginalOwnerChange(factoryAndInfrastructure, current.getOwner()));
} else if (!current.isWater()) {
final TerritoryAttachment territoryAttachment = TerritoryAttachment.get(current);
if (territoryAttachment == null) {
throw new IllegalStateException("No territory attachment for " + current);
}
}
}
bridge.getHistoryWriter().startEvent("Adding original owners");
bridge.addChange(changes);
}
use of games.strategy.engine.data.Territory in project triplea by triplea-game.
the class GameDataExporter method ownerInitialize.
private void ownerInitialize(final GameData data) {
xmlfile.append(" <ownerInitialize>\n");
for (final Territory terr : data.getMap().getTerritories()) {
if (!terr.getOwner().getName().equals(Constants.PLAYER_NAME_NEUTRAL)) {
xmlfile.append(" <territoryOwner territory=\"").append(terr.getName()).append("\" owner=\"").append(terr.getOwner().getName()).append("\"/>\n");
}
}
xmlfile.append(" </ownerInitialize>\n");
}
Aggregations