use of games.strategy.engine.data.GameMap in project triplea by triplea-game.
the class AirThatCantLandUtil method removeAirThatCantLand.
void removeAirThatCantLand(final PlayerID player, final boolean spareAirInSeaZonesBesideFactories) {
final GameData data = bridge.getData();
final GameMap map = data.getMap();
for (final Territory current : getTerritoriesWhereAirCantLand(player)) {
final Predicate<Unit> ownedAir = Matches.unitIsAir().and(Matches.alliedUnit(player, data));
final Collection<Unit> air = current.getUnits().getMatches(ownedAir);
final boolean hasNeighboringFriendlyFactory = map.getNeighbors(current, Matches.territoryHasAlliedIsFactoryOrCanProduceUnits(data, player)).size() > 0;
final boolean skip = spareAirInSeaZonesBesideFactories && current.isWater() && hasNeighboringFriendlyFactory;
if (!skip) {
removeAirThatCantLand(player, current, air);
}
}
}
use of games.strategy.engine.data.GameMap in project triplea by triplea-game.
the class GameDataExporter method connections.
private void connections(final GameData data) {
xmlfile.append(" <!-- Territory Connections -->\n");
final GameMap map = data.getMap();
final List<Connection> reverseConnectionTracker = new ArrayList<>();
for (final Territory ter : map.getTerritories()) {
for (final Territory nb : map.getNeighbors(ter)) {
if (!reverseConnectionTracker.contains(new Connection(ter, nb))) {
xmlfile.append(" <connection t1=\"").append(ter.getName()).append("\" t2=\"").append(nb.getName()).append("\"/>\n");
reverseConnectionTracker.add(new Connection(nb, ter));
}
}
}
}
use of games.strategy.engine.data.GameMap in project triplea by triplea-game.
the class RulesAttachment method setBattle.
private void setBattle(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length < 5) {
throw new GameParseException("battle must have at least 5 fields, attacker:defender:resultType:round:territory1..." + thisErrorMsg());
}
final PlayerID attacker = getData().getPlayerList().getPlayerId(s[0]);
if (attacker == null && !s[0].equalsIgnoreCase("any")) {
throw new GameParseException("no player named: " + s[0] + thisErrorMsg());
}
final PlayerID defender = getData().getPlayerList().getPlayerId(s[1]);
if (defender == null && !s[1].equalsIgnoreCase("any")) {
throw new GameParseException("no player named: " + s[1] + thisErrorMsg());
}
if (!s[2].equalsIgnoreCase("any")) {
throw new GameParseException("battle allows the following for resultType: any" + thisErrorMsg());
}
if (!s[3].equalsIgnoreCase("currentRound")) {
try {
getInt(s[3].split("-")[0]);
getInt(s[3].split("-")[1]);
} catch (final Exception e) {
throw new GameParseException("round must either be currentRound or two numbers like: 2-4" + thisErrorMsg());
}
}
final ArrayList<Territory> terrs = new ArrayList<>();
final GameMap map = getData().getMap();
// this loop starts on 4, so do not replace with an enhanced for loop
for (int i = 4; i < s.length; i++) {
final Territory t = map.getTerritory(s[i]);
if (t == null) {
throw new GameParseException("no such territory called: " + s[i] + thisErrorMsg());
}
terrs.add(t);
}
m_battle.add(Tuple.of((s[0] + ":" + s[1] + ":" + s[2] + ":" + s[3]), terrs));
}
use of games.strategy.engine.data.GameMap in project triplea by triplea-game.
the class ParserTest method testTerritoriesConnected.
@Test
public void testTerritoriesConnected() {
final GameMap map = gameData.getMap();
assertEquals(1, map.getDistance(map.getTerritory("canada"), map.getTerritory("us")));
}
use of games.strategy.engine.data.GameMap in project triplea by triplea-game.
the class SpecialMoveDelegate method allowAirborne.
private static boolean allowAirborne(final PlayerID player, final GameData data) {
if (!TechAbilityAttachment.getAllowAirborneForces(player, data)) {
return false;
}
final int airborneDistance = TechAbilityAttachment.getAirborneDistance(player, data);
final Set<UnitType> airborneBases = TechAbilityAttachment.getAirborneBases(player, data);
final Set<UnitType> airborneTypes = TechAbilityAttachment.getAirborneTypes(player, data);
if (airborneDistance <= 0 || airborneBases.isEmpty() || airborneTypes.isEmpty()) {
return false;
}
final GameMap map = data.getMap();
final Collection<PlayerID> alliesForBases = data.getRelationshipTracker().getAllies(player, true);
final Collection<Territory> territoriesWeCanLaunchFrom = CollectionUtils.getMatches(map.getTerritories(), Matches.territoryHasUnitsThatMatch(getAirborneMatch(airborneBases, alliesForBases)));
return !territoriesWeCanLaunchFrom.isEmpty();
}
Aggregations